:root {
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-2: #f0f3f6;
  --border: #e1e6eb;
  --text: #17212b;
  --muted: #5f6b77;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f2;
  --high: #b42318;
  --high-soft: #fdecea;
  --medium: #b54708;
  --medium-soft: #fef4e6;
  --info: #1d5fa8;
  --info-soft: #e8f1fb;
  --ok: #067647;
  --ok-soft: #e7f6ee;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418; --surface: #161d22; --surface-2: #1d262d; --border: #2a353e; --text: #e6edf2; --muted: #95a3af;
    --accent: #2dd4bf; --accent-ink: #062b27; --accent-soft: #123532;
    --high: #f97066; --high-soft: #3a1a18; --medium: #fdb022; --medium-soft: #36290f;
    --info: #84caff; --info-soft: #132a40; --ok: #47cd89; --ok-soft: #10301f;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; margin: 2px 0 0; }
code { font-family: var(--mono); font-size: .9em; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); flex: none; position: relative;
}
.logo::after {
  content: ""; position: absolute; left: 8px; top: 6px; width: 8px; height: 13px;
  border: solid var(--accent-ink); border-width: 0 3px 3px 0; transform: rotate(45deg);
}
.brand-lg .logo { width: 40px; height: 40px; border-radius: 10px; }
.brand-lg .logo::after { left: 13px; top: 8px; width: 10px; height: 18px; }
.brand-name { font-weight: 650; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px;
  padding: 8px 14px; font: inherit; font-weight: 550; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--high); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
input, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px;
}
input:focus, textarea:focus, .btn:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---------- auth ---------- */
.auth { min-height: 100%; display: grid; place-items: center; align-content: center; gap: 16px; padding: 24px 16px; }
.auth-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; box-shadow: var(--shadow);
}
.auth-card .brand { margin-bottom: 22px; align-items: flex-start; }
.auth-card .brand p { margin: 2px 0 0; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tabs button { border: 0; background: transparent; padding: 8px; border-radius: 7px; font: inherit; font-weight: 550; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
form label { display: block; font-weight: 550; font-size: 13.5px; margin-bottom: 14px; }
form label input { margin-top: 6px; font-weight: 400; }
.hint { font-size: 13px; color: var(--muted); background: var(--surface-2); padding: 10px 12px; border-radius: 8px; margin: 0 0 14px; }
.error { color: var(--high); background: var(--high-soft); padding: 9px 12px; border-radius: 8px; font-size: 13.5px; margin: 0 0 14px; }
.fineprint { max-width: 420px; text-align: center; font-size: 12px; color: var(--muted); margin: 0; }

/* ---------- app shell ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.company { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; font-weight: 550;
}
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; z-index: 10;
}
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: none; font: inherit; padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--text); }
.menu-item:hover { background: var(--surface-2); }
.invite { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; display: grid; gap: 4px; font-size: 12.5px; }
.invite code { font-size: 18px; letter-spacing: .12em; font-weight: 700; color: var(--text); }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 340px 1fr; }
.sidebar { overflow-y: auto; padding: 16px; display: grid; gap: 12px; align-content: start; border-right: 1px solid var(--border); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card h2 { margin-bottom: 10px; }
.skeleton { color: var(--muted); }

.run-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.run-date { font-size: 18px; font-weight: 650; }
.pill { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.pill.DRAFT { background: var(--surface-2); color: var(--muted); }
.pill.PENDING_APPROVAL { background: var(--medium-soft); color: var(--medium); }
.pill.SUBMITTED, .pill.PAID { background: var(--ok-soft); color: var(--ok); }
.run-total { font-size: 28px; font-weight: 700; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.meter { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter.over > span { background: var(--medium); }
.meter-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.flag { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 6px; }
.flag.high { background: var(--high-soft); color: var(--high); }
.flag.medium { background: var(--medium-soft); color: var(--medium); }
.flag.info { background: var(--info-soft); color: var(--info); }
.flag.none { background: var(--ok-soft); color: var(--ok); }
.kv { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 6px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13.5px; }
.list li { line-height: 1.4; }
.list .meta { display: block; font-size: 12px; color: var(--muted); }
.audit li { font-size: 12.5px; padding-left: 10px; border-left: 2px solid var(--border); }
.audit strong { font-weight: 600; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.chat-head h2 { text-transform: none; letter-spacing: -.01em; font-size: 16px; color: var(--text); }
.messages { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 860px; width: 100%; }
.msg.user { align-self: flex-end; width: auto; max-width: 75%; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.msg.agent .bubble { background: var(--surface); border: 1px solid var(--border); padding: 12px 16px; border-radius: 14px 14px 14px 4px; box-shadow: var(--shadow); overflow-x: auto; }
.bubble:empty { display: none; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.bubble th { background: var(--surface-2); }
.bubble pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tool {
  font: 12px/1.2 var(--mono); padding: 5px 9px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--muted); cursor: pointer; max-width: 100%;
}
.tool.running::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; border: 2px solid var(--muted); border-top-color: transparent; animation: spin .8s linear infinite; vertical-align: -1px; }
.tool.success { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); }
.tool.error { color: var(--high); border-color: color-mix(in srgb, var(--high) 40%, var(--border)); background: var(--high-soft); }
.tool-detail { width: 100%; font: 12px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; color: var(--muted); max-height: 220px; overflow: auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.thinking { color: var(--muted); font-size: 13.5px; }
.thinking::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.approval {
  border: 1px solid color-mix(in srgb, var(--medium) 45%, var(--border)); background: var(--medium-soft);
  border-radius: 12px; padding: 14px 16px; margin-top: 10px;
}
.approval h3 { margin: 0 0 4px; font-size: 15px; }
.approval .amount { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.approval .actions { display: flex; gap: 8px; margin-top: 12px; }
.approval.done { opacity: .75; }
.notice { font-size: 13.5px; padding: 10px 12px; border-radius: 10px; margin-top: 8px; }
.notice.guardrail { background: var(--info-soft); color: var(--info); }
.notice.error { background: var(--high-soft); color: var(--high); }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 24px 10px; }
.suggestions button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--text); }
.suggestions button:hover { border-color: var(--accent); color: var(--accent); }
.composer { display: flex; gap: 10px; padding: 12px 24px 18px; border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea { resize: none; max-height: 160px; }

.welcome { color: var(--muted); max-width: 640px; }
.welcome h3 { color: var(--text); margin: 0 0 6px; font-size: 18px; }

.hood-link { font-weight: 600; font-size: 13.5px; color: #4338ca; text-decoration: none; padding: 6px 10px; border-radius: 8px; background: #eef0ff; white-space: nowrap; }
.hood-link:hover { text-decoration: underline; }
.hood-cta { width: min(420px, 100%); display: grid; gap: 2px; text-decoration: none; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid #4338ca; border-radius: 12px; padding: 12px 16px; font-size: 13.5px; }
.hood-cta strong { color: #4338ca; } .hood-cta span { color: var(--muted); }
@media (prefers-color-scheme: dark) { .hood-link { background: #23234a; color: #a5b4fc; } .hood-cta strong { color: #a5b4fc; } .hood-cta { border-left-color: #a5b4fc; } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow-y: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); overflow: visible; }
  .chat { min-height: 75vh; }
  .brand-name { display: none; }
}
@media (max-width: 560px) { .hood-link { padding: 5px 7px; font-size: 12.5px; } .company { display: none; } }
@media (max-width: 560px) {
  .topbar { padding: 10px 16px; }
  .messages, .chat-head { padding-left: 16px; padding-right: 16px; }
  .composer, .suggestions { padding-left: 16px; padding-right: 16px; }
  .msg.user { max-width: 90%; }
  .company { max-width: 40vw; }
}
