/* WCar admin dashboard — brand tokens, glass surfaces, layout, components. RTL, light theme.
   Sharp, square geometry; icons in neutral ink; orange reserved for primary actions and the active page. */

:root {
  color-scheme: light;
  /* Brand palette */
  --cream: #FDFBF3;
  --bg-top: #FFFFFF;
  --bg-bottom: #F8F4E9;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.88);
  --hairline: rgba(0, 0, 0, 0.08);
  --hairline-strong: rgba(0, 0, 0, 0.14);
  --ink: #191B1F;
  --ink-2: #3A3C41;
  --muted: #6B665C;
  --faint: #8F897D;
  --accent: #FF6704;
  --accent-hover: #EC5C00;
  --accent-ink: #C24E00;
  --accent-ring: rgba(255, 103, 4, 0.28);
  --good: #1FA971; --good-ink: #15845A; --good-soft: rgba(31, 169, 113, 0.12);
  --bad: #E63338;  --bad-ink: #C8242A;  --bad-soft: rgba(230, 51, 56, 0.10);
  --warn: #F5A623; --warn-ink: #A86A05; --warn-soft: rgba(245, 166, 35, 0.16);
  --tint: rgba(25, 27, 31, 0.05);       /* neutral fill for icon boxes, hovers, active nav */
  --tint-2: rgba(25, 27, 31, 0.08);
  --track: rgba(56, 46, 26, 0.08);
  --grid: rgba(56, 46, 26, 0.07);

  --shadow: 0 6px 20px rgba(56, 46, 26, 0.10);
  --shadow-sm: 0 1px 4px rgba(56, 46, 26, 0.08);
  --shadow-lg: 0 24px 60px rgba(56, 46, 26, 0.22);
  --r: 4px;        /* surfaces */
  --r-sm: 3px;     /* controls */
  --blur: saturate(1.4) blur(14px);
  --font: "IBM Plex Sans Arabic", "Tajawal", "Noto Sans Arabic", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--cream); overflow-x: hidden; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); overflow-x: hidden;
  font: 400 13.5px/1.6 var(--font);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--cream) 40%, var(--bg-bottom) 100%) fixed;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: url("/assets/watermark.svg") 0 0 / 360px 360px repeat;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
