/* Mobile first, high contrast, large touch targets (usable with gloves). */
:root {
  --ink: #0d1b24;
  --ink-soft: #3a4d5a;
  --paper: #ffffff;
  --panel: #eef3f6;
  --line: #9fb3c0;
  --brand: #0b3d5c;
  --brand-ink: #ffffff;
  --accent: #0a6ebd;
  --ok: #11672f;
  --ok-bg: #d9f2e1;
  --warn: #7a4a00;
  --warn-bg: #ffecc2;
  --bad: #a1121f;
  --bad-bg: #fde0e2;
  --wait: #4b3a8f;
  --wait-bg: #e6e1fa;
  --unsent: #5c3d00;
  --unsent-bg: #fff3c4;
  --tap: 60px;
  --radius: 12px;
  font-size: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 4px solid #ffb000; outline-offset: 2px; }
main:focus { outline: none; }   /* focused on screen change, for screen readers */

/* --- top bar (every screen) --- */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  min-height: 64px; padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.bar-title { flex: 1; font-weight: 700; font-size: 1.05rem; overflow: hidden;
             text-overflow: ellipsis; white-space: nowrap; }
.bar-btn {
  min-width: 52px; min-height: 52px; border: 2px solid rgba(255,255,255,.5);
  border-radius: var(--radius); background: transparent; color: inherit;
  font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.net {
  padding: 6px 10px; border-radius: 999px; font-weight: 700; font-size: .85rem;
  white-space: nowrap;
}
.net.online { background: var(--ok-bg); color: var(--ok); }
.net.offline { background: var(--bad-bg); color: var(--bad); }
.net.offline::before { content: "● "; }
.net.online::before { content: "● "; }
.unsent {
  min-width: 44px; padding: 6px 10px; border-radius: 999px; text-align: center;
  font-weight: 700; font-size: .85rem; text-decoration: none;
  background: var(--unsent-bg); color: var(--unsent);
}
.unsent.zero { background: rgba(255,255,255,.15); color: var(--brand-ink); }

.menu {
  position: sticky; top: 64px; z-index: 9; display: grid; gap: 4px;
  padding: 8px; background: var(--brand); border-top: 1px solid rgba(255,255,255,.3);
}
.menu a, .menu button {
  display: flex; align-items: center; min-height: var(--tap); padding: 0 16px;
  border-radius: var(--radius); color: var(--brand-ink); text-decoration: none;
  font-weight: 600; background: rgba(255,255,255,.08); border: 0; text-align: left;
  cursor: pointer;
}

/* --- layout --- */
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 96px; }
h1 { font-size: 1.4rem; margin: 4px 0 12px; }
h2 { font-size: 1.15rem; margin: 20px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--ink-soft); }
.loading { color: var(--ink-soft); }

.banner {
  max-width: 640px; margin: 8px auto 0; padding: 12px 16px;
  border: 2px solid var(--warn); border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn); font-weight: 600;
}
.banner button { margin-top: 8px; }
#banners { padding: 0 16px; }

/* --- big buttons --- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: var(--tap); padding: 12px 16px; margin: 8px 0;
  border: 2px solid var(--brand); border-radius: var(--radius);
  background: var(--paper); color: var(--brand); font-weight: 700;
  font-size: 1.05rem; text-align: center; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.danger.primary { background: var(--bad); color: #fff; }
.btn[disabled], .btn[aria-disabled="true"] {
  border-color: var(--line); color: var(--ink-soft); background: var(--panel);
  cursor: not-allowed;
}
.btn .big { font-size: 1.5rem; }
.tiles { display: grid; gap: 12px; grid-template-columns: 1fr; }
.tiles .btn { min-height: 84px; margin: 0; font-size: 1.15rem; }
@media (min-width: 560px) { .tiles { grid-template-columns: 1fr 1fr; } }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* --- forms --- */
.field { margin: 16px 0; }
.field > label, .field > .label {
  display: block; font-weight: 700; margin-bottom: 6px;
}
select, input[type="date"], input[type="text"], input[type="password"], textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 2px solid var(--ink-soft); border-radius: var(--radius); background: #fff;
}
textarea { min-height: 120px; font-family: ui-monospace, monospace; font-size: .9rem; }
.stepper { display: grid; grid-template-columns: var(--tap) 1fr var(--tap); gap: 8px;
           align-items: center; }
