/* ══════════════════════════════════════════════════════════════
   ZIP085 PORTAL — DESIGN SYSTEM
   Source: prototype-redesign.html (approved prototype)
   Aesthetic: Industrial Precision — neutral monochrome
   Fonts: DM Sans (body) + JetBrains Mono (code/data)
   ══════════════════════════════════════════════════════════════ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --font-body: 'DM Sans', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', monospace;
  --radius-sm: 3px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --sidebar-w: 240px;
  --navbar-h: 48px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── DARK THEME (default) — Steel-Blue accent ─── */
[data-theme="dark"] {
  --bg-base: #111215;
  --bg-surface: #18191d;
  --bg-elevated: #1f2024;
  --bg-hover: #2e2f36;
  --bg-active: #34353b;
  --bg-input: #111214;
  --border: #3c3e46;
  --border-subtle: #313238;
  --border-focus: var(--accent);
  --text-primary: #e8e9ed;
  --text-secondary: #9ea0a8;
  --text-muted: #7e7f87;
  --text-inverse: #111215;
  /* ── accent (UI system color, not a badge color) ── */
  --accent: #7b9bb5;
  --accent-hover: #93b1c8;
  --accent-subtle: rgba(123, 155, 181, 0.12);
  --accent-text: #8caabe;
  /* ── 12 badge colors: CVD-safe, WCAG AA white text ──
     Lightness bands for CVD safety:
     DARK   (CR 7-10): green, navy, rose, brown
     MEDIUM (CR 5.5-7): red, teal, blue, purple, slate
     BRIGHT (CR 4.5-5.5): orange, gold, lime            */
  --c-red:    #B83232;
  --c-orange: #AD5E10;
  --c-gold:   #7A6810;
  --c-lime:   #4E7E18;
  --c-green:  #0C6034;
  --c-teal:   #107575;
  --c-blue:   #2862B0;
  --c-navy:   #2C3590;
  --c-purple: #8530A0;
  --c-rose:   #982852;
  --c-brown:  #7A4828;
  --c-slate:  #586270;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.35);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.45);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.55);
  --navbar-bg: #0e0f12;
  --sidebar-bg: #0e0f12;
  --glow: 0 0 16px rgba(123, 155, 181, 0.08);
}

/* ─── LIGHT THEME ─── */
[data-theme="light"] {
  --bg-base: #f2f2f4;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover: #eaeaee;
  --bg-active: #e0e0e4;
  --bg-input: #f6f6f8;
  --border: #d4d4d8;
  --border-subtle: #e4e4e8;
  --border-focus: var(--accent);
  --text-primary: #18181b;
  --text-secondary: #3f3f46;
  --text-muted: #a1a1aa;
  --text-inverse: #ffffff;
  --accent: #27272a;
  --accent-hover: #18181b;
  --accent-subtle: rgba(39, 39, 42, 0.06);
  --accent-text: #27272a;
  --success: #388e3c;
  --success-subtle: rgba(56, 142, 60, 0.08);
  --success-text: #2e7d32;
  --danger: #c62828;
  --danger-subtle: rgba(198, 40, 40, 0.08);
  --danger-text: #b71c1c;
  --warning: #e68a00;
  --warning-subtle: rgba(230, 138, 0, 0.08);
  --warning-text: #cc7a00;
  /* ── 12 badge colors: same as dark theme, CVD-safe ── */
  --c-red:    #B83232;
  --c-orange: #AD5E10;
  --c-gold:   #7A6810;
  --c-lime:   #4E7E18;
  --c-green:  #0C6034;
  --c-teal:   #107575;
  --c-blue:   #2862B0;
  --c-navy:   #2C3590;
  --c-purple: #8530A0;
  --c-rose:   #982852;
  --c-brown:  #7A4828;
  --c-slate:  #586270;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --navbar-bg: #ffffff;
  --sidebar-bg: #ffffff;
  --glow: 0 0 16px rgba(39, 39, 42, 0.04);
}

/* ─── BASE ─── */
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--text-primary); }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }


/* ═══ NAVBAR ═══ */

