/* ============================================================
   Custom Properties
   ============================================================ */
:root {
  /* Severity palette — tuned for WCAG AA on --surface */
  --critical: #f87171;
  --high: #fb923c;
  --medium: #facc15;
  --low: #60a5fa;
  --safe: #4ade80;

  /* Surface & text */
  --bg: #0f1117;
  --surface: #1a1d27;
  --text: #e2e4e9;
  --muted: #8b8fa3;
  --border: #2a2d3a;
  --accent: #6366f1;
  --accent-light: #a5b4fc;

  /* Typography */
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ============================================================
   Base Resets
   ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================================
   Navigation
   ============================================================ */
nav:not(.breadcrumbs) {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 3.5rem;
}

.nav-brand {
  font-family: var(--font-mono);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
}

.nav-links a {
  color: var(--accent-light);
  text-decoration: none;
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.nav-links a:hover {
  color: var(--text);
  background-color: rgba(255, 255, 255, 0.05);
}

.nav-links a.active {
  color: #fff;
  background-color: #1e1f3a;
}

/* ============================================================
   Main Container
   ============================================================ */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ============================================================
   Views (hash-routed sections)
   ============================================================ */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* ============================================================
   Headings
   ============================================================ */
h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

/* ============================================================
   Stats Bar
   ============================================================ */
.stats-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  flex: 1;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card-primary {
  flex: 1;
  padding: 1.5rem 1.25rem;
  border-color: var(--accent);
  border-width: 1px 1px 1px 4px;
}

.stat-card-primary .stat-value {
  font-size: 2.25rem;
  color: var(--text);
}

.stats-bar-severity {
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.stat-card-severity {
  padding: 0.875rem 0.75rem;
  text-align: center;
  align-items: center;
  border-top: 3px solid transparent;
}

.stat-card-severity .stat-value {
  font-size: 1.375rem;
}

.stat-card-severity.sev-critical {
  border-top-color: var(--critical);
  border-radius: 2px 2px 10px 10px;
}

.stat-card-severity.sev-high {
  border-top-color: var(--high);
  border-radius: 2px 2px 10px 10px;
}

.stat-card-severity.sev-medium {
  border-top-color: var(--medium);
  border-radius: 2px 2px 10px 10px;
}

.stat-card-severity.sev-low {
  border-top-color: var(--low);
  border-radius: 2px 2px 10px 10px;
}

.stat-critical { color: #fca5a5; }
.stat-high     { color: #fdba74; }
.stat-medium   { color: #fde047; }
.stat-low      { color: #93c5fd; }

/* ============================================================
   Dashboard Grid (panels)
   ============================================================ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.panel {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
}

.panel-body {
  min-height: 12rem;
}

/* ============================================================
   Table Controls (search + filter)
   ============================================================ */
.table-controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.search-input,
.filter-dropdown {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.search-input:focus,
.filter-dropdown:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.search-input:focus:not(:focus-visible),
.filter-dropdown:focus:not(:focus-visible) {
  outline: none;
}

.search-input {
  flex: 1;
}

.filter-dropdown {
  min-width: 10rem;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b8fa3' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.filter-dropdown option {
  background-color: var(--surface);
  color: var(--text);
}

/* ============================================================
   Table
   ============================================================ */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  background-color: var(--surface);
  border-collapse: collapse;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  font-size: 0.875rem;
}

thead th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

thead th:hover {
  color: var(--text);
}

tbody td {
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

/* ============================================================
   Severity Badges
   ============================================================ */
.badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.175rem 0.5rem;
  border-radius: 9999px;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-critical {
  color: #fecaca;
  background-color: #3b1113;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.badge-high {
  color: #fed7aa;
  background-color: #3b1e0a;
  border: 1px solid rgba(249, 115, 22, 0.4);
}

.badge-medium {
  color: #fef08a;
  background-color: #332b05;
  border: 1px solid rgba(234, 179, 8, 0.35);
}

.badge-low {
  color: #bfdbfe;
  background-color: #0f1e3d;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.badge-safe {
  color: #bbf7d0;
  background-color: #0b2618;
  border: 1px solid rgba(34, 197, 94, 0.35);
}

/* ============================================================
   Breadcrumbs
   ============================================================ */
.breadcrumbs {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.breadcrumbs a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.breadcrumbs a:hover {
  color: var(--text);
}

.breadcrumbs .separator {
  margin: 0 0.375rem;
  opacity: 0.5;
}

/* ============================================================
   Skill Detail
   ============================================================ */
.detail-metadata {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.detail-findings {
  margin-top: 1rem;
}

.findings-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.findings-list li {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}

/* ============================================================
   Utility Classes
   ============================================================ */
.muted {
  color: var(--muted);
}

/* ============================================================
   Severity Bar Chart
   ============================================================ */
.severity-bar {
  display: flex;
  height: 2rem;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.severity-bar-segment {
  height: 100%;
  transition: width 0.3s ease;
  min-width: 2px; /* ensure tiny segments are visible */
}

/* ============================================================
   Bar Chart Legend
   ============================================================ */
.bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.8125rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-count {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text);
}

/* ============================================================
   Category Bar Chart
   ============================================================ */
.category-bars {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.category-bar-row {
  display: grid;
  grid-template-columns: 10rem 1fr 2.5rem;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8125rem;
}

.category-bar-label {
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-bar-track {
  height: 1.25rem;
  background-color: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  overflow: hidden;
}

.category-bar-fill {
  height: 100%;
  background-color: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.category-bar-count {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text);
}

/* ============================================================
   Top Risks Section
   ============================================================ */
.top-risks {
  margin-top: 2rem;
}

.top-risks h2 {
  margin-bottom: 1rem;
}

.risk-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}

.risk-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.risk-card-skill {
  font-weight: 600;
  color: var(--text);
}

.risk-card-description {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ============================================================
   Category Badge
   ============================================================ */
.badge-category {
  color: var(--muted);
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}

/* ============================================================
   Table Links and Sort Indicators
   ============================================================ */
tbody a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

tbody a:hover {
  text-decoration: underline;
}

th.sort-asc::after {
  content: ' \2191';
  color: var(--accent);
  font-size: 0.75rem;
}

th.sort-desc::after {
  content: ' \2193';
  color: var(--accent);
  font-size: 0.75rem;
}

/* ============================================================
   Metadata Grid
   ============================================================ */
.metadata-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.metadata-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.metadata-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metadata-value {
  font-size: 0.9375rem;
  color: var(--text);
}

/* ============================================================
   Analyzer Pills
   ============================================================ */
.analyzer-pill {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--muted);
}

/* ============================================================
   Finding Cards (details/summary based)
   ============================================================ */
.finding-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  overflow: hidden;
}

.finding-card summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem;
  cursor: pointer;
  flex-wrap: wrap;
  list-style: none;
}

.finding-card summary::-webkit-details-marker {
  display: none;
}

.finding-card summary::before {
  content: '\25B6';
  font-size: 0.625rem;
  color: var(--muted);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.finding-card[open] summary::before {
  transform: rotate(90deg);
}

.finding-title {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
  flex: 1;
  min-width: 0;
}

.finding-body {
  padding: 0 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.finding-description {
  font-size: 0.875rem;
  color: var(--text);
  line-height: 1.6;
}

.finding-file {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
}

.finding-snippet pre {
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--text);
}

.finding-remediation {
  font-size: 0.875rem;
  line-height: 1.5;
  padding: 0.75rem 1rem;
  background-color: rgba(99, 102, 241, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  color: var(--muted);
}

.finding-remediation strong {
  color: var(--text);
}

/* ============================================================
   Safe/Unsafe Status
   ============================================================ */
.status-safe {
  color: var(--safe);
  font-weight: 600;
}

.status-unsafe {
  color: var(--critical);
  font-weight: 600;
}

/* ============================================================
   No Findings Message
   ============================================================ */
.no-findings {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

.no-findings .badge {
  font-size: 1rem;
  padding: 0.375rem 1rem;
  margin-bottom: 0.75rem;
}

/* ============================================================
   Footer
   ============================================================ */
footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  margin-top: 2rem;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.footer-item a {
  color: #818cf8;
  text-decoration: none;
  display: inline-block;
  padding: 0.25rem 0;
  min-height: 1.5rem;
}

.footer-item a:hover {
  text-decoration: underline;
}

/* ============================================================
   Notes List
   ============================================================ */
.note-card {
  display: block;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.note-card:hover {
  border-color: var(--accent);
  background-color: rgba(99, 102, 241, 0.04);
}

.note-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.note-date {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.note-tags {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.tag-pill {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  background-color: rgba(99, 102, 241, 0.1);
  color: var(--accent);
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.note-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.note-excerpt {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ============================================================
   Note Detail
   ============================================================ */
.note-detail-header {
  margin-bottom: 2rem;
}

.note-detail-header h1 {
  margin-bottom: 0.75rem;
}

.note-detail-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.note-body {
  font-size: 0.9375rem;
  line-height: 1.75;
  color: var(--text);
}

.note-body h3 {
  font-size: 1.0625rem;
  font-weight: 600;
  margin: 1.75rem 0 0.75rem;
  color: var(--text);
}

.note-body p {
  margin-bottom: 1rem;
}

.note-body ul,
.note-body ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.note-body li {
  margin-bottom: 0.375rem;
}

.note-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.125rem 0.375rem;
  background-color: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.note-body strong {
  font-weight: 600;
  color: var(--text);
}

.note-body em {
  font-style: italic;
  color: var(--muted);
}

/* ============================================================
   Scan Metadata Bar
   ============================================================ */
.scan-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  font-size: 0.8125rem;
  color: var(--muted);
  padding: 0.75rem 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.scan-meta strong {
  color: var(--text);
}

/* ============================================================
   Reduced Motion (accessibility)
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  .stats-bar {
    flex-direction: column;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .table-controls {
    flex-direction: column;
  }

  .filter-dropdown {
    min-width: unset;
  }

  .nav-inner {
    padding: 0 1rem;
  }

  main {
    padding: 1.5rem 1rem 3rem;
  }

  .metadata-grid {
    grid-template-columns: 1fr;
  }

  .category-bar-row {
    grid-template-columns: 6rem 1fr 2rem;
  }

  .finding-card summary {
    padding: 0.75rem 1rem;
  }

  .risk-card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .note-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .note-detail-meta {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ============================================================
   Focus States
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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