/* ==========================================================================
   Kelid (کلید) · Customer Console
   Design system: neutral surfaces, subtle borders, one restrained accent.
   ========================================================================== */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f6f6f7;
  --surface-3: #efeff1;
  --text: #111113;
  --text-2: #55575e;
  --text-3: #8a8c94;
  --border: #e7e7ea;
  --border-strong: #d3d3d9;
  --accent: #3b4fd8;
  --accent-hover: #2f40b8;
  --accent-soft: #eef0fd;
  --accent-text: #2f40b8;
  --success: #167a4a;
  --success-soft: #e8f5ee;
  --danger: #c0352b;
  --danger-soft: #fbeceb;
  --warning: #9a5b00;
  --warning-soft: #fdf3e1;
  --primary-btn: #111113;
  --primary-btn-hover: #2a2a2e;
  --primary-btn-text: #ffffff;
  --overlay: rgba(17, 17, 19, 0.38);
  --shadow-pop: 0 8px 28px rgba(17, 17, 19, 0.12), 0 1px 3px rgba(17, 17, 19, 0.08);
  --shadow-drawer: -12px 0 32px rgba(17, 17, 19, 0.1);
  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);

  --font: Inter, Vazirmatn, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --topbar-h: 52px;
  --sidebar-w: 216px;
  --radius: 8px;
  --radius-sm: 6px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

:root { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0c0e;
  --surface: #141417;
  --surface-2: #1a1a1e;
  --surface-3: #232328;
  --text: #ededf0;
  --text-2: #a4a6ae;
  --text-3: #6f717a;
  --border: #26262b;
  --border-strong: #37373d;
  --accent: #7c8cff;
  --accent-hover: #97a4ff;
  --accent-soft: #1b1e38;
  --accent-text: #a6b1ff;
  --success: #4cc38a;
  --success-soft: #10241b;
  --danger: #f0776e;
  --danger-soft: #2b1614;
  --warning: #e6a441;
  --warning-soft: #2a2010;
  --primary-btn: #ededf0;
  --primary-btn-hover: #ffffff;
  --primary-btn-text: #111113;
  --overlay: rgba(0, 0, 0, 0.6);
  --shadow-pop: 0 8px 28px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --shadow-drawer: -12px 0 32px rgba(0, 0, 0, 0.5);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0c0e;
    --surface: #141417;
    --surface-2: #1a1a1e;
    --surface-3: #232328;
    --text: #ededf0;
    --text-2: #a4a6ae;
    --text-3: #6f717a;
    --border: #26262b;
    --border-strong: #37373d;
    --accent: #7c8cff;
    --accent-hover: #97a4ff;
    --accent-soft: #1b1e38;
    --accent-text: #a6b1ff;
    --success: #4cc38a;
    --success-soft: #10241b;
    --danger: #f0776e;
    --danger-soft: #2b1614;
    --warning: #e6a441;
    --warning-soft: #2a2010;
    --primary-btn: #ededf0;
    --primary-btn-hover: #ffffff;
    --primary-btn-text: #111113;
    --overlay: rgba(0, 0, 0, 0.6);
    --shadow-pop: 0 8px 28px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);
    --shadow-drawer: -12px 0 32px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden], .hidden { display: none !important; }
:focus { outline: none; }
:focus-visible { box-shadow: var(--focus); border-radius: var(--radius-sm); }
.skip-link { position: absolute; inset-inline-start: 8px; top: 8px; transform: translateY(-200%); z-index: 300; background: var(--surface); padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); }
.skip-link:focus { transform: none; }

