:root {
  --navy: #012563;          /* brand text + accents */
  --navy-dark: #011a47;
  --brand: #012563;         /* filled buttons, avatar, toasts (white text on top) */
  --brand-hover: #011a47;
  --navy-tint: #e8edf6;
  --navy-tint-2: #f3f6fb;
  --ink: #111827;
  --muted: #5b6474;
  --line: #e3e7ee;
  --line-strong: var(--line-strong);
  --bg: #ffffff;
  --surface: #ffffff;       /* cards, menus, inputs */
  --surface-past: #fbfcfd;
  --panel: #f6f7f9;
  --topbar: rgba(255, 255, 255, .92);
  --flash: #fff6cc;
  --backdrop: rgba(1, 26, 71, .28);
  --repcard: #0e7490;
  --repcard-tint: #e0f2f6;
  --kinobi: #b45309;
  --kinobi-tint: #fdf0e1;
  --good: #15803d;
  --good-tint: #e5f5ea;
  --bad: #b91c1c;
  --bad-tint: #fbe9e9;
  --bad-line: #f3c7c7;
  --warn: #a16207;
  --warn-tint: #fdf6dd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(1, 37, 99, .06), 0 4px 14px rgba(1, 37, 99, .06);
  color-scheme: light;
}

/* Dark mode: follows the phone/computer setting unless someone picks Light or Dark in their menu. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --navy: #a8c0f5; --navy-dark: #c5d6fa; --brand: #2f5bc4; --brand-hover: #3a68d6;
    --navy-tint: #1c2945; --navy-tint-2: #172036;
    --ink: #e8ecf4; --muted: #9aa5ba; --line: #283146; --line-strong: #3a4766;
    --bg: #0b0f19; --surface: #131a28; --surface-past: #111724; --panel: #182033;
    --topbar: rgba(11, 15, 25, .9); --flash: #4a3d0c; --backdrop: rgba(0, 0, 0, .55);
    --repcard: #4cc3df; --repcard-tint: #0f2e38; --kinobi: #f2a654; --kinobi-tint: #3a2610;
    --good: #4ade80; --good-tint: #11301f; --bad: #f87171; --bad-tint: #3a1719; --bad-line: #6b2a2d;
    --warn: #facc15; --warn-tint: #352b0b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --navy: #a8c0f5; --navy-dark: #c5d6fa; --brand: #2f5bc4; --brand-hover: #3a68d6;
  --navy-tint: #1c2945; --navy-tint-2: #172036;
  --ink: #e8ecf4; --muted: #9aa5ba; --line: #283146; --line-strong: #3a4766;
  --bg: #0b0f19; --surface: #131a28; --surface-past: #111724; --panel: #182033;
  --topbar: rgba(11, 15, 25, .9); --flash: #4a3d0c; --backdrop: rgba(0, 0, 0, .55);
  --repcard: #4cc3df; --repcard-tint: #0f2e38; --kinobi: #f2a654; --kinobi-tint: #3a2610;
  --good: #4ade80; --good-tint: #11301f; --bad: #f87171; --bad-tint: #3a1719; --bad-line: #6b2a2d;
  --warn: #facc15; --warn-tint: #352b0b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px clamp(16px, 3vw, 32px);
  background: var(--topbar); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { flex: none; border-radius: 50%; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.wordmark {
  color: var(--navy); font-weight: 800; letter-spacing: .32em; font-size: 15px;
  font-stretch: expanded; white-space: nowrap;
}
.tagline { color: var(--muted); font-size: 12px; white-space: nowrap; }
.status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.source-chips { display: flex; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); white-space: nowrap;
}
.chip .sw { width: 8px; height: 8px; border-radius: 50%; }
.chip.off { color: var(--muted); }
.chip.err { color: var(--bad); border-color: var(--bad-line); background: var(--bad-tint); }
.live {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600;
  color: var(--muted); padding: 4px 10px; border-radius: 999px; background: var(--panel);
}
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa3b2; }
.live.on { color: var(--good); background: var(--good-tint); }
.live.on .dot { background: var(--good); animation: ping 2s infinite; }
.live.off { color: var(--bad); background: var(--bad-tint); }
.live.off .dot { background: var(--bad); }
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(21, 128, 61, .5); }
  70% { box-shadow: 0 0 0 7px rgba(21, 128, 61, 0); }
  100% { box-shadow: 0 0 0 0 rgba(21, 128, 61, 0); }
}

.banner {
  margin: 12px clamp(16px, 3vw, 32px) 0; padding: 10px 14px; border-radius: var(--radius);
  background: var(--navy-tint); color: var(--navy); font-size: 14px;
}

main { padding: 16px clamp(16px, 3vw, 32px) 48px; max-width: 1500px; margin: 0 auto; }

/* ---------- KPIs */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); text-align: left; cursor: pointer; transition: border-color .15s;
}
.kpi:hover { border-color: var(--line-strong); }
.kpi .label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-size: 30px; font-weight: 750; color: var(--navy); line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .split { display: flex; gap: 10px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.kpi .split span { display: inline-flex; align-items: center; gap: 5px; }
.kpi .split i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.kpi.warn .value { color: var(--warn); }
.kpi.good .value { color: var(--good); }

/* ---------- toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 10px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.nav { display: flex; align-items: center; gap: 6px; flex: 1 1 auto; min-width: 0; }
.range-label { margin: 0 0 0 8px; font-size: 20px; font-weight: 700; color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 7px 12px;
  font-weight: 600; cursor: pointer; color: var(--navy);
}
.btn:hover { background: var(--navy-tint-2); }
a.btn { text-decoration: none; display: inline-block; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-tint); border-color: var(--bad-line); }
.btn.icon { width: 36px; padding: 6px 0; font-size: 20px; line-height: 1; }
.views { display: inline-flex; background: var(--panel); border-radius: 10px; padding: 3px; }
.views button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font-weight: 600;
  color: var(--muted); cursor: pointer;
}
.views button.active { background: var(--surface); color: var(--navy); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input, .filters select {
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; background: var(--surface); min-width: 0;
}
.filters input { width: 230px; }
.filters input:focus, .filters select:focus, .btn:focus-visible, .views button:focus-visible {
  outline: 2px solid var(--navy); outline-offset: 1px;
}

/* ---------- appointment card */
.appt {
  position: relative; display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--src, var(--navy));
  border-radius: 9px; padding: 8px 10px; margin-bottom: 6px; transition: box-shadow .15s, transform .15s;
}
.appt:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.appt .time { font-size: 12px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; white-space: nowrap; flex-shrink: 0; }
.appt .who { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .row { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; }
.appt .row .badge { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.appt.past:not(.flash) { background: var(--surface-past); }
.appt.flash { animation: flash 3s ease-out; }
@keyframes flash {
  0%, 30% { background: var(--flash); box-shadow: 0 0 0 3px rgba(234, 179, 8, .35); }
  100% { background: var(--surface); box-shadow: none; }
}
.src-repcard { --src: var(--repcard); }
.src-kinobi { --src: var(--kinobi); }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  white-space: nowrap; background: var(--panel); color: var(--muted);
}
.badge.signed { background: var(--good-tint); color: var(--good); }
.badge.held { background: var(--navy-tint); color: var(--navy); }
.badge.notheld { background: var(--bad-tint); color: var(--bad); }
.badge.needs { background: var(--warn-tint); color: var(--warn); }
.badge.sched { background: var(--navy-tint-2); color: var(--navy); }
.badge.source-repcard { background: var(--repcard-tint); color: var(--repcard); }
.badge.source-kinobi { background: var(--kinobi-tint); color: var(--kinobi); }

/* ---------- week */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.day-col { background: var(--panel); border-radius: var(--radius); padding: 8px; min-height: 180px; }
.day-col.today { background: var(--navy-tint); box-shadow: inset 0 0 0 2px var(--navy); }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline; padding: 2px 4px 8px; cursor: pointer;
}
.day-head .dname { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.day-head .dnum { font-size: 20px; font-weight: 750; color: var(--navy); margin-left: 4px; }
.day-head .count { font-size: 12px; font-weight: 700; color: var(--navy); background: var(--surface); border-radius: 999px; padding: 1px 8px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 6px; }

/* ---------- day */
.day-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 20px; align-items: start; }
.hour { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; border-top: 1px solid var(--line); padding: 8px 0; }
.hour .h { font-size: 12px; font-weight: 700; color: var(--muted); padding-top: 9px; }
.side { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; }
.side h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; margin-bottom: 8px; font-size: 14px; }
.bar { grid-column: 1 / -1; height: 6px; background: var(--surface); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

/* ---------- month */
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.mhead { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); padding: 0 6px 4px; letter-spacing: .05em; }
.mcell {
  min-height: 96px; background: var(--panel); border-radius: 10px; padding: 6px 8px; cursor: pointer;
  border: 1px solid transparent; text-align: left; display: flex; flex-direction: column; gap: 4px;
}
.mcell:hover { border-color: var(--line-strong); background: var(--surface); }
.mcell.other { opacity: .45; }
.mcell.today { box-shadow: inset 0 0 0 2px var(--navy); background: var(--navy-tint); }
.mcell .n { font-weight: 700; color: var(--navy); font-size: 14px; }
.mcell .total { font-size: 22px; font-weight: 750; color: var(--ink); line-height: 1; font-variant-numeric: tabular-nums; }
.mcell .total small { font-size: 11px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.stack { display: flex; height: 6px; border-radius: 99px; overflow: hidden; background: var(--surface); margin-top: auto; }
.stack i { display: block; height: 100%; }

/* ---------- list */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--panel); position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--navy-tint-2); }
tr.group td { background: var(--surface); font-weight: 700; color: var(--navy); padding-top: 16px; cursor: default; }
tr.flash { animation: flash 3s ease-out; }

