/* ─── Custom Properties ────────────────────────────────────────────────────── */
:root {
  --sidebar-bg: #1a1d23;
  --sidebar-width: 228px;
  --sidebar-link-hover: rgba(255,255,255,.07);
  --sidebar-link-active: rgba(255,255,255,.13);
  --sidebar-text: rgba(255,255,255,.82);
  --sidebar-muted: rgba(255,255,255,.38);
  --surface: #f8fafc;
  --card-bg: #ffffff;
  --border-color: #e8ecf0;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --topbar-height: 52px;

  /* Severity palette */
  --sev-critical: #dc2626;
  --sev-high:     #ea580c;
  --sev-medium:   #d97706;
  --sev-low:      #3b82f6;
  --sev-info:     #6b7280;
}

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

html { font-size: 14px; }
@media (min-width: 768px) { html { font-size: 15px; } }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--surface);
  color: var(--text-primary);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ────────────────────────────────────────────────────────────────── */
#wrapper { min-height: 100vh; }

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  max-width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  font-size: .875rem;
  flex-shrink: 0;
  z-index: 1000;
  transition: transform .25s ease;
}

.sidebar-brand {
  color: #fff !important;
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.sidebar-brand .brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  border-radius: 8px;
  font-size: 1rem;
}
.sidebar-brand .brand-accent { color: #818cf8; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 6px;
  padding: .45rem .75rem;
  font-size: .875rem;
  font-weight: 450;
  transition: background .15s, color .15s;
}
.sidebar-link:hover { background: var(--sidebar-link-hover); color: #fff; }
.sidebar-link.active { background: var(--sidebar-link-active); color: #fff; font-weight: 600; }
.sidebar-link i { font-size: .95rem; opacity: .75; }
.sidebar-link.active i { opacity: 1; }

.sidebar-badge {
  font-size: .7rem;
  font-weight: 600;
  background: rgba(255,255,255,.18);
  color: #fff;
  border-radius: 20px;
  padding: .1rem .45rem;
}
.sidebar-badge-danger { background: #dc2626; }

.sidebar-section-header {
  list-style: none;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--sidebar-muted);
  padding: .25rem .75rem;
  margin-bottom: .25rem;
}

.sidebar-divider { border: none; border-top: 1px solid rgba(255,255,255,.08); margin: 0; }

.sidebar-user-btn {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: .35rem .5rem;
  border-radius: 6px;
  transition: background .15s;
}
.sidebar-user-btn:hover { background: var(--sidebar-link-hover); color: #fff; }
.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: #4f46e5;
  border-radius: 50%;
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-user-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

/* Mobile sidebar */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: .75rem;
  left: .75rem;
  z-index: 1100;
  background: var(--sidebar-bg);
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: .3rem .55rem;
  cursor: pointer;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 999;
}

@media (max-width: 991px) {
  .sidebar-toggle { display: block; }
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
  }
  #sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  #page-content-wrapper { margin-left: 0 !important; }
}

/* ─── Topbar ────────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 1px 0 rgba(0,0,0,.04);
}
.topbar-breadcrumb .breadcrumb { font-size: .8rem; }
.topbar-breadcrumb .breadcrumb-item + .breadcrumb-item::before { color: var(--text-secondary); }

/* ─── Page content ──────────────────────────────────────────────────────────── */
.page-content { padding: 1.75rem; }
@media (max-width: 576px) { .page-content { padding: 1rem; } }

/* ─── Auth wrapper ──────────────────────────────────────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 1.5rem 1rem;
}

.auth-wrapper .row {
  width: 100%;
  margin: 0;
}

.auth-wrapper [class*="col-"] {
  width: 100%;
  max-width: 28rem;
  margin: 0 auto;
  float: none;
}

@media (max-width: 576px) {
  .auth-wrapper {
    align-items: flex-start;
    padding: 1rem .875rem 2rem;
  }

  .auth-wrapper .card-body {
    padding: 1.25rem !important;
  }
}

.login-page {
  width: 100%;
  display: flex;
  justify-content: center;
}

.login-shell {
  width: 100%;
  max-width: 28rem;
  margin: 2rem auto;
}

.login-card {
  width: 100%;
}

.login-logo {
  font-size: 3rem;
}

.login-form .form-control {
  min-height: 2.75rem;
}

@media (max-width: 576px) {
  .login-shell {
    max-width: 100%;
    margin: .5rem auto 0;
  }

  .login-logo {
    font-size: 2.5rem;
  }
}

/* ─── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border-color) !important;
  border-radius: .625rem !important;
  box-shadow: 0 1px 3px rgba(0,0,0,.07) !important;
}
.card-header {
  background: var(--card-bg) !important;
  border-bottom: 1px solid var(--border-color);
  border-radius: .625rem .625rem 0 0 !important;
  font-weight: 600;
  font-size: .875rem;
  padding: .875rem 1.125rem;
}
.card-footer {
  background: var(--card-bg) !important;
  border-top: 1px solid var(--border-color);
  border-radius: 0 0 .625rem .625rem !important;
}

/* ─── Stat cards ─────────────────────────────────────────────────────────────── */
.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--card-bg);
  border-radius: .625rem;
  padding: 1.1rem 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
  border: 1px solid var(--border-color);
  transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.stat-card-danger  { border-color: #fca5a5; background: #fff5f5; }
.stat-card-warning { border-color: #fcd34d; background: #fffbeb; }
.stat-card-neutral { border-color: var(--border-color); }

.stat-icon { font-size: 1.85rem; opacity: .4; flex-shrink: 0; }
.stat-value { font-size: 1.85rem; font-weight: 700; line-height: 1; letter-spacing: -.03em; }
.stat-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-secondary); margin-top: .2rem; }
.stat-sub   { font-size: .72rem; color: #9ca3af; }

/* ─── Health score badge ─────────────────────────────────────────────────────── */
.health-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 1.25rem;
  line-height: 1;
  border: 3px solid;
  flex-shrink: 0;
}
.health-badge-good   { color: #16a34a; border-color: #16a34a; background: #f0fdf4; }
.health-badge-fair   { color: #d97706; border-color: #d97706; background: #fffbeb; }
.health-badge-poor   { color: #dc2626; border-color: #dc2626; background: #fef2f2; }
.health-badge small  { font-size: .55rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; opacity: .7; margin-top: .1rem; }

/* ─── Severity badges ────────────────────────────────────────────────────────── */
.sev-critical { background: #fef2f2; color: var(--sev-critical); border: 1px solid #fecaca; }
.sev-high     { background: #fff7ed; color: var(--sev-high);     border: 1px solid #fed7aa; }
.sev-medium   { background: #fffbeb; color: var(--sev-medium);   border: 1px solid #fde68a; }
.sev-low      { background: #eff6ff; color: var(--sev-low);      border: 1px solid #bfdbfe; }
.sev-info     { background: #f9fafb; color: var(--sev-info);     border: 1px solid #e5e7eb; }

.badge-sev {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .7rem;
  font-weight: 600;
  padding: .2rem .5rem;
  border-radius: 20px;
  white-space: nowrap;
}

/* ─── Tables ─────────────────────────────────────────────────────────────────── */
.table th {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
  color: var(--text-secondary);
  background: #f9fafb;
  border-bottom: 2px solid var(--border-color);
  padding: .65rem 1rem;
}
.table td { vertical-align: middle; padding: .6rem 1rem; border-color: #f3f4f6; }
.table tbody tr:nth-child(even) td { background: #fafbfc; }
.table tbody tr:hover td { background: #f0f4ff; }

/* ─── Risk cards (hardening) ─────────────────────────────────────────────────── */
.risk-card { transition: box-shadow .15s; }
.risk-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1) !important; }
.risk-card-header { display: flex; align-items: center; justify-content: space-between; }
.risk-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 700;
  padding: 0 .55rem;
}
.risk-count-danger  { background: #fef2f2; color: #dc2626; border: 1.5px solid #fca5a5; }
.risk-count-warning { background: #fffbeb; color: #d97706; border: 1.5px solid #fde68a; }
.risk-count-success { background: #f0fdf4; color: #16a34a; border: 1.5px solid #86efac; }
.risk-count-info    { background: #eff6ff; color: #3b82f6; border: 1.5px solid #bfdbfe; }

.user-risk-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .75rem;
  border-bottom: 1px solid #f3f4f6;
  font-size: .82rem;
  gap: .5rem;
}
.user-risk-row:last-child { border-bottom: none; }
.user-risk-row:hover { background: #f9fafb; }
.user-risk-actions { display: flex; gap: .4rem; flex-shrink: 0; }

/* ─── Timeline (user detail) ─────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before {
  content: '';
  position: absolute;
  left: .45rem;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--border-color);
}
.timeline-item { position: relative; margin-bottom: 1rem; }
.timeline-dot {
  position: absolute;
  left: -1.5rem;
  top: .35rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--card-bg);
  background: var(--text-secondary);
}
.timeline-dot-critical { background: var(--sev-critical); }
.timeline-dot-high     { background: var(--sev-high); }
.timeline-dot-medium   { background: var(--sev-medium); }
.timeline-dot-low      { background: var(--sev-low); }

/* ─── Module tile cards ──────────────────────────────────────────────────────── */
.module-tile {
  transition: transform .15s, box-shadow .15s;
  color: inherit;
}
.module-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,.1) !important;
  color: inherit;
}

/* ─── Findings ──────────────────────────────────────────────────────────────── */
.finding-block {
  border-radius: .375rem;
  padding: .6rem .75rem;
  font-size: .82rem;
}
.finding-block-label {
  font-weight: 600;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .25rem;
  opacity: .7;
}
.finding-why  { background: #fff8e1; border: 1px solid #ffe082; }
.finding-todo { background: #e8f5e9; border: 1px solid #a5d6a7; }

/* ─── Collapsible chevron ────────────────────────────────────────────────────── */
.collapse-icon { transition: transform .2s ease; }
[aria-expanded="true"] .collapse-icon { transform: rotate(180deg); }

/* ─── JSON diff viewer ────────────────────────────────────────────────────────── */
.json-diff {
  font-family: 'Courier New', monospace;
  font-size: .78rem;
  background: #1e2229;
  color: #abb2bf;
  border-radius: .375rem;
  padding: .875rem 1rem;
  overflow-x: auto;
  max-height: 300px;
  overflow-y: auto;
}
.json-diff .added   { color: #98c379; }
.json-diff .removed { color: #e06c75; text-decoration: line-through; }
.json-diff .changed { color: #e5c07b; }

/* ─── Country flag ────────────────────────────────────────────────────────────── */
.country-flag { font-size: 1.2em; line-height: 1; }
.suspicious-country td { background: #fef2f2 !important; }

/* ─── Chart container ────────────────────────────────────────────────────────── */
.chart-container { position: relative; }

/* ─── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-secondary);
}
.empty-state-icon { font-size: 2.5rem; opacity: .25; margin-bottom: .75rem; }
.empty-state p    { max-width: 320px; margin: 0 auto .75rem; }

/* ─── Loading skeleton ────────────────────────────────────────────────────────── */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .5; }
}
.skeleton {
  border-radius: .375rem;
  background: #e5e7eb;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-text  { height: .875rem; margin-bottom: .4rem; }
.skeleton-title { height: 1.5rem; margin-bottom: .75rem; width: 60%; }

/* ─── Misc ───────────────────────────────────────────────────────────────────── */
.ls-wide { letter-spacing: .08em; }
.filter-btn.active { box-shadow: 0 0 0 2px currentColor; }
.font-mono { font-family: 'Courier New', monospace; }
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Focus ring */
.btn:focus-visible, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 2px rgba(99,102,241,.35);
  outline: none;
}
