:root {
  --bg: #0e1116;
  --bg2: #151a22;
  --bg3: #1c2430;
  --border: #242e3c;
  --text: #e6ebf2;
  --muted: #8b98ab;
  --accent: #4f8cff;
  --ok: #2fbf71;
  --warn: #e0a832;
  --err: #e05252;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.92em; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 224px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; cursor: default; }
.brand span { color: var(--muted); font-weight: 500; font-size: 13px; margin-left: 6px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; margin-top: 18px; }
.sidebar nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
}
.sidebar nav a:hover { color: var(--text); background: var(--bg3); }
.sidebar nav a.active { background: var(--bg3); color: var(--text); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.side-foot a { color: var(--muted); text-decoration: none; font-size: 12.5px; padding: 6px 10px; }
.side-foot a:hover { color: var(--text); }
.side-foot .ver { color: #55617a; font-size: 11px; padding: 0 10px; }

.main { flex: 1; min-width: 0; padding: 26px 30px 40px; max-width: 1280px; }

.page-title { font-size: 20px; font-weight: 600; margin: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.back { color: var(--muted); text-decoration: none; font-size: 13px; display: inline-block; margin-bottom: 10px; }
.back:hover { color: var(--text); }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.section-title { font-size: 13px; color: var(--muted); font-weight: 500; margin: 14px 0 6px; }

/* ---------- cards & stats ---------- */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1.25fr; gap: 14px; align-items: start; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 5px; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.chart-wrap { height: 300px; padding-top: 8px; }

/* ---------- forms ---------- */
label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12.5px; }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  width: 100%;
}
textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #56637a; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 14px; margin-bottom: 6px; }

/* ---------- buttons / badges ---------- */
.btn {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: #35455c; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { background: #3d7cf0; }
.btn.danger { background: transparent; border-color: rgba(224, 82, 82, 0.4); color: #f0938f; }
.btn.danger:hover { background: rgba(224, 82, 82, 0.12); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.wide { width: 100%; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.badge.ok { background: rgba(47, 191, 113, 0.15); color: var(--ok); }
.badge.muted { background: rgba(139, 152, 171, 0.15); color: var(--muted); }
.badge.warn { background: rgba(224, 168, 50, 0.15); color: var(--warn); }
.badge.err { background: rgba(224, 82, 82, 0.15); color: #f0938f; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.table th {
  color: var(--muted);
  font-size: 11px;
  text-align: left;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 8px;
}
.table td { padding: 9px 8px; border-top: 1px solid var(--border); vertical-align: middle; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: rgba(255, 255, 255, 0.02); }
.table .num { text-align: right; }

/* ---------- misc ---------- */
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.banner { border-radius: 8px; padding: 9px 12px; font-size: 13px; margin: 10px 0; }
.banner.err { background: rgba(224, 82, 82, 0.12); color: #f0938f; border: 1px solid rgba(224, 82, 82, 0.35); }
.banner.ok { background: rgba(47, 191, 113, 0.1); color: #7bd8a5; border: 1px solid rgba(47, 191, 113, 0.3); }
.banner.warn { background: rgba(224, 168, 50, 0.1); color: #e6c075; border: 1px solid rgba(224, 168, 50, 0.35); }
.keybox {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--bg);
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 10px;
  margin: 10px 0;
}
.keybox code { flex: 1; word-break: break-all; font-size: 12px; color: #bcd0f5; }
.boot, .boot-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  color: var(--muted);
}

/* ---------- login ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card {
  width: 100%;
  max-width: 350px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 30px 28px;
}
.login-card h1 { font-size: 18px; margin: 14px 0 18px; }
.login-card .btn { margin-top: 6px; }

/* ---------- support ticket thread ---------- */
.t-thread { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.t-msg {
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg);
}
.t-msg-admin { border-left-color: var(--accent); }
.t-msg-user  { border-left-color: var(--muted); background: var(--bg2); }
.t-msg-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
}
.t-msg-meta b { color: var(--text); font-weight: 600; }
.t-msg-meta span { margin-left: auto; }
.t-msg-body {
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.55;
}

/* ---------- collapsible proxy cards ---------- */
/* Nav icons: hidden on desktop (the rail there has room for labels), revealed
   by the breakpoints below. currentColor keeps them in sync with link state. */
.nav-ico { display: none; width: 18px; height: 18px; flex: none; }
.collapse-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chevron {
  display: inline-block;
  font-size: 13px;
  line-height: 1;
  transition: transform 0.2s ease;
}
.chevron.collapsed {
  transform: rotate(-90deg);
}

/* ---------- toggle switch ---------- */
.toggle {
  display: inline-block;
  width: 40px;
  height: 20px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  vertical-align: middle;
  flex-shrink: 0;
  user-select: none;
}

.toggle.on {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle-slider {
  display: block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.toggle.on .toggle-slider {
  background: #fff;
  transform: translateX(20px);
}

/* ---------- proxy cards ---------- */
/* Only structural hooks here: the desktop look matches the inline styles these
   classes replaced, so the mobile block below is what actually restacks them. */
.proxy-id { display: flex; align-items: center; gap: 8px; min-width: 0; }
.proxy-id-text { min-width: 0; }
.proxy-name { margin: 0 0 6px; overflow-wrap: anywhere; }
.proxy-actions { flex-wrap: wrap; }

.hc-box {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg3);
  border-radius: 8px;
}
.hc-row { align-items: center; gap: 12px; flex-wrap: wrap; }
.hc-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.hc-caption { margin-left: 12px; }
.hc-select { width: auto; padding: 6px; }

.models-wrap { margin-top: 14px; min-width: 0; }
.models-title { margin: 0 0 8px; }
.model-alias { margin-left: 8px; }
.model-error {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Long upstream model ids are unbroken strings; let them wrap instead of
   forcing every table wider than its container. */
.table code { overflow-wrap: anywhere; }

@media (max-width: 940px) {
  .grid2 { grid-template-columns: 1fr; }
  .main { padding: 18px 16px 30px; }
  /* Icon rail: icon over a compact label. 84px (not the old 72px) so
     "Customers"/"Dashboard" still fit on one line. */
  .sidebar { width: 84px; padding: 16px 8px; }
  .nav-ico { display: block; width: 20px; height: 20px; }
  .sidebar nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 3px;
    font-size: 10.5px;
    line-height: 1.15;
    text-align: center;
  }
  .brand { font-size: 12px; letter-spacing: 0; text-align: center; overflow: hidden; }
  .brand span, .side-foot .txt { display: none; }
}

/* Phones: the icon rail still eats 72px of a 375px screen, and eight of the
   admin tables are 5-10 columns wide. Move the nav to a scrollable top bar and
   let tables keep their natural width inside a horizontal scroller. */
@media (max-width: 640px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: auto;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;      /* brand + Log out on the first line, nav on its own */
    align-items: center;
    gap: 8px 12px;
    padding: 10px 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .brand { font-size: 15px; flex: 1 1 auto; }
  .brand span { display: inline; font-size: 12px; margin-left: 4px; }
  .sidebar nav {
    order: 3;
    flex: 1 1 100%;       /* full-width row: at 375px a shared row left the nav 103px */
    min-width: 0;          /* without this a flex item refuses to shrink, so the
                              overflow scroller never engages and Log out is pushed
                              off-screen */
    flex-direction: row;
    margin-top: 0;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav a {
    flex-direction: row;    /* top bar reads better icon-then-label than stacked */
    gap: 7px;
    white-space: nowrap;
    padding: 7px 11px;
    border-radius: 999px;
    font-size: 13px;
    text-align: left;
  }
  .nav-ico { width: 16px; height: 16px; }
  .side-foot { flex: none; flex-direction: row; align-items: center; gap: 8px; margin-top: 0; margin-left: auto; }
  .side-foot .btn.wide { width: auto; }
  .side-foot .ver { display: none; }

  .main { padding: 14px 12px 30px; }
  .page-head { gap: 10px; }
  .page-title { font-size: 18px; }
  .card, .stat { padding: 13px 12px; border-radius: 10px; }
  .card-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .chart-wrap { height: 240px; }

  /* Horizontal scroller instead of crushing 8-column tables to ~40px each. */
  .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: max-content; }
  .table th { white-space: nowrap; }

  /* Opt-in wide tables stack into one card per row instead: a 1066px table
     inside a 351px card only ever shows two columns, which reads as squished.
     Every cell keeps its label, so no data is lost. */
  .table-cards { min-width: 0; }
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: auto; }
  .table-cards tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  .table-cards tr:last-child { margin-bottom: 0; }
  .table-cards td { border-top: 0; padding: 4px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .table-cards td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    flex: none;
  }
  /* The model name is the row title, not a label/value pair. */
  .table-cards td:not([data-label]) {
    display: block;
    padding: 0 0 7px;
    margin-bottom: 5px;
    border-bottom: 1px solid var(--border);
  }
  .table-cards td:not([data-label]) code { font-size: 13px; }
  .table-cards input[type="text"] { width: auto; flex: 0 1 62%; min-width: 0; }
  .table-cards .model-status {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px 8px;
  }
  .table-cards .model-status > div { margin: 0; }
  .table-cards .model-error { max-width: none; white-space: normal; overflow: visible; text-align: right; }
  .hc-note { display: none; }

  /* Sub-16px form text makes iOS zoom the whole page on focus. */
  input, select, textarea { font-size: 16px; }

  .proxy-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .proxy-actions { justify-content: flex-start; }
  .hc-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .hc-caption { margin-left: 0; }
  .hc-select { width: 100%; }
  .model-error { max-width: 120px; }

  /* Comfortable touch targets: the defaults are ~26px tall. */
  .btn { padding: 8px 14px; }
  .btn.small { padding: 7px 12px; font-size: 13px; }
  .table td { padding: 11px 8px; }
  .collapse-btn { width: 34px; height: 34px; }
  .toggle { width: 48px; height: 28px; }
  .toggle-slider { width: 22px; height: 22px; top: 2px; left: 2px; }
  .toggle.on .toggle-slider { transform: translateX(20px); }
}
