/* ==========================================================================
   CityOs CPMS — design system
   Layers: 1 tokens · 2 base · 3 layout · 4 components · 5 modules · 6 responsive
   Theming: light is the default; html[data-theme="dark"] re-maps semantic tokens.
   ========================================================================== */

/* ---------- 1. Tokens ---------------------------------------------------- */

:root {
  color-scheme: light;

  /* primitive ramps */
  --navy-950: #061421;
  --navy-900: #0b1f33;
  --navy-800: #123c63;
  --navy-700: #1b4b76;
  --navy-600: #2c6394;
  --gray-0: #ffffff;
  --gray-50: #f6f8fb;
  --gray-100: #eef2f7;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-500: #64748b;
  --gray-550: #556678;
  --gray-600: #4b6076;
  --gray-700: #334759;
  --gray-900: #0f1e2e;
  --teal-100: #d7f2ec;
  --teal-300: #6ee7d5;
  --teal-500: #14a08c;
  --teal-600: #0d9488;
  --teal-700: #0f766e;
  --amber-100: #fdf0d5;
  --amber-500: #d97706;
  --amber-600: #8f4407;
  --rose-100: #fbe3e7;
  --rose-500: #d1394f;
  --rose-600: #b02a3e;
  --green-600: #05663f;
  --sky-600: #0b6b9c;

  /* surfaces */
  --bg: var(--gray-50);
  --bg-2: var(--gray-100);
  --bg-3: var(--gray-0);
  --surface: var(--gray-0);
  --surface-2: var(--gray-100);
  --surface-hover: var(--gray-200);
  --panel: var(--gray-0);
  --panel-strong: var(--gray-0);
  --bg-hover: var(--gray-200);
  --overlay: rgba(6, 20, 33, 0.55);

  /* lines */
  --border: var(--gray-200);
  --border-strong: var(--gray-300);

  /* text */
  --text: var(--gray-900);
  --text-secondary: var(--gray-700);
  --text-muted: var(--gray-550);
  --muted: var(--gray-600);

  /* brand + actions */
  --primary: var(--navy-900);
  --primary-hover: var(--navy-800);
  --primary-ink: #ffffff;
  --accent: var(--teal-600);
  --accent-ink: var(--teal-700);
  --accent-soft: var(--teal-100);
  --accent-2: var(--amber-500);
  --accent-3: var(--sky-600);

  /* semantic status */
  --success: var(--green-600);
  --success-soft: #dcf5e8;
  --warning: var(--amber-600);
  --warning-soft: var(--amber-100);
  --danger: var(--rose-600);
  --danger-soft: var(--rose-100);
  --info: var(--sky-600);
  --info-soft: #dbeefb;

  /* button primitives */
  --btn-primary-bg: var(--primary);
  --btn-primary-fg: var(--primary-ink);
  --btn-primary-bg-hover: var(--primary-hover);
  --btn-secondary-bg: var(--gray-0);
  --btn-secondary-fg: var(--text);
  --btn-secondary-bg-hover: var(--gray-100);
  --btn-warning-bg: var(--warning);
  --btn-warning-fg: #ffffff;
  --btn-warning-bg-hover: #7d3c05;

  /* elevation */
  --shadow-xs: 0 1px 2px rgba(15, 30, 46, 0.06);
  --shadow-sm: 0 1px 3px rgba(15, 30, 46, 0.08), 0 1px 2px rgba(15, 30, 46, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 30, 46, 0.08), 0 1px 3px rgba(15, 30, 46, 0.05);
  --shadow-lg: 0 12px 32px rgba(15, 30, 46, 0.12), 0 2px 6px rgba(15, 30, 46, 0.06);
  --shadow: var(--shadow-md);
  --shadow-soft: var(--shadow-sm);

  /* radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-pill: 999px;
  --radius: var(--radius-md);

  /* spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 2.5rem;
  --space-8: 3rem;
  --space-10: 4rem;

  /* typography */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --text-2xs: 0.6875rem;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.25rem;
  --leading-tight: 1.2;
  --leading-normal: 1.55;

  /* motion */
  --dur-fast: 120ms;
  --dur-base: 180ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);

  /* chrome */
  --nav-width: 260px;
  --header-height: 60px;
  --content-max: 1440px;
  --target-min: 24px;
  --print-bg: var(--gray-0);
  --print-ink: #000000;
  --z-nav: 40;
  --z-header: 30;
  --z-overlay: 60;
  --z-toast: 80;
  --focus-ring: 0 0 0 3px rgba(20, 160, 140, 0.35);
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0a0e1a;
  --bg-2: #111827;
  --bg-3: #0a0e1a;
  --surface: #111827;
  --surface-2: #1a2235;
  --surface-hover: #243049;
  --panel: #1a2235;
  --panel-strong: #111827;
  --bg-hover: #243049;
  --overlay: rgba(2, 10, 18, 0.7);

  --border: #2a3550;
  --border-strong: #3b82f6;

  --text: #e5e7eb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --muted: #9ca3af;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-ink: #ffffff;
  --accent: #3b82f6;
  --accent-ink: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --accent-2: #f59e0b;
  --accent-3: #8b5cf6;

  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.15);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.15);

  --btn-primary-bg: #3b82f6;
  --btn-primary-fg: #ffffff;
  --btn-primary-bg-hover: #2563eb;
  --btn-secondary-bg: #1a2235;
  --btn-secondary-fg: var(--text);
  --btn-secondary-bg-hover: #243049;
  --btn-warning-bg: #b45309;
  --btn-warning-fg: #fff7ed;
  --btn-warning-bg-hover: #d97706;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.35);
}

