/* Clinic Reminders — design system: design-system/clinic-reminders/MASTER.md (ui-ux-pro-max).
   Style: Minimalism & Swiss, light mode, champagne + gold palette; Lora headings + Raleway body.
   All text/UI pairs checked against WCAG (see MASTER.md "Palette: Champagne and gold"). */
:root {
  /* surfaces */
  --bg: #FAFAF9;
  --surface: #FFFFFF;
  --surface-2: #F5F1EA;            /* warm champagne tint */
  --border: #E7E5E4;               /* decorative dividers and card edges */
  --border-input: #8C857F;         /* form control edges: 3.6:1 on white */
  /* text */
  --text: #292524;                 /* body: 14.5:1 on bg */
  --heading: #1C1917;              /* 16.7:1 on bg */
  --muted: #57534E;                /* 7.3:1 on bg, 6.8:1 on surface-2 */
  /* brand */
  --primary: #A16207;              /* gold: decorative accents (active bar, stat rule, focus) */
  --accent: #1C1917;               /* buttons: white text 17.5:1 */
  --accent-hover: #44403C;
  --accent-soft: #F5EFE3;          /* champagne highlight */
  --gold-text: #854D0E;            /* gold text/links: 6.6:1 on bg */
  --gold-text-hover: #713F12;
  --accent-2: #CA8A04;             /* decorative secondary (step rail) */
  --ring: #A16207;                 /* focus ring: 4.9:1 on white */
  /* status */
  --green: #15803D;  --green-soft: #DCFCE7;
  --amber: #B45309;  --amber-soft: #FEF3C7;
  --red: #B91C1C;    --red-soft: #FEE2E2;
  --blue: #1D4ED8;   --blue-soft: #DBEAFE;
  /* shape & depth (Swiss: flat, crisp) */
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28, 25, 23, .06);
  --shadow-pop: 0 12px 32px rgba(28, 25, 23, .18);
  /* spacing (density 7) */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --ease: 200ms ease;
  --font-heading: 'Lora', Georgia, serif;
  --font-body: 'Raleway', system-ui, -apple-system, 'Segoe UI', sans-serif;
  /* theme-dependent details */
  --on-accent: #FFFFFF;
  --danger-border: #E5A3A3;
  --placeholder: #78716C;
  --ring-soft: rgba(161, 98, 7, .22);
  --tab-hover: rgba(255, 255, 255, .6);
  --bubble-bg: #DCF8C6;  --bubble-text: #1F2D1A;
  --step-bg: #FBF9F5;
  --backdrop: rgba(28, 25, 23, .45);
  --toast-bg: #292524;   --toast-text: #FFFFFF;
  --login-tint: #F3ECDF;
  --seg-active: #FFFFFF;
  --callout-border: #F3D9A4;  --callout-info-border: #BFD4F5;
  color-scheme: light;
}

/* Dark theme: chosen in the app (data-theme="dark"), or following the device when set to Auto.
   Every pair checked for WCAG contrast (see design-system MASTER.md "Dark mode"). */