.navbar {
  height: var(--navbar-h);
  background: var(--navbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  transition: background var(--transition), border-color var(--transition);
  backdrop-filter: blur(12px);
}
[data-theme="dark"] .navbar { background: rgba(14, 15, 18, 0.9); }
[data-theme="light"] .navbar { background: rgba(255, 255, 255, 0.9); }

.navbar-brand {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 24px;
  letter-spacing: -0.5px;
}
.navbar-brand .brand-dot {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 2px;
  display: inline-block;
  box-shadow: var(--glow);
}

.navbar-center {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
}
.navbar-link {
  padding: 6px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.navbar-link:hover { color: var(--text-primary); background: var(--bg-hover); }
.navbar-link.active { color: var(--accent-text); background: var(--accent-subtle); }

.navbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

/* Navbar Icon Buttons (theme toggle, logout) */
.navbar-icon-btn {
  width: 28px; height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all var(--transition);
  text-decoration: none;
  position: relative;
  overflow: hidden;
}
.navbar-icon-btn:hover { border-color: var(--accent); color: var(--accent-text); background: var(--accent-subtle); }
.navbar-icon-btn.btn-logout:hover { border-color: var(--danger); color: var(--danger-text); background: var(--danger-subtle); }

/* Theme Toggle icon animation */
.theme-toggle .icon-sun, .theme-toggle .icon-moon {
  position: absolute; transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
[data-theme="dark"] .theme-toggle .icon-sun { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="dark"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(0.5); }
[data-theme="light"] .theme-toggle .icon-sun { opacity: 0; transform: rotate(-90deg) scale(0.5); }
[data-theme="light"] .theme-toggle .icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }

.navbar-user {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  padding: 4px 10px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
}
.navbar-user strong { color: var(--text-secondary); font-weight: 600; }


/* ═══ LAYOUT ═══ */

.app-layout {
  display: flex;
  margin-top: var(--navbar-h);
  flex: 1;
}


/* ═══ SIDEBAR ═══ */

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  position: fixed;
  top: var(--navbar-h);
  left: 0; bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
  transition: all var(--transition);
  z-index: 50;
}

.sidebar-section { margin-bottom: 4px; }
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  cursor: pointer;
  user-select: none;
  transition: all var(--transition);
}
.sidebar-header:hover { background: var(--bg-hover); }
.sidebar-header-text {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent-text);
  transition: color var(--transition);
}
.sidebar-header:hover .sidebar-header-text { color: var(--text-primary); }
.sidebar-chevron {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}
.sidebar-section.collapsed .sidebar-chevron { transform: rotate(-90deg); }
.sidebar-section.collapsed .sidebar-items { display: none; }

.sidebar-admin-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.sidebar-admin-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px 7px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  transition: all var(--transition);
  border-left: 2px solid transparent;
  cursor: pointer;
}
.sidebar-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.sidebar-item.active {
  color: var(--accent-text);
  background: var(--accent-subtle);
  border-left-color: var(--accent);
  font-weight: 500;
}
.sidebar-item i {
  font-size: 15px;
  width: 18px;
  text-align: center;
  opacity: 0.7;
}
.sidebar-item.active i { opacity: 1; }
.sidebar-item .item-badge {
  margin-left: auto;
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-active);
  color: var(--text-muted);
}

.sidebar-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 8px 16px;
}

/* Sidebar toggle (mobile) */
.sidebar-toggle {
  display: none;
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all var(--transition);
}
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
  backdrop-filter: blur(2px);
}


/* ═══ MAIN CONTENT ═══ */

.content-wrapper {
  flex: 1;
  margin-left: var(--sidebar-w);
  overflow-y: auto;
  transition: margin-left var(--transition);
}
.main-content {
  width: 100%;
  padding: 16px 32px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.page-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}
.breadcrumb {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 12px;
}
.breadcrumb a { color: var(--text-secondary); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent-text); }
.breadcrumb .sep { opacity: 0.4; }


/* ═══ CARDS ═══ */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition);
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.1px;
}
.card-body { padding: 18px; }
.card-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}


