/* Autoclaw dashboard — modern dark theme.
   Loaded after styles.css. Presentation only: markup, IDs and JS untouched. */

:root {
  --bg: #080b0a;
  --surface: #111513;
  --surface-2: #181d1a;
  --line: #232b27;
  --line-strong: #5a665f;
  --text: #f2f5f3;
  --muted: #98a39c;
  --accent: #e79a5f;
  --accent-hover: #f3b07a;
  --accent-ink: #1a110a;
  --ok: #7fd3a2;
  --warn: #eac478;
  --err: #f09c9c;
  --info: #7fb7d4;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: 216px;
  --shadow-card: 0 18px 40px rgba(0, 0, 0, 0.28);
}

* { scrollbar-width: thin; scrollbar-color: #303a34 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #303a34; border-radius: 999px; border: 3px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }
::selection { background: rgba(231, 154, 95, 0.28); }

body {
  background:
    linear-gradient(rgba(255, 255, 255, 0.016) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, rgba(255, 255, 255, 0.016) 1px, transparent 1px) 0 0 / 48px 48px,
    radial-gradient(1000px 520px at 88% -12%, rgba(231, 154, 95, 0.09), transparent 62%),
    radial-gradient(900px 520px at -8% 108%, rgba(127, 183, 212, 0.06), transparent 62%),
    var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

/* ---------- Sidebar ---------- */
.sidebar {
  gap: 1.05rem;
  padding: 1rem 0.65rem;
  background: linear-gradient(180deg, #121614 0%, #0b0e0d 100%);
  border-right: 1px solid rgba(231, 154, 95, 0.1);
}
.brand { gap: 0.55rem; padding: 0.2rem 0.35rem; }
.brand-mark {
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 9px;
  background: #0d1110;
  box-shadow: 0 0 0 1px rgba(231, 154, 95, 0.28), 0 8px 22px rgba(231, 154, 95, 0.16);
}
.brand-name { font-size: 0.95rem; letter-spacing: 0.01em; }
.brand-sub { font-size: 0.68rem; letter-spacing: 0.02em; }

.nav { gap: 2px; }
.nav a {
  position: relative;
  min-height: 35px;
  padding: 0 0.6rem;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}
.nav a::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(231, 154, 95, 0.16), rgba(231, 154, 95, 0.02));
  opacity: 0;
  transition: opacity 140ms ease;
  pointer-events: none;
}
.nav a:hover { background: rgba(255, 255, 255, 0.025); color: var(--text); }
.nav a:hover .nav-icon { color: var(--accent); }
.nav a[aria-current="page"] {
  background: transparent;
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav a[aria-current="page"]::before { opacity: 1; }
.nav a[aria-current="page"] .nav-icon { color: var(--accent); }
.nav-icon { width: 17px; height: 17px; flex: 0 0 auto; color: var(--muted); }
.nav-label { flex: 1 1 auto; }
.nav-count {
  margin-left: auto;
  padding: 0 0.35rem;
  border-radius: 999px;
  border-color: rgba(231, 154, 95, 0.32);
  color: var(--accent);
  background: rgba(231, 154, 95, 0.08);
  font-size: 0.66rem;
}

.sidebar-bottom { gap: 0.75rem; }
.lang-switch { border-radius: 999px; padding: 2px; }
.lang-switch button { min-height: 25px; font-size: 0.7rem; border-radius: 999px; }
.lang-switch button[aria-pressed="true"] {
  background: rgba(231, 154, 95, 0.16);
  color: var(--accent);
}
.dot.ok { animation: dotPulse 2.6s ease-out infinite; }
@keyframes dotPulse {
  0% { box-shadow: 0 0 0 0 rgba(127, 211, 162, 0.35); }
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.foot-account .signout {
  margin-left: auto;
  opacity: 0.7;
  font-size: 0.7rem;
}
.foot-account .signout:hover { opacity: 1; }
.foot-avatar {
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(231, 154, 95, 0.2), rgba(127, 183, 212, 0.1));
  border-color: rgba(231, 154, 95, 0.3);
  color: var(--accent);
}

/* ---------- Content and header ---------- */
.content { max-width: 1400px; padding: 1.05rem 1.35rem 2rem; }
.page-head {
  align-items: center;
  padding-bottom: 0.85rem;
  margin-bottom: 1.05rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
h1 {
  font-size: 1.45rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  background: linear-gradient(92deg, #ffffff 10%, #c9d3cd 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
@supports not (background-clip: text) {
  h1 { background: none; color: var(--text); }
}
.page-desc { margin-top: 0.18rem; font-size: 0.82rem; }
.section-head { margin-top: 1.2rem; margin-bottom: 0.65rem; }
.section-head:first-child { margin-top: 0; }
.section-head h2 { font-size: 0.95rem; }

.page:not([hidden]) { animation: pageIn 220ms ease-out; }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.banner {
  border-color: rgba(240, 156, 156, 0.35);
  background: linear-gradient(180deg, rgba(240, 156, 156, 0.12), rgba(240, 156, 156, 0.05));
  border-radius: 10px;
  margin-bottom: 0.85rem;
}

/* ---------- Cards ---------- */
.card,
.stat-card,
fieldset {
  border: 1px solid transparent;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.008)) padding-box,
    linear-gradient(155deg, rgba(231, 154, 95, 0.26), rgba(255, 255, 255, 0.05) 42%, rgba(127, 183, 212, 0.12)) border-box;
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.card { padding: 0.9rem 1rem 1rem; }
fieldset { padding: 0.9rem 1rem 1rem; }
.card-head { margin-bottom: 0.65rem; }
.card-head h2, .card-head h3 { font-size: 0.93rem; }

/* ---------- Stat tiles ---------- */
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(172px, 1fr)); gap: 0.65rem; }
.stat-card {
  position: relative;
  overflow: hidden;
  padding: 0.8rem 0.9rem 0.85rem;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 22px 48px rgba(0, 0, 0, 0.36); }
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent 78%);
  opacity: 0.9;
}
.stat-card:nth-child(2)::before { background: linear-gradient(90deg, var(--ok), transparent 78%); }
.stat-card:nth-child(3)::before { background: linear-gradient(90deg, var(--warn), transparent 78%); }
.stat-card:nth-child(4)::before { background: linear-gradient(90deg, var(--info), transparent 78%); }
.stat-card:nth-child(5)::before { background: linear-gradient(90deg, var(--accent), transparent 78%); }
.stat-card:nth-child(6)::before { background: linear-gradient(90deg, var(--info), transparent 78%); }