svg.i { width: 16px; height: 16px; flex: none; stroke-width: 1.8; }
.mono, code { font-family: var(--mono); font-size: .92em; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
.mono.path { display: inline-block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
[dir="rtl"] :is(div, td, dd, p).mono { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link { color: var(--accent-ink); font-weight: 500; }
.link:hover { text-decoration: underline; }

/* ---------- App shell ---------- */

.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }

.sidebar { position: sticky; top: 0; height: 100vh; padding: 14px 14px 14px 0; display: flex; flex-direction: column; }
.sidebar-inner {
  position: relative; flex: 1; display: flex; flex-direction: column; padding: 18px 12px 12px; min-height: 0; overflow-y: auto;
  background: var(--glass); border: 1px solid var(--hairline); border-radius: var(--r);
  box-shadow: var(--shadow); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 18px; margin-bottom: 10px; border-bottom: 1px solid var(--hairline); }
.brand img { width: 36px; height: 36px; border-radius: var(--r); flex: none; object-fit: contain; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

.nav { display: grid; gap: 2px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 12px; border-radius: var(--r-sm);
  color: var(--muted); font-weight: 500; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--tint); color: var(--ink); }
.nav-item.active { background: var(--tint-2); color: var(--ink); font-weight: 600; }
.nav-item.active::before { content: ""; position: absolute; inset-block: 8px; inset-inline-start: 0; width: 3px; background: var(--accent); }
.nav-count {
  margin-inline-start: auto; font-size: 11px; font-weight: 600; min-width: 24px; text-align: center;
  padding: 0 6px; border-radius: var(--r-sm); background: var(--tint); color: var(--muted);
}

.side-foot { margin-top: auto; padding-top: 14px; display: grid; gap: 8px; }
.side-status {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-sm);
  background: var(--glass-strong); border: 1px solid var(--hairline); font-size: 12.5px;
}
.side-status b { display: block; font-weight: 600; }
.side-status span { color: var(--muted); font-size: 11.5px; }
.pulse { width: 8px; height: 8px; background: var(--good); flex: none; box-shadow: 0 0 0 3px var(--good-soft); }
.pulse.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.pulse.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.side-logout {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 36px;
  border-radius: var(--r-sm); border: 1px solid var(--hairline); background: transparent;
  color: var(--muted); font: 500 12.5px var(--font); cursor: pointer;
}
.side-logout:hover { background: var(--glass-strong); color: var(--ink); }

.main { min-width: 0; display: flex; flex-direction: column; }
.scrim { display: none; }
.topbar { padding: 14px 14px 0; }
.topbar-inner { max-width: 1172px; margin: 0 auto; padding: 14px 20px; min-height: 68px; display: flex; align-items: center; gap: 14px; }
.topbar-inner > div:not(.top-actions) { flex: 1; min-width: 0; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.crumbs a:hover { color: var(--ink); }
.crumbs svg.i { width: 13px; height: 13px; }
.page-title { font-size: 18px; font-weight: 700; line-height: 1.35; }
.page-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.top-actions { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn.sidebar-btn { width: 36px; padding: 0; flex: none; }
.sidebar-btn .when-closed, html.sb-collapsed .sidebar-btn .when-open { display: none; }
html.sb-collapsed .sidebar-btn .when-closed { display: inline-flex; }
.sidebar-btn > span { display: inline-flex; }
.sidebar .drawer-close { display: none; }

/* Collapsed sidebar (desktop): an icon-only rail; labels come back as tooltips via title. */
@media (min-width: 921px) {
  .app { transition: grid-template-columns .2s ease; }
  html.sb-collapsed .app { grid-template-columns: 72px minmax(0, 1fr); }
  html.sb-collapsed .sidebar .label, html.sb-collapsed .nav-count { display: none; }
  html.sb-collapsed .sidebar-inner { padding-inline: 8px; }
  html.sb-collapsed .brand { justify-content: center; padding-inline: 0; }
  html.sb-collapsed .nav-item { justify-content: center; padding: 0; }
  html.sb-collapsed .side-status { justify-content: center; padding: 12px 0; }
}

.content { width: 100%; max-width: 1200px; margin: 0 auto; padding: 16px 14px 48px; display: grid; gap: 16px; align-content: start; min-width: 0; }

/* ---------- Layout helpers ---------- */

.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr); align-items: start; }
.stack { display: grid; gap: 16px; align-content: start; min-width: 0; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ---------- Card (glass surface) ---------- */

.card, .glass {
  background: var(--glass); border: 1px solid var(--hairline); border-radius: var(--r);
  box-shadow: var(--shadow); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--hairline); }
.card-title { font-size: 14px; font-weight: 600; }
.card-desc { font-size: 12px; color: var(--muted); margin-top: 1px; }
.card-head .end { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }
.card-body { padding: 16px 18px; }
.card-foot { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--hairline); }
.card-foot .end { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }

/* Square icon box: neutral ink by default; status tones only where the icon carries a state. */
.chip-icon, .head-icon {
  width: 32px; height: 32px; border-radius: var(--r-sm); display: grid; place-items: center; flex: none;
  background: var(--tint); color: var(--ink-2); border: 1px solid var(--hairline);
}
.chip-icon.good { background: var(--good-soft); color: var(--good-ink); border-color: transparent; }
.chip-icon.bad { background: var(--bad-soft); color: var(--bad-ink); border-color: transparent; }
.chip-icon.warn { background: var(--warn-soft); color: var(--warn-ink); border-color: transparent; }
.chip-icon.lg { width: 40px; height: 40px; }
.chip-icon.lg svg.i { width: 19px; height: 19px; }

/* ---------- Stat tiles ---------- */

