:root {
  --bg: #f4f6fa; --card: #fff; --ink: #1f2a37; --muted: #6b7280; --line: #e3e8ef; --brand: #0f5fae; --brand-2: #0b4a88;
  --met: #1e9e4a; --miss1: #f08c00; --miss2: #d6336c; --pending: #3b82c4; --future: #d0d5dc;
  --met-bg: #e3f6ea; --miss1-bg: #fff1dc; --miss2-bg: #fde4ec; --pending-bg: #e2effa;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 2px 8px rgba(16,24,40,.05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f141b; --card: #161d26; --ink: #e6edf3; --muted: #9aa5b1; --line: #26303c; --brand: #4c9be8; --brand-2: #79b4ee;
    --future: #3a4450; --met-bg: #12301d; --miss1-bg: #3a2a0e; --miss2-bg: #3a1424; --pending-bg: #142a40; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 1.6rem; margin: .6em 0 .4em; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 .6em; }
h3 { font-size: 1rem; margin: .2em 0 .5em; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .center { text-align: center; } .right { text-align: right; }

/* top bar */
.topbar { background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .topbar { background: #0b3c6e; } }
.topbar .wrap { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 10px; font-size: 1.05rem; white-space: nowrap; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M5 17h6l3-7 4 13 3-6h6' stroke='%230f5fae' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/80% no-repeat; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.nav a, .nav button { color: #fff; text-decoration: none; padding: 8px 10px; border-radius: 8px; font-size: .92rem; background: none; border: 0; cursor: pointer; font: inherit; font-size: .92rem; }
.nav a:hover, .nav button:hover, .nav a.on { background: rgba(255,255,255,.16); }
.nav a.on { font-weight: 600; }
.logout { margin: 0; }
.menu-btn { display: none; margin-left: auto; background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; }
@media (max-width: 900px) {
  .menu-btn { display: block; }
  .nav { display: none; width: 100%; flex-direction: column; align-items: stretch; padding-bottom: 10px; }
  .nav.open { display: flex; }
  .nav button { text-align: left; width: 100%; }
}

/* today strip + legend */
.today-strip { background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 0; }
.today-strip .wrap { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; justify-content: space-between; }
.today-date { font-size: 1rem; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.today-date .dow { font-weight: 700; color: var(--brand); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend b { color: var(--ink); font-weight: 600; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.sw.met, .dot.met { background: var(--met); } .sw.miss1, .dot.miss1 { background: var(--miss1); } .sw.miss2, .dot.miss2 { background: var(--miss2); }
.sw.pending { background: var(--pending); } .sw.future { background: var(--future); }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--pending-bg); color: var(--ink); text-decoration: none; font-size: .85rem; }
.chip:hover { outline: 1px solid var(--brand); }

/* cards, layout */
main.wrap { padding-bottom: 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin: 16px 0; }
.grid2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 16px; }
.grid2 > * { min-width: 0; }
.grid2 > .card { margin: 0; } .grid2 + .card, .card + .grid2 { margin-top: 16px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: minmax(0,1fr); } }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.link-card { text-decoration: none; color: inherit; margin: 0; display: block; transition: transform .1s; }
.link-card:hover { transform: translateY(-2px); border-color: var(--brand); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 16px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat span { display: block; font-size: .82rem; color: var(--muted); }
.stat b { display: block; font-size: 1.7rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }

/* forms */
label { display: block; font-weight: 600; font-size: .9rem; margin: 0 0 12px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-weight: 400; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; transform: scale(1.15); }
label.check { font-weight: 400; display: flex; align-items: center; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; align-items: end; }
.form-grid .full { grid-column: 1 / -1; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; } .form-row .grow { flex: 1; min-width: 220px; }
.filter { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
.filter label { margin: 0; }
.presets { width: 100%; display: flex; gap: 6px; flex-wrap: wrap; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 0 0 12px; }
fieldset.members { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 2px 16px; }
fieldset.members legend { font-weight: 600; font-size: .9rem; }
fieldset.members label { margin: 4px 0; }
.btn { display: inline-block; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: #fff; background: var(--miss2); border-color: var(--miss2); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.link.danger { color: var(--miss2); }
form.inline { display: inline; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.inline-label { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.inline-label select { width: auto; margin: 0; }

/* auth */
.auth { display: flex; justify-content: center; padding: 30px 0; }
.auth-card { width: 100%; max-width: 420px; }
.code-input { font-size: 1.6rem; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }

/* flash */
.flash { padding: 12px 14px; border-radius: 8px; margin: 14px 0; border: 1px solid; }
.flash.ok { background: var(--met-bg); border-color: var(--met); }
.flash.warn { background: var(--miss1-bg); border-color: var(--miss1); }
.flash.err { background: var(--miss2-bg); border-color: var(--miss2); }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me > * { background: var(--pending-bg); }
tr.inactive { opacity: .55; }
.edit-row { background: var(--bg); }

/* badges & status colors */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; color: #fff; white-space: nowrap; }
.badge.met { background: var(--met); } .badge.miss1 { background: var(--miss1); } .badge.miss2 { background: var(--miss2); }
.badge.pending { background: var(--pending); } .badge.future { background: #8a94a0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }

/* challenge grid */
.board-head > div { min-width: 0; }
.board-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.daybox { background: var(--brand); color: #fff; border-radius: var(--radius); padding: 12px 20px; text-align: center; min-width: 110px; margin-top: 14px; }
.daybox b { display: block; font-size: 1.5rem; } .daybox span { font-size: .9rem; opacity: .9; }
table.grid { width: auto; border-collapse: separate; border-spacing: 4px; }
table.grid th, table.grid td { border: 0; padding: 0; }
table.grid thead th { text-transform: none; letter-spacing: 0; font-size: .74rem; text-align: center; padding: 0 2px 4px; }
table.grid thead th a { color: var(--muted); text-decoration: none; display: block; line-height: 1.25; }
table.grid thead th a span { display: block; }
table.grid thead th .dn { color: var(--ink); font-weight: 700; }
table.grid thead th.is-today a { color: var(--brand); } table.grid thead th.is-today .dn { color: var(--brand); }
table.grid th.sticky { position: sticky; left: 0; background: var(--card); z-index: 1; padding-right: 10px; white-space: nowrap; font-size: .92rem; text-align: left; }
table.grid td.num { padding: 0 8px; }
td.cell { width: 50px; min-width: 50px; height: 40px; text-align: center; border-radius: 7px; font-size: .78rem; font-weight: 700; color: #fff; cursor: default; font-variant-numeric: tabular-nums; }
td.cell.met { background: var(--met); } td.cell.miss1 { background: var(--miss1); } td.cell.miss2 { background: var(--miss2); }
td.cell.pending { background: var(--pending); } td.cell.future { background: var(--future); color: var(--muted); }
td.cell.sel { outline: 3px solid var(--ink); outline-offset: 1px; }
td.cell:focus { outline: 3px solid var(--brand); }
.cells { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
span.cell { width: 30px; height: 30px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 700; color: #fff; }
span.cell.met { background: var(--met); } span.cell.miss1 { background: var(--miss1); } span.cell.miss2 { background: var(--miss2); }
span.cell.pending { background: var(--pending); } span.cell.future { background: var(--future); color: var(--muted); }
.mini-board { border-top: 1px solid var(--line); padding: 12px 0; }
.mini-board:first-of-type { border-top: 0; }
.cell-tip { position: fixed; left: 16px; right: 16px; bottom: 16px; background: var(--ink); color: var(--bg); padding: 12px 14px; border-radius: 10px; white-space: pre-line; font-size: .9rem; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; z-index: 10; max-width: 420px; margin: 0 auto; }
.cell-tip.show { opacity: 1; transform: none; }

/* charts */
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 340px; }

/* upload */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.tab { padding: 10px 16px; border-radius: 10px 10px 0 0; border: 1px solid var(--line); border-bottom: 0; background: var(--bg); font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); }
.tab.on { background: var(--card); color: var(--brand); }
.tabs + .card { margin-top: 0; border-top-left-radius: 0; }
.steps-list li { margin-bottom: 4px; }
.progress .bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress .bar span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }

.foot { color: var(--muted); font-size: .85rem; padding: 20px 0 30px; border-top: 1px solid var(--line); }
@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 14px; }
  .board-head { flex-direction: column; }
  .daybox { margin-top: 0; }
  .stat b { font-size: 1.4rem; }
  .legend { font-size: .78rem; }
}

/* invite rows */
.invite-row { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.3fr); gap: 0 12px; }
.invites legend { font-weight: 600; font-size: .9rem; }
.invites .btn { margin: 0 12px 10px 0; }
@media (max-width: 600px) { .invite-row { grid-template-columns: minmax(0,1fr); border-bottom: 1px dashed var(--line); margin-bottom: 8px; } }

/* challenges list & group report */
.section-title { margin: 26px 0 4px; font-size: 1.2rem; }
.challenge-card h2 { margin: 6px 0 2px; }
.challenge-card h2 a { color: inherit; text-decoration: none; }
.my-result { background: var(--pending-bg); border-radius: 10px; padding: 10px 16px; text-align: right; }
.my-result span, .my-result small { display: block; font-size: .8rem; color: var(--muted); }
.my-result b { font-size: 1.2rem; }
table.compact th, table.compact td { padding: 6px 8px; }
.filter .full-row { width: 100%; margin: 0; }
.nowrap { white-space: nowrap; }
