body.m { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; font-size: 15px; background: var(--cream); }
body.m.side-mini { grid-template-columns: 72px minmax(0, 1fr); }

/* Side menu */
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--paper); padding: 18px 12px; }
.side-top { padding: 4px 8px 22px; }
.side .logo { font-size: 22px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: 10px; }
.tab { display: flex; align-items: center; gap: 12px; height: 42px; padding: 0 12px; border: 0; border-radius: 10px; background: none; color: var(--muted); text-decoration: none; cursor: pointer; font-size: 15px; white-space: nowrap; text-align: left; width: 100%; }
.tab svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab:hover { background: var(--cream); color: var(--ink); }
.tab.is-active { background: var(--ink); color: var(--cream); }
.tab .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tab .cnt { font-size: 12px; min-width: 24px; height: 20px; padding: 0 7px; border-radius: 10px; background: var(--cream); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.tab.is-active .cnt { background: rgba(255,255,255,.16); color: var(--cream); }
body.side-mini .side .lbl, body.side-mini .tab .cnt { display: none; }
body.side-mini .tab { justify-content: center; padding: 0; }
body.side-mini .side-top { padding: 4px 0 22px; display: flex; justify-content: center; }
body.side-mini #side-toggle svg { transform: rotate(180deg); }

/* Main */
.mmain { min-width: 0; padding: 0 36px 60px; }
.mtop { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 20px; height: 76px; background: var(--cream); border-bottom: 1px solid var(--line); margin-bottom: 24px; }
.mtop h1 { font-size: 34px; white-space: nowrap; }
.mstatus { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mstatus.ok { color: #2e6b4a; }
.mstatus.bad { color: #b42318; }
.mtools { display: flex; gap: 10px; }
.banner { background: var(--apricot-soft); border-radius: 12px; padding: 14px 18px; margin-bottom: 22px; font-size: 14px; }
.help { color: var(--muted); font-size: 14px; margin: 0 0 18px; max-width: 70em; }
.help code { background: var(--paper); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); cursor: pointer; font-size: 14px; white-space: nowrap; }
.chip span { color: var(--muted); margin-left: 4px; }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: var(--cream); }
.chip.is-on span { color: #b9c0cf; }
.search { height: 38px; width: 320px; max-width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); padding: 0 14px; font-size: 14px; }

/* Grids */
.grid { border-top: 1px solid var(--line); }
.ghead, .mrow { display: grid; align-items: center; gap: 14px; padding: 0 6px; }
.ghead { height: 40px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); }
.ghead span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mrow { min-height: 54px; border-bottom: 1px solid var(--line); }
.mrow:hover { background: rgba(255,255,255,.55); }
.gsub { display: flex; align-items: center; gap: 10px; padding: 18px 6px 8px; font-family: var(--serif); font-size: 20px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.gsub span { font-family: var(--sans); font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; }
.empty { padding: 40px 6px; color: var(--muted); }

.grid.resp .ghead, .grid.resp .mrow { grid-template-columns: 104px minmax(150px, 1.1fr) minmax(130px, 1fr) minmax(160px, 1.4fr) 116px 136px 150px; }
.grid.qs .ghead, .grid.qs .mrow { grid-template-columns: 52px 52px 120px minmax(180px, 2fr) minmax(120px, 1.2fr) 96px minmax(150px, 1.5fr) 40px 36px 72px; gap: 12px; }
.grid.st .ghead, .grid.st .mrow { grid-template-columns: 70px minmax(160px, 1fr) minmax(240px, 2.4fr) 96px 76px; }

.cell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cell.muted { color: var(--muted); }
.cell b { font-weight: 600; }
.mrow.is-new .nm::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--apricot); margin-right: 8px; vertical-align: 2px; }
.mrow.is-archived { color: var(--muted); }

