/* WPC-SOP Portal — Main Stylesheet
   Version: 1.0.0
   Fonts: Sora (display/nav) + Source Serif 4 (body/SOP content)
*/

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700&family=Source+Serif+4:ital,wght@0,300;0,400;0,600;1,400&display=swap');

/* ── CSS Custom Properties ──────────────────────────────────────────────────── */
:root {
    /* Brand */
    --brand-navy:       #0f2d4a;
    --brand-blue:       #1a4b7c;
    --brand-mid:        #2563a8;
    --brand-accent:     #3b82f6;
    --brand-gold:       #f0a500;
    --brand-gold-soft:  #fbbf24;

    /* Light Mode */
    --bg-base:          #f5f7fa;
    --bg-surface:       #ffffff;
    --bg-sidebar:       #f0f3f7;
    --bg-nav:           #0f2d4a;
    --bg-hover:         #e8edf5;
    --bg-active:        #dce5f3;
    --border-color:     #d1dae8;
    --border-subtle:    #e8edf5;
    --text-primary:     #111827;
    --text-secondary:   #4b5563;
    --text-muted:       #9ca3af;
    --text-nav:         #e8edf5;
    --text-nav-muted:   rgba(232,237,245,0.6);
    --shadow-sm:        0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:        0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg:        0 10px 30px rgba(0,0,0,0.1);

    /* Classifications */
    --clf-public:           #16a34a;
    --clf-internal:         #2563eb;
    --clf-sensitive:        #d97706;
    --clf-confidential:     #dc2626;
    --clf-highly-conf:      #7c3aed;

    /* Toggle */
    --toggle-bg-off:    #374151;
    --toggle-bg-on:     #3b82f6;
    --toggle-thumb:     #ffffff;

    /* Layout */
    --nav-height:       64px;
    --sidebar-width:    280px;
    --radius-sm:        6px;
    --radius-md:        10px;
    --radius-lg:        14px;
    --radius-xl:        20px;
    --transition:       0.2s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="dark"] {
    --bg-base:          #0d1117;
    --bg-surface:       #161b22;
    --bg-sidebar:       #0d1117;
    --bg-nav:           #090e14;
    --bg-hover:         #1f2937;
    --bg-active:        #263547;
    --border-color:     #30363d;
    --border-subtle:    #21262d;
    --text-primary:     #e6edf3;
    --text-secondary:   #8b949e;
    --text-muted:       #484f58;
    --text-nav:         #e6edf3;
    --text-nav-muted:   rgba(230,237,243,0.5);
    --shadow-sm:        0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md:        0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg:        0 10px 30px rgba(0,0,0,0.5);
}

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

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

body {
    font-family: 'Sora', system-ui, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
    min-height: 100vh;
}

/* ── Navigation Bar ─────────────────────────────────────────────────────────── */
.nav {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--nav-height);
    background: var(--bg-nav);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 100;
    gap: 16px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.3);
}

/* ── Logo ───────────────────────────────────────────────────────────────────── */
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    flex-shrink: 0;
    padding: 4px 0;
}

.logo-mark {
    width: 44px;
    height: 44px;
    position: relative;
}

.logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.logo-text-top {
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.02em;
}

.logo-text-bottom {
    font-size: 9px;
    font-weight: 400;
    color: var(--brand-gold);
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

/* ── Search Bar ─────────────────────────────────────────────────────────────── */
.nav-search {
    flex: 1;
    max-width: 520px;
    margin: 0 auto;
    position: relative;
}

.nav-search input {
    width: 100%;
    height: 38px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 999px;
    padding: 0 40px 0 16px;
    font-family: 'Sora', sans-serif;
    font-size: 14px;
    color: var(--text-nav);
    outline: none;
    transition: background var(--transition), border-color var(--transition);
}

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

.nav-search input:focus {
    background: rgba(255,255,255,0.13);
    border-color: var(--brand-accent);
}

.nav-search-icon {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-nav-muted);
    pointer-events: none;
}