/* ═══ STAT CARDS ═══ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--stat-color, var(--accent));
  opacity: 0;
  transition: opacity var(--transition);
}
.stat-card:hover { border-color: var(--stat-color, var(--accent)); }
.stat-card:hover::before { opacity: 1; }
.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1;
  color: var(--text-primary);
}
.stat-change {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-family: var(--font-mono);
  margin-top: 8px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.stat-change.up { color: var(--success-text); background: var(--success-subtle); }
.stat-change.down { color: var(--danger-text); background: var(--danger-subtle); }
.stat-icon {
  position: absolute;
  top: 14px; right: 16px;
  font-size: 20px;
  color: var(--text-muted);
  opacity: 0.3;
}


/* ═══ TABLE ═══ */

.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
  white-space: nowrap;
}
tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }
.td-mono { font-family: var(--font-mono); font-size: 12px; letter-spacing: -0.3px; white-space: nowrap; }
.td-secondary { color: var(--text-secondary); white-space: nowrap; }


/* ═══ BADGES ═══ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.badge-red    { background: color-mix(in srgb, var(--c-red) 75%, transparent); color: #fff; }
.badge-orange { background: color-mix(in srgb, var(--c-orange) 75%, transparent); color: #fff; }
.badge-gold   { background: color-mix(in srgb, var(--c-gold) 75%, transparent); color: #fff; }
.badge-lime   { background: color-mix(in srgb, var(--c-lime) 75%, transparent); color: #fff; }
.badge-green  { background: color-mix(in srgb, var(--c-green) 75%, transparent); color: #fff; }
.badge-teal   { background: color-mix(in srgb, var(--c-teal) 75%, transparent); color: #fff; }
.badge-blue   { background: color-mix(in srgb, var(--c-blue) 75%, transparent); color: #fff; }
.badge-navy   { background: color-mix(in srgb, var(--c-navy) 75%, transparent); color: #fff; }
.badge-purple { background: color-mix(in srgb, var(--c-purple) 75%, transparent); color: #fff; }
.badge-rose   { background: color-mix(in srgb, var(--c-rose) 75%, transparent); color: #fff; }
.badge-brown  { background: color-mix(in srgb, var(--c-brown) 75%, transparent); color: #fff; }
.badge-slate  { background: color-mix(in srgb, var(--c-slate) 75%, transparent); color: #fff; }
.badge-success { background: var(--success-subtle); color: var(--success-text); }
.badge-danger  { background: var(--danger-subtle); color: var(--danger-text); }
.badge-warning { background: var(--warning-subtle); color: var(--warning-text); }
.badge-info    { background: var(--accent-subtle); color: var(--accent-text); }
.badge-muted   { background: var(--bg-hover); color: var(--text-muted); }
.badge-xs { padding: 2px 6px; font-size: 10px; }
.badge-fixed { min-width: 72px; justify-content: center; text-align: center; }
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}


/* ═══ BUTTONS ═══ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}
.btn i { font-size: 14px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-sm i { font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 14px; }

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); box-shadow: var(--glow); color: var(--text-inverse); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--text-muted); }

.btn-danger-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-danger-ghost:hover { background: var(--danger-subtle); color: var(--danger-text); border-color: var(--danger); }

.btn-dark {
  background: var(--text-primary);
  color: var(--bg-base);
  border-color: var(--text-primary);
}
.btn-dark:hover { opacity: 0.85; }

.btn:disabled, .btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-group {
  display: inline-flex;
  gap: 0;
}
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn + .btn { margin-left: -1px; }


/* ═══ FORMS ═══ */

.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.1px;
}
.form-input, .form-select, textarea.form-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-body);
  transition: all var(--transition);
  outline: none;
}
textarea.form-input {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}
.form-input:focus, .form-select:focus, textarea.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
  background: var(--bg-surface);
}
.form-input::placeholder, textarea.form-input::placeholder { color: var(--text-muted); }
.form-input:disabled, .form-select:disabled, textarea.form-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.form-input[readonly] { opacity: 0.7; cursor: default; }
.form-input.mono { font-family: var(--font-mono); }

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238c8d94' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Tool pages — form inputs capped at readable width */
.tool-content .form-input,
.tool-content .form-select {
  max-width: 400px;
}
.tool-content .input-group {
  max-width: 400px;
}

