/* ══════════════════════════════════════════════════════════════════════════════
   PORTAL MDBOOK - GTI FATEC
   SISTEMA DE DESIGN & TIPOGRAFIA RESPONSIVA DE ALTA LEGIBILIDADE
   (Otimizado para Telas Desktop, Tablets e Smartphones)
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── 1. VARIÁVEIS DE TEMA E CORES NATIVAS DO MDBOOK ────────────────────────── */
:root {
    /* O tema padrão do mdBook fixa --content-max-width em 750px (variables.css),
       independente do estado da sidebar. Em telas largas isso gera margens
       laterais enormes (vazias) mesmo com a sidebar oculta. Usamos min() (não
       clamp()) para crescer com a viewport até um teto maior sem nunca impor
       um piso — em telas estreitas o valor cai livremente, sem risco de
       overflow horizontal no celular. A legibilidade do texto corrido é
       preservada à parte, limitando título/prosa a uma coluna de leitura
       confortável (ver seção 2). */
    --content-max-width: min(1200px, 92vw);

    --card-bkg: rgba(248, 250, 252, 0.85);
    --card-border: #e2e8f0;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --table-stripe: #f8fafc;
    --table-border: #e2e8f0;
    --code-inline-bkg: #f1f5f9;
    --code-inline-color: #0f172a;
    --quiz-select-bkg: rgba(37, 99, 235, 0.12);
    --quiz-select-border: #2563eb;
    --scrollbar-thumb: #cbd5e1;
    --scrollbar-track: #f1f5f9;
    --accent-glow: rgba(37, 99, 235, 0.15);
}

html.rust {
    --card-bkg: rgba(242, 238, 229, 0.9);
    --card-border: #d4ccb8;
    --card-shadow: 0 4px 6px -1px rgba(60, 40, 20, 0.08);
    --table-stripe: #eae4d5;
    --table-border: #d4ccb8;
    --code-inline-bkg: #eae4d5;
    --code-inline-color: #2b2b29;
    --quiz-select-bkg: rgba(163, 76, 38, 0.15);
    --quiz-select-border: #a34c26;
    --scrollbar-thumb: #b8ad9b;
    --scrollbar-track: #e1e1db;
    --accent-glow: rgba(163, 76, 38, 0.2);
}

html.coal {
    --card-bkg: rgba(31, 36, 40, 0.85);
    --card-border: #333a42;
    --card-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
    --table-stripe: #1a1d20;
    --table-border: #333a42;
    --code-inline-bkg: #22272b;
    --code-inline-color: #38bdf8;
    --quiz-select-bkg: rgba(14, 165, 233, 0.2);
    --quiz-select-border: #38bdf8;
    --scrollbar-thumb: #475569;
    --scrollbar-track: #141617;
    --accent-glow: rgba(56, 189, 248, 0.2);
}

html.navy {
    --card-bkg: rgba(30, 36, 54, 0.85);
    --card-border: #2d3748;
    --card-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    --table-stripe: #1a2030;
    --table-border: #2d3748;
    --code-inline-bkg: #1f273d;
    --code-inline-color: #7dd3fc;
    --quiz-select-bkg: rgba(56, 189, 248, 0.22);
    --quiz-select-border: #38bdf8;
    --scrollbar-thumb: #475569;
    --scrollbar-track: #161923;
    --accent-glow: rgba(56, 189, 248, 0.25);
}

html.ayu {
    --card-bkg: rgba(25, 34, 45, 0.85);
    --card-border: #2d3b4a;
    --card-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    --table-stripe: #141b22;
    --table-border: #2d3b4a;
    --code-inline-bkg: #1f2a38;
    --code-inline-color: #ffb454;
    --quiz-select-bkg: rgba(255, 180, 84, 0.2);
    --quiz-select-border: #ffb454;
    --scrollbar-thumb: #3b4b5e;
    --scrollbar-track: #0f1419;
    --accent-glow: rgba(255, 180, 84, 0.25);
}

/* ── 2. TIPOGRAFIA RESPONSIVA DE ALTA LEGIBILIDADE (1rem = 10px no mdBook) ── */
html {
    scroll-behavior: smooth;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    line-height: 1.75;
    font-size: 1.65rem; /* 16.5px */
    letter-spacing: 0.01em;
}

/* Títulos hierárquicos e confortáveis */
.content h1 {
    font-size: clamp(2.4rem, 4.5vw, 3.2rem);
    line-height: 1.3;
    word-break: break-word;
    margin-top: 1.8rem;
    margin-bottom: 1.2rem;
    font-weight: 700;
}