.search-suggestions {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 200;
    display: none;
}

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

.search-suggestion-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background var(--transition);
    text-decoration: none;
}

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

/* ── Nav Right ───────────────────────────────────────────────────────────────── */
.nav-right {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

.nav-icon-btn {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-nav-muted);
    transition: background var(--transition), color var(--transition);
    position: relative;
}

.nav-icon-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-nav);
}

.nav-badge {
    position: absolute;
    top: 4px; right: 4px;
    width: 8px; height: 8px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid var(--bg-nav);
}

.user-avatar-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--brand-gold);
    border: 2px solid rgba(255,255,255,0.2);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--brand-navy);
    display: flex; align-items: center; justify-content: center;
    transition: border-color var(--transition);
    position: relative;
}

.user-avatar-btn:hover { border-color: var(--brand-gold); }

/* Dropdown */
.dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: 300;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity var(--transition), transform var(--transition);
}

.dropdown.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.dropdown-header {
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border-subtle);
}

.dropdown-name { font-weight: 600; font-size: 14px; color: var(--text-primary); }
.dropdown-email { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.dropdown-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 16px;
    font-size: 13px; color: var(--text-secondary);
    text-decoration: none; cursor: pointer;
    transition: background var(--transition), color var(--transition);
    border: none; background: none; width: 100%; text-align: left;
}

.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-item.danger:hover { background: #fef2f2; color: #dc2626; }

[data-theme="dark"] .dropdown-item.danger:hover { background: #1f0a0a; color: #f87171; }

.dropdown-divider { border-top: 1px solid var(--border-subtle); margin: 4px 0; }

/* ── Page Layout ─────────────────────────────────────────────────────────────── */
.layout {
    display: flex;
    margin-top: var(--nav-height);
    min-height: calc(100vh - var(--nav-height));
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: var(--nav-height);
    bottom: 0;
    left: 0;
    overflow-y: auto;
    transition: background var(--transition), border-color var(--transition);
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

.sidebar-section {
    padding: 16px 12px 8px;
}

.sidebar-section-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 0 8px;
    margin-bottom: 4px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    border: none; background: none; width: 100%; text-align: left;
    position: relative;
}

.sidebar-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-item.active {
    background: var(--bg-active);
    color: var(--brand-mid);
    font-weight: 500;
}

.sidebar-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 4px; bottom: 4px;
    width: 3px;
    background: var(--brand-accent);
    border-radius: 0 3px 3px 0;
}

.sidebar-item-badge {
    margin-left: auto;
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-hover);
    color: var(--text-muted);
    padding: 1px 7px;
    border-radius: 999px;
}

.sidebar-item.active .sidebar-item-badge {
    background: rgba(37,99,168,0.12);
    color: var(--brand-mid);
}