.stepper button {
  min-height: var(--tap); border: 2px solid var(--brand); border-radius: var(--radius);
  background: var(--panel); color: var(--brand); font-size: 1.8rem; font-weight: 700;
  cursor: pointer;
}
.num-wrap { position: relative; }
.num-wrap input.num {
  width: 100%; min-height: var(--tap); text-align: center; font-size: 1.6rem;
  font-weight: 800; border: 2px solid var(--ink-soft); border-radius: var(--radius);
  padding: 0 2.2em 0 .4em; background: #fff;
}
.num-unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
            font-weight: 800; color: var(--ink-soft); pointer-events: none; }
.stepper output {
  text-align: center; font-size: 1.6rem; font-weight: 800; min-height: var(--tap);
  line-height: var(--tap); border: 2px solid var(--line); border-radius: var(--radius);
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  min-height: 48px; min-width: 64px; padding: 0 14px; border-radius: 999px;
  border: 2px solid var(--brand); background: #fff; color: var(--brand);
  font-weight: 700; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--brand); color: #fff; }
.error { color: var(--bad); font-weight: 700; }
.note {
  padding: 12px; border-radius: var(--radius); background: var(--panel);
  border-left: 6px solid var(--accent); margin: 12px 0;
}
.note.warn { border-left-color: var(--warn); background: var(--warn-bg); }
/* Approvals: what counts now and after approval (step 12) */
.effect { margin: 8px 0; padding: 8px 12px; border-radius: var(--radius); background: var(--panel); }
.effect p { margin: 4px 0; }

