:root {
  --bg: #f3f5f2; --surface: #ffffff; --surface2: #eef2ee; --text: #17201c; --muted: #66736d; --line: #dde3de;
  --brand: #163f38; --brand-text: #ffffff; --accent: #1f7a5c; --accent-soft: #dcefe6;
  --warn: #a86a00; --warn-soft: #fff3d6; --danger: #b3261e; --danger-soft: #fde4e1; --ok: #1f7a5c; --ok-soft: #dcefe6;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --nav-h: 62px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1512; --surface: #151f1b; --surface2: #1b2823; --text: #e6ece9; --muted: #93a39c; --line: #27352f;
  --brand: #0f2622; --accent: #4cc293; --accent-soft: #173a2e;
  --warn: #f0b545; --warn-soft: #3a2d10; --danger: #ff7b72; --danger-soft: #3d1a18; --ok: #4cc293; --ok-soft: #173a2e;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.center { text-align: center; }
.warn-text { color: var(--warn); font-size: 13px; }

/* Top bar and navigation */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; background: var(--brand); color: var(--brand-text); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand small { display: block; font-size: 12px; opacity: .75; }
.logo { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: rgba(255,255,255,.14); font-weight: 800; letter-spacing: .5px; }
.who { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.topbar .chip { background: rgba(255,255,255,.16); color: #fff; }
.topbar .chip.warn { background: #f0b545; color: #2a1d00; }
.layout { display: flex; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); min-width: 0; }
.nav a .ico { font-size: 19px; line-height: 1; }
.nav a.active { color: var(--accent); font-weight: 700; }
.view { flex: 1; min-width: 0; max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) {
  .nav { position: sticky; top: 56px; flex-direction: column; width: 210px; height: calc(100vh - 56px); padding: 12px 8px; border-top: 0; border-right: 1px solid var(--line); background: transparent; }
  .nav a { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 12px; font-size: 15px; border-radius: 10px; }
  .nav a.active { background: var(--accent-soft); }
  .view { padding-bottom: 32px; }
}

/* Generic blocks */
.page-title { font-size: 22px; margin: 4px 0 14px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.page-head .page-title { margin-bottom: 10px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; font-size: 17px; margin: 22px 0 10px; }
.link { font-size: 14px; color: var(--accent); font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow); }
.card h3 { font-size: 16px; margin-bottom: 10px; }
.card h4, .form h4 { font-size: 14px; margin: 14px 0 8px; }
.empty { padding: 26px 12px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.loading { padding: 30px; text-align: center; color: var(--muted); }
.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.btns, .btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row { margin: 12px 0; }
.btn-row.sticky { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: var(--surface); padding: 10px 0 2px; margin-bottom: 0; }
@media (min-width: 900px) { .btn-row.sticky { bottom: 0; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #06130e; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 16px; padding: 6px 8px; cursor: pointer; border-radius: 8px; }
.icon-btn:hover { background: var(--surface2); }

.chip { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface2); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.chips:empty { display: none; }

.alerts { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.alert { display: block; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--text); font-size: 14px; margin-bottom: 8px; }
.alert.warn { background: var(--warn-soft); }
.alert.danger { background: var(--danger-soft); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; }
.kpi small { color: var(--muted); font-size: 13px; }
.kpi b { font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi b.sm { font-size: 17px; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi.neg b { color: var(--danger); }
.kpi.warn b { color: var(--warn); }
.kpi.wide { grid-column: span 2; }
@media (max-width: 420px) { .kpi.wide { grid-column: 1 / -1; } }

/* Quick actions */
.actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.action { display: flex; flex-direction: column; gap: 2px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.action .ico { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 17px; margin-bottom: 6px; }
.action small { color: var(--muted); font-size: 13px; }
.action:active { transform: scale(.98); }

/* Document cards */
.doc-card { display: flex; gap: 12px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.doc-card.cancelled { opacity: .6; }
.doc-card.cancelled b { text-decoration: line-through; }
.doc-ico { flex: 0 0 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--surface2); font-size: 16px; }
.t-receipt .doc-ico, .action.t-receipt .ico { background: var(--ok-soft); color: var(--ok); }
.t-sale .doc-ico, .t-mix_sale .doc-ico, .action.t-sale .ico, .action.t-mix_sale .ico { background: var(--warn-soft); color: var(--warn); }
.t-writeoff .doc-ico, .t-cash_out .doc-ico, .action.t-writeoff .ico, .action.t-cash_out .ico { background: var(--danger-soft); color: var(--danger); }
.doc-main { flex: 1; min-width: 0; }
.doc-top { display: flex; justify-content: space-between; gap: 8px; }
.doc-partner { font-size: 14px; }
.doc-lines { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

/* Stock */
.toolbar, .filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search], .filters input[type=search] { flex: 1 1 220px; }
.cat { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 14px 0 6px; }
.stock-row, .menu-row, .move-row, .user-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.stock-row small, .menu-row small, .move-row small, .user-row small { display: block; color: var(--muted); font-size: 13px; }
.stock-row .qty { white-space: nowrap; font-variant-numeric: tabular-nums; }
.stock-row .qty b { font-size: 17px; }
.stock-row.low { border-left: 4px solid var(--warn); }
.stock-row.neg .qty b { color: var(--danger); }
.inactive { opacity: .55; }
.gdot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.group-sum { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.group-sum div { display: flex; flex-direction: column; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; font-size: 13px; color: var(--muted); }
.group-sum b { color: var(--text); font-size: 17px; font-variant-numeric: tabular-nums; }
.move-row .qty { white-space: nowrap; font-weight: 700; font-variant-numeric: tabular-nums; }
.qty.in { color: var(--ok); }
.qty.out { color: var(--danger); }
.menu-row > span { color: var(--muted); font-size: 20px; }
.user-row { flex-wrap: wrap; cursor: default; }
.user-ctl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Forms */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-height: 42px; min-width: 0; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field .hint { color: var(--muted); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.with-btn { display: flex; gap: 6px; }
.with-btn select { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.check input { min-height: auto; width: 18px; height: 18px; }
.line { display: grid; grid-template-columns: 1fr 110px 34px 34px; gap: 6px; align-items: center; margin-bottom: 6px; }
.line .unit { font-size: 13px; color: var(--muted); }
@media (max-width: 420px) { .line { grid-template-columns: 1fr 86px 28px 30px; } }
.preview-box:not(:empty) { margin: 10px 0; padding: 10px 12px; background: var(--accent-soft); border-radius: 10px; font-size: 14px; }
.adj { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
.adj-row { display: grid; grid-template-columns: 1fr 120px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.adj-row small { display: block; color: var(--muted); font-size: 12px; }
.files { display: flex; gap: 6px; flex-wrap: wrap; }
.file { display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px; background: var(--surface2); border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 13px; color: var(--text); cursor: pointer; }
.dates { display: flex; align-items: center; gap: 6px; }
.dates input { flex: 1; min-width: 0; }

/* Period and segmented controls */
.period { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.seg, .chips-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.period .seg { margin: 0; }
.seg button, .chips-row button { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.seg button.on, .chips-row button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .seg button.on, :root[data-theme="dark"] .chips-row button.on { color: #06130e; }
.chips-row { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
.chips-row button { flex: 0 0 auto; }

/* Document view */
.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0 0 10px; }
.props dt { color: var(--muted); font-size: 13px; }
.props dd { margin: 0; overflow-wrap: anywhere; }
.props.small { font-size: 14px; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
.tbl .r { text-align: right; white-space: nowrap; }
.tbl.stats td:first-child { min-width: 150px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.timeline small { display: block; color: var(--muted); font-size: 12px; }
.ver { padding: 8px 0; border-top: 1px dashed var(--line); font-size: 14px; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-top: 8px; }
.pre { white-space: pre-wrap; background: var(--surface2); padding: 10px; border-radius: 8px; overflow-wrap: anywhere; }
.preview { max-width: 100%; border-radius: 8px; }

/* Concrete */
.conc-row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; }
.conc-row summary { list-style: none; display: flex; justify-content: space-between; gap: 10px; padding: 12px 0; color: var(--text); font-weight: 400; margin: 0; }
.conc-row summary::-webkit-details-marker { display: none; }
.conc-row summary small { display: block; color: var(--muted); font-size: 13px; }
.conc-row[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.comps { display: flex; gap: 6px 12px; flex-wrap: wrap; font-size: 14px; }
.comp { white-space: nowrap; }

/* Charts */
.chart-scroll { overflow-x: auto; }
.chart-svg { display: block; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .axis { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 10px; background: var(--surface2); border-radius: 5px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 5px; }
.hbar-val { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Dialog and toast */
dialog { border: 0; padding: 0; background: transparent; max-width: min(560px, calc(100vw - 24px)); width: 100%; color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg { background: var(--surface); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.dlg header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dlg header h3 { font-size: 17px; }
.dlg-body { padding: 14px 16px; overflow: auto; }
.dlg footer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 50; display: flex; flex-direction: column; gap: 6px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast-item { padding: 11px 14px; border-radius: 10px; background: #22302b; color: #fff; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); transition: opacity .3s; }
.toast-item.success { background: #1f7a5c; }
.toast-item.error { background: #b3261e; }
.toast-item.hide { opacity: 0; }
.test-box { background: var(--warn-soft); border-color: transparent; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 14px; }

.filters select { flex: 1 1 150px; }
.filters .dates { flex: 1 1 260px; }

/* --- Layout fixes 2026-11-04: no overlaps on 320–1366 px --- */
.dates input { flex: 1 1 0; width: 0; min-width: 0; }
.period .dates { flex: 1 1 280px; }
@media (max-width: 400px) { .period .dates, .filters .dates { flex-basis: 100%; } .dates input { font-size: 14px; padding: 8px; } }
.page-head { margin-bottom: 6px; }
.chips-row { scrollbar-width: none; margin-top: 4px; }
.chips-row::-webkit-scrollbar { display: none; }
/* Sticky submit bar: full width of the card, opaque, separated from fields */
.form { padding-bottom: 0; }
.btn-row.sticky { margin: 12px -14px 0; padding: 10px 14px calc(10px + 0px); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -6px 14px rgba(0, 0, 0, .06); z-index: 5; }
.adj-row { grid-template-columns: minmax(0, 1fr) 110px; }
.adj-row span { min-width: 0; overflow-wrap: anywhere; }
.line select { min-width: 0; width: 100%; }
.line input { min-width: 0; width: 100%; }
.user-ctl select { max-width: 100%; }
.who .chip { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
.btn { white-space: nowrap; }
@media (max-width: 360px) { .btn { padding: 8px 12px; } .page-title { font-size: 20px; } }
/* Material presets */
.presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 4px; }
.presets > span { width: 100%; font-size: 13px; color: var(--muted); font-weight: 600; }
.preset { padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface2); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.preset.on, .preset:hover { border-color: var(--accent); background: var(--accent-soft); }
.dlg-body .hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
@media (max-width: 380px) {
  .dates { flex-wrap: wrap; }
  .dates > span { display: none; }
  .dates input { flex: 1 1 130px; width: auto; }
}
.nav { overflow: hidden; }
.nav a > span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
@media (max-width: 360px) { .nav a { font-size: 10px; } }