:root[data-theme="dark"] {
  --bg: #141211;
  --surface: #1E1B19;
  --surface-2: #292522;
  --border: #34302C;
  --border-input: #7A736C;
  --text: #E7E2DC;
  --heading: #FAF7F2;
  --muted: #A8A29E;
  --primary: #D6A642;
  --accent: #E3BE6E;
  --accent-hover: #F0D493;
  --accent-soft: #2E2618;
  --gold-text: #E3B65E;
  --gold-text-hover: #F0CC85;
  --accent-2: #B88A2E;
  --ring: #E3B65E;
  --green: #4ADE80;  --green-soft: #12301F;
  --amber: #FBBF24;  --amber-soft: #2B220F;
  --red: #FCA5A5;    --red-soft: #3B1414;
  --blue: #93C5FD;   --blue-soft: #16213A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, .55);
  --on-accent: #1C1917;
  --danger-border: #7F2D2D;
  --placeholder: #8F8881;
  --ring-soft: rgba(227, 182, 94, .25);
  --tab-hover: rgba(255, 255, 255, .06);
  --bubble-bg: #1F3A2B;  --bubble-text: #E2F5D5;
  --step-bg: #221F1C;
  --backdrop: rgba(0, 0, 0, .6);
  --toast-bg: #E7E2DC;   --toast-text: #1C1917;
  --login-tint: #221C14;
  --seg-active: #3D362F;
  --callout-border: #5C4718;  --callout-info-border: #2C3E66;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #141211;
    --surface: #1E1B19;
    --surface-2: #292522;
    --border: #34302C;
    --border-input: #7A736C;
    --text: #E7E2DC;
    --heading: #FAF7F2;
    --muted: #A8A29E;
    --primary: #D6A642;
    --accent: #E3BE6E;
    --accent-hover: #F0D493;
    --accent-soft: #2E2618;
    --gold-text: #E3B65E;
    --gold-text-hover: #F0CC85;
    --accent-2: #B88A2E;
    --ring: #E3B65E;
    --green: #4ADE80;  --green-soft: #12301F;
    --amber: #FBBF24;  --amber-soft: #2B220F;
    --red: #FCA5A5;    --red-soft: #3B1414;
    --blue: #93C5FD;   --blue-soft: #16213A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-pop: 0 12px 32px rgba(0, 0, 0, .55);
    --on-accent: #1C1917;
    --danger-border: #7F2D2D;
    --placeholder: #8F8881;
    --ring-soft: rgba(227, 182, 94, .25);
    --tab-hover: rgba(255, 255, 255, .06);
    --bubble-bg: #1F3A2B;  --bubble-text: #E2F5D5;
    --step-bg: #221F1C;
    --backdrop: rgba(0, 0, 0, .6);
    --toast-bg: #E7E2DC;   --toast-text: #1C1917;
    --login-tint: #221C14;
    --seg-active: #3D362F;
    --callout-border: #5C4718;  --callout-info-border: #2C3E66;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  font-variant-numeric: lining-nums tabular-nums; /* Raleway defaults to old-style figures */
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold-text); text-decoration: none; font-weight: 600; transition: color var(--ease); }
a:hover { color: var(--gold-text-hover); text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-heading); color: var(--heading); font-weight: 600; font-variant-numeric: lining-nums proportional-nums; } /* Lora's tabular feature widens word spaces */
h1 { font-size: 28px; margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h2 { font-size: 19px; margin: 0 0 var(--space-3); }
h3 { font-size: 16px; margin: 0 0 var(--space-2); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* Visible keyboard focus everywhere (never removed without replacement) */
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
button:focus-visible, .btn:focus-visible, a:focus-visible { border-radius: var(--radius-sm); }

/* layout */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  padding: var(--space-5) var(--space-3); display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 var(--space-3) var(--space-5); border-bottom: 1px solid var(--border); margin-bottom: var(--space-3); }
.brand strong { display: block; font-variant-numeric: lining-nums proportional-nums; font-family: var(--font-heading); font-size: 18px; color: var(--heading); line-height: 1.25; }
.brand span { font-size: 13px; color: var(--muted); }
.app-version { margin-top: var(--space-2); font-size: 12px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; cursor: default; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: var(--space-3); min-height: 40px; padding: 8px var(--space-3); border-radius: var(--radius-sm);
  color: var(--text); font-weight: 500; transition: background-color var(--ease), color var(--ease);
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--gold-text); font-weight: 700; box-shadow: inset 3px 0 0 var(--primary); }
.nav .dot { width: 9px; height: 9px; border-radius: 50%; margin-left: auto; flex-shrink: 0; }
.sidebar .spacer { flex: 1; }
.main { flex: 1; min-width: 0; padding: var(--space-6) 40px 64px; max-width: 1240px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-5); flex-wrap: wrap; }
.page-head .actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--space-5); }
.card + .card { margin-top: var(--space-4); }
.grid { display: grid; gap: var(--space-4); }
.grid > .card { margin-top: 0; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.stat { border-top: 3px solid var(--primary); }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stat .value { font-variant-numeric: lining-nums proportional-nums; font-family: var(--font-heading); color: var(--heading); font-size: 34px; font-weight: 600; margin-top: var(--space-1); line-height: 1.2; }
.stat .sub { color: var(--muted); font-size: 13px; }

/* buttons & inputs */
button, .btn {
  font: inherit; font-size: 15px; font-weight: 600; border: 1px solid var(--border-input); background: var(--surface); color: var(--text);
  min-height: 40px; padding: 8px 16px; border-radius: var(--radius-sm); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  transition: background-color var(--ease), border-color var(--ease), color var(--ease);
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
button:active { transform: translateY(1px); }
a.btn { text-decoration: none; }
a.btn.disabled { opacity: .5; pointer-events: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
button.danger { color: var(--red); border-color: var(--danger-border); }
button.danger:hover { background: var(--red-soft); color: var(--red); }
button.sm { min-height: 32px; padding: 4px 12px; font-size: 13px; }
button.link { border: none; background: none; color: var(--gold-text); padding: 4px; min-height: 0; }
button.link:hover { color: var(--gold-text-hover); text-decoration: underline; background: none; }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text); background: var(--surface); border: 1px solid var(--border-input);
  border-radius: var(--radius-sm); min-height: 40px; padding: 8px 12px; width: 100%;
  transition: border-color var(--ease), box-shadow var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--placeholder); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px var(--ring-soft); }