.stat { padding: 14px 16px; display: grid; gap: 8px; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.stat-value.text { font-size: 17px; line-height: 1.6; letter-spacing: 0; }
.stat-foot { font-size: 12px; color: var(--muted); }
.stat-foot b { color: var(--ink); font-weight: 600; }

/* Home: headline card + titled groups of stat cards */
.hero { display: flex; align-items: center; gap: 18px; padding: 20px 22px; flex-wrap: wrap; }
.hero-main { flex: 1; min-width: 200px; }
.hero-value { font-size: 40px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; margin: 2px 0 4px; }
.hero-split { display: grid; grid-template-columns: repeat(3, minmax(88px, 1fr)); border: 1px solid var(--hairline); border-radius: var(--r-sm); background: var(--glass-strong); }
.hero-split div { padding: 10px 14px; text-align: center; }
.hero-split div + div { border-inline-start: 1px solid var(--hairline); }
.hero-split b { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hero-split span { font-size: 11.5px; color: var(--muted); }
.stat-group { display: grid; gap: 8px; }
.group-title { font-size: 12.5px; font-weight: 600; color: var(--muted); padding-inline-start: 2px; }

/* Settings summary strip */
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.summary > div { padding: 12px 16px; display: flex; align-items: center; gap: 10px; min-width: 0; }
.summary > div + div { border-inline-start: 1px solid var(--hairline); }
.summary .k { font-size: 11.5px; color: var(--muted); }
.summary .v { font-weight: 600; font-size: 13px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--hairline-strong); background: var(--glass-strong); color: var(--ink);
  font: 500 13px var(--font); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { background: #fff; border-color: rgba(0, 0, 0, .22); }
.btn:focus-visible, .input:focus-visible, .nav-item:focus-visible, .tab:focus-visible, .switch input:focus-visible + span, .icon-btn:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--accent-ring);
}
.btn svg.i { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.btn-danger:hover { background: #cf2a2f; border-color: #cf2a2f; }
.btn-danger-ghost { color: var(--bad-ink); }
.btn-danger-ghost:hover { background: var(--bad-soft); border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.icon-btn {
  width: 30px; height: 30px; display: inline-grid; place-items: center; border-radius: var(--r-sm);
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--tint); border-color: var(--hairline); color: var(--ink); }
.icon-btn.danger:hover { color: var(--bad-ink); background: var(--bad-soft); border-color: transparent; }
.icon-btn.good:hover { color: var(--good-ink); background: var(--good-soft); border-color: transparent; }
.icon-btn[disabled], .icon-btn[aria-disabled="true"] { opacity: .35; cursor: not-allowed; pointer-events: none; }
.icon-btn.sm { width: 24px; height: 24px; }
.icon-btn.sm svg.i { width: 13px; height: 13px; }
.actions { display: inline-flex; gap: 0; align-items: center; }
.actions form { display: contents; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; max-width: 100%;
  border-radius: var(--r-sm); font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--tint); color: var(--muted);
}
.badge svg.i { width: 12px; height: 12px; stroke-width: 2.2; }
.badge.dot::before { content: ""; width: 6px; height: 6px; background: currentColor; flex: none; }
.badge.good { background: var(--good-soft); color: var(--good-ink); }
.badge.bad { background: var(--bad-soft); color: var(--bad-ink); }
.badge.warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge.accent { background: var(--tint-2); color: var(--ink); }

/* ---------- Callouts & toast ---------- */

.callout {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--r);
  border: 1px solid var(--hairline); background: var(--glass); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
.callout b { display: block; font-weight: 600; font-size: 13.5px; }
.callout p { color: var(--muted); font-size: 12.5px; }
.callout .end { margin-inline-start: auto; }
.callout.bad { border-color: rgba(230, 51, 56, .28); background: rgba(255, 244, 243, .85); border-inline-start: 3px solid var(--bad); }
.callout.warn { border-color: rgba(245, 166, 35, .35); background: rgba(255, 249, 236, .9); border-inline-start: 3px solid var(--warn); }
.callout.good { border-color: rgba(31, 169, 113, .28); background: rgba(240, 251, 245, .85); border-inline-start: 3px solid var(--good); }

.toast {
  position: fixed; z-index: 60; top: 18px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: var(--r);
  background: var(--ink); color: #fff; box-shadow: var(--shadow-lg); font-weight: 500; font-size: 13px;
  animation: toast-in .25s ease-out; max-width: calc(100vw - 32px);
}
.toast svg.i { color: var(--good); }
.toast.bad { background: var(--bad); }
.toast.bad svg.i { color: #fff; }
.toast.hide { opacity: 0; visibility: hidden; pointer-events: none; transform: translate(-50%, -8px); transition: .3s; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } }

/* ---------- Tables (always fit the card — no horizontal scrolling) ---------- */

table.table { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th {
  text-align: start; font-weight: 500; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 10px 10px; background: rgba(248, 244, 233, .6); border-bottom: 1px solid var(--hairline);
}
.table td { padding: 10px 10px; border-bottom: 1px solid var(--hairline); vertical-align: middle; overflow: hidden; text-overflow: ellipsis; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: rgba(255, 255, 255, .7); }
.table th:first-child, .table td:first-child { padding-inline-start: 18px; }
.table th:last-child, .table td:last-child { padding-inline-end: 14px; }
.table .end { text-align: end; }
.sort { display: inline-flex; align-items: center; gap: 3px; color: inherit; }
.sort:hover { color: var(--ink); }
.sort svg.i { width: 12px; height: 12px; opacity: .45; }
.sort.on { color: var(--ink); font-weight: 600; }
.sort.on svg.i { opacity: 1; }
.cell-main { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-sub.cell-id { display: flex; align-items: center; gap: 2px; }
.cell-sub.ltr { text-align: right; }
.ltr-clip { display: block; direction: ltr; unicode-bidi: isolate; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-main[dir="auto"] { text-align: right; }
.row-link:hover .cell-main { color: var(--accent-ink); }

/* Columns that drop out on narrower screens, before the table turns into cards. */
@media (max-width: 1280px) { .table .col-wide { display: none; } }

/* ---------- Forms ---------- */

.field { display: grid; gap: 6px; }
.field + .field, .field + .form-row, .form-row + .field { margin-top: 14px; }
.field label, .label { font-size: 12.5px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); }
.input {
  width: 100%; height: 38px; padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid var(--hairline-strong); background: rgba(255, 255, 255, .92); color: var(--ink);
  font: 400 13.5px var(--font); transition: border-color .15s, box-shadow .15s;
}
.input:hover { border-color: rgba(0, 0, 0, .24); }
.input:focus { border-color: var(--ink-2); }
.input::placeholder { color: var(--faint); font-family: var(--font); }
textarea.input { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; line-height: 1.6; }
.input.mono { font-family: var(--mono); font-size: 13px; }
.input-icon { position: relative; }
.input-icon svg.i { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 15px; height: 15px; }
.input-icon .input { padding-inline-start: 36px; }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row > .field { margin-top: 0; }
.inline-form { display: flex; gap: 8px; align-items: end; }
.inline-form .field { flex: 1; min-width: 0; }

/* Segmented choice (radio / checkbox pills) */
.choice { display: flex; gap: 6px; flex-wrap: wrap; }
.choice label {
  position: relative; display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px;
  border-radius: var(--r-sm); border: 1px solid var(--hairline-strong); background: rgba(255, 255, 255, .92);
  font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer; transition: .15s;
}
.choice label svg.i { width: 14px; height: 14px; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice label:has(input:checked) { border-color: var(--ink); background: var(--ink); color: #fff; font-weight: 600; }
.choice label:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--accent-ring); }
.choice label:has(input:disabled) { opacity: .45; cursor: not-allowed; }

/* Toggle switch — square, knob moves toward the inline end when on (iOS RTL) */
.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { width: 42px; height: 22px; border-radius: var(--r-sm); background: rgba(56, 46, 26, .2); transition: background .2s; position: relative; }
.switch span::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px;
  border-radius: 2px; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s;
}
.switch input:checked + span { background: var(--ink); }
.switch.good input:checked + span { background: var(--good); }
.switch.bad input:checked + span { background: var(--bad); }
.switch.warn input:checked + span { background: var(--warn); }
.switch input:checked + span::after { transform: translateX(-20px); }

/* Setting row: icon + text + control */
.setting { display: flex; align-items: center; gap: 14px; padding: 14px 18px; }
.setting + .setting { border-top: 1px solid var(--hairline); }
.setting-text { flex: 1; min-width: 0; }
.setting-title { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.setting-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Tabs ---------- */

.tabs { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--r); background: var(--tint); border: 1px solid var(--hairline); flex-wrap: wrap; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 500; color: var(--muted); transition: background .15s, color .15s; white-space: nowrap;
}
.tab svg.i { width: 14px; height: 14px; }
.tab:hover { color: var(--ink); }
.tab.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
.tab .count { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tab.active .count { color: var(--ink); }

/* Page-level tabs (Settings): a full-width underline bar */
.page-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--hairline-strong); }
.page-tabs .tab { height: 40px; padding: 0 16px; border-radius: 0; background: transparent; box-shadow: none; font-size: 13px; position: relative; }
.page-tabs .tab.active { background: transparent; color: var(--ink); box-shadow: none; }
.page-tabs .tab.active::after { content: ""; position: absolute; inset-inline: 0; bottom: -1px; height: 2px; background: var(--accent); }

.toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--hairline); flex-wrap: wrap; }
.toolbar .search { margin-inline-start: auto; width: min(300px, 100%); }

