:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #5d6470;
  --line: #dde1e7;
  --brand: #1f2a44;
  --accent: #c8102e;
  --accent-soft: #fdecee;
  --ok: #1f7a4d;
  --warn: #9a6200;
  --warn-soft: #fff6e0;
  --bad: #b3261e;
  --bad-soft: #fdeceb;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--brand); }
button, input, select { font: inherit; }

.topbar {
  background: var(--brand); color: #fff;
  padding: 10px 14px calc(10px) 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  position: sticky; top: 0; z-index: 30;
}
.topbar-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.topbar h1 { font-size: 17px; margin: 0; line-height: 1.2; }
.topbar .sub { font-size: 12px; opacity: .8; margin-top: 2px; }
.topbar a, .topbar button.link { color: #fff; font-size: 14px; }
.topbar-actions { display: flex; gap: 12px; align-items: center; white-space: nowrap; }

button.link { background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 600; min-height: 44px;
}
.btn.secondary { background: #fff; color: var(--brand); }
.btn.danger { background: var(--bad); border-color: var(--bad); }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 14px; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type=text], input[type=password], input[type=search] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px;
}

.search { position: relative; margin-top: 10px; }
.search input { border: 0; }
.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; color: var(--ink);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-height: 60vh; overflow: auto; z-index: 40;
}
.results button {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px 14px;
  border-bottom: 1px solid var(--line); cursor: pointer; font-size: 16px;
}
.results button:hover, .results button:focus { background: var(--bg); outline: none; }
.results .empty { padding: 12px 14px; color: var(--muted); }

