/* ═══════════════════════════════════════════════════════════════════════════
   UtiliShift Common Handbook Framework CSS
   Master Reference Implementation: sip_article.html
   ═══════════════════════════════════════════════════════════════════════════ */

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

:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --text: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #0284c7;
    --primary-light: #e0f2fe;
    --primary-dark: #0369a1;
    --accent: #f59e0b;
    --accent-light: #fef3c7;
    --success: #10b981;
    --success-light: #d1fae5;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --code-bg: #0f172a;
    --code-text: #f8fafc;
    --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius: 12px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Fira Code', monospace;
    --max-width: 1320px;
    --toc-width: 320px;
}

[data-theme="dark"] {
    --bg: #090d16;
    --surface: #131c2e;
    --surface-hover: #1e293b;
    --text: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border: #1e293b;
    --primary: #38bdf8;
    --primary-light: #0c4a6e;
    --primary-dark: #7dd3fc;
    --accent: #fbbf24;
    --accent-light: #451a03;
    --code-bg: #030712;
    --code-text: #f3f4f6;
    --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #090d16;
        --surface: #131c2e;
        --surface-hover: #1e293b;
        --text: #f8fafc;
        --text-secondary: #cbd5e1;
        --text-muted: #94a3b8;
        --border: #1e293b;
        --primary: #38bdf8;
        --primary-light: #0c4a6e;
        --primary-dark: #7dd3fc;
        --accent: #fbbf24;
        --accent-light: #451a03;
        --code-bg: #030712;
        --code-text: #f3f4f6;
        --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.5);
        --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    }
}

html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.75;
    padding: 0;
    margin: 0;
    overflow-x: clip;
}

/* ── Progress Bar ── */
#progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    width: 0%;
    z-index: 1000;
    transition: width 0.1s;
}

/* ── Layout ── */
.handbook-wrapper {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.toc-sidebar {
    position: fixed;
    top: 4.25rem;
    left: 0;
    z-index: 95;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 0.75rem 1.25rem;
    box-shadow: var(--shadow-lg);
    width: fit-content;
    max-width: min(340px, 92vw);
    box-sizing: border-box;
}

.toc-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
    user-select: none;
}

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

.toc-chevron {
    transition: transform 0.2s ease;
    font-size: 0.75rem;
    color: var(--primary);
    display: inline-block;
}

details[open] .toc-chevron {
    transform: rotate(180deg);
}

details[open] .toc-list {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    max-height: 65vh;
    overflow-y: auto;
    width: 340px;
    max-width: 85vw;
}

@media (max-width: 640px) {
    h1 { font-size: 1.75rem !important; }
    h2 { font-size: 1.35rem !important; }
    h3 { font-size: 1.15rem !important; }
    p { font-size: 0.95rem !important; }
    .hero-banner { padding: 1.25rem !important; }
    .handbook-content { padding: 1rem !important; border-radius: 8px; }
    .toc-link { white-space: normal; word-break: break-word; font-size: 0.8rem; }
    .meta-pills .pill { font-size: 0.75rem; padding: 0.25rem 0.6rem; }
}

.toc-sidebar h3, .toc-summary-heading {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

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

.toc-item {
    margin-bottom: 0.35rem;
}

.toc-link {
    display: block;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toc-link:hover, .toc-link.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

/* ── Main Content ── */
.handbook-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3rem 3.5rem;
    box-shadow: var(--shadow-lg);
    min-width: 0;
}

@media (max-width: 768px) {
    .handbook-content {
        padding: 1.25rem;
    }
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
    font-weight: 800;
    line-height: 1.25;
    margin-top: 2.8rem;
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
    color: var(--text);
}

h1 {
    font-size: 2.75rem;
    margin-top: 0;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

h2 {
    font-size: 2rem;
    padding-bottom: 0.5rem;
    border-bottom: 3px solid var(--border);
    position: relative;
}

h2::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 80px;
    height: 3px;
    background: var(--primary);
}

h3 {
    font-size: 1.45rem;
    color: var(--text);
}

h4 {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

p {
    margin-bottom: 1.25rem;
    color: var(--text-secondary);
    font-size: 1.05rem;
}

a {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

a:hover {
    border-bottom-color: var(--primary);
}

ul, ol {
    margin: 1rem 0 1.5rem 2rem;
    color: var(--text-secondary);
}

li {
    margin-bottom: 0.5rem;
}

/* ── Hero ── */
.hero-banner {
    background: linear-gradient(135deg, var(--primary-light), var(--bg));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    margin-bottom: 2.5rem;
}

.meta-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.pill {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.35rem 0.85rem;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.pill-primary {
    background: var(--primary);
    color: #ffffff;
    border: none;
}

/* ── Alerts ── */
.alert {
    padding: 1.25rem 1.5rem;
    margin: 1.75rem 0;
    border-radius: var(--radius);
    border-left: 5px solid;
    background: var(--bg);
    font-size: 1rem;
}

.alert-title {
    font-weight: 700;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.alert-note {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--text);
}

.alert-tip {
    border-color: var(--success);
    background: var(--success-light);
    color: var(--text);
}

.alert-important {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--text);
}

.alert-warning {
    border-color: var(--warning);
    background: var(--warning-light);
    color: var(--text);
}

.alert-caution {
    border-color: var(--danger);
    background: var(--danger-light);
    color: var(--text);
}

/* ── Code Blocks ── */
.code-block-container {
    position: relative;
    margin: 1.5rem 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.code-header {
    background: #1e293b;
    color: #94a3b8;
    padding: 0.5rem 1rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #334155;
    border-top-left-radius: calc(var(--radius) - 1px);
    border-top-right-radius: calc(var(--radius) - 1px);
}

.code-block-container pre {
    border-bottom-left-radius: calc(var(--radius) - 1px);
    border-bottom-right-radius: calc(var(--radius) - 1px);
}

.copy-btn {
    background: #334155;
    color: #f8fafc;
    border: none;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

.copy-btn:hover {
    background: var(--primary);
}

pre {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 1.25rem;
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    overscroll-behavior-x: contain;
    white-space: pre !important;
    word-break: normal !important;
    word-wrap: normal !important;
    overflow-wrap: normal !important;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.65;
    margin: 0;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) var(--code-bg);
}

pre::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}

pre::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.6);
    border-radius: 4px;
}

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

pre::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    word-break: break-word;
}

pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    white-space: pre !important;
    word-break: normal !important;
    word-wrap: normal !important;
    overflow-wrap: normal !important;
}

/* ── Tables ── */
.table-responsive {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    overscroll-behavior-x: contain;
    margin: 1.75rem 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    position: relative;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) var(--surface-hover);
}

.table-responsive::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}

.table-responsive::-webkit-scrollbar-track {
    background: var(--surface-hover);
    border-radius: 4px;
}

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

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

table {
    width: 100%;
    min-width: 650px;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: left;
}

@media (max-width: 768px) {
    table {
        min-width: 600px;
    }
    th, td {
        padding: 0.65rem 0.85rem;
        font-size: 0.85rem;
    }
}

th, td {
    padding: 0.85rem 1.15rem;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--primary-light);
    color: var(--text);
    font-weight: 700;
}

tr:nth-child(even) {
    background: var(--bg);
}

tr:hover {
    background: var(--surface-hover);
}

/* ── Cards & Badges ── */
.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin: 1.5rem 0;
}

.item-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    transition: transform 0.15s, box-shadow 0.15s;
}

.item-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.item-badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-light);
    color: var(--warning);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-info {
    background: var(--primary-light);
    color: var(--primary);
}

/* ── Search Inputs ── */
.search-box-wrapper {
    margin: 1.5rem 0 2rem 0;
}

.search-input {
    width: 100%;
    padding: 0.85rem 1.25rem;
    font-size: 1rem;
    font-family: var(--font-sans);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ── Diagrams ── */
.diagram-container {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    margin: 2rem 0;
    text-align: center;
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    overscroll-behavior-x: contain;
    box-sizing: border-box;
}

.diagram-title {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text);
}

/* ── Additional Reusable Components ── */
blockquote {
    border-left: 4px solid var(--primary);
    padding: 0.8rem 1.2rem;
    margin: 1.5rem 0;
    background: var(--bg);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-style: italic;
    color: var(--text-secondary);
}

img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
}

figure {
    margin: 1.5rem 0;
    text-align: center;
}

figcaption {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

.comparison-box {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin: 1.75rem 0;
}

.references-list, .references {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--text-muted);
}

.btn-back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s, transform 0.2s;
    z-index: 99;
}

.btn-back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.btn-back-to-top:hover {
    transform: translateY(-3px);
    background: var(--primary-dark);
/* ── Timeline Component ── */
.timeline {
    position: relative;
    margin: 2rem 0;
    padding-left: 2rem;
    border-left: 3px solid var(--primary);
}

.timeline-item {
    position: relative;
    margin-bottom: 1.75rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -2.4rem;
    top: 0.25rem;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid var(--surface);
}

.timeline-year {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--primary);
}

.timeline-content {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-top: 0.35rem;
}

/* ── Decision Trees ── */
.decision-tree-box {
    background: var(--bg);
    border: 2px dashed var(--primary);
    border-radius: var(--radius);
    padding: 1.75rem;
    margin: 1.75rem 0;
}

.tree-node {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.tree-arrow {
    text-align: center;
    font-size: 1.25rem;
    color: var(--primary);
    margin: 0.25rem 0;
}

/* ── Interactive Widget Box ── */
.widget-box {
    background: linear-gradient(135deg, var(--surface), var(--primary-light));
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    padding: 2rem;
    margin: 2rem 0;
}

.widget-form-group {
    margin-bottom: 1.25rem;
}

.widget-label {
    display: block;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.widget-select, .widget-input-num {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text);
}

.widget-btn {
    background: var(--primary);
    color: #ffffff;
    border: none;
    padding: 0.85rem 1.75rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.widget-btn:hover { background: var(--primary-dark); }

.widget-result {
    margin-top: 1.5rem;
    padding: 1.25rem;
    border-radius: 8px;
    display: none;
    font-weight: 600;
}

/* ── Print Styling ── */
@media print {
    .toc-sidebar, #progress-bar, .copy-btn, .search-input, .btn-back-to-top {
        display: none !important;
    }

    .handbook-wrapper {
        display: block;
        padding: 0;
    }

    .handbook-content {
        border: none;
        box-shadow: none;
        padding: 0;
    }

    body {
        background: #ffffff;
        color: #000000;
        font-size: 12pt;
    }

    h1, h2, h3 {
        color: #000000 !important;
        background: none !important;
        -webkit-text-fill-color: initial !important;
    }

    pre, code {
        border: 1px solid #ccc;
        background: #f5f5f5 !important;
        color: #000000 !important;
    }
}