.ml { display: contents; }
.ml > span { display: none; }
.mrow input[type=text], .mrow input[type=number], .mrow select, .mrow textarea, .resp select { width: 100%; min-width: 0; height: 36px; border: 1px solid transparent; border-radius: 8px; background: transparent; padding: 0 8px; font-size: 14px; text-overflow: ellipsis; }
.mrow textarea { resize: none; padding: 8px; line-height: 1.35; height: 36px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.mrow textarea:focus { field-sizing: content; height: auto; min-height: 36px; max-height: 140px; white-space: pre-wrap; overflow: auto; }
.mrow input:hover, .mrow select:hover, .mrow textarea:hover { border-color: var(--line); background: var(--paper); }
.mrow input:focus, .mrow select:focus, .mrow textarea:focus { outline: none; border-color: var(--ink); background: #fff; }
.mrow select { cursor: pointer; }
.mrow .ro, .mrow .ro:hover { pointer-events: none; color: var(--muted); border-color: transparent; background: transparent; }
.mrow input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--ink); justify-self: start; margin: 0 0 0 4px; }
.mrow.saving { background: rgba(239,143,87,.08); }
.mrow .num b { font-weight: 500; padding-left: 8px; }
.acts { display: flex; gap: 6px; justify-content: flex-end; }
.acts button, .rbtn { height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); cursor: pointer; font-size: 13px; white-space: nowrap; }
.acts button:hover, .rbtn:hover { border-color: var(--ink); }
.acts .del.sure { background: #b42318; border-color: #b42318; color: #fff; }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 1px 8px; white-space: nowrap; }
.pill { display: inline-block; max-width: 100%; font-size: 12px; padding: 2px 9px; border-radius: 10px; background: var(--mist); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.pill + .pill { margin-left: 4px; }
.st-sel { height: 34px !important; border: 1px solid var(--line) !important; background: var(--paper) !important; border-radius: 8px; }

/* Charts */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.kpi .k { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.kpi .v { font-family: var(--serif); font-size: 42px; line-height: 1.1; margin-top: 6px; white-space: nowrap; }
.kpi .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; min-width: 0; }
.card.wide { margin-bottom: 14px; }
.card-h { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.card-h h2 { font-size: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.card-h .sub { font-size: 13px; color: var(--muted); white-space: nowrap; }
.weeks { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 10px; align-items: end; height: 190px; }
.wk { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; min-width: 0; }
.wk .b { width: 100%; max-width: 44px; background: var(--ink); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.wk.zero .b { background: var(--mist); }
.wk .n { font-size: 12px; color: var(--muted); }
.wk .d { font-size: 11px; color: var(--muted); white-space: nowrap; }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.hb { display: grid; grid-template-columns: minmax(0, 190px) minmax(0, 1fr) 64px; gap: 12px; align-items: center; padding: 6px 0; font-size: 14px; }
.hb .l { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hb .t { height: 10px; background: var(--mist); border-radius: 5px; overflow: hidden; }
.hb .t i { display: block; height: 100%; background: var(--apricot); border-radius: 5px; }
.hb .c { text-align: right; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.avg { display: flex; align-items: baseline; gap: 10px; margin: -4px 0 10px; }
.avg b { font-family: var(--serif); font-weight: 400; font-size: 34px; }
.avg span { color: var(--muted); font-size: 13px; }

/* Modals */
.modal { width: min(880px, calc(100vw - 40px)); max-height: calc(100vh - 60px); border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--paper); color: var(--ink); box-shadow: 0 30px 80px -30px rgba(38,49,74,.5); }
.modal.small { width: min(560px, calc(100vw - 40px)); }
.modal::backdrop { background: rgba(38,49,74,.42); }
.mhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding: 24px 28px 18px; border-bottom: 1px solid var(--line); }
.mhead h2 { font-size: 30px; }
.mhead .sub { color: var(--muted); font-size: 14px; margin-top: 4px; overflow-wrap: anywhere; }
.x { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; background: none; cursor: pointer; font-size: 20px; line-height: 1; flex: none; }
.mbody { padding: 22px 28px 28px; }
.mfoot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 28px; border-top: 1px solid var(--line); }
.mr-meta { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px; margin-bottom: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
.field > span { white-space: nowrap; }
.field input, .field select, .field textarea { height: 42px; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 0 12px; font-size: 15px; color: var(--ink); width: 100%; }
.field textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 42px; }
.field.check { flex-direction: row; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); }
.field.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.form2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form2 .full { grid-column: 1 / -1; }
.ferr { color: #b42318; font-size: 14px; }
.ans-step { font-family: var(--serif); font-size: 20px; padding: 16px 0 6px; border-bottom: 1px solid var(--line); }
.ans { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 20px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.ans dt { color: var(--muted); }
.ans dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.ans dd.none { color: #a7a29a; }

/* Auto-collapse menu on mid widths so rows fit */
@media (min-width: 1081px) and (max-width: 1380px) {
  body.m { grid-template-columns: 72px minmax(0, 1fr); }
  body.m .side .lbl, body.m .tab .cnt { display: none; }
  body.m .tab { justify-content: center; padding: 0; }
  body.m .side-top { padding: 4px 0 22px; display: flex; justify-content: center; }
  body.m #side-toggle { display: none; }
  .mmain { padding: 0 24px 60px; }
}

/* Tablet and phone: cards */
@media (max-width: 1080px) {
  body.m, body.m.side-mini { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; gap: 8px; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .side-top { padding: 0 6px 0 0; }
  .side .logo .lbl { display: none; }
  .side-nav { flex-direction: row; gap: 4px; }
  .side-foot { display: none; }
  .tab { width: auto; height: 38px; }
  body.m.side-mini .side .lbl, body.m.side-mini .tab .cnt { display: inline; }
  .mmain { padding: 0 20px 48px; }
  .mtop { position: static; height: auto; padding: 18px 0; flex-wrap: wrap; gap: 10px 16px; }
  .mtop h1 { font-size: 28px; }
  .mstatus { order: 3; flex-basis: 100%; }
  .ghead { display: none; }
  .grid { border-top: 0; }
  .mrow, .grid.resp .mrow, .grid.qs .mrow, .grid.st .mrow { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-flow: row dense; gap: 10px 14px; padding: 16px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); }
  .ml { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
  .ml > span { display: block; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
  .ml.wide { grid-column: 1 / -1; }
  .ml.chk { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 8px; }
  .mrow input[type=text], .mrow input[type=number], .mrow select, .mrow textarea { border-color: var(--line); background: #fff; }
  .mrow textarea, .mrow textarea:focus { field-sizing: content; height: auto; min-height: 36px; max-height: 160px; white-space: pre-wrap; overflow: auto; }
  .acts { grid-column: 1 / -1; justify-content: flex-start; }
  .gsub { border-bottom: 0; padding: 18px 2px 10px; }
  .grid.resp .mrow .cell.wide { grid-column: 1 / -1; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .side { padding: 8px 12px; }
  .side-top { display: none; }
  .tab { padding: 0 11px; gap: 6px; font-size: 14px; }
  .tab svg, .tab .cnt, body.m.side-mini .tab .cnt { display: none; }
  .card-h { flex-wrap: wrap; gap: 4px 12px; }
  .card-h h2 { white-space: normal; overflow: visible; }
  .mtools { width: 100%; }
  .search { width: 100%; }
  .weeks { gap: 4px; height: 160px; }
  .wk .d { font-size: 10px; }
  .wk:nth-child(even) .d { visibility: hidden; }
  .hb { grid-template-columns: minmax(0, 1fr) 54px; gap: 4px 10px; }
  .hb .l { grid-column: 1 / -1; }
  .hb .t { grid-column: 1; }
  .mr-meta, .form2, .ans { grid-template-columns: minmax(0, 1fr); }
  .ans { gap: 2px; }
  .mhead, .mbody, .mfoot { padding-left: 18px; padding-right: 18px; }
  .kpi .v { font-size: 34px; }
}