/* Classification pills in sidebar */
.clf-pill {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 10px; font-weight: 600;
    padding: 2px 7px;
    border-radius: 999px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.clf-public          { background: #dcfce7; color: #15803d; }
.clf-internal        { background: #dbeafe; color: #1d4ed8; }
.clf-sensitive       { background: #fef3c7; color: #b45309; }
.clf-confidential    { background: #fee2e2; color: #b91c1c; }
.clf-highly_confidential { background: #ede9fe; color: #6d28d9; }

[data-theme="dark"] .clf-public          { background: #052e16; color: #4ade80; }
[data-theme="dark"] .clf-internal        { background: #0c1a3d; color: #60a5fa; }
[data-theme="dark"] .clf-sensitive       { background: #1c1000; color: #fbbf24; }
[data-theme="dark"] .clf-confidential    { background: #1c0000; color: #f87171; }
[data-theme="dark"] .clf-highly_confidential { background: #1b0936; color: #c084fc; }

/* ── Main Content ────────────────────────────────────────────────────────────── */
.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 28px 32px;
    max-width: calc(100vw - var(--sidebar-width));
    min-height: calc(100vh - var(--nav-height));
}

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

.card-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.card-body  { padding: 20px; }

/* ── SOP List Items ──────────────────────────────────────────────────────────── */
.sop-list { display: flex; flex-direction: column; gap: 1px; }

.sop-item {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition);
}

.sop-item:last-child { border-bottom: none; }
.sop-item:hover { background: var(--bg-hover); }
.sop-item:first-child { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.sop-item:last-child  { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

.sop-item-star {
    color: var(--text-muted); font-size: 16px;
    cursor: pointer; flex-shrink: 0;
    background: none; border: none; padding: 2px;
    transition: color var(--transition), transform 0.15s;
}

.sop-item-star:hover { transform: scale(1.2); }
.sop-item-star.starred { color: var(--brand-gold); }

.sop-item-body { flex: 1; min-width: 0; }

.sop-item-title {
    font-size: 14px; font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sop-item-meta {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; color: var(--text-muted);
    margin-top: 2px;
}

.sop-item-actions {
    display: flex; align-items: center; gap: 6px;
    flex-shrink: 0; opacity: 0;
    transition: opacity var(--transition);
}

.sop-item:hover .sop-item-actions { opacity: 1; }

.btn-icon {
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all var(--transition);
}

.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon.danger:hover { background: #fef2f2; border-color: #fecaca; color: #dc2626; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500;
    cursor: pointer; border: none;
    font-family: 'Sora', sans-serif;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--brand-mid);
    color: #fff;
}
.btn-primary:hover { background: var(--brand-navy); }

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: var(--bg-active); color: var(--text-primary); }

.btn-danger {
    background: #dc2626;
    color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

.btn-sm { padding: 5px 11px; font-size: 12px; }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

.form-label {
    display: block;
    font-size: 13px; font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-primary);
    font-family: 'Sora', sans-serif;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

textarea.form-control { height: auto; padding: 10px 12px; resize: vertical; }
select.form-control { cursor: pointer; }

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 12px; color: #dc2626; margin-top: 4px; }

/* ── Dark Mode Toggle — styled like the image ───────────────────────────────── */
.theme-toggle-wrap {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}

.theme-toggle-label {
    font-size: 12px; font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.theme-toggle {
    position: relative;
    width: 64px; height: 34px;
    cursor: pointer;
    user-select: none;
}

.theme-toggle input {
    opacity: 0; width: 0; height: 0; position: absolute;
}

.theme-toggle-track {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--toggle-bg-off);
    transition: background 0.3s cubic-bezier(0.4,0,0.2,1);
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.4);
}

.theme-toggle input:checked ~ .theme-toggle-track {
    background: var(--toggle-bg-on);
}

.theme-toggle-thumb {
    position: absolute;
    top: 3px; left: 3px;
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--toggle-thumb);
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    display: flex; align-items: center; justify-content: center;
}

.theme-toggle input:checked ~ .theme-toggle-thumb {
    transform: translateX(30px);
}

/* Moon/sun icon inside thumb */
.theme-toggle-thumb::after {
    content: '';
    width: 14px; height: 14px;
    border-radius: 50%;
    background: #94a3b8;
    box-shadow: -4px 0 0 -1px #94a3b8;
    transition: all 0.3s;
}

.theme-toggle input:checked ~ .theme-toggle-thumb::after {
    background: #fbbf24;
    box-shadow: 0 0 6px 2px rgba(251,191,36,0.5);
    border-radius: 50%;
}

/* ── Classification Badge ────────────────────────────────────────────────────── */
.clf-badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11px; font-weight: 600;
    padding: 3px 9px;
    border-radius: 999px;
    text-transform: uppercase; letter-spacing: 0.06em;
}

/* ── SOP Reader ──────────────────────────────────────────────────────────────── */
.sop-reader { max-width: 820px; }

.sop-reader-header {
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.sop-reader-title {
    font-family: 'Source Serif 4', serif;
    font-size: 32px; font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2; margin-bottom: 12px;
}

.sop-reader-meta {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
    font-size: 13px; color: var(--text-muted);
}

.sop-reader-body {
    font-family: 'Source Serif 4', serif;
    font-size: 16px; line-height: 1.8;
    color: var(--text-primary);
}

.sop-reader-body h1, .sop-reader-body h2, .sop-reader-body h3 {
    font-family: 'Sora', sans-serif; font-weight: 600;
    margin: 28px 0 12px;
    color: var(--text-primary);
}

.sop-reader-body h1 { font-size: 24px; }
.sop-reader-body h2 { font-size: 20px; }
.sop-reader-body h3 { font-size: 17px; }

.sop-reader-body p  { margin-bottom: 16px; }
.sop-reader-body ul, .sop-reader-body ol { margin: 12px 0 16px 24px; }
.sop-reader-body li { margin-bottom: 6px; }

.sop-reader-body pre {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    font-size: 13px; margin: 16px 0;
}

.sop-reader-body code {
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 13px;
    background: var(--bg-hover);
    padding: 1px 5px; border-radius: 3px;
}

.sop-reader-body pre code { background: none; padding: 0; }

.sop-reader-body blockquote {
    border-left: 3px solid var(--brand-accent);
    padding: 8px 16px;
    margin: 16px 0;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.sop-reader-body table {
    width: 100%; border-collapse: collapse; margin: 16px 0;
    font-size: 14px;
}

.sop-reader-body th {
    background: var(--bg-hover);
    font-family: 'Sora', sans-serif;
    font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-secondary);
    padding: 10px 14px; border-bottom: 2px solid var(--border-color);
    text-align: left;
}

.sop-reader-body td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.sop-classification-footer {
    margin-top: 40px;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-hover);
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Flag Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 500;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity var(--transition);
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 28px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: scale(1); }
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.modal-desc  { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }

/* ── Alerts ──────────────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    display: flex; align-items: flex-start; gap: 10px;
}

.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.alert-info    { background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; }
.alert-warn    { background: #fffbeb; border: 1px solid #fde68a; color: #b45309; }

[data-theme="dark"] .alert-success { background: #052e16; border-color: #14532d; color: #4ade80; }
[data-theme="dark"] .alert-error   { background: #1c0000; border-color: #7f1d1d; color: #f87171; }
[data-theme="dark"] .alert-info    { background: #0c1a3d; border-color: #1e3a8a; color: #60a5fa; }
[data-theme="dark"] .alert-warn    { background: #1c1000; border-color: #78350f; color: #fbbf24; }

/* ── Page header ─────────────────────────────────────────────────────────────── */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}

.page-title { font-size: 22px; font-weight: 600; color: var(--text-primary); }
.page-subtitle { font-size: 14px; color: var(--text-secondary); margin-top: 2px; }

/* ── Table ───────────────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
    padding: 11px 14px;
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--text-muted);
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}
.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-hover); }

/* ── Auth Pages ──────────────────────────────────────────────────────────────── */
.auth-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-base);
    padding: 20px;
}

.auth-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.auth-logo {
    display: flex; flex-direction: column; align-items: center;
    gap: 12px; margin-bottom: 32px;
}

.auth-logo-mark { /* SVG logo centered */ }

.auth-title { font-size: 22px; font-weight: 700; color: var(--text-primary); text-align: center; }
.auth-subtitle { font-size: 13px; color: var(--text-muted); text-align: center; margin-top: 4px; }

/* ── Version badge ───────────────────────────────────────────────────────────── */
.version-badge {
    font-size: 10px; color: var(--text-muted);
    font-family: monospace; letter-spacing: 0.05em;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-primary { color: var(--text-primary); }
.text-danger { color: #dc2626; }
.text-success { color: #16a34a; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.ml-auto { margin-left: auto; }
.mb-4  { margin-bottom: 4px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.fw-600 { font-weight: 600; }
.fs-13  { font-size: 13px; }
.fs-12  { font-size: 12px; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform var(--transition); z-index: 90; }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; max-width: 100vw; padding: 20px 16px; }
    .nav-search { max-width: 300px; }
}

@media (max-width: 600px) {
    .nav-search { display: none; }
    .main { padding: 16px 12px; }
    .sop-reader-title { font-size: 24px; }
}

/* ── Dashboard ───────────────────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
    position: relative;
}
.stat-card-warning { border-left: 3px solid var(--color-warning); }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-top: .25rem; }
.stat-action { font-size: .75rem; color: var(--color-primary); text-decoration: none; }

.dashboard-section { margin-bottom: 2.5rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-title { font-size: 1.05rem; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; gap: .5rem; }
.section-link { font-size: .85rem; color: var(--color-primary); text-decoration: none; }
.section-link:hover { text-decoration: underline; }

.sop-list-compact { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; }
.sop-list-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: .875rem 1.25rem; text-decoration: none; color: var(--text-primary);
    border-bottom: 1px solid var(--border-subtle);
    transition: background .15s;
}
.sop-list-item:last-child { border-bottom: none; }
.sop-list-item:hover { background: var(--bg-hover); }
.sop-list-item-main { display: flex; align-items: center; gap: .75rem; }
.sop-list-title { font-size: .9rem; font-weight: 500; }
.sop-list-item-meta { display: flex; align-items: center; gap: 1rem; color: var(--text-muted); font-size: .8rem; flex-shrink: 0; }
.empty-state-inline { padding: 1.5rem; color: var(--text-muted); font-size: .9rem; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); }
.empty-state-inline a { color: var(--color-primary); }

/* ── SOP Grid ────────────────────────────────────────────────────────────────── */
.sop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}
.sop-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column;
    transition: box-shadow .2s, transform .2s;
}
.sop-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.sop-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .875rem; }
.sop-card-actions { display: flex; align-items: center; gap: .375rem; }
.sop-card-link { text-decoration: none; color: inherit; flex: 1; }
.sop-card-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); margin-bottom: .5rem; line-height: 1.4; }
.sop-card-excerpt { font-size: .83rem; color: var(--text-muted); line-height: 1.5; }
.sop-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 1rem; padding-top: .75rem; border-top: 1px solid var(--border-subtle); }

/* ── Search Results ──────────────────────────────────────────────────────────── */
.search-results-list { display: flex; flex-direction: column; gap: 1rem; }
.search-result-item {
    background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}
.search-result-meta { display: flex; align-items: center; gap: .75rem; margin-bottom: .5rem; }
.search-result-title { font-size: 1.05rem; font-weight: 600; color: var(--color-primary); text-decoration: none; display: block; margin-bottom: .5rem; }
.search-result-title:hover { text-decoration: underline; }
.search-result-excerpt { font-size: .88rem; color: var(--text-secondary); line-height: 1.6; margin-bottom: .875rem; }
.search-result-excerpt mark { background: rgba(59,130,246,.2); color: var(--text-primary); border-radius: 2px; padding: 0 2px; }
.search-result-footer { display: flex; align-items: center; justify-content: space-between; }

/* ── Flags ───────────────────────────────────────────────────────────────────── */
.flags-list { display: flex; flex-direction: column; gap: 1rem; }
.flag-card { background: var(--bg-surface); border: 1px solid var(--color-warning); border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow-sm); }
.flag-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.flag-card-info { display: flex; align-items: flex-start; gap: .75rem; }
.flag-sop-link { font-size: 1rem; font-weight: 600; color: var(--color-primary); text-decoration: none; display: block; margin-bottom: .375rem; }
.flag-sop-link:hover { text-decoration: underline; }
.flag-card-meta { text-align: right; font-size: .8rem; color: var(--text-muted); flex-shrink: 0; }
.flag-by { display: block; margin-bottom: .25rem; }
.flag-notes { background: var(--bg-sidebar); border-radius: var(--radius-md); padding: .875rem 1rem; margin-bottom: 1rem; font-size: .9rem; color: var(--text-secondary); line-height: 1.6; }
.flag-card-actions { display: flex; gap: .75rem; }

