:root {
  --bg: #f3f4f6; --card: #fff; --ink: #111; --muted: #6b7280; --line: #e5e7eb; --black: #111;
  --green: #16a34a; --green-bg: #dcfce7; --yellow: #eab308; --yellow-bg: #fef9c3;
  --orange: #ea580c; --orange-bg: #ffedd5; --red: #dc2626; --red-bg: #fee2e2;
  --radius: 16px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* topo */
.topbar { background: var(--black); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 800; letter-spacing: .5px; display: flex; align-items: center; gap: 8px; }
.brand i { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; display: inline-block; }
.topbar .spacer { flex: 1; }
.topbar button { background: transparent; border: 1px solid #444; color: #fff; border-radius: 999px; padding: 6px 12px; }
.nav { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px 0; max-width: 1100px; margin: 0 auto; scrollbar-width: none; }
.nav button { white-space: nowrap; border: 0; background: #e5e7eb; border-radius: 999px; padding: 8px 14px; font-weight: 600; }
.nav button.on { background: var(--black); color: #fff; }
main { max-width: 1100px; margin: 0 auto; padding: 14px 16px calc(40px + env(safe-area-inset-bottom)); }

/* cards */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 10px; }
.big { font-size: 34px; font-weight: 800; line-height: 1; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.page-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }
.page-title h1 { font-size: 24px; }

/* chips / badges */
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; background: #e5e7eb; color: #374151; }
.chip.green { background: var(--green-bg); color: #166534; } .chip.yellow { background: var(--yellow-bg); color: #854d0e; }
.chip.orange { background: var(--orange-bg); color: #9a3412; } .chip.red { background: var(--red-bg); color: #991b1b; }
.chip.black { background: var(--black); color: #fff; } .chip.gray { background: #e5e7eb; color: #374151; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); } .dot.red { background: var(--red); } .dot.yellow { background: var(--yellow); } .dot.orange { background: var(--orange); }
.bar { height: 8px; border-radius: 99px; background: #e5e7eb; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--black); border-radius: 99px; }

/* prontidão */
.ready { display: flex; gap: 14px; align-items: center; }
.ready .emoji { font-size: 52px; line-height: 1; }
.ready.green .label { color: var(--green); } .ready.yellow .label { color: #a16207; }
.ready.orange .label { color: var(--orange); } .ready.red .label { color: var(--red); }
.ready .label { font-weight: 800; font-size: 18px; }
.rec { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: #f9fafb; border-left: 4px solid var(--black); }
.rec.green { border-color: var(--green); } .rec.yellow { border-color: var(--yellow); } .rec.orange { border-color: var(--orange); } .rec.red { border-color: var(--red); }

/* alertas */
.alert { display: flex; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--yellow-bg); }
.alert.high { background: var(--red-bg); }
.alert b { display: block; font-size: 13px; }

/* tabelas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 6px 8px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 800; border-bottom: 0; }
td input { width: 100%; min-width: 70px; }
td input[type=text]:not(.name) { min-width: 100px; }
td input.name { min-width: 160px; }

/* formulários */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff; }
textarea { min-height: 80px; resize: vertical; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.btn { border: 0; border-radius: 12px; padding: 11px 18px; font-weight: 700; background: var(--black); color: #fff; }
.btn.green { background: var(--green); } .btn.ghost { background: #e5e7eb; color: var(--ink); } .btn.red { background: var(--red); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { margin: 0; }
.days input { position: absolute; opacity: 0; pointer-events: none; }
.days span { display: inline-block; padding: 8px 12px; border-radius: 10px; background: #e5e7eb; font-weight: 700; font-size: 13px; }
.days input:checked + span { background: var(--black); color: #fff; }
.days input:focus-visible + span { outline: 3px solid #22c55e; }
.scale { display: flex; gap: 8px; }
.scale label { flex: 1; margin: 0; }
.scale input { position: absolute; opacity: 0; pointer-events: none; }
.scale span { display: block; text-align: center; padding: 12px 0; border-radius: 12px; background: #e5e7eb; font-weight: 800; }
.scale input:checked + span { background: var(--black); color: #fff; }
.scale input:focus-visible + span { outline: 3px solid #22c55e; }
.q { padding: 12px 0; border-bottom: 1px solid var(--line); }
.q:last-of-type { border-bottom: 0; }

/* semanas / periodização */
.weeks { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.week { flex: 0 0 auto; min-width: 92px; border-radius: 12px; padding: 8px 10px; color: #fff; text-align: center; border: 3px solid transparent; background: none; }
.week small { display: block; opacity: .85; font-size: 11px; }
.week.now { border-color: #111; box-shadow: 0 0 0 2px #fff inset; }
.week.sel { outline: 3px solid #22c55e; outline-offset: 1px; }

/* calendário */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; max-width: 520px; }
.cal .h { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); }
.cal button.d { aspect-ratio: 1; border-radius: 10px; border: 2px solid transparent; background: #f3f4f6; font-weight: 700; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.cal button.d small { font-size: 9px; font-weight: 600; opacity: .8; }
.cal button.d.out { visibility: hidden; }
.cal button.d.train { border-color: #111; background: #fff; }
.cal button.d.presente { background: var(--green); color: #fff; border-color: var(--green); }
.cal button.d.falta { background: var(--red); color: #fff; border-color: var(--red); }
.cal button.d.reposicao { background: var(--yellow); color: #111; border-color: var(--yellow); }
.cal button.d.today { box-shadow: 0 0 0 3px #22c55e44; }
.cal button.d:disabled { cursor: default; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; }

/* gráficos */
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { font: 11px system-ui, sans-serif; fill: #6b7280; }

/* lista de alunos */
.student { display: block; width: 100%; text-align: left; border: 0; background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.student .name { font-weight: 800; font-size: 16px; }
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); margin-bottom: 12px; }
.kpi { background: var(--card); border-radius: var(--radius); padding: 12px 14px; border: 0; text-align: left; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.kpi b { font-size: 26px; display: block; line-height: 1.1; }
.kpi.on { outline: 3px solid var(--black); }

/* login */
.login { max-width: 420px; margin: 8vh auto 0; padding: 0 16px; }
.login .logo { text-align: center; margin-bottom: 20px; }
.login .logo img { width: 72px; height: 72px; border-radius: 18px; }
.seg { display: flex; background: #e5e7eb; border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 700; }
.seg button.on { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.error { color: var(--red); font-weight: 600; margin-top: 8px; min-height: 1.2em; }

/* modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 20px; padding: 22px; max-width: 420px; width: 100%; }
.pin { font: 800 38px/1 ui-monospace, Consolas, monospace; letter-spacing: 6px; text-align: center; padding: 16px; background: #f3f4f6; border-radius: 12px; margin: 14px 0; user-select: all; }
#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(30px); background: var(--black); color: #fff; padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--red); }
pre.code { background: #111; color: #d1fae5; padding: 14px; border-radius: 12px; overflow-x: auto; font-size: 12px; max-height: 360px; }

@media (min-width: 900px) { .grid.two { grid-template-columns: 1fr 1fr; } }
@media print { .topbar, .nav, .btn { display: none !important; } }

/* início do aluno: semana em tiras */
.strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.strip .cell { border: 2px solid transparent; background: #f3f4f6; border-radius: 12px; padding: 8px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; font: inherit; color: inherit; min-width: 0; }
.strip button.cell { cursor: pointer; }
.strip .cell b { font-size: 11px; color: var(--muted); }
.strip .cell .n { font-size: 18px; font-weight: 800; line-height: 1.1; }
.strip .cell small { font-size: 10px; line-height: 1.15; min-height: 1.15em; overflow-wrap: anywhere; }
.strip .cell.train { background: #fff; border-color: #111; }
.strip .cell.presente { background: var(--green); border-color: var(--green); color: #fff; }
.strip .cell.falta { background: var(--red); border-color: var(--red); color: #fff; }
.strip .cell.reposicao { background: var(--yellow); border-color: var(--yellow); color: #111; }
.strip .cell.presente b, .strip .cell.falta b { color: #fff; }
.strip .cell.reposicao b { color: #111; }
.strip .cell.today { box-shadow: 0 0 0 3px #22c55e66; }
.cal button.d.sel { outline: 3px solid #111; outline-offset: 1px; }
.btn.yellow { background: var(--yellow); color: #111; }
.btn.on { outline: 3px solid #111; outline-offset: 1px; }
.pend { max-height: 360px; overflow: auto; }
.pend-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
