:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1b1f24; --muted: #66707c; --border: #dfe3e8;
  --accent: #0b6bcb; --accent-ink: #ffffff; --ok: #1f7a4d; --warn: #9a5b00; --warn-bg: #fff6e5;
  --bad: #b42318; --bad-bg: #fdecea; --ok-bg: #e8f5ee; --user: #e8f0fb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --surface: #1a1f25; --text: #e6e9ed; --muted: #98a2ae; --border: #2c333b;
    --accent: #4c9be8; --accent-ink: #0b1320; --ok: #5cc28f; --warn: #f0b456; --warn-bg: #2d2412;
    --bad: #f07b72; --bad-bg: #2e1715; --ok-bg: #12261b; --user: #1d2a3a;
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --surface: #1a1f25; --text: #e6e9ed; --muted: #98a2ae; --border: #2c333b;
  --accent: #4c9be8; --accent-ink: #0b1320; --ok: #5cc28f; --warn: #f0b456; --warn-bg: #2d2412;
  --bad: #f07b72; --bad-bg: #2e1715; --ok-bg: #12261b; --user: #1d2a3a;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); padding: 8px 14px; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--accent); }
button.small { padding: 4px 10px; font-size: 13px; margin-top: 8px; }
input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }

.top { display: flex; align-items: center; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.brand { font-weight: 700; font-size: 17px; }
.plan { font-weight: 500; color: var(--muted); margin-left: 6px; }
.mode { margin-left: auto; font-size: 12px; color: var(--warn); background: var(--warn-bg); padding: 3px 8px; border-radius: 99px; }
.mode:empty { display: none; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: 16px; padding: 16px; max-width: 1280px; margin: 0 auto; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
.pane { min-width: 0; }

.convo { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; min-height: calc(100vh - 100px); }
@media (max-width: 860px) { .convo { min-height: 60vh; } }
.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant { background: var(--bg); align-self: flex-start; }
.msg.user { background: var(--user); align-self: flex-end; }
.msg.thinking { color: var(--muted); font-style: italic; }
.msg .tools { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }
.interim { padding: 0 16px; color: var(--muted); font-style: italic; min-height: 1.4em; }
/* Composer: a large auto-growing box with the mic and Send underneath, like a chat app's message box. */
.composer { margin: 12px; display: flex; flex-direction: column; gap: 8px; padding: 10px 10px 8px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--bg); }
.composer:focus-within { border-color: var(--accent); }
.composer textarea { font: inherit; font-size: 15px; line-height: 1.5; color: var(--text); background: transparent; border: 0; outline: none;
  resize: none; width: 100%; min-height: calc(4 * 1.5em + 8px); max-height: 40vh; padding: 4px 6px; overflow-y: auto; }
.composer-bar { display: flex; align-items: center; gap: 10px; }
.composer-hint { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mic { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.mic[aria-pressed="true"] { background: var(--bad); border-color: var(--bad); color: #fff; }
.speak { font-size: 13px; color: var(--muted); padding: 0 14px 12px; }
.mode .short, .top button .short { display: none; }
.routebar { display: none; }

/* ---- Phones and narrow windows ---------------------------------------------------------------- */
@media (max-width: 860px) {
  body { padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  .top { gap: 10px; padding: 10px 16px; }
  .brand { font-size: 16px; white-space: nowrap; }
  .top button { white-space: nowrap; padding: 6px 10px; }
  .mode .long, .top button .long { display: none; }
  .mode .short, .top button .short { display: inline; }
  .layout { padding: 12px 16px; gap: 12px; }
  .convo { min-height: 55vh; }
  .composer { margin: 10px; }
  .composer textarea { font-size: 16px; min-height: calc(3 * 1.5em + 8px); }  /* 16px keeps iOS from zooming into the field */
  .mic { padding: 10px 16px; }
  .routebar {
    display: grid; grid-template-columns: 1fr auto; gap: 0 10px; align-items: center; text-align: left;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface); color: var(--text); border: 0; border-top: 2px solid var(--border); border-radius: 0;
    box-shadow: 0 -4px 14px rgb(0 0 0 / .08);
  }
  .routebar.ok { border-top-color: var(--ok); }
  .routebar.info { border-top-color: var(--accent); }
  .routebar.alert { border-top-color: var(--warn); }
  .rb-status { grid-column: 1; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
  .rb-dest { grid-column: 1; font-size: 15px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rb-next { grid-column: 2; grid-row: 1 / span 2; font-size: 13px; color: var(--accent); white-space: nowrap; }
}
@media (max-width: 520px) { #micLabel { display: none; } }
@media (pointer: coarse) { #micLabel { display: inline; } .mic { padding: 10px 14px; } }

.draft { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.fields { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 14px; }
.fields .k { color: var(--muted); }
.fields .v { overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; margin-left: 6px; vertical-align: 1px; }
.pill.unconfirmed { background: var(--warn-bg); color: var(--warn); }
.pill.confirmed { background: var(--ok-bg); color: var(--ok); }

.routing .dest { font-size: 17px; font-weight: 650; }
.routing .fax { font-size: 15px; margin-top: 2px; }
.routing.ok { border-color: var(--ok); }
.routing.info { border-color: var(--accent); }
.routing.alert { border-color: var(--warn); }
.routing .why { margin: 10px 0 0; padding-left: 18px; font-size: 13px; }
.routing .why li { margin-bottom: 4px; }
.routing .why a { color: var(--accent); font-size: 12px; white-space: nowrap; }
.routing .warn { margin-top: 8px; font-size: 13px; background: var(--warn-bg); color: var(--warn); padding: 6px 8px; border-radius: 6px; }
.routing .unverified { background: var(--bad-bg); color: var(--bad); }

.missing ul { margin: 0; padding-left: 18px; font-size: 14px; }
.missing.done ul { color: var(--ok); list-style: none; padding: 0; }
.src { font-size: 12px; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.attest { font-size: 13px; display: flex; gap: 8px; align-items: flex-start; }
.receipt { font-size: 13px; background: var(--ok-bg); color: var(--ok); padding: 8px; border-radius: 8px; overflow-wrap: anywhere; }
.receipt.err { background: var(--bad-bg); color: var(--bad); }
