/* ========== RESET E BASE ========== */
* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: "Georgia", "Times New Roman", serif;
    font-size: 18px;
    line-height: 1.55;
    color: #1a1a1a;
    background: #fff;
    margin: 0;
}

/* ========== LAYOUT ========== */
.layout {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 32px;
    display: flex;
}

/* ========== MENU LATERAL ========== */
.menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    height: 100vh;
    padding: 32px 20px;
    overflow-y: auto;
    background: #f7f7f7;
    border-right: 1px solid #e0e0e0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.4;
    transition: transform 0.3s ease;
}

/* Listas do menu */
.menu ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.menu ul ul {
    margin-left: 12px;
    padding-left: 1em;
}

.menu li {
    list-style: none;
    margin: 4px 0;
}

/* Links do menu */
.menu a {
    display: block;
    padding: 6px 8px;
    text-decoration: none;
    color: #222;
    border-radius: 4px;
    transition: background 0.15s ease, color 0.15s ease;
}

.menu a:hover {
    background: #e9e9e9;
}

.menu ul ul a {
    font-size: 1em;
    color: #444;
}

.menu a.active {
    background: #d8efff;
    color: #0b5ed7;
    font-weight: 500;
}

/* Título do TOC */
.menu #TOC > h2 {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #666;
    margin-bottom: 16px;
}

/* TOC colapsável */
.menu li.has-children {
    position: relative;
    padding-left: 0;
}

.menu li.has-children > a {
    display: inline;
}

.menu li.collapsed > ul {
    display: none;
}

.menu button.toc-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-right: 6px;
    margin-left: 0;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    font-family: system-ui, sans-serif;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    color: #666;
    opacity: 0.85;
    transition: all 0.15s ease;
    vertical-align: middle;
}

.menu button.toc-toggle:hover {
    opacity: 1;
    background: #f0f0f0;
    border-color: #999;
    color: #333;
}

.menu button.toc-toggle::before {
    content: "+";
}

.menu li:not(.collapsed) > button.toc-toggle::before {
    content: "−";
}

/* Controles de expansão/colapso */
.toc-controls {
    display: flex;
    gap: 8px;
    margin-top: 24px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e0e0e0;
}

.toc-expand-all,
.toc-collapse-all {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #ccc;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    color: #333;
    font-weight: 500;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.toc-expand-all:hover,
.toc-collapse-all:hover {
    background: #f0f0f0;
    border-color: #999;
}

.toc-expand-all:active,
.toc-collapse-all:active {
    background: #e8e8e8;
}

/* ========== BOTÕES DE CONTROLE ========== */

/* Botão hambúrguer (mobile) */
.menu-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1001;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 0;
}

.menu-toggle span {
    display: block;
    width: 28px;
    height: 3px;
    background: #1a1a1a;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.menu-toggle[aria-expanded="true"] span:nth-child(1) {
    transform: rotate(45deg) translate(9px, 9px);
}

.menu-toggle[aria-expanded="true"] span:nth-child(2) {
    opacity: 0;
}

.menu-toggle[aria-expanded="true"] span:nth-child(3) {
    transform: rotate(-45deg) translate(8px, -8px);
}

/* Botão toggle do menu lateral (desktop) */
.sidebar-toggle {
    position: fixed;
    top: 16px;
    left: 290px;
    z-index: 1002;
    width: 32px;
    height: 32px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.sidebar-toggle:hover {
    background: #f0f0f0;
    border-color: #999;
}

.sidebar-toggle-icon {
    width: 16px;
    height: 16px;
    position: relative;
}

.sidebar-toggle-icon::before,
.sidebar-toggle-icon::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 2px;
    left: 2px;
    background: #666;
    transition: all 0.3s ease;
}

.sidebar-toggle-icon::before {
    top: 4px;
    transform: rotate(-45deg);
}

.sidebar-toggle-icon::after {
    bottom: 4px;
    transform: rotate(45deg);
}

/* Estado do menu oculto */
.menu-hidden .menu {
    transform: translateX(-100%);
}

.menu-hidden .content {
    margin-left: auto;
    margin-right: auto;
    max-width: 900px;
}

.menu-hidden .sidebar-toggle {
    left: 16px;
}

.menu-hidden .sidebar-toggle-icon::before {
    transform: rotate(45deg);
    left: 6px;
}

.menu-hidden .sidebar-toggle-icon::after {
    transform: rotate(-45deg);
    left: 6px;
}