/* ---- Grid ---- */
.grid-wrap {
  overflow: auto; background: var(--card);
  height: calc(100vh - var(--top-h, 120px)); height: calc(100dvh - var(--top-h, 120px));
  -webkit-overflow-scrolling: touch;
}
table.grid { border-collapse: separate; border-spacing: 0; font-size: 15px; min-width: 100%; }
.grid th, .grid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; }
.grid thead th {
  position: sticky; top: 0; background: #e9ecf2; z-index: 3; padding: 8px 4px; font-size: 14px; min-width: 46px;
}
.grid thead th.corner { left: 0; z-index: 4; text-align: left; padding-left: 10px; font-weight: 600; }
.grid tbody th {
  position: sticky; left: 0; background: #fff; z-index: 2; text-align: left; padding: 6px 10px; white-space: nowrap;
  font-weight: 600; font-size: 14px; min-width: 92px;
}
.grid tbody th small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.grid td { padding: 0; }
.grid td button {
  width: 100%; min-height: 46px; border: 0; background: none; cursor: pointer; font-size: 16px; font-weight: 600; color: var(--ink);
}
.grid td button:hover { background: var(--bg); }
.grid td.zero button { color: #b8bdc6; font-weight: 400; }
.grid tr.is-current th { background: var(--accent); color: #fff; }
.grid tr.is-current th small { color: #fff; opacity: .9; }
.grid tr.is-current td { background: var(--accent-soft); }
.grid tr.is-past th, .grid tr.is-past td button { opacity: .6; }
.today-btn { margin-left: auto; }

/* ---- Sheets ---- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 88vh;
  border-radius: 16px 16px 0 0; background: var(--card); color: var(--ink);
}
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 16px; } }
dialog.sheet::backdrop { background: rgba(10, 14, 24, .45); }
.sheet-head {
  position: sticky; top: 0; background: var(--card); display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); z-index: 1;
}
.sheet-head h2 { font-size: 18px; margin: 0; flex: 1; }
.sheet-head .back, .sheet-head .close { border: 0; background: var(--bg); border-radius: 999px; width: 36px; height: 36px; font-size: 20px; cursor: pointer; }
.sheet-body { padding: 12px 16px 24px; overflow: auto; }
.sheet-body p { margin: 4px 0 12px; }

ul.names { list-style: none; margin: 0; padding: 0; }
ul.names li button {
  display: flex; justify-content: space-between; width: 100%; border: 0; background: none; text-align: left;
  padding: 13px 4px; border-bottom: 1px solid var(--line); font-size: 16px; cursor: pointer; color: var(--ink);
}
ul.names li button span.w { color: var(--muted); font-variant-numeric: tabular-nums; }
ul.names li button:hover { background: var(--bg); }

/* ---- Plan ---- */
.plan h3 { font-size: 15px; margin: 18px 0 8px; }
.now { background: var(--brand); color: #fff; border-radius: var(--radius); padding: 14px 16px; }
.now-label { font-size: 13px; opacity: .85; }
.now-main { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 4px; }
.now .big { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.now .unit { opacity: .85; }
.now-classes { font-size: 16px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 0; }
.facts div { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; }
.tbl tr.is-current td { background: var(--accent-soft); font-weight: 600; }
.muted { color: var(--muted); font-size: 14px; }

/* ---- Pages ---- */
.page { max-width: 760px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card h2 { font-size: 18px; margin: 0 0 8px; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.msg { padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.msg.ok { background: #e7f5ee; color: var(--ok); }
.msg.bad { background: var(--bad-soft); color: var(--bad); }
.msg.warn { background: var(--warn-soft); color: var(--warn); }
.hidden { display: none !important; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress div { height: 100%; background: var(--brand); width: 0; transition: width .1s; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.summary div { background: var(--bg); border-radius: 10px; padding: 10px; }
.summary strong { display: block; font-size: 24px; }
.summary span { font-size: 13px; color: var(--muted); }
ul.issues { margin: 6px 0; padding-left: 20px; font-size: 14px; }
.links-list .item { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.links-list .item .nm { flex: 1; min-width: 160px; }
.links-list .item .nm small { display: block; color: var(--muted); }

.login { max-width: 380px; margin: 12vh auto 0; padding: 16px; }
.login h1 { font-size: 22px; margin: 0 0 4px; }
.center-msg { text-align: center; padding: 40px 16px; color: var(--muted); }
details.card summary { cursor: pointer; }
details.card[open] summary { margin-bottom: 10px; }

/* ---- Tabs, roster, status ---- */
.tabs { display: flex; gap: 6px; margin-top: 10px; }
.tabs button {
  flex: 1; border: 0; border-radius: 10px; padding: 9px 0; font-weight: 600; cursor: pointer;
  background: rgba(255,255,255,.12); color: #fff; min-height: 40px;
}
.tabs button[aria-selected="true"] { background: #fff; color: var(--brand); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 12px 12px 4px; -webkit-overflow-scrolling: touch; }
.chips button {
  flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 12px;
  font-size: 14px; cursor: pointer; white-space: nowrap; color: var(--ink);
}
.chips button[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.roster { padding: 4px 12px 40px; }
.roster .count { font-size: 13px; color: var(--muted); margin: 6px 4px; }
.roster ul.names { background: #fff; border-radius: var(--radius); padding: 0 12px; }
.badge { display: inline-block; font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.flag { margin-left: 4px; }
ul.names li button .right { display: flex; gap: 10px; align-items: center; color: var(--muted); font-variant-numeric: tabular-nums; }
ul.names li button .sub2 { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.overdue { color: var(--bad) !important; font-weight: 600; }

.review { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.review .st { font-size: 17px; font-weight: 700; }
.review .meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.review .changed { margin-top: 8px; }
.review-form { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.choices { display: grid; gap: 8px; }
.choices label {
  display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer;
}
.choices label:has(input:checked) { border-color: var(--brand); background: #eef1f7; }
.choices input { width: 18px; height: 18px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.fields label { font-size: 13px; color: var(--muted); display: grid; gap: 4px; }
.fields select, .fields input, .review-form textarea {
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 16px; background: #fff; width: 100%;
}
.review-form textarea { margin-top: 10px; min-height: 60px; resize: vertical; }
