/* Sandėlis — warehouse journal. Layout: left rail on desktop, bottom tab bar on phone; content column max 72rem. */
:root {
  --bg: #f3f4f1; --panel: #ffffff; --panel-2: #f8f9f6; --line: #dde0d8; --fg: #1d221c; --muted: #6a7066;
  --accent: #b5651d; --accent-fg: #ffffff; --accent-soft: #f6e7d8;
  --ok: #2f7d4a; --ok-soft: #e1f1e6; --warn: #a86400; --warn-soft: #fbefd9; --bad: #b3261e; --bad-soft: #f8e1df;
  --c-in: #3b6ea8; --c-melt: #b5651d; --c-ship: #2f7d4a; --c-sale: #7a4fa3;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 10px; --shadow: 0 1px 2px rgba(20, 24, 18, .06), 0 4px 16px rgba(20, 24, 18, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151814; --panel: #1d211c; --panel-2: #222720; --line: #333a31; --fg: #e9ece6; --muted: #9aa195;
    --accent: #e08a3c; --accent-fg: #1a1205; --accent-soft: #3a2a19;
    --ok: #6cc28a; --ok-soft: #1f3326; --warn: #e6a948; --warn-soft: #382c16; --bad: #ef7a72; --bad-soft: #3d1f1d;
    --c-in: #7aa7dc; --c-melt: #e08a3c; --c-ship: #6cc28a; --c-sale: #b48ad8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
body { padding-bottom: env(safe-area-inset-bottom, 0px); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 100vh; }
.app > div { min-width: 0; }
.rail { display: none; }
.top { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; gap: 12px; }
.top h1 { font-size: 1.1rem; margin: 0; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-grid; place-items: center; color: var(--accent-fg); font-size: 12px; font-weight: 700; }
main { padding: 16px max(16px, env(safe-area-inset-right, 0px)) 96px max(16px, env(safe-area-inset-left, 0px)); max-width: 72rem; width: 100%; margin: 0 auto; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--panel); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabs a, .rail a { text-decoration: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; font-size: .72rem; position: relative; }
.tabs a.on, .rail a.on { color: var(--accent); }
.tabs svg, .rail svg { width: 22px; height: 22px; }
.badge { position: absolute; top: 4px; right: calc(50% - 20px); background: var(--bad); color: #fff; border-radius: 999px; font-size: .68rem; min-width: 18px; height: 18px; padding: 0 5px; display: grid; place-items: center; font-weight: 600; }
@media (min-width: 900px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  .rail { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; padding: 18px 12px; border-right: 1px solid var(--line); background: var(--panel); }
  .rail .brand { padding: 4px 10px 18px; }
  .rail a { flex-direction: row; gap: 10px; font-size: .95rem; padding: 9px 10px; border-radius: 8px; color: var(--fg); }
  .rail a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .rail a .badge { position: static; margin-left: auto; }
  .rail .spacer { flex: 1; }
  .tabs { display: none; }
  .top .brand { display: none; }
  main { padding-bottom: 32px; }
}

/* ---------- blocks ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); gap: 14px; }
.h2 { font-size: 1rem; font-weight: 600; margin: 0; }
.h3 { font-size: .78rem; font-weight: 600; margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; color: var(--fg); min-height: 38px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: .88rem; }
.btn:focus-visible, .chip:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: .5; cursor: default; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; color: var(--muted); font-size: .9rem; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--fg); color: var(--bg); }

/* action grid on the day screen */
.actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .actions { grid-template-columns: repeat(4, 1fr); } }
.act { border: 1px solid var(--line); background: var(--panel); border-radius: var(--r); padding: 14px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-height: 76px; border-left: 4px solid var(--c, var(--line)); }
.act:hover { box-shadow: var(--shadow); }
.act b { font-weight: 600; }
.act span { color: var(--muted); font-size: .82rem; }

.daybar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.daybar input[type=date] { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--panel); min-height: 38px; }
.sumstrip { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi .l { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 1.45rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: .8rem; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); display: inline-block; flex: none; }

/* entry list */
.list { display: flex; flex-direction: column; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--panel-2); }
.item .ic { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); font-weight: 700; font-size: .8rem; }
.item .t { min-width: 0; }
.item .t b { font-weight: 600; }
.item .t div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .q { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: .74rem; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.pending { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.rejected { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.yana { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.fix { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }

/* tables */
.tbl-wrap { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: .8rem; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.neg { color: var(--bad); }
.pend { color: var(--warn); font-size: .8rem; }

/* tanks */
.tanks { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 10px; }
.tank { border: 1px solid var(--line); border-radius: var(--r); padding: 12px; background: var(--panel); display: flex; flex-direction: column; gap: 6px; }
.tank .bar { height: 10px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); overflow: hidden; display: flex; }
.tank .bar i { display: block; height: 100%; }
.tank .bar i.our { background: var(--c-melt); }
.tank .bar i.yana { background: color-mix(in srgb, var(--c-melt) 45%, var(--panel)); }

/* forms */
.sheet-back { position: fixed; inset: 0; background: rgba(10, 12, 9, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--panel); width: 100%; max-width: 40rem; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); box-shadow: var(--shadow); }
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: 16px; } }
.sheet h2 { margin: 0 0 12px; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); min-width: 0; }
.form input, .form select, .form textarea { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: var(--panel); color: var(--fg); min-height: 40px; width: 100%; font-size: 1rem; }
.form textarea { min-height: 64px; resize: vertical; }
.form .check { flex-direction: row; align-items: center; gap: 8px; color: var(--fg); font-size: .95rem; }
.form .check input { width: auto; min-height: 0; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 10px; margin: 0; }
.form legend { font-size: .78rem; color: var(--muted); padding: 0 4px; }
.hint { font-size: .82rem; color: var(--muted); }
.hint b { color: var(--fg); font-weight: 600; }
.calc { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; font-size: .9rem; }
.warnbox { background: var(--warn-soft); color: var(--fg); border-radius: 8px; padding: 10px 12px; font-size: .9rem; }
.warnbox b { color: var(--warn); }
.errbox { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 12px; font-size: .9rem; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; padding-top: 4px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input, .filters select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--panel); min-height: 36px; max-width: 100%; }

.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: .92rem; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* login / install */
.install, .login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.install-card, .login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: 100%; max-width: 26rem; box-shadow: var(--shadow); }
.install-card h1, .login-card h1 { margin: 0; font-size: 1.4rem; }
.install .ok { color: var(--ok); } .install .err { color: var(--bad); }
.install fieldset { margin-bottom: 4px; }

@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
}
@media (max-width: 420px) { .form .three { grid-template-columns: 1fr 1fr; } }

/* stock places: cards side by side, rows = name | kg (+ buckets/pallets) | ± */
.grid-places { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); gap: 14px; align-items: start; }
table.stk { width: 100%; }
table.stk td { vertical-align: middle; padding: 9px 6px; }
table.stk td:first-child { width: 100%; overflow-wrap: anywhere; padding-left: 0; }
table.stk .stk-name { font-weight: 500; }
table.stk td.r { white-space: nowrap; line-height: 1.25; }
table.stk td.r .small { font-size: .78rem; }
table.stk .act-cell { width: 1%; padding-right: 0; }
.stk-btn { width: 32px; height: 32px; min-height: 32px; padding: 0; justify-content: center; color: var(--muted); border: 1px solid var(--line); }
.stk-btn:hover { border-color: var(--line); color: var(--accent); background: var(--panel-2); }
