/* ============ AI Proxy - dark modern theme ============ */
:root {
  --bg: #0f1115;
  --bg-soft: #161922;
  --panel: #1c2029;
  --panel-2: #212633;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b93a5;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --green: #34d399;
  --amber: #fbbf24;
  --rose: #fb7185;
  --cyan: #22d3ee;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
}

a { color: var(--accent-2); text-decoration: none; }
code, pre {
  font-family: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
  font-size: 12.5px;
}
code {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  color: var(--cyan);
}
code.wrap { word-break: break-all; }

.icon { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: -4px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: none;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 20px; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
}
.brand-mark .icon { width: 20px; height: 20px; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.05); color: var(--text); }
.nav-link.active { background: rgba(99,102,241,.16); color: var(--accent-2); }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 2px; }
.whoami { display: flex; align-items: center; gap: 10px; padding: 8px 10px; color: var(--muted); font-size: 13px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 650; }

.content { padding: 24px 28px; flex: 1; }
.footer {
  padding: 14px 28px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

/* ---------- flash ---------- */
.flash {
  display: flex; align-items: center; gap: 10px;
  margin: 14px 28px 0;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
}
.flash-success { border-color: rgba(52,211,153,.4); background: rgba(52,211,153,.08); }
.flash-error   { border-color: rgba(251,113,133,.4); background: rgba(251,113,133,.08); }
.flash-info    { border-color: rgba(34,211,238,.4);  background: rgba(34,211,238,.08); }

.key-reveal { display: block; }
.key-reveal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.key-reveal-body { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.key-reveal-body code { font-size: 14px; padding: 8px 12px; word-break: break-all; }
.key-reveal p { margin: 8px 0 0; }

/* ---------- stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  display: flex; gap: 14px; align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-icon {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 12px;
}
.stat-icon .icon { width: 22px; height: 22px; }
.c-indigo { background: rgba(99,102,241,.16); color: var(--accent-2); }
.c-green  { background: rgba(52,211,153,.14); color: var(--green); }
.c-amber  { background: rgba(251,191,36,.14); color: var(--amber); }
.c-rose   { background: rgba(251,113,133,.14); color: var(--rose); }
.c-teal   { background: rgba(45,212,191,.14); color: #2dd4bf; }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-sub { color: var(--muted); font-size: 12px; }

/* ---------- panels & tables ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 24px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; font-size: 15.5px; font-weight: 650; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.table td { font-size: 13.5px; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,.025); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }
.table .actions { text-align: right; width: 1%; }
td.empty { text-align: center; color: var(--muted); padding: 28px 12px !important; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge-ok    { color: var(--green); border-color: rgba(52,211,153,.4); background: rgba(52,211,153,.08); }
.badge-error { color: var(--rose);  border-color: rgba(251,113,133,.4); background: rgba(251,113,133,.08); }
.badge-quota { color: var(--amber); border-color: rgba(251,191,36,.4);  background: rgba(251,191,36,.08); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit; font-weight: 550;
  cursor: pointer;
  transition: filter .15s, background .15s;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.12); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-google { background: #fff; border-color: #d8dce3; color: #1f2430; justify-content: center; }
.btn-google:hover { background: #f6f8fb; }
.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 12px;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }
.btn.disabled, .btn:disabled { opacity: .45; pointer-events: none; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.07); color: var(--text); }
.icon-btn.danger:hover { color: var(--rose); background: rgba(251,113,133,.1); }
.icon-btn .icon { width: 16px; height: 16px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: 12.5px; font-weight: 550; }
.field input, .field select, .field textarea {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  padding: 9px 12px;
  font: inherit;
  width: 100%;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.2); }
.field-inline { gap: 0; }
.field-inline input, .field-inline select { width: auto; }
.check { display: flex; align-items: center; gap: 9px; cursor: pointer; color: var(--text); }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5,7,10,.65);
  display: grid; place-items: center;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 520px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  max-height: 92vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 15.5px; display: flex; align-items: center; gap: 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- pager ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 16px; flex-wrap: wrap; }
.pager-nav { display: flex; align-items: center; gap: 14px; }
.pager-per { display: flex; align-items: center; gap: 8px; margin: 0; }
.pager-per select { width: auto; }

/* ---------- misc ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0 0 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.code-block {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre;
}
.inline { display: inline; }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(900px 500px at 20% 10%, #1c2134 0%, var(--bg) 60%); }
.login-wrap { width: 100%; max-width: 380px; padding: 20px; }
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .brand-mark { margin: 0 auto 10px; width: 48px; height: 48px; border-radius: 13px; }
.login-brand .brand-name { font-size: 18px; font-weight: 700; }
.login-brand .brand-sub { color: var(--muted); font-size: 13px; }
.login-back {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}
.login-back:hover { color: var(--accent-2); }