.stat-icon {
  width: 1.85rem;
  height: 1.85rem;
  border: 0;
  border-radius: 8px;
  background: rgba(231, 154, 95, 0.12);
  color: var(--accent);
}
.stat-card:nth-child(2) .stat-icon { background: rgba(127, 211, 162, 0.12); color: var(--ok); }
.stat-card:nth-child(3) .stat-icon { background: rgba(234, 196, 120, 0.12); color: var(--warn); }
.stat-card:nth-child(4) .stat-icon { background: rgba(127, 183, 212, 0.12); color: var(--info); }
.stat-card:nth-child(5) .stat-icon { background: rgba(231, 154, 95, 0.12); color: var(--accent); }
.stat-card:nth-child(6) .stat-icon { background: rgba(127, 183, 212, 0.12); color: var(--info); }
.stat-icon svg { width: 0.95rem; height: 0.95rem; }
.stat-label { font-size: 0.64rem; letter-spacing: 0.08em; color: var(--muted); }
.stat-value {
  margin-top: 0.55rem;
  font-size: clamp(1.35rem, 2.1vw, 1.75rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}
.stat-note { margin-top: 0.2rem; font-size: 0.72rem; }

/* ---------- Tables ---------- */
.table-wrap {
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.12);
}
th {
  background: rgba(255, 255, 255, 0.035);
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
th, td { padding: 0.44rem 0.65rem; font-size: 0.82rem; }
tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.012); }
tbody tr:hover td { background: rgba(231, 154, 95, 0.06); }

