:root {
  --blue: #1d4486;
  --blue-dark: #142f5f;
  --blue-soft: #e8eef8;
  --red: #b01e2e;
  --red-soft: #fbe9eb;
  --gold: #f2c230;
  --gold-soft: #fdf6dc;
  --orange: #c45a17;
  --orange-soft: #fcebdf;
  --green: #2f7d4f;
  --green-soft: #e6f3eb;
  --ink: #1b2233;
  --muted: #5a6478;
  --line: #dfe4ee;
  --bg: #f6f8fc;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 47, 95, .06), 0 4px 14px rgba(20, 47, 95, .07);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: "Nunito Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 16px; line-height: 1.45; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { font-family: "Fredoka", "Nunito Sans", sans-serif; line-height: 1.15; margin: 0; color: var(--blue-dark); }
h2 { font-size: 1.6rem; margin: 18px 0 6px; }
h3 { font-size: 1.15rem; font-weight: 600; }
.h3 { margin: 22px 0 4px; }
a { color: var(--blue); font-weight: 700; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; top: 8px; background: #fff; padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.lede { color: var(--muted); margin: 0 0 14px; max-width: 46em; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 40; background: var(--blue); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.top-row { display: flex; align-items: center; gap: 10px; padding-top: 8px; padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; min-width: 0; }
.brand img { width: 36px; height: 36px; }
.brand b { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 1.15rem; display: block; line-height: 1.1; }
.brand small { display: block; font-size: .78rem; color: #c9d5ea; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved { margin-left: auto; font-size: .78rem; color: #c9d5ea; font-weight: 700; white-space: nowrap; }
.saved.err { color: #ffd2d6; }
.progress { padding-bottom: 8px; }
.progress-text { display: flex; justify-content: space-between; gap: 10px; font-size: .85rem; font-weight: 700; margin-bottom: 4px; }
.progress-text #prog-pct { color: var(--gold); white-space: nowrap; }
.bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.18); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--gold); border-radius: 99px; transition: width .3s; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  display: flex; align-items: center; gap: 6px; color: #dbe5f6; text-decoration: none; font-weight: 700; font-size: .9rem;
  padding: 10px 12px 11px; border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs a svg { width: 18px; height: 18px; }
.tabs a[aria-current="page"] { color: #fff; border-bottom-color: var(--gold); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; cursor: pointer;
  background: var(--blue); color: #fff; font: inherit; font-weight: 800; font-size: .92rem; padding: 10px 14px;
  border-radius: 10px; border: 0; min-height: 44px;
}
.btn:hover { background: var(--blue-dark); color: #fff; }
.btn.alt { background: var(--blue-soft); color: var(--blue); }
.btn.alt:hover { background: #d6e1f3; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.danger:hover { background: #f6d3d7; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: .85rem; }
.btn.file { position: relative; overflow: hidden; }
.btn.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.icon-btn { background: transparent; border: 0; cursor: pointer; padding: 8px; border-radius: 10px; color: var(--muted); display: inline-grid; place-items: center; min-width: 40px; min-height: 40px; }
.icon-btn:hover { background: var(--blue-soft); color: var(--blue); }
input, select, textarea { font: inherit; color: var(--ink); }
input[type="text"], input[type="search"], input[type="number"], input:not([type]), select, textarea {
  border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; min-height: 40px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,68,134,.15); }
input.bad { border-color: var(--red); background: var(--red-soft); }
input.manual { border-color: var(--orange); background: #fffaf6; font-weight: 800; }
input::placeholder { color: #8f98aa; }
textarea { min-height: 80px; resize: vertical; }

.toolbar { display: flex; gap: 10px; margin: 14px 0 10px; }
.search { position: relative; flex: 1; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; min-height: 44px; }

.seg { display: flex; gap: 4px; background: #fff; border-radius: 12px; padding: 4px; box-shadow: var(--shadow); overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1; border: 0; background: transparent; cursor: pointer; font: inherit; font-weight: 800; font-size: .88rem;
  color: var(--muted); padding: 8px 10px; border-radius: 9px; white-space: nowrap; min-height: 40px;
}
.seg button[aria-pressed="true"] { background: var(--blue); color: #fff; }
.seg button .n { font-weight: 700; opacity: .75; margin-left: 3px; }
.seg.small { box-shadow: none; border: 1.5px solid var(--line); }
.seg.small button { min-height: 34px; padding: 5px 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin: 10px 0 6px; }
.sel { display: flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 700; color: var(--muted); }
.sel select { min-height: 36px; padding: 4px 8px; width: auto; max-width: 170px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: .88rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.chk input { width: 18px; height: 18px; }

/* ---------- list ---------- */
.list { margin-top: 8px; }
.group { margin-bottom: 12px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.group > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: var(--blue-soft); font-family: "Fredoka", sans-serif; font-weight: 600; color: var(--blue-dark); font-size: 1.05rem;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary .chev { transition: transform .2s; color: var(--blue); }
.group[open] > summary .chev { transform: rotate(90deg); }
.group > summary .meta { margin-left: auto; font-family: "Nunito Sans", sans-serif; font-size: .82rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.group > summary .done-all { color: var(--green); }

.row { display: flex; align-items: stretch; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.check { display: grid; place-items: center; width: 60px; flex-shrink: 0; cursor: pointer; }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check .box {
  width: 32px; height: 32px; border-radius: 9px; border: 2.5px solid #9aa6bd; background: #fff; display: grid; place-items: center; transition: all .15s;
}
.check .box svg { width: 20px; height: 20px; stroke-width: 3; color: #fff; opacity: 0; }
.check input:checked + .box { background: var(--green); border-color: var(--green); }
.check input:checked + .box svg { opacity: 1; }
.check input:focus-visible + .box { box-shadow: 0 0 0 3px rgba(29,68,134,.3); }
.row-main {
  flex: 1; min-width: 0; text-align: left; background: transparent; border: 0; cursor: pointer; font: inherit; color: inherit;
  padding: 11px 12px 11px 0; display: grid; grid-template-columns: 1fr; gap: 3px;
}
.row-main:hover .nm { color: var(--blue); }
.nm { font-weight: 800; font-size: 1rem; }
.portion { font-size: .86rem; color: var(--ink); background: var(--bg); border-radius: 8px; padding: 4px 8px; justify-self: start; }
.portion b { color: var(--blue-dark); }
.qty { font-size: .95rem; }
.qty b { font-size: 1.05rem; color: var(--blue-dark); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { font-size: .72rem; font-weight: 800; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.warn { background: var(--gold-soft); color: #7d5d00; border-color: #f0dc95; }
.chip.manual { background: var(--orange-soft); color: var(--orange); border-color: #f3cdb1; }
.note-prev { font-size: .85rem; color: var(--muted); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row.done { background: #f7faf8; }
.row.done .nm { text-decoration: line-through; text-decoration-thickness: 2px; color: var(--muted); }
.row.done .qty, .row.done .portion { opacity: .6; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- cards / attendance ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card > h3 { margin-bottom: 4px; }
.days { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.day h3 { margin-bottom: 10px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 3px; }
.field > span { font-size: .78rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.field.wide { grid-column: 1 / -1; }
.field .hint { font-size: .78rem; color: var(--muted); }
.field .hint.warn { color: #8a6500; }
.meals { display: grid; gap: 8px; }
.meal-row { display: grid; grid-template-columns: 1fr 120px; gap: 6px 12px; align-items: center; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; }
.meal-row .mn { font-weight: 800; }
.meal-row .mm { grid-column: 1 / -1; font-size: .85rem; color: var(--muted); }
.meal-row .field > span { font-size: .7rem; }
.cov { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 8px; }
.cov b { display: block; }
.cov ul { margin: 6px 0 0; padding-left: 18px; font-size: .9rem; }
.cov .gap { color: var(--red); font-weight: 700; }

table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th, table.t td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.t th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.t td.n, table.t th.n { text-align: right; white-space: nowrap; }
table.t tr:last-child td { border-bottom: 0; }
table.t tfoot td { font-weight: 800; border-top: 2px solid var(--line); }
.tscroll { overflow-x: auto; }
.import-result { margin-top: 12px; font-size: .9rem; background: var(--bg); border-radius: 10px; padding: 10px 12px; }

/* ---------- editor dialog ---------- */
dialog#editor {
  border: 0; padding: 0; border-radius: 18px; width: min(760px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  box-shadow: 0 20px 60px rgba(0,0,0,.3); background: var(--bg); color: var(--ink); overflow: hidden;
}
dialog#editor[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(20, 30, 50, .5); }
@media (max-width: 640px) {
  dialog#editor { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
}
.ed-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 18px; background: #fff; border-bottom: 1px solid var(--line); }
.ed-head h2 { margin: 0; font-size: 1.25rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-body { overflow-y: auto; padding: 14px 14px calc(24px + env(safe-area-inset-bottom)); }
.ed-sec { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.ed-sec > h3 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.ed-sec > h3 .sub { margin-left: auto; font-family: "Nunito Sans", sans-serif; font-size: .8rem; font-weight: 700; color: var(--muted); }
.ed-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.ed-check { display: flex; align-items: center; gap: 10px; font-weight: 800; cursor: pointer; margin-bottom: 12px; }
.ed-check input { width: 26px; height: 26px; accent-color: var(--green); }
.badge { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 99px; vertical-align: 1px; }
.badge.auto { background: var(--blue-soft); color: var(--blue); }
.badge.manual { background: var(--orange); color: #fff; }
.with-reset { display: flex; gap: 4px; }
.with-reset button { flex-shrink: 0; border: 0; background: var(--orange-soft); color: var(--orange); border-radius: 10px; cursor: pointer; font-weight: 800; padding: 0 10px; font: inherit; font-size: .8rem; }
.uses { display: grid; gap: 8px; }
.use { border: 1.5px solid var(--line); border-radius: 12px; padding: 10px; display: grid; grid-template-columns: 1.3fr 1fr .7fr .8fr .8fr auto; gap: 8px; align-items: end; }
.use .field > span { font-size: .68rem; }
.use .sub { grid-column: 1 / -1; font-size: .85rem; color: var(--muted); }
.use .sub b { color: var(--blue-dark); }
@media (max-width: 640px) { .use { grid-template-columns: 1fr 1fr; } .use .rm { grid-column: 2; justify-self: end; } }
.math { background: var(--blue-soft); border-radius: 12px; padding: 12px 14px; font-size: .9rem; margin-top: 12px; }
.math div { padding: 2px 0; }
.math .res { font-weight: 800; color: var(--blue-dark); font-size: 1rem; border-top: 1px solid #cbd8ee; margin-top: 6px; padding-top: 6px; }
.flags { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.flags li { font-size: .88rem; padding: 8px 10px; border-radius: 10px; background: var(--gold-soft); border: 1px solid #f0dc95; }
.flags li.info { background: var(--blue-soft); border-color: #cbd8ee; }
.flags li.asm { background: #fff; border: 1px dashed var(--line); }
.orig { font-size: .82rem; color: var(--muted); margin-top: 8px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; border-radius: 12px; padding: 10px 10px 10px 16px; display: flex; gap: 12px; align-items: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: calc(100vw - 32px); font-weight: 700; font-size: .92rem;
}
.toast button { background: var(--gold); color: var(--ink); border: 0; border-radius: 8px; padding: 8px 12px; font: inherit; font-weight: 800; cursor: pointer; }

/* ---------- print ---------- */
.print-only { display: none; }
@media print {
  body > *:not(#print) { display: none !important; }
  #print { display: block !important; color: #000; font-size: 11pt; }
  #print h1 { font-size: 16pt; margin: 0 0 2pt; color: #000; }
  #print h2 { font-size: 12.5pt; margin: 12pt 0 4pt; color: #000; border-bottom: 1.5pt solid #000; padding-bottom: 2pt; }
  #print .p-sub { font-size: 9pt; color: #444; margin-bottom: 6pt; }
  #print table { width: 100%; border-collapse: collapse; }
  #print td, #print th { border-bottom: .5pt solid #bbb; padding: 4pt 4pt; text-align: left; vertical-align: top; }
  #print th { font-size: 8.5pt; text-transform: uppercase; }
  #print td.b { width: 16pt; } #print td.b span { display: inline-block; width: 11pt; height: 11pt; border: 1pt solid #000; }
  #print tr.done td { color: #777; text-decoration: line-through; }
  #print td.n { white-space: nowrap; text-align: right; }
  #print .nt { font-size: 9pt; color: #333; font-style: italic; }
  #print td.pt { font-size: 9pt; color: #333; }
  #print tr { page-break-inside: avoid; }
}
