:root {
  --navy: #013A71;
  --navy-700: #0A4A86;
  --navy-50: #EAF0F7;
  --navy-100: #D6E2EF;
  --ink: #0F1B2A;
  --g-700: #3B4757;
  --g-600: #546072;
  --g-500: #6E7987;
  --g-400: #97A1AE;
  --g-300: #C6CED8;
  --g-200: #E1E6EC;
  --g-100: #EEF1F5;
  --bg: #F4F6F9;
  --white: #FFFFFF;
  --ok: #1E9A68;
  --warn: #D99A00;
  --bad: #D33F3F;
  --r: 12px;
  --pad: 16px;
  --shadow: 0 1px 2px rgba(15, 27, 42, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Montserrat, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;            /* never a sideways scroll on a phone (clip keeps the sticky tabs working) */
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--navy); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--g-300); border-radius: 9px;
  background: var(--white); color: var(--ink);
  font-weight: 600; font-size: 13px; letter-spacing: .01em;
}
.btn:hover { border-color: var(--g-400); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: var(--white); }
.btn.primary:hover { background: var(--navy-700); }
.btn.quiet { border-color: transparent; background: var(--g-100); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
.btn.wide { width: 100%; }
a.btn { text-decoration: none; }
.btn.link { border: 0; background: none; color: var(--g-600); font-weight: 500; min-height: 32px; }

/* ---------------------------------------------------------------- login */
.login {
  min-height: 100vh; display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh var(--pad) 40px;
  background: linear-gradient(180deg, var(--navy) 0, var(--navy) 260px, var(--bg) 260px);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--white);
  border-radius: 16px; padding: 28px 24px 22px; box-shadow: 0 10px 30px rgba(1, 58, 113, .18);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.mark {
  width: 42px; height: 42px; border-radius: 11px; background: var(--navy); color: var(--white);
  display: grid; place-items: center; font-weight: 700; font-size: 20px;
}
.login-title { font-weight: 700; font-size: 20px; line-height: 1.1; }
.login-sub { color: var(--g-500); font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.login label { display: block; font-size: 12px; font-weight: 600; color: var(--g-600); margin: 0 0 6px; }
.login input {
  width: 100%; height: 46px; padding: 0 14px; margin-bottom: 14px;
  border: 1px solid var(--g-300); border-radius: 10px; background: var(--white); font-size: 16px;
}
.login input:focus, .filters input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px var(--navy-100);
}
#code { letter-spacing: .35em; font-weight: 600; font-size: 20px; text-align: center; }
.login-note { color: var(--g-600); font-size: 13px; margin: 0 0 14px; }
.login-err { color: var(--ink); font-weight: 600; font-size: 13px; min-height: 18px; margin: 10px 0 0; }
.login-err:not(:empty)::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--bad); margin-right: 7px; vertical-align: 1px;
}

/* ---------------------------------------------------------------- header */
.top { background: var(--navy); color: var(--white); padding: 0 var(--pad); padding-top: env(safe-area-inset-top); }
.top-inner { max-width: 980px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; height: 54px; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: .01em; }
.brand-sub { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: rgba(255, 255, 255, .7); }
.refresh {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .06); color: rgba(255, 255, 255, .9); border-radius: 999px;
  padding: 5px 11px; font-size: 12px; font-weight: 500;
}
.refresh.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.modes { max-width: 980px; margin: 0 auto; display: flex; gap: 6px; flex-wrap: wrap; padding: 0 0 12px; }
.mode {
  font-size: 11px; font-weight: 600; letter-spacing: .03em; padding: 3px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, .1); color: rgba(255, 255, 255, .85);
}
.mode b { color: var(--white); font-weight: 700; }
.mode.hot { background: var(--white); color: var(--navy); }
.mode.hot b { color: var(--navy); }

