/* =========================================================
   Afya DS Hub — tokens visuais
   A cor de marca (--brand) é definida no admin (Configurações)
   e aplicada em tempo de execução. Os demais tokens ficam aqui.
   ========================================================= */
:root {
  --brand: #3451D1;
  --brand-ink: #ffffff;
  --brand-soft: color-mix(in srgb, var(--brand) 9%, var(--surface));
  --brand-line: color-mix(in srgb, var(--brand) 28%, var(--surface));
  --brand-strong: color-mix(in srgb, var(--brand) 82%, #000);

  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --surface-2: #F1F3F6;
  --ink: #1B2130;
  --ink-2: #4A5366;
  --muted: #6B7385;
  --line: #E2E5EB;
  --line-strong: #CDD2DB;

  --ok: #12805C;    --ok-soft: #E6F4EE;
  --warn: #9A5B00;  --warn-soft: #FDF2DC;
  --bad: #B42318;   --bad-soft: #FDECEA;
  --gold: #B7791F;

  --radius-s: 6px;
  --radius: 10px;
  --radius-l: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-l: 0 12px 32px rgba(16, 24, 40, .12);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar: 264px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1218; --surface: #161A22; --surface-2: #1D222C;
    --ink: #E8EBF1; --ink-2: #BAC1CE; --muted: #8C94A4;
    --line: #262C37; --line-strong: #353C49;
    --ok: #4CC79A; --ok-soft: #12291F; --warn: #F0B54A; --warn-soft: #2E2410; --bad: #F2877C; --bad-soft: #321713;
    --gold: #E5B455;
    --brand-soft: color-mix(in srgb, var(--brand) 18%, var(--surface));
    --brand-line: color-mix(in srgb, var(--brand) 45%, var(--surface));
    --brand-strong: color-mix(in srgb, var(--brand) 70%, #fff);
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    --shadow-l: 0 12px 32px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0; letter-spacing: -0.015em; }
h1 { font-size: 30px; font-weight: 750; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 650; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Layout do app ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; background: linear-gradient(to right, var(--surface) calc(var(--sidebar) - 1px), var(--line) calc(var(--sidebar) - 1px), var(--line) var(--sidebar), transparent var(--sidebar)); }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: var(--ink); font-weight: 750; font-size: 17px; letter-spacing: -0.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 6px; }
.brand-mark i { background: var(--brand-ink); border-radius: 2px; opacity: .95; }
.brand-mark i:nth-child(2) { border-radius: 50%; opacity: .7; }
.brand-mark i:nth-child(3) { grid-column: span 2; opacity: .5; }
.nav-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-s); color: var(--ink-2); font-weight: 500; font-size: 14px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 650; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; }
.me { display: flex; align-items: center; gap: 10px; padding: 6px 10px 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-strong); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.me-name { font-weight: 650; font-size: 14px; line-height: 1.2; }
.me-company { font-size: 12px; color: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 12px 32px; display: flex; gap: 12px; align-items: center; }
.btn.menu-btn { display: none; }
.search { position: relative; flex: 1; max-width: 560px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { width: 100%; padding: 9px 12px 9px 38px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.search input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-l); max-height: 60vh; overflow: auto; padding: 6px; display: none; }
.search-results.open { display: block; }
.search-results a { display: block; padding: 10px 12px; border-radius: var(--radius-s); color: var(--ink); }
.search-results a:hover, .search-results a:focus { background: var(--surface-2); text-decoration: none; }
.search-results .empty { padding: 12px; color: var(--muted); }
.content { padding: 32px; max-width: 1180px; width: 100%; }