select { cursor: pointer; }
textarea { resize: vertical; min-height: 110px; }
.field { display: block; margin-bottom: var(--space-4); }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; color: var(--text); }
.field .hint { font-weight: 400; color: var(--muted); font-size: 13px; margin-top: 6px; display: block; }
.row { display: flex; gap: var(--space-3); align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
.inline { display: inline-flex; align-items: center; gap: var(--space-2); }
.inline input, .inline select { width: auto; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--primary); cursor: pointer; }
input[type=file] { padding: 6px; cursor: pointer; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 10px 12px; border-bottom: 2px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable td { transition: background-color var(--ease); }
tr.clickable:hover td { background: var(--accent-soft); }
.phone { white-space: nowrap; }
td .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* badges (always text + color, never color alone) */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.rose { background: var(--accent-soft); color: var(--gold-text); }

.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: var(--radius); width: fit-content; flex-wrap: wrap; }
.tabs button { border: none; background: none; min-height: 34px; padding: 4px 14px; font-size: 14px; font-weight: 600; color: var(--muted); }
.tabs button:hover { color: var(--text); background: var(--tab-hover); }
.tabs button.active { background: var(--seg-active); color: var(--gold-text); box-shadow: var(--shadow); }
.toolbar { display: flex; gap: var(--space-3); align-items: center; margin-bottom: var(--space-4); flex-wrap: wrap; }

.empty { text-align: center; padding: 40px var(--space-4); color: var(--muted); }
.bubble { background: var(--bubble-bg); border-radius: 12px 12px 2px 12px; padding: 10px 12px; white-space: pre-wrap; font-size: 14px; color: var(--bubble-text); max-width: 460px; }
.msg-preview { white-space: pre-wrap; color: var(--muted); font-size: 14px; max-width: 520px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: var(--space-2); }
.chip { font-size: 13px; padding: 4px 10px; min-height: 30px; display: inline-flex; align-items: center; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); color: var(--gold-text); cursor: pointer; font-family: ui-monospace, monospace; transition: border-color var(--ease), color var(--ease); }
.chip:hover { border-color: var(--primary); color: var(--gold-text-hover); }

/* step editor */
.step { border: 1px solid var(--border); border-left: 3px solid var(--accent-2); border-radius: var(--radius-sm); padding: var(--space-4); margin-bottom: var(--space-3); background: var(--step-bg); }
.step .step-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: var(--space-3); align-items: end; }
.step .step-repeat { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-top: var(--space-3); font-size: 14px; }
.step .step-repeat input[type=number] { width: 80px; }
.step .step-repeat select { width: auto; }
.step .step-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-2); font-weight: 700; font-size: 14px; color: var(--heading); }
.step-summary { font-size: 14px; color: var(--muted); }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: var(--backdrop); display: flex; align-items: flex-start; justify-content: center; padding: 48px var(--space-4); overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 580px; box-shadow: var(--shadow-pop); }
.modal.wide { max-width: 840px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px var(--space-5); border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-body { padding: var(--space-5); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); }
.x { border: none; background: none; font-size: 24px; line-height: 1; color: var(--muted); min-width: 40px; min-height: 40px; padding: 0; }
.x:hover { background: var(--surface-2); color: var(--text); }

/* toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; left: auto; display: flex; flex-direction: column; gap: var(--space-2); z-index: 60; }
.toast { background: var(--toast-bg); color: var(--toast-text); padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow-pop); font-size: 14px; max-width: 380px; }
.toast.error { background: #B91C1C; color: #FFFFFF; } /* same in both themes: 6.5:1 */

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-4); background: linear-gradient(160deg, var(--bg) 0%, var(--login-tint) 100%); }
.login .card { width: 100%; max-width: 380px; padding: var(--space-6); border-top: 3px solid var(--primary); }
.login h1 { margin-bottom: var(--space-1); }