/* ---------------------------------------------------------------- today */
.today { max-width: 980px; margin: 0 auto; padding: 14px var(--pad) 4px; }
.today-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.today h2 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--g-600); }
.today-date { font-size: 12px; color: var(--g-500); }
.stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--white); border: 1px solid var(--g-200); border-radius: var(--r); box-shadow: var(--shadow);
  overflow: hidden;
}
.stat { padding: 11px 10px 10px; border-right: 1px solid var(--g-100); border-bottom: 1px solid var(--g-100); min-width: 0; }
.stat:nth-child(4n) { border-right: 0; }
.stat:nth-last-child(-n+4) { border-bottom: 0; }
.stat .n { font-size: 22px; font-weight: 700; line-height: 1.1; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat .n small { font-size: 12px; font-weight: 600; color: var(--g-500); margin-left: 2px; }
.stat .l { font-size: 10.5px; font-weight: 600; color: var(--g-500); letter-spacing: .04em; text-transform: uppercase; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .s { font-size: 11px; color: var(--g-500); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.flag .n { color: var(--navy); }
.warnings { margin-top: 8px; font-size: 12px; color: var(--g-600); }
.warnings div::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); margin-right: 7px; vertical-align: 1px; }

/* ---------------------------------------------------------------- tabs */
.tabs {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  max-width: 980px; margin: 0 auto; padding: 8px var(--pad) 0; border-bottom: 1px solid var(--g-200);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; border: 0; background: none; padding: 10px 10px 11px; font-size: 13px; font-weight: 600;
  color: var(--g-500); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button.on { color: var(--navy); border-bottom-color: var(--navy); }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px;
  background: var(--navy); color: var(--white); font-size: 10.5px; line-height: 18px; text-align: center; font-weight: 700;
}
.badge:empty { display: none; }

main { max-width: 980px; margin: 0 auto; padding: 14px var(--pad) 90px; }

/* ---------------------------------------------------------------- filters */
.filters { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 12px; }
.filters > * { min-width: 0; }
.seg { display: flex; background: var(--g-100); border-radius: 10px; padding: 3px; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.seg button {
  flex: 1 0 auto; border: 0; background: none; border-radius: 8px; padding: 7px 10px;
  font-size: 12.5px; font-weight: 600; color: var(--g-600); white-space: nowrap;
}
.seg button.on { background: var(--white); color: var(--navy); box-shadow: 0 1px 2px rgba(15, 27, 42, .12); }
.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-row input[type=search] {
  flex: 1 1 0; width: 0; min-width: 0; height: 40px; padding: 0 12px; border: 1px solid var(--g-300); border-radius: 9px;
  background: var(--white); font-size: 16px;   /* 16px: iPhone Safari doesn't zoom in on focus */
}
.filter-row select { flex: none; height: 40px; border: 1px solid var(--g-300); border-radius: 9px; background: var(--white); padding: 0 6px; font-size: 16px; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--g-600); white-space: nowrap; }
.check input { accent-color: var(--navy); width: 16px; height: 16px; }

/* ---------------------------------------------------------------- lists + items */
.list { background: var(--white); border: 1px solid var(--g-200); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.list:empty { display: none; }
.item { border-bottom: 1px solid var(--g-100); }
.item:last-child { border-bottom: 0; }
.item-head { display: flex; gap: 11px; padding: 12px 14px; cursor: pointer; align-items: flex-start; }
.item-head:hover { background: #FAFBFC; }
.item.open > .item-head { background: var(--navy-50); }
.ico {
  flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--navy-50); color: var(--navy); position: relative;
}
.ico svg { width: 17px; height: 17px; }
.ico .dir {
  position: absolute; right: -3px; bottom: -3px; width: 15px; height: 15px; border-radius: 50%;
  background: var(--white); border: 1px solid var(--g-200); display: grid; place-items: center; color: var(--g-600);
}
.ico .dir svg { width: 9px; height: 9px; }
.item.muted .ico { background: var(--g-100); color: var(--g-500); }
.item.muted .who, .item.muted .sum { color: var(--g-500); }
.item-main { flex: 1; min-width: 0; }
.row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.who { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .lp { font-weight: 500; color: var(--g-500); font-size: 12.5px; margin-left: 4px; }
.when { flex: none; font-size: 12px; color: var(--g-500); font-variant-numeric: tabular-nums; }
.row2 { font-size: 12.5px; color: var(--g-600); margin-top: 1px; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.row2 .what { font-weight: 600; color: var(--g-700); }
.sum { font-size: 13px; color: var(--g-700); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chip {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
  background: var(--g-100); color: var(--g-600); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.chip.navy { background: var(--navy-50); color: var(--navy); }
.chip.solid { background: var(--navy); color: var(--white); }
.chip.test { background: transparent; border: 1px solid var(--g-300); color: var(--g-500); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad, .dot.alert { background: var(--bad); }

.item-body { padding: 4px 14px 16px 59px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; margin: 6px 0 10px; }
.kv dt { color: var(--g-500); font-weight: 600; font-size: 12px; }
.kv dd { margin: 0; color: var(--ink); word-break: break-word; }
.quote { background: var(--g-100); border-radius: 10px; padding: 9px 12px; font-size: 13px; margin: 6px 0; white-space: pre-wrap; word-break: break-word; }
.label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--g-500); margin: 12px 0 4px; }
.muted-text { color: var(--g-500); font-size: 12.5px; }
audio { width: 100%; margin: 6px 0 10px; height: 40px; }

.convo { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.turn { max-width: 88%; padding: 8px 11px; border-radius: 12px; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.turn .t { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; margin-bottom: 2px; opacity: .7; }
.turn.gregory { align-self: flex-start; background: var(--navy-50); color: var(--ink); border-bottom-left-radius: 4px; }
.turn.caller { align-self: flex-end; background: var(--white); border: 1px solid var(--g-200); border-bottom-right-radius: 4px; }
.turn .tool { display: block; margin-top: 4px; font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--g-600); white-space: pre-wrap; word-break: break-all; }
.bubble-in { align-self: flex-start; background: var(--g-100); }
.bubble-out { align-self: flex-end; background: var(--navy); color: var(--white); }
.bubble-in, .bubble-out { max-width: 85%; padding: 8px 11px; border-radius: 12px; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.bubble-out .t, .bubble-in .t { display: block; font-size: 10.5px; opacity: .7; margin-top: 3px; }

.empty { text-align: center; color: var(--g-500); padding: 30px 10px; font-size: 13px; }

/* ---------------------------------------------------------------- cards (morning, replies, callbacks) */
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 2px 8px; }
.section-title:first-child { margin-top: 2px; }
.section-title h3 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--g-600); }
.section-title .aside { font-size: 12px; color: var(--g-500); }
.card { background: var(--white); border: 1px solid var(--g-200); border-radius: var(--r); padding: 13px 14px; margin-bottom: 8px; box-shadow: var(--shadow); }
.card.alert { border-color: var(--navy-100); background: linear-gradient(90deg, var(--navy-50), var(--white) 70%); box-shadow: inset 3px 0 0 var(--navy); }
.card.dim { opacity: .72; }
.card-head { display: flex; gap: 10px; align-items: flex-start; }
.card-head .check input { margin-top: 2px; }
.card-title { font-weight: 700; font-size: 14px; }
.card-title .lp { font-weight: 500; color: var(--g-500); font-size: 12.5px; }
.card-meta { font-size: 12.5px; color: var(--g-600); display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; margin-top: 3px; }
.card-text { font-size: 13px; margin-top: 8px; color: var(--g-700); word-break: break-word; }
.card-text b { color: var(--ink); font-weight: 600; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.card-actions .grow { flex: 1; }
.info {
  background: var(--white); border: 1px dashed var(--g-300); border-radius: var(--r); padding: 12px 14px;
  font-size: 13px; color: var(--g-600); margin-bottom: 12px;
}
.bar {
  position: sticky; bottom: 0; z-index: 4; display: flex; gap: 8px; padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(244, 246, 249, 0), var(--bg) 30%);
}
.bar .btn { flex: 1; min-height: 44px; }
textarea {
  width: 100%; min-height: 88px; resize: vertical; border: 1px solid var(--g-300); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; line-height: 1.45; background: var(--white); margin-top: 8px;
}
.count { font-size: 11.5px; color: var(--g-500); text-align: right; margin-top: 3px; }
.fact { font-size: 12.5px; margin-top: 8px; display: flex; gap: 7px; align-items: flex-start; color: var(--g-700); }
.fact .dot { margin-top: 5px; }

/* ---------------------------------------------------------------- health + controls */
.health-list { background: var(--white); border: 1px solid var(--g-200); border-radius: var(--r); box-shadow: var(--shadow); }
.hrow { display: grid; grid-template-columns: 10px 1fr auto; gap: 4px 12px; padding: 11px 14px; border-bottom: 1px solid var(--g-100); align-items: center; }
.hrow:last-child { border-bottom: 0; }
.hrow .dot { align-self: center; }
.hrow .hl { font-weight: 600; font-size: 13.5px; }
.hrow .hv { font-weight: 700; font-size: 13.5px; text-align: right; font-variant-numeric: tabular-nums; }
.hrow .hn { grid-column: 2 / 4; font-size: 12px; color: var(--g-500); margin-top: -2px; }
.ctl { background: var(--white); border: 1px solid var(--g-200); border-radius: var(--r); padding: 13px 14px; margin-bottom: 8px; box-shadow: var(--shadow); }
.ctl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ctl-name { font-weight: 700; font-size: 14px; }
.ctl-key { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--g-500); }
.ctl-help { font-size: 12.5px; color: var(--g-600); margin: 4px 0 10px; }
.ctl .seg button { text-transform: uppercase; font-size: 12px; letter-spacing: .04em; }
.ctl .seg button.on { background: var(--navy); color: var(--white); }
.ro { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 10px 14px; border-bottom: 1px solid var(--g-100); }
.ro > div { min-width: 0; flex: 1; }
.ro:last-child { border-bottom: 0; }
.ro .ctl-help { margin: 2px 0 0; }
.ro b { font-weight: 700; text-transform: uppercase; text-align: right; max-width: 50%; overflow-wrap: anywhere; }
.stop {
  width: 100%; min-height: 56px; margin: 16px 0 6px; border: 0; border-radius: 12px; background: var(--ink); color: var(--white);
  font-weight: 700; font-size: 15px; letter-spacing: .06em; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.stop:hover { background: #1C2B3E; }
.stop .sq { width: 14px; height: 14px; background: var(--white); border-radius: 2px; }
.stop-note { font-size: 12px; color: var(--g-500); text-align: center; margin: 0 0 14px; }
.audit { font-size: 12.5px; }
.audit .arow { padding: 8px 14px; border-bottom: 1px solid var(--g-100); display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.audit .arow:last-child { border-bottom: 0; }
.audit .at { color: var(--g-500); font-variant-numeric: tabular-nums; white-space: nowrap; }
.audit .ad { color: var(--g-600); grid-column: 2; word-break: break-word; }
.signout { margin-top: 18px; text-align: center; font-size: 12.5px; color: var(--g-500); }

/* ---------------------------------------------------------------- modal + toast */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15, 27, 42, .45); display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.modal-card { width: 100%; max-width: 420px; background: var(--white); border-radius: 16px; padding: 20px 18px 16px; box-shadow: 0 20px 50px rgba(15, 27, 42, .3); margin-bottom: env(safe-area-inset-bottom); }
.modal-card h3 { margin: 0 0 8px; font-size: 17px; }
#modal-body { font-size: 13.5px; color: var(--g-700); }
#modal-body p { margin: 0 0 10px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1; min-height: 44px; }
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--white); padding: 10px 16px; border-radius: 999px; font-size: 13px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(15, 27, 42, .25); max-width: calc(100% - 32px);
}

@media (min-width: 720px) {
  .stats { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .stat { border-bottom: 0; }
  .stat:nth-child(4n) { border-right: 1px solid var(--g-100); }
  .stat:last-child { border-right: 0; }
  .modal { align-items: center; }
  .filters { grid-template-columns: auto 1fr; align-items: center; }
  .tabs button { padding: 11px 14px 12px; }
}
@media (max-width: 360px) {
  .stat .n { font-size: 19px; }
  .stat .l { font-size: 9.5px; }
}