/* ---------- 2. Base ------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

body::before {
  display: none;
}

body.auth-locked {
  overflow: hidden;
}

body.nav-locked {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
h4,
strong {
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--text);
}

h1 {
  font-size: var(--text-3xl);
  line-height: var(--leading-tight);
}

h2 {
  font-size: var(--text-xl);
  line-height: var(--leading-tight);
}

h3 {
  font-size: var(--text-md);
}

h4 {
  font-size: var(--text-base);
}

p {
  margin: 0;
}

a {
  color: var(--accent-ink);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code,
pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.eyebrow {
  margin: 0 0 var(--space-2);
  color: var(--accent-ink);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: var(--text-xs);
  font-weight: 700;
}

.section-label {
  margin: 0 0 var(--space-2);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: var(--text-xs);
  font-weight: 700;
}

.lede {
  max-width: 68ch;
  margin: var(--space-3) 0 0;
  color: var(--muted);
  line-height: var(--leading-normal);
}

.note {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.meta-chip strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---------- 3. Layout ---------------------------------------------------- */

.shell {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 650;
}

.skip-link:focus {
  top: var(--space-4);
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding-block: var(--space-6);
}

.app-shell {
  display: block;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--header-height);
  padding: var(--space-2) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
  padding-block: var(--space-5) var(--space-8);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  margin-right: auto;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  line-height: var(--leading-tight);
}

.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-secondary);
}

.nav-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.brand-name {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: flex-end;
}

.header-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.hero {
  grid-column: 1 / -1;
  position: relative;
  overflow: hidden;
  margin-top: var(--space-4);
}

.hero::before,
.hero::after {
  display: none;
}

.hero-top,
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: flex-start;
}

.panel-head {
  margin-bottom: var(--space-4);
}

.panel-head.slim {
  margin-bottom: var(--space-3);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
  min-width: 0;
}