/* ========== CONTEÚDO PRINCIPAL ========== */
.content {
    margin-left: 360px;
    margin-right: auto;
    max-width: 800px;
    flex: 1;
    padding-top: 64px;
    transition: margin-left 0.3s ease, max-width 0.3s ease;
}

.content p {
    margin: 1.4em 0;
    text-align: justify;
}

/* Títulos */
.content h1,
.content h2,
.content h3,
.content h4 {
    font-family: "Georgia", "Times New Roman", serif;
    font-weight: 700;
    line-height: 1.25;
    margin-top: 3em;
    margin-bottom: 1em;
}

.content h1 { font-size: 2.1em; }
.content h2 { font-size: 1.6em; }
.content h3 { font-size: 1.3em; }

/* Listas */
.content ul,
.content ol {
    margin: 1.4em 0 1.4em 2em;
}

/* Links */
.content a {
    color: #1a5fb4;
    text-decoration: underline;
}

/* Figuras */
.content figure {
    margin: 2.5em 0;
    text-align: center;
}

.content figcaption {
    font-size: 0.9em;
    color: #555;
    margin-top: 0.6em;
}

/* Título do documento */
.document-title h1 {
    font-size: 3em;
    margin-top: 0;
    margin-bottom: 0.4em;
}

.document-title .author,
.document-title .date {
    font-size: 0.95em;
    color: #555;
    margin: 0;
}

/* ========== CÓDIGO ========== */
pre, code {
    font-family: "Courier New", monospace;
    background: #f5f5f5;
}

pre {
    padding: 20px;
    overflow-x: auto;
    border-left: 4px solid #1a5fb4;
    margin: 2em 0;
    font-size: 0.9em;
}

code {
    padding: 3px 6px;
}

/* ========== CITAÇÕES ========== */
blockquote {
    margin: 2em 0;
    padding: 1em 1.5em;
    background: #fafafa;
    border-left: 4px solid #ccc;
    color: #555;
}

/* ========== RESPONSIVIDADE ========== */

/* Tablets e telas médias (até 1024px) */
@media (max-width: 1024px) {
    .layout {
        padding: 48px 24px;
    }

    .menu {
        width: 280px;
    }

    .content {
        margin-left: 300px;
        max-width: 650px;
    }

    .content h1 {
        font-size: 1.8em;
    }

    .content h2 {
        font-size: 1.4em;
    }
}

/* Dispositivos móveis (até 768px) */
@media (max-width: 768px) {
    .menu-toggle {
        display: flex;
    }

    .sidebar-toggle {
        display: none;
    }

    .layout {
        padding: 32px 16px;
        padding-top: 60px;
    }

    .menu {
        position: fixed;
        top: 0;
        left: -100%;
        width: 100%;
        max-width: 300px;
        height: 100vh;
        background: #f7f7f7;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
        padding-top: 60px;
    }

    .menu.active {
        left: 0;
    }

    .content {
        margin-left: 0;
        max-width: 100%;
        padding: 0;
    }

    .content p {
        text-align: left;
    }

    .content h1 {
        font-size: 1.8em;
    }

    .content h2 {
        font-size: 1.4em;
    }

    .content h3 {
        font-size: 1.15em;
    }

    body {
        font-size: 16px;
    }

    .document-title h1 {
        font-size: 2em;
    }

    .content ul,
    .content ol {
        margin: 1.2em 0 1.2em 1.5em;
    }
}

/* Smartphones pequenos (até 480px) */
@media (max-width: 480px) {
    .layout {
        padding: 24px 12px;
        padding-top: 50px;
    }

    .menu-toggle {
        top: 12px;
        left: 12px;
        width: 36px;
        height: 36px;
    }

    .menu-toggle span {
        width: 24px;
        height: 2px;
    }

    .menu {
        max-width: 100%;
        padding: 16px;
        padding-top: 50px;
    }

    body {
        font-size: 15px;
        line-height: 1.5;
    }

    .content h1 {
        font-size: 1.5em;
        margin-top: 1.5em;
    }

    .content h2 {
        font-size: 1.2em;
    }

    .content h3 {
        font-size: 1.05em;
    }

    .document-title h1 {
        font-size: 1.6em;
    }

    .content pre {
        padding: 12px;
        font-size: 0.85em;
    }

    .menu #TOC > h2 {
        font-size: 0.85rem;
    }
}