/* ── Import ──────────────────────────────────────────────────────────────────── */
.import-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-bottom: 2rem; }
@media (max-width: 768px) { .import-layout { grid-template-columns: 1fr; } }
.import-section { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 1.5rem; }
.import-section-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.import-hint { font-size: .85rem; color: var(--text-muted); margin-bottom: 1.25rem; }
.import-hint code { background: var(--bg-sidebar); padding: 1px 5px; border-radius: 3px; font-family: monospace; }

.dropzone {
    border: 2px dashed var(--border-color); border-radius: var(--radius-lg);
    padding: 2rem; text-align: center; cursor: pointer;
    transition: border-color .2s, background .2s;
    margin-bottom: 1.25rem;
}
.dropzone.drag-over { border-color: var(--color-primary); background: rgba(59,130,246,.05); }
.dropzone-inner svg { color: var(--text-muted); margin-bottom: .75rem; }
.dropzone-text { font-size: .95rem; font-weight: 500; color: var(--text-secondary); margin-bottom: .25rem; }
.dropzone-subtext { font-size: .8rem; color: var(--text-muted); margin-bottom: .75rem; }
.dropzone-file-list { text-align: left; margin-top: 1rem; }
.dropzone-file-item { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--text-secondary); padding: .375rem 0; border-bottom: 1px solid var(--border-subtle); }
.dropzone-file-item svg { color: var(--text-muted); flex-shrink: 0; }

