:root {
    --ground: #eef0f2;
    --surface: #ffffff;
    --surface-2: #f7f8f9;
    --ink: #1a1e24;
    --muted: #5c6673;
    --faint: #8a93a0;
    --border: #d9dde2;
    --border-strong: #c3c9d0;
    --accent: #e8720c;
    --accent-ink: #ffffff;
    --accent-soft: #fbead9;
    --proc: #2f6fb0;
    --proc-soft: #e4eef7;
    --ok: #2e7d53;
    --ok-soft: #e2f1e9;
    --warn: #c9750a;
    --warn-soft: #f9ecda;
    --crit: #c62f2f;
    --crit-soft: #f8e3e3;
    --shadow: 0 1px 2px rgba(20,25,35,.05), 0 6px 20px rgba(20,25,35,.06);
    --radius: 9px;
    --field: 36px;
    font-synthesis-weight: none;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --ground: #12151a;
      --surface: #1a1f26;
      --surface-2: #20262e;
      --ink: #e9ecef;
      --muted: #9aa6b2;
      --faint: #6d7883;
      --border: #2b323b;
      --border-strong: #3a424d;
      --accent: #f2861f;
      --accent-ink: #17130d;
      --accent-soft: #34281a;
      --proc: #63a4dd;
      --proc-soft: #1b2a38;
      --ok: #5cbd88;
      --ok-soft: #16281f;
      --warn: #e0a24a;
      --warn-soft: #2e2513;
      --crit: #e8776f;
      --crit-soft: #2f1a1a;
      --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    }
  }
  :root[data-theme="light"] {
    --ground:#eef0f2; --surface:#fff; --surface-2:#f7f8f9; --ink:#1a1e24; --muted:#5c6673; --faint:#8a93a0;
    --border:#d9dde2; --border-strong:#c3c9d0; --accent:#e8720c; --accent-ink:#fff; --accent-soft:#fbead9;
    --proc:#2f6fb0; --proc-soft:#e4eef7; --ok:#2e7d53; --ok-soft:#e2f1e9; --warn:#c9750a; --warn-soft:#f9ecda;
    --crit:#c62f2f; --crit-soft:#f8e3e3; --shadow:0 1px 2px rgba(20,25,35,.05),0 6px 20px rgba(20,25,35,.06);
  }
  :root[data-theme="dark"] {
    --ground:#12151a; --surface:#1a1f26; --surface-2:#20262e; --ink:#e9ecef; --muted:#9aa6b2; --faint:#6d7883;
    --border:#2b323b; --border-strong:#3a424d; --accent:#f2861f; --accent-ink:#17130d; --accent-soft:#34281a;
    --proc:#63a4dd; --proc-soft:#1b2a38; --ok:#5cbd88; --ok-soft:#16281f; --warn:#e0a24a; --warn-soft:#2e2513;
    --crit:#e8776f; --crit-soft:#2f1a1a; --shadow:0 1px 2px rgba(0,0,0,.4),0 8px 24px rgba(0,0,0,.35);
  }

  * { box-sizing: border-box; }
  body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
  }
  .wrap { max-width: 900px; margin: 0 auto; padding: 0 18px 96px; }

  /* Topbar */
  .topbar {
    position: sticky; top: 0; z-index: 20;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
  }
  .topbar-inner { max-width: 900px; margin: 0 auto; padding: 9px 18px; display: flex; align-items: center; gap: 14px; }
  .brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
  .mark {
    width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
    background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 15px;
    letter-spacing: -.02em; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
  }
  .brand b { font-weight: 700; letter-spacing: -.01em; font-size: 15px; display: block; line-height: 1.15; }
  .brand span { color: var(--muted); font-size: 12px; }
  .who { text-align: right; font-size: 12.5px; color: var(--muted); line-height: 1.3; }
  .who b { color: var(--ink); font-weight: 650; }
  .theme-btn {
    width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border);
    background: var(--surface); color: var(--muted); cursor: pointer; font-size: 16px;
    display: grid; place-items: center;
  }
  .theme-btn:hover { border-color: var(--border-strong); color: var(--ink); }

  /* Tabs */
  .tabs { display: flex; gap: 3px; margin: 16px 0 14px; background: var(--surface-2); padding: 3px; border-radius: 9px; border: 1px solid var(--border); width: fit-content; }
  .tab {
    appearance: none; border: 0; background: transparent; color: var(--muted); cursor: pointer;
    font: inherit; font-weight: 600; font-size: 13.5px; padding: 6px 14px; border-radius: 7px;
  }
  .tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

  h1.page { font-size: 19px; font-weight: 750; letter-spacing: -.02em; margin: 0 0 2px; text-wrap: balance; }
  .page-sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

  /* Card */
  .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; }
  .card-h { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
  .card-h .eyebrow { font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--faint); }
  .card-b { padding: 13px 14px; }

  label.f { display: block; }
  .f-label { font-size: 11.5px; font-weight: 650; color: var(--muted); margin-bottom: 4px; display: flex; gap: 5px; align-items: center; }
  .req { color: var(--accent); }
  .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
  @media (max-width: 620px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
  /* Ряд с полями по содержимому — узкие поля не растягиваются на всю ширину */
  .frow { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
  .frow .f { margin: 0; }
  .f.w-sm { width: 104px; flex: 0 0 auto; }
  .f.w-md { width: 168px; flex: 0 0 auto; }
  .f.grow { flex: 1 1 220px; min-width: 170px; }

  input, select {
    width: 100%; height: var(--field); padding: 0 10px; font: inherit; font-size: 13.5px;
    color: var(--ink); background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: 7px; transition: border-color .12s, box-shadow .12s;
  }
  input[readonly] { background: var(--surface-2); color: var(--muted); border-style: dashed; }
  input:focus-visible, select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  select { cursor: pointer; }
  .prefill-note { font-size: 11.5px; color: var(--faint); margin-top: 5px; }

  /* Section (delivery date group) */
  .section { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden; }
  .section-h { display: flex; align-items: center; gap: 12px; padding: 9px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
  .section-tag { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 12.5px; letter-spacing: -.01em; }
  .section-tag .n { width: 21px; height: 21px; border-radius: 6px; background: var(--ink); color: var(--surface); display: grid; place-items: center; font-size: 11.5px; font-weight: 700; }
  .section-date { display: flex; align-items: center; gap: 8px; margin-left: auto; }
  .section-date .f-label { margin: 0; }
  .section-date input { height: 32px; width: 158px; }
  .icon-btn { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--muted); width: 32px; height: 32px; border-radius: 7px; cursor: pointer; font-size: 16px; display: grid; place-items: center; flex: none; }
  .icon-btn:hover { border-color: var(--crit); color: var(--crit); background: var(--crit-soft); }

  .items { width: 100%; }
  .items-scroll { overflow-x: auto; }
  table.pos { width: 100%; border-collapse: collapse; min-width: 640px; }
  table.pos th { font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); text-align: left; padding: 8px 8px 6px; border-bottom: 1px solid var(--border); }
  table.pos td { padding: 4px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
  table.pos tr:last-child td { border-bottom: 0; }
  table.pos input, table.pos select { height: 33px; }
  .col-n { width: 34px; color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; text-align: center; }
  .col-qty { width: 96px; }
  .col-qty input { text-align: right; font-variant-numeric: tabular-nums; }
  .col-unit { width: 118px; }
  .col-fix { width: 116px; }
  .col-x { width: 42px; }
  .fix { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap; }
  .fix input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
  .row-x { appearance: none; border: 0; background: transparent; color: var(--faint); cursor: pointer; font-size: 18px; width: 30px; height: 30px; border-radius: 7px; }
  .row-x:hover { color: var(--crit); background: var(--crit-soft); }
  .section-f { padding: 7px 10px; border-top: 1px solid var(--border); }

  .btn { appearance: none; font: inherit; font-weight: 650; font-size: 13.5px; cursor: pointer; border-radius: 7px; padding: 0 15px; height: var(--field); display: inline-flex; align-items: center; gap: 8px; border: 1px solid transparent; transition: filter .12s, background .12s; }
  .btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--ink); height: 33px; }
  .btn-ghost:hover { background: var(--surface-2); }
  .btn-soft { background: var(--accent-soft); color: var(--accent); border-color: transparent; height: 34px; }
  .btn-soft:hover { filter: brightness(.97); }
  .btn-primary { background: var(--accent); color: var(--accent-ink); }
  .btn-primary:hover { filter: brightness(1.05); }
  .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .btn[disabled] { opacity: .5; cursor: not-allowed; }

  /* Urgency + submit bar */
  .actionbar { position: sticky; bottom: 12px; margin-top: 14px; display: flex; align-items: center; gap: 12px; padding: 9px 12px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: 0 8px 30px rgba(20,25,35,.14); }
  .urg { display: flex; align-items: center; gap: 9px; margin-right: auto; }
  .urg-label { font-size: 12px; color: var(--muted); }
  .badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; letter-spacing: .01em; white-space: nowrap; }
  .badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
  .b-normal { color: var(--muted); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
  .b-urgent { color: var(--warn); background: var(--warn-soft); }
  .b-super  { color: var(--crit); background: var(--crit-soft); }
  .b-proc { color: var(--proc); background: var(--proc-soft); }
  .b-ok { color: var(--ok); background: var(--ok-soft); }
  .b-draft { color: var(--muted); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
  .b-fail { color: var(--crit); background: var(--crit-soft); }

  /* Cabinet */
  .req-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 9px; overflow: hidden; }
  .req-head { display: flex; align-items: center; gap: 12px; padding: 11px 14px; cursor: pointer; }
  .req-head:hover { background: var(--surface-2); }
  .req-title { font-weight: 700; font-size: 14.5px; letter-spacing: -.01em; }
  .req-meta { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
  .req-badges { margin-left: auto; display: flex; gap: 7px; align-items: center; }
  .chev { color: var(--faint); transition: transform .18s; font-size: 13px; }
  .req-card.open .chev { transform: rotate(90deg); }
  .req-body { display: none; border-top: 1px solid var(--border); }
  .req-card.open .req-body { display: block; }
  .pos-list { padding: 6px 0; }
  .pos-line { display: flex; align-items: center; gap: 12px; padding: 7px 14px; }
  .pos-line + .pos-line { border-top: 1px solid var(--border); }
  .pos-name { font-size: 13.5px; }
  .pos-sub { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
  .pos-line .badge { margin-left: auto; }
  .group-label { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); padding: 12px 16px 4px; display: flex; gap: 8px; align-items: center; }

  .toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--surface); padding: 12px 18px; border-radius: 10px; font-size: 13.5px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.3); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: 90vw; }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
  .hidden { display: none !important; }
  .foot { text-align: center; color: var(--faint); font-size: 11.5px; margin-top: 30px; }
  @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

  /* --- Мобильная вёрстка: позиции превращаются в карточки --- */
  @media (max-width: 640px) {
    .wrap { padding: 0 12px 96px; }
    .topbar-inner { padding: 10px 12px; gap: 10px; }
    .who { display: none; }
    .brand span { display: none; }
    .tabs { width: 100%; }
    .tab { flex: 1; }

    .items-scroll { overflow: visible; }
    table.pos, table.pos tbody, table.pos tr, table.pos td { display: block; width: auto; }
    table.pos { min-width: 0; }
    table.pos thead { display: none; }
    table.pos tr { position: relative; border: 1px solid var(--border); border-radius: 8px; margin: 10px; padding: 13px 10px 10px; background: var(--surface-2); display: grid; grid-template-columns: 1fr 1fr; gap: 9px 10px; }
    table.pos td { border: 0 !important; padding: 0; }
    table.pos td[data-label]::before { content: attr(data-label); display: block; font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); margin-bottom: 5px; }
    table.pos td.col-qty, table.pos td.col-unit, table.pos td.col-fix { width: auto; }
    /* Наименование, цель и срок — на всю ширину; кол-во + ед.изм. рядом */
    table.pos td[data-label="Наименование"], table.pos td[data-label="Цель использования"], table.pos td.col-fix { grid-column: 1 / -1; }
    table.pos td.col-n { position: absolute; top: -10px; left: 12px; width: auto; padding: 1px 8px; background: var(--ink); color: var(--surface); border-radius: 5px; font-size: 11px; font-weight: 700; }
    table.pos td.col-x { position: absolute; top: 8px; right: 8px; width: auto; }
    .col-qty input { text-align: left; }
    .row-two { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }

    .section-h { flex-wrap: wrap; }
    .section-date { margin-left: auto; }
    .section-date input { width: 150px; }
    .frow .f.grow { flex-basis: 100%; }
    .card-b { padding: 14px; }

    .actionbar { flex-wrap: wrap; bottom: 10px; }
    .actionbar .urg { width: 100%; margin-right: 0; }
    .actionbar .btn-primary { width: 100%; justify-content: center; }
  }