.content h2 {
    font-size: clamp(2.0rem, 3.5vw, 2.5rem);
    line-height: 1.35;
    word-break: break-word;
    margin-top: 2.2rem;
    margin-bottom: 1rem;
    padding-bottom: 0.4rem;
    font-weight: 700;
}

.content h3 {
    font-size: clamp(1.7rem, 2.8vw, 2.0rem);
    line-height: 1.4;
    word-break: break-word;
    margin-top: 1.8rem;
    margin-bottom: 0.8rem;
    font-weight: 600;
}

.content h4 {
    font-size: 1.7rem;
    line-height: 1.45;
    margin-top: 1.5rem;
    margin-bottom: 0.6rem;
    font-weight: 600;
}

.content h5 {
    font-size: 1.55rem;
    line-height: 1.45;
    margin-top: 1.2rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

/* Textos corridos, listas e blocos de citação */
.content p,
.content li,
.content blockquote {
    font-size: 1.65rem;
    line-height: 1.75;
    letter-spacing: 0.01em;
}

/* Coluna de leitura: com o container mais largo (seção 1), texto corrido
   muito extenso por linha prejudica a legibilidade. Mantemos título e prosa
   numa medida confortável, enquanto tabelas, blocos de código, admonitions e
   diagramas (não selecionados aqui) usam a largura total do container para
   exibir melhor dados tabulares e linhas de código longas.
   Usamos rem (relativo à raiz, 1rem = 10px neste projeto) e não ch: ch é
   relativo à fonte de cada elemento, então h1 (fonte maior) e p (fonte menor)
   resultariam em medidas diferentes e desalinhadas entre si. */
.content main > h1,
.content main > h2,
.content main > h3,
.content main > h4,
.content main > h5,
.content main > h6,
.content main > p,
.content main > ul,
.content main > ol,
.content main > blockquote,
.content main > hr,
.content main > .chapter-progress-badge {
    max-width: 78rem;
    margin-left: auto;
    margin-right: auto;
}

.content li {
    margin-bottom: 0.4rem;
}

/* Código em linha (inline code) */
.content :not(pre) > code {
    background-color: var(--code-inline-bkg);
    color: var(--code-inline-color);
    padding: 0.2em 0.5em;
    border-radius: 5px;
    font-size: 0.92em;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* ── 3. DIAGRAMAS MERMAID & RENDERIZAÇÃO VETORIAL ──────────────────────────── */
.mermaid-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--card-bkg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    padding: 1.5rem 1rem;
    margin: 2rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.mermaid-container:hover {
    border-color: var(--quiz-select-border);
    box-shadow: 0 6px 14px -2px var(--accent-glow);
}

.mermaid {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.mermaid svg {
    /* SEM !important: o Mermaid já define inline um max-width igual ao
       tamanho nativo/desenhado de cada diagrama (via useMaxWidth:true em
       mermaid-init.js). Com !important aqui, essa regra sempre vencia e
       forçava TODO diagrama a esticar para 100% do container — inflando
       diagramas pequenos (ex: 656px nativo) bem além do texto ao redor.
       Sem !important, o inline (mais específico) prevalece quando existe,
       e este max-width:100% só entra como rede de segurança — encolhendo
       o diagrama em telas estreitas (mobile) ou em tipos de diagrama sem
       useMaxWidth configurado. */
    max-width: 100%;
    height: auto;
    display: block;
}

/* ── 4. RESPONSIVIDADE DE DIAGRAMAS SVG ESTÁTICOS & ARQUITETURA ────────────── */
@media (max-width: 768px) {
    .mermaid-container {
        padding: 1rem 0.5rem;
        margin: 1.25rem 0;
        border-radius: 8px;
    }

    .mermaid svg {
        min-width: 320px;
    }

    .content img[src$=".svg"] {
        max-width: 100%;
        height: auto;
        display: block;
        margin: 0 auto;
    }

    .content p:has(> img[src$=".svg"]) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
    }
}

/* ── 5. TABELAS RESPONSIVAS E LEGÍVEIS ─────────────────────────────────────── */
.content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.8rem 0;
    border: 1px solid var(--table-border);
    border-radius: 8px;
    overflow: hidden;
}

.content table th {
    background-color: var(--card-bkg);
    padding: 0.9rem 1.2rem;
    font-size: 1.55rem;
    font-weight: 700;
    text-align: left;
    border-bottom: 2px solid var(--table-border);
}

.content table td {
    padding: 0.85rem 1.2rem;
    font-size: 1.55rem;
    line-height: 1.65;
    border-bottom: 1px solid var(--table-border);
    vertical-align: top;
}

.content table tr:nth-child(even) {
    background-color: var(--table-stripe);
}

@media (max-width: 820px) {
    .content table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: normal;
    }

    .content table th, 
    .content table td {
        padding: 0.75rem 0.95rem;
        font-size: 1.45rem;
    }
}

