/* ============================================================
   Doseweek — screen styles
   Calm, clinical-but-warm: paper tones, deep green ink, amber
   accents, Fraunces display + Public Sans text.
   Fonts are bundled locally (OFL-licensed variable fonts).
   ============================================================ */

@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces-var.ttf") format("truetype-variations");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces-Italic-var.ttf") format("truetype-variations");
  font-weight: 100 900; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "Public Sans";
  src: url("fonts/PublicSans-var.ttf") format("truetype-variations");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Public Sans";
  src: url("fonts/PublicSans-Italic-var.ttf") format("truetype-variations");
  font-weight: 100 900; font-style: italic; font-display: swap;
}

:root {
  --paper: #f4f1ea;
  --paper-soft: #faf8f3;
  --card: #fffdf9;
  --ink: #22332d;
  --ink-soft: #5c6f68;
  --ink-faint: #8fa09a;
  --green: #2f6f5e;
  --green-deep: #245548;
  --green-tint: #e3efe9;
  --amber: #c9812e;
  --amber-tint: #faeedd;
  --line: #ddd6c8;
  --line-soft: #e9e4d8;
  --danger: #a4463c;
  --danger-tint: #f7e6e3;
  --shadow: 0 1px 2px rgba(34, 51, 45, .06), 0 8px 28px rgba(34, 51, 45, .08);
  --radius: 14px;
  --font-display: "Fraunces", Georgia, serif;
  --font-text: "Public Sans", -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.55;
}

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--green); color: #fff; padding: 10px 16px;
  border-radius: 0 0 10px 0; z-index: 60;
}
.skip-link:focus { left: 0; }

/* ---------- header ---------- */

.app-header {
  background: linear-gradient(180deg, var(--green-deep), var(--green));
  color: #f2efe6;
  padding: 28px 20px 72px;
}
.header-inner {
  max-width: 1080px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; gap: 14px; align-items: center; }
.brand-mark { width: 44px; height: 44px; flex: none; }
.brand-name {
  font-family: var(--font-display); font-weight: 640; font-size: 30px;
  margin: 0; letter-spacing: .01em; line-height: 1.1;
}
.brand-tag { margin: 2px 0 0; font-size: 13.5px; opacity: .82; }
.header-note { font-size: 13px; opacity: .75; max-width: 240px; margin: 6px 0 0; text-align: right; }

/* ---------- layout ---------- */

.app-main {
  max-width: 1080px; margin: -52px auto 0; padding: 0 20px 48px;
  display: grid; gap: 24px;
  grid-template-columns: minmax(0, 1fr);
}

.panel { min-width: 0; }

