/* Лаборатория Шлейфа — оформление «Travertino»: римский камень, тушь, бордо. */

:root {
  --ground: #E7E3DB;
  --surface: #F4F2EE;
  --surface-2: #DCD6CC;
  --field: #DCD6CC;
  --field-ink: #1E1B18;
  --field-ink-2: #5E574F;
  --field-hover: #D2CBC0;
  --ink: #1E1B18;
  --ink-2: #5A534B;
  --line: #D9D3C9;
  --accent: #7A2232;
  --accent-hover: #8E2A3B;
  --accent-ink: #F8F2EF;
  --c-profit: #8E2A3B;
  --c-cost: #8F8170;
  --liquid: #B89A72;
  --liquid-low: #8E2A3B;
  --glass: #A79E92;
  --good: #3D6B4A;
  --bad: #8E2A3B;
  --font-display: "Forum", "Times New Roman", serif;
  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;

  --side-w: 248px;
  --gap: 20px;
  --pad: 28px;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --t-fast: 160ms;
  --t-drawer: 280ms;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 400; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Каркас ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: 32px 24px 24px;
  background: var(--field); color: var(--field-ink);
}
.wordmark { font-family: var(--font-display); font-size: 28px; line-height: 1.05; color: inherit; text-decoration: none; }
.side-nav { display: grid; gap: 2px; margin-top: 48px; }
.side-nav a {
  padding: 9px 12px; margin: 0 -12px;
  color: var(--field-ink-2); text-decoration: none; font-size: 15px;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}
.side-nav a:hover { background: var(--field-hover); color: var(--field-ink); }
.side-nav a[aria-current="page"] { color: var(--field-ink); background: var(--field-hover); }
.side-foot { margin-top: auto; }
.logout { border: 0; background: none; padding: 0; color: var(--field-ink-2); font-size: 14px; }
.logout:hover { color: var(--field-ink); }
.topbar, .tabbar { display: none; }

.main { width: 100%; max-width: 1240px; padding: 36px 40px 64px; display: grid; gap: var(--gap); align-content: start; }