/* ── 6. BLOCOS DE CÓDIGO & TERMINAL ────────────────────────────────────────── */
.content pre {
    border-radius: 8px;
    padding: 1.2rem 1.4rem;
    font-size: 1.45rem;
    line-height: 1.6;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--card-border);
}

.content pre code {
    font-size: 1.45rem;
    line-height: 1.6;
}

@media (max-width: 768px) {
    .content pre {
        padding: 1rem 1.15rem;
        font-size: 1.38rem;
        border-radius: 6px;
    }

    .content pre code {
        font-size: 1.38rem;
        line-height: 1.55;
    }

    /* Botão de cópia de código com alvo de toque adequado */
    .buttons .clip-button {
        width: 38px;
        height: 38px;
        opacity: 0.85;
    }
}

/* ── 7. QUIZZES INTERATIVOS FORMATIVOS & TOUCH TARGETS (48px) ──────────────── */
.admonish-question ul {
    list-style: none !important;
    padding-left: 0 !important;
    margin: 1rem 0 !important;
}

.admonish-question li {
    cursor: pointer;
    min-height: 48px;
    display: flex;
    align-items: center;
    padding: 0.75rem 1.1rem;
    margin: 0.6rem 0;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background-color: var(--card-bkg);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    font-size: 1.55rem;
    line-height: 1.55;
}

.admonish-question li:hover {
    background-color: var(--quiz-select-bkg);
    border-color: var(--quiz-select-border);
    transform: translateX(2px);
}

.admonish-question li input[type="checkbox"] {
    cursor: pointer;
    margin-right: 0.85rem;
    width: 20px;
    height: 20px;
    min-width: 20px;
    accent-color: #2563eb;
}

.admonish-question li.quiz-option-selected {
    background-color: var(--quiz-select-bkg) !important;
    border-color: var(--quiz-select-border) !important;
    font-weight: 600;
    box-shadow: 0 2px 6px var(--accent-glow);
}

.admonish-question details {
    margin-top: 1.2rem;
    padding: 1rem 1.2rem;
    background-color: var(--card-bkg);
    border-radius: 8px;
    border-left: 4px solid var(--quiz-select-border);
    border-top: 1px solid var(--card-border);
    border-right: 1px solid var(--card-border);
    border-bottom: 1px solid var(--card-border);
    font-size: 1.55rem;
    line-height: 1.65;
}

.admonish-question details summary {
    cursor: pointer;
    font-weight: 600;
    padding: 0.35rem 0;
    min-height: 42px;
    display: flex;
    align-items: center;
    font-size: 1.6rem;
}

/* ── 8. ADMONITIONS & CALLOUTS NO DESKTOP E MOBILE ─────────────────────────── */
:is(.admonition) {
    font-size: 1.6rem;
}

:is(.admonition-title, summary.admonition-title) {
    font-size: 1.6rem !important;
    min-height: 4.2rem !important;
    font-weight: 700;
}

:is(.admonition) p, 
:is(.admonition) li {
    font-size: 1.6rem;
    line-height: 1.7;
}

@media (max-width: 768px) {
    :is(.admonition) {
        margin: 1.2rem 0 !important;
        padding: 0 1rem !important;
        border-radius: 6px !important;
    }

    :is(.admonition-title, summary.admonition-title) {
        padding-inline: 3.6rem 0.8rem !important;
        min-height: 3.8rem !important;
        font-size: 1.5rem !important;
    }

    :is(.admonition-title, summary.admonition-title)::before {
        inset-inline-start: 1rem !important;
        width: 1.8rem !important;
        height: 1.8rem !important;
    }

    :is(.admonition) p, 
    :is(.admonition) li {
        font-size: 1.55rem;
    }
}

/* ── 9. SIDEBAR & NAVEGAÇÃO ────────────────────────────────────────────────── */
.sidebar .chapter li a {
    font-size: 1.5rem;
    line-height: 1.5;
    padding: 5px 0;
}