.app-nav {
  display: flex;
  flex-direction: column;
  padding: var(--space-3) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.nav-inner {
  display: grid;
  gap: var(--space-1);
  align-content: start;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.nav-footer {
  display: grid;
  gap: var(--space-1);
  flex: none;
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.nav-user-role {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-user-role strong {
  color: var(--text);
}

.nav-user-desc {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.nav-collapse {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding: 0.4rem var(--space-2);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 650;
}

.nav-collapse:hover,
.nav-collapse:focus-visible {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-nav);
  background: var(--overlay);
}

.panel,
.card {
  scroll-margin-top: calc(var(--header-height) + var(--space-6));
}

.detail {
  display: grid;
  gap: var(--space-4);
  min-width: 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.full-span {
  grid-column: 1 / -1;
}

/* 3.4 Module views — the nav shows one module at a time instead of scrolling a
   seven-screen page. `body[data-view]` is written by applyView() in app.js. */
.view-hidden {
  display: none !important;
}

body[data-view]:not([data-view="panel-fleet"]) .panel.detail {
  grid-column: 1 / -1;
}

body[data-view="panel-sessions"] #panel-sessions,
body[data-view="panel-events"] #panel-events {
  grid-column: 1 / -1;
}

.admin-grid > .admin-card:not(.view-hidden) {
  grid-column: 1 / -1;
}

/* Fleet search row */
.fleet-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.fleet-tools .field-wrap {
  flex: 1 1 12rem;
  min-width: 0;
}

.fleet-filters {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.fleet-filters select {
  width: auto;
  min-width: 9.5rem;
}

.fleet-summary {
  min-height: 1.25rem;
  margin-bottom: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

/* ---------- 4. Components ------------------------------------------------ */

/* 4.1 Buttons */
.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0.6rem 1rem;
  min-height: 2.375rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.btn:hover {
  text-decoration: none;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  box-shadow: var(--shadow-xs);
}

.btn-primary:hover {
  background: var(--btn-primary-bg-hover);
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-fg);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--btn-secondary-bg-hover);
}

.btn-warning {
  background: var(--btn-warning-bg);
  color: var(--btn-warning-fg);
}

.btn-warning:hover {
  background: var(--btn-warning-bg-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-sm {
  min-height: 1.875rem;
  padding: 0.3rem 0.7rem;
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}

.btn.is-loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--btn-primary-fg);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

/* 4.2 Forms */
input,
select,
textarea {
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.7rem;
  min-height: 2.375rem;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

textarea {
  min-height: 5rem;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--gray-500);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

input[disabled],
select[disabled],
textarea[disabled] {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}

input[type="checkbox"],
input[type="radio"] {
  /* Chrome renders these at their intrinsic glyph size and ignores padding, so the
     only way to give the control itself a 24px target is to size it at 24px. */
  width: 1.5rem;
  height: 1.5rem;
  min-height: 0;
  /* Inside a flex label (e.g. .anme-check) a narrow viewport shrinks the box back to
     its 13px intrinsic width, so keep the 24px target from being compressed. */
  flex: 0 0 auto;
  padding: 0;
  accent-color: var(--accent);
}

/* WCAG 2.2 SC 2.5.8: both the 24px box and its label carry a full-size hit area. */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--target-min);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 550;
  cursor: pointer;
}

label {
  display: grid;
  gap: var(--space-1);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 600;
}

.field {
  display: grid;
  gap: var(--space-1);
}

.field-label {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 600;
}

.field-error {
  color: var(--danger);
  font-size: var(--text-xs);
  font-weight: 600;
}

.required-mark {
  color: var(--danger);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border: 0;
  background: transparent;
  padding: 0;
  min-height: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.switch::before {
  content: "";
  width: 36px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--surface-hover);
  border: 1px solid var(--border-strong);
  transition: background-color var(--dur-base) var(--ease);
}

.switch::after {
  content: "";
  width: 14px;
  height: 14px;
  margin-left: -32px;
  margin-right: 18px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: transform var(--dur-base) var(--ease);
}

.switch[aria-checked="true"]::before {
  background: var(--accent);
  border-color: var(--accent);
}

.switch[aria-checked="true"]::after {
  transform: translateX(16px);
}

.admin-form {
  display: grid;
  gap: var(--space-3);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

/* 4.3 Surfaces */
.panel,
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.panel {
  padding: var(--space-5);
}

.card {
  padding: var(--space-4) var(--space-5);
}

.card h3 {
  margin-bottom: var(--space-3);
}

.card-body {
  display: grid;
  gap: var(--space-3);
}

.stat-card,
.command-card,
.admin-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: var(--space-4);
  box-shadow: var(--shadow-xs);
}

.command-card,
.admin-card {
  display: grid;
  gap: var(--space-3);
}

.command-card h4,
.admin-card h4 {
  font-size: var(--text-md);
}

.command-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.command-card button {
  margin-top: auto;
}

/* 4.4 Status + badges */
.status-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.status-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--gray-500);
  flex: none;
}

.status-connected {
  background: var(--success);
}

.status-warning {
  background: var(--amber-500);
}

.status-danger {
  background: var(--rose-500);
}

.status-unknown {
  background: var(--gray-500);
}

.badge,
.cp-item-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge-neutral {
  color: var(--text-muted);
}

.badge-success,
.badge-active,
.badge-charging {
  border-color: transparent;
  background: var(--success-soft);
  color: var(--success);
}

.badge-warning,
.badge-maintenance {
  border-color: transparent;
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-danger {
  border-color: transparent;
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-info {
  border-color: transparent;
  background: var(--info-soft);
  color: var(--info);
}

/* 4.5 Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}

.data-table caption {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.data-table th,
.data-table td {
  padding: 0.625rem var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover td {
  background: var(--surface-2);
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table .actions {
  display: flex;
  gap: var(--space-1);
  justify-content: flex-end;
  white-space: nowrap;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.pagination-btns {
  display: flex;
  gap: var(--space-1);
}

/* 4.6 Tabs */
.anme-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.anme-tab {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  min-height: 2.125rem;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.anme-tab:hover,
.anme-tab:focus-visible {
  color: var(--text);
  background: var(--surface-hover);
}

.anme-tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* 4.7 Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: var(--overlay);
}

.modal {
  width: min(560px, 100%);
  max-height: calc(100vh - var(--space-8));
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.modal-head,
.modal-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
}

.modal-head {
  border-bottom: 1px solid var(--border);
}

.modal-foot {
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-body {
  padding: var(--space-4);
  display: grid;
  gap: var(--space-3);
}

/* 4.8 Tooltip */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  max-width: 22rem;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--navy-950);
  color: var(--primary-ink);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease);
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
}

/* 4.9 Toast */
.toast {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: var(--z-toast);
  min-width: 280px;
  max-width: min(480px, calc(100vw - var(--space-6)));
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-strong);
  background: var(--panel-strong);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: var(--text-base);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease), transform var(--dur-base) var(--ease);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

.toast.error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.toast.info {
  border-color: var(--info);
  background: var(--info-soft);
  color: var(--info);
}

/* 4.10 Empty + loading states */
.empty-state {
  display: grid;
  gap: var(--space-2);
  justify-items: center;
  padding: var(--space-5) var(--space-3);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

.skeleton {
  position: relative;
  overflow: hidden;
  min-height: 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--surface-hover), transparent);
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-row {
  min-height: 56px;
  border-radius: var(--radius-md);
}

.skeleton-block {
  min-height: 64px;
  border-radius: var(--radius-md);
}

.filter-label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 160px;
}

