/* Clinic portal (P7). Deep teal for the clinic's frame, marigold only for "needs you",
   green for confirmed, red only for emergencies. System fonts with Telugu and Devanagari
   fallbacks so transcripts render; no web fonts (nothing leaves our server). */

:root {
  --ink: #0f4a52;
  --ink-deep: #0a363c;
  --on-ink: #f2f8f8;
  --on-ink-soft: #b9d3d6;
  --page: #f3f6f6;
  --surface: #ffffff;
  --line: #d9e3e3;
  --text: #16262a;
  --muted: #5a6e72;
  --link: #0f5f69;
  --marigold: #d98a12;
  --marigold-text: #8a5200;
  --marigold-soft: #fdf0d9;
  --go: #1f7a4d;
  --go-soft: #e1f2e8;
  --alarm: #b8322a;
  --alarm-soft: #fbe6e3;
  --mail: #3b5b86;
  --mail-soft: #e6edf7;
  --quiet-soft: #eef2f2;
  --focus: #e3a21a;
  --radius: 12px;
  --radius-sm: 7px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Telugu",
    "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #0c3a40;
    --ink-deep: #082a2f;
    --on-ink: #e6f2f2;
    --on-ink-soft: #9cbfc3;
    --page: #0d1a1c;
    --surface: #13252a;
    --line: #263d42;
    --text: #e3eded;
    --muted: #97adb0;
    --link: #7fcbd3;
    --marigold: #f0ac3c;
    --marigold-text: #f6c470;
    --marigold-soft: #3a2c12;
    --go: #4fbf86;
    --go-soft: #173427;
    --alarm: #f07468;
    --alarm-soft: #3b1d1a;
    --mail: #8fb0dc;
    --mail-soft: #1c2a3d;
    --quiet-soft: #1b3035;
    color-scheme: dark;
  }
}

*,
*::before,
*::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 16px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}

a { color: var(--link); text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.6rem; line-height: 1.2; font-weight: 680; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin-top: 0.2rem; }
.sr, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 50; background: var(--surface); padding: 8px 12px; }

/* ---------- frame ---------- */

.top { background: var(--ink); color: var(--on-ink); }
.top-inner {
  max-width: 1180px; margin: 0 auto; padding: 0.8rem 1rem 0.4rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand {
  color: var(--on-ink); font-weight: 700; font-size: 1.12rem; text-decoration: none; margin-right: auto;
  min-width: 0; overflow-wrap: anywhere;
}
.on-call { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.on-call a { color: var(--on-ink); }
.pulse {
  width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--marigold);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--marigold) 70%, transparent);
  animation: pulse 1.6s ease-out infinite;
}
@keyframes pulse { to { box-shadow: 0 0 0 0.7rem transparent; } }
.signout { display: flex; align-items: center; gap: 0.75rem; font-size: 0.875rem; color: var(--on-ink-soft); }
.linkish { background: none; border: 0; color: var(--on-ink); font: inherit; text-decoration: underline; cursor: pointer; padding: 0; }

.tabs { max-width: 1180px; margin: 0 auto; padding: 0 0.6rem; display: flex; gap: 0.2rem; }
.tabs a {
  color: var(--on-ink-soft); text-decoration: none; font-weight: 600; padding: 0.65rem 0.75rem 0.7rem;
  border-bottom: 3px solid transparent; display: inline-flex; align-items: center; gap: 0.4rem;
}
.tabs a:hover { color: var(--on-ink); }
.tabs a[aria-current="page"] { color: var(--on-ink); border-bottom-color: var(--marigold); }
.count {
  min-width: 1.35rem; height: 1.35rem; padding: 0 0.35rem; border-radius: 999px;
  background: var(--marigold); color: #241600; font-size: 0.75rem; font-weight: 750;
  display: inline-grid; place-items: center;
}
.count[hidden] { display: none; }

