/* Chat-app layout: plum sidebar on desktop, bottom tab bar on phones. Dark mode follows the OS. */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8f7f9;
  --fg: #1d1c1d;
  --muted: #616061;
  --border: #e2dee4;
  --side: #3f0e40;
  --side-fg: #d9c9da;
  --side-strong: #ffffff;
  --side-hover: #350d36;
  --side-active: #1164a3;
  --accent: #007a5a;
  --accent-fg: #ffffff;
  --link: #1264a3;
  --danger: #e01e5a;
  --danger-bg: #fde7ee;
  --warn: #9a6700;
  --warn-bg: #fdf1d6;
  --ok: #007a5a;
  --ok-bg: #e1f3ea;
  --cell: #ecebee;
  --shadow: 0 8px 24px rgba(29, 28, 29, .14);
  --font: "Lato", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1d21; --surface: #1a1d21; --surface-2: #222529; --fg: #d1d2d3; --muted: #9b9c9f;
    --border: #35373b; --side: #19171d; --side-fg: #b9b3bc; --side-strong: #f2eff3; --side-hover: #26232b;
    --side-active: #1164a3; --accent: #007a5a; --accent-fg: #ffffff; --link: #4fb0e8;
    --danger: #f0567c; --danger-bg: #3b1823; --warn: #e8b54d; --warn-bg: #362b12; --ok: #4fcf9b; --ok-bg: #14342a;
    --cell: #2a2d31; --shadow: 0 8px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 15px; line-height: 1.5; }
a { color: var(--link); }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.hint { font-size: 13px; color: var(--muted); }
.stack { display: grid; gap: 14px; align-content: start; }

/* Shell */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); height: 100%; }
.side { background: var(--side); color: var(--side-fg); display: flex; flex-direction: column; min-height: 0; padding-top: env(safe-area-inset-top, 0px); }
.ws { padding: 14px 16px; border-bottom: 1px solid rgba(255, 255, 255, .1); display: grid; gap: 2px; }
.ws b { color: var(--side-strong); font-size: 17px; font-weight: 900; }
.ws span { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.ws span::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #2bac76; }
.side nav { padding: 10px 8px; display: grid; gap: 1px; overflow-y: auto; }
.group { font-size: 12px; padding: 12px 10px 4px; opacity: .8; }
.nav-link { text-decoration: none; padding: 5px 10px; border-radius: 6px; color: var(--side-fg); display: flex; align-items: center; gap: 8px; font-size: 15px; }
.nav-link:hover { background: var(--side-hover); }
.nav-link.on { background: var(--side-active); color: #fff; font-weight: 700; }
.nav-link .hash { opacity: .7; width: 14px; text-align: center; }
.badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 9px; padding: 0 6px; }
.me { margin-top: auto; padding: 12px 14px; border-top: 1px solid rgba(255, 255, 255, .1); display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--side-strong); }
.me form { margin-left: auto; }
.me button { background: none; border: 0; color: var(--side-fg); font-size: 12px; text-decoration: underline; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; padding-top: max(10px, env(safe-area-inset-top, 0px)); border-bottom: 1px solid var(--border); min-height: 54px; }
.topbar h1 { font-size: 17px; font-weight: 900; white-space: nowrap; }
.topbar .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.lang { margin-left: auto; display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; flex: none; }
.lang button { background: none; border: 0; padding: 3px 9px; font-size: 12px; font-weight: 700; color: var(--muted); }
.lang button.on { background: var(--fg); color: var(--surface); }
.content { flex: 1; overflow: auto; padding: 18px max(18px, env(safe-area-inset-right, 0px)) 24px max(18px, env(safe-area-inset-left, 0px)); min-height: 0; }
.content > * { max-width: 980px; }
.tabbar { display: none; border-top: 1px solid var(--border); background: var(--surface); padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabbar a { flex: 1; text-decoration: none; padding: 8px 2px 10px; font-size: 11px; color: var(--muted); display: grid; justify-items: center; gap: 2px; }
.tabbar svg { width: 20px; height: 20px; }
.tabbar a.on { color: var(--fg); font-weight: 700; }
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .tabbar { display: flex; }
  .content { padding: 14px 16px 20px; }
  .topbar { padding-inline: 16px; }
}