.panel {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.panel-head h2 {
  font-family: var(--font-display); font-weight: 560; font-size: 22px; margin: 0;
}
.panel-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- buttons ---------- */

.btn {
  font: 600 14px/1 var(--font-text);
  border-radius: 10px; padding: 11px 16px;
  border: 1px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background .16s ease, border-color .16s ease, transform .12s ease, box-shadow .16s ease;
}
.btn svg { width: 14px; height: 14px; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.btn-primary { background: var(--green); color: #fff; box-shadow: 0 2px 8px rgba(47,111,94,.25); }
.btn-primary:hover { background: var(--green-deep); }

.btn-ghost { background: transparent; color: var(--green-deep); border-color: var(--line); }
.btn-ghost:hover { background: var(--green-tint); border-color: var(--green); }

.icon-btn {
  background: none; border: none; cursor: pointer; color: var(--ink-soft);
  width: 34px; height: 34px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--paper); color: var(--ink); }

/* ---------- med list ---------- */

.med-list { display: grid; gap: 12px; }

.med-card {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 16px; align-items: center;
  border: 1px solid var(--line-soft);
  background: var(--paper-soft);
  border-radius: 12px;
  padding: 14px 16px;
  animation: card-in .28s ease both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.med-swatch {
  width: 14px; height: 44px; border-radius: 7px; background: var(--swatch, var(--green));
}
.med-name { font-weight: 700; font-size: 16px; margin: 0; }
.med-sub { margin: 2px 0 0; font-size: 13.5px; color: var(--ink-soft); }
.med-sub .sep { margin: 0 6px; color: var(--ink-faint); }
.med-actions { display: flex; gap: 4px; }

/* ---------- empty states ---------- */

.empty-state {
  text-align: center; padding: 40px 20px 32px; color: var(--ink-soft);
  border: 1.5px dashed var(--line); border-radius: 12px; background: var(--paper-soft);
}
.empty-state.small { padding: 28px 20px; }
.empty-art { width: 56px; height: 56px; color: var(--ink-faint); margin-bottom: 10px; }
.empty-state h3 { font-family: var(--font-display); font-weight: 560; font-size: 19px; color: var(--ink); margin: 0 0 6px; }
.empty-state p { max-width: 420px; margin: 0 auto 16px; font-size: 14.5px; }

/* ---------- modal ---------- */

.modal-backdrop[hidden] { display: none; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(34, 51, 45, .45);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; overflow-y: auto;
  animation: fade-in .18s ease both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  width: 100%; max-width: 520px; padding: 24px;
  animation: modal-in .22s cubic-bezier(.2,.9,.3,1.2) both;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-head h2 { font-family: var(--font-display); font-weight: 560; font-size: 21px; margin: 0; }

.field { margin-bottom: 16px; }
.field label, .field-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.req { color: var(--danger); }
.opt { color: var(--ink-faint); font-weight: 400; font-size: 12.5px; }
.field input[type="text"], .field input[type="date"], .field input[type="time"], .field select {
  width: 100%; font: 400 15px var(--font-text); color: var(--ink);
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-tint);
}
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13px; margin: 6px 0 0; }
.field-hint { color: var(--ink-faint); font-size: 12.5px; margin: 6px 0 0; }

.weekday-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.weekday-chip {
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  border-radius: 999px; padding: 7px 13px; font: 600 13px var(--font-text); cursor: pointer;
  transition: all .14s ease;
}
.weekday-chip[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; }
.weekday-chip:hover { border-color: var(--green); }

.times-inputs { display: flex; gap: 10px; flex-wrap: wrap; }
.time-slot { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 120px; }
.time-slot span { font-size: 12px; color: var(--ink-faint); font-weight: 600; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---------- week bar ---------- */

.week-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 18px;
}
.week-nav { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- sheet (printable checklist, previewed on screen) ---------- */

.sheet {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px 28px 20px;
  box-shadow: 0 2px 10px rgba(34,51,45,.07);
  transition: opacity .2s ease;
}
.sheet.week-flip { animation: sheet-in .25s ease both; }
@keyframes sheet-in { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }

.sheet-head { margin-bottom: 16px; }
.sheet-title-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap;
  border-bottom: 2.5px solid var(--ink); padding-bottom: 10px;
}
.sheet-title-row h2 { font-family: var(--font-display); font-weight: 640; font-size: 24px; margin: 0; }
.sheet-range { font-size: 15px; font-weight: 600; margin: 0; color: var(--ink); }
.sheet-meta {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--ink-soft); margin-top: 8px;
}

/* grid table */
.check-table {
  width: 100%; border-collapse: collapse; table-layout: fixed;
}
.check-table th, .check-table td {
  border: 1px solid var(--line); padding: 8px 8px; vertical-align: top;
  font-size: 13px; text-align: left;
}
.check-table thead th {
  background: var(--paper-soft); font-weight: 700; font-size: 12.5px;
  padding: 7px 8px;
}
.check-table thead th .th-date { display: block; font-weight: 500; color: var(--ink-soft); font-size: 11.5px; }
.check-table thead th.is-today { background: var(--green-tint); box-shadow: inset 0 2.5px 0 var(--green); }
.check-table .med-col { width: 22%; }
.check-table td.med-cell { background: var(--paper-soft); }
.check-table td.med-cell .m-name { font-weight: 700; font-size: 13.5px; display: block; }
.check-table td.med-cell .m-note { font-weight: 400; color: var(--ink-soft); font-size: 12px; display: block; margin-top: 1px; }
.check-table td.med-cell .m-freq { color: var(--ink-faint); font-size: 11px; display: block; margin-top: 3px; }
.check-table td.is-today { background: #f2f8f5; }
.check-table tr { break-inside: avoid; }

.dose {
  display: flex; align-items: center; gap: 7px;
  padding: 3px 0; font-size: 12.5px; white-space: nowrap;
}
.dose + .dose { border-top: 1px dotted var(--line); }
.dose .box {
  width: 13px; height: 13px; flex: none;
  border: 1.6px solid var(--ink); border-radius: 3px;
  display: inline-block;
}
.dose .dose-time { font-weight: 600; }

.day-total-row td {
  background: var(--paper-soft); font-size: 11.5px; color: var(--ink-soft);
  font-weight: 600; padding: 6px 8px;
}

.sheet-foot {
  display: flex; justify-content: space-between; gap: 10px;
  margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-faint);
}

/* today strip */
.today-strip { margin-top: 24px; }
.today-strip h2 { font-family: var(--font-display); font-weight: 560; font-size: 19px; margin: 0 0 10px; }
.today-list { display: flex; gap: 10px; flex-wrap: wrap; }
.today-chip {
  display: flex; align-items: center; gap: 9px;
  background: var(--green-tint); border: 1px solid #cfe2d8;
  border-radius: 999px; padding: 8px 14px; font-size: 13.5px;
  animation: card-in .3s ease both;
}
.today-chip .t-time { font-weight: 700; color: var(--green-deep); }
.today-chip .t-name { font-weight: 600; }
.today-chip .t-note { color: var(--ink-soft); font-size: 12.5px; }
.today-none { color: var(--ink-soft); font-size: 14px; }

/* ---------- footer & toast ---------- */

.app-footer {
  max-width: 1080px; margin: 0 auto; padding: 0 20px 40px;
  color: var(--ink-faint); font-size: 12.5px; text-align: center;
}

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: #f4f1ea; font-size: 14px; font-weight: 500;
  padding: 11px 20px; border-radius: 999px; box-shadow: var(--shadow);
  z-index: 70; animation: toast-in .22s ease both;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  .app-header { padding: 22px 16px 64px; }
  .header-note { display: none; }
  .app-main { padding: 0 14px 36px; margin-top: -48px; gap: 16px; }
  .panel { padding: 16px; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .panel-actions { width: 100%; }
  .panel-actions .btn { flex: 1; justify-content: center; }
  .med-card { grid-template-columns: 10px 1fr; }
  .med-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .week-bar { flex-direction: column; align-items: stretch; }
  .week-nav { justify-content: space-between; }
  #print-btn { justify-content: center; }
  .sheet { padding: 16px 12px; overflow-x: auto; }
  .check-table { min-width: 620px; }
  .sheet-title-row h2 { font-size: 19px; }
  .times-inputs { flex-direction: column; }
}

/* ============================================================
   Print styles — crisp black & white, one page per week,
   no screen chrome.
   ============================================================ */

@media print {
  @page { size: letter portrait; margin: 12mm 11mm; }

  :root { --line: #999; }

  body { background: #fff; font-size: 12px; }

  .no-print { display: none !important; }

  .app-main { margin: 0; padding: 0; display: block; max-width: none; }

  .schedule-panel {
    border: none; box-shadow: none; padding: 0; background: #fff; border-radius: 0;
  }

  .sheet {
    border: none; box-shadow: none; border-radius: 0;
    padding: 0; animation: none;
  }

  .sheet-title-row { border-bottom: 2.5px solid #000; }
  .sheet-title-row h2 { font-size: 20px; }
  .sheet-range { font-size: 13px; }
  .sheet-meta { color: #333; font-size: 10.5px; }

  .check-table th, .check-table td {
    border: 1px solid #666; padding: 6px; font-size: 11px;
  }
  .check-table thead th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; font-size: 10.5px; }
  .check-table thead th.is-today { background: #ddd !important; box-shadow: inset 0 2px 0 #000; }
  .check-table td.med-cell { background: #f4f4f4 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .check-table td.is-today { background: #f9f9f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .check-table td.med-cell .m-name { font-size: 11.5px; }
  .check-table td.med-cell .m-note, .check-table td.med-cell .m-freq { color: #333; }

  .dose { font-size: 10.5px; padding: 2px 0; }
  .dose .box { border-color: #000; width: 11px; height: 11px; }

  .day-total-row td { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; color: #222; font-size: 10px; }

  .sheet-foot { border-top: 1px solid #999; color: #444; font-size: 10px; }
}