/* ---------- Componentes ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; justify-content: center; padding: 9px 16px; border-radius: var(--radius-s); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-strong); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { padding: 7px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); box-shadow: var(--shadow); }
.card.pad { padding: 22px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.brand { background: var(--brand-soft); color: var(--brand-strong); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.page-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 26px; }
.page-head .head-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-strong); display: grid; place-items: center; flex: none; }
.page-head .head-icon .icon { width: 24px; height: 24px; }
.page-head p { color: var(--ink-2); margin-top: 6px; max-width: 70ch; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

/* Hero */
.hero { position: relative; overflow: hidden; border-radius: var(--radius-l); padding: 36px; background: var(--ink); color: #fff; margin-bottom: 28px; }
.hero h1 { font-size: 32px; max-width: 22ch; }
.hero p { color: rgba(255,255,255,.78); margin-top: 10px; max-width: 60ch; font-size: 16px; }
.hero-grid { position: absolute; right: -30px; top: -30px; display: grid; grid-template-columns: repeat(4, 54px); gap: 10px; opacity: .9; transform: rotate(-8deg); }
.hero-grid i { height: 54px; border-radius: 12px; background: var(--brand); opacity: .55; }
.hero-grid i:nth-child(3n) { border-radius: 50%; opacity: .35; }
.hero-grid i:nth-child(4n) { opacity: .2; }
.hero > *:not(.hero-grid) { position: relative; }
@media (prefers-color-scheme: dark) { .hero { background: #232A38; } }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 30px 0 12px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

.tile { display: flex; flex-direction: column; gap: 8px; padding: 18px; color: var(--ink); transition: border-color .15s, transform .15s; }
a.tile:hover { text-decoration: none; border-color: var(--brand-line); transform: translateY(-1px); }
.tile .tile-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-strong); display: grid; place-items: center; }
.tile p { color: var(--ink-2); font-size: 14px; }
.tile .meta { margin-top: auto; padding-top: 6px; font-size: 12px; color: var(--muted); }

.link-card { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; padding: 18px; color: var(--ink); }
a.link-card:hover { text-decoration: none; border-color: var(--brand-line); }
a.link-card:hover .ext { color: var(--brand-strong); }
.link-card .title { font-weight: 650; font-size: 15px; }
.link-card .desc { grid-column: 1 / -1; color: var(--ink-2); font-size: 14px; }
.link-card .ext { color: var(--muted); }
.link-card .meta { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.link-card.deprecated { opacity: .72; }
.link-card .from { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.list { display: grid; gap: 10px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 550; cursor: pointer; color: var(--ink-2); }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--surface); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .icon { width: 30px; height: 30px; margin-bottom: 8px; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 22px; letter-spacing: -0.02em; }
.stat span { font-size: 12px; color: var(--muted); }

.rank-list { display: grid; gap: 2px; }
.rank-item { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 8px 6px; border-radius: var(--radius-s); }
.rank-item.me { background: var(--brand-soft); }
.rank-pos { font-weight: 750; color: var(--muted); text-align: center; }
.rank-pos.top1 { color: var(--gold); }
.rank-name { font-weight: 600; font-size: 14px; line-height: 1.2; }
.rank-company { font-size: 12px; color: var(--muted); }
.rank-pts { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Tabelas */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.me td { background: var(--brand-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
.clip { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; overflow-x: auto; }
.tabs a, .tabs button { padding: 10px 14px; border: none; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--ink-2); font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; }
.tabs a:hover, .tabs button:hover { color: var(--ink); text-decoration: none; }
.tabs .on { color: var(--brand-strong); border-bottom-color: var(--brand); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-s); padding: 3px; gap: 2px; }
.seg button { border: none; background: transparent; padding: 6px 12px; border-radius: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* Formulários */
.field { display: grid; gap: 6px; }
.field label, .field .label { font-size: 13px; font-weight: 650; color: var(--ink-2); }
.field .help { font-size: 12px; color: var(--muted); }
.input, .field input[type=text], .field input[type=email], .field input[type=password], .field input[type=url], .field input[type=number], .field select, .field textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-s); background: var(--surface);
}
.field textarea { min-height: 84px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: var(--radius-s); font-size: 14px; display: none; }
.form-error.show { display: block; }
.notice { background: var(--brand-soft); color: var(--ink); padding: 12px 14px; border-radius: var(--radius); font-size: 14px; }
.notice.warn { background: var(--warn-soft); }
.option-row { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
.option-row input[type=radio] { width: 16px; height: 16px; accent-color: var(--ok); }

/* Telas de autenticação */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-side { background: var(--ink); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-side .brand { color: #fff; padding: 0; }
.auth-side h1 { font-size: 36px; max-width: 16ch; margin-top: 40px; }
.auth-side p { color: rgba(255,255,255,.75); margin-top: 14px; max-width: 46ch; font-size: 16px; }
.auth-side .hero-grid { right: -40px; top: auto; bottom: -40px; }
.auth-main { display: grid; place-items: center; padding: 40px 24px; }
.auth-box { width: 100%; max-width: 400px; }
.auth-box h2 { font-size: 24px; margin-bottom: 6px; }
.auth-box .sub { color: var(--muted); margin-bottom: 24px; }
.auth-box form { display: grid; gap: 14px; }
.auth-foot { margin-top: 20px; font-size: 14px; color: var(--ink-2); text-align: center; }
@media (prefers-color-scheme: dark) { .auth-side { background: #1B2130; } }

/* Quiz */
.deck { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.deck p { color: var(--ink-2); font-size: 14px; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.quiz { max-width: 760px; }
.quiz-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.question { padding: 28px; }
.question h2 { font-size: 21px; line-height: 1.35; margin: 12px 0 20px; letter-spacing: -0.01em; }
.options { display: grid; gap: 10px; }
.option { display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: start; text-align: left; width: 100%; padding: 13px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer; font-size: 15px; line-height: 1.45; }
.option:hover:not([disabled]) { border-color: var(--brand); background: var(--brand-soft); }
.option .letter { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-strong); display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--ink-2); }
.option[disabled] { cursor: default; }
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.option.right .letter { background: var(--ok); border-color: var(--ok); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .letter { background: var(--bad); border-color: var(--bad); color: #fff; }
.feedback { margin-top: 18px; padding: 16px; border-radius: var(--radius); background: var(--surface-2); }
.feedback b { display: block; margin-bottom: 4px; }
.feedback.right b { color: var(--ok); }
.feedback.wrong b { color: var(--bad); }
.points-badge { display: inline-flex; gap: 6px; align-items: center; margin-top: 10px; font-size: 13px; font-weight: 650; color: var(--brand-strong); }

/* Métricas */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin-bottom: 18px; }
.kpi { padding: 16px; }
.kpi b { display: block; font-size: 26px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 13px; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 4px; position: relative; }
.bars .bar i { display: block; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 1px; }
.bars .bar:hover i { background: var(--brand-strong); }
.bars-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 200px) 1fr 48px; gap: 10px; align-items: center; font-size: 14px; padding: 5px 0; }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* Modal e toasts */
.modal-back { position: fixed; inset: 0; background: rgba(15, 18, 24, .5); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { width: 100%; max-width: 640px; max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border-radius: var(--radius-l); box-shadow: var(--shadow-l); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
#toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: var(--surface); padding: 11px 16px; border-radius: var(--radius); box-shadow: var(--shadow-l); font-size: 14px; max-width: 360px; animation: in .2s ease-out; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

/* Responsivo */
@media (max-width: 1080px) { .split { grid-template-columns: 1fr; } .two-col { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar); z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-l); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .btn.menu-btn { display: inline-flex; }
  .app { background: none; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .content { padding-top: 22px; }
  .hero { padding: 26px 22px; } .hero h1 { font-size: 25px; }
  .hero-grid { opacity: .35; }
  h1 { font-size: 25px; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { padding: 28px 24px; } .auth-side h1 { font-size: 26px; margin-top: 20px; }
  .auth-side .hero-grid { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(3, 1fr); }
  .question { padding: 20px; } .question h2 { font-size: 18px; }
  .hbar { grid-template-columns: 110px 1fr 40px; }
}