.sidebar .part-title {
    font-size: 1.6rem;
    font-weight: 700;
    margin-top: 15px;
}

/* Em telas de toque (mobile/tablet) a sidebar vira a navegação principal
   (overlay). padding:5px 0 resulta em ~32px de alvo de toque, abaixo do
   mínimo recomendado (44-48px). Aumentamos só nesse breakpoint — no desktop
   o padding compacto continua valendo, mostrando mais capítulos por tela. */
@media (max-width: 768px) {
    .sidebar .chapter li a {
        padding: 12px 0;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* ── 10. BARRA DE ROLAGEM SUAVE & ELEGANTE ─────────────────────────────────── */
::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

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

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

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

/* ── 11. BOTÃO VOLTAR AO TOPO FLUTUANTE (MOBILE & DESKTOP) ─────────────────── */
#back-to-top-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: var(--quiz-select-border);
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
    font-size: 20px;
}

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

#back-to-top-btn:hover {
    opacity: 1;
    transform: translateY(-3px) scale(1.05);
}

@media (max-width: 768px) {
    #back-to-top-btn {
        bottom: 16px;
        right: 16px;
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
}

/* ── 12. INDICADOR DE PROGRESSO "CAPÍTULO/ATIVIDADE X DE 20" ──────────────── */
/* Injetado por chapter-progress.js no topo de cada capítulo/atividade,
   ajudando o aluno a se situar no percurso das 20 semanas sem precisar
   abrir a sidebar (crítico no celular, onde a lista completa exige rolagem). */
.chapter-progress-badge {
    display: block;
    margin-top: 1.4rem;
    margin-bottom: 0.4rem;
}

.chapter-progress-label {
    display: inline-block;
    padding: 0.4rem 1rem;
    border-radius: 999px;
    background-color: var(--quiz-select-bkg);
    border: 1px solid var(--quiz-select-border);
    color: var(--quiz-select-border);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: normal;
}

.chapter-progress-track {
    display: block;
    width: 100%;
    max-width: 220px;
    height: 4px;
    margin-top: 0.5rem;
    border-radius: 2px;
    background-color: var(--card-border);
    overflow: hidden;
}

.chapter-progress-fill {
    display: block;
    height: 100%;
    background-color: var(--quiz-select-border);
    border-radius: 2px;
}

@media (max-width: 768px) {
    .chapter-progress-label {
        font-size: 1.15rem;
        padding: 0.35rem 0.85rem;
    }
}

/* ── 13. LIGHTBOX DE DIAGRAMAS MERMAID (TOQUE PARA AMPLIAR) ────────────────── */
/* diagram-lightbox.js abre o SVG numa sobreposição maior ao clicar/tocar no
   diagrama — essencial no celular, onde a versão inline (limitada ao tamanho
   nativo desde a correção da seção 3) fica pequena demais para ler texto. */
.mermaid-container {
    cursor: zoom-in;
}

.diagram-lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 2rem 1rem;
    background-color: rgba(4, 8, 14, 0.92);
    animation: diagram-lightbox-fade-in 0.15s ease;
}

@keyframes diagram-lightbox-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.diagram-lightbox-scroller {
    max-width: 95vw;
    max-height: 82vh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    background-color: var(--bg, #ffffff);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.diagram-lightbox-svg {
    display: block;
    /* Propositalmente ignora o cap de tamanho nativo do diagrama (seção 3):
       aqui o objetivo é ampliar para leitura, não preservar o tamanho
       original. max-width:none + !important sobrepõe o inline do Mermaid. */
    width: min(90vw, 1200px) !important;
    max-width: none !important;
    height: auto !important;
}

.diagram-lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
}

.diagram-lightbox-close:hover {
    background-color: rgba(255, 255, 255, 0.22);
}

.diagram-lightbox-hint {
    color: rgba(255, 255, 255, 0.65);
    font-size: 1.2rem;
    text-align: center;
}

body.diagram-lightbox-open {
    overflow: hidden;
}

@media (max-width: 768px) {
    .diagram-lightbox-scroller {
        max-height: 78vh;
        padding: 1rem;
    }

    .diagram-lightbox-close {
        top: 0.6rem;
        right: 0.6rem;
        width: 40px;
        height: 40px;
    }

    .diagram-lightbox-hint {
        padding: 0 1rem;
        font-size: 1.1rem;
    }
}