.import-results { margin-top: 2rem; }
.import-results-title { font-size: 1rem; font-weight: 600; margin-bottom: .875rem; }
.import-results-list { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; }
.import-result-item { display: flex; align-items: center; gap: .75rem; padding: .875rem 1.25rem; border-bottom: 1px solid var(--border-subtle); font-size: .88rem; }
.import-result-item:last-child { border-bottom: none; }
.import-result-success svg { color: var(--color-success); }
.import-result-error svg { color: var(--color-danger); }
.import-result-name { font-weight: 500; flex: 1; }
.import-result-msg { color: var(--text-muted); }

/* ── SOP Editor ──────────────────────────────────────────────────────────────── */
.editor-layout { display: grid; grid-template-columns: 1fr 280px; gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .editor-layout { grid-template-columns: 1fr; } }
.editor-main { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; }
.editor-tabs-group { border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; padding: 0 1.25rem; margin-bottom: 0; }
.editor-tabs { display: flex; gap: .25rem; padding: .75rem 0; }
.editor-tab { background: none; border: none; font: 500 .875rem var(--font-sans); color: var(--text-muted); cursor: pointer; padding: .375rem .875rem; border-radius: var(--radius-md); transition: all .15s; }
.editor-tab.active { background: var(--bg-active); color: var(--color-primary); }
.editor-tab-hint { font-size: .75rem; color: var(--text-muted); }
.editor-panel.active { display: block; }
.editor-textarea { width: 100%; min-height: 540px; border: none; outline: none; resize: vertical; font-family: 'Courier New', monospace; font-size: .9rem; line-height: 1.7; color: var(--text-primary); background: var(--bg-surface); padding: 1.25rem; }
.editor-toolbar { display: flex; gap: .25rem; padding: .5rem 1.25rem; border-top: 1px solid var(--border-subtle); background: var(--bg-sidebar); }
.toolbar-btn { background: none; border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: .25rem .625rem; font-size: .8rem; cursor: pointer; color: var(--text-secondary); transition: all .15s; }
.toolbar-btn:hover { background: var(--bg-hover); border-color: var(--color-primary); color: var(--color-primary); }

