/* Camada visual e responsiva v1.3 — carregada por último para preservar o tema base. */
:root {
    --mobile-dock-height: 68px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body { max-width: 100%; }
body { overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
button, a, input, select, textarea { touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid rgba(98, 92, 242, .28);
    outline-offset: 2px;
}
.topbar-avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 13px;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-2), var(--cyan));
    box-shadow: 0 8px 20px rgba(98, 92, 242, .18);
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mobile-topbar-brand, .mobile-dock, .auth-mobile-features { display: none; }
.login-benefits {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: -6px 0 21px;
}
.login-benefits span {
    min-width: 0;
    padding: 10px 6px;
    border: 1px solid var(--line);
    border-radius: 11px;
    color: var(--muted);
    background: #fafaff;
    text-align: center;
    font-size: 9px;
    font-weight: 700;
    line-height: 1.25;
}
.login-benefits i { display: block; margin-bottom: 4px; color: var(--primary); font-size: 16px; font-style: normal; }
.password-wrap button {
    width: auto;
    min-width: 62px;
    padding: 0 8px;
    font-size: 10px;
    font-weight: 800;
    color: var(--primary);
}
.password-wrap input { padding-right: 74px; }
.is-submitting [type="submit"] { opacity: .68; cursor: wait; }
.moderation-question { display: block; color: var(--muted); font-size: 10px; }
.btn--moderator {
    color: #fff;
    background: linear-gradient(135deg, #098765, #13ad7e);
    box-shadow: 0 7px 18px rgba(9, 135, 101, .2);
}
.user-admin-card { overflow: hidden; }
.user-admin-card--pending {
    border-color: rgba(245, 154, 61, .42);
    box-shadow: 0 14px 38px rgba(149, 100, 0, .07);
}
.account-role-summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px 14px;
    align-items: center;
    margin-bottom: 14px;
}
.account-role-summary > span { color: var(--muted); font-size: 9px; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
.account-role-summary > strong { color: var(--primary); font-size: 12px; }
.account-role-summary > small { grid-column: 1 / -1; margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.approval-panel {
    margin: 15px -10px 6px;
    padding: 16px;
    border: 1px solid #fae1b5;
    border-radius: 15px;
    background: linear-gradient(145deg, #fffaf0, #fff);
}
.approval-panel > div:first-child { display: flex; flex-direction: column; }
.approval-panel > div:first-child strong { font-size: 13px; }
.approval-panel > div:first-child small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.approval-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 13px; }
.approval-actions--single { grid-template-columns: 1fr; }
.approval-actions form { min-width: 0; }
.approval-actions .btn { min-width: 0; padding-right: 8px; padding-left: 8px; font-size: 11px; }
.approval-note { margin: 10px 0 0; color: #6f624b; font-size: 9px; line-height: 1.45; }
.access-settings { margin-top: 15px; border-top: 1px solid var(--line); padding-top: 13px; }
.access-settings > summary { color: var(--primary); cursor: pointer; font-size: 11px; font-weight: 850; }
.access-settings > form { margin-top: 14px; }
.field--readonly {
    min-height: 65px;
    justify-content: center;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #f7f7fb;
}
.field--readonly strong { color: var(--primary); font-size: 13px; }
.field--readonly small { color: var(--muted); font-size: 9px; }
.protected-account-note { margin: 15px 0 0; padding: 11px; border-radius: 11px; color: var(--muted); background: #f7f7fb; font-size: 10px; text-align: center; }

@media (hover: none) {
    .btn:hover, .area-card:hover, .question-card:hover { transform: none; }
}

@media (max-width: 980px) {
    body.sidebar-open { overflow: hidden; }
    .sidebar {
        width: min(86vw, 320px);
        padding: max(20px, env(safe-area-inset-top)) 16px calc(18px + var(--safe-bottom));
        box-shadow: 24px 0 70px rgba(10, 14, 38, .35);
        visibility: hidden;
    }
    .sidebar-open .sidebar { visibility: visible; }
    .sidebar-close {
        display: grid !important;
        flex: none;
        width: 42px;
        height: 42px;
        color: #dce1f5;
        background: rgba(255,255,255,.08);
    }
    .nav-main { margin-top: 22px; padding-right: 2px; overscroll-behavior: contain; }
    .nav-link { min-height: 46px; }
    .sidebar-backdrop { backdrop-filter: blur(3px); }

    .topbar {
        height: 62px;
        display: grid;
        grid-template-columns: 42px minmax(0, 1fr) 42px;
        gap: 10px;
        padding: 0 14px;
        padding-top: env(safe-area-inset-top);
        box-sizing: content-box;
    }
    .menu-trigger {
        display: grid !important;
        width: 42px;
        height: 42px;
        color: var(--ink);
        background: #f0f1f7;
        border: 1px solid var(--line);
    }
    .mobile-topbar-brand {
        display: flex !important;
        min-width: 0;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }
    .mobile-topbar-brand img { flex: none; }
    .mobile-topbar-brand span { display: flex; min-width: 0; flex-direction: column; line-height: 1.08; }
    .mobile-topbar-brand small {
        color: var(--primary);
        font-size: 8px;
        font-weight: 900;
        letter-spacing: .14em;
        text-transform: uppercase;
    }
    .mobile-topbar-brand strong {
        max-width: 42vw;
        overflow: hidden;
        color: var(--ink);
        font-size: 12px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .topbar-actions { justify-content: flex-end; }
    .top-pill { display: none; }
    .topbar-avatar { width: 40px; height: 40px; border-radius: 13px; }

    .mobile-dock {
        position: fixed;
        z-index: 34;
        right: 10px;
        bottom: max(8px, var(--safe-bottom));
        left: 10px;
        height: var(--mobile-dock-height);
        display: grid !important;
        grid-template-columns: repeat(5, 1fr);
        padding: 6px;
        border: 1px solid rgba(224, 226, 237, .9);
        border-radius: 21px;
        background: rgba(255,255,255,.94);
        box-shadow: 0 16px 45px rgba(18, 23, 54, .18);
        backdrop-filter: blur(18px);
    }
    .mobile-dock a, .mobile-dock button {
        position: relative;
        min-width: 0;
        border: 0;
        border-radius: 15px;
        color: #7a7f94;
        background: transparent;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 1px;
    }
    .mobile-dock span { height: 25px; font-size: 20px; line-height: 25px; }
    .mobile-dock small { font-size: 8px; font-weight: 800; }
    .mobile-dock .is-active { color: var(--primary); background: #625cf20e; }
    .mobile-dock .is-active::before {
        content: "";
        position: absolute;
        top: 1px;
        width: 18px;
        height: 3px;
        border-radius: 99px;
        background: var(--primary);
    }
    .page-content { padding-bottom: calc(var(--mobile-dock-height) + var(--safe-bottom) + 38px); }

    /* O login mantém identidade visual no celular em vez de esconder metade da página. */
    .auth-body { background: var(--navy); }
    .auth-shell { min-height: 100dvh; display: block; }
    .auth-visual {
        display: flex;
        min-height: 238px;
        max-height: 290px;
        padding: max(24px, env(safe-area-inset-top)) 24px 48px;
        background: radial-gradient(circle at 12% 90%,#39cec93b 0,transparent 32%),radial-gradient(circle at 88% 10%,#625cf25c 0,transparent 35%),linear-gradient(145deg,#101633,#262b60);
    }
    .auth-visual .brand { padding: 0; }
    .auth-visual .brand img { width: 42px; height: 42px; }
    .auth-pitch { margin: 24px 0 0; }
    .auth-pitch .eyebrow, .auth-pitch > p, .auth-proof { display: none; }
    .auth-pitch h1 { max-width: 460px; margin: 0; font-size: clamp(25px, 7vw, 35px); letter-spacing: -.04em; }
    .auth-mobile-features {
        display: flex;
        flex-wrap: wrap;
        gap: 7px;
        margin-top: 15px;
    }
    .auth-mobile-features span {
        padding: 6px 9px;
        border: 1px solid rgba(255,255,255,.12);
        border-radius: 99px;
        color: #c8cfe8;
        background: rgba(255,255,255,.06);
        font-size: 9px;
        font-weight: 750;
    }
    .auth-panel {
        position: relative;
        z-index: 3;
        min-height: calc(100dvh - 210px);
        margin-top: -28px;
        padding: 31px 20px calc(28px + var(--safe-bottom));
        border-radius: 28px 28px 0 0;
        background: #fff;
        display: flex;
        align-items: flex-start;
        justify-content: center;
    }
    .auth-card { width: min(480px, 100%); }
}

@media (max-width: 680px) {
    body { font-size: 14px; }
    .page-content { padding: 19px 12px calc(var(--mobile-dock-height) + var(--safe-bottom) + 34px); }
    h1 { font-size: 29px; }
    .card { padding: 18px; border-radius: 17px; }
    .page-header { margin-bottom: 20px; }
    .page-header h1 { margin-bottom: 6px; font-size: 29px; }
    .page-header p { font-size: 12px; line-height: 1.55; }
    .header-illustration { display: none; }
    .btn { min-height: 44px; }
    .btn--small { min-height: 38px; }
    .icon-button { min-width: 40px; min-height: 40px; }
    .field { gap: 8px; }
    .field > span { font-size: 12px; }
    .field input, .field select, .field textarea, .comments-card textarea, .filter-bar input, .filter-bar select {
        min-height: 48px;
        border-radius: 12px;
        padding: 12px 13px;
        font-size: 16px;
    }
    .field textarea, .comments-card textarea { min-height: 96px; }
    .password-wrap button { top: 6px; min-height: 36px; }
    .check-row { font-size: 12px; line-height: 1.45; }
    .check-row input { width: 18px; height: 18px; flex: none; }

    .hero-dashboard {
        gap: 22px;
        padding: 25px 20px;
        border-radius: 22px;
        background: radial-gradient(circle at 90% 0,#6f65ff66 0,transparent 38%),linear-gradient(145deg,#151b3b,#2d2967);
    }
    .hero-copy h1 { max-width: 330px; font-size: 28px; }
    .hero-copy p { margin-bottom: 18px; font-size: 12px; }
    .hero-actions { display: grid; grid-template-columns: 1fr 1fr; flex-direction: initial; }
    .hero-actions .btn { width: auto; padding: 11px 8px; font-size: 11px; }
    .level-orb { width: 100%; justify-content: flex-start; padding-top: 17px; border-top: 1px solid rgba(255,255,255,.1); }
    .level-ring { width: 76px; height: 76px; }

    .stats-grid, .stats-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 12px 0; }
    .stats-grid--3 .stat-card:last-child:nth-child(odd) { grid-column: 1 / -1; }
    .stat-card { min-width: 0; gap: 10px; padding: 14px 12px; border-radius: 15px; }
    .stat-icon { width: 38px; height: 38px; border-radius: 12px; font-size: 18px; }
    .stat-card small { font-size: 9px; }
    .stat-card strong { font-size: 19px; }
    .stat-card em { max-width: 100%; overflow: hidden; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }

    .content-grid, .content-grid--wide { gap: 12px; }
    .section-heading { gap: 10px; margin: 25px 0 13px; }
    .section-heading h2 { font-size: 19px; }
    .section-heading a { flex: none; font-size: 11px; }
    .area-grid { gap: 10px; }
    .area-card { min-width: 0; padding: 15px; border-radius: 16px; }
    .area-card > div { min-width: 0; flex: 1; }
    .area-card h3 { font-size: 14px; }
    .area-card p, .area-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .dashboard-aside { margin-top: 3px; }
    .recommendation { padding: 23px 18px; }
    .recent-section .table-card { margin-bottom: 4px; }

    .filter-bar { gap: 9px; padding: 10px; border-radius: 15px; }
    .filter-bar .search-field { min-width: 0; }
    .search-field { min-height: 48px; padding-left: 12px; }
    .search-field input { min-height: 46px; padding-left: 8px; }
    .filter-check { min-height: 42px; padding: 9px 4px; display: flex; align-items: center; gap: 8px; }
    .filter-check input { width: 18px; height: 18px; }
    .filter-bar .btn { width: 100%; }

    .question-grid { gap: 11px; }
    .question-card { min-height: 0; padding: 16px; border-radius: 16px; }
    .question-card h2 { margin-bottom: 17px; font-size: 14px; }
    .question-meta { margin: 13px 0 9px; }
    .star-button { width: 42px; height: 42px; padding: 0; }
    .pagination { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; padding: 3px 1px 8px; }
    .pagination a { flex: 0 0 40px; width: 40px; height: 40px; }

    .builder-layout { gap: 11px; }
    .builder-card { padding: 18px; }
    .card-title { margin-bottom: 18px; }
    .choice-card { min-height: 76px; padding: 13px; }
    .range-field input { min-height: 34px; }
    .builder-summary { padding: 23px 20px; border-radius: 18px; }

    .study-top {
        position: sticky;
        z-index: 23;
        top: calc(62px + env(safe-area-inset-top));
        gap: 10px;
        margin: -8px -4px 12px;
        padding: 8px 4px;
        background: rgba(245,246,251,.95);
        backdrop-filter: blur(12px);
    }
    .study-top > .icon-button { width: 42px; height: 42px; flex: none; }
    .study-progress > span { font-size: 10px; }
    .question-stage { padding: 17px 15px; border-radius: 18px; }
    .question-stage-header { align-items: flex-start; }
    .question-text { margin: 18px 0; font-size: 16px; line-height: 1.65; }
    .alternative { min-height: 60px; gap: 11px; padding: 13px 11px; border-radius: 13px; }
    .alt-letter { width: 31px; height: 31px; }
    .alt-text { min-width: 0; overflow-wrap: anywhere; }
    .answer-form > .btn {
        position: sticky;
        z-index: 18;
        bottom: calc(var(--mobile-dock-height) + var(--safe-bottom) + 15px);
        min-height: 50px;
        box-shadow: 0 12px 32px rgba(98,92,242,.3);
    }
    .explanation { padding: 17px 14px; }
    .study-actions .btn, .study-actions form { width: 100%; }
    .study-actions form .btn { width: 100%; }
    .study-aside { gap: 10px; }
    .question-nav { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 5px; }
    .question-nav a { width: 40px; height: 40px; flex: 0 0 40px; aspect-ratio: auto; }

    .result-hero { padding: 27px 17px; border-radius: 21px; }
    .result-hero h1 { font-size: 27px; }
    .result-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
    .result-actions .btn { width: auto; padding: 10px 7px; font-size: 11px; }
    .result-list { margin-top: 12px; }
    .result-row { padding: 13px 0; }
    .result-row p { line-height: 1.45; }

    .deck-grid { gap: 11px; }
    .deck-card { padding: 17px; border-radius: 17px; }
    .deck-card h2 { margin-top: 13px; }
    .flash-row { gap: 10px; padding: 15px; border-radius: 15px; }
    .flash-row h2, .flash-row p { overflow-wrap: anywhere; }
    .review-shell > header { margin-bottom: 12px; }
    .flip-card, .flip-card-inner { min-height: min(590px, calc(100dvh - 175px)); }
    .flip-face { padding: 25px 16px; border-radius: 20px; }
    .flash-content { max-height: 58dvh; overflow-y: auto; font-size: 19px; line-height: 1.55; }
    .grade { min-height: 58px; }

    .profile-hero { padding: 22px 18px; border-radius: 20px; }
    .profile-hero .avatar--xl { width: 66px; height: 66px; border-radius: 21px; font-size: 25px; }
    .profile-hero > div:nth-child(2) { min-width: 0; }
    .profile-hero h1, .profile-hero p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .profile-hero h1 { font-size: 22px; }
    .performance-row { gap: 8px; }
    .toggle-row { min-height: 62px; }
    .achievement-card { padding: 14px 10px; }

    .podium { min-height: 235px; margin-top: 8px; }
    .podium-place { min-width: 0; }
    .podium-place--1 { min-height: 225px; }
    .podium-place--2 { min-height: 195px; }
    .podium-place--3 { min-height: 175px; }
    .podium-place p { display: none; }
    .podium-place > strong { font-size: 12px; }
    .ranking-card { overflow-x: hidden; }
    .ranking-card > header, .ranking-row { padding: 12px 10px; gap: 8px; }
    .rank-user { min-width: 0; }
    .rank-user > span:last-child { min-width: 0; }
    .rank-user strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    .filter-pills { margin-right: -12px; padding-right: 12px; overflow-x: auto; scrollbar-width: none; }
    .filter-pills::-webkit-scrollbar { display: none; }
    .filter-pills a { flex: 0 0 auto; min-height: 38px; display: inline-flex; align-items: center; }
    .user-admin-card { padding: 16px; }
    .user-admin-card header { align-items: flex-start; gap: 9px; }
    .user-admin-card header .avatar { width: 38px; height: 38px; border-radius: 12px; }
    .user-admin-card header .status { margin-left: auto; }
    .user-admin-card h2 { overflow-wrap: anywhere; font-size: 14px; }
    .user-admin-card p { overflow-wrap: anywhere; }
    .account-origin { align-items: flex-start; flex-direction: column; gap: 5px; padding: 10px; font-size: 10px; }
    .approval-panel { margin-right: -5px; margin-left: -5px; padding: 14px; }
    .approval-actions { grid-template-columns: 1fr; }
    .approval-actions .btn { min-height: 48px; font-size: 12px; }
    .approval-note { font-size: 10px; }
    .access-settings > summary { min-height: 40px; display: flex; align-items: center; font-size: 12px; }

    .admin-tabs {
        position: sticky;
        z-index: 21;
        top: calc(62px + env(safe-area-inset-top));
        margin: 0 -12px 17px;
        padding: 0 10px;
        background: rgba(245,246,251,.96);
        box-shadow: 0 7px 18px rgba(25,29,61,.04);
        backdrop-filter: blur(12px);
        scrollbar-width: none;
    }
    .admin-tabs::-webkit-scrollbar { display: none; }
    .admin-tabs a { min-height: 45px; padding: 12px 10px 9px; }
    .filter-pills { overflow-x: auto; padding-bottom: 5px; }
    .filter-pills a { flex: none; min-height: 38px; display: flex; align-items: center; }
    .quick-admin { gap: 9px; }
    .quick-admin > a { min-height: 72px; padding: 14px; }
    .user-admin-card header { align-items: flex-start; }
    .user-admin-card header > div { overflow: hidden; }
    .user-admin-card h2, .user-admin-card p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .account-origin { align-items: flex-start; gap: 8px; }
    .moderation-card form { display: grid; grid-template-columns: repeat(3, 1fr); }
    .moderation-card form .btn { min-width: 0; padding: 7px 4px; font-size: 10px; }
    .taxonomy-area { padding: 17px; }
    .simulation-question-list { max-height: 58dvh; }
    .simulation-question-list label { min-height: 66px; padding: 11px 9px; }
    .simulation-question-list .alt-letter { width: 64px; overflow: hidden; font-size: 9px; }
    .source-row { grid-template-columns: 38px minmax(0, 1fr); }
    .source-row em { grid-column: 2; justify-self: start; }

    .table-card {
        margin: 0;
        border-radius: 16px;
        -webkit-overflow-scrolling: touch;
        box-shadow: inset -16px 0 18px -20px rgba(20,25,55,.5);
    }
    .table-card table { min-width: 690px; }
    .table-card th, .table-card td { padding: 13px 14px; }
    .table-card th:first-child, .table-card td:first-child {
        position: sticky;
        z-index: 2;
        left: 0;
        background: #fff;
        box-shadow: 8px 0 14px -15px rgba(20,25,55,.65);
    }
    .table-card th:first-child { background: #fafaff; }

    .modal {
        width: 100%;
        max-width: none;
        max-height: min(88dvh, 780px);
        margin: auto 0 0;
        border-radius: 24px 24px 0 0;
        overflow-y: auto;
    }
    .modal > form { padding: 22px 17px calc(20px + var(--safe-bottom)); }
    .modal footer { position: sticky; bottom: 0; padding-top: 12px; background: #fff; }
    .modal footer .btn { flex: 1; }

    .auth-visual { min-height: 225px; padding-right: 20px; padding-left: 20px; }
    .auth-panel { min-height: calc(100dvh - 195px); padding: 28px 17px calc(25px + var(--safe-bottom)); }
    .auth-heading { margin-bottom: 20px; }
    .auth-heading h2 { margin-bottom: 7px; font-size: 27px; }
    .auth-heading p { font-size: 12px; line-height: 1.5; }
    .login-benefits { gap: 6px; margin-bottom: 18px; }
    .login-benefits span { padding: 9px 4px; font-size: 8px; }
    .stack-form { gap: 14px; }
    .stack-form > .btn--large { min-height: 51px; }
    .login-options { align-items: flex-start; }
    .login-options .check-row { flex: 1; }
    .login-options > a { padding-top: 3px; font-size: 11px; white-space: nowrap; }
    .auth-switch { font-size: 12px; }
    .legal-scroll { max-height: 48dvh; padding-right: 8px; }
    .legal-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .legal-actions .btn { min-width: 0; padding: 10px 7px; font-size: 11px; }
}

@media (max-width: 380px) {
    .auth-mobile-features span:last-child { display: none; }
    .login-benefits { grid-template-columns: 1fr 1fr; }
    .login-benefits span:last-child { display: none; }
    .stats-grid, .stats-grid--3 { grid-template-columns: 1fr; }
    .stats-grid--3 .stat-card:last-child:nth-child(odd) { grid-column: auto; }
    .hero-actions, .result-actions { grid-template-columns: 1fr; }
    .legal-actions { grid-template-columns: 1fr; }
    .mobile-dock { right: 6px; left: 6px; }
    .mobile-dock small { font-size: 7px; }
    .podium-place .avatar { width: 42px; height: 42px; }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 980px) {
    .auth-visual { min-height: 175px; }
    .auth-pitch { margin-top: 10px; }
    .auth-pitch h1 { font-size: 24px; }
    .auth-mobile-features { display: none; }
    .auth-panel { min-height: auto; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