/* ---------- Controls ---------- */
.btn {
  min-height: 33px;
  padding: 0.26rem 0.75rem;
  border-radius: 8px;
  border-color: rgba(255, 255, 255, 0.09);
  background: linear-gradient(180deg, #1b201d, #141817);
  font-size: 0.82rem;
}
.btn:hover { border-color: rgba(231, 154, 95, 0.3); background: linear-gradient(180deg, #222824, #181d1a); }
.btn.primary {
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: var(--accent-ink);
  box-shadow: 0 8px 20px rgba(231, 154, 95, 0.18);
}
.btn.primary:hover { background: linear-gradient(135deg, var(--accent-hover), #f7c08f); }
.btn.small { min-height: 27px; font-size: 0.74rem; }

.badge { border-radius: 999px; padding: 0.08rem 0.48rem; font-size: 0.67rem; }
.badge.ok { background: rgba(127, 211, 162, 0.1); border-color: rgba(127, 211, 162, 0.32); }
.badge.warn { background: rgba(234, 196, 120, 0.1); border-color: rgba(234, 196, 120, 0.32); }
.badge.err { background: rgba(240, 156, 156, 0.1); border-color: rgba(240, 156, 156, 0.32); }

.seg { border-radius: 7px; }
.seg[aria-pressed="true"] { background: rgba(231, 154, 95, 0.14); color: var(--accent); }

input, select {
  background: #0b0f0d;
  border-color: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}
input:hover, select:hover { border-color: rgba(231, 154, 95, 0.35); }

.meter { background: rgba(255, 255, 255, 0.06); border-radius: 999px; }
.meter-fill { background: linear-gradient(90deg, var(--accent), var(--accent-hover)); border-radius: 999px; }
.quota-bar { height: 5px; border-radius: 999px; }

/* ---------- Account and lane rows ---------- */
.overview-accounts, .account-list { gap: 0.6rem; }
.overview-account, .account-item, .active-account, .lane {
  border-radius: 10px;
  padding: 0.72rem 0.82rem;
}
.overview-account[data-active="true"], .account-item[data-active="true"] {
  border-color: rgba(231, 154, 95, 0.45);
  box-shadow: inset 2px 0 0 var(--accent);
}
.lane[data-state="down"] { border-color: rgba(240, 156, 156, 0.4); }
.account-avatar {
  border-radius: 9px;
  background: linear-gradient(145deg, rgba(231, 154, 95, 0.2), rgba(127, 183, 212, 0.1));
  border-color: rgba(231, 154, 95, 0.28);
}

.empty {
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.015);
}

.invite-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0 0 0.85rem;
}
.invite-input { max-width: 230px; min-height: 33px; }
.invite-row .note { margin: 0; }

.import-box { margin: 0 0 0.85rem; }
.import-box > summary { cursor: pointer; font-weight: 600; }
.import-box[open] > summary { margin-bottom: 0.6rem; }
.import-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 0.6rem;
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Dialogs and code ---------- */
dialog {
  border: 1px solid transparent;
  background:
    linear-gradient(180deg, #171c19, #111513) padding-box,
    linear-gradient(155deg, rgba(231, 154, 95, 0.3), rgba(255, 255, 255, 0.06)) border-box;
  border-radius: 14px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(5, 7, 6, 0.76); backdrop-filter: blur(3px); }
.code-block, #log-view, .docs-code { background: #080b0a; border-color: rgba(255, 255, 255, 0.06); }

/* ---------- Focus ---------- */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
.table-wrap:focus-visible, pre:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  /* One column means two rows. Left alone, the grid stretches BOTH rows to
     fill the viewport, which balloons the top bar on short pages and pushes
     the connection footer away from the nav. */
  .shell { grid-template-rows: max-content minmax(0, 1fr); }
  .sidebar { padding: 0.75rem 0.9rem; }
  .nav a { min-height: 40px; padding: 0 0.65rem; }
  .nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--accent); }
  /* The nav scrolls sideways with its scrollbar hidden: fade the trailing edge
     while more items remain (app.js clears it at the end of the scroll). */
  .nav[aria-label="Main navigation"] {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 2.25rem), transparent 100%);
    mask-image: linear-gradient(90deg, #000 calc(100% - 2.25rem), transparent 100%);
  }
  .nav[aria-label="Main navigation"][data-at-end="1"] {
    -webkit-mask-image: none;
    mask-image: none;
  }
  .content { padding: 0.9rem 0.9rem 1.6rem; }

  /* Tables become stacks of labelled cells: seven numeric columns cannot be
     read by scrolling sideways on a phone, and nothing said they could. */
  [data-page] .table-wrap { overflow: visible; }
  [data-page] table,
  [data-page="keys"] table,
  [data-page="requests"] table,
  [data-page="api-docs"] table { display: block; min-width: 0; }
  [data-page] thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  [data-page] tbody { display: grid; gap: 0.6rem; padding: 0.6rem; }
  [data-page] tbody:empty { display: none; }
  [data-page] tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem 0.9rem;
    padding: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
  }
  [data-page] td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  [data-page] td:first-child,
  [data-page] td.wide { grid-column: 1 / -1; }
  /* Endpoint cards read better with method and path sharing their first line. */
  [data-page] .stack-pairs td:first-child { grid-column: auto; }
  /* Reward cards: who + what on their own lines, the three numbers on one. */
  [data-page] .stack-3 tbody tr { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; }
  [data-page] .stack-3 td:first-child { font-weight: 600; }
  [data-page] td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0.14rem;
    font-size: 0.64rem;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
  }
  [data-page] td.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
  .docs-code { white-space: normal; overflow-wrap: anywhere; }
}
@media (max-width: 760px) {
  h1 { font-size: 1.25rem; }
  .overview-bottom { grid-template-columns: 1fr; }
  .lane-facts > div { grid-template-columns: 92px minmax(0, 1fr); }
  .account-main { flex: 1 1 100%; }
  /* Facts as a two-column grid: as a wrapping flex row, the last label was
     orphaned at the right edge with its value dropped onto a new line. */
  .account-item .account-facts,
  .active-account-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem 1rem;
    width: 100%;
    margin-left: 0;
  }
  .account-actions { width: 100%; }
  /* Keep name and points on one line. With a 260px flex-basis the row only
     wrapped for some names, so neighbouring cards had different heights. */
  .overview-account { flex-wrap: nowrap; }
  .overview-account .account-main { flex: 1 1 0; min-width: 0; }
  .overview-account .account-main > div { min-width: 0; }
}
@media (max-width: 620px) {
  .btn { min-height: 40px; }
  .btn.small { min-height: 36px; }
  .card, .stat-card, fieldset { padding: 0.75rem; }
}
@media (max-width: 460px) {
  /* Six stat cards in one column pushed every real number below the fold. */
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
  .stat-value { font-size: 1.3rem; }
}

/* ---------- Connect blocks ---------- */
/* Four connector cards read best as a balanced 2x2 grid. */
.connect-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 760px) {
  .connect-grid { grid-template-columns: 1fr; }
}
.connect-block { min-height: 118px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Key allowlist ---------- */
.model-lock { margin-top: 0.9rem; padding-top: 0.8rem; }
.model-picks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.35rem;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 0.4rem;
}
.pick {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font: 0.76rem var(--mono);
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.pick:hover { color: var(--text); border-color: var(--line-strong); }
.pick input { min-height: 0; width: 0.9rem; height: 0.9rem; }

/* ---------- Utilities ---------- */
.warn-text { color: var(--warn); }
/* Side-by-side cards only stretch to match their neighbour's content. */
.overview-bottom { align-items: start; }
