[hidden] { display: none !important; }
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --text: #16191d; --muted: #5d6673; --border: #e2e5ea;
  --accent: #424488; --accent-text: #ffffff; --accent-soft: #e9e9f5; --brand-teal: #3fa9c4; --good: #1e7f4f; --good-soft: #e3f4ea;
  --warn: #9a6200; --warn-soft: #fbf0d9; --bad: #b42318; --bad-soft: #fde8e6; --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1f242c; --text: #e8ebef; --muted: #9aa4b1; --border: #2a3039;
    --accent: #3fa9c4; --accent-text: #0f1216; --accent-soft: #15303a; --good: #5cc98f; --good-soft: #143425;
    --warn: #e2b04d; --warn-soft: #3a2d12; --bad: #ff8a80; --bad-soft: #3d1a17;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 20px; margin: 0 0 8px; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { height: 24px; width: auto; display: block; }
.logo-dark { display: none; }
@media (prefers-color-scheme: dark) { .logo-light { display: none; } .logo-dark { display: block; } }
.brand-text { padding-left: 12px; border-left: 1px solid var(--border); }
.name { font-weight: 600; }
.sub { color: var(--muted); font-size: 12.5px; }
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tenant-pick { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.tabs { display: flex; gap: 2px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 12px 12px 10px; font: inherit; cursor: pointer; white-space: nowrap; border-radius: 0; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.panel { display: flex; flex-direction: column; gap: 16px; }
.panel.narrow { max-width: 520px; margin: 40px auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12.5px; }
.kpi.bad .v { color: var(--bad); }
.toolbar, .row { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
textarea { font-family: var(--mono); font-size: 12.5px; width: 100%; resize: vertical; }
input[type="search"] { min-width: 260px; }
label { display: block; color: var(--muted); font-size: 12.5px; margin: 10px 0 4px; }
label.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
form.card input, form.card select { width: 100%; }
form.card button { margin-top: 14px; }
.row input { width: auto; }
button { font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid transparent; background: var(--accent); color: var(--accent-text); font-weight: 500; }
button.secondary { background: var(--accent-soft); color: var(--accent); }
button.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
button.danger { background: var(--bad); color: #fff; }
button.small { padding: 4px 10px; font-size: 12.5px; }
button:disabled { opacity: .55; cursor: default; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; text-align: right; }
td.mono, .mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
tr.bad td { background: var(--bad-soft); }
.hint { color: var(--muted); margin: 0; }
.error { color: var(--bad); }
.msg { margin: 10px 0 0; min-height: 1em; }
.empty { color: var(--muted); padding: 18px; text-align: center; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: 140px 1fr 48px; gap: 10px; align-items: center; font-size: 13px; }
.bar .track { background: var(--surface-2); border-radius: 6px; height: 10px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 6px; }
.bar.bad .fill { background: var(--bad); }
.bar .n { text-align: right; font-variant-numeric: tabular-nums; }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0 0 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.secret { margin-top: 14px; padding: 12px; border-radius: 8px; background: var(--warn-soft); color: var(--text); }
.danger-zone { border-color: var(--bad-soft); }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; }
@media (max-width: 640px) {
  .top { padding: 12px 16px; flex-wrap: wrap; } main { padding: 16px; } input[type="search"] { min-width: 0; width: 100%; }
  .toolbar { flex-wrap: wrap; } .bar { grid-template-columns: 110px 1fr 40px; }
}
.setup-note { font-size: 12px; max-width: 340px; margin-top: 4px; }

/* ---------- test chat ---------- */
.chat { display: flex; flex-direction: column; gap: 12px; }
.chat-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chat-head #chat-new { margin-left: auto; }
.chat-user { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.chat-user input { width: 260px; max-width: 100%; font-family: var(--mono); font-size: 12.5px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; min-height: 280px; max-height: 62vh; overflow-y: auto; padding: 12px; background: var(--surface-2); border-radius: var(--radius); }
.chat-empty { color: var(--muted); margin: auto; text-align: center; }
.bubble { max-width: 78%; padding: 9px 13px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.assistant a { color: var(--accent); }
.bubble.error { align-self: stretch; max-width: none; background: var(--bad-soft); color: var(--bad); }
.step { align-self: flex-start; max-width: 90%; font-size: 12.5px; }
.step summary { cursor: pointer; color: var(--muted); list-style: none; display: flex; gap: 6px; align-items: center; }
.step summary::-webkit-details-marker { display: none; }
.step summary::before { content: "▸"; font-size: 10px; }
.step[open] summary::before { content: "▾"; }
.step pre, .approval pre { margin: 6px 0 0; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; font: 12px/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow: auto; }
.approval { align-self: stretch; border: 1px solid var(--warn); background: var(--warn-soft); border-radius: var(--radius); padding: 12px 14px; }
.approval .row { margin-top: 10px; }
.approval h3 { margin: 0 0 4px; font-size: 14px; }
.thinking { align-self: flex-start; color: var(--muted); font-style: italic; }
.chat-input { display: flex; gap: 10px; align-items: flex-end; }
.chat-input textarea { font-family: var(--font); font-size: 14px; flex: 1; min-height: 44px; }
@media (max-width: 640px) { .bubble { max-width: 92%; } .chat-head #chat-new { margin-left: 0; } }
.connect-btn { align-self: flex-start; display: inline-block; background: var(--accent); color: var(--accent-text); padding: 7px 14px; border-radius: 8px; text-decoration: none; font-weight: 500; }
.connect-btn.done { background: var(--good-soft); color: var(--good); }
.connect-btn:hover { filter: brightness(1.08); }
.thinking-block { align-self: stretch; max-width: 90%; font-size: 13px; color: var(--muted); border-left: 3px solid var(--border); padding: 2px 0 2px 10px; }
.thinking-block summary { cursor: pointer; font-style: italic; list-style: none; }
.thinking-block summary::-webkit-details-marker { display: none; }
.thinking-block.live summary { color: var(--accent); }
.thinking-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 4px; max-height: 320px; overflow-y: auto; font-style: italic; }

.btn-ms { display: inline-flex; align-items: center; gap: 10px; padding: 10px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-weight: 600; text-decoration: none; }
.btn-ms:hover { background: var(--surface-2); }
#token-signin summary { cursor: pointer; color: var(--muted); margin: 8px 0; }

.users-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.users-head h2 { margin: 0; margin-right: auto; }
.users-head input { min-width: 240px; flex: 0 1 340px; }
.connect-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px; margin: 8px 0; background: var(--surface-2); border-radius: 8px; }
.connect-form input { flex: 1 1 220px; }
.connect-form #connect-result { flex-basis: 100%; word-break: break-all; }
table.users th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.users th .sort { color: var(--muted); font-size: .8em; }
table.users td.uid { word-break: break-all; }
table.users .nowrap { white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.app-chip { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; font-size: 11px; font-weight: 700; color: hsl(var(--hue) 55% 30%); background: hsl(var(--hue) 70% 90%); vertical-align: middle; }
@media (prefers-color-scheme: dark) { .app-chip { color: hsl(var(--hue) 70% 80%); background: hsl(var(--hue) 35% 22%); } }
.menu-cell { width: 1%; text-align: right; position: relative; }
.row-menu summary { list-style: none; cursor: pointer; padding: 2px 8px; border-radius: 6px; color: var(--muted); letter-spacing: 1px; }
.row-menu summary::-webkit-details-marker { display: none; }
.row-menu summary:hover, .row-menu[open] summary { background: var(--surface-2); color: var(--text); }
.row-menu .menu { position: absolute; right: 8px; z-index: 5; display: flex; flex-direction: column; min-width: 190px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.row-menu .menu button { background: none; color: var(--text); text-align: left; padding: 8px 10px; font-weight: 400; }
.row-menu .menu button:hover { background: var(--surface-2); }
.row-menu .menu .danger-text { color: #b42318; }
tr.open > td { background: var(--surface-2); }
tr.accounts-row > td { background: var(--surface-2); padding-top: 0; }
table.accounts { width: 100%; }
table.accounts td { border: 0; padding: 6px 8px; }
.table-wrap:has(> table.users) { overflow: visible; }
table.users tr:last-child .row-menu .menu { bottom: 100%; }

.copy-box { display: flex; flex-direction: column; gap: 10px; padding: 8px 0; }
.copy-targets { display: flex; flex-wrap: wrap; gap: 6px 18px; }

/* OAuth login setup for API apps */
.login-setup .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px 16px; }
.login-setup label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.login-setup code { padding: 4px 8px; border-radius: 6px; background: var(--soft, rgba(127,127,127,.12)); word-break: break-all; }