.mono { font-family: var(--mono); font-size: 0.92em; letter-spacing: -0.01em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.right { text-align: end; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }

[data-icon] { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ico { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 500; font-size: 13px; white-space: nowrap; position: relative;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { background: var(--surface-3); }
.btn.primary { background: var(--primary-btn); border-color: var(--primary-btn); color: var(--primary-btn-text); }
.btn.primary:hover { background: var(--primary-btn-hover); border-color: var(--primary-btn-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(0.92); }
.btn.danger-ghost { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn.danger-ghost:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn.block { width: 100%; height: 36px; }
.btn[disabled], .btn.is-loading { opacity: 0.55; pointer-events: none; }
.btn.is-loading .btn-label { visibility: hidden; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.6s linear infinite;
}
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.sm { width: 24px; height: 24px; }
.link-btn { border: 0; background: transparent; padding: 0; color: var(--accent-text); font-weight: 500; }
.link-btn:hover { text-decoration: underline; }
.text-link { color: var(--accent-text); font-weight: 500; }
.text-link:hover { text-decoration: underline; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Form controls ---------- */
.field { display: grid; gap: 6px; }
.field > label, .field-label { font-size: 13px; font-weight: 500; }
.hint { font-size: 12px; color: var(--text-3); }
.field-error { font-size: 12px; color: var(--danger); }
.input, .select {
  height: 32px; width: 100%; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
textarea.input { height: auto; padding: 8px 10px; }
.input::placeholder { color: var(--text-3); }
.input:hover, .select:hover { border-color: var(--text-3); }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.select { appearance: none; padding-right: 26px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%238a8c94' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; cursor: pointer; }
.select.has-value, .input.has-value { border-color: color-mix(in srgb, var(--accent) 55%, var(--border-strong)); background-color: var(--accent-soft); }
.input-group { position: relative; display: flex; }
.input-group .input { padding-inline-end: 36px; }
.input-addon { position: absolute; inset-inline-end: 2px; top: 2px; width: 28px; height: 28px; border: 0; border-radius: 4px; background: transparent; color: var(--text-3); display: grid; place-items: center; }
.input-addon:hover { color: var(--text); background: var(--surface-3); }
.input-icon { position: relative; }
.input-icon > [data-icon], .input-icon > .ico { position: absolute; inset-inline-start: 9px; top: 8px; color: var(--text-3); pointer-events: none; }
.input-icon .input { padding-inline-start: 30px; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; padding: 4px 0; }
.check input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 2px 12px; }
.chip-input { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; min-height: 32px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
.chip-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.chip-input input { flex: 1; min-width: 120px; border: 0; background: transparent; outline: none; padding: 2px 6px; height: 22px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding-block: 0; padding-inline: 8px 4px; border-radius: 4px; background: var(--surface-3); font-family: var(--mono); font-size: 12px; }
.chip button { border: 0; background: transparent; width: 16px; height: 16px; padding: 0; border-radius: 3px; color: var(--text-3); display: grid; place-items: center; }
.chip button:hover { color: var(--text); background: var(--border-strong); }

.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--radius-sm); background: var(--surface-3); flex-wrap: wrap; }
.seg button { height: 26px; padding: 0 10px; border: 0; border-radius: 4px; background: transparent; color: var(--text-2); font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border-strong); }
.seg .count { margin-inline-start: 5px; color: var(--text-3); font-weight: 400; font-variant-numeric: tabular-nums; }

/* ---------- Badges & status ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: 10px; font-size: 11.5px; font-weight: 500; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge.plain::before { display: none; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.info { background: var(--accent-soft); color: var(--accent-text); }
.badge.live::before { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.success { background: var(--success); }
.dot.warning { background: var(--warning); }
.dot.danger { background: var(--danger); }

.http { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.http::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.http.s2 { color: var(--success); } .http.s2::before { background: var(--success); }
.http.s3, .http.s4 { color: var(--warning); } .http.s3::before, .http.s4::before { background: var(--warning); }
.http.s5, .http.err { color: var(--danger); } .http.s5::before, .http.err::before { background: var(--danger); }
.http.pending { color: var(--text-2); } .http.pending::before { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.fo-mark { display: inline-flex; vertical-align: middle; margin-inline-start: 6px; }
.method { font-family: var(--mono); font-size: 11.5px; font-weight: 600; color: var(--text-2); letter-spacing: 0.02em; }
.tag { display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: 4px; border: 1px solid var(--border); font-size: 11.5px; color: var(--text-2); background: var(--surface); white-space: nowrap; }
.tag.mono { font-family: var(--mono); font-size: 11px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.auth-wrap { width: 100%; max-width: 380px; display: grid; gap: 22px; justify-items: center; }
.auth-brand { font-size: 15px; }
.auth-card { width: 100%; display: grid; gap: 16px; padding: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.auth-card h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.auth-card .muted { margin-top: 2px; font-size: 13px; }
.auth-switch { text-align: center; font-size: 13px; color: var(--text-2); }
.auth-foot { display: flex; align-items: center; gap: 10px; width: 100%; font-size: 12.5px; }
.auth-foot a:hover { color: var(--text); text-decoration: underline; }
.inline-alert { padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px; background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent); }
.inline-alert.info { background: var(--accent-soft); color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.inline-alert.warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }

/* ---------- Brand / topbar ---------- */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: -0.01em; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--text); color: var(--bg); display: inline-grid; place-items: center; }
.brand-mark .ico { width: 13px; height: 13px; stroke-width: 2; }
.brand-text { display: inline-flex; align-items: baseline; gap: 7px; white-space: nowrap; line-height: 1.2; }
.brand-fa { font-family: "Vazirmatn", system-ui, sans-serif; font-weight: 600; letter-spacing: 0; line-height: 1.2; color: var(--text-3); border-inline-start: 1px solid var(--border); padding-inline-start: 7px; }
.app { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 60; height: var(--topbar-h); display: flex; align-items: center; gap: 10px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.crumb-sep { color: var(--border-strong); font-size: 18px; font-weight: 300; margin: 0 -2px; }
.project-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; max-width: 320px; padding-block: 0; padding-inline: 10px 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; font-weight: 500;
}
.project-btn:hover, .project-btn[aria-expanded="true"] { background: var(--surface-3); }
.project-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-btn .chev { color: var(--text-3); }
.search-trigger {
  display: inline-flex; align-items: center; gap: 8px; height: 30px; width: 240px; padding-block: 0; padding-inline: 10px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-3); font-size: 13px;
}
.search-trigger:hover { border-color: var(--border-strong); color: var(--text-2); }
.search-label { flex: 1; text-align: start; }
kbd { font: 500 11px var(--mono); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); background: var(--surface); color: var(--text-3); }
.top-link { padding: 0 8px; color: var(--text-2); font-weight: 500; }
.top-link:hover { color: var(--text); }
.avatar-btn { border: 0; padding: 0; background: transparent; border-radius: 50%; }
.avatar-btn span { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-3); border: 1px solid var(--border-strong); font-size: 12px; font-weight: 600; color: var(--text-2); }
.avatar-btn:hover span { border-color: var(--text-3); }
.nav-toggle { display: none; margin-inline-start: -6px; }

/* ---------- Shell / sidebar ---------- */
.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
  position: sticky; top: var(--topbar-h); align-self: flex-start; width: var(--sidebar-w); flex: none; height: calc(100vh - var(--topbar-h));
  display: flex; flex-direction: column; justify-content: space-between; padding: 12px 10px; overflow-y: auto; border-inline-end: 1px solid var(--border); background: var(--surface);
}
.nav-group { margin: 18px 8px 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.nav-item { position: relative; display: flex; align-items: center; gap: 9px; height: 30px; padding: 0 8px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500; font-size: 13.5px; }
.nav-item [data-icon] { color: var(--text-3); }
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--surface-3); color: var(--text); }
.nav-item.active [data-icon] { color: var(--accent); }
.nav-item.active::before { content: ""; position: absolute; inset-inline-start: -10px; top: 6px; bottom: 6px; width: 2px; border-radius: 2px; background: var(--accent); }
.sidebar-foot { padding: 8px; font-size: 12.5px; }
.sidebar-foot a { display: flex; align-items: center; gap: 8px; color: var(--text-3); }
.sidebar-foot a:hover { color: var(--text); }
.scrim { display: none; }
main { flex: 1; min-width: 0; }
.view { max-width: 1160px; margin: 0 auto; padding: 28px 28px 72px; animation: view-in 0.16s var(--ease); }
.view.switching { animation: none; opacity: 0.45; transition: opacity 0.12s; }
@keyframes view-in { from { opacity: 0; transform: translateY(3px); } }

