:root {
  --bg:        #0f1117;
  --card:      #1a1d27;
  --border:    #2d3748;
  --primary:   #6366f1;
  --primary-d: #4f46e5;
  --success:   #10b981;
  --danger:    #ef4444;
  --warn:      #f59e0b;
  --muted:     #64748b;
  --text:      #e2e8f0;
  --fg:        #e2e8f0;
  --input-bg:  #131720;
  --th-bg:     #141720;
  --code-bg:   rgba(255,255,255,.06);
}

body.light {
  --bg:        #f1f5f9;
  --card:      #ffffff;
  --border:    #dde3ed;
  --primary:   #4f46e5;
  --primary-d: #4338ca;
  --success:   #059669;
  --danger:    #dc2626;
  --warn:      #d97706;
  --muted:     #8898aa;
  --text:      #1e293b;
  --fg:        #1e293b;
  --input-bg:  #f8fafc;
  --th-bg:     #f1f5f9;
  --code-bg:   rgba(0,0,0,.06);
}

/* theme toggle button */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  transition: all .12s;
  line-height: 1;
  padding: 0;
}
.theme-toggle:hover { background: var(--card); color: var(--text); }

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { text-decoration: none; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Isolate page content stacking context so it never bleeds above nav/nav-mobile */
#app { isolation: isolate; }

/* ── NAV ── */
nav {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 200;
}
.nav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  color: #818cf8;
  cursor: pointer;
}
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-link {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.12s;
}
.nav-link:hover, .nav-link.active { background: var(--card); color: var(--text); }
.nav-right { display: flex; align-items: center; gap: 10px; }

/* ── CARD ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 18px;
  height: 36px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: all 0.12s;
  border: none;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-d); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--card); color: var(--text); }
.btn-sm { padding: 0 12px; height: 30px; font-size: 13px; border-radius: 6px; line-height: 1; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-full { width: 100%; }

/* ── INPUTS ── */
.input, .select-input {
  width: 100%;
  padding: 9px 13px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.12s;
  font-family: inherit;
}
.input:focus, .select-input:focus { border-color: var(--primary); }
.input::placeholder { color: var(--muted); }
.select-input { appearance: none; cursor: pointer; }

label.form-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 5px;
}

/* ── BADGE ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.badge-green  { background: #064e3b; color: #34d399; }
.badge-red    { background: #7f1d1d; color: #f87171; }
.badge-blue   { background: #1e1b4b; color: #818cf8; }
.badge-yellow { background: #78350f; color: #fbbf24; }
.badge-gray   { background: #1e293b; color: #64748b; }
.badge-purple { background: #3b0764; color: #c4b5fd; }

body.light .badge-green  { background: #d1fae5; color: #065f46; }
body.light .badge-red    { background: #fee2e2; color: #991b1b; }
body.light .badge-blue   { background: #e0e7ff; color: #3730a3; }
body.light .badge-yellow { background: #fef3c7; color: #92400e; }
body.light .badge-gray   { background: #f1f5f9; color: #475569; }
body.light .badge-purple { background: #ede9fe; color: #5b21b6; }

/* ── TABLE ── */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tbl td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover td { background: var(--th-bg); }

/* ── TOAST ── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  align-items: flex-end;
}
.toast {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  max-width: 340px;
  pointer-events: auto;
  animation: toast-in 0.2s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.toast-success { background: #064e3b; border: 1px solid #10b981; color: #6ee7b7; }
.toast-error   { background: #7f1d1d; border: 1px solid #ef4444; color: #fca5a5; }
.toast-info    { background: #1e1b4b; border: 1px solid #6366f1; color: #a5b4fc; }
@keyframes toast-in { from { opacity: 0; transform: translateX(60px); } to { opacity: 1; transform: none; } }

/* ── MODAL ── */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#modal-overlay.open { display: flex; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(2px);
}

/* ── SPINNER ── */
.spinner {
  display: inline-block;
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; justify-content: center; padding: 60px; }

/* ── CODE / TOKEN ── */
.code { font-family: 'Consolas', 'Monaco', monospace; background: var(--code-bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; color: var(--primary); }
.token-box {
  font-family: monospace;
  font-size: 12px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  word-break: break-all;
  color: #34d399;
}

/* ── EMPTY STATE ── */
.empty-box {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
}
.empty-box .emo { font-size: 48px; margin-bottom: 12px; }
.empty-box h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-box p  { font-size: 14px; margin-bottom: 20px; }

/* ── BREADCRUMB ── */
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 18px; }
.breadcrumb a { color: #818cf8; cursor: pointer; }
.breadcrumb span { margin: 0 6px; }

/* ── HERO ── */
.hero-glow {
  background: radial-gradient(ellipse at 50% -10%, rgba(99,102,241,0.18) 0%, transparent 65%);
}
.feature-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin-bottom: 14px;
  flex-shrink: 0;
}

/* ── SECTION ── */
.page-wrap { max-width: 1024px; margin: 0 auto; padding: 32px 20px; }
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
}
.page-title { font-size: 22px; font-weight: 700; }
.page-sub   { font-size: 13px; color: var(--muted); margin-top: 3px; }

/* ── GRID ── */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }

/* ── FORM GROUP ── */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

/* ── UTILS ── */
.mt-auto { margin-top: auto; }
.gap-2 { gap: 8px; }
.sep { border-top: 1px solid var(--border); margin: 16px 0; }

