@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@500;700&display=swap');

/* ═══════════════════════════════════════════════════════
   smartusers — HIGH CONTRAST SAS RADIUS THEME
   (Maximum Text Readability & Crisp Visibility)
   ═══════════════════════════════════════════════════════ */

:root {
  --bg: #e2e8f0;              /* Clear light grey */
  --panel: #ffffff;           /* Pure white */
  --panel-soft: #f1f5f9;
  --panel-hover: #e2e8f0;
  --panel-dark: #1e293b;      /* Deep high-contrast dark slate for cards */
  --panel-dark-soft: #0f172a;

  --ink: #1e293b;             /* High contrast dark text for white panels */
  --ink-strong: #0f172a;      /* Deep black-slate for titles */
  --muted: #475569;           /* High contrast muted text (easily readable) */
  --line: #cbd5e1;            /* Crisp line borders */

  --sas-red: #dc2626;         /* High visibility red */
  --sas-blue: #0284c7;        /* High visibility blue */
  --sas-teal: #0d9488;        /* High visibility teal */
  --sas-orange: #d97706;      /* High visibility orange */
  
  --sidebar-w: 230px;
  --sidebar-bg: #1e293b;      /* Dark navy sidebar */
  --sidebar-header: #0f172a;
  --sidebar-text: #e2e8f0;    /* Bright text for sidebar links */
  --sidebar-hover-bg: #334155;
  --sidebar-hover-text: #ffffff;
  --sidebar-active-bg: #334155;
  --sidebar-active-text: #ffffff;
  --sidebar-active-bar: #dc2626;

  --topbar-bg: #ffffff;
  --topbar-h: 52px;

  --radius: 6px;
  --radius-lg: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --transition: all 0.15s ease-in-out;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: "Cairo", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  direction: rtl;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; border: 0; }
a { color: var(--sas-blue); text-decoration: none; font-weight: 700; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #cbd5e1; }
::-webkit-scrollbar-thumb { background: #64748b; border-radius: 3px; }

/* ═══════════════════════════════════════════════════════
   LAYOUT — Sidebar Right (First Child RTL), Main Left
   ═══════════════════════════════════════════════════════ */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ─── Sidebar (Bright High-Contrast Text) ─── */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--sidebar-header);
  border-bottom: 1px solid rgba(0,0,0,0.3);
  height: var(--topbar-h);
}

