:root {
    --primary-dark: #0b2e4f;
    --primary-main: #123e6b;
    --primary-light: #1f5f9c;
    --accent: #2a84d2;
    --ink: #1b2733;
    --muted: #5a6b7d;
    --paper: #ffffff;
    --page-bg: #eef2f7;
    --line: #e2e8f0;
    --sidebar-bg: #f8fafc;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
    background: var(--page-bg);
    color: var(--ink);
}

/* ===================== Top bar ===================== */

.doc-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    background: linear-gradient(120deg, var(--primary-dark), var(--primary-main));
    color: #ffffff;
    padding: 12px 24px;
    box-shadow: 0 4px 18px rgba(11, 46, 79, 0.25);
}

.doc-topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.doc-logo {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    background: #ffffff;
    border-radius: 8px;
    padding: 3px;
}

.doc-topbar-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.doc-header-ministry,
.doc-header-org {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #ffffff;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-header-org {
    opacity: 0.85;
}

.doc-topbar-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.doc-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    padding: 9px 16px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.doc-action-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.doc-action-btn:active {
    transform: translateY(1px);
}

.doc-action-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
}

.doc-action-btn-primary:hover {
    background: #3a91da;
}

.doc-action-icon {
    font-size: 15px;
    line-height: 1;
}

/* ===================== Layout ===================== */

.doc-layout {
    display: flex;
    align-items: flex-start;
    gap: 28px;
    max-width: 1180px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}

.doc-toc {
    position: sticky;
    top: 76px;
    flex: 0 0 260px;
    width: 260px;
    background: var(--sidebar-bg);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px 16px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}

.doc-toc-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--muted);
    margin-bottom: 10px;
}

.doc-toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: toc;
}

.doc-toc li {
    counter-increment: toc;
}

.doc-toc a {
    display: block;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--muted);
    text-decoration: none;
    padding: 6px 8px;
    border-radius: 7px;
    border-left: 2px solid transparent;
    transition: background 0.12s ease, color 0.12s ease;
}

.doc-toc a::before {
    content: counter(toc) ". ";
    font-weight: 700;
    color: var(--primary-light);
}

.doc-toc a:hover {
    background: #eef2f7;
    color: var(--primary-dark);
}

.doc-toc a.is-active {
    background: #e4edf9;
    color: var(--primary-dark);
    border-left-color: var(--accent);
    font-weight: 600;
}

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

.doc-card {
    background: var(--paper);
    border-radius: 16px;
    box-shadow: 0 18px 48px rgba(11, 46, 79, 0.1);
    padding: 40px 48px 52px;
}

/* ===================== Document header ===================== */

.doc-title {
    font-size: 24px;
    font-weight: 800;
    color: var(--primary-dark);
    margin: 0 0 8px;
    line-height: 1.35;
}

.doc-subtitle {
    font-size: 14.5px;
    font-weight: 600;
    color: var(--primary-main);
    margin: 0 0 12px;
    line-height: 1.4;
}

.doc-updated {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-dark);
    background: #eef2f7;
    border-radius: 999px;
    padding: 5px 14px;
    margin: 0 0 28px;
}

/* ===================== Sections ===================== */

.doc-section {
    margin-bottom: 30px;
    padding-top: 6px;
    scroll-margin-top: 88px;
}

.doc-section + .doc-section {
    border-top: 1px solid var(--line);
    padding-top: 26px;
}

.doc-section h2 {
    font-size: 16.5px;
    font-weight: 700;
    color: var(--primary-dark);
    margin: 0 0 10px;
}

.doc-section h3 {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--primary-main);
    margin: 16px 0 8px;
}

.doc-section p {
    font-size: 14.5px;
    line-height: 1.7;
    color: var(--ink);
    margin: 0 0 10px;
}

.doc-section p a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.doc-section ul,
.doc-section ol {
    margin: 0 0 10px;
    padding-left: 22px;
}

.doc-section li {
    font-size: 14.5px;
    line-height: 1.7;
    color: var(--ink);
    margin-bottom: 5px;
}

.doc-meta {
    margin-top: 8px;
    padding: 18px 20px;
    border-radius: 12px;
    background: var(--sidebar-bg);
    border: 1px solid var(--line);
}