/* ---------- Шапка и кнопки ---------- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.head h1 { font-family: var(--font-display); font-size: 46px; line-height: 1; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 22px;
  border: 0; border-radius: 0; text-decoration: none;
  font-weight: 500; font-size: 15px;
  transition: background-color var(--t-fast) ease, transform var(--t-fast) var(--ease-out);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-quiet { background: var(--surface-2); color: var(--ink); }
.btn-quiet:hover { background: var(--line); }

/* ---------- Фильтры ---------- */
.filters { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.seg { display: inline-flex; background: var(--surface-2); padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 8px 14px; min-height: 38px;
  color: var(--ink-2); font-size: 14px; white-space: nowrap;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 500; }
.seg-small button { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.select select, .more select {
  appearance: none; border: 0; border-radius: 0;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%235A534B' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center;
  padding: 0 34px 0 14px; min-height: 44px; font-size: 14px;
}
.more { position: relative; }
.more summary {
  list-style: none; cursor: pointer; min-height: 44px; display: flex; align-items: center;
  padding: 0 14px; background: var(--surface-2); font-size: 14px; color: var(--ink-2);
}
.more summary::-webkit-details-marker { display: none; }
.more[open] summary { color: var(--ink); }
.more-body {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  margin-top: 8px; padding: 16px; background: var(--surface);
}
.more-body .field input { background: var(--ground); }
.more-body .field select { background-color: var(--ground); }
.range { color: var(--ink-2); font-size: 14px; margin-left: auto; }
.filters:has(.more[open]) .range { margin-left: 0; width: 100%; }

/* ---------- Панели ---------- */
.panel { background: var(--surface); padding: var(--pad); }
.panel h2 { font-family: var(--font-display); font-size: 26px; line-height: 1.15; }
.lede { color: var(--ink-2); margin-top: 6px; max-width: 64ch; }
.summary { color: var(--ink-2); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.pair-wide { grid-template-columns: 1.35fr 1fr; }

/* ---------- Главные цифры ---------- */
.hero { display: grid; gap: 28px; }
.hero-figs { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 32px; align-items: end; }
.hero .fig-label { font-family: var(--font-ui); font-size: 15px; color: var(--ink-2); }
.fig-value { font-size: 64px; line-height: 1; font-weight: 500; letter-spacing: -0.03em; margin-top: 10px; white-space: nowrap; }
.fig-delta { margin-top: 10px; font-size: 14px; color: var(--ink-2); min-height: 21px; }
.up { color: var(--good); }
.down { color: var(--bad); }
.fig-side { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px; margin: 0; }
.fig-side div { display: grid; gap: 4px; align-content: end; }
.fig-side dt { color: var(--ink-2); font-size: 14px; }
.fig-side dd { margin: 0; font-size: 24px; line-height: 1.1; font-weight: 500; letter-spacing: -0.01em; white-space: nowrap; }
.fig-side dd.sub { font-size: 13px; font-weight: 400; color: var(--ink-2); letter-spacing: 0; }

/* ---------- Графики ---------- */
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.chart-head h3 { font-size: 15px; font-weight: 500; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; gap: 18px; font-size: 13px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 7px; }
.key { width: 10px; height: 10px; border-radius: 2px; }
.key-profit { background: var(--c-profit); }
.key-cost { background: var(--c-cost); }
.chart { position: relative; height: 240px; margin-top: 16px; }
.chart-tall { height: 280px; }

/* ---------- Склад: полка флаконов ---------- */
.shelf-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; }
.vials {
  list-style: none; margin: 28px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 26px 12px;
}
.vial { display: grid; justify-items: center; align-content: start; text-align: center; gap: 10px; }
.vial svg { width: 38px; height: 86px; overflow: visible; }
.vial .glass { fill: none; stroke: var(--glass); stroke-width: 1.5; }
.vial .cap { fill: var(--glass); }
.vial .juice { fill: var(--liquid); transform: scaleY(var(--fill)); transform-box: fill-box; transform-origin: bottom; }
.vial.low .juice { fill: var(--liquid-low); }
.vial .v-name { font-size: 13px; line-height: 1.3; }
.vial .v-brand { display: block; color: var(--ink-2); }
.vial .v-ml, .vial .v-idle { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.vial.low .v-ml { color: var(--ink); font-weight: 500; }
.vial .v-idle { display: none; }
.vials[data-mode="idle"] .v-ml { display: none; }
.vials[data-mode="idle"] .v-idle { display: block; }
.vials-empty { color: var(--ink-2); grid-column: 1 / -1; }
.shelf-more { margin-top: 24px; }

/* ---------- Таблицы ---------- */
.rank { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 14px; }
.rank th { text-align: left; font-weight: 400; color: var(--ink-2); padding: 0 0 10px; font-size: 13px; }
.rank td { padding: 11px 0; border-top: 1px solid var(--line); vertical-align: top; }
.rank .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 16px; }
.rank .who { display: block; color: var(--ink-2); font-size: 13px; }
.bar { display: block; height: 3px; margin-top: 8px; background: var(--c-profit); border-radius: 0 2px 2px 0; }

.clients { list-style: none; margin: 18px 0 0; padding: 0; font-size: 14px; }
.clients li { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.clients .c-n { color: var(--ink-2); font-size: 13px; }
.clients .num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Выезжающая панель с формой ---------- */
.scrim { position: fixed; inset: 0; background: rgba(30, 27, 24, .38); opacity: 0; transition: opacity var(--t-drawer) ease; z-index: 20; }
.scrim.on { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: min(540px, 100vw);
  background: var(--surface); color: var(--ink);
  box-shadow: -24px 0 48px rgba(30, 27, 24, .18);
  transform: translateX(100%);
  transition: transform var(--t-drawer) var(--ease-out);
  overflow-y: auto; overscroll-behavior: contain;
}
.drawer.on { transform: none; }
.sheet { display: grid; gap: 18px; padding: 28px 32px 32px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { font-family: var(--font-display); font-size: 32px; }
.close { border: 0; background: var(--surface-2); width: 44px; height: 44px; font-size: 22px; line-height: 1; }

.field { display: grid; gap: 6px; font-size: 14px; color: var(--ink-2); min-width: 0; margin: 0; padding: 0; border: 0; }
.field legend { padding: 0; margin-bottom: 6px; }
.field-row { display: flex; gap: 14px; align-items: flex-end; }
.field-row .field { flex: 0 0 auto; }
.field-row .grow { flex: 1 1 0; }
.field input:not([type="radio"]), .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 0; border-radius: 0; background: var(--ground); color: var(--ink);
  box-shadow: inset 0 -1px 0 var(--glass);
  font-size: 15px;
}
.field select { appearance: none; background: var(--ground) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%235A534B' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center; padding-right: 32px; }
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; box-shadow: inset 0 -2px 0 var(--accent); }
.has-error input, .has-error select, .has-error textarea { box-shadow: inset 0 -2px 0 var(--bad); }
.err { font-style: normal; color: var(--bad); font-size: 13px; }
.err-box { background: var(--surface-2); color: var(--ink); padding: 12px 14px; font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button, .chip span {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 0; background: var(--ground); color: var(--ink);
  min-height: 42px; min-width: 48px; padding: 0 14px; font-size: 15px; cursor: pointer;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease, transform var(--t-fast) var(--ease-out);
}
.chips button:hover, .chip span:hover { background: var(--surface-2); }
.chips button:active, .chip span:active { transform: scale(.96); }
.chips button[aria-pressed="true"], .chip input:checked + span { background: var(--ink); color: var(--surface); }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.field .chips .chip-input { width: 84px; min-height: 42px; text-align: center; }
.calc { color: var(--ink-2); font-size: 14px; min-height: 21px; padding-bottom: 12px; font-variant-numeric: tabular-nums; }
.more-fields summary { cursor: pointer; color: var(--ink-2); font-size: 14px; padding: 4px 0; }
.more-fields-body { display: grid; gap: 14px; margin-top: 12px; }
.sheet-foot { display: flex; gap: 10px; margin-top: 6px; position: sticky; bottom: 0; background: var(--surface); padding: 12px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 40; max-width: min(560px, calc(100vw - 32px));
  transform: translate(-50%, 12px); opacity: 0;
  background: var(--ink); color: var(--surface);
  padding: 12px 18px; font-size: 14px;
  transition: opacity 200ms ease, transform 200ms var(--ease-out);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Вход ---------- */
.auth { min-height: 100vh; display: grid; place-content: center; gap: 36px; padding: 32px 20px; }
.auth-mark { font-family: var(--font-display); font-size: 56px; line-height: 1; text-align: center; }
.auth-form { width: min(380px, 100%); display: grid; gap: 16px; background: var(--surface); padding: 28px; margin: 0 auto; }
.auth-form .field input { background: var(--ground); }
.auth-form .btn { width: 100%; margin-top: 4px; }

/* ---------- Узкие экраны и телефон ---------- */
@media (max-width: 1180px) {
  .hero-figs { grid-template-columns: 1fr; }
  .fig-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  :root { --pad: 20px; --gap: 14px; }
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 10;
    padding: 14px 20px; background: var(--field); color: var(--field-ink);
  }
  .topbar .wordmark { font-size: 21px; }
  .main { padding: 20px 16px 104px; }
  .head h1 { font-size: 36px; }
  .head .actions { display: none; }
  .filters { gap: 10px; }
  .filters .seg, .select, .select select, .more, .more summary { width: 100%; }
  .seg button { flex: 1; padding: 8px 6px; font-size: 13px; }
  .more-body .field { flex: 1 1 140px; }
  .range { margin-left: 0; }
  .fig-value { font-size: 46px; }
  .fig-side { gap: 18px 14px; }
  .fig-side dd { font-size: 20px; }
  .pair, .pair-wide { grid-template-columns: 1fr; }
  .chart-tall { height: 240px; }
  .shelf-head .seg { width: 100%; }
  .vials { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 22px 6px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    background: var(--field); padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  }
  .tabbar a {
    color: var(--field-ink-2); min-height: 48px; font-size: 14px; text-decoration: none;
    display: flex; align-items: center; justify-content: center;
  }
  .tabbar [aria-current="page"] { color: var(--field-ink); }
  .tabbar .tab-main { background: var(--accent); color: var(--accent-ink); font-weight: 500; }
  .sheet { padding: 22px 18px 28px; }
  .field-row { flex-wrap: wrap; }
  .field-row .grow { flex-basis: 100%; }
  .auth-mark { font-size: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation: none !important; }
}