.form-input.is-invalid, .form-select.is-invalid {
  border-color: var(--danger);
}
.form-input.is-invalid:focus, .form-select.is-invalid:focus {
  box-shadow: 0 0 0 3px var(--danger-subtle);
}
.form-error {
  font-size: 11px;
  color: var(--danger-text);
  margin-top: 4px;
}

.input-group {
  display: flex;
}
.input-group .form-input {
  border-radius: 0;
}
.input-group .form-input:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .form-input:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-group .btn {
  border-radius: 0;
}
.input-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ═══ FIELD WRAP (input/select with clear button) ═══ */

.field-wrap {
  position: relative;
}
.field-wrap .form-input,
.field-wrap .form-select { padding-right: 32px; }
.field-clear {
  position: absolute;
  right: 4px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px;
  display: none; align-items: center; justify-content: center;
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 14px; transition: all var(--transition); padding: 0;
}
.field-clear:hover { color: var(--text-primary); background: var(--bg-hover); }
.field-clear.visible { display: flex; }

/* ═══ SEARCH WRAP (input with inline clear) ═══ */

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap .form-input { padding-right: 28px; }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: none;
  border: none; background: none; cursor: pointer;
  color: var(--text-muted); font-size: 13px; line-height: 1;
  padding: 2px; transition: color var(--transition);
}
.search-clear:hover { color: var(--text-primary); }
.search-wrap.has-value .search-clear { display: block; }

/* ═══ TOOLBAR ═══ */

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.toolbar .form-input,
.toolbar .form-select { width: auto; }
.toolbar-stats {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}


/* ═══ MODAL ═══ */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px;
  /* flex-start so tall modals scroll naturally from top */
  align-items: flex-start;
  justify-content: center;
}
.modal.show { display: flex; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 199;
}
.modal-dialog {
  width: 100%;
  max-width: 500px;
  margin: auto 0;
  position: relative;
  z-index: 201;
}
.modal-dialog-lg { max-width: 720px; }
.modal-dialog-sm { max-width: 380px; }
.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.btn-close {
  width: 28px; height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition);
}
.btn-close:hover { background: var(--bg-hover); color: var(--text-primary); }


/* ═══ TABS ═══ */

.nav-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.nav-tab {
  padding: 8px 14px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--transition);
  cursor: pointer;
  background: none;
  font-family: var(--font-body);
}
.nav-tab:hover { color: var(--text-primary); }
.nav-tab.active {
  color: var(--accent-text);
  border-bottom-color: var(--accent);
}
.tab-content > .tab-pane { display: none; }
.tab-content > .tab-pane.active { display: block; }


/* ═══ ACCORDION ═══ */

.accordion {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.accordion-item { border-bottom: 1px solid var(--border); }
.accordion-item:last-child { border-bottom: none; }
.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-surface);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  transition: background var(--transition);
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
}
.accordion-header:hover { background: var(--bg-hover); }
.accordion-header .chevron {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}
.accordion-header.collapsed .chevron { transform: rotate(-90deg); }
.accordion-body {
  padding: 16px;
  border-top: 1px solid var(--border-subtle);
  font-size: 13px;
  color: var(--text-secondary);
}
.collapse { display: none; }
.collapse.show { display: block; }


/* ═══ DROPDOWN ═══ */

.dropdown { position: relative; display: inline-flex; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 180px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 150;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-item i { font-size: 14px; opacity: 0.6; }
.dropdown-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 0;
}


/* ═══ PAGINATION ═══ */

.pagination {
  display: flex;
  gap: 2px;
  align-items: center;
}
.page-btn {
  min-width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.page-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.page-btn.active {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.page-btn:disabled, .page-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}


/* ═══ TABLE FOOTER ═══ */

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
}


/* ═══ DYNAMIC TABLE LAYOUT ═══
   Add class "page-table" to <body> to enable.
   Tables fill available viewport height, only .table-wrapper scrolls.
   Structure: .main-content > [headers] > .card > .card-body > .table-wrapper + .table-footer
*/