.brand {
  font-size: 17px;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand span { color: #f87171; }

.brand-tag {
  font-size: 9px;
  background: #dc2626;
  color: #ffffff;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 900;
}

.nav {
  display: flex;
  flex-direction: column;
  padding: 6px 0;
  flex: 1;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 18px;
  background: transparent;
  color: #e2e8f0;            /* Bright light gray text */
  font-size: 13px;
  font-weight: 700;           /* Bold text */
  text-align: right;
  border: 0;
  cursor: pointer;
  width: 100%;
  transition: var(--transition);
  position: relative;
  border-right: 4px solid transparent;
}

.nav button .icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  color: #cbd5e1;            /* High visibility icon */
}

.nav button .arrow {
  margin-right: auto;
  font-size: 10px;
  color: #94a3b8;
}

.nav button:hover {
  background: var(--sidebar-hover-bg);
  color: #ffffff;
}

.nav button.active {
  background: var(--sidebar-active-bg);
  color: #ffffff;
  font-weight: 800;
  border-right-color: var(--sidebar-active-bar);
}

.nav button.active .icon { color: #f87171; }

.sidebar-footer {
  padding: 12px 16px;
  background: var(--sidebar-header);
  border-top: 1px solid rgba(0,0,0,0.3);
  text-align: center;
  font-size: 11px;
  color: #cbd5e1;
  font-weight: 700;
}

/* ─── Expandable Nav Groups (SAS Submenu) ─── */
.nav-group { border-top: 1px solid rgba(255,255,255,0.04); }

.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 18px;
  background: transparent;
  color: #e2e8f0;
  font-size: 13px;
  font-weight: 700;
  text-align: right;
  border: 0;
  cursor: pointer;
  width: 100%;
  transition: var(--transition);
  border-right: 4px solid transparent;
}

.nav-group-toggle .icon { font-size: 15px; width: 20px; text-align: center; color: #cbd5e1; }
.nav-group-toggle .arrow { margin-right: auto; font-size: 10px; color: #94a3b8; transition: transform 0.2s; }
.nav-group-toggle:hover { background: var(--sidebar-hover-bg); color: #ffffff; }
.nav-group.open .nav-group-toggle { border-right-color: var(--sidebar-active-bar); }
.nav-group.open .nav-group-toggle .arrow { transform: rotate(-90deg); }

.nav-sub {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease-in-out;
  background: rgba(0,0,0,0.12);
}

.nav-group.open .nav-sub { max-height: 600px; }

.nav-sub button {
  display: block;
  width: 100%;
  padding: 8px 18px 8px 40px;
  background: transparent;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 600;
  text-align: right;
  border: 0;
  cursor: pointer;
  transition: var(--transition);
  border-right: 3px solid transparent;
}

.nav-sub button:hover {
  background: rgba(255,255,255,0.05);
  color: #ffffff;
}

.nav-sub button.active {
  color: #ffffff;
  background: rgba(255,255,255,0.08);
  border-right-color: #38bdf8;
  font-weight: 800;
}

/* ─── Main Area ─── */
.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

/* ─── Topbar ─── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  height: var(--topbar-h);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #0f172a;
  font-weight: 800;
  background: #f1f5f9;
  padding: 4px 12px 4px 6px;
  border-radius: 20px;
  border: 1px solid #cbd5e1;
}

.user-badge .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #0284c7;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: #ffffff;
}

.sub-header {
  padding: 8px 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  color: #334155;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sub-header span {
  color: #0284c7;
  font-weight: 800;
  font-family: monospace;
}

/* ─── Content Area ─── */
.content-area {
  flex: 1;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.section { display: none; }
.section.active { display: block; }

/* ═══════════════════════════════════════════════════════
   TOP STATS CARDS (White Cards, High Contrast)
   ═══════════════════════════════════════════════════════ */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.stat {
  background: #ffffff;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-info b {
  font-size: 22px;
  font-weight: 900;
  color: #0f172a;            /* Black-slate number */
  display: block;
  line-height: 1.2;
}

.stat-info span {
  font-size: 12px;
  color: #334155;            /* High visibility label */
  font-weight: 700;
  margin-top: 3px;
  display: block;
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  font-size: 18px;
  background: #f1f5f9;
  color: #0284c7;
  border: 1px solid #cbd5e1;
}

/* ═══════════════════════════════════════════════════════
   DASHBOARD CARDS — Dark Slate Cards (#1e293b)
   ═══════════════════════════════════════════════════════ */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.dash-grid .card {
  background: #1e293b;        /* Deep dark slate */
  color: #ffffff;
  border: 1px solid #0f172a;
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-md);
  margin-bottom: 0;
}

.dash-grid .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.dash-grid .card-header h2 {
  font-size: 14px;
  font-weight: 800;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dash-grid .info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 12.5px;
}

.dash-grid .info-row:last-child { border-bottom: 0; }

.dash-grid .info-row .label {
  color: #cbd5e1;            /* Bright grayish white label (HIGH CONTRAST) */
  font-weight: 700;
}

.dash-grid .info-row .value {
  color: #38bdf8;            /* Bright Cyan/Sky Blue value */
  font-weight: 800;
  font-family: monospace;
  font-size: 13.5px;
}

.dash-grid .info-row .value.green {
  color: #4ade80;            /* Bright Lime Green */
}

.dash-grid .info-row .value.white {
  color: #ffffff;            /* Pure White */
}

.dash-grid .info-row .value.warning {
  color: #facc15;            /* Bright Yellow */
}

/* ═══════════════════════════════════════════════════════
   STANDARD WHITE CARDS & TABLES (High Contrast)
   ═══════════════════════════════════════════════════════ */
.card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.card-header h2, .card h2 {
  font-size: 14.5px;
  font-weight: 900;
  color: #0f172a;            /* Black slate heading */
}

/* ─── Toolbars ─── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  background: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.pill {
  background: #f1f5f9;
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  color: #334155;            /* Dark clear text */
  border: 1px solid #cbd5e1;
}

/* ═══════════════════════════════════════════════════════
   BUTTONS (High Contrast)
   ═══════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 15px;
  border-radius: 4px;
  font-size: 12.5px;
  font-weight: 800;
  border: 1px solid transparent;
  cursor: pointer;
  background: #0284c7;        /* Solid bright blue */
  color: #ffffff;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: #0369a1;
}

.btn.secondary {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #94a3b8;
}

.btn.secondary:hover {
  background: #f1f5f9;
}

.btn.green { background: #0d9488; }
.btn.green:hover { background: #0f766e; }

.btn.red { background: #dc2626; }
.btn.red:hover { background: #b91c1c; }

.btn.sm { padding: 4px 9px; font-size: 11px; }

/* ═══════════════════════════════════════════════════════
   DATA TABLES (High Contrast Black on White)
   ═══════════════════════════════════════════════════════ */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  min-height: 90px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-weight: 700;
}

th, td {
  padding: 11px 15px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  background: #e2e8f0;        /* Light slate header background */
  font-weight: 900;
  color: #0f172a;            /* Black slate text */
  font-size: 12px;
  border-bottom: 2px solid #cbd5e1;
}

td {
  color: #0f172a;            /* Clear black text inside cells */
}

tr:last-child td { border-bottom: 0; }
tr:nth-child(even) td { background: #f8fafc; }
tr:hover td { background: #e0f2fe; }

td code {
  background: #e0f2fe;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  color: #0369a1;            /* Dark cyan-blue code */
  border: 1px solid #bae6fd;
}

.empty-text {
  padding: 30px;
  text-align: center;
  color: #475569;
  font-size: 13px;
  font-weight: 800;
  white-space: normal;
}

/* ═══════════════════════════════════════════════════════
   BADGES & STATUS
   ═══════════════════════════════════════════════════════ */
.status, .badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 800;
}

.status.online {
  background: #ccfbf1;
  color: #0f766e;
  border: 1px solid #5eead4;
}

.status.offline {
  background: #f1f5f9;
  color: #64748b;
  border: 1px solid #cbd5e1;
}

.status.active {
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #86efac;
}

.status.expired, .status.disabled {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

.badge.blue {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #7dd3fc;
}

/* ═══════════════════════════════════════════════════════
   INPUTS & FORMS (Clear Black Text)
   ═══════════════════════════════════════════════════════ */
.input, select, textarea {
  width: 100%;
  padding: 8px 14px;
  border-radius: 4px;
  border: 1px solid #94a3b8;
  background: #ffffff;
  color: #0f172a;            /* Black text */
  font-size: 13px;
  font-weight: 700;
  outline: 0;
}

.input:focus, select:focus, textarea:focus {
  border-color: #0284c7;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.2);
}

.input::placeholder { color: #64748b; font-weight: 500; }

.grid { display: grid; gap: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.split { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.label { display: block; font-size: 12px; font-weight: 800; color: #0f172a; margin-bottom: 4px; }
.actions { display: flex; align-items: center; gap: 6px; }

/* ═══════════════════════════════════════════════════════
   CHART
   ═══════════════════════════════════════════════════════ */
.mini-chart {
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  gap: 4px;
  align-items: flex-end;
  min-height: 150px;
  padding-top: 12px;
}

.bar {
  background: linear-gradient(180deg, #38bdf8 0%, rgba(56,189,248,0.2) 100%);
  border-radius: 3px 3px 0 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 3px 1px;
  color: #ffffff;
  font-size: 9px;
  font-weight: 800;
  position: relative;
  border-top: 2px solid #38bdf8;
}

/* ═══════════════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #0f172a;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 24px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 15px 40px rgba(0,0,0,0.4);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  justify-content: center;
}

.login-page .brand { color: #dc2626; font-size: 22px; }
.login-page h1 { color: #0f172a; margin-bottom: 4px; font-size: 15px; font-weight: 800; text-align: center; }
.login-page .muted { color: #475569; text-align: center; font-weight: 600; }

/* ═══════════════════════════════════════════════════════
   MODALS & TOAST
   ═══════════════════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  place-items: center;
  z-index: 100;
}

.modal.show, .modal.open { display: grid; }

.modal-box {
  background: #ffffff;
  border-radius: var(--radius-lg);
  width: 92%;
  max-width: 700px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 22px;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 { font-size: 16px; font-weight: 900; color: #0f172a; }
.close { font-size: 22px; color: #475569; cursor: pointer; background: transparent; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.detail-tile {
  background: #f1f5f9;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid #cbd5e1;
}

.detail-tile span { font-size: 11px; color: #475569; display: block; font-weight: 800; }
.detail-tile b { font-size: 14px; font-weight: 900; color: #0f172a; margin-top: 2px; display: block; }

.code-block {
  background: #0f172a;
  border-radius: var(--radius);
  margin-top: 8px;
  overflow: hidden;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: #1e293b;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.code-block-header span { font-size: 11px; font-weight: 800; color: #cbd5e1; }
.code-block-header button {
  background: #0d9488;
  color: #ffffff;
  padding: 3px 10px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 800;
}

.code-block pre {
  padding: 12px;
  margin: 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #f8fafc;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: #0f172a;
  color: #ffffff;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  display: none;
  z-index: 200;
  font-weight: 800;
  font-size: 13px;
  border-right: 4px solid #0d9488;
}
.toast.show { display: block; }

/* ─── MikroTik Version Toggle ─── */
.version-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 14px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--line);
  width: fit-content;
}

.version-btn {
  padding: 8px 22px;
  border: 0;
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition);
}

.version-btn.active {
  background: var(--sidebar-bg);
  color: #fff;
}

.version-btn:hover:not(.active) {
  background: var(--panel-hover);
}

.mikrotik-version { display: none; }
.mikrotik-version.active { display: block; }

/* ─── Hamburger Button ─── */
.hamburger {
  display: none;
  background: transparent;
  border: 2px solid var(--line);
  color: var(--ink);
  font-size: 20px;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.hamburger:hover {
  background: var(--panel-hover);
}

/* ─── Sidebar Overlay (Mobile) ─── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  backdrop-filter: blur(2px);
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — Full Mobile Support
   ═══════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — Ultra Mobile & Tablet Optimization
   ═══════════════════════════════════════════════════════ */

/* ─── Desktop Adjustments (<= 1100px) ─── */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  :root { --sidebar-w: 210px; }
}

/* ─── Tablets & Mobile Devices (<= 900px) ─── */
@media (max-width: 900px) {
  html, body { overflow-x: hidden; }
  .shell { grid-template-columns: 1fr !important; }

  /* Mobile Slide-out Sidebar Drawer */
  .sidebar {
    position: fixed;
    top: 0;
    right: -290px;
    width: 270px;
    height: 100dvh;
    z-index: 999;
    box-shadow: -5px 0 25px rgba(0,0,0,0.5);
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
  }

  .sidebar.open {
    right: 0 !important;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 998;
    backdrop-filter: blur(3px);
  }

  .sidebar-overlay.open {
    display: block !important;
  }

  /* Hamburger Toggle Button */
  .hamburger {
    display: inline-flex !important;
  }

  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .form-grid, .split, .detail-grid { grid-template-columns: 1fr; gap: 10px; }
  .content-area { padding: 10px; }
  .topbar { padding: 8px 12px; }

  /* Tables horizontal scroll wrapper for touch */
  .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    margin-top: 8px;
  }

  .table-wrap table {
    min-width: 650px;
    width: 100%;
  }

  /* ─── Smart Mobile Card Layout ─── */
  .mobile-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    margin-top: 8px;
  }

  .mobile-card {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 12px 14px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
  }

  .mobile-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 8px;
  }

  .mobile-card-title {
    font-size: 14px;
    font-weight: 800;
    color: var(--ink-strong);
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .mobile-card-body {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 12px;
    font-size: 12px;
  }

  .mobile-card-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .mobile-card-field span {
    font-size: 10.5px;
    color: var(--muted);
    font-weight: 600;
  }

  .mobile-card-field b {
    font-size: 12px;
    color: var(--ink);
    font-weight: 700;
  }

  .mobile-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px dashed #e2e8f0;
  }

  .mobile-card-actions .btn {
    flex: 1;
    text-align: center;
    justify-content: center;
    padding: 6px 8px;
    font-size: 11.5px;
  }
}

/* ─── Smartphones (<= 600px) ─── */
@media (max-width: 600px) {
  /* Toolbar & Search Bar Stack on Mobile */
  .toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 10px !important;
  }

  .toolbar .input {
    max-width: 100% !important;
    width: 100% !important;
    font-size: 13px;
  }

  .toolbar > div {
    width: 100% !important;
    display: flex;
    gap: 6px;
  }

  .toolbar > div .btn {
    flex: 1;
    text-align: center;
    justify-content: center;
  }

  /* Stats grid on mobile */
  .stats {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }

  .stat {
    padding: 10px 12px;
  }

  .stat-info b {
    font-size: 18px;
  }

  .stat-info span {
    font-size: 10px;
  }

  .stat-icon {
    font-size: 20px;
  }

  /* Topbar Layout */
  .topbar {
    padding: 8px;
    gap: 6px;
  }

  .topbar-left {
    gap: 6px;
    width: 100%;
    justify-content: space-between;
  }

  .topbar-right {
    display: none;
  }

  .user-badge {
    padding: 4px 8px;
    font-size: 11px;
  }

  .sub-header {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 800;
  }

  /* Content Padding */
  .content-area {
    padding: 6px;
  }

  /* Modal Dialogs on Mobile */
  .modal-box {
    width: 95vw !important;
    max-height: 92dvh !important;
    margin: 4dvh auto !important;
    padding: 14px !important;
  }

  .modal-head h2 {
    font-size: 14px;
  }

  /* Table cells touch spacing */
  table th, table td {
    padding: 8px 10px;
    font-size: 11.5px;
  }

  .card {
    padding: 12px;
    border-radius: 8px;
  }

  .card-header h2 {
    font-size: 13px;
  }

  .detail-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .detail-tile {
    padding: 8px;
  }

  .detail-tile span {
    font-size: 10px;
  }

  .detail-tile b {
    font-size: 13px;
  }

  .code-block pre {
    font-size: 10px;
    padding: 8px;
  }

  .version-toggle {
    width: 100%;
  }

  .version-btn {
    flex: 1;
    text-align: center;
    padding: 8px 10px;
  }

  /* Login card mobile fit */
  .login-card {
    width: 92vw;
    padding: 20px 16px;
  }
}

/* ─── Extra Small Devices (<= 400px) ─── */
@media (max-width: 400px) {
  .stats {
    grid-template-columns: 1fr !important;
  }
  .hamburger {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }
  .sidebar {
    width: 250px;
  }
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