/* --- Экран входа --- */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 26px 22px; }
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 18px; }
.auth-brand b { font-weight: 700; font-size: 15px; display: block; line-height: 1.15; }
.auth-brand span { color: var(--muted); font-size: 12px; }
.auth-card h2 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; margin: 0 0 3px; }
.auth-card p.sub { color: var(--muted); font-size: 12.5px; margin: 0 0 18px; }
.auth-card .f + .f { margin-top: 12px; }
.auth-err { display: none; margin-top: 12px; font-size: 12.5px; color: var(--crit); background: var(--crit-soft); padding: 8px 10px; border-radius: 7px; }
.auth-err.show { display: block; }
.auth-card .btn-primary { width: 100%; justify-content: center; margin-top: 16px; }
.auth-hint { text-align: center; color: var(--faint); font-size: 11px; margin-top: 14px; }

/* --- Прочее --- */
.logout-btn { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--muted); height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; }
.logout-btn:hover { border-color: var(--border-strong); color: var(--ink); }
.form-errors { display: none; background: var(--crit-soft); color: var(--crit); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; margin-bottom: 12px; }
.form-errors.show { display: block; }
.form-errors ul { margin: 4px 0 0; padding-left: 18px; }
.state { text-align: center; color: var(--muted); font-size: 13.5px; padding: 40px 10px; }
.state.err { color: var(--crit); }
.input-bad { border-color: var(--crit) !important; box-shadow: 0 0 0 3px var(--crit-soft) !important; }

/* --- Экран успеха после отправки --- */
.success-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 34px 24px; text-align: center; max-width: 460px; margin: 30px auto; }
.success-ico { width: 56px; height: 56px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; font-size: 28px; font-weight: 700; margin: 0 auto 14px; }
.success-card h2 { font-size: 19px; font-weight: 750; letter-spacing: -.01em; margin: 0 0 8px; text-wrap: balance; }
.success-card p { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; line-height: 1.55; }
.success-card p b { color: var(--ink); }
.success-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* --- Панель запроса на правку (кабинет) --- */
.edit-req { border-top: 1px solid var(--border); padding: 13px 14px; background: var(--surface-2); }
.edit-req-note { font-size: 12px; color: var(--muted); line-height: 1.5; margin-bottom: 9px; }
.edit-req-note b { color: var(--ink); font-weight: 650; }
.edit-req-text { width: 100%; font: inherit; font-size: 13.5px; color: var(--ink); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px; padding: 8px 10px; resize: vertical; min-height: 40px; transition: border-color .12s, box-shadow .12s; }
.edit-req-text:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.edit-req-actions { display: flex; gap: 8px; margin-top: 9px; flex-wrap: wrap; }