.editor-sidebar { display: flex; flex-direction: column; gap: 1rem; }
.sidebar-section { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 1.25rem; }
.sidebar-section-title { font-size: .85rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: .875rem; }
.sidebar-actions { display: flex; flex-direction: column; gap: .625rem; }
.btn-full { width: 100%; text-align: center; justify-content: center; }
.btn-danger-ghost { background: none; border: 1px solid var(--color-danger); color: var(--color-danger); }
.btn-danger-ghost:hover { background: rgba(239,68,68,.08); }
.btn-ghost { background: none; border: 1px solid var(--border-color); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); }

.version-history-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.version-history-item { display: flex; align-items: center; justify-content: space-between; font-size: .82rem; }
.version-tag { font-family: monospace; background: var(--bg-sidebar); padding: 2px 6px; border-radius: 3px; font-size: .78rem; }
.version-date { color: var(--text-muted); }
.version-badge { font-family: monospace; background: var(--bg-sidebar); padding: 2px 8px; border-radius: 4px; font-size: .85rem; color: var(--text-secondary); }
.version-bump-group { display: flex; align-items: center; gap: .75rem; font-size: .85rem; color: var(--text-secondary); }
.select-sm { font-size: .85rem; padding: .375rem .75rem; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-surface); color: var(--text-primary); }
.toggle-label { display: flex; align-items: center; gap: .625rem; cursor: pointer; font-size: .9rem; }
.toggle-slider-sm {
    width: 36px; height: 20px; background: var(--border-color); border-radius: 10px;
    position: relative; transition: background .2s; flex-shrink: 0;
}
.toggle-slider-sm::after { content: ''; position: absolute; width: 14px; height: 14px; background: #fff; border-radius: 50%; top: 3px; left: 3px; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle-label input { display: none; }
.toggle-label input:checked + .toggle-slider-sm { background: var(--color-primary); }
.toggle-label input:checked + .toggle-slider-sm::after { transform: translateX(16px); }

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 2rem; }
.pagination-btn { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); color: var(--text-secondary); text-decoration: none; transition: all .15s; }
.pagination-btn:hover { background: var(--bg-hover); border-color: var(--color-primary); color: var(--color-primary); }
.pagination-info { font-size: .875rem; color: var(--text-muted); }

