/* ============================================================
   SilaCares FAMILY PORTAL
   Light + dark. Same brand system as the marketing site.
   ============================================================ */

:root, [data-theme="light"] {
  --bg:        #f6f5f1;
  --surface:   #ffffff;
  --surface-2: #fbfaf7;
  --sidebar:   #141833;
  --ink:       #141833;
  --text:      #2a2e44;
  --text-soft: #646b83;
  --text-dim:  #8d93a8;
  --line:      rgba(20,24,51,.10);
  --line-soft: rgba(20,24,51,.06);
  --brass:     #c98b2e;
  --brass-ink: #8f6010;
  --brass-lt:  #e0a94a;
  --brass-tint:#faf3e6;
  --indigo:    #3a4386;
  --indigo-tint:#eceef8;
  --ok:        #3e7c64;
  --ok-tint:   #eaf3ef;
  --warn:      #b9821f;
  --warn-tint: #fdf4e3;
  --danger:    #c0453c;
  --danger-tint:#fdecea;
  --shadow-sm: 0 1px 3px rgba(20,24,51,.05);
  --shadow-md: 0 8px 30px rgba(20,24,51,.08);
  --shadow-lg: 0 24px 64px rgba(20,24,51,.14);
  --radius:    16px;
  --radius-sm: 11px;
}
[data-theme="dark"] {
  --brass-ink: #f0c176;
  --bg:        #0e1124;
  --surface:   #181c36;
  --surface-2: #1f2442;
  --sidebar:   #0a0d1e;
  --ink:       #f3f4fa;
  --text:      #dfe2ee;
  --text-soft: #a3aac4;
  --text-dim:  #7b83a0;
  --line:      rgba(255,255,255,.11);
  --line-soft: rgba(255,255,255,.07);
  --brass:     #e0a94a;
  --brass-lt:  #f0c176;
  --brass-tint:rgba(224,169,74,.13);
  --indigo:    #8b96e8;
  --indigo-tint:rgba(139,150,232,.14);
  --ok:        #63b494;
  --ok-tint:   rgba(99,180,148,.14);
  --warn:      #e2b060;
  --warn-tint: rgba(226,176,96,.14);
  --danger:    #e8776c;
  --danger-tint:rgba(232,119,108,.14);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 8px 30px rgba(0,0,0,.36);
  --shadow-lg: 0 24px 64px rgba(0,0,0,.5);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  transition: background .3s ease, color .3s ease;
}
img, svg { max-width: 100%; display: block; }
a { color: var(--indigo); text-decoration: none; }
h1,h2,h3,h4 { font-family: "Fraunces", Georgia, serif; color: var(--ink); margin: 0 0 .4em; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; }
h1 { font-size: 1.72rem; } h2 { font-size: 1.24rem; } h3 { font-size: 1.02rem; }
p { margin: 0 0 1em; }
:focus-visible { outline: 2px solid var(--indigo); outline-offset: 2px; border-radius: 5px; }
* { min-width: 0; }

/* ============================================================
   SHELL
   ============================================================ */
.shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }

/* mobile nav backdrop — MUST be out of flow at every width, or it
   steals a grid cell and squeezes <main> into the sidebar column */
.scrim { display: none; position: fixed; inset: 0; background: rgba(10,13,30,.5); z-index: 55; }