body.page-table { height: 100vh; max-height: 100vh; overflow: hidden; }
body.page-table .app-layout { height: calc(100vh - var(--navbar-h)); min-height: 0; overflow: hidden; }
body.page-table .content-wrapper { display: flex; flex-direction: column; overflow: hidden; height: 100%; }
body.page-table .main-content {
  flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
body.page-table .main-content > .breadcrumb,
body.page-table .main-content > .section-title,
body.page-table .main-content > .page-header,
body.page-table .main-content > .stats-grid,
body.page-table .main-content > .mode-toggle {
  flex-shrink: 0;
}
body.page-table #main-content {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
}
body.page-table #main-content > .section-title,
body.page-table #main-content > .page-header,
body.page-table #main-content > .stats-grid,
body.page-table #main-content > .mode-toggle {
  flex-shrink: 0;
}
body.page-table #main-content > .card,
body.page-table #main-content > .mode-panel.active,
body.page-table .main-content > .card,
body.page-table .main-content > .mode-panel.active {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
}
body.page-table .mode-panel.active > .card {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
}
body.page-table .card > .card-body {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
}
body.page-table .card-body > .toolbar,
body.page-table .card-body > .filter-form,
body.page-table .card-body > div:not(.table-wrapper):not(.table-footer) {
  flex-shrink: 0;
}
body.page-table .table-footer { flex-shrink: 0; }
body.page-table .card-body > .table-wrapper {
  flex: 1; overflow-y: auto; min-height: 0;
}


/* ═══ ALERTS ═══ */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.alert i { font-size: 16px; }
.alert-success { background: var(--success-subtle); color: var(--success-text); border-color: var(--success); }
.alert-danger { background: var(--danger-subtle); color: var(--danger-text); border-color: var(--danger); }
.alert-warning { background: var(--warning-subtle); color: var(--warning-text); border-color: var(--warning); }
.alert-info { background: var(--accent-subtle); color: var(--accent-text); border-color: var(--accent); }
.alert-close {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.5;
  font-size: 14px;
}
.alert-close:hover { opacity: 1; }


/* ═══ TOAST ═══ */

.toast-container {
  position: fixed;
  top: 60px; right: 16px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  min-width: 280px;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 1px solid;
}
.toast-success { background: var(--success-subtle); color: var(--success-text); border-color: var(--success); }
.toast-warning { background: var(--warning-subtle); color: var(--warning-text); border-color: var(--warning); }
.toast-error { background: var(--danger-subtle); color: var(--danger-text); border-color: var(--danger); }
.toast i { font-size: 16px; }
.toast-close {
  margin-left: auto;
  background: none; border: none;
  color: inherit; cursor: pointer;
  opacity: 0.5; font-size: 14px;
}
.toast-close:hover { opacity: 1; }


/* ═══ SPINNER ═══ */

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.spinner-sm { width: 14px; height: 14px; border-width: 1.5px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }


/* ═══ EMPTY STATE ═══ */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state i {
  font-size: 48px;
  opacity: 0.25;
  margin-bottom: 16px;
  display: block;
}
.empty-state-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.empty-state-text {
  font-size: 13px;
  margin-bottom: 16px;
  max-width: 320px;
  margin-inline: auto;
}


/* ═══ AUTH PAGES (login/register — no sidebar) ═══ */

.auth-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--navbar-h));
  margin-top: var(--navbar-h);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-md);
}
.auth-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 24px;
  letter-spacing: -0.3px;
}
.auth-footer {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 20px;
}
.auth-footer a { color: var(--accent-text); }
.auth-footer a:hover { color: var(--text-primary); }


/* ═══ GRID & LAYOUT HELPERS ═══ */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}


/* ═══ SPACING ═══ */

.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mb-32 { margin-bottom: 32px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }


/* ═══ FOOTER ═══ */

.footer {
  margin-left: var(--sidebar-w);
  padding: 16px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  transition: margin-left var(--transition);
}
.footer a { color: var(--text-secondary); text-decoration: none; }
.footer a:hover { color: var(--accent-text); }

