:root {
  --ground: #F3F4F1;
  --surface: #FFFFFF;
  --soft: #F7F8F5;
  --ink: #16181D;
  --muted: #5F6672;
  --line: #E3E5E0;
  --line-strong: #C9CCC5;
  --seg: #E4E6E1;
  --dir-m: #2B5FD9;
  --dir-p: #E39A2D;
  --dir-r: #3A3F4A;
  --dir-s: #8A9099;
  --good: #1E7F5C;
  --bad: #A23B3B;
  --warn-bg: #FBEFD8;
  --info-bg: #E8EEFC;
  --info-ink: #1F4AB0;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(22, 24, 29, 0.06);
  --tabbar-h: 78px;
  font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: var(--ground);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--ground); }
body { overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--info-ink); }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.bold { font-weight: 700; }
.good { color: var(--good); }
.bad { color: var(--bad); }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.screen { flex: 1; padding: 0 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
.screen.has-footer { padding-bottom: calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom)); }

.topbar { padding: calc(20px + env(safe-area-inset-top)) 4px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.topbar .sub { font-size: 13px; font-weight: 600; color: var(--muted); }
.avatar { width: 40px; height: 40px; border-radius: 20px; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; border: 0; flex-shrink: 0; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.card.dark { background: var(--ink); color: #fff; }
.card h2 { margin: 0; font-size: 17px; font-weight: 800; }
.card .card-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.label-cap { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.section-cap { padding: 8px 4px 0; }

.seg { display: flex; background: var(--seg); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; height: 44px; border: 0; border-radius: 11px; font-size: 15px; font-weight: 700; background: transparent; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(22, 24, 29, 0.12); }
.seg.small button { height: 36px; font-size: 13px; }

.btn { height: 48px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-size: 15px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.ok { background: var(--good); color: #fff; border-color: var(--good); }
.btn.danger { background: #fff; color: var(--bad); border-color: #E4C4C4; }
.btn.small { height: 40px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn.icon { width: 48px; padding: 0; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.recording { background: var(--bad); color: #fff; border-color: var(--bad); }
.linkbtn { background: none; border: 0; padding: 8px 0; color: var(--info-ink); font-weight: 700; font-size: 14px; text-align: left; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip .dot { width: 8px; height: 8px; border-radius: 4px; }
.badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--info-bg); color: var(--info-ink); white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: #6B4A10; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .flabel { font-size: 13px; font-weight: 700; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; min-height: 46px; border: 1px solid var(--line-strong); border-radius: 12px; padding: 10px 12px; font-size: 16px; background: var(--surface); outline: none; }
textarea.input { resize: vertical; line-height: 1.4; }
.input:focus { border-color: var(--ink); }
.field.uncertain .input, .field.uncertain .chips { background: var(--warn-bg); border-radius: 12px; }
.field.uncertain > label::after, .field.uncertain > .flabel::after { content: " — проверьте"; color: #8A5A0B; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--ink); }

.entry-text { border: 0; outline: none; resize: none; font-size: 17px; line-height: 1.45; padding: 0; background: transparent; width: 100%; min-height: 84px; }
.photo-thumb { position: relative; width: 72px; height: 72px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb button { position: absolute; top: 2px; right: 2px; width: 26px; height: 26px; border-radius: 13px; border: 0; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 14px; line-height: 1; }

.question { background: var(--warn-bg); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.question p { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.4; }
.notice { background: var(--info-bg); color: var(--info-ink); border-radius: 12px; padding: 10px 12px; font-size: 13px; font-weight: 600; }
.notice.warn { background: var(--warn-bg); color: #6B4A10; }

.list-item { background: var(--surface); border-radius: 16px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; border: 0; width: 100%; text-align: left; box-shadow: var(--shadow); }
.list-item .t { font-weight: 600; }
.list-item .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.amount-plus { color: var(--good); font-weight: 800; }
.amount-minus { font-weight: 800; }

.items-table { display: flex; flex-direction: column; gap: 8px; }
.item-line { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 36px; grid-template-areas: "name name name x" "qty unit price ."; gap: 6px; align-items: center; padding: 8px; background: var(--soft); border-radius: 12px; }
.item-line > :nth-child(1) { grid-area: name; }
.item-line > :nth-child(2) { grid-area: qty; }
.item-line > :nth-child(3) { grid-area: unit; }
.item-line > :nth-child(4) { grid-area: price; }
.item-line > :nth-child(5) { grid-area: x; }
.item-line .input { min-height: 40px; padding: 8px; font-size: 15px; }
.item-line .x { width: 36px; height: 40px; border: 0; background: none; color: var(--muted); font-size: 22px; }

/* рабочие */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tile { border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.tile .k { font-size: 11px; font-weight: 700; }
.tile .v { font-size: 18px; font-weight: 800; }
.tile.m { background: var(--dir-m); color: #fff; }
.tile.p { background: var(--dir-p); color: var(--ink); }
.tile.r { background: var(--dir-r); color: #fff; }
.tile.n { background: var(--surface); }
.tile.n .k { color: var(--muted); }
.worker { background: var(--surface); border-radius: 18px; padding: 12px 12px 12px 14px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); }
.worker .name { font-size: 16px; font-weight: 700; }
.worker > .row.between { flex-wrap: wrap; }
.worker .daylabel { font-size: 12px; font-weight: 600; color: var(--muted); }
.worker .daylabel.off { color: var(--bad); }
.dirbtns { display: flex; gap: 6px; }
.dirbtn { min-width: 46px; height: 44px; padding: 0 6px; border-radius: 12px; font-size: 15px; font-weight: 800; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); }
.dirbtn.on.M { background: var(--dir-m); border-color: var(--dir-m); color: #fff; }
.dirbtn.on.P { background: var(--dir-p); border-color: var(--dir-p); color: var(--ink); }
.dirbtn.on.R { background: var(--dir-r); border-color: var(--dir-r); color: #fff; }
.worker textarea { min-height: 70px; font-size: 14px; background: var(--soft); border-color: var(--line); }
.worker .halflabel { font-size: 12px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.footer-bar { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 20; }
.footer-bar .inner { max-width: 560px; margin: 0 auto; padding: 10px 16px; background: var(--ground); border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.datenav { display: flex; align-items: center; gap: 2px; background: var(--surface); border-radius: 12px; padding: 4px; }
.datenav button { width: 38px; height: 38px; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; border-radius: 10px; }
.datenav input { border: 0; background: transparent; font-weight: 700; font-size: 14px; width: 128px; text-align: center; }

/* дашборд */
.hero-num { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.kpis .k { font-size: 12px; color: #C3C7CE; }
.kpis .v { font-size: 15px; font-weight: 700; }
.legend-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto 44px; gap: 10px; align-items: center; font-size: 14px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--line); }
.bar span { display: block; height: 100%; }
.dist-row { display: flex; flex-direction: column; gap: 4px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.dist-row:last-of-type { border-bottom: 0; padding-bottom: 0; }
.dist-row .big { font-size: 20px; font-weight: 800; }
.table-rows { display: flex; flex-direction: column; font-size: 14px; }
.table-rows .tr { display: grid; grid-template-columns: minmax(0, 1fr) auto 92px; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: baseline; }
.answer { white-space: pre-wrap; line-height: 1.5; font-size: 15px; background: var(--soft); border-radius: 14px; padding: 12px 14px; }
.chart-box { position: relative; width: 100%; }

/* таббар */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar .inner { max-width: 560px; margin: 0 auto; display: flex; padding: 8px 8px 10px; }
.tabbar button { flex: 1; min-height: 56px; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.tabbar button.on { color: var(--ink); font-weight: 800; }

/* шторка */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(22, 24, 29, 0.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--ground); border-radius: 22px 22px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h3 { margin: 0; font-size: 19px; font-weight: 800; }
.sheet-close { width: 40px; height: 40px; border-radius: 20px; border: 0; background: var(--seg); font-size: 20px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); z-index: 60; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 14px; font-size: 14px; font-weight: 600; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2); }
.toast.err { background: var(--bad); }

.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; gap: 16px; max-width: 420px; margin: 0 auto; }
.login h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }

.admin-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 4px; }
.admin-tabs .chip { flex-shrink: 0; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 14px; }
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; }
.btn:not(.primary):not(.ok) .spinner { border-color: rgba(0, 0, 0, 0.15); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; font-size: 14px; }
.file-chip { display: inline-flex; align-items: center; gap: 10px; max-width: 100%; padding: 8px 8px 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--soft); }
.file-chip .file-badge { font-size: 11px; font-weight: 800; padding: 4px 6px; border-radius: 6px; background: var(--ink); color: #fff; }
.file-chip .file-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file-chip button { width: 28px; height: 28px; border-radius: 14px; border: 0; background: var(--seg); font-size: 16px; flex-shrink: 0; }