/* Simple shell for signed-out pages */
.entrance { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--side); }
.entrance > div { width: min(400px, 100%); }
.entrance .brand { color: var(--side-strong); font-size: 22px; font-weight: 900; text-align: center; margin-bottom: 14px; }
.entrance .brand small { display: block; font-size: 13px; font-weight: 400; color: var(--side-fg); }
.entrance .lang { margin: 14px auto 0; border-color: rgba(255, 255, 255, .25); width: max-content; }
.entrance .lang button { color: var(--side-fg); }
.entrance .lang button.on { background: var(--side-strong); color: var(--side); }

/* Pieces */
.av { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; font-weight: 900; font-size: 13px; color: #fff; flex: none; overflow: hidden; }
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.lg { width: 84px; height: 84px; border-radius: 16px; font-size: 28px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 7px 14px; font-weight: 700; font-size: 14px; text-decoration: none; color: var(--fg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn:hover { filter: brightness(.96); }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--danger-bg); color: var(--danger); }
.pill.neutral { background: var(--cell); color: var(--muted); }
.messages { display: grid; gap: 8px; margin-bottom: 14px; }
.message { padding: 10px 14px; border-radius: 8px; background: var(--ok-bg); color: var(--ok); font-weight: 700; font-size: 14px; }
.message.error { background: var(--danger-bg); color: var(--danger); }
.strikes { display: inline-flex; gap: 4px; vertical-align: middle; }
.strikes i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--danger); }
.strikes i.on { background: var(--danger); }
.banner { padding: 14px 16px; display: grid; gap: 4px; }
.banner.win { background: var(--ok-bg); border-color: var(--ok); }