/* 4.11 Definition lists */
.kv-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin: 0;
}

/* Label and value share a row so a 12-field panel reads as a scannable table
   instead of a 12-block stack. */
.kv-row {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}

.kv-row:last-child {
  border-bottom: 0;
}

.kv-list dt {
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.kv-row dd {
  margin: 0;
  color: var(--text);
  font-size: var(--text-base);
  overflow-wrap: break-word;
}

@media (max-width: 480px) {
  .kv-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

/* ---------- 5. Modules --------------------------------------------------- */

/* 5.1 Login */
.login-card {
  display: grid;
  gap: var(--space-5);
  width: min(960px, 100%);
  padding: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.login-card.split {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  align-items: center;
}

.login-copy {
  display: grid;
  align-content: center;
  gap: var(--space-3);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.login-copy .lede {
  max-width: 40ch;
}

.login-copy .brand-name {
  font-size: var(--text-md);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.login-points {
  display: grid;
  gap: var(--space-1);
  margin: var(--space-2) 0 0;
  padding-left: 1.1rem;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.login-pane {
  display: grid;
  gap: var(--space-3);
  align-content: start;
}

.login-top {
  display: flex;
  justify-content: flex-end;
}

.login-form {
  display: grid;
  align-content: center;
  gap: var(--space-4);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
}

.login-info {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.login-info h3 {
  margin: 0;
  font-size: var(--text-lg);
  color: var(--text);
}

.info-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.info-label {
  color: var(--text-secondary);
  font-weight: var(--font-medium);
}

.info-value {
  color: var(--text);
  font-family: var(--font-mono);
}

.info-hint {
  display: grid;
  gap: var(--space-1);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border);
}

.credential-help {
  font-style: italic;
  color: var(--text-muted);
}

.login-submit {
  width: 100%;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.role-card {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
}

.role-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-1);
}

.role-name {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--text);
}

.role-badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.role-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.4;
}

.role-credentials {
  display: grid;
  gap: var(--space-1);
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border);
  font-size: var(--text-sm);
}

.role-credentials .info-value {
  font-weight: var(--font-semibold);
  font-family: var(--font-mono);
  color: var(--text);
}

.login-error {
  min-height: 1.25rem;
  color: var(--danger);
  font-size: var(--text-sm);
  font-weight: 600;
}

.login-note {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-1);
}

.form-help {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.password-wrap {
  position: relative;
  display: grid;
}

.password-wrap input {
  padding-right: 4.5rem;
}

.password-toggle {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  min-height: 0;
  padding: 0.3rem 0.55rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  color: var(--text);
  background: var(--surface-hover);
}

.login-credentials {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.login-credentials h3 {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.credentials-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.credentials-table th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  color: var(--text-muted);
  font-weight: 700;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}

.credentials-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  overflow-wrap: anywhere;
}

.credentials-table tr:hover td {
  background: var(--bg-hover);
}

.credentials-table td:first-child {
  font-weight: 600;
}

/* Three columns share a narrow card, so the role and password cells keep their
   own width and the email gets whatever is left. */
.credentials-table th:nth-child(2),
.credentials-table td:nth-child(2) {
  width: 42%;
}

.credentials-table th:last-child,
.credentials-table td:last-child {
  width: 33%;
}

.credential-fill {
  padding: 0;
  border: 0;
  background: none;
  font-weight: 500;
  text-align: left;
  justify-content: flex-start;
  white-space: normal;
  overflow-wrap: anywhere;
}

.credential-fill:hover {
  text-decoration: underline;
}

.credentials-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: center;
}

.credential-secret {
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text);
  overflow-wrap: anywhere;
}

