:root {
  color-scheme: light;
  --ink: #2d2430;
  --muted: #766a73;
  --paper: #fffaf7;
  --surface: #ffffff;
  --line: #eadde2;
  --berry: #7d3152;
  --berry-dark: #60213e;
  --rose: #f5dce6;
  --peach: #f7e9df;
  --green: #41715c;
  --blue: #376e86;
  --shadow: 0 18px 55px rgba(74, 37, 54, .12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.topbar {
  min-height: 84px; padding: 16px clamp(18px, 4vw, 56px); display: flex; align-items: center;
  justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); background: rgba(255,250,247,.92);
  position: sticky; top: 0; z-index: 5; backdrop-filter: blur(14px);
}
h1, h2, p { margin-top: 0; }
h1 { font-family: Georgia, serif; font-size: clamp(1.7rem, 3vw, 2.35rem); margin-bottom: 0; letter-spacing: -.03em; }
h2 { font-family: Georgia, serif; font-size: 1.35rem; margin-bottom: 0; }
.eyebrow { color: var(--berry); text-transform: uppercase; letter-spacing: .14em; font-size: .68rem; font-weight: 800; margin-bottom: 4px; }
.muted, .field-note { color: var(--muted); }
.field-note { font-size: .78rem; margin: -7px 0 16px; }

.app-shell { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(290px, .75fr); gap: 24px; padding: 28px clamp(18px, 4vw, 56px) 56px; }
.calendar-panel, .timeline-panel, .login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.calendar-panel, .timeline-panel { padding: clamp(16px, 3vw, 28px); }
.section-heading, .month-nav, .header-actions, .dialog-header, .dialog-actions, .fieldset-heading { display: flex; align-items: center; }
.section-heading, .dialog-header, .fieldset-heading { justify-content: space-between; gap: 12px; }
.section-heading { margin-bottom: 20px; }
.month-nav { gap: 8px; }
.header-actions { gap: 12px; }
.user-email { color: var(--muted); font-size: .82rem; }

button { border: 0; }
.primary, .ghost, .danger { border-radius: 12px; padding: 10px 15px; font-weight: 750; }
.primary { color: white; background: var(--berry); box-shadow: 0 7px 18px rgba(125,49,82,.22); }
.primary:hover { background: var(--berry-dark); }
.ghost { background: var(--peach); color: var(--ink); }
.danger { color: #8b1e2d; background: #fde7e9; }
.compact { padding: 7px 10px; font-size: .82rem; }
.icon-button { width: 36px; height: 36px; border-radius: 50%; background: transparent; color: var(--berry); font-size: 1.35rem; }
.icon-button:hover { background: var(--rose); }

.weekdays, .calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays { color: var(--muted); font-size: .72rem; font-weight: 800; text-align: center; padding-bottom: 8px; }
.calendar { border-left: 1px solid var(--line); border-top: 1px solid var(--line); }
.day { min-height: 105px; padding: 8px; text-align: left; background: white; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--ink); overflow: hidden; }
.day:hover { background: #fff6f4; }
.day.outside { background: #fbf8f6; color: #b9adb3; }
.day-number { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 50%; font-weight: 700; font-size: .83rem; }
.day.today .day-number { background: var(--berry); color: white; }
.day-events { display: flex; flex-direction: column; gap: 4px; margin-top: 5px; }
.event-marker { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-left: 3px solid #927f89; background: #f2edf0; padding: 3px 5px; border-radius: 4px; font-size: .65rem; }
.event-marker.possible_pfapa { border-color: var(--berry); background: var(--rose); }
.event-marker.possible_infection { border-color: var(--blue); background: #dfeff4; }
.event-marker.other { border-color: var(--green); background: #e3f0e9; }
.more { font-size: .65rem; color: var(--muted); }

.episode-list { display: flex; flex-direction: column; gap: 9px; }
.episode-card { width: 100%; display: flex; gap: 10px; text-align: left; padding: 13px; background: #fffaf9; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); }
.episode-card:hover { border-color: #c99caf; transform: translateY(-1px); }
.episode-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.episode-body > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .85rem; }
.episode-body small { color: var(--berry); font-size: .72rem; }
.classification-dot { flex: 0 0 9px; width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; background: #927f89; }
.classification-dot.possible_pfapa { background: var(--berry); }
.classification-dot.possible_infection { background: var(--blue); }
.classification-dot.other { background: var(--green); }
.count-pill { display: grid; place-items: center; min-width: 28px; height: 28px; border-radius: 14px; color: var(--berry); background: var(--rose); font-weight: 800; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 10% 0%, #f7dce7, transparent 42%), var(--paper); }
.login-card { width: min(430px, 100%); padding: 38px; }
.login-logo { width: 58px; height: 58px; margin-bottom: 18px; }
.stack { display: grid; gap: 15px; margin-top: 25px; }
label { display: grid; gap: 6px; color: #51464d; font-size: .79rem; font-weight: 750; }
input, select, textarea { width: 100%; border: 1px solid #d9cbd1; border-radius: 10px; padding: 10px 11px; color: var(--ink); background: white; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(125,49,82,.13); border-color: var(--berry); }
textarea { resize: vertical; }
.form-error { min-height: 1.1em; color: #a02535; font-size: .82rem; margin-bottom: 0; }

dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100vh - 24px); overflow: auto; border: 0; border-radius: 22px; padding: 0; color: var(--ink); box-shadow: 0 28px 100px rgba(49,22,35,.28); }
dialog::backdrop { background: rgba(45,36,48,.45); backdrop-filter: blur(3px); }
#password-dialog { width: min(480px, calc(100% - 24px)); }
#password-form { padding: 22px; }
.password-fields { margin-top: 18px; }
#episode-form { display: grid; gap: 17px; padding: 24px; }
.dialog-header { border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 13px; }
fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 0; }
legend { font-size: .82rem; font-weight: 800; padding: 0 4px; }
.fieldset-heading legend { padding: 0; }
.check-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }
.check { display: flex; align-items: center; gap: 8px; background: #faf5f6; padding: 9px; border-radius: 9px; font-weight: 650; }
.check input { width: auto; accent-color: var(--berry); }
.repeat-list { display: grid; gap: 10px; margin-top: 10px; }
.repeat-row { display: grid; align-items: end; gap: 8px; padding: 10px; border-radius: 10px; background: #faf7f5; }
.measurement-row { grid-template-columns: 1.2fr .85fr .7fr 1.1fr auto; }
.medication-row { grid-template-columns: 1.3fr 1.1fr .8fr .9fr auto; }
.medication-row .wide { grid-column: 1 / -2; }
.repeat-row .icon-button { margin-bottom: 1px; }
.dialog-actions { border-top: 1px solid var(--line); padding-top: 16px; gap: 9px; }
.action-spacer { flex: 1; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 15px); opacity: 0; pointer-events: none; background: var(--ink); color: white; padding: 10px 16px; border-radius: 12px; transition: .2s; z-index: 20; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .timeline-panel { order: -1; }
  .day { min-height: 76px; padding: 5px; }
  .event-marker { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 50%; font-size: 0; background: #927f89; }
  .event-marker.possible_pfapa { background: var(--berry); }
  .event-marker.possible_infection { background: var(--blue); }
  .event-marker.other { background: var(--green); }
}

@media (max-width: 600px) {
  .topbar { min-height: 72px; }
  .user-email { display: none; }
  .app-shell { padding: 14px 10px 40px; gap: 14px; }
  .calendar-panel, .timeline-panel { padding: 14px 10px; border-radius: 16px; }
  .section-heading { padding-inline: 4px; }
  .day { min-height: 63px; }
  .form-grid, .check-grid { grid-template-columns: 1fr 1fr; }
  .measurement-row, .medication-row { grid-template-columns: 1fr 1fr; }
  .repeat-row .remove-row { grid-column: 2; justify-self: end; }
  .medication-row .wide { grid-column: 1 / -1; }
  #episode-form { padding: 18px 14px; }
}