.page { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.crumb { margin-bottom: 0.6rem; font-size: 0.9rem; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.15rem 1.2rem; margin-bottom: 1rem;
}
.panel > h2 { margin-bottom: 0.6rem; }
.panel > .hint { margin: -0.35rem 0 0.8rem; }
.empty { color: var(--muted); }

/* ---------- today ---------- */

.lede { margin: 0.4rem 0 1.6rem; }
.lede .date { color: var(--muted); font-weight: 600; margin-bottom: 0.35rem; }
.lede h1 {
  font-size: clamp(1.55rem, 1.05rem + 2.2vw, 2.55rem); line-height: 1.22; font-weight: 600;
  max-width: 34ch; letter-spacing: -0.02em; overflow-wrap: break-word;
}
.lede h1 a { color: inherit; text-decoration-color: var(--marigold); text-decoration-thickness: 0.12em; }
.lede .n { font-weight: 780; }
.alarm {
  margin-top: 1rem; background: var(--alarm-soft); color: var(--alarm); border-left: 4px solid var(--alarm);
  padding: 0.7rem 0.9rem; border-radius: var(--radius-sm); font-weight: 600; max-width: 60rem;
  margin-bottom: 1rem;
}
.alarm a { color: inherit; }
.alarm[hidden] { display: none; }

.today-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 1rem; align-items: start; }

.feed { list-style: none; margin: 0.4rem 0 0; padding: 0 0 0 0.35rem; position: relative; }
.feed::before { content: ""; position: absolute; left: 0.67rem; top: 0.4rem; bottom: 0.4rem; width: 2px; background: var(--line); }
.ev { display: flex; gap: 0.85rem; padding: 0.55rem 0.5rem 0.65rem 0; position: relative; border-radius: var(--radius-sm); }
.ev-dot {
  flex: none; width: 0.7rem; height: 0.7rem; margin-top: 0.42rem; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--muted); position: relative; z-index: 1;
}
.ev-call .ev-dot { border-color: var(--ink); background: var(--ink); }
.ev-live .ev-dot { border-color: var(--marigold); background: var(--marigold); animation: pulse 1.6s ease-out infinite; }
.ev-appointment .ev-dot { border-color: var(--marigold); }
.ev-message .ev-dot { border-color: var(--link); }
.ev-emergency .ev-dot { border-color: var(--alarm); background: var(--alarm); }
.ev-whatsapp .ev-dot { border-color: var(--go); }
.ev-email .ev-dot { border-color: var(--mail); }
.ev-body { min-width: 0; }
.ev-meta { font-size: 0.8rem; color: var(--muted); display: flex; gap: 0.45rem; align-items: center; flex-wrap: wrap; }
.ev-title { font-weight: 620; color: var(--text); text-decoration: none; }
a.ev-title:hover { text-decoration: underline; }
.ev-detail { color: var(--muted); font-size: 0.92rem; overflow-wrap: anywhere; }
/* Alerts sit under the call they belong to: one quiet line each. */
.ev-whatsapp, .ev-email { padding-top: 0.15rem; padding-bottom: 0.2rem; }
.ev-whatsapp .ev-dot, .ev-email .ev-dot { width: 0.5rem; height: 0.5rem; margin: 0.5rem 0.1rem 0 0.1rem; }
.ev-whatsapp .ev-body, .ev-email .ev-body { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.5rem; }
.ev-whatsapp .ev-title, .ev-email .ev-title { font-weight: 500; font-size: 0.9rem; color: var(--muted); order: 2; }
.ev-whatsapp .ev-meta, .ev-email .ev-meta { order: 1; }
.ev.fresh { animation: arrive 2.4s ease-out; }
@keyframes arrive { from { background: var(--marigold-soft); } to { background: transparent; } }

/* ---------- badges, pills ---------- */

