/* ---------- палитра: серая основа, жёлтый только как акцент ---------- */
:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --ink: #24282e;
  --ink-2: #4b5259;
  --muted: #7a828c;
  --line: #e2e5ea;
  --line-2: #cfd3d9;
  --accent: #fbdd7a;       /* фирменный жёлтый МСП, дозированно */
  --accent-ink: #4a3d0a;
  --dark: #33383f;
  --found: #e6f1e8;  --found-ink: #2c6b3f;
  --wo: #e6e8ec;     --wo-ink: #5a6068;
  --nf: #fae8e6;     --nf-ink: #a8271f;
  --ni: #fbf3dc;     --ni-ink: #7d6218;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(20, 24, 30, .06);
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5; -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100vh;
}
a { color: inherit; }
.wrap { width: min(1180px, 100% - 40px); margin: 0 auto; }
.main { flex: 1; padding: 28px 0 48px; }
h1 { font-size: 1.7rem; margin: 0 0 6px; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 12px; font-weight: 600; }
.lead { color: var(--ink-2); margin: 0 0 24px; max-width: 70ch; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }

/* ---------- шапка ---------- */
.topbar { background: var(--dark); color: #d7dadf; font-size: .8rem; }
.topbar .wrap { display: flex; justify-content: space-between; align-items: center; min-height: 32px; gap: 20px; }
.topbar a { color: #fff; text-decoration: none; }
.topbar a:hover { text-decoration: underline; }
.topbar-user { display: flex; gap: 14px; align-items: center; white-space: nowrap; }
.topbar .role { color: #9aa1aa; }
.header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 68px; gap: 24px; }
.brand { display: flex; align-items: center; gap: 16px; text-decoration: none; }
.brand-logo { height: 40px; width: auto; display: block; }
.brand-text { padding-left: 16px; border-left: 1px solid var(--line-2); white-space: nowrap; }
@media (max-width: 1150px) { .brand-text small { display: none; } }
@media (max-width: 1000px) { .header-inner { flex-wrap: wrap; padding-bottom: 6px; } .nav a { padding: 10px 12px; } }
@media (max-width: 600px) { .brand-logo { height: 32px; } .brand-text small { display: none; } }
.brand-mark {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: .85rem; letter-spacing: .02em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 1.05rem; }
.brand-text small { color: var(--muted); font-size: .78rem; }
.nav { display: flex; gap: 4px; }
.nav a {
  text-decoration: none; padding: 22px 12px; color: var(--ink-2); font-weight: 500; white-space: nowrap;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.active { color: var(--ink); border-bottom-color: var(--accent); }
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; padding: 18px 0; }
.footer .wrap { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }

/* ---------- карточки и сетка ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: 1.4fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 860px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } .nav a { padding: 12px 10px; } .header-inner { flex-wrap: wrap; } }

/* ---------- формы и кнопки ---------- */
label { display: block; font-size: .86rem; color: var(--ink-2); margin-bottom: 5px; font-weight: 500; }
input[type=text], input[type=password], select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: var(--radius);
  font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--dark); outline-offset: 1px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 160px; margin-bottom: 0; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: var(--radius);
  border: 1px solid var(--line-2); background: #fff; color: var(--ink); font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: #e9c95c; color: var(--accent-ink); }
.btn-primary:hover { background: #f5d465; }
.btn-dark { background: var(--dark); border-color: var(--dark); color: #fff; }
.btn-dark:hover { background: #22262c; }
.btn-sm { padding: 5px 10px; font-size: .84rem; }
.btn-danger { color: var(--nf-ink); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- зона загрузки ---------- */
.drop {
  border: 2px dashed var(--line-2); border-radius: 8px; padding: 40px 24px; text-align: center;
  background: var(--surface-2); transition: border-color .15s, background .15s; cursor: pointer;
}
.drop:hover, .drop.over { border-color: var(--dark); background: #fff; }
.drop input { display: none; }
.drop .drop-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 4px; }
.drop .drop-file { margin-top: 12px; font-weight: 500; color: var(--ink); }
.drop-actions { margin-top: 16px; display: flex; gap: 10px; justify-content: center; }

/* ---------- сообщения ---------- */
.flash { padding: 11px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; font-size: .93rem; }
.flash-ok { background: var(--found); border-color: #cfe3d4; color: var(--found-ink); }
.flash-error { background: var(--nf); border-color: #f0cfcb; color: var(--nf-ink); }
.flash-message { background: var(--ni); border-color: #ecdca9; color: var(--ni-ink); }

/* ---------- статусы ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge-found { background: var(--found); color: var(--found-ink); }
.badge-written_off { background: var(--wo); color: var(--wo-ink); }
.badge-not_found { background: var(--nf); color: var(--nf-ink); }
.badge-no_inv { background: var(--ni); color: var(--ni-ink); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-found { background: #4f9c66; } .dot-written_off { background: #8c939c; } .dot-not_found { background: #d1443b; } .dot-no_inv { background: #cfa72e; }

/* ---------- счётчики результата ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 18px 0; }
@media (max-width: 860px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  text-align: left; cursor: pointer; font: inherit; color: var(--ink);
}
.stat:hover { border-color: var(--line-2); }
.stat.active { border-color: var(--dark); box-shadow: inset 0 0 0 1px var(--dark); }
.stat .num { font-size: 1.7rem; font-weight: 600; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .84rem; margin-top: 2px; }

/* ---------- таблицы ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; max-height: 72vh; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-2); color: var(--ink-2); font-weight: 600; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tbody tr:hover { background: #fafbfc; }
tr.st-written_off td { color: var(--wo-ink); }
tr.st-written_off .inv { text-decoration: line-through; }
tr.st-not_found { background: #fff7f6; }
tr.st-no_inv { background: #fffcf2; }
td.num { color: var(--muted); text-align: right; }
.mono { font-family: Consolas, "Roboto Mono", monospace; font-size: .88rem; }
.compact td { padding: 6px 10px; }

/* ---------- панель результата ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=text] { max-width: 340px; }
.toolbar .spacer { flex: 1; }
details.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
details.panel summary { padding: 12px 18px; cursor: pointer; font-weight: 500; color: var(--ink-2); list-style: none; display: flex; justify-content: space-between; }
details.panel summary::after { content: "▾"; color: var(--muted); }
details.panel[open] summary::after { content: "▴"; }
details.panel .panel-body { padding: 4px 18px 18px; border-top: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* ---------- логин ---------- */
.login-wrap { max-width: 400px; margin: 40px auto; }
.login-wrap .card { padding: 30px; }

/* ---------- справочные карточки ---------- */
.ref { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.ref b { font-size: .95rem; }
.ref .file { color: var(--ink-2); word-break: break-all; }
.ref.missing { border-style: dashed; color: var(--muted); }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a { text-decoration: none; font-weight: 500; }
.list a:hover { text-decoration: underline; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: .86rem; color: var(--ink-2); }
.legend p { margin: 0; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ширины колонок таблицы результата */
#rt th:nth-child(1) { width: 44px; }
#rt th:nth-child(2) { width: 160px; }
#rt th:nth-child(3), #rt th:nth-child(7) { min-width: 240px; white-space: normal; }
#rt th:nth-child(5) { min-width: 170px; }
.legend { flex-direction: column; gap: 8px; }

/* ---------- главная: сервисы ---------- */
.services { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 860px) { .services { grid-template-columns: 1fr; } }
.service {
  display: flex; flex-direction: column; gap: 8px; padding: 22px; background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); min-height: 130px;
}
.service:hover { border-color: var(--line-2); border-left-color: var(--dark); }
.service b { font-size: 1.1rem; }
.service span { color: var(--ink-2); font-size: .92rem; }
.service-admin { border-left-color: var(--line-2); }
#gt input[type=text] { padding: 5px 8px; font-size: .9rem; }

/* Shared responsive navigation */
.upload-dates { display:flex; flex-wrap:wrap; gap:4px 24px; padding:8px 0; }
.topbar .wrap { flex-wrap:wrap; gap:6px 20px; }
.topbar-user { flex-wrap:wrap; white-space:normal; padding:6px 0; }
.app-body { display:flex; flex:1; min-width:0; }
.authenticated .main { width:auto; min-width:0; flex:1; margin:0; padding:28px 24px 48px; }
.sidebar { width:232px; flex:0 0 232px; align-self:flex-start; position:sticky; top:0; max-height:100vh; overflow-y:auto; background:var(--surface); border-right:1px solid var(--line); padding:18px 12px; }
.sidebar nav { display:flex; flex-direction:column; gap:6px; }
.sidebar a { display:block; text-decoration:none; padding:11px 12px; border-radius:6px; overflow-wrap:anywhere; border-left:3px solid transparent; }
.sidebar a:hover { background:var(--surface-2); }
.sidebar a.active { background:#fff6d9; border-left-color:var(--accent); font-weight:600; }
.menu-toggle { display:none; }
.main .grid > *, .main .card, .table-wrap { min-width:0; max-width:100%; }
@media(max-width:760px) {
  .app-body { flex-direction:column; }
  .menu-toggle { display:inline-flex; }
  .sidebar { display:none; position:static; width:100%; flex:auto; max-height:60vh; border-right:0; border-bottom:1px solid var(--line); }
  .sidebar.is-open { display:block; }
  .authenticated .main { width:100%; padding:22px 16px 36px; }
  .header-inner { gap:10px; padding:12px 0; }
  .brand { gap:8px; min-width:0; }
  .brand-text { padding-left:8px; white-space:normal; }
  .brand-text b { font-size:.88rem; }
  .topbar-user { gap:10px; }
  .upload-dates { flex-direction:column; gap:2px; }
  .main .grid-2, .main .grid-3 { grid-template-columns:1fr; }
  .main .card { padding:16px; overflow-wrap:anywhere; }
  .main input, .main select, .main textarea { max-width:100%; }
}
/* Native radios remain focusable; button styling exposes the exclusive purpose. */
.purpose-picker{border:0;padding:0;margin:0 0 16px;display:flex;flex-wrap:wrap;gap:8px}
.purpose-picker legend{margin-bottom:8px;font-size:14px}
.purpose-option{position:relative;cursor:pointer}
.purpose-option input{position:absolute;opacity:0;width:1px;height:1px}
.purpose-option input:checked + .btn{background:#f7d956;border-color:#a78d23;color:#222;box-shadow:inset 0 0 0 1px #a78d23}
.purpose-option input:focus-visible + .btn{outline:3px solid #285bb5;outline-offset:3px}

/* ---------- проверка перемещения: шаги, сводка, вкладки ---------- */
.summary { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; margin:0 0 22px; }
.summary-item { background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); padding:12px 16px; display:flex; flex-direction:column; }
.summary-item b { font-size:1.6rem; font-weight:600; line-height:1.1; }
.summary-item span { color:var(--muted); font-size:.84rem; }
.summary-ready { border-left:4px solid #4f9c66; }
.summary-choose { border-left:4px solid #cfa72e; }
.summary-excluded { border-left:4px solid #8c939c; }
.step { display:flex; align-items:center; gap:12px; margin:24px 0 10px; }
.step:first-of-type { margin-top:4px; }
.step-number { display:inline-grid; place-items:center; width:32px; height:32px; border-radius:50%; background:var(--accent); color:var(--accent-ink); font-weight:700; flex:0 0 32px; }
.step-title { margin:0; font-size:1.2rem; }
.tabs { display:flex; gap:4px; border-bottom:2px solid var(--line); margin-bottom:14px; flex-wrap:wrap; }
.tab { text-decoration:none; padding:10px 16px; color:var(--ink-2); font-weight:500; border-bottom:3px solid transparent; margin-bottom:-2px; border-radius:var(--radius) var(--radius) 0 0; }
.tab:hover { background:var(--surface-2); color:var(--ink); }
.tab.active { background:#fff6d9; border-bottom-color:var(--accent); color:var(--ink); font-weight:600; }
.tab-count { display:inline-block; min-width:26px; text-align:center; padding:1px 8px; border-radius:999px; background:var(--surface-2); border:1px solid var(--line-2); font-size:.82rem; margin-left:4px; }
.tab.active .tab-count { background:var(--accent); border-color:#e9c95c; color:var(--accent-ink); }
.hint { color:var(--ink-2); margin:0 0 12px; max-width:80ch; }
.search-bar input[type=search] { flex:1; min-width:220px; max-width:520px; padding:9px 11px; border:1px solid var(--line-2); border-radius:var(--radius); font:inherit; }
.select-actions { margin-bottom:10px; }
.selected-line { font-size:.95rem; }
.selected-line b { font-size:1.05rem; }
.check-col { width:44px; text-align:center; }
.check-col input { width:18px; height:18px; }
#movement-items .table-wrap { max-height:65vh; }
.empty { padding:24px; text-align:center; color:var(--muted); border:1px dashed var(--line-2); border-radius:var(--radius); }
.choose-list { display:flex; flex-direction:column; gap:14px; max-height:65vh; overflow:auto; }
.choose-row { border:1px solid var(--line-2); border-radius:var(--radius); padding:10px 14px 12px; margin:0; background:var(--surface-2); }
.choose-row.is-chosen { border-color:#4f9c66; background:#f4faf5; }
.choose-row legend { padding:0 6px; font-weight:600; color:var(--ink); font-size:.95rem; }
.choose-question { margin:4px 0 8px; color:var(--ink-2); font-size:.9rem; }
.choose-option { display:flex; align-items:flex-start; gap:10px; padding:8px 10px; margin:0 0 6px; background:#fff; border:1px solid var(--line); border-radius:var(--radius); cursor:pointer; font-weight:400; color:var(--ink); font-size:.92rem; }
.choose-option:hover { border-color:var(--line-2); }
.choose-option input { margin-top:3px; width:16px; height:16px; flex:0 0 16px; }
.choose-option:has(input:checked) { border-color:#e9c95c; background:#fff6d9; }
.choose-option.is-disabled { color:var(--muted); cursor:not-allowed; background:var(--surface-2); }
.pager { display:flex; align-items:center; justify-content:center; gap:14px; margin:16px 0 6px; flex-wrap:wrap; }
.pager .btn[aria-disabled=true] { opacity:.45; cursor:default; }
.pager-info { font-weight:500; }
.generate-bar { display:flex; align-items:center; gap:18px; flex-wrap:wrap; margin:16px 0 10px; }
.btn-lg { padding:14px 26px; font-size:1.08rem; font-weight:600; }
.generate-count { font-size:1rem; color:var(--ink-2); }
.generate-count b { font-size:1.15rem; color:var(--ink); }
@media (max-width:760px) {
  .summary { grid-template-columns:repeat(2,1fr); }
  .tab { padding:9px 10px; font-size:.9rem; }
  .btn-lg { width:100%; justify-content:center; }
  .search-bar input[type=search] { max-width:100%; }
}
