:root {
  color-scheme: light;
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #243432;
  background: #f7f8f3;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #74bb9166;
  outline-offset: 2px;
}

.page { width: min(100%, 1280px); margin: 0 auto; padding: 0 32px; }
.topbar {
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e3e9e2;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; letter-spacing: .02em; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: #2d6659; color: #fff; font-size: 25px; font-weight: 400; }
.text-button { min-height: 40px; padding: 0 8px; border: 0; background: none; color: #63756e; }
.text-button:hover, .archive-toggle:hover { text-decoration: underline; }
main { min-height: 70vh; }
.loading { margin: 0; padding: 32px 0; color: #718078; text-align: center; font-size: 14px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 24px 0 16px; }
.section-head h1 { margin: 0; font-size: 25px; line-height: 1.25; letter-spacing: -.04em; }
.head-actions { display: flex; align-items: center; gap: 8px; }
.primary, .secondary {
  min-height: 42px;
  border-radius: 11px;
  padding: 9px 15px;
  font-weight: 700;
}
.primary { border: 1px solid #2d6659; background: #2d6659; color: #fff; box-shadow: 0 4px 12px #2d66591c; }
.primary:hover { background: #235449; }
.primary:disabled { opacity: .5; cursor: wait; }
.secondary { border: 1px solid #d5e1d7; background: #fff; color: #385349; }
.secondary:hover { background: #f1f6f2; }
.add-button { padding-inline: 16px; }
.add-button span { margin-right: 3px; font-size: 19px; vertical-align: -1px; }
.refresh-button { padding-inline: 14px; }

.overview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 62px; padding: 12px 16px; border: 1px solid #e2ebe3; border-radius: 14px; background: #fff; }
.metric span { color: #718078; font-size: 13px; }
.metric strong { font-size: 23px; line-height: 1; letter-spacing: -.04em; }

.med-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.med-card { min-width: 0; padding: 18px; border: 1px solid #e2ebe4; border-radius: 16px; background: #fff; box-shadow: 0 5px 18px #4d685708; }
.med-card.overdue { border-color: #edc8a2; background: #fffdfa; }
.med-card.low { border-color: #e9d9b7; }
.med-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.med-card h2 { min-width: 0; margin: 0 0 5px; overflow-wrap: anywhere; font-size: 19px; line-height: 1.3; letter-spacing: -.03em; }
.med-card .meta { color: #819087; font-size: 12px; line-height: 1.45; }
.badge { flex: 0 0 auto; align-self: flex-start; padding: 5px 9px; border-radius: 99px; background: #e7f3ec; color: #3c7a60; font-size: 11px; font-weight: 750; white-space: nowrap; }
.badge.warn { background: #fff0db; color: #a26926; }
.badge.muted { background: #eef0ee; color: #79827a; }
.timing { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 15px 0 11px; }
.time-box { min-width: 0; padding: 10px; border-radius: 10px; background: #f5f8f4; }
.time-box span, .stock-line span { display: block; margin-bottom: 4px; color: #84938a; font-size: 11px; }
.time-box strong { display: block; overflow-wrap: anywhere; font-size: 13px; font-weight: 750; }
.stock-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 11px; border-top: 1px solid #edf0eb; }
.stock-line strong { font-size: 16px; color: #286c54; }
.forecast { min-height: 18px; margin: 9px 0 12px; color: #758379; font-size: 12px; line-height: 1.5; }
.card-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.card-actions button { min-width: 0; min-height: 40px; padding: 7px 4px; border: 1px solid #dce7dc; border-radius: 9px; background: #fff; color: #426357; font-size: 12px; font-weight: 700; white-space: nowrap; }
.card-actions button:hover { background: #f0f7f1; }
.card-actions .take { border-color: #2d6659; background: #2d6659; color: #fff; }
.card-actions .take:hover { background: #235449; }

.empty { margin: 0; padding: 34px 16px; border: 1px dashed #c9d8cc; border-radius: 15px; color: #7e9084; text-align: center; }
.archive-toggle { min-height: 42px; padding: 8px 0; border: 0; background: none; color: #668774; font-size: 13px; font-weight: 700; }
.archived-list { margin-bottom: 12px; opacity: .8; }
footer { margin-top: 34px; padding: 16px 0 26px; border-top: 1px solid #e3e9e2; color: #9aa89d; font-size: 11px; }

.modal { width: min(calc(100% - 28px), 520px); max-height: min(92dvh, 820px); overflow: auto; padding: 24px; border: 0; border-radius: 18px; box-shadow: 0 24px 80px #183c3150; }
.wide-modal { width: min(calc(100% - 28px), 700px); }
.modal::backdrop { background: #1b3029a8; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
.modal-head h2 { margin: 0; font-size: 22px; letter-spacing: -.04em; }
.close { flex: 0 0 auto; width: 40px; height: 40px; border: 0; border-radius: 10px; background: #f1f5ef; color: #6b7d6e; font-size: 23px; line-height: 1; }
.modal label { display: block; margin: 14px 0 0; color: #4c6255; font-size: 13px; font-weight: 750; }
.modal input:not([type=checkbox]), .modal select, .modal textarea, .login-form input { display: block; width: 100%; min-height: 44px; margin-top: 6px; padding: 10px 12px; border: 1px solid #d7e2d8; border-radius: 10px; outline: none; background: #fbfcf9; color: #243432; }
.modal input:focus, .modal select:focus, .modal textarea:focus, .login-form input:focus { border-color: #3e8a6e; box-shadow: 0 0 0 3px #74bb912e; }
.modal textarea { min-height: 64px; resize: vertical; }
.choice-field { margin-top: 14px; }
.field-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.field-title { color: #4c6255; font-size: 13px; font-weight: 750; }
.unit-note { color: #89978c; font-size: 12px; }
.choice-options { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 7px; }
.choice-options button { min-width: 48px; min-height: 40px; padding: 7px 13px; border: 1px solid #d7e2d8; border-radius: 10px; background: #fff; color: #426357; font-size: 14px; font-weight: 700; }
.choice-options button:hover { background: #f0f7f1; }
.choice-options button[aria-pressed="true"] { border-color: #2d6659; background: #2d6659; color: #fff; }
.choice-options button:disabled { cursor: default; opacity: .7; }
.advanced-options { margin-top: 8px; }
.advanced-options summary { display: flex; align-items: center; gap: 7px; width: fit-content; min-height: 38px; padding: 0 10px; border: 1px solid #dce7dc; border-radius: 9px; color: #526c5f; cursor: pointer; font-size: 13px; font-weight: 700; list-style: none; }
.advanced-options summary::-webkit-details-marker { display: none; }
.advanced-options summary::after { content: "＋"; color: #6f8978; font-size: 15px; }
.advanced-options[open] summary::after { content: "−"; }
.hint { margin-top: 8px; color: #89978c; font-size: 12px; }
.checkbox-row { display: flex !important; align-items: center; gap: 9px; }
.checkbox-row input { width: 18px; height: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
.time-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; }
.time-row label { min-width: 0; }
.time-row button { min-height: 44px; }
.dialog-intro { margin: 0 0 8px; color: #78897c; }
.dose-difference { margin-top: 12px; padding: 10px 12px; border: 1px solid #f1d4a4; border-radius: 9px; background: #fff3e0; color: #98622f; font-size: 13px; }
.history-section h3 { margin: 22px 0 9px; font-size: 15px; }
.history-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0; padding: 12px; border: 1px solid #e6ece4; border-radius: 12px; }
.history-item strong { font-size: 13px; }
.history-item small { display: block; margin-top: 4px; color: #8a998c; line-height: 1.5; }
.history-item button { min-height: 38px; padding: 7px 10px; border: 0; border-radius: 8px; background: #eaf3eb; color: #386d51; white-space: nowrap; }
.history-item.voided { opacity: .48; }
.locked, .unavailable { max-width: 480px; margin: 64px auto; }
.panel { padding: 28px; border: 1px solid #e3ebe3; border-radius: 18px; background: #fff; }
.locked h1, .unavailable h1 { margin: 0; font-size: 26px; letter-spacing: -.04em; }
.locked p { color: #78897c; line-height: 1.6; }
.login-form label { display: block; margin-top: 20px; font-size: 13px; font-weight: 700; }
.login-form button { margin-top: 14px; }
.unavailable button { margin-top: 18px; }
.toast { position: fixed; z-index: 10; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); left: 16px; width: fit-content; max-width: min(520px, calc(100vw - 32px)); margin: 0 auto; padding: 12px 18px; transform: translateY(16px); border-radius: 12px; background: #244b3d; box-shadow: 0 10px 35px #1f3c2b55; color: #fff; opacity: 0; pointer-events: none; text-align: center; font-size: 14px; transition: .2s; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #9a4938; }

@media (min-width: 1200px) {
  .med-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .page { padding: 0 20px; }
  .topbar { height: 62px; }
  .brand { font-size: 18px; }
  .section-head { margin-top: 18px; }
  .section-head h1 { font-size: 23px; }
  .overview { gap: 8px; }
  .metric { min-height: 58px; padding: 10px 12px; border-radius: 12px; }
  .metric span { font-size: 12px; }
  .metric strong { font-size: 21px; }
  .med-list { gap: 10px; }
  .med-card { padding: 15px; }
  .time-box { padding: 9px; }
  .card-actions { gap: 6px; }
  .card-actions button { min-height: 42px; }
  footer { margin-top: 24px; }
}

@media (max-width: 620px) {
  .page { padding: 0 16px; }
  .topbar { height: 58px; }
  .section-head { gap: 10px; margin: 16px 0 12px; }
  .section-head h1 { font-size: 21px; }
  .head-actions { gap: 6px; }
  .add-button { min-height: 44px; padding: 8px 12px; font-size: 13px; }
  .refresh-button { min-height: 44px; padding: 8px 10px; font-size: 13px; }
  .overview { gap: 6px; margin-bottom: 12px; }
  .metric { min-height: 56px; display: block; padding: 9px 10px; }
  .metric span { display: block; margin-bottom: 5px; font-size: 11px; white-space: nowrap; }
  .metric strong { font-size: 20px; }
  .med-list { grid-template-columns: minmax(0, 1fr); }
  .med-card { padding: 15px; }
  .med-card h2 { font-size: 18px; }
  .card-actions button, .choice-options button { min-height: 44px; }
  .time-box strong { font-size: 13px; }
  .empty { padding: 27px 14px; }
  .modal { width: min(calc(100% - 20px), 520px); max-height: min(92dvh, 820px); padding: 19px; }
  .wide-modal { width: min(calc(100% - 20px), 700px); }
  .modal-head { margin-bottom: 16px; }
  .modal-head h2 { font-size: 20px; }
  .close { width: 44px; height: 44px; }
  .modal-actions .primary, .modal-actions .secondary { flex: 1; min-height: 44px; }
  .modal-actions { position: sticky; bottom: 0; z-index: 1; margin: 22px -19px -19px; padding: 12px 19px 19px; border-top: 1px solid #edf0eb; background: #fff; }
  .history-item { align-items: flex-start; padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
