:root{
  --bg:#0B0E14;
  --surface:#131820;
  --surface-2:#171D26;
  --border:#1F2733;
  --text:#E4E9F0;
  --muted:#6B7686;
  --accent:#F2A93B;
  --ok:#3ECF8E;
  --warn:#F2A93B;
  --err:#E5484D;
  --off:#4B5563;
  --radius:9px;
}
*{box-sizing:border-box;}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:'IBM Plex Sans', sans-serif; font-size:14px;
}
.mono{font-family:'IBM Plex Mono', monospace;}
.muted{color:var(--muted);}
.small{font-size:11.5px;}

.shell{display:grid; grid-template-columns:230px 1fr; min-height:100vh;}

/* --- rail --- */
.rail{
  background:var(--surface); border-right:1px solid var(--border);
  display:flex; flex-direction:column; padding:22px 16px;
}
.brand{display:flex; align-items:center; gap:10px; margin-bottom:30px; padding:0 4px;}
.brand-dot{width:9px; height:9px; border-radius:50%; background:var(--accent); box-shadow:0 0 10px var(--accent);}
.brand-name{font-weight:700; font-size:14.5px; letter-spacing:.01em;}
.brand-sub{font-size:11px; color:var(--muted); font-family:'IBM Plex Mono',monospace;}

.nav{display:flex; flex-direction:column; gap:2px; flex:1;}
.nav-item{
  display:flex; align-items:center; gap:10px; text-align:left; background:none; border:none;
  color:var(--muted); padding:10px 10px; border-radius:7px; cursor:pointer; font-size:13.5px;
  font-family:'IBM Plex Sans', sans-serif;
}
.nav-item .idx{font-family:'IBM Plex Mono',monospace; font-size:10.5px; color:var(--border); width:16px;}
.nav-item:hover{background:var(--surface-2); color:var(--text);}
.nav-item.active{background:var(--surface-2); color:var(--text);}
.nav-item.active .idx{color:var(--accent);}

.rail-foot{padding-top:16px; border-top:1px solid var(--border); display:flex; flex-direction:column; gap:4px;}

/* --- main --- */
.main{padding:32px 40px; max-width:1180px;}
.tab{display:none;}
.tab.active{display:block; animation:fade .25s ease;}
@keyframes fade{from{opacity:0; transform:translateY(4px);} to{opacity:1; transform:translateY(0);}}

.page-head{display:flex; align-items:center; justify-content:space-between; margin-bottom:24px;}
.page-head h1{font-size:21px; margin:0; font-weight:600;}

.live-pill{
  display:flex; align-items:center; gap:6px; font-family:'IBM Plex Mono',monospace; font-size:11px;
  color:var(--ok); border:1px solid var(--border); padding:5px 10px; border-radius:20px;
}
.pulse{width:6px; height:6px; border-radius:50%; background:var(--ok); animation:pulse 1.6s infinite;}
@keyframes pulse{0%,100%{opacity:1;}50%{opacity:.35;}}

.metric-grid{display:grid; grid-template-columns:repeat(4,1fr); gap:14px; margin-bottom:30px;}
.metric-card{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:18px;}
.metric-card.accent{border-color:rgba(242,169,59,.35);}
.metric-label{font-size:11.5px; color:var(--muted); margin-bottom:8px; text-transform:uppercase; letter-spacing:.04em;}
.metric-value{font-size:26px; font-weight:600;}

.panel-title{font-size:12px; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); margin:0 0 12px;}

.signal-strip{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  padding:18px; display:flex; flex-wrap:wrap; gap:16px; margin-bottom:30px; min-height:64px;
}
.signal{
  display:flex; flex-direction:column; align-items:center; gap:6px; width:64px;
}
.signal-bars{display:flex; align-items:flex-end; gap:2px; height:34px;}
.signal-bars i{width:4px; border-radius:1px; background:var(--border); display:block;}
.signal-bars i.lit{background:var(--ok);}
.signal-bars.warn i.lit{background:var(--warn);}
.signal-bars.err i.lit{background:var(--err);}
.signal-label{font-size:9.5px; font-family:'IBM Plex Mono',monospace; color:var(--muted); text-align:center; line-height:1.3;}

.two-col{display:grid; grid-template-columns:1fr 1fr; gap:16px;}
.card{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:18px;}

