:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #e4e2dc;
  --accent: #2f6b4f;
  --accent-text: #ffffff;
  --accent-soft: #e3efe8;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --error: #b42318;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --card: #212226;
    --text: #ececef;
    --muted: #9a9aa2;
    --line: #2f3036;
    --accent: #5fbf8c;
    --accent-text: #0e1a13;
    --accent-soft: #1f3329;
    --warn: #f0b45a;
    --warn-soft: #3a2e1b;
    --error: #ff8a80;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 48px);
}
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.count { background: var(--line); color: var(--text); border-radius: 99px; padding: 0 8px; font-size: 0.75rem; letter-spacing: 0; }
.muted { color: var(--muted); }
.empty { margin: 4px 0 0; }
.empty.big { text-align: center; padding: 48px 0; }

button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
}
button:disabled { opacity: 0.5; cursor: default; }
button.secondary { background: var(--accent-soft); color: var(--accent); }
button.small { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }
button.link { background: none; color: var(--accent); padding: 4px 6px; min-height: 32px; font-weight: 500; }
button.icon { background: var(--card); color: var(--text); width: 40px; padding: 0; border: 1px solid var(--line); }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 40px;
}

header { margin-bottom: 16px; }
.title-row { display: flex; align-items: center; justify-content: space-between; }
.icons { display: flex; gap: 8px; }
.sync { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 0.9rem; margin-top: 2px; }
.sync.error { color: var(--error); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; }
.chip { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 99px; font-weight: 500; white-space: nowrap; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 24px; }
.total-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.total-name { font-weight: 600; }
.total-sum { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--warn); }
.total-card.zero .total-sum { color: var(--accent); }
.total-sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; }

.group { margin-bottom: 28px; }
.exams { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.exam {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 4px 12px;
  align-items: start;
}
.exam-main { min-width: 0; }
.exam-meta { color: var(--muted); font-size: 0.8rem; }
.exam-title { font-weight: 600; }
.exam-name { color: var(--text); overflow-wrap: anywhere; }
.exam-verbal { margin: 4px 0 0; font-size: 0.9rem; color: var(--muted); white-space: pre-line; }
.exam-info { margin-top: 4px; font-size: 0.9rem; }
.exam-info summary { color: var(--accent); cursor: pointer; }
.exam-info p { white-space: pre-line; margin: 4px 0 0; color: var(--muted); }
.exam-actions { grid-column: 2; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

.grade, .date-badge {
  width: 48px; height: 48px; border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.15rem;
  background: var(--warn-soft); color: var(--warn);
}
.grade.empty { color: var(--muted); background: var(--line); }
.done .grade { background: var(--accent-soft); color: var(--accent); }
.date-badge { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.date-badge span { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.date-badge small { font-size: 0.7rem; font-weight: 500; color: var(--muted); margin-top: 2px; }
.waiting .date-badge { color: var(--muted); }

.amount-wrap { display: flex; align-items: center; gap: 4px; }
.amount { width: 72px; text-align: right; font-variant-numeric: tabular-nums; }
.paid-label { display: flex; flex-direction: column; font-weight: 600; color: var(--accent); }
.paid-label small { font-weight: 400; color: var(--muted); font-size: 0.75rem; }
.done.skipped .paid-label { color: var(--muted); }
.done.skipped { opacity: 0.75; }

.done-group summary { list-style: none; cursor: pointer; }
.done-group summary::-webkit-details-marker { display: none; }
.done-group summary h2::after { content: "▸"; margin-left: 2px; }
.done-group[open] summary h2::after { content: "▾"; }

.login { max-width: 320px; margin: 15vh auto 0; display: flex; flex-direction: column; gap: 10px; }
.login h1 { margin-bottom: 12px; }
.login label { font-size: 0.9rem; color: var(--muted); }
.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 28px; }
.error-text { color: var(--error); margin: 0; }

dialog { border: 0; border-radius: 18px; padding: 20px; background: var(--card); color: var(--text); width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h2 { font-size: 1.15rem; text-transform: none; letter-spacing: 0; color: var(--text); }
dialog p { font-size: 0.9rem; margin: 0 0 12px; }
.rate-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.rate-row label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.9rem; }
.rate-row input { width: 64px; text-align: right; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 0.95rem;
  transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--error); color: #fff; }

@media (min-width: 560px) {
  .exam { grid-template-columns: 48px 1fr auto; }
  .exam-actions { grid-column: 3; margin-top: 0; justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* WhatsApp dialog */
#wa-dialog { width: min(460px, calc(100vw - 32px)); }
.wa-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.wa-head h2 { margin: 0; }
.wa p { font-size: 0.92rem; margin: 8px 0; }
.wa-status { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.wa-status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.wa-status.open .dot { background: var(--accent); }
.wa-status.linking .dot, .wa-status.connecting .dot { background: var(--warn); }
.wa-qr { background: #fff; border-radius: 12px; padding: 8px; width: min(280px, 100%); margin: 8px auto; }
.wa-qr svg { display: block; width: 100%; height: auto; }
.wa-pair { margin-top: 8px; font-size: 0.92rem; }
.wa-pair summary { color: var(--accent); cursor: pointer; }
.wa-pair .row { display: flex; gap: 8px; }
.wa-pair input { flex: 1; min-width: 0; }
.wa-code { font: 700 1.8rem ui-monospace, monospace; letter-spacing: 0.12em; text-align: center; margin: 12px 0; }
.wa-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.wa-form .field { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.wa-form select { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 40px; }
.wa-form fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 12px; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.wa-form legend { font-size: 0.9rem; color: var(--muted); padding: 0 4px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.check-row { display: flex; align-items: center; gap: 6px; }
.hour { width: 64px; }
button.link.danger { color: var(--error); margin-top: 8px; padding-left: 0; }