/* ---------- Key-value & list rows ---------- */

.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); margin: 0; }
.kv dt, .kv dd { margin: 0; padding: 10px 0; border-bottom: 1px solid var(--hairline); }
.kv dt { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; }
.kv dd { font-weight: 500; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; min-width: 0; }
.kv dd .mono { overflow-wrap: anywhere; white-space: normal; }
[dir="rtl"] .kv dd.mono { justify-content: flex-end; }
.kv dt:last-of-type, .kv dd:last-of-type { border-bottom: 0; }

.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px; font-size: 13px; }
.list-row + .list-row { border-top: 1px solid var(--hairline); }
.list-row .k { color: var(--muted); display: flex; align-items: center; gap: 8px; min-width: 0; }
.list-row .v { font-weight: 600; }

/* ---------- Meter (versions table) ---------- */

.meter { height: 6px; background: var(--track); overflow: hidden; min-width: 40px; }
.meter > span { display: block; height: 100%; background: var(--ink-2); }

/* ---------- Empty state ---------- */

.empty { display: grid; place-items: center; text-align: center; gap: 8px; padding: 40px 20px; color: var(--muted); }
.empty .chip-icon { width: 44px; height: 44px; }
.empty b { color: var(--ink); font-size: 14px; }

/* Notification preview (iOS banner) */
.preview { border-radius: var(--r); padding: 16px 14px; margin-top: 16px; background: linear-gradient(160deg, #F3E9D6, #EADFC8); border: 1px solid var(--hairline); }
.preview-label { font-size: 11.5px; color: var(--muted); margin-bottom: 10px; text-align: center; }
.ios-banner {
  display: flex; gap: 10px; align-items: start; padding: 10px 12px; border-radius: 16px; max-width: 340px; margin: 0 auto;
  background: rgba(255, 255, 255, .8); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: 0 8px 24px rgba(56, 46, 26, .16);
}
.ios-banner img { width: 34px; height: 34px; border-radius: 8px; flex: none; }
.ios-banner .t-col { flex: 1; min-width: 0; }
.ios-banner .t-row { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--muted); }
.ios-banner .t { font-weight: 600; font-size: 13.5px; color: var(--ink); }
.ios-banner .m { font-size: 13px; white-space: pre-line; overflow-wrap: anywhere; }

/* ---------- Code block & copy ---------- */

.copy-field { display: flex; gap: 8px; align-items: center; }
.copy-field .input { direction: ltr; text-align: left; min-width: 0; }

/* ---------- Dialog ---------- */

dialog.modal {
  border: 1px solid var(--hairline); padding: 0; border-radius: var(--r); width: min(420px, calc(100vw - 32px));
  background: rgba(255, 255, 255, .96); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(25, 27, 31, .32); backdrop-filter: blur(3px); }
.modal-body { padding: 22px 22px 6px; display: grid; gap: 8px; justify-items: start; }
.modal-title { font-size: 15.5px; font-weight: 700; }
.modal-text { color: var(--muted); font-size: 13px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 16px 22px 20px; }
dialog.modal.wide { width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); }
dialog.modal.wide form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--hairline); }
.modal-head .modal-title { flex: 1; }
.modal-scroll { padding: 16px 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--hairline); }

