/* Watcher app. Tokens first; a phone shows one screen (header, content, tab bar),
   a wide window shows menu, list and chat side by side (.app.wide, below). */
:root {
  --bg: #EDF0F5;
  --surface: #FFFFFF;
  --sunk: #F5F7FA;
  --ink: #141A2A;
  --muted: #586176;
  --line: #D8DDE7;
  --accent: #2747A8;
  --accent-soft: #E3E9FA;
  --on-accent: #FFFFFF;
  --red: #B82A2A;
  --red-soft: #FBE6E5;
  --amber: #9A5B00;
  --amber-soft: #FFF0D3;
  --green: #1D7443;
  --green-soft: #E0F2E7;
  --bubble-in: #ECEFF4;
  --font: -apple-system, "Thonburi", "SF Pro Text", "Leelawadee UI", "Noto Sans Thai", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D1119; --surface: #161B27; --sunk: #1C2231; --ink: #E7EBF3; --muted: #9BA4B9; --line: #2A3143;
    --accent: #8AA4FF; --accent-soft: #1F2A4C; --on-accent: #0D1119;
    --red: #FF8A82; --red-soft: #3A1D1F; --amber: #F2B65A; --amber-soft: #382A12; --green: #67D396; --green-soft: #15301F;
    --bubble-in: #232A3A; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--surface); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.5; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app { height: 100%; display: flex; flex-direction: column; }
.loading { margin: auto; color: var(--muted); }

.top { padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); background: var(--surface); }
.top h1 { font-size: 20px; margin: 0; flex: 1; line-height: 1.25; min-width: 0; overflow-wrap: anywhere; }
.top .sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--sunk); display: grid; place-items: center; flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.banner { padding: 8px 16px; font-size: 14px; font-weight: 600; background: var(--red-soft); color: var(--red); }
.banner.info { background: var(--amber-soft); color: var(--amber); }
.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--surface); }
.content.stale { opacity: .55; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); background: var(--surface); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { border: 0; background: none; padding: 8px 0 8px; font-size: 12px; color: var(--muted); display: grid; justify-items: center; gap: 2px; min-height: 56px; position: relative; }
.tabs button svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--accent); font-weight: 600; }
.badge { position: absolute; top: 4px; left: calc(50% + 6px); background: var(--red); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; font-weight: 600; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 16px; }
.tile { border-radius: 14px; padding: 8px 10px; background: var(--sunk); display: grid; }
.tile b { font-size: 24px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile span { font-size: 12px; color: var(--muted); }
.tile.red b { color: var(--red); } .tile.amber b { color: var(--amber); } .tile.green b { color: var(--green); }
.group { padding: 10px 16px 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.case { display: grid; grid-template-columns: 4px 1fr auto; gap: 0 12px; width: 100%; text-align: left; border: 0; background: none; padding: 12px 16px 12px 0; border-bottom: 1px solid var(--line); }
.case .stripe { border-radius: 0 4px 4px 0; background: var(--amber); grid-row: span 4; }
.case.check .stripe { background: var(--red); }
.case .name { font-weight: 600; overflow-wrap: anywhere; }
.case .meta { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.case .msg { grid-column: 2 / 4; font-size: 15px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.case .why { grid-column: 2 / 4; font-size: 13px; color: var(--red); }
.case .act { grid-column: 2 / 4; margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; padding: 1px 9px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.grey { background: var(--sunk); color: var(--muted); }

.chat { padding: 12px 16px 20px; display: grid; gap: 6px; }
.b { max-width: 84%; padding: 7px 12px; border-radius: 16px; font-size: 15px; overflow-wrap: anywhere; white-space: pre-wrap; }
.b.in { background: var(--bubble-in); justify-self: start; border-bottom-left-radius: 6px; }
.b.out { background: var(--accent); color: var(--on-accent); justify-self: end; border-bottom-right-radius: 6px; }
.b small { display: block; font-size: 11px; opacity: .75; white-space: normal; }
.b.ocr { border: 1px dashed var(--line); }
.b.out.ocr { border-color: transparent; opacity: .85; }
.ocr-block { border: 1px dashed var(--line); border-radius: 14px; padding: 8px 12px; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.ocr-block summary { cursor: pointer; list-style: none; color: var(--ink); }
.ocr-block summary::-webkit-details-marker { display: none; }
.ocr-block small { display: block; font-size: 11px; color: var(--muted); }
.ocr-line { margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--line); }
.ocr-line .side { display: inline-block; min-width: 46px; font-size: 11px; font-weight: 600; color: var(--muted); }
.sys { justify-self: center; font-size: 12px; color: var(--muted); background: var(--sunk); border: 1px dashed var(--line); border-radius: 10px; padding: 2px 10px; text-align: center; }
.panel { margin: 12px 16px 0; border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: grid; gap: 8px; background: var(--sunk); }
.panel h2 { font-size: 15px; margin: 0; }
.panel p { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.panel .note { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 9px 14px; font-weight: 600; font-size: 15px; min-height: 44px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.end { height: calc(env(safe-area-inset-bottom) + 20px); }
.photo-btn { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 8px 14px 8px 8px; font-size: 14px; justify-self: start; margin: 12px 16px 0; }
.photo-btn .thumb { width: 36px; height: 52px; border-radius: 6px; background: var(--accent-soft); border: 1px solid var(--line); }

.lead { padding: 12px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 4px; width: 100%; text-align: left; border-left: 0; border-right: 0; border-top: 0; background: none; }
.lead .hd { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.meter { height: 6px; border-radius: 3px; background: var(--sunk); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--amber); border-radius: 3px; }
.meter i.hot { background: var(--red); }
.lead .reasons { font-size: 13px; color: var(--muted); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 16px; }
.scr { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; gap: 2px; }
.scr b { font-size: 16px; }
.scr span { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.scr.busy { background: var(--accent-soft); border-color: transparent; }
.scr.down { background: var(--red-soft); border-color: transparent; }
.scr.down span { color: var(--red); }
.scr.paused { background: var(--sunk); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.report { margin: 0; padding: 12px 16px 24px; white-space: pre-wrap; font: inherit; font-size: 15px; overflow-wrap: anywhere; }

.login { margin: auto; width: min(100%, 360px); padding: 24px 16px; display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 26px; }
.login p { margin: 0; color: var(--muted); }
.login label { font-size: 14px; font-weight: 600; }
.login input { width: 100%; font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--sunk); color: var(--ink); }
.login .err { color: var(--red); font-size: 14px; min-height: 1.5em; }
.hidden-user { position: absolute; left: -9999px; width: 1px; height: 1px; }

.case[aria-current="true"], .lead[aria-current="true"] { background: var(--accent-soft); }
@media (hover: hover) {
  .case:hover, .lead:hover { background: var(--sunk); }
  .case[aria-current="true"]:hover, .lead[aria-current="true"]:hover { background: var(--accent-soft); }
}

/* Wide windows (computer, iPad across): menu | list | chat. Phones never get here. */
.app.wide { flex-direction: row; background: var(--bg); }
.app.wide .tabs { display: flex; flex-direction: column; gap: 4px; width: 196px; flex: none; padding: 16px 12px; border-top: 0; border-right: 1px solid var(--line); }
.app.wide .brand { font-size: 20px; padding: 2px 12px 14px; }
.app.wide .tabs button { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 8px 12px; border-radius: 10px; font-size: 15px; text-align: left; }
.app.wide .tabs button[aria-current="page"] { background: var(--accent-soft); }
.app.wide .badge { position: static; order: 2; margin-left: auto; }
.app.wide .top { padding-top: 14px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.split { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(320px, 400px) 1fr; }
.single { flex: 1; min-height: 0; display: flex; justify-content: center; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.pane .content { flex: 1; min-height: 0; }
.split .list { border-right: 1px solid var(--line); }
.single .list { width: 100%; max-width: 880px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.pick { margin: auto; }
.app.wide .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.app.wide .b { max-width: min(80%, 620px); }

.viewer { position: fixed; inset: 0; background: rgba(8, 10, 16, .92); display: grid; place-items: center; padding: calc(env(safe-area-inset-top) + 12px) 12px calc(env(safe-area-inset-bottom) + 12px); z-index: 10; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 12px; }
.viewer p { color: #fff; }
