/* ============================================
   CyberSOC Playbook — Core Theme & Layout
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Backgrounds */
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2234;
    --bg-hover: #1e293b;
    --bg-active: #243044;

    /* Borders */
    --border-primary: #1e3a5f;
    --border-secondary: #2d4a6f;
    --border-glow: #0ea5e9;

    /* Text */
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-heading: #f8fafc;

    /* Accents */
    --accent-cyan: #06b6d4;
    --accent-cyan-dim: rgba(6, 182, 212, 0.15);
    --accent-green: #10b981;
    --accent-green-dim: rgba(16, 185, 129, 0.15);
    --accent-purple: #a855f7;
    --accent-purple-dim: rgba(168, 85, 247, 0.15);
    --accent-amber: #f59e0b;
    --accent-amber-dim: rgba(245, 158, 11, 0.15);
    --accent-red: #ef4444;
    --accent-red-dim: rgba(239, 68, 68, 0.15);
    --accent-blue: #3b82f6;
    --accent-blue-dim: rgba(59, 130, 246, 0.15);

    /* Layout */
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --content-max-width: 960px;
    --border-radius: 8px;
    --border-radius-sm: 4px;
    --border-radius-lg: 12px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    --shadow-glow-cyan: 0 0 20px rgba(6, 182, 212, 0.15);
    --shadow-glow-purple: 0 0 20px rgba(168, 85, 247, 0.15);
}

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

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

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- Grid Background Pattern --- */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(6, 182, 212, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(6, 182, 212, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    color: var(--text-heading);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

h1 { font-size: 2rem; margin-bottom: 1rem; }
h2 { font-size: 1.5rem; margin-bottom: 0.875rem; margin-top: 2.5rem; }
h3 { font-size: 1.25rem; margin-bottom: 0.75rem; margin-top: 2rem; }
h4 { font-size: 1.1rem; margin-bottom: 0.5rem; margin-top: 1.5rem; }
h5 { font-size: 0.95rem; margin-bottom: 0.375rem; margin-top: 1rem; }
h6 { font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--text-secondary); }

p {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

a {
    color: var(--accent-cyan);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: #22d3ee;
    text-decoration: underline;
}

strong { color: var(--text-heading); }

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

li {
    margin-bottom: 0.375rem;
}

code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.875em;
    background: var(--bg-tertiary);
    padding: 0.125rem 0.375rem;
    border-radius: var(--border-radius-sm);
    color: var(--accent-cyan);
}

hr {
    border: none;
    border-top: 1px solid var(--border-primary);
    margin: 2rem 0;
}

/* --- Top Bar --- */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    z-index: 1000;
    backdrop-filter: blur(12px);
    background: rgba(17, 24, 39, 0.95);
}

.topbar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-right: 2rem;
    flex-shrink: 0;
}

.topbar-logo svg {
    width: 32px;
    height: 32px;
}

.topbar-logo span {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-heading);
    white-space: nowrap;
}

.topbar-logo .logo-accent {
    color: var(--accent-cyan);
}

.topbar-search {
    flex: 1;
    max-width: 480px;
    position: relative;
}

.topbar-search input {
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.topbar-search input::placeholder {
    color: var(--text-muted);
}

.topbar-search input:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px var(--accent-cyan-dim);
}

.topbar-search .search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 16px;
    height: 16px;
    pointer-events: none;
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 1001;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-primary);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.search-result-item:hover {
    background: var(--bg-hover);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-heading);
}

.search-result-context {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.search-result-context mark {
    background: var(--accent-cyan-dim);
    color: var(--accent-cyan);
    border-radius: 2px;
    padding: 0 2px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.btn-topbar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border-primary);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-topbar:hover {
    background: var(--bg-hover);
    color: var(--text-heading);
    border-color: var(--border-secondary);
}

.btn-menu {
    display: none;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    overflow-y: auto;
    z-index: 900;
    padding: 1rem 0;
    transition: transform var(--transition-normal);
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-section-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 1.25rem 1.25rem 0.5rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
}

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

.sidebar-nav a.active {
    color: var(--accent-cyan);
    background: var(--accent-cyan-dim);
    border-left-color: var(--accent-cyan);
}

.sidebar-nav a svg,
.sidebar-nav a .nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-nav a.active svg,
.sidebar-nav a.active .nav-icon {
    opacity: 1;
}

.sidebar-nav .nav-label {
    flex: 1;
}

.sidebar-nav .nav-count {
    font-size: 0.7rem;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    font-family: 'JetBrains Mono', monospace;
}

/* In-page TOC in sidebar */
.sidebar-toc {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-primary);
}

.sidebar-toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-toc-list a {
    padding: 0.375rem 1.25rem 0.375rem 1.5rem;
    font-size: 0.8rem;
    border-left: 2px solid transparent;
}

.sidebar-toc-list a.toc-h3 {
    padding-left: 2.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sidebar-toc-list a.toc-active {
    color: var(--accent-cyan);
    border-left-color: var(--accent-cyan);
}

/* --- Main Content Area --- */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 2rem 2.5rem 4rem;
    max-width: calc(var(--content-max-width) + 5rem);
    position: relative;
    z-index: 1;
}

/* Page header area */
.page-header {
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-primary);
}

.page-header h1 {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-header .page-icon {
    width: 36px;
    height: 36px;
    color: var(--accent-cyan);
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-top: 0.5rem;
    margin-bottom: 0;
}

.page-meta {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.page-meta span {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

/* Section dividers */
.section {
    margin-bottom: 3rem;
}

.section > h2:first-child {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-primary);
}

.section-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--accent-cyan-dim);
    color: var(--accent-cyan);
    border-radius: 50%;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -100px;
    left: 1rem;
    background: var(--accent-cyan);
    color: var(--bg-primary);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    z-index: 9999;
    font-weight: 600;
}

.skip-link:focus {
    top: 0.5rem;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-primary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-secondary);
}

/* --- Selection --- */
::selection {
    background: var(--accent-cyan-dim);
    color: var(--text-heading);
}

/* --- Responsive --- */
@media (max-width: 1199px) {
    .sidebar {
        width: 220px;
    }
    .main-content {
        margin-left: 220px;
    }
}

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

    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
        box-shadow: var(--shadow-lg);
    }

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

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        top: var(--topbar-height);
        background: rgba(0, 0, 0, 0.5);
        z-index: 899;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 1.5rem 1rem 3rem;
    }

    .topbar-logo span {
        display: none;
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.1rem; }
}

@media (max-width: 480px) {
    .topbar-search {
        display: none;
    }

    .main-content {
        padding: 1rem 0.75rem 2rem;
    }
}