.doc-meta p {
    font-size: 12.5px;
    line-height: 1.65;
    color: var(--muted);
    margin: 0 0 4px;
}

.doc-meta strong {
    color: var(--ink);
}

/* ===================== Toast ===================== */

.doc-toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translate(-50%, 12px);
    background: var(--primary-dark);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 12px 20px;
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 100;
}

.doc-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ===================== Responsive ===================== */

@media (max-width: 980px) {
    .doc-toc {
        display: none;
    }
    .doc-layout {
        padding: 24px 16px 48px;
    }
    .doc-card {
        padding: 28px 22px 36px;
    }
}

@media (max-width: 600px) {
    .doc-topbar {
        padding: 10px 14px;
    }
    .doc-topbar-actions {
        width: 100%;
        justify-content: stretch;
    }
    .doc-action-btn {
        flex: 1;
        justify-content: center;
    }
    .doc-title {
        font-size: 20px;
    }
    .doc-card {
        padding: 22px 16px 30px;
    }
}

/* ===================== Print / PDF export ===================== */

@media print {
    :root {
        --primary-dark: #000000;
        --primary-main: #000000;
        --primary-light: #000000;
        --accent: #000000;
        --ink: #000000;
        --muted: #333333;
        --paper: #ffffff;
        --page-bg: #ffffff;
        --line: #999999;
        --sidebar-bg: transparent;
    }

    .doc-topbar,
    .doc-toc,
    .doc-toast {
        display: none !important;
    }

    body,
    .doc-card,
    .doc-title,
    .doc-subtitle,
    .doc-updated,
    .doc-section p,
    .doc-section li,
    .doc-meta p {
        font-family: 'Times New Roman TJ', 'Times New Roman', 'Noto Serif Tajik', serif !important;
        color: #000000 !important;
        background: #ffffff !important;
    }

    .doc-layout {
        display: block;
        padding: 0;
        max-width: none;
    }

    .doc-card {
        box-shadow: none;
        border-radius: 0;
        padding: 0;
    }

    .doc-title {
        font-size: 20pt;
        font-weight: 700;
        margin-bottom: 6pt;
    }

    .doc-subtitle {
        font-size: 15pt;
        font-weight: 700;
        margin-bottom: 6pt;
    }

    .doc-updated {
        font-size: 12pt;
        background: none !important;
        padding: 0;
        margin-bottom: 16pt;
    }

    .doc-section h2 {
        font-size: 15pt;
        font-weight: 700;
        break-after: avoid;
    }

    .doc-section h3 {
        font-size: 14pt;
        font-weight: 700;
        break-after: avoid;
    }

    .doc-section p,
    .doc-section li,
    .doc-meta p {
        font-size: 14pt;
        line-height: 1.5;
    }

    .doc-section p a {
        color: #000000 !important;
        text-decoration: underline;
    }

    .doc-section {
        break-inside: auto;
    }

    .doc-section h2,
    .doc-section h3,
    .doc-section > p:first-of-type {
        break-inside: avoid;
    }

    .doc-meta {
        border: 1px solid #000000;
        break-inside: avoid;
    }

    @page {
        margin: 2cm 1.8cm;
    }
}

/* ===================== Dark mode ===================== */

@media (prefers-color-scheme: dark) {
    :root {
        --page-bg: #0a1420;
        --paper: #101c2c;
        --line: #223349;
        --sidebar-bg: #16233590;
        --ink: #dbe6f2;
        --muted: #8ea2b8;
    }

    .doc-toc a {
        color: var(--muted);
    }

    .doc-toc a:hover {
        background: #16233590;
        color: #ffffff;
    }

    .doc-toc a.is-active {
        background: #1c2f47;
        color: #7fb0f0;
    }

    .doc-title {
        color: #ffffff;
    }

    .doc-subtitle {
        color: #7fb0f0;
    }

    .doc-updated {
        background: #16233590;
        color: #dbe6f2;
    }

    .doc-section h2,
    .doc-section h3 {
        color: #7fb0f0;
    }

    .doc-section p a {
        color: #7fb0f0;
    }

    .doc-meta strong {
        color: #dbe6f2;
    }
}