/* My day */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 10px; display: grid; justify-items: center; line-height: 1.2; min-width: 58px; text-decoration: none; color: var(--fg); }
.chip small { font-size: 11px; color: var(--muted); }
.chip b { font-size: 15px; }
.chip.on { border-color: var(--link); box-shadow: inset 0 0 0 1px var(--link); }
.chip.locked { opacity: .55; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; margin-top: 3px; background: var(--danger); }
.chip .dot.ok { background: var(--ok); }
.chip .dot.today { background: var(--cell); }
.summary { padding: 16px; display: grid; gap: 10px; }
.summary-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.summary-head .big { font-size: 30px; font-weight: 900; }
.summary-head .big small { font-size: 16px; color: var(--muted); font-weight: 700; }
.bar { height: 10px; border-radius: 5px; background: var(--cell); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--warn); border-radius: 5px; transition: width .25s; }
.bar i.full { background: var(--ok); }
.exercise { display: grid; grid-template-columns: minmax(0, 1fr) auto 64px; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); }
.exercise:first-child { border-top: 0; }
.exercise label b { display: block; }
.exercise label span { font-size: 12px; color: var(--muted); }
.exercise .points { text-align: right; font-weight: 900; }
.exercise .points small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.exercise .field-errors { grid-column: 1 / -1; }
.exercise .field-errors:empty { display: none; }
.stepper { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.stepper button { width: 38px; height: 38px; border: 0; background: var(--surface-2); font-size: 18px; font-weight: 700; }
.stepper input { width: 64px; height: 38px; border: 0; border-inline: 1px solid var(--border); text-align: center; font: inherit; font-weight: 700; background: var(--surface); color: var(--fg); -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.locked-form .stepper { opacity: .5; }
.statusrow { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; }
.htmx-request .summary { opacity: .7; }
@media (max-width: 480px) {
  .exercise { grid-template-columns: minmax(0, 1fr) auto; }
  .exercise .points { display: none; }
}

/* Board */
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
table.board { border-collapse: separate; border-spacing: 0; font-size: 13px; width: max-content; min-width: 100%; }
.board th, .board td { padding: 0; border-bottom: 1px solid var(--border); }
.board thead th { font-size: 11px; font-weight: 700; color: var(--muted); padding: 8px 2px; text-align: center; background: var(--surface-2); }
.board thead th.today { color: var(--link); }
.board .who { position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left; padding: 6px 10px; min-width: 170px; border-right: 1px solid var(--border); }
.board thead .who { z-index: 3; background: var(--surface-2); }
.board .who button { background: none; border: 0; padding: 0; display: flex; align-items: center; gap: 8px; text-align: left; }
.board .who .av { width: 26px; height: 26px; font-size: 11px; border-radius: 6px; }
.board .who b { font-size: 13px; display: block; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.board .who small { font-size: 11px; color: var(--muted); display: block; }
.board td.c { text-align: center; padding: 4px 2px; }
.cell { display: block; width: 42px; margin: 0 auto; padding: 5px 0; border-radius: 5px; font-weight: 700; font-size: 12px; font-variant-numeric: tabular-nums; background: none; border: 0; }
.cell.ok { background: var(--ok-bg); color: var(--ok); }
.cell.adaptation { background: var(--cell); color: var(--muted); }
.cell.strike { background: var(--danger-bg); color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.cell.today { box-shadow: inset 0 0 0 2px var(--link); color: var(--fg); }
.cell.none { color: var(--muted); font-weight: 400; cursor: default; }
.board td.sum { font-weight: 900; padding: 4px 12px; text-align: right; font-variant-numeric: tabular-nums; }
.board td.st { padding: 4px 10px; }
.board tr.out td { opacity: .5; }
.board tr.out td.who { opacity: 1; }
.board tr.out .who b { text-decoration-line: line-through; }
.tip-content { display: none; }
#tip { position: fixed; z-index: 50; max-width: 280px; background: var(--surface); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 12px 14px; font-size: 13px; pointer-events: none; }
#tip h4 { margin: 0 0 6px; font-size: 14px; }
#tip table { border-collapse: collapse; width: 100%; }
#tip td { padding: 2px 0; font-variant-numeric: tabular-nums; }
#tip td:last-child { text-align: right; font-weight: 700; padding-left: 14px; }
#tip tr.total td { border-top: 1px solid var(--border); padding-top: 5px; font-weight: 900; }
#tip .note { margin-top: 6px; }
#tip .note.bad { color: var(--danger); }
#tip .bio { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
#tip .bio .av { width: 48px; height: 48px; border-radius: 10px; font-size: 17px; }
#tip dl { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
#tip dt { color: var(--muted); }
#tip dd { margin: 0; }

/* Join */
.two-columns { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .two-columns { grid-template-columns: minmax(0, 1fr); } }
.rules { padding: 18px; display: grid; gap: 10px; }
.rules h2 { font-size: 18px; }
.rules-text { white-space: pre-line; }
.exercise-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.exercise-table td { padding: 6px 0; border-bottom: 1px solid var(--border); }
.exercise-table td:last-child { text-align: right; font-weight: 700; }
.pay { padding: 18px; display: grid; gap: 12px; justify-items: center; text-align: center; }
.qr { width: 220px; max-width: 100%; background: #fff; border-radius: 8px; padding: 6px; }
.qr svg { width: 100%; height: auto; display: block; }
.pay dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; text-align: left; font-size: 13px; width: 100%; margin: 0; }
.pay dt { color: var(--muted); }
.pay dd { margin: 0; font-weight: 700; word-break: break-word; }

/* Forms */
.form { display: grid; gap: 12px; max-width: 560px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 13px; font-weight: 700; }
.field .required { color: var(--danger); }
.field input, .field select, .field textarea,
.auth-card input:not([type=checkbox]):not([type=hidden]) { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--fg); width: 100%; }
.errorlist { margin: 0; padding: 0; list-style: none; color: var(--danger); font-size: 13px; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .two-fields { grid-template-columns: 1fr; } }
.upload { display: flex; gap: 14px; align-items: center; }
.auth-card { width: min(400px, 100%); padding: 24px; display: grid; gap: 14px; }
.auth-card h1 { font-size: 22px; font-weight: 900; text-align: center; }
.auth-card form { display: grid; gap: 12px; }
.auth-card p { color: var(--muted); font-size: 14px; }
.auth-card label { font-size: 13px; font-weight: 700; display: block; margin-bottom: 4px; }
.auth-card form > button[type=submit]:not(.btn) { background: var(--accent); border: 1px solid var(--accent); color: var(--accent-fg); border-radius: 6px; padding: 9px 14px; font-weight: 700; }
.or { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.google-mark { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 12px; color: #fff; background: #4285f4; }

/* Admin screen */
.admin-card h2 { padding: 12px 14px; font-size: 15px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.admin-card h2 .hint { font-weight: 400; margin-left: auto; }
.waiting { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.waiting:first-of-type { border-top: 0; }
.waiting .name { flex: 1; min-width: 160px; }
.waiting .name small { display: block; color: var(--muted); font-size: 12px; }
.waiting form { display: flex; gap: 8px; }
.participants { width: 100%; border-collapse: collapse; font-size: 14px; }
.participants th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 8px 14px; background: var(--surface-2); }
.participants td { padding: 8px 14px; border-top: 1px solid var(--border); }
.switch { width: 38px; height: 22px; border-radius: 11px; border: 0; background: var(--cell); position: relative; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: left .15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { left: 19px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
