:root {
  --bg: #0b0d12;
  --bg2: #11141b;
  --card: #151924;
  --card2: #1b2030;
  --line: #262c3d;
  --text: #e7eaf2;
  --muted: #8b93a7;
  --accent: #7c8cff;
  --accent2: #5b6cf0;
  --in: #6aa8ff;
  --out: #f2b25c;
  --ok: #3ecf8e;
  --warn: #f2b25c;
  --bad: #ff6b6b;
  --radius: 14px;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1a1f3a 0%, transparent 60%), var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
code { font-family: var(--mono); font-size: 0.92em; background: #0006; padding: 1px 5px; border-radius: 5px; }
h2 { margin: 0 0 4px; font-size: 20px; }
h3 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--muted); margin: 0 0 12px; }
.pad { padding: 16px; }
.hidden { display: none !important; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
  background: #0b0d12cc; backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand small { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: conic-gradient(from 200deg, var(--accent), #48d1cc, var(--out), var(--accent)); box-shadow: 0 0 18px #7c8cff55; }
.tabs { display: flex; gap: 4px; margin: 0 auto; background: var(--bg2); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.tab { background: none; border: 0; color: var(--muted); padding: 7px 16px; border-radius: 9px; cursor: pointer; font: inherit; font-weight: 600; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--card2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.quota-pill { font-size: 12px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg2); white-space: nowrap; }
.quota-pill.warn { border-color: var(--warn); color: var(--warn); }
.quota-pill.over { border-color: var(--bad); color: var(--bad); }

.banner { padding: 9px 18px; font-weight: 600; font-size: 13px; }
.banner.warn { background: #f2b25c22; color: var(--warn); border-bottom: 1px solid #f2b25c55; }
.banner.over { background: #ff6b6b22; color: var(--bad); border-bottom: 1px solid #ff6b6b55; }

/* ---------- buttons / inputs ---------- */
.btn { font: inherit; font-weight: 600; border-radius: 10px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card2); color: var(--text); transition: .15s; }
.btn:hover { border-color: #3a4260; }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent2)); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { background: #ff6b6b1f; border-color: #ff6b6b66; color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px #7c8cff33; }

/* ---------- views ---------- */
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; }
.scroll { flex: 1; overflow-y: auto; padding: 22px; max-width: 1280px; margin: 0 auto; width: 100%; }

/* ---------- chat ---------- */
.convs { width: 260px; flex: none; border-right: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 12px; background: #0d1017; }
.conv-list { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.conv { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 10px; cursor: pointer; color: var(--muted); }
.conv:hover { background: var(--card); color: var(--text); }
.conv.active { background: var(--card2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.conv .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .del { opacity: 0; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 15px; }
.conv:hover .del { opacity: 1; }
.conv .del:hover { color: var(--bad); }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { display: flex; gap: 10px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chat-head .model-picker { flex: 1; min-width: 220px; max-width: 520px; }
.opts { position: relative; }
.opts summary { list-style: none; }
.opts summary::-webkit-details-marker { display: none; }
.opts-body { position: absolute; right: 0; top: 44px; z-index: 30; width: 300px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; box-shadow: 0 20px 50px #0009; }
.opts-body label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 22px 18px 10px; display: flex; flex-direction: column; gap: 16px; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 440px; }
.empty h2 { color: var(--text); }
.msg { max-width: 860px; width: 100%; margin: 0 auto; display: flex; gap: 12px; }
.msg .av { width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.msg.user .av { background: #2a3150; }
.msg.assistant .av { background: conic-gradient(from 200deg, var(--accent), #48d1cc, var(--out), var(--accent)); color: #0b0d12; }
.msg .body { flex: 1; min-width: 0; }
.msg.user .bubble { background: var(--card2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.bubble { word-wrap: break-word; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: #07090d; border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 13px; }
.bubble pre code { background: none; padding: 0; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 12px 0 6px; font-size: 15px; }
.bubble table { border-collapse: collapse; margin: 8px 0; }
.bubble td, .bubble th { border: 1px solid var(--line); padding: 4px 8px; }
.bubble .err { color: var(--bad); }
.reasoning { margin-bottom: 8px; }
.reasoning summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.reasoning div { white-space: pre-wrap; color: var(--muted); font-size: 12.5px; border-left: 2px solid var(--line); padding-left: 10px; margin-top: 6px; max-height: 240px; overflow-y: auto; }
.meta { margin-top: 6px; font-size: 11.5px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.meta b { color: var(--text); font-weight: 600; }
.meta .in { color: var(--in); } .meta .out { color: var(--out); }
.cursor::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.composer { display: flex; gap: 10px; padding: 14px 18px 18px; max-width: 900px; width: 100%; margin: 0 auto; align-items: flex-end; }
.composer textarea { resize: none; max-height: 220px; min-height: 44px; padding: 11px 14px; border-radius: 12px; }

/* ---------- model picker ---------- */
.model-picker { position: relative; }
.mp-btn { width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; }
.mp-btn .id { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 13px; }
.mp-btn .prov { font-size: 11px; color: var(--muted); }
.mp-pop { position: absolute; z-index: 40; top: 44px; left: 0; right: 0; min-width: 320px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 24px 60px #000a; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.mp-row { display: flex; gap: 8px; }
.mp-row select { width: 46%; }
.mp-list { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; }
.mp-item { display: flex; justify-content: space-between; gap: 10px; padding: 7px 9px; border-radius: 8px; cursor: pointer; font-family: var(--mono); font-size: 12.5px; }
.mp-item:hover, .mp-item.sel { background: var(--card2); }
.mp-item span:last-child { color: var(--muted); font-family: inherit; font-size: 11px; white-space: nowrap; }
.mp-count { font-size: 11px; color: var(--muted); }

/* ---------- consumo ---------- */
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.server-head { margin-top: 36px; padding-top: 24px; border-top: 1px dashed var(--line); }
.tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #48d1cc22; color: #48d1cc; vertical-align: middle; }
.seg { display: inline-flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { background: none; border: 0; color: var(--muted); font: inherit; padding: 5px 12px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--card2); color: var(--text); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.kpi .big { font-size: 28px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.kpi .sub { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.kpi .sub .in { color: var(--in); } .kpi .sub .out { color: var(--out); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 8px; }
.sw.in { background: var(--in); } .sw.out { background: var(--out); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart { position: relative; height: 240px; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .tip { position: absolute; pointer-events: none; background: #07090df0; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 7px 0; border-bottom: 1px solid #ffffff08; }
.bar-row .name { font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.bar-row .track { grid-column: 1 / -1; height: 6px; border-radius: 4px; background: #ffffff0a; display: flex; overflow: hidden; }
.bar-row .track i { display: block; height: 100%; }
.bar-row .track i.in { background: var(--in); } .bar-row .track i.out { background: var(--out); }
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 7px 10px; border-bottom: 1px solid #ffffff08; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.t td.mono { font-family: var(--mono); max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
table.t td.wrap { white-space: normal; min-width: 200px; color: var(--muted); }
.num { text-align: right !important; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); } .dot.off { background: #555; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line); }
.badge.bad { color: var(--bad); border-color: #ff6b6b55; } .badge.warn { color: var(--warn); border-color: #f2b25c55; } .badge.ok { color: var(--ok); border-color: #3ecf8e55; }

/* ---------- controles ---------- */
.form { display: grid; gap: 10px; margin-bottom: 16px; }
.form label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.switch { display: flex !important; align-items: center; gap: 10px; cursor: pointer; color: var(--text) !important; }
.switch input { display: none; }
.switch span { width: 38px; height: 22px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { left: 19px; }
.limit { margin-top: 12px; }
.limit .row { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 5px; }
.progress { height: 10px; border-radius: 6px; background: #ffffff0d; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ok); border-radius: 6px; transition: width .4s; }
.progress.warn i { background: var(--warn); } .progress.over i { background: var(--bad); }
#testPicker { margin-bottom: 10px; }
.test-log { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.test-item { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 12.5px; background: var(--bg2); }
.test-item .h { display: flex; justify-content: space-between; gap: 8px; }
.test-item .m { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.test-item .r { color: var(--muted); margin-top: 3px; word-break: break-word; }
.danger-zone { border-color: #ff6b6b33; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--card2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; transition: .25s; opacity: 0; z-index: 99; box-shadow: 0 10px 40px #000a; }
.toast.show { transform: translateX(-50%); opacity: 1; }

.only-mobile { display: none; }
@media (max-width: 900px) {
  .kpis { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .tabs { order: 3; width: 100%; justify-content: center; }
  .only-mobile { display: inline-block; }
  .convs { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: .25s; box-shadow: 20px 0 60px #000a; }
  .convs.open { transform: none; }
  .scroll { padding: 14px; }
  .opts-body { right: -10px; width: 280px; }
}

/* ---------- monitor / chaves ---------- */
.scroll.wide { max-width: 1440px; }
.kpis.k4 { grid-template-columns: repeat(4, 1fr); }
.kpi .big.sm { font-size: 22px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid3 .card p.muted, .card-head + p.muted { margin-top: -4px; font-size: 12px; }
.live { font-size: 11px; font-weight: 600; color: var(--ok); border: 1px solid #3ecf8e55; background: #3ecf8e14; padding: 2px 9px; border-radius: 999px; vertical-align: middle; }
.live::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: middle; animation: blink 2s infinite; }
.foot { font-size: 12px; margin-top: 4px; }
.supply-top { display: flex; gap: 22px; flex-wrap: wrap; align-items: baseline; margin-bottom: 12px; }
.supply-top b { font-size: 18px; }
.supply-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px 22px; }
.sup { font-size: 12.5px; }
.sup .row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.sup .row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.sup .progress { height: 7px; }
.sup .note { color: var(--muted); font-size: 11px; margin-top: 3px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.copyline { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.copyline > span:first-child { color: var(--muted); font-size: 12px; width: 70px; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.seg.small { margin: 8px 0; }
.seg.small button { padding: 4px 10px; font-size: 12px; }
.snippet { background: #07090d; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-family: var(--mono); font-size: 12px; overflow-x: auto; white-space: pre; margin: 0 0 8px; max-height: 260px; }
.newkey { margin-top: 14px; border: 1px solid #3ecf8e66; background: #3ecf8e10; border-radius: 12px; padding: 14px; }
.newkey .k { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.newkey .k code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 8px 10px; font-size: 12.5px; }
.newkey .warn { color: var(--warn); font-size: 12.5px; font-weight: 600; }
.mini { display: grid; gap: 3px; min-width: 150px; }
.mini .progress { height: 6px; }
.mini small { color: var(--muted); }
.acts { display: flex; gap: 6px; }
.limit-edit { display: flex; gap: 6px; align-items: center; }
.limit-edit input { width: 110px; padding: 4px 8px; font-size: 12px; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: radial-gradient(900px 500px at 70% 0%, #1a1f3a 0%, transparent 60%), var(--bg); }
.login-card { width: min(360px, 92vw); background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: grid; gap: 12px; text-align: center; box-shadow: 0 30px 80px #000a; }
.logo.big { width: 46px; height: 46px; border-radius: 14px; margin: 0 auto; }
.login-card .err { color: var(--bad); margin: 0; min-height: 18px; font-size: 13px; }

@media (max-width: 1100px) { .kpis.k4 { grid-template-columns: repeat(2, 1fr); } .grid3 { grid-template-columns: 1fr; } }
@media (max-width: 900px) { .row2 { grid-template-columns: 1fr; } .tabs { overflow-x: auto; justify-content: flex-start; } .tab { padding: 7px 12px; } }
@media (max-width: 520px) { .kpis.k4 { grid-template-columns: 1fr 1fr; } .kpi .big { font-size: 22px; } }
