:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c232d;
  --border: #2b333d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4493f8;
  --accent-2: #2f81f7;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* Layout: fixed sidebar + scrollable content */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 18px; }
.logo { font-size: 28px; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; background: none; border: none; color: var(--muted);
  padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; text-align: left; width: 100%;
}
.nav-item span { font-size: 15px; width: 18px; text-align: center; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: rgba(68,147,248,.14); color: var(--accent); font-weight: 600; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.acct { display: flex; align-items: center; gap: 9px; padding: 2px 6px; }
.acct[hidden] { display: none; }
.acct-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-2); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; text-transform: uppercase; }
.acct-name { font-size: 13px; font-weight: 500; }
.btn.block { width: 100%; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 24px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
h1 { margin: 0; font-size: 19px; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.scan-meta { color: var(--muted); font-size: 12px; line-height: 1.5; }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #283039; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); }
.btn.primary:hover { background: var(--accent); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: progress; }
.btn.tiny { padding: 4px 8px; font-size: 12px; }

.tabs { display: flex; gap: 4px; padding: 0 24px; border-bottom: 1px solid var(--border); }
.tab {
  background: none; border: none; color: var(--muted);
  padding: 12px 16px; cursor: pointer; font-size: 14px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 24px; max-width: 1180px; width: 100%; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Settings cards */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; max-width: 720px; }
.card h3 { margin-bottom: 6px; }
.card p { margin: 0; }
.card code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-family: ui-monospace, monospace; color: var(--accent); font-size: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.key-row { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.key-row input { flex: 1; font-family: ui-monospace, monospace; font-size: 13px; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--panel-2); border: 1px solid var(--border); border-radius: 26px; cursor: pointer; transition: .2s; }
.slider::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: var(--muted); border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: rgba(63,185,80,.25); border-color: var(--green); }
.switch input:checked + .slider::before { transform: translateX(20px); background: var(--green); }

.panel-head { display: flex; align-items: baseline; gap: 14px; margin: 8px 0 14px; flex-wrap: wrap; }
.panel-head h2, h3 { margin: 0; }
h2 { font-size: 16px; }
h3 { font-size: 14px; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 12.5px; }

/* Server cards */
.server-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 14px;
  align-items: center;
}
.server-card.offline { opacity: .55; }
.prio-control { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.prio-num { font-size: 18px; font-weight: 700; }
.prio-control .arrow { background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); border-radius: 5px; width: 22px; height: 18px; cursor: pointer; line-height: 1; font-size: 10px; }
.prio-control .arrow:hover { color: var(--text); }
.handle { cursor: grab; color: var(--muted); font-size: 20px; user-select: none; }
.server-card.dragging { outline: 2px dashed var(--accent); }

.server-info .name-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.server-name { font-weight: 600; font-size: 15px; }
.server-url { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }
.server-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.badge.online { background: rgba(63,185,80,.18); color: var(--green); }
.badge.offline { background: rgba(248,81,73,.16); color: var(--red); }
.badge.type { background: rgba(68,147,248,.16); color: var(--accent); text-transform: none; letter-spacing: 0; }

.server-actions { display: flex; flex-direction: column; gap: 8px; min-width: 290px; }
.server-actions .row { display: flex; gap: 6px; align-items: center; }
select, input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 9px; font-size: 13px; outline: none;
}
select:focus, input:focus { border-color: var(--accent); }
select { flex: 1; min-width: 0; }
.bench-result { font-size: 12px; color: var(--muted); min-height: 16px; }
.bench-result .fast { color: var(--green); font-weight: 600; }
.last-bench { font-size: 12px; }
.last-bench-val { color: var(--amber); font-weight: 600; }
.alias-row { margin-top: 8px; }
.alias-input { width: 220px; max-width: 100%; padding: 5px 8px; font-size: 12.5px; }

/* Models tab */
.pull-row { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.pull-row input { flex: 1; min-width: 240px; }
.model-actions { white-space: nowrap; display: flex; gap: 6px; }
td .mchip {
  display: inline-block; font-size: 11px; padding: 2px 7px; margin: 2px 3px 2px 0; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--border); font-family: -apple-system, sans-serif;
}
td .mchip.offline { opacity: .5; text-decoration: line-through; }
td .fast { color: var(--green); font-weight: 600; }

.add-manual { margin-top: 10px; color: var(--muted); }
.add-manual summary { cursor: pointer; }
.add-manual code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-family: ui-monospace, monospace; color: var(--accent); font-size: 11.5px; }
.manual-row { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.msg { font-size: 12px; }
.msg.ok { color: var(--green); }
.msg.err { color: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 50px; border: 1px dashed var(--border); border-radius: var(--radius); }

/* Proxy tab */
.proxy-banner {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px; font-size: 13px; line-height: 1.7;
}
.proxy-banner code { background: var(--panel-2); padding: 2px 7px; border-radius: 5px; font-family: ui-monospace, monospace; color: var(--accent); }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; text-align: center; }
.stat-num { font-size: 30px; font-weight: 700; }
.stat-num.ok { color: var(--green); }
.stat-num.bad { color: var(--red); }
.stat-label { color: var(--muted); font-size: 12px; margin-top: 4px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }

table.mini { width: 100%; border-collapse: collapse; }
table.mini td { padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
table.mini td:last-child { text-align: right; color: var(--muted); }
.bar { height: 6px; background: var(--accent); border-radius: 3px; margin-top: 3px; }

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th { text-align: left; padding: 10px 12px; background: var(--panel); color: var(--muted); font-weight: 600; position: sticky; top: 0; }
table.data td { padding: 8px 12px; border-top: 1px solid var(--border); font-family: ui-monospace, monospace; }
table.data tr:hover td { background: var(--panel); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.dot.ok { background: var(--green); } .dot.bad { background: var(--red); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 8px; opacity: 0; transition: all .25s; pointer-events: none; z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--red); }
.login-overlay {
  position: fixed; inset: 0; background: rgba(13,17,23,.92); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.login-overlay[hidden] { display: none; }
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; width: 340px; max-width: 90vw; text-align: center;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.login-logo { font-size: 40px; }
.login-box h2 { font-size: 18px; }
.login-box p { color: var(--muted); font-size: 13px; margin: 0; }
.login-box input { padding: 10px 12px; font-size: 14px; }
.login-box .msg { min-height: 16px; }

.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; }
  .brand { padding: 4px 8px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; border: none; padding-top: 0; }
  .server-card { grid-template-columns: auto 1fr; }
  .server-actions { min-width: 0; grid-column: 1 / -1; }
  .two-col, .stats-grid { grid-template-columns: 1fr; }
}