/* Footer for pages without sidebar (auth, public) */
.footer-simple {
  padding: 16px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
}
.footer-simple a { color: var(--text-secondary); text-decoration: none; }
.footer-simple a:hover { color: var(--accent-text); }


/* ═══ MOBILE BOTTOM TAB BAR ═══ */

.bottom-tabs {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  z-index: 90;
  padding: 4px 0;
  padding-bottom: env(safe-area-inset-bottom, 4px);
}
.bottom-tabs-inner {
  display: flex;
  justify-content: space-around;
}
.bottom-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 10px;
  font-weight: 500;
  border: none;
  background: none;
  cursor: pointer;
  transition: color var(--transition);
  min-width: 56px;
}
.bottom-tab i { font-size: 18px; }
.bottom-tab.active { color: var(--accent-text); }
.bottom-tab:hover { color: var(--text-primary); }
.bottom-tab.theme-toggle {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 2px;
}
.bottom-tab.theme-toggle i {
  grid-row: 1; grid-column: 1;
  position: static;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}


/* ═══ ANIMATIONS ═══ */

.fade-in { animation: fadeIn 0.4s ease both; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.stagger-1 { animation-delay: 0.05s; }
.stagger-2 { animation-delay: 0.1s; }
.stagger-3 { animation-delay: 0.15s; }
.stagger-4 { animation-delay: 0.2s; }


/* ═══ RESPONSIVE — TABLET ═══ */

@media (max-width: 1024px) {
  .main-content { padding: 20px 24px; }
}

/* ═══ RESPONSIVE — MOBILE ═══ */

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay.open { display: block; }
  .content-wrapper { margin-left: 0; }
  .main-content { padding: 16px; padding-bottom: 80px; }
  .footer { margin-left: 0; display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px 14px; }
  .stat-value { font-size: 20px; }
  .stat-icon { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  body.authenticated > .navbar { display: none; }
  body.authenticated > .app-layout { margin-top: 0; }
  body.authenticated .sidebar { top: 0; }
  body.authenticated .main-content { padding-bottom: 64px; }
  .navbar-center { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .bottom-tabs { display: block; }
  .card-header { padding: 12px 14px; }
  .card-body { padding: 14px; }
  table { font-size: 12px; }
  thead th, tbody td { padding: 8px 10px; }
  .modal { padding: 16px; }
  .modal-dialog { max-width: none; }
  .modal-dialog-sm { max-width: none; }
  .modal-dialog-lg { max-width: none; }
  .modal-content { max-height: calc(100vh - 32px); border-radius: var(--radius); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .main-content { padding: 12px; padding-bottom: 80px; }
  .page-title { font-size: 18px; }
  .auth-card { padding: 24px; }
  .modal { padding: 8px; }
  .modal-content { max-height: calc(100vh - 16px); border-radius: var(--radius-sm); }
  .modal-header { padding: 12px 14px; }
  .modal-body { padding: 14px; }
  .modal-footer { padding: 12px 14px; }
}

/* ═══ RESPONSIVE — LANDSCAPE PHONE ═══ */
/* Phones in landscape: height ≤500px (all phones max ~430px, tablets min ~600px) */

@media (max-height: 500px) and (orientation: landscape) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay.open { display: block; }
  .content-wrapper { margin-left: 0; }
  .main-content { padding: 8px 16px; padding-bottom: 60px; }
  .footer { margin-left: 0; display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 10px 12px; }
  .stat-value { font-size: 20px; }
  .stat-icon { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  body.authenticated > .navbar { display: none; }
  body.authenticated > .app-layout { margin-top: 0; }
  body.authenticated .sidebar { top: 0; }
  body.authenticated .main-content { padding-bottom: 48px; }
  .navbar-center { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .bottom-tabs { display: block; }
  .card-header { padding: 10px 14px; }
  .card-body { padding: 12px; }
  table { font-size: 12px; }
  thead th, tbody td { padding: 6px 10px; }
  .modal { padding: 8px; }
  .modal-dialog { max-width: none; }
  .modal-dialog-sm { max-width: none; }
  .modal-dialog-lg { max-width: none; }
  .modal-content { max-height: calc(100vh - 16px); }
  .section-title { margin-bottom: 8px; }
}