/* ── Filter bar ──────────────────────────────────────────────────────────────── */
.filter-bar { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.5rem; padding: .75rem 1rem; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); font-size: .88rem; }
.filter-label { color: var(--text-muted); }
.filter-clear { color: var(--color-danger); text-decoration: none; margin-left: auto; }
.filter-clear:hover { text-decoration: underline; }

/* ── Back button ─────────────────────────────────────────────────────────────── */
.btn-back { display: inline-flex; align-items: center; gap: .375rem; font-size: .85rem; color: var(--text-muted); text-decoration: none; margin-bottom: .5rem; transition: color .15s; }
.btn-back:hover { color: var(--color-primary); }

/* ── Page header ─────────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.75rem; gap: 1rem; }
.page-header-left { display: flex; flex-direction: column; }
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); margin: 0; }
.page-subtitle { font-size: .88rem; color: var(--text-muted); margin: .25rem 0 0; }
.page-header-actions { display: flex; align-items: center; gap: .75rem; flex-shrink: 0; }

/* ── Field helpers ───────────────────────────────────────────────────────────── */
.field-hint { font-size: .78rem; color: var(--text-muted); margin-top: .375rem; }
.required { color: var(--color-danger); }
.mt-4 { margin-top: 1rem; }
.form-input-lg { font-size: 1.1rem; font-weight: 500; }

/* ── Extra badge sizes ───────────────────────────────────────────────────────── */
.badge-sm { font-size: .65rem; padding: 2px 6px; }

/* ── Colors ──────────────────────────────────────────────────────────────────── */
:root {
    --color-success: #16a34a;
    --color-warning: #d97706;
    --color-danger:  #dc2626;
}

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.btn-sm { font-size: .8rem; padding: .35rem .75rem; }