/* ---------- Page structure ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-title h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; }
.page-desc { margin-top: 3px; color: var(--text-2); font-size: 13.5px; max-width: 640px; }
.page-head > div:first-child { flex: 1 1 360px; min-width: 0; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: none; }
.ctx { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }
.ctx b { color: var(--text); font-weight: 500; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h2 { font-size: 14px; font-weight: 600; }
.section-head .sub { font-size: 12.5px; color: var(--text-3); margin-inline-start: 8px; font-weight: 400; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }

.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.panel-pad { padding: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-head h2, .panel-head h3 { font-size: 14px; font-weight: 600; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .input-icon { width: 260px; }
.toolbar .select { width: auto; min-width: 128px; }
.toolbar .date-input { width: 132px; }
.toolbar .toolbar-end { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.toolbar .filters { display: contents; }
.filter-toggle { display: none; }
.clear-filters { font-size: 12.5px; }

/* ---------- Metrics ---------- */
.metrics { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.metric { padding: 12px 14px; border-inline-end: 1px solid var(--border); min-width: 0; }
.metric:last-child { border-inline-end: 0; }
.metric-label { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.metric-value { margin-top: 3px; font-size: 20px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-sub { margin-top: 1px; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; min-height: 18px; }
.delta { font-size: 12px; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--text-2); } .delta.good { color: var(--success); } .delta.bad { color: var(--danger); }

/* ---------- Chart ---------- */
.chart-panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px 0; }
.chart-title { display: flex; align-items: baseline; gap: 10px; }
.chart-title strong { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.chart-title span { font-size: 12.5px; color: var(--text-3); }
.chart { direction: ltr; position: relative; display: grid; grid-template-columns: 44px 1fr; grid-template-rows: 1fr auto; height: 232px; padding: 16px 16px 10px 12px; }
.chart-y { position: relative; }
.chart-y span { position: absolute; right: 8px; transform: translateY(50%); font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.chart-plot { position: relative; border-bottom: 1px solid var(--border-strong); }
.chart-grid { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--border); }
.chart-bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.bar-col { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; position: relative; }
.bar-col:hover { background: var(--surface-2); }
.bar { width: 100%; border-radius: 2px 2px 0 0; background: var(--accent); min-height: 0; transition: height 0.25s var(--ease); opacity: 0.88; }
.bar-col:hover .bar { opacity: 1; }
.bar.zero { height: 1px !important; background: var(--border-strong); opacity: 1; }
.chart.err .bar { background: var(--danger); }
.chart-x { grid-column: 2; display: flex; justify-content: space-between; margin-top: 6px; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; min-width: 120px; padding: 7px 10px; border-radius: var(--radius-sm); background: var(--text); color: var(--bg); font-size: 12px; box-shadow: var(--shadow-pop); transform: translate(-50%, -100%); white-space: nowrap; }
.chart-tip b { display: block; font-variant-numeric: tabular-nums; font-size: 13px; }
.chart-empty { position: absolute; inset: 16px 16px 30px 56px; display: grid; place-items: center; text-align: center; color: var(--text-3); font-size: 13px; pointer-events: none; }

/* ---------- Tables ---------- */
.table-wrap { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface); }
.table-wrap.boxed { border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.data th {
  position: sticky; top: var(--topbar-h); z-index: 2; height: 34px; padding: 0 9px; text-align: start; white-space: nowrap;
  font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
table.data th.right, table.data td.right { text-align: end; }
table.data th button { border: 0; background: transparent; padding: 0; font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit; display: inline-flex; align-items: center; gap: 4px; }
table.data th button:hover { color: var(--text); }
table.data th button .ico { width: 11px; height: 11px; opacity: 0.35; }
table.data th button[data-dir] .ico { opacity: 1; color: var(--text); }
table.data td { white-space: nowrap; height: 42px; padding: 6px 9px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:focus-visible { outline: none; box-shadow: none; }
table.data tr.clickable:focus-visible td { background: var(--accent-soft); }
table.data tr.selected td { background: var(--accent-soft); }
table.data tr.dim td { opacity: 0.55; }
table.data tr.dim:hover td { opacity: 1; }
table.data td.strong { font-weight: 500; }
.cell-2 { display: grid; gap: 1px; min-width: 0; }
.cell-2 .sub { font-size: 12px; color: var(--text-3); }
.unit { font-size: 11.5px; color: var(--text-3); margin-inline-start: 3px; font-family: var(--font); }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; font-size: 12.5px; color: var(--text-2); border-top: 1px solid var(--border); flex-wrap: wrap; }
.table-foot .pager { display: flex; align-items: center; gap: 6px; }
.row-actions { display: flex; justify-content: flex-end; }
table.data th:last-child:empty, table.data td.right:last-child .row-actions { padding: 0; }
table.data td:has(.row-actions) { width: 1%; padding-inline: 0 8px; }

/* ---------- Skeletons / empty / error ---------- */
.sk { display: block; height: 12px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 45%, var(--surface-3) 65%); background-size: 300% 100%; animation: shimmer 1.3s linear infinite; }
.sk.h-lg { height: 24px; } .sk.h-chart { height: 100%; border-radius: var(--radius-sm); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.sk-table td { height: 42px; }
.empty { display: grid; justify-items: center; gap: 6px; padding: 44px 20px; text-align: center; }
.empty .empty-icon { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-3); margin-bottom: 6px; }
.empty .empty-icon .ico { width: 18px; height: 18px; }
.empty h3 { font-size: 14px; font-weight: 600; }
.empty p { color: var(--text-2); font-size: 13px; max-width: 380px; }
.empty .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }
.empty.compact { padding: 28px 16px; }
.error-state { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border)); background: var(--danger-soft); border-radius: var(--radius); color: var(--text); }
.error-state .ico { color: var(--danger); width: 18px; height: 18px; }
.error-state .msg { flex: 1; min-width: 0; }
.error-state strong { display: block; font-size: 13.5px; }
.error-state span { font-size: 12.5px; color: var(--text-2); }