/* whatsapp */
.qr-box { display: flex; gap: var(--space-6); align-items: flex-start; flex-wrap: wrap; }
.qr-box img { width: 280px; height: 280px; border-radius: var(--radius); border: 1px solid var(--border); padding: var(--space-2); background: #fff; } /* QR stays dark-on-white in every theme so phones can scan it */
ol.steps { padding-left: 20px; margin: 0; }
ol.steps li { margin-bottom: 6px; }
.callout { background: var(--amber-soft); border: 1px solid var(--callout-border); border-left: 3px solid var(--amber); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); font-size: 14px; }
.callout.info { background: var(--blue-soft); border-color: var(--callout-info-border); border-left-color: var(--blue); }
.callout ul { margin: 6px 0 0; padding-left: 18px; }
.status-line { display: flex; align-items: center; gap: var(--space-2); }
.pulse { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.pulse.green { background: var(--green); }
.pulse.amber { background: var(--amber); }
.pulse.red { background: var(--red); }

.detail-head { display: flex; justify-content: space-between; gap: var(--space-4); align-items: flex-start; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px var(--space-4); font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* language switch */
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) var(--space-3) 0; border-top: 1px solid var(--border); padding-top: var(--space-3); }
.lang-switch { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 2px; flex-shrink: 0; }
.lang-switch button { border: none; background: none; min-height: 32px; padding: 3px 10px; font-size: 13px; font-weight: 700; color: var(--muted); border-radius: 6px; }
.lang-switch button.active { background: var(--seg-active); color: var(--gold-text); box-shadow: var(--shadow); }

/* phone number with country picker */
.phone-row { display: flex; gap: var(--space-2); }
.phone-row select { width: 44%; max-width: 250px; flex-shrink: 0; }
.phone-row input { flex: 1; min-width: 0; }

/* CSV import example */
.csv-example table { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--surface-2); border-radius: var(--radius-sm); }
.csv-example th { text-transform: none; letter-spacing: 0; color: var(--gold-text); font-family: inherit; }
.csv-example td, .csv-example th { padding: 6px 12px; }
.csv-guide { margin: var(--space-3) 0; padding-left: 18px; font-size: 14px; }
.csv-guide li { margin-bottom: 4px; }

/* responsive */
@media (max-width: 1024px) {
  .main { padding: var(--space-5) var(--space-5) 56px; }
}
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .step .step-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 10; flex-direction: row; align-items: center; overflow-x: auto; padding: var(--space-2) var(--space-3); border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar .spacer { display: none; }
  .brand { padding: 0 var(--space-3) 0 0; margin: 0; border: none; display: flex; align-items: center; flex-shrink: 0; }
  .brand strong, .brand span { display: none; }
  .app-version { margin: 0; white-space: nowrap; }
  .nav { flex-direction: row; gap: 2px; }
  .nav a { white-space: nowrap; }
  .nav a.active { box-shadow: inset 0 -3px 0 var(--primary); }
  .main { padding: var(--space-5) var(--space-4) 48px; }
  h1 { font-size: 24px; }
  .sidebar-foot { padding: 0 0 0 var(--space-2); border: none; }
  .sidebar-foot .link { display: none; }
  #toast-root { left: 16px; right: 16px; bottom: 16px; }
  .toast { max-width: none; }
  .phone-row { flex-direction: column; }
  .phone-row select { width: 100%; max-width: none; }
  .modal-backdrop { padding: var(--space-4) var(--space-2); }
}
/* Larger touch targets on touch screens */
@media (pointer: coarse) {
  button, .btn, input, select, .nav a { min-height: 44px; }
  button.sm, .tabs button, .lang-switch button { min-height: 40px; }
}
/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  button:active { transform: none; }
}

/* visually hidden but read by screen readers */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* theme switch (Auto / Light / Dark) */
.theme-switch { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 2px; flex-shrink: 0; }
.theme-switch button { border: none; background: none; min-height: 32px; min-width: 34px; padding: 3px 8px; color: var(--muted); border-radius: 6px; }
.theme-switch button svg { width: 16px; height: 16px; display: block; }
.theme-switch button.active { background: var(--seg-active); color: var(--gold-text); box-shadow: var(--shadow); }
.sidebar-foot .switches { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.sidebar-foot { flex-wrap: wrap; row-gap: var(--space-2); }
