/* ==========================================================================
   Cybersecurity Foundations — Global Design System
   Phase 1 shared core. No page-level CSS is allowed outside this file.
   ========================================================================== */

/* ---------- Theme tokens ---------- */
:root {
  --radius-md: 8px;
  --radius-sm: 5px;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-width: 280px;
  --header-height: 56px;
  --transition-fast: 0.2s ease;
}

:root[data-theme="dark"] {
  --bg-primary: #0b1220;
  --bg-secondary: #131c2e;
  --bg-elevated: #1a2540;
  --text-primary: #e8edf5;
  --text-secondary: #9aa7bd;
  --accent-blue: #4da3ff;
  --accent-blue-hover: #7bbcff;
  --border-color: #2a3652;
  --shadow-color: rgba(0, 0, 0, 0.45);
  --code-bg: #0e1729;
}

:root[data-theme="light"] {
  --bg-primary: #f6f8fb;
  --bg-secondary: #ffffff;
  --bg-elevated: #eef2f8;
  --text-primary: #17233b;
  --text-secondary: #4c5a72;
  --accent-blue: #1f6feb;
  --accent-blue-hover: #1a5cc4;
  --border-color: #d3dce8;
  --shadow-color: rgba(23, 35, 59, 0.12);
  --code-bg: #eef2f8;
}

/* ---------- Global reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

img,
svg {
  max-width: 100%;
  display: block;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

a {
  color: var(--accent-blue);
  text-decoration: none;
}

a:hover {
  color: var(--accent-blue-hover);
  text-decoration: underline;
}

h1, h2, h3, h4 {
  line-height: 1.25;
  color: var(--text-primary);
}

h1 { font-size: 1.9rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.4rem; margin: 1.6rem 0 0.8rem; }
h3 { font-size: 1.15rem; margin: 1.2rem 0 0.6rem; }

p, li {
  color: var(--text-primary);
}

code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.1rem 0.35rem;
  font-size: 0.9em;
}

/* ---------- App shell / header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--header-height);
  padding: 0 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.site-header .site-title {
  font-weight: 700;
  color: var(--text-primary);
}

.site-header .site-title:hover {
  color: var(--accent-blue);
  text-decoration: none;
}

.header-spacer {
  flex: 1;
}

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.menu-toggle:hover {
  background: var(--bg-elevated);
}

.menu-toggle .bar {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--text-primary);
  border-radius: 2px;
  transition: transform var(--transition-fast);
}

.theme-toggle {
  margin-left: auto;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  background: var(--bg-elevated);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.theme-toggle:hover {
  border-color: var(--accent-blue);
}

/* ---------- Layout: sidebar + main ---------- */
.layout {
  display: flex;
  min-height: calc(100vh - var(--header-height));
}

.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 1rem 0.75rem 2rem;
  overflow-y: auto;
  max-height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
  transition: transform 0.25s ease;
}

.sidebar .nav-section {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin: 1.1rem 0.5rem 0.35rem;
}

.sidebar ul {
  list-style: none;
}

.sidebar nav a {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar nav a:hover {
  background: var(--bg-elevated);
  color: var(--accent-blue);
  text-decoration: none;
}

.sidebar nav a.active {
  background: var(--bg-elevated);
  color: var(--accent-blue);
  font-weight: 600;
}

.sidebar-home a {
  display: block;
  padding: 0.45rem 0.6rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.main-content {
  flex: 1;
  min-width: 0;
}

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

body.sidebar-open .backdrop {
  display: block;
}

/* ---------- Container ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

/* ---------- Grid utilities ---------- */
.grid-2,
.grid-3 {
  display: grid;
  gap: 1rem;
  margin: 1rem 0;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.col-span {
  grid-column: 1 / -1;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  box-shadow: 0 2px 6px var(--shadow-color);
  transition: border-color var(--transition-fast), transform var(--transition-fast);
}

.card:hover {
  border-color: var(--accent-blue);
}

.card h3 {
  margin: 0 0 0.4rem;
  font-size: 1.02rem;
}

.card h3 a {
  color: var(--text-primary);
}

.card h3 a:hover {
  color: var(--accent-blue);
  text-decoration: none;
}

.card p {
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.card-badge {
  margin-top: 0.6rem;
}

/* ---------- Lists ---------- */
ul,
ol {
  padding-left: 1.3rem;
  margin: 0.5rem 0;
}

li {
  margin: 0.3rem 0;
}

.list-unstyled {
  list-style: none;
  padding-left: 0;
}

.link-list {
  list-style: none;
  padding-left: 0;
}

.link-list li {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.link-list li:last-child {
  border-bottom: none;
}

/* ---------- Disclosure (details/summary) ---------- */
details {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin: 0.6rem 0;
  overflow: hidden;
}

details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: background var(--transition-fast);
}

details > summary::-webkit-details-marker {
  display: none;
}

details > summary:hover {
  background: var(--bg-elevated);
}

details > summary::after {
  content: "+";
  flex: 0 0 auto;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-blue);
  transition: transform 0.25s ease;
}

details[open] > summary::after {
  transform: rotate(45deg);
}

@keyframes disclosure-open {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

details[open] > *:not(summary) {
  animation: disclosure-open 0.3s ease;
}

details .details-body {
  padding: 0.25rem 1rem 0.9rem;
  color: var(--text-secondary);
}

details .details-body p {
  color: var(--text-secondary);
}

/* QA accordions inside cards */
.qa-block details {
  background: var(--bg-elevated);
}

/* ---------- Badges / inputs / misc ---------- */
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-blue);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

.filter-input {
  width: 100%;
  max-width: 480px;
  padding: 0.6rem 0.9rem;
  font: inherit;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.filter-input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--shadow-color);
}

.filter-empty-state {
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 1rem;
}

.hidden {
  display: none !important;
}

.section-heading {
  margin-top: 2.2rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--accent-blue);
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    max-height: none;
    z-index: 45;
    transform: translateX(-105%);
    box-shadow: 4px 0 14px var(--shadow-color);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .grid-2,
  .grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }

  h1 {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 1rem 0.85rem 2rem;
  }

  .site-header {
    padding: 0 0.6rem;
  }
}

/* ---------- Inline SVG diagram system (details tier) ---------- */
.diagram {
  display: block;
  width: 100%;
  height: auto;
  margin: 0.5rem 0;
}

.diagram text {
  fill: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
}

.diagram .title {
  font-size: 15px;
  font-weight: 700;
}

.diagram .muted {
  fill: var(--text-secondary);
  font-size: 11.5px;
}

.diagram .node {
  fill: var(--bg-secondary);
  stroke: var(--border-color);
  stroke-width: 1.5;
}

.diagram .node-accent {
  fill: var(--bg-elevated);
  stroke: var(--accent-blue);
  stroke-width: 1.5;
}

.diagram .flow {
  stroke: var(--accent-blue);
  stroke-width: 2;
  fill: none;
}

.diagram .flow-head {
  fill: var(--accent-blue);
  stroke: none;
}

.diagram .warn {
  stroke: #e5484d;
  stroke-width: 2;
  fill: none;
}

.diagram .warn-text {
  fill: #e5484d;
  font-size: 11.5px;
  font-weight: 600;
}

.caption {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: center;
  margin: 0.35rem 0 0.25rem;
}
