:root {
  --bg: #0b1220; --panel: #131c2e; --panel2: #1a2640; --line: #243252; --text: #eef2f8; --muted: #93a1ba;
  --accent: #fbbf24; --accent-ink: #1a1203; --red: #ff6b6b; --amber: #fbbf24; --green: #4ade80;
  --chip-reno: #7c5a2b; --chip-gc: #1f5d7a; --chip-other: #3a4560;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f9; --panel: #ffffff; --panel2: #eaeef6; --line: #d5dbe8; --text: #101828; --muted: #5a6780;
    --accent: #d97706; --accent-ink: #ffffff; --red: #d92d20; --amber: #b45309; --green: #15803d;
    --chip-reno: #c9894a; --chip-gc: #3b8fb5; --chip-other: #7b87a1;
    color-scheme: light;
  }
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 640px; margin: 0 auto;
  padding-top: env(safe-area-inset-top); }

/* header + controls */
.top { padding: 8px 12px 6px; display: grid; gap: 6px; border-bottom: 1px solid var(--line); background: var(--bg); }
.title-row { display: flex; align-items: center; gap: 8px; }
.title-row h1 { font-size: 19px; margin: 0; flex: 1; letter-spacing: .2px; }
.pill { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); }
.pill.off { background: #5b2020; color: #ffd7d7; }
button.pill { border: 0; font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; }
.pill.ok { background: #16402a; color: #c9f5d9; }
.pill.warn { background: #4a3b10; color: #ffe8a6; }
.icon-btn { min-width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 20px; }
.search { width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 0 12px; }
.chips { display: flex; gap: 6px; }
.chipbtn { flex: 1; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; }
.chipbtn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.selects { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
select { height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); padding: 0 8px; font-size: 14px; width: 100%; }

.banner { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--panel2); font-size: 13px; color: var(--muted); }
.banner span { flex: 1; }
.banner button { height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; }

/* list */
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 9px 12px; min-height: 62px;
  border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.row:active { background: var(--panel2); }
.row.closed { opacity: .55; }
.r-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.r-name b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; color: #fff; white-space: nowrap; }
.chip.reno_contractor { background: var(--chip-reno); } .chip.young_gc { background: var(--chip-gc); } .chip.other { background: var(--chip-other); }
.chip.ex { background: transparent; color: var(--muted); border: 1px dashed var(--muted); }
.r-next { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; grid-column: 1; }
.r-next.overdue { color: var(--red); font-weight: 700; }
.r-next.today { color: var(--amber); font-weight: 600; }
.r-side { grid-row: 1 / span 2; grid-column: 2; display: flex; flex-direction: column; align-items: flex-end; gap: 0; }
.r-ago { font-size: 12px; color: var(--muted); }
.call { display: inline-flex; align-items: center; min-height: 36px; padding: 0 2px; color: var(--accent); font-size: 14px; text-decoration: none; font-variant-numeric: tabular-nums; font-weight: 600; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }

/* bottom bar */
.bar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; align-items: center;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); pointer-events: none;
  background: linear-gradient(transparent, var(--bg) 55%); }
.bar > * { pointer-events: auto; }
.mic { width: 78px; height: 78px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 34px;
  box-shadow: 0 6px 18px rgba(0,0,0,.45); }
.mic:active { transform: scale(.96); }
.fab { position: absolute; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 30px; line-height: 1; box-shadow: 0 4px 12px rgba(0,0,0,.35); }

/* sheets */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 94dvh; overflow-y: auto; border-radius: 18px 18px 0 0;
  border: 1px solid var(--line); padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 2px 0 8px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.sheet h2 span { flex: 1; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; overflow-x: auto; }
.tab { flex: 1 0 auto; height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; border-color: var(--accent); }
.soon { padding: 28px 12px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.field.full { grid-column: 1 / -1; }
.field input, .field textarea { height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); padding: 0 10px; font-size: 16px; color: var(--text); width: 100%; }
.field select { height: 44px; font-size: 16px; }
.field textarea { height: 84px; padding: 8px 10px; resize: vertical; }
.btns { display: flex; gap: 8px; margin-top: 12px; }
.btn { flex: 1; height: 50px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); flex: 2; }
.btn.danger { color: var(--red); flex: 0 0 auto; padding: 0 14px; }
.btn.small { height: 44px; font-size: 14px; }
.logrow { display: flex; gap: 6px; margin: 10px 0 2px; align-items: center; }
.logrow label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.quick { display: flex; gap: 6px; margin-top: 6px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.tag-new { color: var(--green); } .tag-upd { color: var(--accent); }
.listen { display: flex; align-items: center; gap: 10px; margin: 4px 0 8px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--red); animation: pulse 1s infinite; }
.dot.idle { background: var(--muted); animation: none; }
@keyframes pulse { 50% { opacity: .25; } }
.transcript { width: 100%; min-height: 130px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 10px; font-size: 18px; }
.menu-item { display: block; width: 100%; height: 52px; margin-bottom: 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); text-align: left; padding: 0 14px; font-size: 16px; }
#toast { position: fixed; left: 50%; bottom: calc(120px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--panel2);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 99px; z-index: 30; opacity: 0; pointer-events: none; transition: opacity .2s; font-size: 14px; max-width: 90vw; }
#toast.show { opacity: 1; pointer-events: auto; }
#toast.action { cursor: pointer; background: #1d4ed8; color: #fff; border-color: #1d4ed8; font-weight: 600; }
input.code { font-size: 28px; letter-spacing: 8px; text-align: center; font-family: ui-monospace, monospace; }
.si-note { font-size: 15px; margin: 8px 0; }

/* ---------- SMS thread ---------- */
.r-acts { display: flex; align-items: center; gap: 6px; }
.txt { min-width: 40px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 17px; padding: 0; }
.thread-wrap { display: flex; flex-direction: column; }
.thread { display: flex; flex-direction: column; gap: 6px; min-height: 160px; max-height: calc(94dvh - 260px); overflow-y: auto;
  padding: 4px 2px 8px; -webkit-overflow-scrolling: touch; }
.thread .empty { padding: 28px 12px; }
.bubble { max-width: 82%; padding: 8px 11px 5px; border-radius: 16px; font-size: 16px; line-height: 1.3; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.in { align-self: flex-start; background: var(--panel2); border-bottom-left-radius: 5px; }
.bubble.out { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; }
.bubble.pending { opacity: .7; }
.bubble.failed { background: transparent; color: var(--red); border: 1px solid var(--red); cursor: pointer; }
.b-meta { font-size: 11px; opacity: .75; margin-top: 3px; text-align: right; }
.bubble.in .b-meta { text-align: left; }
.b-ch { font-size: 11px; font-weight: 700; opacity: .7; }
.compose { display: flex; gap: 6px; align-items: flex-end; margin-top: 6px; }
.compose-text { flex: 1; min-height: 50px; max-height: 140px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  padding: 13px 12px; font-size: 16px; color: var(--text); resize: none; line-height: 1.3; }
.btn.compose-mic { flex: 0 0 50px; font-size: 20px; }
.btn.compose-mic.live { background: var(--red); color: #fff; border-color: var(--red); }
.btn.compose-send { flex: 0 0 76px; }
.btn:disabled { opacity: .5; }