.sidebar {
  background: var(--sidebar); color: #aab1cc; padding: 22px 16px;
  display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; font-family: "Fraunces", Georgia, serif; font-size: 1.24rem; font-weight: 600; color: #fff; letter-spacing: -.025em; padding: 6px 10px 18px; }
.sidebar .brand svg { width: 30px; height: 30px; flex: none; }
.sidebar .sec { font-size: .66rem; letter-spacing: .16em; text-transform: uppercase; color: #6b7395; margin: 18px 12px 8px; font-weight: 600; }
.sidebar a.nav {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px; color: #aab1cc;
  font-size: .89rem; font-weight: 450; transition: .2s;
}
.sidebar a.nav svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.sidebar a.nav:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar a.nav.active { background: rgba(201,139,46,.16); color: #fff; font-weight: 550; }
.sidebar a.nav.active svg { color: var(--brass-lt); opacity: 1; }
.sidebar .spacer { flex: 1; }
.sidebar .who {
  display: flex; align-items: center; gap: 10px; padding: 12px;
  border-top: 1px solid rgba(255,255,255,.1); margin-top: 10px;
}
.sidebar .who .av { width: 34px; height: 34px; border-radius: 50%; background: var(--brass); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .78rem; flex: none; }
.sidebar .who b { color: #fff; font-size: .84rem; display: block; font-weight: 500; }
.sidebar .who small { color: #7b83a0; font-size: .72rem; }

.main { padding: 26px 32px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.topbar .greet small { color: var(--text-soft); font-size: .86rem; display: block; margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

.menu-btn { display: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; cursor: pointer; }
.menu-btn span { display: block; width: 17px; height: 1.6px; background: var(--ink); margin: 4px 0; border-radius: 2px; }

/* ============================================================
   CONTROLS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 999px; border: 1px solid transparent; cursor: pointer;
  font-family: inherit; font-size: .86rem; font-weight: 550; padding: 10px 19px;
  transition: .22s; white-space: nowrap;
}
.btn-primary { background: var(--ink); color: var(--bg); }
[data-theme="dark"] .btn-primary { background: var(--brass); color: #16182e; }
.btn-primary:hover { opacity: .88; transform: translateY(-1px); }
.btn-accent { background: var(--brass); color: #16182e; font-weight: 600; }

.btn-accent:hover { transform: translateY(-1px); opacity: .92; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--text-soft); }
.btn-sm { padding: 7px 14px; font-size: .79rem; }
.btn svg { width: 15px; height: 15px; flex: none; }

.theme-toggle {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 10px; cursor: pointer; color: var(--text); display: inline-flex; align-items: center; gap: 7px;
  font-size: .8rem; font-family: inherit; font-weight: 500;
}
.theme-toggle svg { width: 15px; height: 15px; }

.select, select.select, input.inp, textarea.inp {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 13px; font-family: inherit; font-size: .85rem; color: var(--text);
  -webkit-appearance: none; appearance: none; width: 100%;
}
select.select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888fa6' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; background-size: 14px; padding-right: 34px; }
.inp:focus, .select:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-tint); }
label.lbl { display: block; font-size: .79rem; font-weight: 550; color: var(--text-soft); margin-bottom: 6px; }
.field { margin-bottom: 16px; }

/* person switcher */
.person-switch { display: flex; gap: 7px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px; }
.person-switch button {
  display: inline-flex; align-items: center; gap: 8px; border: 0; background: transparent; cursor: pointer;
  border-radius: 999px; padding: 6px 14px 6px 6px; font-family: inherit; font-size: .83rem; color: var(--text-soft); font-weight: 500;
}
.person-switch button img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.person-switch button.on { background: var(--ink); color: var(--bg); }
[data-theme="dark"] .person-switch button.on { background: var(--brass); color: #16182e; }

/* ============================================================
   CARDS & LAYOUT
   ============================================================ */
.card { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow-sm); }
.card > h3 { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.card .sub { color: var(--text-soft); font-size: .81rem; margin: 0 0 16px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-2 { grid-template-columns: 1fr 2fr; }
.mb { margin-bottom: 16px; }

/* stat tiles */
.tile { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); display: flex; gap: 14px; align-items: flex-start; }
.tile .ico { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex: none; }
.tile .ico svg { width: 19px; height: 19px; }
.tile .ico.ok { background: var(--ok-tint); color: var(--ok); }
.tile .ico.br { background: var(--brass-tint); color: var(--brass-ink); }
.tile .ico.in { background: var(--indigo-tint); color: var(--indigo); }
.tile .ico.dg { background: var(--danger-tint); color: var(--danger); }
.tile .n { font-family: "Fraunces", Georgia, serif; font-size: 1.72rem; color: var(--ink); line-height: 1.1; letter-spacing: -.03em; }
.tile .n small { font-size: .8rem; font-family: inherit; color: var(--text-soft); font-weight: 450; letter-spacing: 0; }
.tile .k { font-size: .78rem; color: var(--text-soft); }
.tile .trend { font-size: .73rem; font-weight: 600; margin-top: 3px; display: inline-block; }
.trend.up { color: var(--ok); } .trend.down { color: var(--danger); } .trend.flat { color: var(--text-dim); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 10px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-tint); color: var(--ok); }
.badge.warn { background: var(--warn-tint); color: var(--warn); }
.badge.dg { background: var(--danger-tint); color: var(--danger); }
.badge.in { background: var(--indigo-tint); color: var(--indigo); }
.badge.br { background: var(--brass-tint); color: var(--brass-ink); }
.badge.mut { background: var(--line-soft); color: var(--text-soft); }

/* lists */
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.row:last-child { border-bottom: 0; }
.row .dot { width: 32px; height: 32px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex: none; font-size: .9rem; }
.row .txt { flex: 1; min-width: 0; }
.row .txt b { display: block; font-size: .87rem; color: var(--ink); font-weight: 550; }
.row .txt small { color: var(--text-soft); font-size: .77rem; }
.row .when { font-size: .75rem; color: var(--text-dim); white-space: nowrap; }

/* timeline */
.tl { position: relative; padding-left: 26px; }
.tl::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 1px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 18px 0; }
.tl-item::before { content: ""; position: absolute; left: -23px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--brass); box-shadow: 0 0 0 3px var(--bg); }
.tl-item.ok::before { background: var(--ok); }
.tl-item.dg::before { background: var(--danger); }
.tl-item .t { font-size: .72rem; color: var(--text-dim); font-weight: 600; letter-spacing: .04em; }
.tl-item b { display: block; font-size: .87rem; color: var(--ink); font-weight: 550; margin-top: 1px; }
.tl-item p { font-size: .8rem; color: var(--text-soft); margin: 2px 0 0; }

/* tables */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .84rem; min-width: 560px; }
table.tbl th { text-align: left; font-weight: 600; color: var(--text-soft); font-size: .73rem; text-transform: uppercase; letter-spacing: .09em; padding: 0 12px 10px; border-bottom: 1px solid var(--line); }
table.tbl td { padding: 12px; border-bottom: 1px solid var(--line-soft); color: var(--text); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl td b { color: var(--ink); font-weight: 550; }

/* charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .76rem; color: var(--text-soft); margin-top: 12px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 6px; }

/* filter bar */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.filters .f { min-width: 145px; flex: 1; }
.filters .f label { display: block; font-size: .71rem; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }

/* voice note */
.vn { display: flex; align-items: center; gap: 11px; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 12px; padding: 11px 13px; }
.vn .play { width: 30px; height: 30px; border-radius: 50%; background: var(--indigo); flex: none; position: relative; border: 0; cursor: pointer; }
.vn .play::after { content: ""; position: absolute; left: 11px; top: 8px; border-left: 9px solid #fff; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.vn .wave { display: flex; align-items: center; gap: 2.5px; height: 24px; flex: 1; }
.vn .wave i { width: 3px; background: var(--text-dim); border-radius: 3px; opacity: .5; }
.vn .len { font-size: .74rem; color: var(--text-dim); }

/* segmented */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; cursor: pointer; font-family: inherit; font-size: .79rem; font-weight: 500; color: var(--text-soft); padding: 6px 14px; border-radius: 999px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); font-weight: 600; }

/* toggle switch */
.tgl { position: relative; width: 44px; height: 25px; background: var(--line); border-radius: 999px; border: 0; cursor: pointer; flex: none; transition: background .25s; }
.tgl::after { content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%; background: #fff; transition: left .25s cubic-bezier(.2,.7,.3,1); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.tgl[aria-checked="true"] { background: var(--brass); }
.tgl[aria-checked="true"]::after { left: 22px; }
.tgl-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.tgl-row:last-child { border-bottom: 0; }
.tgl-row b { display: block; font-size: .87rem; color: var(--ink); font-weight: 550; }
.tgl-row small { color: var(--text-soft); font-size: .78rem; }

/* person card */
.person { display: flex; gap: 14px; align-items: center; }
.person img { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; flex: none; }
.person .av-init { width: 54px; height: 54px; border-radius: 50%; background: var(--indigo-tint); color: var(--indigo); display: flex; align-items: center; justify-content: center; font-weight: 600; flex: none; }
.person b { display: block; color: var(--ink); font-size: .97rem; font-weight: 600; }
.person small { color: var(--text-soft); font-size: .8rem; }

.hr { height: 1px; background: var(--line-soft); border: 0; margin: 20px 0; }
.muted { color: var(--text-soft); }
.tiny { font-size: .76rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* print — doctor report */
@media print {
  .sidebar, .topbar-actions, .menu-btn, .filters, .no-print { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .main { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
}

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

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1180px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g-2-1, .g-1-2, .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 258px; z-index: 60;
    transform: translateX(-100%); transition: transform .3s cubic-bezier(.2,.7,.3,1);
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: block; }
  .main { padding: 18px 18px 50px; }
  .scrim.on { display: block; }
}
@media (max-width: 620px) {
  .g4, .g2 { grid-template-columns: 1fr; }
  h1 { font-size: 1.42rem; }
  .main { padding: 16px 14px 44px; }
  .card { padding: 16px 15px; }
  .filters .f { min-width: 100%; }
  .person-switch { width: 100%; overflow-x: auto; }
}

/* chips (loved-ones editor) */
.chip-row { display: flex; gap: 9px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px; font-size: .84rem; cursor: pointer; background: var(--surface); font-family: inherit; color: var(--text-soft); transition: .18s; }
.chip.selected { border-color: var(--brass); background: var(--brass-tint); color: var(--brass-ink); font-weight: 600; }