/* ── STATS GRID ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-card {
  text-align: center;
  padding: 18px 12px 14px;
}
.stat-value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}
.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-top: 7px;
  line-height: 1.3;
}
.stat-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.3;
}
.section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
  margin-top: 0;
}

/* ── AUDIT FILTERS ── */
.audit-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.audit-filters .input {
  height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

/* ── HAMBURGER BUTTON ── */
.nav-burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.12s;
}
.nav-burger:hover { background: var(--card); }
.nav-burger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
.nav-burger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-burger.open span:nth-child(2) { opacity: 0; }
.nav-burger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── MOBILE NAV DRAWER ── */
.nav-mobile {
  display: none;
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  z-index: 199;
  padding: 6px 0 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.nav-mobile.open { display: block; }
.nav-mobile .nav-link {
  display: block;
  padding: 11px 20px;
  border-radius: 0;
  font-size: 15px;
  width: 100%;
}
.nav-mobile-sep {
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

/* ── TABLE SCROLL WRAPPER ── */
.tbl-wrap, .tbl-scroll-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── NAV DROPDOWN GROUPS (desktop) ── */
.nav-dropdown-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.nav-dropdown-toggle {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 2px;
  user-select: none;
}
.nav-caret {
  font-size: 9px;
  opacity: 0.6;
  margin-left: 1px;
  transition: transform .15s;
}
.nav-dropdown-open .nav-caret {
  transform: rotate(180deg);
}
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  min-width: 160px;
  padding: 6px 0;
  z-index: 9999;
  white-space: nowrap;
}
.nav-dropdown-open .nav-dropdown-menu {
  display: block;
}
.nav-dropdown-item {
  display: block;
  padding: 8px 16px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background .1s;
}
.nav-dropdown-item:hover {
  background: rgba(99,102,241,.12);
  color: var(--primary);
}

/* ── MOBILE NAV GROUP LABELS ── */
.nav-mobile-group-label {
  padding: 10px 20px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 2px;
}
.nav-mobile-group-item {
  padding-left: 32px !important;
}

/* ── PROJECT GEAR DROPDOWN ── */
.proj-gear-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  min-width: 170px;
  padding: 6px 0;
  z-index: 9000;
  white-space: nowrap;
}
.proj-gear-wrap.open .proj-gear-menu { display: block; }
.proj-gear-item {
  display: block;
  padding: 9px 16px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background .1s;
}
.proj-gear-item:hover { background: rgba(99,102,241,.1); }
.proj-gear-danger { color: var(--danger) !important; }
.proj-gear-danger:hover { background: rgba(239,68,68,.1) !important; }

/* ── TOGGLE SWITCH ── */
.sw { display: inline-flex; align-items: center; cursor: pointer; vertical-align: middle; gap: 7px; user-select: none; }
.sw-track {
  width: 38px; height: 21px; border-radius: 11px;
  background: rgba(148,163,184,.3); position: relative;
  transition: background .18s; flex-shrink: 0;
}
.sw-track.on  { background: #10b981; }
.sw-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 15px; height: 15px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .18s;
}
.sw-track.on .sw-thumb { transform: translateX(17px); }

/* ── FLOATING GEAR MENU (position:fixed, escapes table overflow) ── */
#gear-float-menu {
  position: fixed;
  display: none;
  z-index: 99999;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.45);
  min-width: 180px;
  padding: 6px 0;
  white-space: nowrap;
}

/* ── USER GEAR DROPDOWN ── */
.user-gear-wrap { position: relative; display: inline-block; }
.user-gear-btn  { cursor: pointer; }
.user-gear-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  min-width: 180px;
  padding: 6px 0;
  z-index: 9000;
  white-space: nowrap;
  text-align: left;
}
.user-gear-wrap.open .user-gear-menu { display: block; }
.user-gear-section {
  font-size: 10px;
  color: var(--muted);
  padding: 6px 14px 2px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.user-gear-item {
  display: block;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background .1s;
}
.user-gear-item:hover { background: rgba(99,102,241,.1); }
.user-gear-sep { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.user-gear-danger { color: var(--danger) !important; }
.user-gear-danger:hover { background: rgba(239,68,68,.1) !important; }

/* ── CLICKABLE TABLE ROWS ── */
.tbl-clickable {
  cursor: pointer;
  transition: background .1s;
}
.tbl-clickable:hover {
  background: rgba(99,102,241,.07);
}

/* ── MOBILE FILTER ACCORDION ── */
.filter-toggle-bar { display: none; }
.filter-collapse-body { display: block; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  /* Nav */
  .nav-burger { display: flex; }
  .nav-links-desktop { display: none !important; }

  /* Page layout */
  .page-wrap { padding: 16px 12px; }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .page-header .btn, .page-header button { width: 100%; justify-content: center; }

  /* Grids */
  .cards-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Tables — cards that contain tables get horizontal scroll on mobile */
  .tbl-wrap { overflow-x: auto; }
  .tbl-scroll-wrap { overflow-x: auto; }
  .card:has(> table.tbl) { overflow-x: auto; }
  .card:has(> .tbl-wrap) { overflow-x: auto; }
  .card:has(> .tbl-scroll-wrap) { overflow-x: auto; }

  /* Audit filters stack vertically */
  .audit-filters { flex-direction: column; align-items: stretch; }
  .audit-filters .input  { width: 100% !important; }
  .audit-filters select  { width: 100% !important; }
  .audit-filters button  { width: 100%; }

  /* Mobile filter accordion */
  .filter-toggle-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }
  .filter-caret { font-size: 9px; opacity: .6; transition: transform .15s; }
  .filter-toggle-bar.open .filter-caret { transform: rotate(180deg); }
  .filter-collapse-body { display: none; }
  .filter-toggle-bar.open + .filter-collapse-body { display: block; }
  .filter-toggle-bar-count { margin-left: auto; }

  /* Stab nav scrollable */
  .stab-nav { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }

  /* Modal full-width on mobile */
  #modal-overlay { padding: 10px; }
  #modal-box     { max-width: 100% !important; }

  /* Hero section */
  .hero-glow { padding: 0; }
}