/* ---------- drawer */
.drawer { position: fixed; inset: 0; z-index: 40; background: var(--backdrop); display: flex; justify-content: flex-end; }
.drawer-panel {
  position: relative; width: min(440px, 100%); height: 100%; overflow-y: auto; background: var(--surface);
  padding: 24px 24px 40px; box-shadow: -10px 0 30px rgba(1, 37, 99, .15); animation: slide .2s ease-out;
}
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.close { position: absolute; top: 14px; right: 14px; }
.drawer h2 { margin: 10px 0 2px; font-size: 22px; color: var(--navy); padding-right: 40px; }
.drawer .when { font-weight: 600; margin-bottom: 14px; }
.drawer dl { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 10px 12px; margin: 16px 0 0; font-size: 14px; }
.drawer dt { color: var(--muted); font-weight: 600; }
.drawer dd { margin: 0; overflow-wrap: anywhere; }
.drawer a { color: var(--navy); }
.drawer .notes { margin-top: 16px; background: var(--panel); border-radius: 10px; padding: 12px 14px; white-space: pre-wrap; font-size: 14px; }

/* ---------- toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px)); }
.toast {
  background: var(--brand); color: #fff; border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow);
  font-size: 14px; cursor: pointer; animation: rise .25s ease-out;
}
.toast b { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; opacity: .75; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }

/* ---------- account menu + dialogs */
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 13px;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 240px; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.menu-head { display: grid; gap: 2px; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-head span:not(.badge) { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.menu-head .badge { justify-self: start; margin-top: 4px; text-transform: capitalize; }
.menu a, .menu button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none;
  border-radius: 8px; color: var(--ink); text-decoration: none; cursor: pointer; font-size: 14px;
}
.menu a:hover, .menu button:hover { background: var(--navy-tint-2); }
.dialog { background: var(--surface); color: var(--ink); border: 0; border-radius: 16px; padding: 22px; width: min(400px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(1, 26, 71, .25); }
.dialog::backdrop { background: var(--backdrop); }
.dialog h2 { margin: 0 0 14px; color: var(--navy); font-size: 20px; }
.dialog form { display: grid; gap: 12px; }
.dialog label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.dialog input, .dialog select { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; font-size: 15px; color: var(--ink); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.primary-btn { background: var(--brand); color: #fff; border-color: var(--brand); }
.primary-btn:hover { background: var(--brand-hover); }
.err { color: var(--bad); background: var(--bad-tint); border-radius: 9px; padding: 8px 12px; font-size: 14px; }

/* ---------- responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .day-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .tagline, .source-chips { display: none; }
  .banner { font-size: 13px; padding: 8px 12px; }
  /* summary tiles become one swipeable row */
  .kpis { display: flex; overflow-x: auto; gap: 8px; margin: 0 -16px 12px; padding: 2px 16px 6px; scroll-snap-type: x mandatory; scroll-padding-inline: 16px; scrollbar-width: none; }
  .kpis::-webkit-scrollbar { display: none; }
  .kpi { flex: 0 0 auto; min-width: 128px; padding: 8px 12px; scroll-snap-align: start; box-shadow: none; }
  .kpi .label { font-size: 10.5px; }
  .kpi .value { font-size: 22px; margin-top: 0; }
  .kpi .split { gap: 8px; font-size: 11px; margin-top: 2px; }
  .toolbar { gap: 8px; }
  .nav { flex-basis: 100%; }
  .range-label { font-size: 17px; }
  .views { flex: 1 1 auto; }
  .views button { flex: 1; padding: 6px 4px; }
  .filters { flex-basis: 100%; }
  .filters input { flex: 1 1 100%; width: auto; }
  .filters select { flex: 1 1 30%; min-width: 0; }
  .filters #fPartner, .filters #fOffice { flex: 1 1 45%; }
  .week { grid-template-columns: minmax(0, 1fr); }
  .day-col { min-height: 0; }
  .month { gap: 3px; }
  .mcell { min-height: 58px; padding: 4px 5px; }
  .mcell .total { font-size: 16px; }
  .mcell .total small { display: none; }
  .mhead { padding: 0 2px 2px; font-size: 10px; }
  .hour { grid-template-columns: 48px minmax(0, 1fr); }
}

/* ---------- appearance switch (account menu) */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; background: var(--panel); border-radius: 9px; padding: 3px; margin: 4px 4px 6px; }
.menu .seg button { text-align: center; padding: 6px 4px; font-size: 13px; font-weight: 600; color: var(--muted); border-radius: 7px; }
.menu .seg button[aria-pressed="true"] { background: var(--surface); color: var(--navy); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.menu .label-sm { display: block; padding: 6px 10px 0; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- Face ID */
.faceid-banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.faceid-banner span { flex: 1 1 220px; }
.faceid-banner .btn { padding: 5px 10px; }
.pk-list { display: grid; gap: 8px; margin: 0 0 14px; }
.pk-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.pk-row small { display: block; color: var(--muted); font-size: 12px; }
.dialog p.help { margin: -6px 0 14px; color: var(--muted); font-size: 14px; }
.ok { color: var(--good); background: var(--good-tint); border-radius: 9px; padding: 8px 12px; font-size: 14px; }

/* refresh button */
.btn.refresh { display: inline-grid; place-items: center; }
.btn.refresh.spin svg { animation: rr-spin .8s linear infinite; }
.btn.refresh:disabled { opacity: .7; cursor: default; }
@keyframes rr-spin { to { transform: rotate(360deg); } }
@media (max-width: 760px) {
  .status { flex-wrap: nowrap; gap: 8px; }
  .btn.refresh { width: 34px; height: 34px; padding: 0; }
}
@media (max-width: 430px) {
  .brand { gap: 8px; }
  .brand img { width: 34px; height: 34px; }
  .wordmark { font-size: 14px; letter-spacing: .16em; }
}
