:root {
  --bg: #f6f1ea;
  --ink: #2b2118;
  --muted: #7a6b5d;
  --card: #fffaf4;
  --line: #e6d9cc;
  --accent: #8b4a2b;
  --ok: #3d6b4f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  min-height: 100%;
}
.hidden { display: none !important; }
header {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  padding-top: calc(10px + var(--safe-top));
  background: var(--ink); color: #f6f1ea; position: sticky; top: 0; z-index: 30;
}
.brand { font-weight: 700; letter-spacing: .04em; flex: 0 0 auto; }
.who-name { opacity: .85; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-desktop { display: none; flex: 1; gap: 4px; flex-wrap: wrap; }
.nav-desktop a, .drawer nav a {
  color: inherit; text-decoration: none; padding: 12px 14px; border-radius: 8px;
  opacity: .9; display: block;
}
.nav-desktop a.active, .drawer nav a.active, .nav-desktop a:hover, .drawer nav a:hover {
  background: #4a372b; opacity: 1;
}
.burger {
  display: flex; align-items: center; justify-content: center;
  width: 44px; min-height: 44px; padding: 0; margin-left: auto;
  background: transparent; border: 1px solid #cbb; color: #f6f1ea; font-size: 22px;
}
.menu-overlay {
  position: fixed; inset: 0; background: rgba(20,12,8,.45); z-index: 20;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(320px, 88vw);
  background: #2b2118; color: #f6f1ea; z-index: 21;
  display: flex; flex-direction: column; padding: calc(12px + var(--safe-top)) 14px calc(16px + var(--safe-bottom));
  box-shadow: -8px 0 24px rgba(0,0,0,.25);
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.drawer-head .ghost { width: auto; color: #f6f1ea; border-color: #6a5a4c; }
.drawer nav { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; }
.drawer-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid #4a372b; }
.drawer-bio { margin-top: auto; padding-top: 16px; border-top: 1px solid #4a372b; }
.drawer-bio button, .drawer-actions button { width: 100%; color: #f6f1ea; border-color: #6a5a4c; }
.drawer .err { color: #f3b4a4; }
main { padding: 14px; padding-bottom: calc(18px + var(--safe-bottom)); max-width: none; margin: 0 auto; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px;
}
.block {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px;
}
.block h2 { margin: 0 0 6px; font-size: 18px; }
.block h3 { margin: 12px 0 4px; font-size: 15px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; line-height: 1.4; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.kpi b { display: block; font-size: 22px; }
.muted, .kpi span { color: var(--muted); font-size: 12px; }
.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  max-height: calc(100dvh - 200px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.table-wrap table {
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}
.table-wrap th, .table-wrap td {
  text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line);
  vertical-align: middle; background: #fffaf4;
}
.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #efe4d8;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.table-wrap thead tr:nth-child(2) th { top: 28px; z-index: 3; }
.table-wrap td.num, .table-wrap th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap tbody tr:hover:not(.row-l1):not(.row-l2) td { filter: brightness(0.97); }
.row-l1 td { font-weight: 700; background: #e8d9c8 !important; }
.row-l2 td { font-weight: 600; background: #f3ebe2 !important; }
.row-sku td:nth-child(5) { padding-left: 14px; }
.toggle {
  background: none; border: 0; padding: 0; margin: 0; width: auto; min-height: 0;
  color: inherit; font: inherit; font-weight: 700; cursor: pointer; text-align: left;
}
.freeze-1 td:nth-child(1), .freeze-1 thead th:nth-child(1),
.freeze-5 tbody td:nth-child(1), .freeze-5 thead tr:first-child th:nth-child(1) {
  position: sticky; left: 0; z-index: 2; min-width: 8.5em; max-width: 14em;
  box-shadow: 4px 0 6px -4px rgba(43,33,24,.35);
}
.freeze-5 tbody td:nth-child(2), .freeze-5 thead tr:first-child th:nth-child(2) {
  position: sticky; left: 8.5em; z-index: 2; min-width: 7em;
}
.freeze-5 tbody td:nth-child(3), .freeze-5 thead tr:first-child th:nth-child(3) {
  position: sticky; left: 15.5em; z-index: 2; min-width: 5.5em;
}
.freeze-5 tbody td:nth-child(4), .freeze-5 thead tr:first-child th:nth-child(4) {
  position: sticky; left: 21em; z-index: 2; min-width: 6em;
}
.freeze-5 tbody td:nth-child(5), .freeze-5 thead tr:first-child th:nth-child(5) {
  position: sticky; left: 27em; z-index: 2; min-width: 12em; max-width: 18em;
  box-shadow: 6px 0 8px -6px rgba(43,33,24,.35);
}
.freeze-5 thead tr:first-child th:nth-child(-n+5) { z-index: 6; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-bottom: 12px; }
.chart-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.chart-card svg { width: 100%; height: 180px; display: block; }
.chart-card .tick { font-size: 10px; fill: #7a6b5d; }
.leg-row { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; margin-bottom: 4px; }
.leg { display: flex; align-items: center; gap: 6px; }
.leg i { width: 14px; height: 3px; display: inline-block; border-radius: 2px; }
.ser-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 12px; }
.chk { flex-direction: row; align-items: center; gap: 6px; margin: 0; font-size: 13px; }
.chk input { width: auto; min-height: 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: end; }
.toolbar label { flex-direction: row; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--muted); }
.toolbar input, .toolbar select {
  padding: 8px; border: 1px solid var(--line); border-radius: 8px;
  min-height: 40px; font-size: 16px; flex: 1;
}
.toolbar button { width: auto; padding: 8px 12px; }
input, select, button { font: inherit; }
label { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
label input {
  min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; /* iOS: no zoom on focus */
}
button {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 12px 14px; cursor: pointer; min-height: 44px; width: 100%;
}
button.ghost { background: transparent; border: 1px solid #cbb; color: inherit; }
header button, .who button, .burger { width: auto; }
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; padding-bottom: calc(16px + var(--safe-bottom)); }
.login-card { width: min(360px, 100%); }
.login-card button { margin-top: 8px; }
.err { color: #a33; min-height: 1.2em; }
@media (max-width: 720px) {
  main { padding: 10px; }
}
@media (min-width: 900px) {
  .who-name { flex: 0 0 auto; max-width: 140px; }
  .nav-desktop { display: flex; flex: 1; }
  .nav-desktop a { color: #f6f1ea; white-space: nowrap; padding: 8px 10px; }
}