/* ---------- Overview extras ---------- */
.quickstart { margin-bottom: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.quickstart-head { padding: 16px 18px 4px; }
.quickstart-head h2 { font-size: 15px; font-weight: 600; }
.quickstart-head p { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.steps { display: grid; grid-template-columns: 240px 1fr; gap: 0; }
.steps ol { list-style: none; margin: 0; padding: 14px 18px 18px; display: grid; gap: 4px; align-content: start; }
.step { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-size: 13px; }
.step .n { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border-strong); display: grid; place-items: center; font-size: 11px; font-weight: 600; flex: none; }
.step.done .n { background: var(--success); border-color: var(--success); color: #fff; }
.step.current { background: var(--surface-2); color: var(--text); }
.step.current .n { border-color: var(--accent); color: var(--accent); }
.step b { display: block; font-weight: 500; color: var(--text); }
.quickstart-code { padding-block: 14px 18px; padding-inline: 0 18px; min-width: 0; }
.kv-side { display: grid; gap: 0; }
.kv-side .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.kv-side .row:last-child { border-bottom: 0; }
.kv-side .row span:first-child { color: var(--text-2); }
.side-block + .side-block { margin-top: 24px; }
.side-title { font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); margin-bottom: 6px; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; position: relative; margin: 8px 0 6px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.3s var(--ease); }
.meter.warn > i { background: var(--warning); } .meter.bad > i { background: var(--danger); }
.attn { display: grid; gap: 2px; }
.attn-item { display: flex; gap: 8px; align-items: flex-start; padding: 8px 8px; margin: 0 -8px; border-radius: var(--radius-sm); font-size: 13px; width: calc(100% + 16px); border: 0; background: transparent; text-align: start; }
button.attn-item:hover { background: var(--surface-2); }
.attn-item .dot { margin-top: 6px; }
.attn-item .sub { display: block; font-size: 12px; color: var(--text-3); }
.ok-line { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; padding: 4px 0; }
.ok-line .ico { color: var(--success); }

/* ---------- Code block ---------- */
.code { position: relative; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.code pre { direction: ltr; text-align: left; margin: 0; padding: 12px 14px; overflow-x: auto; font: 12.5px/1.6 var(--mono); tab-size: 2; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding-block: 6px; padding-inline: 14px 8px; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text-3); }
.copy-btn { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px; border: 0; border-radius: 4px; background: transparent; color: var(--text-2); font-size: 12px; font-weight: 500; }
.copy-btn:hover { background: var(--surface-3); color: var(--text); }
.copy-btn.copied { color: var(--success); }
.copy-inline { border: 0; background: transparent; padding: 2px; border-radius: 4px; color: var(--text-3); display: inline-grid; place-items: center; vertical-align: middle; }
.copy-inline:hover { color: var(--text); background: var(--surface-3); }
.copy-inline.copied { color: var(--success); }
.secret-box { display: flex; align-items: center; gap: 8px; padding-block: 10px; padding-inline: 14px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.secret-box code { direction: ltr; text-align: left; flex: 1; min-width: 0; font: 13px/1.5 var(--mono); word-break: break-all; user-select: all; }

/* ---------- Key list specifics ---------- */
.key-name { font-weight: 500; }
.key-mask { font-family: var(--mono); font-size: 12.5px; color: var(--text-2); letter-spacing: 0.01em; }
.restr { font-size: 12px; color: var(--text-3); }

/* ---------- Model catalog ---------- */
.caps { display: flex; gap: 4px; flex-wrap: wrap; }
.price-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.provider-name { display: inline-flex; align-items: center; gap: 6px; }
.pdot { width: 8px; height: 8px; border-radius: 2px; flex: none; background: var(--text-3); }
.pdot.openai { background: #10a37f; } .pdot.xai { background: #6b7280; } .pdot.gemini { background: #4285f4; } .pdot.byteplus { background: #d9480f; }

/* ---------- Settings ---------- */
.settings-section { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 32px; padding: 24px 0; border-top: 1px solid var(--border); }
.settings-section:first-of-type { border-top: 0; padding-top: 4px; }
.settings-section h2 { font-size: 14px; font-weight: 600; }
.settings-section > div:first-child p { margin-top: 4px; font-size: 13px; color: var(--text-2); }
.form-grid { display: grid; gap: 16px; max-width: 480px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-actions { display: flex; gap: 8px; align-items: center; }
.prefix-input { position: relative; }
.prefix-input > span { position: absolute; left: 10px; top: 5px; color: var(--text-3); }
.prefix-input .input { padding-left: 22px; font-variant-numeric: tabular-nums; }
.danger-zone { border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); border-radius: var(--radius); }
.danger-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; flex-wrap: wrap; }
.danger-row strong { font-weight: 500; display: block; }
.danger-row span { font-size: 13px; color: var(--text-2); }
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 0; margin: 0; font-size: 13px; }
.kv dt, .kv dd { padding: 9px 0; border-bottom: 1px solid var(--border); margin: 0; min-width: 0; }
.kv dt { color: var(--text-2); }
.kv dd { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; word-break: break-word; }
.kv dt:last-of-type, .kv dd:last-of-type { border-bottom: 0; }

/* ---------- Docs cards ---------- */
.doc-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.doc-link { display: block; padding: 14px 16px; border-inline-end: 1px solid var(--border); border-bottom: 1px solid var(--border); margin-block: 0 -1px; margin-inline: 0 -1px; }
.doc-link:hover { background: var(--surface-2); }
.doc-link strong { display: flex; align-items: center; justify-content: space-between; font-weight: 500; font-size: 13.5px; }
.doc-link strong .ico { color: var(--text-3); width: 14px; height: 14px; }
.doc-link span { display: block; margin-top: 2px; font-size: 12.5px; color: var(--text-2); }

/* ---------- Popovers / menus ---------- */
.popover { position: fixed; z-index: 120; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow-pop); animation: pop-in 0.12s var(--ease); overflow: hidden; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.985); } }
.menu { padding: 4px; min-width: 200px; }
.menu-item { display: flex; align-items: center; gap: 9px; width: 100%; padding: 0 10px; height: 30px; border: 0; border-radius: 4px; background: transparent; text-align: start; font-size: 13px; color: var(--text); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-3); box-shadow: none; }
.menu-item [data-icon] { color: var(--text-3); }
.menu-item.danger { color: var(--danger); } .menu-item.danger [data-icon] { color: var(--danger); }
.menu-item[disabled] { opacity: 0.45; pointer-events: none; }
.menu-sep { height: 1px; margin: 4px -4px; background: var(--border); }
.menu-label { padding: 8px 10px 4px; font-size: 12px; color: var(--text-3); }
.menu-head { padding: 10px 12px; border-bottom: 1px solid var(--border); margin: -4px -4px 4px; }
.menu-head strong { display: block; font-weight: 500; }
.menu-head span { font-size: 12.5px; color: var(--text-2); }
.project-menu { width: 340px; max-width: calc(100vw - 16px); }
.project-menu .search { padding: 8px; border-bottom: 1px solid var(--border); }
.project-list { max-height: 300px; overflow-y: auto; padding: 4px; }
.project-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 0; border-radius: 4px; background: transparent; text-align: start; }
.project-item:hover, .project-item:focus-visible { background: var(--surface-3); box-shadow: none; }
.project-item .info { flex: 1; min-width: 0; }
.project-item .info b { display: block; font-weight: 500; }
.project-item .info span { font-size: 12px; color: var(--text-3); }
.project-item .check-mark { color: var(--accent); }
.project-foot { padding: 4px; border-top: 1px solid var(--border); }