/* ---------- Pager ---------- */

.pager { display: flex; align-items: center; gap: 4px; }
.pager-info { font-size: 12px; color: var(--muted); }
.page-num { min-width: 30px; height: 30px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: var(--r-sm); font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.page-num:hover { background: var(--tint); color: var(--ink); }
.page-num.on { background: var(--ink); color: #fff; font-weight: 600; }
.page-num.gap { pointer-events: none; }

/* ---------- Login ---------- */

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); padding: 32px 28px 24px; display: grid; gap: 18px; }
.login-card .brand { padding: 0; margin: 0; border: 0; justify-content: center; flex-direction: column; text-align: center; gap: 12px; }
.login-card .brand img { width: 52px; height: 52px; }
.login-title { font-size: 18px; font-weight: 700; }
.login-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.login-foot { text-align: center; font-size: 11.5px; color: var(--faint); }
.form-error { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: var(--r-sm); background: var(--bad-soft); color: var(--bad-ink); font-size: 12.5px; font-weight: 500; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary > div:nth-child(3) { border-inline-start: 0; }
  .summary > div:nth-child(n + 3) { border-top: 1px solid var(--hairline); }
  .grid-main { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 920px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: 268px; z-index: 50; padding: 10px; transform: translateX(105%); visibility: hidden; transition: transform .25s ease, visibility 0s .25s; }
  .nav-open .sidebar { visibility: visible; transition: transform .25s ease; }
  .sidebar .drawer-close { display: inline-grid; position: absolute; top: 18px; inset-inline-end: 18px; z-index: 1; }
  html.sb-collapsed .sidebar-btn .when-open { display: inline-flex; }
  html.sb-collapsed .sidebar-btn .when-closed { display: none; }
  .sidebar-inner { background: rgba(255, 255, 255, .96); }
  .nav-open .sidebar { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(25, 27, 31, .3); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .nav-open .scrim { opacity: 1; pointer-events: auto; }
  .topbar { padding: 10px 10px 0; }
  .topbar-inner { padding: 12px 14px; min-height: 60px; flex-wrap: wrap; }
  .content { padding: 12px 10px 40px; gap: 12px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .page-title { font-size: 16.5px; }
}

/* Tables become stacked cards on phones: every value stays visible, nothing scrolls sideways. */
@media (max-width: 760px) {
  table.table, .table tbody { display: block; }
  .table thead { display: none; }
  .table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 12px; padding: 12px 14px; border-bottom: 1px solid var(--hairline); }
  .table tr:last-child { border-bottom: 0; }
  .table td, .table th:first-child, .table td:first-child, .table td:last-child { padding: 0; border: 0; }
  .table td[data-label]::before { content: attr(data-label); display: block; font: 500 11px var(--font); direction: rtl; text-align: right; color: var(--muted); margin-bottom: 1px; }
  .table td.end:has(> .actions:empty), .table td.phone-hide { display: none; }
  .table td.primary { grid-column: 1 / -1; }
  .table td.end { grid-column: 1 / -1; text-align: start; border-top: 1px dashed var(--hairline); padding-top: 6px; }
  .table .col-wide { display: block; }
}
@media (max-width: 600px) {
  .stats { gap: 10px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 22px; }
  .hero { padding: 16px; }
  .hero-value { font-size: 32px; }
  .hero-split { width: 100%; }
  .form-row { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: 100px minmax(0, 1fr); }
  .card-head, .card-body, .setting, .list-row, .nlog, .card-foot { padding-inline: 14px; }
    .card-head:has(.tabs) { flex-wrap: wrap; }
  .card-head .end:has(.tabs) { margin-inline-start: 0; width: 100%; }
  .toolbar { padding-inline: 14px; }
  .toolbar .search { width: 100%; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .top-actions { width: 100%; }
  .summary { grid-template-columns: minmax(0, 1fr); }
  .summary > div + div { border-inline-start: 0; border-top: 1px solid var(--hairline); }
  .page-tabs { overflow: hidden; }
  .page-tabs .tab { padding: 0 10px; flex: 1; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
