/* OmniRoute — routing-console theme.
   Signature element: the monospace "route receipt / ticket".
   Offline-friendly: system fonts only, no web-font fetches. */

:root {
  --bg: #f4f2ec;          /* warm paper */
  --bg-2: #efece4;        /* slightly deeper paper (rails, wells) */
  --panel: #fbfaf6;       /* card surface */
  --panel-2: #f2efe7;     /* raised chips / headers */
  --line: #e2ddd1;        /* soft warm border */
  --line-soft: #ebe7dc;
  --text: #2b2a26;        /* warm near-black */
  --muted: #6f6b60;       /* warm gray */
  --faint: #9c978a;
  --accent: #d97757;      /* Claude clay/coral */
  --accent-ink: #ffffff;
  --accent-tint: #f6ece7; /* faint coral wash */
  --link: #b5623f;        /* deeper coral for links */
  --ok: #4f8a5b;          /* muted green — free / success */
  --ok-ink: #e8f1e8;
  --err: #b3403f;         /* muted red — errors */
  --err-ink: #f6e6e5;
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --shadow: 0 1px 2px rgba(60,50,40,.04), 0 8px 24px rgba(60,50,40,.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg) fixed;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-rows: auto 1fr; min-height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: rgba(251,250,246,.82);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 20;
}
.wordmark { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; font-size: 19px; display: flex; align-items: center; gap: 9px; }
.wordmark .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(217,119,87,.20); }
.wordmark b { color: var(--accent); font-weight: 700; }
.wordmark .sub { color: var(--faint); font-weight: 500; font-size: 12px; margin-left: 4px; letter-spacing: 0; }
.topbar .spacer { flex: 1; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* toggle switch */
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 34px; height: 19px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); position: relative; transition: background .15s, border-color .15s; }
.switch .track::after { content: ""; position: absolute; top: 1px; left: 1px; width: 15px; height: 15px; border-radius: 50%; background: var(--faint); transition: transform .15s, background .15s; }
.switch input:checked + .track { background: rgba(217,119,87,.22); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(15px); background: var(--accent); }
.switch.ok input:checked + .track { background: rgba(79,138,91,.20); border-color: var(--ok); }
.switch.ok input:checked + .track::after { background: var(--ok); }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 7px 12px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; transition: border-color .12s, background .12s, transform .04s;
}
.btn:hover { border-color: var(--faint); background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 620; }
.btn-primary:hover { background: #c56746; border-color: #c56746; }
.btn-ghost { background: transparent; }
.btn-icon { padding: 7px 9px; }
.pill-key { font-family: var(--mono); font-size: 11.5px; }
.pill-key .k { color: var(--ok); }
.pill-key .k.off { color: var(--err); }

/* ---------- Body layout ---------- */
.body { display: grid; grid-template-columns: 248px 1fr; min-height: 0; }
.rail {
  border-right: 1px solid var(--line); background: var(--bg-2); padding: 12px;
  display: flex; flex-direction: column; gap: 10px; min-height: 0;
}
.rail h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); margin: 4px 2px; }
.history { overflow: auto; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.hist-item { text-align: left; border: 1px solid var(--line-soft); background: var(--panel); border-radius: var(--radius-sm); padding: 8px 10px; cursor: pointer; }
.hist-item:hover { border-color: var(--line); }
.hist-item .m { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.hist-item .p { font-size: 12.5px; color: var(--text); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hist-item .t { font-size: 10.5px; color: var(--faint); margin-top: 3px; }
.rail-empty { color: var(--faint); font-size: 12.5px; padding: 8px 2px; }

.main { padding: 18px 20px 40px; min-width: 0; max-width: 1180px; }

.notice { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; font-size: 13.5px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.notice b { color: var(--text); }
.notice.hide { display: none; }

/* mode tabs */
.modes { display: inline-flex; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; margin-bottom: 14px; flex-wrap: wrap; }
.mode-tab { border: 0; background: transparent; color: var(--muted); padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 13.5px; display: flex; align-items: center; gap: 7px; }
.mode-tab .g { font-family: var(--mono); color: var(--faint); }
.mode-tab[aria-selected="true"] { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.mode-tab[aria-selected="true"] .g { color: var(--accent); }
.mode-tab[hidden] { display: none; }

.mode-desc { color: var(--muted); font-size: 13px; margin: 0 2px 14px; }

/* selector zone */
.selector { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.selector .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.selector label.lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); }
.search { flex: 1; min-width: 180px; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"], select, textarea {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 11px; font-size: 14px; width: 100%; font-family: inherit;
}
select { appearance: none; }
textarea { resize: vertical; min-height: 92px; line-height: 1.5; }
.count { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

.model-list { margin-top: 10px; max-height: 230px; overflow: auto; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); }
.model-row { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.model-row:last-child { border-bottom: 0; }
.model-row:hover { background: var(--panel-2); }
.model-row input { width: auto; }
.model-row .nm { flex: 1; min-width: 0; }
.model-row .nm .n { font-size: 13.5px; }
.model-row .nm .id { font-family: var(--mono); font-size: 10.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-family: var(--mono); font-size: 10px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag.free { color: var(--ok); border-color: rgba(79,138,91,.45); background: var(--ok-ink); }
.tag.ctx { color: var(--muted); }

/* squads + priority chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.chip { border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); border-radius: 999px; padding: 6px 12px; font-size: 12.5px; cursor: pointer; }
.chip:hover { border-color: var(--faint); color: var(--text); }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: rgba(217,119,87,.12); }
.chip .g { font-family: var(--mono); margin-right: 6px; color: var(--faint); }
.chip[aria-pressed="true"] .g { color: var(--accent); }

/* prompt */
.composer { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 12px; }
.composer .actions { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.composer .hint { color: var(--faint); font-size: 12px; font-family: var(--mono); }
.composer .spacer { flex: 1; }

/* ---------- Results ---------- */
.results { margin-top: 20px; display: flex; flex-direction: column; gap: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.card { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.card .head { display: flex; align-items: center; gap: 9px; padding: 10px 13px; border-bottom: 1px solid var(--line-soft); background: var(--panel-2); }
.card .head .n { font-weight: 600; font-size: 13.5px; }
.card .head .id { font-family: var(--mono); font-size: 10.5px; color: var(--faint); }
.card .head .spacer { flex: 1; }
.status { font-family: var(--mono); font-size: 10.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.status .d { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.status.streaming { color: var(--accent); border-color: rgba(217,119,87,.4); }
.status.streaming .d { background: var(--accent); animation: pulse 1s infinite; }
.status.done { color: var(--ok); border-color: rgba(79,138,91,.45); }
.status.done .d { background: var(--ok); }
.status.error { color: var(--err); border-color: rgba(179,64,63,.45); }
.status.error .d { background: var(--err); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .status.streaming .d { animation: none; } }

.card .body { padding: 13px; }
.answer { white-space: pre-wrap; word-wrap: break-word; font-size: 14.5px; line-height: 1.62; color: var(--text); min-height: 22px; }
.answer.err { color: var(--err); font-size: 13.5px; }
.answer .cursor { display: inline-block; width: 7px; height: 15px; background: var(--accent); vertical-align: text-bottom; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

.reasoning { margin-bottom: 10px; border: 1px dashed var(--line); border-radius: var(--radius-sm); background: var(--bg-2); }
.reasoning summary { cursor: pointer; font-size: 11.5px; color: var(--muted); padding: 7px 10px; font-family: var(--mono); text-transform: uppercase; letter-spacing: .08em; }
.reasoning .r { padding: 0 10px 10px; color: var(--muted); font-size: 13px; white-space: pre-wrap; }

/* telemetry footer (mini receipt) */
.telemetry { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 9px 13px; border-top: 1px solid var(--line-soft); background: var(--bg-2); font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.telemetry b { color: var(--text); font-weight: 600; }
.telemetry .k { color: var(--faint); }

/* THE SIGNATURE: route receipt / ticket */
.receipt {
  font-family: var(--mono); background: #fffdf7; color: var(--text);
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); max-width: 460px; padding: 0;
}
.receipt .perf { height: 8px; background:
  radial-gradient(circle at 6px 8px, transparent 4px, var(--bg) 4px) repeat-x;
  background-size: 12px 8px; }
.receipt .rc { padding: 12px 16px; }
.receipt .rc-title { text-transform: uppercase; letter-spacing: .18em; font-size: 10.5px; color: var(--accent); border-bottom: 1px dashed var(--line); padding-bottom: 8px; margin-bottom: 8px; display: flex; justify-content: space-between; }
.receipt .line { display: flex; justify-content: space-between; gap: 16px; font-size: 12px; padding: 2px 0; }
.receipt .line .k { color: var(--faint); }
.receipt .line .v { color: var(--text); text-align: right; }
.receipt .why { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 12px; color: var(--muted); }
.receipt .why b { color: var(--accent); text-transform: uppercase; font-size: 10px; letter-spacing: .1em; display: block; margin-bottom: 3px; }

/* verdict card */
.verdict { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(217,119,87,.25), var(--shadow); }
.verdict .head { background: var(--accent-tint); border-bottom-color: rgba(217,119,87,.3); }
.verdict .head .badge { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .14em; color: var(--accent); border: 1px solid rgba(217,119,87,.4); border-radius: 999px; padding: 2px 9px; }

.section-label { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); margin: 4px 2px -4px; }

.choose-box { border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--bg-2); }
.choose-box .rec { font-size: 14px; white-space: pre-wrap; }

.src-links { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.src-links a { font-size: 12px; font-family: var(--mono); }
.src-links .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); }

/* transcript (One Answer) */
.turn { margin-bottom: 14px; }
.turn .who { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); margin-bottom: 5px; }
.turn.user .bubble { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 14px; white-space: pre-wrap; }

/* modal */
.backdrop { position: fixed; inset: 0; background: rgba(6,8,12,.62); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.backdrop[hidden] { display: none; }
.modal { width: 100%; max-width: 520px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.modal .m-head { display: flex; align-items: center; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal .m-head h2 { margin: 0; font-size: 16px; }
.modal .m-head .spacer { flex: 1; }
.modal .m-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal .m-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field .help { font-size: 12px; color: var(--faint); margin-top: 6px; }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 150px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.setting:last-child { border-bottom: 0; }
.setting .s-name { font-size: 13.5px; }
.setting .s-sub { font-size: 11.5px; color: var(--faint); }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 999px; font-size: 13px; z-index: 60; box-shadow: var(--shadow); }
.toast[hidden] { display: none; }

.rail-toggle { display: none; }

/* Paid Models page */
.provider-cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-top: 4px; }
.provider-card .body { padding: 14px; }
.provider-card .row { display: flex; gap: 8px; align-items: center; }
.provider-card .row input { flex: 1; }
.provider-card .field .help { line-height: 1.5; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .body { grid-template-columns: 1fr; }
  .rail { position: fixed; inset: 52px 0 0 0; z-index: 30; width: 82%; max-width: 320px; transform: translateX(-100%); transition: transform .2s; }
  .rail.open { transform: translateX(0); }
  .rail-toggle { display: inline-flex; }
  .main { padding: 14px 14px 40px; }
  .grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .rail { transition: none; } }

/* Paid page — two routes */
.two-routes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.route-card { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 15px 16px; }
.route-h { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.route-num { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; font-family: var(--mono); }
.route-tag { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; }
.route-p { color: var(--muted); font-size: 13px; margin: 4px 0 12px; line-height: 1.5; }
@media (max-width: 720px) { .two-routes { grid-template-columns: 1fr; } }

/* The hidden attribute always wins over component display rules. */
[hidden] { display: none !important; }