table.data-table{width:100%; border-collapse:collapse; font-size:13px;}
.data-table th{
  text-align:left; font-size:10.5px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted);
  border-bottom:1px solid var(--border); padding:8px 10px; font-weight:500;
}
.data-table td{padding:9px 10px; border-bottom:1px solid var(--border);}
.data-table tr:last-child td{border-bottom:none;}
.data-table.mono-cells td{font-family:'IBM Plex Mono',monospace; font-size:12px;}

.pill{
  display:inline-flex; align-items:center; gap:5px; padding:3px 9px; border-radius:20px;
  font-size:11px; font-family:'IBM Plex Mono',monospace;
}
.pill.ok{background:rgba(62,207,142,.12); color:var(--ok);}
.pill.warn{background:rgba(242,169,59,.12); color:var(--warn);}
.pill.err{background:rgba(229,72,77,.12); color:var(--err);}
.pill.off{background:rgba(75,85,99,.18); color:var(--off);}
.pill-dot{width:5px; height:5px; border-radius:50%; background:currentColor;}

.btn{
  background:var(--accent); color:#181109; border:none; border-radius:7px; padding:9px 16px;
  font-weight:600; font-size:13px; cursor:pointer;
}
.btn:hover{filter:brightness(1.08);}
.btn.ghost{background:none; border:1px solid var(--border); color:var(--text);}
.btn.small{padding:5px 10px; font-size:12px; border-radius:6px;}
.btn.danger{background:var(--err); color:#fff;}

.kv-card{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:18px; margin-bottom:14px;}
.kv-head{display:flex; justify-content:space-between; align-items:center; margin-bottom:10px; gap:12px; flex-wrap:wrap;}
.kv-head .name{font-weight:600; font-size:14.5px;}
.kv-head .meta{font-family:'IBM Plex Mono',monospace; font-size:11.5px; color:var(--muted); margin-top:3px;}
.quota-summary{display:flex; gap:8px; flex-wrap:wrap; margin-bottom:10px;}
.quota-list{display:flex; flex-direction:column;}
.models-body{display:none;}
.models-body.open{display:flex; flex-direction:column; animation:fade .2s ease;}
.quota-row{display:flex; justify-content:space-between; align-items:center; padding:7px 0; border-top:1px solid var(--border); font-size:12.5px; gap:10px;}
.quota-row .model{font-family:'IBM Plex Mono',monospace; flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}

/* --- per-model action menu (⋯) --- */
.quota-menu{position:relative; display:inline-block;}
.quota-menu-panel{
  display:none; position:absolute; right:0; top:calc(100% + 4px); z-index:20;
  background:var(--surface-2); border:1px solid var(--border); border-radius:8px;
  min-width:170px; padding:4px; box-shadow:0 8px 24px rgba(0,0,0,.4);
}
.quota-menu-panel.open{display:block;}
.qmenu-item{
  display:block; width:100%; text-align:left; background:none; border:none; color:var(--text);
  padding:8px 10px; border-radius:6px; font-size:12.5px; cursor:pointer; font-family:'IBM Plex Sans',sans-serif;
}
.qmenu-item:hover{background:var(--border);}

.usage-bar{width:120px; height:6px; background:var(--border); border-radius:3px; overflow:hidden; display:inline-block; vertical-align:middle; margin-right:8px;}
.usage-fill{height:100%; border-radius:3px;}
.usage-fill.ok{background:var(--ok);}
.usage-fill.warn{background:var(--warn);}
.usage-fill.err{background:var(--err);}

.modal-backdrop{
  display:none; position:fixed; inset:0; background:rgba(6,8,12,.65); align-items:center; justify-content:center; z-index:50;
}
.modal-backdrop.open{display:flex;}
.modal{
  background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:26px;
  width:460px; max-height:86vh; overflow-y:auto;
}
.modal h2{margin:0 0 18px; font-size:16px;}
.field{margin-bottom:14px;}
.field label{display:block; font-size:11.5px; color:var(--muted); margin-bottom:6px;}
.field input, .field select, .field textarea{
  width:100%; background:#0E1319; border:1px solid var(--border); border-radius:6px; padding:9px 10px;
  color:var(--text); font-family:'IBM Plex Mono',monospace; font-size:12.5px; outline:none;
}
.field input:focus, .field select:focus{border-color:var(--accent);}
.field-row{display:grid; grid-template-columns:1fr 1fr; gap:10px;}
.modal-actions{display:flex; justify-content:flex-end; gap:8px; margin-top:18px;}

/* --- checkbox rows & check-group (provider key access control) --- */
.check-row{
  display:flex; align-items:center; gap:8px; cursor:pointer;
  font-size:12.5px; color:var(--text); padding:4px 0;
}
.check-row input[type="checkbox"]{width:auto; accent-color:var(--accent);}
.check-group{
  background:#0E1319; border:1px solid var(--border); border-radius:6px;
  padding:10px 12px; max-height:160px; overflow-y:auto; margin-top:4px;
}
.check-group .check-row{padding:3px 0;}

/* --- chat test --- */
.chat-thread{
  display:flex; flex-direction:column; gap:10px; max-height:420px; overflow-y:auto;
  padding:4px 2px;
}
.chat-bubble{
  max-width:78%; padding:10px 14px; border-radius:12px; font-size:13px; line-height:1.5;
  white-space:pre-wrap; word-break:break-word;
}
.chat-bubble.user{
  align-self:flex-end; background:var(--accent); color:#181109;
  border-bottom-right-radius:4px;
}
.chat-bubble.assistant{
  align-self:flex-start; background:var(--surface-2); border:1px solid var(--border);
  border-bottom-left-radius:4px;
}

/* --- request log detail --- */
.log-pre{
  background:#0B0F14; border:1px solid var(--border); border-radius:6px;
  padding:10px 12px; font-family:'IBM Plex Mono',monospace; font-size:12px;
  white-space:pre-wrap; word-break:break-word; max-height:280px; overflow-y:auto;
  color:var(--text); margin:0;
}
.log-pre.err-text{color:#ff7a7a;}

/* --- request logs list (inline-expandable cards) --- */
.log-list{display:flex; flex-direction:column; gap:10px;}
.log-filter{
  background:#0E1319; border:1px solid var(--border); border-radius:6px;
  padding:8px 10px; color:var(--text); font-family:'IBM Plex Mono',monospace;
  font-size:12px; outline:none; min-width:180px;
}
.log-filter:focus{border-color:var(--accent);}
.log-card{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  overflow:hidden; transition:border-color .15s ease;
}
.log-card:hover{border-color:var(--border);}
.log-head{
  display:flex; align-items:center; gap:14px; padding:12px 16px; cursor:pointer; user-select:none;
}
.log-head:hover{background:var(--surface-2);}
.log-status{
  flex:none; width:38px; text-align:center; font-family:'IBM Plex Mono',monospace; font-weight:600;
  font-size:12px; padding:5px 0; border-radius:6px;
}
.log-status.ok{background:rgba(62,207,142,.12); color:var(--ok);}
.log-status.warn{background:rgba(242,169,59,.12); color:var(--warn);}
.log-status.err{background:rgba(229,72,77,.12); color:var(--err);}
.log-idx{flex:1; min-width:0;}
.log-name{font-weight:600; font-size:13.5px; display:flex; align-items:center; gap:8px; flex-wrap:wrap;}
.log-name .badge{font-weight:500; font-family:'IBM Plex Mono',monospace; font-size:10px; padding:1px 7px; border-radius:20px; text-transform:uppercase; letter-spacing:.03em;}
.log-name .badge.warn{background:rgba(242,169,59,.12); color:var(--warn);}
.log-name .badge.stream{background:rgba(107,118,134,.15); color:var(--muted);}
.log-path{
  font-family:'IBM Plex Mono',monospace; font-size:11.5px; color:var(--muted); margin-top:3px;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.log-path .model{color:var(--text);}
.log-meta{display:flex; align-items:center; gap:8px; flex:none; flex-wrap:wrap;}
.tag{
  font-family:'IBM Plex Mono',monospace; font-size:11px; color:var(--text);
  background:var(--surface-2); border:1px solid var(--border); padding:3px 8px; border-radius:6px;
  white-space:nowrap;
}
.tag.time{color:var(--muted);}
.tag.cost{color:var(--accent);}
.log-toggle{
  flex:none; color:var(--muted); font-family:'IBM Plex Mono',monospace; font-size:12px;
  width:18px; text-align:center; transition:transform .15s ease;
}
.log-card.open .log-toggle{transform:rotate(180deg);}
.log-body{display:none; border-top:1px solid var(--border); height:0;}
.log-card.open .log-body{display:block; animation:fade .18s ease; height:auto;}
.log-grid{display:grid; grid-template-columns:1fr 1fr; gap:14px; padding:14px 16px;}
.log-col-title{
  font-size:10.5px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); margin-bottom:7px;
}
.log-error{
  margin:0 16px 14px; background:rgba(229,72,77,.08); border:1px solid rgba(229,72,77,.3);
  border-radius:6px; padding:9px 12px; font-family:'IBM Plex Mono',monospace; font-size:11.5px;
  color:#ff9090; white-space:pre-wrap; word-break:break-word;
}
.log-empty{margin:0; color:var(--muted); font-size:13px;}

/* --- fallback ladder (per-project auto-mode priority editor) --- */
.fb-head{display:flex; align-items:flex-start; justify-content:space-between; gap:14px; margin-bottom:14px;}
.fb-desc{margin:4px 0 0; font-size:12px; color:var(--muted); line-height:1.5;}
.switch{position:relative; width:42px; height:23px; cursor:pointer; flex:none;}
.switch input{opacity:0; width:0; height:0;}
.switch .slider{position:absolute; inset:0; background:var(--border); border-radius:23px; transition:.2s;}
.switch .slider::before{content:""; position:absolute; height:16px; width:18px; left:3px; top:3.5px; background:#fff; border-radius:50%; transition:.2s;}
.switch input:checked + .slider{background:var(--accent);}
.switch input:checked + .slider::before{transform:translateX(17px);}

.ladder{display:none; flex-direction:column; gap:10px; margin-top:2px;}
.ladder.open{display:flex; animation:fade .2s ease;}
.ladder-list{display:flex; flex-direction:column; gap:6px;}
.ladder-step{
  display:flex; align-items:center; gap:9px; background:#0E1319;
  border:1px solid var(--border); border-radius:8px; padding:7px 10px;
  animation:stepIn .18s ease;
}
@keyframes stepIn{from{opacity:0; transform:translateY(-5px);} to{opacity:1; transform:none;}}
.ladder-rank{
  flex:none; width:22px; height:22px; border-radius:50%; display:flex; align-items:center; justify-content:center;
  background:var(--surface-2); border:1px solid var(--border);
  font-family:'IBM Plex Mono',monospace; font-size:11px; color:var(--accent);
}
.ladder-chip{
  flex:none; font-family:'IBM Plex Mono',monospace; font-size:10px; text-transform:uppercase;
  letter-spacing:.03em; padding:2px 8px; border-radius:20px; background:rgba(107,118,134,.15); color:var(--muted);
}
.ladder-chip.p-openrouter{background:rgba(242,169,59,.14); color:var(--accent);}
.ladder-chip.p-openai{background:rgba(62,170,142,.18); color:#4fd6c9;}
.ladder-chip.p-google{background:rgba(62,207,142,.14); color:var(--ok);}
.ladder-chip.p-anthropic{background:rgba(242,169,59,.12); color:var(--warn);}
.ladder-chip.p-deepseek{background:rgba(167,139,250,.16); color:#b79bff;}
.ladder-model{
  flex:1; font-family:'IBM Plex Mono',monospace; font-size:12.5px; color:var(--text);
  min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.ladder-acts{display:flex; gap:4px; flex:none;}
.ladder-btn{
  width:26px; height:26px; border:1px solid var(--border); background:none; color:var(--muted);
  border-radius:6px; cursor:pointer; font-size:12px; line-height:1;
}
.ladder-btn:hover{color:var(--text); border-color:var(--text);}
.ladder-btn.del:hover{color:var(--err); border-color:var(--err);}
.ladder-add{display:grid; grid-template-columns:1fr 1.6fr auto; gap:8px; align-items:end;}
.ladder-add select, .ladder-add input{width:100%; background:#0E1319; border:1px solid var(--border); border-radius:6px; padding:8px 9px; color:var(--text); font-family:'IBM Plex Mono',monospace; font-size:12px; outline:none;}
.ladder-add select:focus, .ladder-add input:focus{border-color:var(--accent);}

@media (max-width:900px){
  .shell{grid-template-columns:1fr;}
  .rail{display:none;}
  .metric-grid{grid-template-columns:repeat(2,1fr);}
  .two-col{grid-template-columns:1fr;}
  .log-grid{grid-template-columns:1fr;}
  .log-head{flex-wrap:wrap;}
  .log-meta{order:3; width:100%;}
}