.credentials-warning {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--warning);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: var(--text-xs);
  font-weight: 600;
}

/* 5.2 Theme toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.8rem;
  min-height: 2.125rem;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--btn-secondary-fg);
  background: var(--btn-secondary-bg);
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: var(--btn-secondary-bg-hover);
}

.theme-toggle.fixed {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
}

/* 5.3 Sidebar navigation */
.nav-group-label {
  padding: var(--space-3) var(--space-3) var(--space-1);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.55rem var(--space-3);
  border-radius: var(--radius-md);
  border-left: 3px solid transparent;
  color: var(--text-secondary);
  font-size: var(--text-base);
  font-weight: 600;
}

.nav-link:hover,
.nav-link:focus-visible {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
}

.nav-link.is-active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent-ink);
}

.nav-count {
  margin-left: auto;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

/* 5.4 Fleet list (charge points) */
.sidebar {
  align-self: start;
  padding: var(--space-4);
}

.cp-list {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.cp-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.7rem var(--space-3);
  text-align: left;
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}

.cp-item:hover,
.cp-item:focus-visible {
  border-color: var(--accent);
  background: var(--surface-2);
}

.cp-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.cp-item.active .cp-item-id {
  color: var(--accent-ink);
}

.cp-item-id {
  display: block;
  font-size: var(--text-base);
  font-weight: 650;
}

.cp-item-subtitle {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* 5.5 KPI hero */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-4);
  position: relative;
  z-index: 1;
}

.stat-card {
  display: grid;
  align-content: start;
  gap: var(--space-1);
  min-height: 96px;
}

.stat-card span {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-card strong {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-2xl);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-card small {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.stat-card.stat-primary {
  grid-column: 1 / -1;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
}

.stat-card.stat-primary strong {
  font-size: var(--text-3xl);
}

/* 5.6 Entity lists */
.entity-list {
  display: grid;
  gap: var(--space-2);
}

.entity-item {
  display: grid;
  gap: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: var(--space-3);
}

.entity-item-head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
}

.entity-item-body {
  color: var(--muted);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.ws-url-line code {
  font-size: var(--text-sm);
  background: var(--surface-muted);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
}

.test-ws-btn {
  font-size: var(--text-sm);
  padding: 4px 10px;
}

.test-ws-btn.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.entity-actions {
  display: flex;
  gap: var(--space-1);
  align-items: center;
}

/* 5.7 Timeline */
.timeline {
  display: grid;
  gap: var(--space-2);
}

.timeline-item {
  display: grid;
  gap: var(--space-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.timeline-item-head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  align-items: baseline;
}

.timeline-title {
  font-size: var(--text-base);
  font-weight: 650;
  line-height: 1.3;
}

.timeline-time {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.timeline-body {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.45;
  overflow-wrap: break-word;
}

/* 5.8 Sessions / billing grids */
.session-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2) var(--space-4);
}

.session-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.session-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

/* 5.9 ANME */
.anme-head-state {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.anme-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.anme-panel {
  display: grid;
  gap: var(--space-4);
  padding-top: var(--space-4);
}

.anme-field-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.anme-subcard {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}

.anme-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--target-min);
  color: var(--text-secondary);
  font-size: var(--text-base);
}

.anme-check input[type="checkbox"] {
  accent-color: var(--accent);
}

.anme-check-inline {
  display: grid;
  gap: var(--space-1);
}

.anme-url-preview {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--info);
  overflow-wrap: anywhere;
}