/* --- item picker and server numbers --- */
input[type="search"] { width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 2px solid var(--ink-soft); border-radius: var(--radius); background: #fff; }
.pick-list { margin-top: 8px; }
.cat { border: 2px solid var(--line); border-radius: var(--radius); margin: 8px 0; padding: 0 8px; }
.cat > summary { min-height: var(--tap); display: flex; align-items: center; font-weight: 700;
                 cursor: pointer; }
.cat .cat { margin-left: 8px; }
.btn.pick { justify-content: flex-start; text-align: left; min-height: 56px; margin: 6px 0; }
.picked { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px;
          border: 2px solid var(--brand); border-radius: var(--radius); }
.picked .btn { width: auto; margin: 0 0 0 auto; min-height: 48px; }
.srv { margin: 10px 0; padding: 10px 12px; border-radius: var(--radius); background: var(--panel); }
.srv .val { font-weight: 800; }
.srv .age { display: block; color: var(--ink-soft); font-size: .9rem; }
.mode { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode .btn { margin: 0; }
.mode .btn[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.alerts { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.alerts li { padding: 10px 12px; border-radius: var(--radius); border: 2px solid var(--bad);
             background: var(--bad-bg); color: var(--bad); font-weight: 700; }

/* --- records --- */
.records { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.rec { border: 2px solid var(--line); border-radius: var(--radius); padding: 12px; }
.rec.is-off { opacity: .75; border-style: dashed; }
.rec-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rec-title { font-weight: 800; flex: 1 1 100%; }
.rec-when { color: var(--ink-soft); font-size: .9rem; }
.rec-actions { display: grid; gap: 0; margin-top: 8px; }
.rec-actions .btn { min-height: 52px; margin: 4px 0; font-size: .95rem; }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .85rem;
  font-weight: 800; border: 2px solid transparent;
}
.b-unsent { background: var(--unsent-bg); color: var(--unsent); border-color: var(--unsent); }
.b-accepted { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.b-pending { background: var(--wait-bg); color: var(--wait); border-color: var(--wait); }
.b-rejected { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.b-flagged { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.b-off { background: var(--panel); color: var(--ink-soft); border-color: var(--line); }
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.filters .chip { display: inline-flex; align-items: center; text-decoration: none;
                 white-space: nowrap; flex: 0 0 auto; }

dl.kv { display: grid; grid-template-columns: minmax(0, 42%) 1fr; gap: 6px 12px;
        margin: 8px 0; }
dl.kv dd.id { font-weight: 400; font-size: .85rem; word-break: break-all; }
dl.kv dt { color: var(--ink-soft); }
dl.kv dd { margin: 0; font-weight: 700; word-break: break-word; }

/* --- toast and modal --- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 14px 18px; border-radius: var(--radius);
  background: var(--ink); color: #fff; font-weight: 700; opacity: 0;
  pointer-events: none; transition: opacity .2s; z-index: 30;
}
#toast.show { opacity: 1; }
#modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: end center;
  background: rgba(0,0,0,.55); padding: 16px;
}
#modal[hidden] { display: none; }
.dialog {
  width: 100%; max-width: 520px; background: #fff; border-radius: var(--radius);
  padding: 20px 16px 8px;
}
@media (min-width: 560px) { #modal { place-items: center; } }

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f2f6f8; --ink-soft: #b7c7d1; --paper: #0e1418; --panel: #1b252c;
    --line: #4d6270; --brand: #0b3d5c; --accent: #5fb2ff;
  }
  select, input[type="date"], input[type="text"], input[type="password"], textarea,
  .chip, .stepper output, .dialog, .btn:not(.primary) { background: #121b21; }
  .btn:not(.primary), .chip, .stepper button { color: #d6ecff; border-color: #6fa8d6; }
}
.alerts .min { font-weight: 400; }
#alerts { margin-bottom: 20px; }
/* Top bar (step 6): back, online/offline, unsent counter, menu. Nothing
   shrinks or is truncated down to 360 px. */
.bar { gap: 6px; padding-left: 8px; padding-right: 8px; }
.bar .net { margin-left: auto; }
.bar .net, .bar .unsent { flex: 0 0 auto; font-size: .8rem; padding: 6px 8px;
                          white-space: nowrap; }
.bar .unsent { display: inline-grid; justify-items: center; line-height: 1.1;
               padding: 4px 10px; border-radius: 14px; }
.bar .unsent b { font-size: 1rem; }
.bar .unsent span { font-size: .7rem; font-weight: 700; }
.bar .bar-btn { flex: 0 0 auto; min-width: 48px; min-height: 48px; }

/* --- save confirmation (step 6) --- */
/* In the page flow under the top bar: it never covers what is underneath. */
.saved {
  max-width: 608px; margin: 12px auto 0; display: flex; align-items: center; gap: 12px;
  padding: 12px 8px 12px 16px; border-radius: var(--radius); border: 3px solid;
  font-size: 1.05rem;
}
#saved { margin-left: max(16px, calc((100% - 608px) / 2));
         margin-right: max(16px, calc((100% - 608px) / 2)); }
.saved[hidden] { display: none; }
.saved.sent { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.saved.queued, .saved.sending { background: var(--unsent-bg); color: var(--unsent); border-color: var(--unsent); }
.saved.rejected { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.saved-icon { font-size: 1.6rem; font-weight: 900; }
.saved-text { flex: 1; display: grid; gap: 2px; }
.saved-extra { font-size: .9rem; }
.saved-close { min-width: 44px; min-height: 44px; border: 0; background: transparent;
               color: inherit; font-size: 1.3rem; cursor: pointer; }

/* --- field rejected by the server (step 6) --- */
.invalid { border-color: var(--bad) !important; box-shadow: 0 0 0 4px var(--bad-bg); }
.picker.invalid, div.invalid { border: 3px solid var(--bad); border-radius: var(--radius); padding: 6px; }
.field-error { color: var(--bad); font-weight: 700; margin: 6px 0 0; }

/* --- record cards: actions behind a tap (step 6) --- */
.rec-toggle, .rec-summary { display: grid; gap: 6px; width: 100%; text-align: left;
  background: transparent; border: 0; padding: 0; color: inherit; font: inherit; }
.rec-toggle { cursor: pointer; min-height: var(--tap); }
.rec-toggle .rec-title, .rec-summary .rec-title { flex: none; }
.rec-head { display: flex; flex-wrap: wrap; gap: 6px; }
.rec-more { justify-self: end; font-weight: 700; color: var(--accent); }
.rec-more::after { content: " ▾"; }
.rec-toggle[aria-expanded="true"] .rec-more::after { content: " ▴"; }

/* --- filter chips: fade at the right edge while more chips are hidden --- */
.filters-wrap { position: relative; }
.filters-wrap.more-right::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 6px; width: 56px;
  background: linear-gradient(to right, rgba(255,255,255,0), var(--paper));
  pointer-events: none;
}

/* --- approvals (step 6) --- */
.reject-form { margin-top: 8px; padding-top: 8px; border-top: 2px solid var(--line); }
.reject-form textarea { min-height: 80px; font-family: inherit; font-size: 1rem; margin-top: 8px; }
#approvals .badge { display: inline-block; }

/* --- login: people on this device (platform pass) --- */
.btn.account { justify-content: flex-start; text-align: left; flex-wrap: wrap; }
.account-meta { font-weight: 400; }
#new-user { margin-top: 16px; }
#new-user form { padding-bottom: 8px; }

/* --- tablets and desktop (platform pass) --------------------------------- */
@media (hover: hover) {
  .btn:not([disabled]):not([aria-disabled="true"]):hover { filter: brightness(1.12); }
  .btn:not(.primary):not([disabled]):hover { background: var(--panel); }
  .chip:hover, .rec-toggle:hover .rec-more { text-decoration: underline; }
}
:focus-visible { outline: 4px solid #ffb000; outline-offset: 2px; }
form > div:empty { display: none; }

/* Tablet portrait and up: wider column, roomier tiles. */
@media (min-width: 768px) {
  main { max-width: 760px; padding-left: 24px; padding-right: 24px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .banner, .saved { max-width: 712px; }
  #saved { margin-left: max(24px, calc((100% - 712px) / 2));
           margin-right: max(24px, calc((100% - 712px) / 2)); }
}

/* Tablet landscape and desktop: two columns where it helps. */
@media (min-width: 1024px) {
  main { max-width: 1120px; }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  main > form, main > .form-host > form {
    display: grid; grid-template-columns: 1fr 1fr; column-gap: 32px; align-items: start;
  }
  main > form > .btn, main > form > [role="alert"], main > form > .note { grid-column: 1 / -1; }
  main > form > .btn { justify-self: start; width: auto; min-width: 280px; }
  .records { grid-template-columns: 1fr 1fr; align-items: start; }
  #alerts .alerts { grid-template-columns: repeat(3, 1fr); }
  .banner, .saved { max-width: 1072px; }
  #saved { margin-left: max(24px, calc((100% - 1072px) / 2));
           margin-right: max(24px, calc((100% - 1072px) / 2)); }
  .menu { position: fixed; top: 64px; right: 8px; width: 360px; border-radius: 0 0 12px 12px;
          box-shadow: 0 8px 24px rgba(0,0,0,.3); }
}

/* --- supervisor home: low stock as one collapsed line (step 7) --- */
.alerts-line { margin: 16px 0; border: 2px solid var(--line); border-radius: var(--radius);
               padding: 0 12px; }
.alerts-line > summary { min-height: var(--tap); display: flex; align-items: center;
                         font-weight: 800; font-size: 1.1rem; cursor: pointer; }
.alerts-line.has-alerts { border-color: var(--bad); background: var(--bad-bg); }
.alerts-line.has-alerts > summary { color: var(--bad); }
.alerts-line[open] { padding-bottom: 12px; }
#alerts { margin-bottom: 16px; }

/* --- quick switch with PIN (step 7) --- */
.account-row { margin: 8px 0; }
.account-row .btn.account { margin: 0; }
.account-pin { padding: 12px; border: 2px solid var(--brand); border-top: 0;
               border-radius: 0 0 var(--radius) var(--radius); }
.account-pin label { display: block; font-weight: 700; margin-bottom: 6px; }
input.pin { width: 100%; min-height: var(--tap); font-size: 1.6rem; letter-spacing: .4em;
            text-align: center; border: 2px solid var(--ink-soft); border-radius: var(--radius); }

/* --- admin screens (step 9) --- */
.home-group { margin: 20px 0; }
.home-group h2 { margin-bottom: 8px; }
.check-label { display: flex; align-items: center; gap: 12px; min-height: var(--tap); font-weight: 700; }
input.check { width: 28px; height: 28px; }
.key-card .key { font-family: ui-monospace, monospace; font-size: 1rem; word-break: break-all;
                 background: #fff; color: var(--ink); padding: 10px; border-radius: 8px; }
.count-row { border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; }
.count-entry { display: flex; align-items: center; gap: 10px; }
.count-entry input { width: 50%; min-height: var(--tap); font-size: 1.4rem; font-weight: 800;
                     text-align: center; border: 2px solid var(--ink-soft); border-radius: var(--radius); }
.count-entry .unit { font-weight: 800; color: var(--ink-soft); }
.diff { display: block; margin-top: 6px; font-weight: 800; }
.diff.more { color: var(--ok); } .diff.less, .diff.bad { color: var(--bad); }
table.stock, table.errors { width: 100%; border-collapse: collapse; margin: 12px 0; }
table.stock th, table.stock td, table.errors th, table.errors td {
  text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.stock tr.low td { background: var(--bad-bg); color: var(--bad); font-weight: 700; }
.flag-why { color: var(--warn); font-weight: 700; }
input[type="file"] { width: 100%; min-height: var(--tap); padding: 10px; border: 2px dashed var(--line);
                     border-radius: var(--radius); }
#ref-form input[type="text"] { width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 2px solid var(--ink-soft); border-radius: var(--radius); }

/* Stock table on phones: each row stacks, nothing scrolls sideways. */
@media (max-width: 600px) {
  table.stock thead { display: none; }
  table.stock tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.stock td { display: block; border: 0; padding: 2px 8px; }
  table.stock td:nth-child(2) { font-weight: 800; }
  table.stock td:nth-child(3):not(:empty)::before { content: "Минимум: "; font-weight: 400; }
}

/* --- reports (step 10) ----------------------------------------------------- */
.mode.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mode.three .btn { padding-left: 4px; padding-right: 4px; min-width: 0; }
.mode a.btn { text-align: center; text-decoration: none; }
.mode a.btn[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.period-dates { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.period-dates .field { min-width: 0; }
.period-dates input { min-width: 0; width: 100%; box-sizing: border-box; }
.period .chips { margin-bottom: 8px; }
.report-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.report-list .btn { display: flex; flex-direction: column; align-items: flex-start; text-align: left; margin: 0; }
.report-list .btn b { font-size: 1.1rem; }
#report-meta p { margin: 2px 0; }
.xlsx { margin: 8px 0; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0; }
.pager .btn { margin: 0; }
table.report { width: 100%; border-collapse: collapse; margin: 12px 0; }
table.report th, table.report td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left;
  vertical-align: top; overflow-wrap: anywhere; }
table.report .num { text-align: right; white-space: nowrap; }
table.report tfoot td { font-weight: 800; border-top: 2px solid var(--line); }
/* Report tables on phones: each row is a block of "title: value" lines. */
@media (max-width: 700px) {
  table.report thead { display: none; }
  table.report tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  table.report td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 2px 4px;
    text-align: right; white-space: normal; }
  table.report td::before { content: attr(data-label); font-weight: 400; color: var(--ink-soft); text-align: left; }
  table.report td:first-child { font-weight: 800; }
  table.report td:empty { display: none; }
  table.report tfoot tr { border-top: 2px solid var(--line); }
  table.report tfoot td:first-child { display: block; text-align: left; }
  table.report tfoot td:first-child::before { content: none; }
}
/* Tables with many columns stack up to tablet width. */
@media (max-width: 1100px) {
  table.report.many thead { display: none; }
  table.report.many tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  table.report.many td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 2px 4px;
    text-align: right; white-space: normal; }
  table.report.many td::before { content: attr(data-label); font-weight: 400; color: var(--ink-soft); text-align: left; }
  table.report.many td:first-child { font-weight: 800; }
  table.report.many td:empty { display: none; }
  table.report.many tfoot tr { border-top: 2px solid var(--line); }
  table.report.many tfoot td:first-child { display: block; text-align: left; }
  table.report.many tfoot td:first-child::before { content: none; }
}
table.report th, table.report th.num { white-space: normal; }
table.report.many { font-size: 0.85rem; }
table.report.many th, table.report.many td { padding: 4px 4px; }

@media (min-width: 701px) and (max-width: 1100px) {
  table.report { font-size: 0.9rem; }
  table.report th, table.report td { padding: 4px 5px; }
}
#myhours-total .badge { margin-left: 8px; }
.parts { margin: 4px 0; padding-left: 18px; }
.hours-total { float: right; }