/* ---------- Modal / drawer ---------- */
.overlay { position: fixed; inset: 0; z-index: 150; background: var(--overlay); animation: fade-in 0.15s ease; }
@keyframes fade-in { from { opacity: 0; } }
.modal { position: fixed; z-index: 160; left: 50%; top: 12vh; width: 520px; max-width: calc(100vw - 24px); max-height: 82vh; display: flex; flex-direction: column; transform: translateX(-50%); background: var(--surface); border-radius: 10px; border: 1px solid var(--border); box-shadow: var(--shadow-pop); animation: modal-in 0.16s var(--ease); }
@keyframes modal-in { from { opacity: 0; transform: translate(-50%, 8px) scale(0.985); } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 4px; }
.modal-head h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.modal-head p { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.modal-body { padding: 14px 20px; overflow-y: auto; display: grid; gap: 16px; }
.modal-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 10px 10px; }
.modal-foot .left { margin-inline-end: auto; }
.drawer { position: fixed; z-index: 160; top: 0; inset-inline-end: 0; bottom: 0; width: 520px; max-width: 100vw; display: flex; flex-direction: column; background: var(--surface); border-inline-start: 1px solid var(--border); box-shadow: var(--shadow-drawer); animation: drawer-in 0.2s var(--ease); }
.drawer.closing { animation: drawer-out 0.15s ease-in forwards; }
.overlay.closing { animation: fade-out 0.15s ease-in forwards; }
@keyframes drawer-in { from { transform: translateX(28px); opacity: 0; } }
@keyframes drawer-out { to { transform: translateX(28px); opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
.drawer-head { display: flex; align-items: flex-start; gap: 10px; padding: 14px 16px 0; }
.drawer-head .titles { flex: 1; min-width: 0; }
.drawer-head h2 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.drawer-sub { display: flex; align-items: center; gap: 4px; margin-top: 3px; font-size: 12.5px; color: var(--text-2); }
.drawer-tabs { display: flex; gap: 2px; padding: 10px 12px 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
.drawer-tabs button { position: relative; height: 32px; padding: 0 10px; border: 0; background: transparent; color: var(--text-2); font-weight: 500; font-size: 13px; white-space: nowrap; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.drawer-tabs button:hover { color: var(--text); }
.drawer-tabs button[aria-selected="true"] { color: var(--text); }
.drawer-tabs button[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: 8px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 20px; align-content: start; }
.drawer-body h3 { font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); margin-bottom: 4px; }
.drawer-foot { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; background: var(--surface-2); }
.callout { display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; border: 1px solid var(--border); background: var(--surface-2); }
.callout .ico { flex: none; margin-top: 2px; }
.callout.warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, transparent); color: var(--text); }
.callout.warning .ico { color: var(--warning); }
.callout.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.callout.danger .ico { color: var(--danger); }
.callout.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.callout.info .ico { color: var(--accent); }
.callout strong { font-weight: 500; }
.disclosure { border: 1px solid var(--border); border-radius: var(--radius); }
.disclosure > button { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 10px 12px; border: 0; background: transparent; font-weight: 500; font-size: 13px; text-align: start; border-radius: var(--radius); }
.disclosure > button:hover { background: var(--surface-2); }
.disclosure > button .ico { transition: transform 0.15s; color: var(--text-3); }
.disclosure > button[aria-expanded="true"] .ico { transform: rotate(180deg); }
.disclosure-body { display: none; padding: 4px 12px 14px; gap: 16px; }
.disclosure > button[aria-expanded="true"] + .disclosure-body { display: grid; }

/* Routing timeline */
.route { display: grid; gap: 0; }
.route-node { position: relative; display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: start; padding: 0 0 18px; }
.route-node:last-child { padding-bottom: 0; }
.route-node::before { content: ""; position: absolute; inset-inline-start: 11px; top: 26px; bottom: 2px; width: 2px; background: var(--border-strong); }
.route-node:last-child::before { display: none; }
.route-icon { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.route-icon .ico { width: 13px; height: 13px; stroke-width: 2; }
.route-node.ok .route-icon { background: var(--success-soft); color: var(--success); }
.route-node.fail .route-icon { background: var(--danger-soft); color: var(--danger); }
.route-node .who b { font-weight: 500; }
.route-node .who div { font-size: 12.5px; color: var(--text-3); }
.usage-bars { display: grid; gap: 0; }
.usage-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.usage-row:last-child { border-bottom: 0; }
.usage-row span:first-child { color: var(--text-2); }
.usage-row.zero { color: var(--text-3); }
.json-view { max-height: 320px; overflow: auto; }
.param-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.param-table th { text-align: start; font-weight: 500; color: var(--text-3); padding-block: 6px; padding-inline: 0 8px; border-bottom: 1px solid var(--border); font-size: 11.5px; }
.param-table td { padding-block: 7px; padding-inline: 0 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.param-table tr:last-child td { border-bottom: 0; }
.feature-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; }
.feature { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; }
.feature .ico { width: 14px; height: 14px; }
.feature.on .ico { color: var(--success); } .feature.off { color: var(--text-3); } .feature.off .ico { color: var(--text-3); }

/* ---------- Command palette ---------- */
.palette { position: fixed; z-index: 170; left: 50%; top: 14vh; width: 560px; max-width: calc(100vw - 24px); transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-pop); overflow: hidden; animation: modal-in 0.14s var(--ease); }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 48px; border-bottom: 1px solid var(--border); color: var(--text-3); }
.palette-input input { flex: 1; border: 0; background: transparent; outline: none; font-size: 15px; color: var(--text); }
.palette-list { max-height: 340px; overflow-y: auto; padding: 6px; }
.palette-group { padding: 8px 10px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); }
.palette-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: var(--radius-sm); background: transparent; text-align: start; font-size: 13.5px; }
.palette-item [data-icon] { color: var(--text-3); }
.palette-item[aria-selected="true"] { background: var(--surface-3); }
.palette-item .hint { margin-inline-start: auto; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 200; inset-inline-end: 16px; bottom: 16px; display: grid; gap: 8px; justify-items: end; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: 380px; padding: 10px 12px; border-radius: var(--radius); background: var(--text); color: var(--bg); font-size: 13px; box-shadow: var(--shadow-pop); animation: toast-in 0.18s var(--ease); }
.toast.out { animation: toast-out 0.16s ease-in forwards; }
.toast .ico { width: 15px; height: 15px; flex: none; }
.toast.success .ico { color: #4cc38a; } .toast.error .ico { color: #f0776e; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .table-wrap { overflow-x: auto; }
  table.data th { position: static; }
}
@media (max-width: 1180px) {
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric:nth-child(3n) { border-inline-end: 0; }
  .metric:nth-child(-n + 3) { border-bottom: 1px solid var(--border); }
  .two-col { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1100px) {
  .nav-toggle { display: inline-grid; }
  .sidebar { position: fixed; z-index: 140; top: var(--topbar-h); inset-inline-start: 0; bottom: 0; height: auto; transform: translateX(-100%); transition: transform 0.2s var(--ease); box-shadow: none; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  body.nav-open .scrim { display: block; position: fixed; z-index: 130; inset: var(--topbar-h) 0 0 0; background: var(--overlay); animation: fade-in 0.15s; }
  .nav-item.active::before { inset-inline-start: -10px; }
  .view { padding: 20px 16px 56px; }
  .search-label, .search-trigger kbd { display: none; }
  .search-trigger { width: 32px; padding: 0; justify-content: center; border-color: transparent; background: transparent; }
  .table-wrap { overflow-x: auto; }
  table.data th { position: static; }
  table.data { min-width: 720px; }
  .steps { grid-template-columns: 1fr; }
  .quickstart-code { padding: 0 18px 18px; }
  .settings-section { grid-template-columns: 1fr; gap: 14px; }
}
@media (max-width: 640px) {
  .hide-sm { display: none !important; }
  .topbar { padding: 0 10px; gap: 6px; }
  .brand-name, .crumb-sep { display: none; }
  .project-btn { max-width: 34vw; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(3n) { border-inline-end: 1px solid var(--border); }
  .metric:nth-child(2n) { border-inline-end: 0; }
  .metric:nth-child(-n + 3) { border-bottom: 0; }
  .metric:nth-child(-n + 4) { border-bottom: 1px solid var(--border); }
  .chart { height: 200px; grid-template-columns: 36px 1fr; }
  .toolbar { gap: 6px; }
  .toolbar .input-icon { width: 100%; }
  .filter-toggle { display: inline-flex; }
  .toolbar .filters { display: none; width: 100%; flex-direction: column; align-items: stretch; }
  .toolbar .filters.open { display: flex; }
  .toolbar .filters .select, .toolbar .filters .input { width: 100% !important; }
  .modal { top: auto; bottom: 0; left: 0; transform: none; width: 100%; max-width: 100%; max-height: 92vh; border-radius: 12px 12px 0 0; animation: sheet-in 0.2s var(--ease); }
  .modal-foot { border-radius: 0; }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
  .drawer { width: 100vw; border-inline-start: 0; }
  .form-grid.two { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px minmax(0, 1fr); }
  .palette { top: 8vh; }
  .toasts { inset-inline: 12px; bottom: 12px; justify-items: stretch; }
  .toast { max-width: none; }
  .page-head { align-items: flex-start; }
  .feature-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ==========================================================================
   Billing
   ========================================================================== */
.page-tabs { display: flex; gap: 4px; margin: -4px 0 20px; border-bottom: 1px solid var(--border); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.page-tabs::-webkit-scrollbar { display: none; }
.page-tabs a { position: relative; padding: 8px 10px 10px; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.page-tabs a:hover { color: var(--text); }
.page-tabs a[aria-current="page"] { color: var(--text); }
.page-tabs a[aria-current="page"]::after { content: ""; position: absolute; inset-inline: 6px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
.page-sub { margin-bottom: 14px; }
.inline-check { padding: 0 6px; }
.amt-pos { color: var(--success); }
.stat { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); white-space: nowrap; }
.stat i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.stat.success i { background: var(--success); }
.stat.danger i { background: var(--danger); }
.stat.live i { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }

/* Balance header */
.bal-panel { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding: 20px 22px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.bal-amount { margin: 6px 0 4px; font-size: 40px; line-height: 1.1; font-weight: 600; letter-spacing: -0.03em; font-family: var(--font); }
.bal-sub { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 13px; }
.hold { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); }
.metrics.m4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metrics.m4 .metric { border-bottom: 0; border-inline-end: 1px solid var(--border); }
.metrics.m4 .metric:last-child { border-inline-end: 0; }

/* Tooltip */
.tip { position: relative; display: inline-grid; place-items: center; vertical-align: -3px; margin-inline-start: 3px; color: var(--text-3); cursor: help; }
.tip .ico { width: 13px; height: 13px; }
.tip::after {
  content: attr(data-tip); position: absolute; z-index: 30; left: 50%; bottom: calc(100% + 6px); width: max-content; max-width: 240px; padding: 6px 9px; border-radius: var(--radius-sm);
  background: var(--text); color: var(--bg); font-size: 12px; line-height: 1.4; font-weight: 400; text-align: start; white-space: normal; transform: translateX(-50%); opacity: 0; pointer-events: none; transition: opacity 0.12s;
}
.tip:hover::after, .tip:focus-visible::after { opacity: 1; }
.tip:hover, .tip:focus-visible { color: var(--text-2); }

/* Balance chip in the top bar */
.balance-chip { flex: none; display: inline-flex; align-items: center; height: 30px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; }
.bal-link { display: inline-flex; align-items: center; gap: 8px; height: 100%; padding: 0 10px; font-size: 13px; }
.bal-link:hover { background: var(--surface-2); }
.bal-label { color: var(--text-3); }
.bal-link b { font-family: var(--font); font-weight: 600; }
.bal-plus { display: grid; place-items: center; width: 28px; height: 100%; border-inline-start: 1px solid var(--border); color: var(--text-2); }
.bal-plus:hover { background: var(--surface-3); color: var(--text); }
.balance-chip.is-zero { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.balance-chip.is-zero .bal-plus { background: var(--accent-soft); color: var(--accent-text); }

/* Add funds */
.topup { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 32px; align-items: start; }
.topup-title { font-size: 16px; font-weight: 600; }
.amounts { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.amount { height: 52px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; transition: border-color 0.12s, background 0.12s, box-shadow 0.12s; }
.amount:hover:not([disabled]) { border-color: var(--text-3); background: var(--surface-2); }
.amount.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); box-shadow: 0 0 0 1px var(--accent); }
.amount[disabled] { opacity: 0.4; cursor: not-allowed; }
.howto { margin: 24px 0 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; color: var(--text-2); font-size: 13px; }
.howto li { counter-increment: s; position: relative; padding-inline-start: 28px; }
.howto li::before { content: counter(s); position: absolute; inset-inline-start: 0; top: 0; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--border-strong); display: grid; place-items: center; font-size: 11px; font-weight: 600; color: var(--text-3); }
.howto b { color: var(--text); font-weight: 500; }
.topup-summary { position: sticky; top: calc(var(--topbar-h) + 20px); padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-height: 200px; }
.sum-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.sum-status { font-size: 12px; }
.lock { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; transition: color 0.2s; }
.lock .ico { width: 13px; height: 13px; }
.lock.soon { color: var(--warning); }
.lock.expired { color: var(--danger); }
.sum-receive { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.sum-receive > span { color: var(--text-2); }
.sum-receive b { font-size: 18px; font-weight: 600; font-family: var(--font); }
.sum-lines { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; margin: 0; padding: 12px 0; font-size: 13px; }
.sum-lines dt { color: var(--text-2); }
.sum-lines dd { margin: 0; text-align: end; }
.sum-total { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 12px 0 4px; border-top: 1px solid var(--border-strong); }
.sum-total > span { font-weight: 500; }
.sum-total b { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; font-family: var(--font); }
.sum-total small { margin-inline-start: 5px; font-size: 13px; font-weight: 500; color: var(--text-2); letter-spacing: 0; }
.sum-rate { margin: 8px 0 16px; font-size: 12px; color: var(--text-2); }
.sum-note { margin-top: 10px; text-align: center; }
.stale { opacity: 0.45; }
.sum-empty { display: grid; justify-items: center; gap: 10px; padding: 26px 8px; text-align: center; color: var(--text-3); font-size: 13px; }
.sum-empty .ico { width: 22px; height: 22px; }
.sum-empty b { color: var(--text); font-weight: 500; }
.sum-skel { display: grid; gap: 12px; margin-bottom: 16px; }
.sk-row { display: flex; justify-content: space-between; }
.sum-skel .sum-receive { border: 0; padding-bottom: 0; }

/* Payment result */
.result { max-width: 520px; margin: 28px auto; padding: 28px 28px 24px; text-align: center; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); animation: view-in 0.2s var(--ease); }
.result-icon { width: 44px; height: 44px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.result-icon .ico { width: 22px; height: 22px; }
.result-icon.success { background: var(--success-soft); color: var(--success); }
.result-icon.danger { background: var(--danger-soft); color: var(--danger); }
.result-icon.info { background: var(--accent-soft); color: var(--accent-text); }
.result h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.result > p { margin-top: 6px; font-size: 14px; }
.result-kv { margin-top: 18px; text-align: start; }
.result-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; }

/* Payment timeline */
.timeline { list-style: none; margin: 4px 0 0; padding: 0; display: grid; }
.timeline li { position: relative; display: grid; grid-template-columns: 16px 1fr; gap: 10px; padding-bottom: 14px; font-size: 13px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: 7px; top: 14px; bottom: -2px; width: 2px; background: var(--border-strong); }
.timeline li:last-child::before { display: none; }
.tl-dot { width: 10px; height: 10px; margin: 4px 3px 0; border-radius: 50%; background: var(--border-strong); }
.timeline li.done .tl-dot { background: var(--success); }
.timeline li.fail .tl-dot { background: var(--danger); }
.timeline li.todo { color: var(--text-3); }
.timeline b { display: block; font-weight: 500; }
.timeline li .faint { font-size: 12px; }

@media (max-width: 880px) {
  .topup { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .topup-summary { position: static; }
}
@media (max-width: 760px) {
  .metrics.m4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics.m4 .metric:nth-child(2n) { border-inline-end: 0; }
  .metrics.m4 .metric:nth-child(-n + 2) { border-bottom: 1px solid var(--border); }
  .metrics.m4 .metric:nth-child(3) { border-inline-end: 1px solid var(--border); }
}
@media (max-width: 640px) {
  .bal-amount { font-size: 34px; }
  .bal-panel { padding: 16px; }
  .bal-panel > .btn { width: 100%; height: 36px; }
  .amounts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .amount { height: 48px; }
  .bal-label { display: none; }
  .bal-link { padding: 0 8px; }
  .sum-total b { font-size: 24px; }
  .topup-summary { padding: 14px; }
  .topup-summary > .btn.block { position: sticky; bottom: 12px; z-index: 5; box-shadow: var(--shadow-pop); }
  .result { margin: 12px auto; padding: 22px 16px; border: 0; background: transparent; }
  /* Compact rows for transaction tables */
  .table-wrap:has(table.stack) { overflow-x: visible; }
  table.data.stack { min-width: 0; }
  table.data.stack thead { display: none; }
  table.data.stack tbody { display: block; }
  table.data.stack tr { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "a b" "c d"; gap: 3px 12px; padding: 11px 12px; border-bottom: 1px solid var(--border); }
  table.data.stack tr:last-child { border-bottom: 0; }
  table.data.stack td { display: block; height: auto; padding: 0; border: 0; white-space: normal; }
  table.data.stack .m-a { grid-area: a; font-weight: 500; text-align: start; }
  table.data.stack .m-b { grid-area: b; text-align: end; }
  table.data.stack .m-c { grid-area: c; font-size: 12px; color: var(--text-3); }
  table.data.stack .m-d { grid-area: d; text-align: end; font-size: 12px; color: var(--text-2); }
  table.data.stack .m-x { display: none; }
}

/* ==========================================================================
   Preferences (theme / language)
   ========================================================================== */
.pref-btn { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: transparent; color: var(--text-2); font-size: 12px; font-weight: 600; }
.pref-btn:hover { background: var(--surface-3); color: var(--text); }
.pref-btn .ico { width: 14px; height: 14px; }
.auth-foot .icon-btn.sm { width: 28px; height: 28px; }

/* ==========================================================================
   Right-to-left (Persian)
   Layout mirrors through the logical properties above; these rules cover what
   can't: physical icons/animations, and LTR islands (ids, money, code, inputs).
   ========================================================================== */
html[lang="fa"] * { letter-spacing: 0 !important; }
html[lang="fa"] :is(.eyebrow, .nav-group, .side-title, .drawer-body h3, table.data th, .palette-group) { text-transform: none; font-size: 12px; }
[dir="rtl"] .select { padding-right: 10px; padding-left: 26px; background-position: left 9px center; }
[dir="rtl"] .dir-icon { transform: scaleX(-1); }
[dir="rtl"] .drawer { box-shadow: 12px 0 32px rgba(17, 17, 19, 0.1); animation-name: drawer-in-rtl; }
[dir="rtl"] .drawer.closing { animation-name: drawer-out-rtl; }
@keyframes drawer-in-rtl { from { transform: translateX(-28px); opacity: 0; } }
@keyframes drawer-out-rtl { to { transform: translateX(-28px); opacity: 0; } }
@media (max-width: 1100px) {
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  [dir="rtl"] body.nav-open .sidebar { transform: none; }
}
/* Identifiers, amounts and code keep their left-to-right order inside Persian text. */
[dir="rtl"] :is(span, b, strong, code, small, a, i, em).mono,
[dir="rtl"] :is(span, b, strong, small).num,
[dir="rtl"] .key-mask, [dir="rtl"] kbd { unicode-bidi: isolate; direction: ltr; }
[dir="rtl"] :is(td, div, dd, p).mono, [dir="rtl"] td.num { unicode-bidi: plaintext; }
[dir="rtl"] table.data td { text-align: right; }
[dir="rtl"] table.data td.right { text-align: left; }
/* Emails, secrets, amounts and IDs are typed left-to-right. */
[dir="rtl"] :is(input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[inputmode="decimal"], .chip-input input, .chip) { direction: ltr; text-align: left; }
[dir="rtl"] .prefix-input > span { left: 10px; right: auto; }
[dir="rtl"] .input-group .input { padding-right: 10px; padding-left: 36px; }
[dir="rtl"] .input-group .input-addon { right: auto; left: 2px; }
/* Server messages may be English: let each message pick its own direction. */
[dir="rtl"] :is(.inline-alert, .field-error, .error-state .msg span, .toast span, .attn-item .sub) { unicode-bidi: plaintext; }
/* The chart stays left-to-right (time flows left → right); its Persian date labels still read right-to-left. */
[dir="rtl"] :is(.chart-x span, .chart-tip, .chart-empty) { unicode-bidi: plaintext; }