.anme-alert {
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--danger);
  border-left-width: 3px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.anme-alert.info {
  border-color: var(--info);
  background: var(--info-soft);
  color: var(--info);
}

.anme-result {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.anme-result.ready {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

.anme-result.blocked {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.anme-endpoint-test {
  width: 100%;
}

/* ---------- 6. Responsive ------------------------------------------------ */

@media (min-width: 1024px) {
  .nav-toggle {
    display: none;
  }

  .app-body {
    grid-template-columns: var(--nav-width) minmax(0, 1fr);
  }

  .app-nav {
    position: sticky;
    top: calc(var(--header-height) + var(--space-4));
    max-height: calc(100vh - var(--header-height) - var(--space-8));
  }

  .app-shell.is-collapsed .app-body {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .app-shell.is-collapsed .nav-link {
    justify-content: center;
    padding-inline: 0;
  }

  .app-shell.is-collapsed .nav-link span,
  .app-shell.is-collapsed .nav-group-label,
  .app-shell.is-collapsed .nav-user-role,
  .app-shell.is-collapsed .nav-user-desc,
  .app-shell.is-collapsed .nav-collapse span {
    display: none;
  }
}

@media (min-width: 1240px) {
  .layout {
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .stat-card.stat-primary {
    grid-column: span 2;
  }

  .sidebar {
    position: sticky;
    top: calc(var(--header-height) + var(--space-4));
    max-height: calc(100vh - var(--header-height) - var(--space-8));
    overflow: auto;
  }
}

@media (max-width: 1023px) {
  .app-nav {
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    z-index: calc(var(--z-nav) + 1);
    width: min(300px, 86vw);
    overflow: auto;
    border-radius: 0;
    border-width: 0 1px 0 0;
    transform: translateX(-102%);
    transition: transform var(--dur-base) var(--ease);
  }

  .app-shell.nav-open .app-nav {
    transform: none;
  }

  .nav-collapse {
    display: none;
  }
}

@media (max-width: 1100px) {
  .detail-grid,
  .command-grid,
  .admin-grid,
  .anme-field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .login-card.split {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    max-height: none;
  }
}

@media (max-width: 768px) {
  .shell {
    padding-inline: var(--space-4);
  }

  .app-header {
    padding: var(--space-2) var(--space-4);
  }

  .header-user {
    display: none;
  }

  .app-body {
    padding-block: var(--space-4) var(--space-7);
  }

  .brand-sub {
    display: none;
  }

  .login-screen {
    padding-block: var(--space-5);
    align-items: flex-start;
  }

  .login-card,
  .panel {
    padding: var(--space-4);
  }

  .card {
    padding: var(--space-3) var(--space-4);
  }

  .hero-top,
  .panel-head,
  .timeline-item-head {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  .app-header {
    flex-wrap: wrap;
    row-gap: var(--space-2);
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .detail-grid,
  .command-grid,
  .admin-grid,
  .anme-field-grid,
  .session-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 480px) {
  :root {
    --space-5: 1rem;
    --space-6: 1.25rem;
    --space-7: 1.5rem;
  }

  h1 {
    font-size: var(--text-2xl);
  }

  .stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .btn,
  .login-submit,
  .anme-endpoint-test {
    width: 100%;
  }

  .header-actions .btn {
    width: auto;
  }

  .toast {
    left: var(--space-3);
    right: var(--space-3);
    bottom: var(--space-3);
    min-width: 0;
    max-width: none;
  }

  .modal {
    width: 100%;
  }
}

/* Keep the desktop shell aligned with the EvMap CPMS layout: a fixed dark
   navigation rail with the header and dashboard content beside it. */
@media (min-width: 1024px) {
  .app-body.shell {
    display: block;
    max-width: none;
    margin-left: var(--nav-width);
    padding: var(--space-5);
  }

  .app-header {
    margin-left: var(--nav-width);
  }

  .app-nav {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--nav-width);
    max-height: none;
    overflow: auto;
    border: 0;
    border-right: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
  }

  .app-shell.is-collapsed .app-body.shell,
  .app-shell.is-collapsed .app-header {
    margin-left: 64px;
  }

  .app-shell.is-collapsed .app-nav {
    width: 64px;
  }
}

/* ---------- Motion ------------------------------------------------------- */

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(100%);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .app-header,
  .app-nav,
  .sidebar,
  .toast,
  .header-actions {
    display: none !important;
  }

  body {
    background: var(--print-bg);
    color: var(--print-ink);
  }
}