.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 650; line-height: 1.5; padding: 0 0.5rem;
  border-radius: 999px; background: var(--quiet-soft); color: var(--muted); white-space: nowrap;
}
.o-emergency, .k-emergency { background: var(--alarm-soft); color: var(--alarm); }
.o-appointment, .k-appointment { background: var(--marigold-soft); color: var(--marigold-text); }
.o-message, .k-message { background: color-mix(in srgb, var(--link) 14%, transparent); color: var(--link); }
.o-question_answered, .k-call { background: color-mix(in srgb, var(--ink) 12%, transparent); color: var(--text); }
.k-live { background: var(--marigold); color: #241600; }
.k-whatsapp { background: var(--go-soft); color: var(--go); }
.k-email { background: var(--mail-soft); color: var(--mail); }
.sample {
  font-size: 0.7rem; font-weight: 650; padding: 0 0.4rem; border-radius: 4px;
  border: 1px dashed var(--muted); color: var(--muted); white-space: nowrap;
}

.pill { display: inline-block; font-size: 0.75rem; font-weight: 650; padding: 0 0.45rem; border-radius: 5px; white-space: nowrap; }
.s-requested { background: var(--marigold-soft); color: var(--marigold-text); }
.s-confirmed, .s-done { background: var(--go-soft); color: var(--go); }
.s-declined, .s-cancelled, .s-no_show { background: var(--quiet-soft); color: var(--muted); }
.w-sent { background: var(--quiet-soft); color: var(--muted); }
.w-delivered, .w-read { background: var(--go-soft); color: var(--go); }
.w-failed { background: var(--alarm-soft); color: var(--alarm); }

/* ---------- buttons, forms ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: 2.5rem;
  padding: 0.45rem 1rem; border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 650;
  cursor: pointer; text-decoration: none;
}
.btn-go { background: var(--go); color: #fff; }
.btn-go:hover { filter: brightness(1.08); }
.btn-quiet { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-quiet:hover { border-color: var(--muted); }
.btn-wide { width: 100%; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.tel { font-weight: 650; white-space: nowrap; }

.filters { display: flex; align-items: end; gap: 0.6rem; flex-wrap: wrap; font-size: 0.875rem; color: var(--muted); }
.filters label { display: grid; gap: 0.2rem; }
select, input[type="date"], input[type="email"], input[type="password"] {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 9px; padding: 0.5rem 0.65rem; min-height: 2.5rem;
}

.seg { display: inline-flex; background: var(--quiet-soft); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg a { padding: 0.35rem 0.8rem; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.seg a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px color-mix(in srgb, var(--text) 18%, transparent); }

/* ---------- requests ---------- */

.reqs, .plain, .msgs, .calls { list-style: none; margin: 0; padding: 0; }
.req {
  display: flex; justify-content: space-between; gap: 1rem; align-items: center; flex-wrap: wrap;
  padding: 0.85rem 0 0.85rem 0.85rem; border-left: 4px solid var(--marigold); border-top: 1px solid var(--line);
}
.req:first-child { border-top-color: transparent; }
.req-when { font-weight: 700; }
.req-who { font-weight: 600; }
.req-actions { display: flex; gap: 0.5rem; }
.item { padding: 0.7rem 0; border-top: 1px solid var(--line); display: grid; gap: 0.2rem; }
.item:first-child { border-top: 0; padding-top: 0.2rem; }
.item audio { width: 100%; margin-top: 0.3rem; }

/* ---------- calls ---------- */

.calls { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.call-row + .call-row { border-top: 1px solid var(--line); }
.call-row a {
  display: grid; grid-template-columns: 9.5rem minmax(0, 1fr) auto 8rem 5.5rem; gap: 0.25rem 1rem;
  align-items: center; padding: 0.8rem 1rem; color: var(--text); text-decoration: none;
}
.call-row a:hover { background: var(--quiet-soft); }
.call-row.is-live a { background: var(--marigold-soft); }
.c-time, .c-lang, .c-dur { color: var(--muted); font-size: 0.9rem; }
.c-dur { text-align: right; }
.c-who { font-weight: 620; }
.c-sum {
  grid-column: 2 / -1; color: var(--muted); font-size: 0.92rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.facts { display: flex; flex-wrap: wrap; gap: 0.6rem 2rem; margin: 0 0 1rem; }
.facts div { display: grid; }
.facts dt { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.facts dd { margin: 0; font-weight: 600; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 1rem; align-items: start; }
.summary { font-size: 1.05rem; max-width: 62ch; }
.alerts-mini li { padding: 0.35rem 0; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.chat { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.turn { max-width: 86%; padding: 0.55rem 0.8rem 0.65rem; border-radius: 14px; }
.t-bot { background: color-mix(in srgb, var(--ink) 10%, var(--surface)); border-top-left-radius: 4px; }
.t-caller { justify-self: end; background: var(--quiet-soft); border: 1px solid var(--line); border-top-right-radius: 4px; }
.t-who { font-size: 0.78rem; font-weight: 650; color: var(--muted); display: flex; gap: 0.5rem; }
.t-text { overflow-wrap: anywhere; line-height: 1.6; }

/* ---------- calendar ---------- */

.cal-head { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 0.7rem; }
.cal-nav { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.cal-range { font-weight: 650; min-width: 12rem; text-align: center; }
.legend { display: flex; align-items: center; gap: 0.35rem 0.6rem; flex-wrap: wrap; font-size: 0.85rem; margin-bottom: 0.8rem; }
.legend .muted { margin-left: auto; }
.sw { width: 0.85rem; height: 0.85rem; border-radius: 3px; display: inline-block; border: 1px solid var(--line); }
.sw-free { background: var(--surface); }
.sw-some { background: var(--marigold-soft); border-color: var(--marigold); }
.sw-full { background: color-mix(in srgb, var(--ink) 18%, var(--surface)); border-color: var(--ink); }
.sw-leave { background: repeating-linear-gradient(45deg, var(--quiet-soft) 0 3px, var(--line) 3px 6px); }

.cal {
  display: grid; grid-template-columns: repeat(7, minmax(9.5rem, 1fr)); gap: 0.5rem;
  overflow-x: auto; padding-bottom: 0.4rem; scroll-snap-type: x proximity;
}
.cal-day { scroll-snap-align: start; min-width: 0; }
.cal-day h3 {
  font-size: 0.9rem; font-weight: 650; padding: 0.4rem 0.5rem; border-radius: var(--radius-sm);
  display: flex; align-items: baseline; gap: 0.35rem; margin-bottom: 0.4rem; background: var(--quiet-soft);
}
.cal-day h3 .dom { font-size: 1.15rem; }
.cal-day.is-today h3 { background: var(--ink); color: var(--on-ink); }
.closed { color: var(--muted); font-size: 0.875rem; padding: 0.5rem; border: 1px dashed var(--line); border-radius: var(--radius-sm); }
.slots { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; }
.slot {
  border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--radius-sm);
  padding: 0.3rem 0.45rem; font-size: 0.82rem; background: var(--surface);
}
.slot-head { display: flex; justify-content: space-between; gap: 0.3rem; color: var(--muted); }
.slot-head time { font-weight: 650; color: var(--text); }
.cap { font-weight: 650; }
.st-some { border-left-color: var(--marigold); background: var(--marigold-soft); }
.st-full { border-left-color: var(--ink); background: color-mix(in srgb, var(--ink) 9%, var(--surface)); }
.st-leave { background: repeating-linear-gradient(45deg, var(--quiet-soft) 0 4px, transparent 4px 8px); }
.slot.is-past { opacity: 0.55; }
.booking { margin-top: 0.2rem; font-weight: 600; overflow-wrap: anywhere; display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; }
.b-declined, .b-cancelled { text-decoration: line-through; color: var(--muted); font-weight: 500; }

/* ---------- messages ---------- */

.msgs { display: grid; gap: 0.6rem; margin-bottom: 1.2rem; }
.msg {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--link);
  border-radius: var(--radius); padding: 0.9rem 1rem;
}
.msg.is-urgent { border-left-color: var(--alarm); }
.msg.is-done { opacity: 0.65; border-left-color: var(--line); }
.msg-main { display: grid; gap: 0.15rem; min-width: 0; }
.msg-meta { font-size: 0.8rem; color: var(--muted); display: flex; gap: 0.45rem; align-items: center; flex-wrap: wrap; }
.msg-who { font-weight: 650; }
.msg-text { max-width: 70ch; overflow-wrap: anywhere; }
.msg-links { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.2rem; }

/* ---------- alerts table ---------- */

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-top: 0.8rem; }
.table th { text-align: left; font-size: 0.8rem; color: var(--muted); font-weight: 650; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line); }
.table td { padding: 0.6rem 0.8rem; border-top: 1px solid var(--line); vertical-align: middle; }
.table tr:first-child td { border-top: 0; }

/* ---------- toasts ---------- */

.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 40; display: grid; gap: 0.5rem; width: min(24rem, calc(100vw - 2rem)); }
.toast {
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-left: 5px solid var(--marigold);
  border-radius: var(--radius); padding: 0.7rem 0.9rem; box-shadow: 0 8px 24px color-mix(in srgb, #000 22%, transparent);
  animation: toast-in 0.3s ease-out;
}
.toast.k-emergency { border-left-color: var(--alarm); }
.toast.k-whatsapp { border-left-color: var(--go); }
.toast.k-email { border-left-color: var(--mail); }
.toast strong { display: block; }
.toast a { color: inherit; text-decoration: none; }
@keyframes toast-in { from { transform: translateY(0.6rem); opacity: 0; } }

/* ---------- login ---------- */

.login-body { background: var(--ink); min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login {
  background: var(--surface); border-radius: 16px; padding: 2rem 1.6rem; width: min(25rem, 100%);
  box-shadow: 0 20px 50px color-mix(in srgb, #000 35%, transparent);
}
.login h1 { font-size: 1.5rem; }
.login-lede { color: var(--muted); margin: 0.4rem 0 1.3rem; }
.login-form { display: grid; gap: 0.9rem; margin-bottom: 1rem; }
.login-form label { display: grid; gap: 0.3rem; font-weight: 600; font-size: 0.9rem; }
.form-error { background: var(--alarm-soft); color: var(--alarm); padding: 0.6rem 0.8rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-weight: 600; }

/* ---------- small screens ---------- */

@media (max-width: 860px) {
  .today-grid, .detail-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
  .who { display: none; }
  .page { padding-bottom: 6rem; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--ink-deep);
    padding: 0 0 env(safe-area-inset-bottom); justify-content: space-around; gap: 0;
    border-top: 1px solid color-mix(in srgb, var(--on-ink) 15%, transparent);
  }
  .tabs a { flex: 1; justify-content: center; font-size: 0.78rem; padding: 0.75rem 0.2rem; border-bottom: 0; border-top: 3px solid transparent; position: relative; }
  .tabs a[aria-current="page"] { border-top-color: var(--marigold); }
  .tabs .count { position: absolute; top: 0.2rem; right: 0.3rem; min-width: 1.15rem; height: 1.15rem; font-size: 0.68rem; }
  .toasts { bottom: 4.6rem; }
  .call-row a { grid-template-columns: minmax(0, 1fr) auto; }
  .c-time { grid-column: 1; }
  .c-out { grid-column: 2; grid-row: 1; justify-self: end; }
  .c-who { grid-column: 1 / -1; }
  .c-lang, .c-dur { font-size: 0.82rem; }
  .c-dur { text-align: right; }
  .c-sum { grid-column: 1 / -1; }
  .req { padding-left: 0.7rem; }
  .req-actions, .req-actions form, .req-actions .btn { flex: 1; }
  .req-actions .btn { width: 100%; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 0.6rem 0.8rem; border-top: 1px solid var(--line); }
  .table tr:first-child { border-top: 0; }
  .table td { border: 0; padding: 0.1rem 0; }
  .legend .muted { margin-left: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
