:root {
    --color-primary: #4F46E5;
    --color-primary-dark: #4338CA;
    --color-secondary: #111827;
    --color-bg: #f3f4f6;
    --color-surface: #ffffff;
    --color-border: #e5e7eb;
    --color-text: #111827;
    --color-text-muted: #6b7280;
    --color-success: #16a34a;
    --color-danger: #dc2626;
    --color-warning: #d97706;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(17,24,39,.06), 0 1px 1px rgba(17,24,39,.04);
    --shadow-md: 0 8px 24px -8px rgba(17,24,39,.12);
    --sidebar-width: 250px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); }

img { max-width: 100%; }

.container { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
@media (max-width: 560px) { .container { padding: 0 16px; } }

/* ---------- Layout admin (sidebar) ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: #111827;
    color: #e5e7eb;
    flex-shrink: 0;
    padding: 20px 0;
}
.sidebar .brand {
    padding: 8px 20px 22px; font-weight: 700; font-size: 18px; color: #fff;
    border-bottom: 1px solid #1f2937; margin-bottom: 12px; display: flex; align-items: center; min-height: 44px;
}
.sidebar-logo { max-height: 64px; max-width: 100%; object-fit: contain; }
.sidebar nav a {
    display: block; padding: 10px 20px; color: #cbd5e1; text-decoration: none; font-size: 14px;
}
.sidebar nav a:hover, .sidebar nav a.active { background: #1f2937; color: #fff; border-left: 3px solid var(--color-primary); padding-left: 17px; }
.sidebar .section-title { padding: 16px 20px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #6b7280; }

.main { flex: 1; min-width: 0; }
.topbar {
    background: var(--color-surface); border-bottom: 1px solid var(--color-border);
    padding: 14px 24px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
[data-sidebar-toggle] { display: none; }
.content { padding: 24px; }

/* Sidebar em off-canvas para telas pequenas */
@media (max-width: 860px) {
    .sidebar {
        position: fixed; inset: 0 auto 0 0; z-index: 200; transform: translateX(-100%);
        transition: transform .2s ease; box-shadow: var(--shadow-md); overflow-y: auto;
    }
    .sidebar.open { transform: translateX(0); }
    [data-sidebar-toggle] { display: inline-block; }
    .topbar { padding: 12px 16px; flex-wrap: wrap; }
    .content { padding: 16px; }
}

/* ---------- Cards / tabelas ---------- */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
.card h2, .card h3 { margin-top: 0; }
@media (max-width: 560px) { .card { padding: 18px; border-radius: 10px; } }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.stat .value { font-size: 28px; font-weight: 700; }
.stat .label { color: var(--color-text-muted); font-size: 13px; }
@media (max-width: 560px) { .stat .value { font-size: 22px; } }

table { width: 100%; border-collapse: collapse; }
table th, table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); font-size: 14px; }
table th { color: var(--color-text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Formularios ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=tel], input[type=url], select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 14px; background: #fff; color: var(--color-text);
}
textarea { resize: vertical; min-height: 100px; font-family: inherit; }
/* Evita zoom automatico do iOS Safari ao focar campos com font-size < 16px */
@media (max-width: 560px) {
    input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=tel], input[type=url], select, textarea {
        font-size: 16px;
    }
}
.field { margin-bottom: 16px; }
.field-hint { color: var(--color-text-muted); font-size: 12px; margin-top: 4px; }
.field-hint.hint-erro { color: var(--color-danger); font-weight: 600; }
.field-hint.hint-ok { color: var(--color-success); }
input.input-invalido { border-color: var(--color-danger); background: #fef2f2; }
input.input-invalido:focus { outline: 2px solid #fecaca; outline-offset: 0; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
legend { font-weight: 600; padding: 0 6px; }

/* ---------- Botoes ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 11px 20px; border-radius: 8px; border: none; cursor: pointer;
    font-size: 14px; font-weight: 600; text-decoration: none; background: var(--color-primary); color: #fff;
    box-shadow: var(--shadow-sm); transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease;
}
.btn:hover { background: var(--color-primary-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.btn-secondary { background: #fff; color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: #f9fafb; }
.btn-danger { background: var(--color-danger); }
.btn-success { background: var(--color-success); }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-block { display: flex; width: 100%; text-align: center; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-muted { background: #f3f4f6; color: #4b5563; }

/* ---------- Alertas / toasts ---------- */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info { background: #dbeafe; color: #1e40af; }

/* ---------- Paginas publicas ---------- */
.public-page { min-height: 100vh; display: flex; flex-direction: column; }

.public-header {
    background: linear-gradient(120deg, var(--color-primary), var(--color-secondary));
    color: #fff; padding: 32px 0 40px;
}
.public-header h1 { margin: 0; font-size: 28px; letter-spacing: -.01em; }
.public-header p { margin: 6px 0 0; opacity: .88; }

.public-header-logo-badge {
    display: inline-flex; align-items: center; justify-content: center;
    background: #fff; border-radius: 14px; padding: 12px 20px; margin-bottom: 20px;
    box-shadow: 0 10px 24px -10px rgba(0,0,0,.35);
}
.public-header-logo-badge img { max-height: 60px; max-width: 260px; display: block; }

@media (max-width: 560px) {
    .public-header { padding: 22px 0 28px; }
    .public-header h1 { font-size: 22px; }
    .public-header-logo-badge { padding: 8px 14px; margin-bottom: 14px; border-radius: 12px; }
    .public-header-logo-badge img { max-height: 42px; max-width: 190px; }
}

.public-body { flex: 1; padding: 32px 0; }
@media (max-width: 560px) { .public-body { padding: 22px 0; } }
.public-footer { padding: 20px 0; text-align: center; color: var(--color-text-muted); font-size: 13px; }

.question-block { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; background: #fff; }
.question-block .enunciado { font-weight: 600; margin-bottom: 12px; }
.alt-option { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.alt-option:hover { background: #f9fafb; }
.alt-option input { margin-top: 3px; }

/* ---------- Revisao de questoes (tela de resultado) ---------- */
.alt-review { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--color-border); margin-bottom: 6px; font-size: 14px; }
.alt-review.is-correct { background: #f0fdf4; border-color: #bbf7d0; }
.alt-review.is-wrong { background: #fef2f2; border-color: #fecaca; }
.alt-review .alt-tag { margin-left: auto; font-size: 12px; font-weight: 700; white-space: nowrap; }
.alt-review.is-correct .alt-tag { color: var(--color-success); }
.alt-review.is-wrong .alt-tag { color: var(--color-danger); }
.question-block .em-branco-tag { display: inline-block; margin-top: 4px; }

/* ---------- Grafico de aproveitamento (donut) ---------- */
.donut-wrap { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; justify-content: center; }
.donut-chart { position: relative; width: 160px; height: 160px; flex-shrink: 0; }
.donut-chart svg { width: 100%; height: 100%; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.donut-center .pct { font-size: 26px; font-weight: 800; color: var(--color-text); line-height: 1.1; }
.donut-center .label { font-size: 11.5px; color: var(--color-text-muted); }
.donut-legend { display: flex; flex-direction: column; gap: 10px; min-width: 160px; }
.donut-legend-item { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.donut-legend-item .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.donut-legend-item strong { margin-left: auto; }
@media (max-width: 480px) { .donut-wrap { gap: 16px; } .donut-chart { width: 130px; height: 130px; } .donut-center .pct { font-size: 21px; } }

.loading-overlay {
    position: fixed; inset: 0; background: rgba(17,24,39,.85); color: #fff; display: none;
    align-items: center; justify-content: center; flex-direction: column; gap: 16px; z-index: 999; text-align: center; padding: 20px;
}
.loading-overlay.active { display: flex; }
.spinner { width: 48px; height: 48px; border: 4px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cronometro da prova ---------- */
.timer-bar {
    position: sticky; top: 0; z-index: 50; background: #fff; border-bottom: 1px solid var(--color-border);
    padding: 10px 20px; box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.timer-bar-info { display: flex; justify-content: space-between; max-width: 760px; margin: 0 auto 6px; font-size: 13px; color: var(--color-text-muted); }
.timer-bar-info strong { color: var(--color-text); }
.timer-track { max-width: 760px; margin: 0 auto; height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.timer-fill { height: 100%; width: 0%; background: var(--color-primary); border-radius: 999px; transition: width 1s linear, background-color .4s ease; }
.timer-fill.timer-warning { background: var(--color-warning); }
.timer-fill.timer-danger { background: var(--color-danger); }
.timer-bar-info #timer-restante.timer-danger-text { color: var(--color-danger); font-weight: 700; }
@media (max-width: 480px) { .timer-bar { padding: 8px 14px; } .timer-bar-info { font-size: 12px; } }

.score-hero { text-align: center; padding: 32px; }
.score-hero .value { font-size: 48px; font-weight: 800; }
@media (max-width: 480px) { .score-hero { padding: 20px; } .score-hero .value { font-size: 36px; } }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 20px; }
.tabs a { padding: 10px 16px; text-decoration: none; color: var(--color-text-muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--color-primary); border-color: var(--color-primary); font-weight: 600; }

.pagination { display: flex; gap: 6px; margin-top: 16px; }
.pagination a, .pagination span { padding: 6px 12px; border: 1px solid var(--color-border); border-radius: 6px; text-decoration: none; color: var(--color-text); font-size: 13px; }
.pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------- Checklist "Primeiros passos" (menu de gaveta) ---------- */
.onboarding-trigger {
    position: fixed; right: 20px; bottom: 20px; z-index: 150;
    display: inline-flex; align-items: center; gap: 8px;
    background: #111827; color: #fff; border: none; border-radius: 999px;
    padding: 12px 18px; font-size: 13px; font-weight: 600; cursor: pointer;
    box-shadow: var(--shadow-md);
}
.onboarding-trigger-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-danger); flex-shrink: 0; }
.onboarding-trigger-count {
    background: var(--color-danger); color: #fff; border-radius: 999px; font-size: 11px;
    min-width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px;
}

.onboarding-overlay {
    position: fixed; inset: 0; background: rgba(17,24,39,.45); z-index: 160;
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.onboarding-overlay.open { opacity: 1; pointer-events: auto; }

.onboarding-drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: 360px; max-width: 90vw; z-index: 161;
    background: var(--color-surface); box-shadow: -12px 0 32px -12px rgba(0,0,0,.3);
    transform: translateX(100%); transition: transform .25s ease;
    padding: 22px; overflow-y: auto;
}
.onboarding-drawer.open { transform: translateX(0); }
.onboarding-drawer-head { display: flex; justify-content: space-between; align-items: center; }
.onboarding-drawer-head h3 { margin: 0; }
.onboarding-drawer-close { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--color-text-muted); padding: 4px; }

.onboarding-list { list-style: none; margin: 16px 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.onboarding-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: 8px; }
.onboarding-item-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.onboarding-item.is-pending .onboarding-item-dot { background: var(--color-danger); }
.onboarding-item.is-done .onboarding-item-dot { background: var(--color-success); }
.onboarding-item-label { flex: 1; font-size: 13.5px; }
.onboarding-item.is-done .onboarding-item-label { color: var(--color-text-muted); }
