/* Кофейня: кремовый фон, тёмно-коричневый текст, карамельный акцент на данных. */
:root {
  --ground: #F6EFE3;
  --surface: #FFFBF4;
  --sunken: #F1E7D7;
  --border: #E2D4BF;
  --rule: #EDE2D1;
  --control: #CDBBA2;
  --ink: #2A1A0F;
  --muted: #6F5A47;
  --accent: #BF7A2D;
  --accent-ink: #84490C;
  --tint: #F3E0C4;
  --neg: #A1381B;
  --neg-tint: #F8DFD4;
  --pos: #2C6638;
  --warn: #7E5200;
  --warn-tint: #FAE9C3;
  --radius: 10px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 15px/1.45 var(--font); }
body.no-scroll { overflow: hidden; }
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1 { font-size: 26px; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; margin-top: 8px; }
a { color: var(--accent-ink); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.r { text-align: right; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; border-radius: 6px; }

/* ---------- каркас: навигация сбоку на компьютере, снизу на телефоне ---------- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 12px; display: flex; flex-direction: column; gap: 24px; border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px; color: var(--ink); text-decoration: none; }
.brand strong { display: block; font-size: 16px; line-height: 1.2; }
.brand small { display: block; font-size: 12px; color: var(--muted); }
.brand-mark { width: 28px; height: 28px; border-radius: 50%; background: var(--ink); box-shadow: inset 0 0 0 7px var(--ink), inset 0 0 0 10px var(--accent); flex: none; }
.nav { display: grid; gap: 2px; }
.nav-link { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 10px; border-radius: 8px; border: 0; background: none; color: var(--muted); text-decoration: none; cursor: pointer; text-align: left; }
.nav-link:hover { background: var(--sunken); color: var(--ink); }
.nav-link.is-active { background: var(--tint); color: var(--ink); font-weight: 600; }
.nav-link.is-active .icon { stroke: var(--accent-ink); }
.nav-logout { margin-top: auto; }
.tabbar { display: none; }
.main { padding: 32px 40px 64px; min-width: 0; }
.view { max-width: 1160px; margin: 0 auto; display: grid; gap: var(--gap); }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-sub { margin-top: 4px; }
.head-actions, .state-actions, .sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Одноколоночные сетки не растягиваются под широкое содержимое (таблицы, ряды кнопок). */
.view, .card, .card-pad, .chart, .sheet-body, .form, .settings, .import-stage, .import-result { grid-template-columns: minmax(0, 1fr); }

/* ---------- кнопки и поля ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid transparent; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background-color .15s, transform .1s; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--ink); color: var(--surface); }
.btn-primary:hover:not(:disabled) { background: #46301F; }
.btn-ghost { background: var(--surface); border-color: var(--control); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--sunken); }
.btn-danger { background: var(--surface); border-color: var(--neg); color: var(--neg); }
.btn-danger:hover:not(:disabled) { background: var(--neg-tint); }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--accent-ink); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-align: left; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 8px; border: 0; background: none; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
input[type=text], input[type=password], input[type=date], input[type=datetime-local], input[type=file], select {
  width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--control); border-radius: 8px; background: var(--surface); min-width: 0; }
input[type=file] { padding: 7px; }
select { appearance: none; padding-right: 30px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236F5A47' stroke-width='1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 11px; }
input:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--accent-ink); }
.field { display: grid; gap: 4px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; }
.field-hint { font-size: 13px; color: var(--muted); }
.form { display: grid; gap: 14px; }
.form-error { color: var(--neg); font-weight: 600; }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }
.inline-form { display: flex; gap: 8px; align-items: flex-end; }
.inline-form > :first-child { flex: 1; }

/* ---------- фильтры ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-location { width: auto; min-width: 180px; max-width: 100%; font-weight: 600; }
.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--sunken); gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar, .toolbar-actions::-webkit-scrollbar { display: none; }
.segmented button { min-height: 34px; padding: 0 12px; border: 0; border-radius: 7px; background: none; color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; }
.segmented button.is-on { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--border); }
.filter-custom { display: flex; gap: 6px; align-items: center; }
.filter-custom input { width: 150px; }
.toolbar, .tabs-row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; min-width: 0; display: grid; gap: 12px; align-content: start; }
.card-flush { padding: 0; gap: 0; overflow: hidden; }
.card-pad { padding: 16px 20px; display: grid; gap: 12px; justify-items: start; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; min-height: 34px; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--gap); align-items: start; }
.profit-value { font-size: 46px; line-height: 1.1; font-weight: 700; letter-spacing: -0.02em; }
.profit-delta { font-size: 16px; }
.delta { font-weight: 700; }
.pill { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; white-space: nowrap; margin-left: 6px; vertical-align: middle; }
.card-head .pill { margin-left: 0; }
.pill-warn { background: var(--warn-tint); color: var(--warn); }
.pill-neg { background: var(--neg-tint); color: var(--neg); }
.notice { background: var(--warn-tint); border-radius: 8px; padding: 14px 16px; display: grid; gap: 10px; color: #4A3200; }
.notice-slim { display: block; }
.notice-list { display: grid; gap: 6px; }
.notice-list li { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.notice-foot { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.notice .muted { color: #6B4A00; }
.finding { font-size: 16px; }

/* ---------- состояния ---------- */
.state { padding: 20px; display: grid; gap: 12px; justify-items: start; color: var(--muted); }
.card > .state { padding: 4px 0; }
.state-error p { color: var(--neg); font-weight: 600; }
.first-run { max-width: 640px; }
.first-run h2 { font-size: 20px; }
.skeleton { display: grid; gap: 12px; padding: 4px 0; }
.card-flush > .skeleton { padding: 20px; }
.bone { height: 14px; border-radius: 4px; background: var(--sunken); animation: pulse 1.2s ease-in-out infinite alternate; }
.bone-tall { height: 44px; }
@keyframes pulse { from { opacity: 1; } to { opacity: .45; } }

/* ---------- списки и таблицы ---------- */
.rows > li + li { border-top: 1px solid var(--rule); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 52px; padding: 8px 0; text-align: left; }
.card-flush .row { padding: 8px 20px; }
.row-btn { background: none; border: 0; cursor: pointer; border-radius: 6px; }
.row-btn:hover { background: var(--sunken); }
.card:not(.card-flush) .row-btn { margin: 0 -8px; padding: 8px; width: calc(100% + 16px); }
.row-main { display: grid; min-width: 0; }
.row-title { font-weight: 600; }
.row-sub { display: block; font-size: 13px; color: var(--muted); font-weight: 400; }
.row-num { font-weight: 700; white-space: nowrap; }
.table { width: 100%; border-collapse: collapse; }
.table th { font-size: 13px; font-weight: 500; color: var(--muted); text-align: left; padding: 12px 12px 8px; white-space: nowrap; }
.table td { padding: 12px; border-top: 1px solid var(--rule); vertical-align: top; }
.table th.r, .table td.r { text-align: right; }
.table th:first-child, .table td:first-child { padding-left: 20px; }
.table th:last-child, .table td:last-child { padding-right: 20px; }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover, .table-click tbody tr:focus-visible { background: var(--sunken); }
.table-compact th, .table-compact td { padding: 8px 10px; font-size: 14px; }
.table-compact th:first-child, .table-compact td:first-child { padding-left: 0; }
.table-compact th:last-child, .table-compact td:last-child { padding-right: 0; }
.table-scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: 8px; padding: 0 12px; }
.table-scroll td { white-space: nowrap; }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--rule); min-height: 64px; }
.table td.r .row-sub, .table td.r { white-space: nowrap; }
.show-m { display: none; }

/* ---------- график ---------- */
.chart { display: grid; gap: 6px; width: 100%; justify-self: stretch; }
.chart-readout { font-size: 14px; color: var(--muted); min-height: 21px; }
.chart-plot { position: relative; margin-left: var(--ymargin, 38px); }
.chart-grid { position: absolute; inset: 0; }
.chart-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--rule); }
.chart-line:last-child { border-top: 1px solid var(--control); }
.chart-line span { position: absolute; right: 100%; margin-right: 8px; transform: translateY(-50%); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-cols { position: absolute; inset: 0; display: flex; gap: 3px; }
.bar-col { flex: 1; justify-content: center; min-width: 0; height: 100%; padding: 0; border: 0; background: none; cursor: pointer; display: flex; align-items: flex-end; border-radius: 3px; }
.bar { width: 100%; max-width: 56px; margin: 0 auto; height: 100%; background: var(--accent); transform-origin: bottom; transform: scaleY(0); border-radius: 2px 2px 0 0; }
.bar-col:hover .bar, .bar-col.is-active .bar, .bar-peak { background: var(--accent-ink); }
.chart-x { display: flex; gap: 3px; margin-left: var(--ymargin, 38px); }
.chart-x span { flex: 1; min-width: 0; text-align: center; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: visible; }
.chart-x span.is-hidden { visibility: hidden; }
.chart-x-dense span:last-child { display: flex; justify-content: flex-end; }
.barlist { display: grid; gap: 12px; }
.barlist li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; }
.barlist-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barlist-value { font-weight: 700; }
.barlist-track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.barlist-fill { display: block; height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0); }

/* ---------- панель: карточка ингредиента, формы ---------- */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(42, 26, 15, 0.38); display: flex; justify-content: flex-end; }
.sheet { width: min(480px, 100%); height: 100%; background: var(--ground); display: flex; flex-direction: column; outline: none; box-shadow: -12px 0 32px rgba(42, 26, 15, 0.16); }
.sheet-wide { width: min(640px, 100%); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 20px 12px 24px; }
.sheet-head h2 { font-size: 20px; line-height: 1.25; }
.sheet-body { flex: 1; overflow-y: auto; padding: 8px 24px 24px; display: grid; gap: 14px; align-content: start; overscroll-behavior: contain; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 24px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }
.sheet-foot .btn-danger { margin-right: auto; }
.stock-cells { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stock-cell { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 6px; }
.stock-qty { font-size: 28px; font-weight: 700; line-height: 1.15; }
.recipe-rows { display: grid; gap: 8px; }
.recipe-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px 28px 40px; gap: 8px; align-items: center; }
.line-row, .line-head { display: grid; grid-template-columns: minmax(0, 1fr) 60px 84px 84px 40px; gap: 8px; align-items: center; }
.receipt-total { font-size: 20px; font-weight: 700; }
.inv-rows { display: grid; }
.inv-row { display: grid; grid-template-columns: minmax(0, 1fr) 104px 104px; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--rule); }
.inv-row:first-child { border-top: 0; }
.inv-diff { text-align: right; font-weight: 600; font-size: 14px; }
.map-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.kpis > div { padding: 12px 16px; display: grid; gap: 2px; }
.kpis > div + div { border-left: 1px solid var(--rule); }
.kpis strong { font-size: 24px; line-height: 1.2; }
.import-result, .import-stage, .import-errors { display: grid; gap: 12px; }
.import-errors ul { display: grid; gap: 4px; font-size: 14px; color: var(--neg); }

/* ---------- бизнес (Poster) ---------- */
.biz { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); }
.biz-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); align-items: start; }
.kpis-5 { grid-template-columns: repeat(5, 1fr); }
.kpis-5 strong { font-size: 26px; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 6px; }
.dot-neg { background: var(--neg); }
.dot-warn { background: #C4901C; }
.row-top { align-items: flex-start; justify-content: flex-start; }
.row-where { font-weight: 400; }
.signal { display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.signal:hover { background: var(--sunken); }
.signal .row-main { flex: 1; }
.signal .link { align-self: center; white-space: nowrap; }
.card-flush > .card-pad h3 { margin: 0; }

/* ---------- настройки ---------- */
.settings { display: grid; gap: 24px; }
.set-row { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; }
.set-label { display: grid; gap: 4px; padding-top: 4px; }
.set-panel .card-pad + .card-pad, .set-panel .rows + .card-pad { border-top: 1px solid var(--rule); }

/* ---------- вход, уведомления ---------- */
.login-wrap { grid-column: 1 / -1; min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.login .brand { padding: 0; }
.login h1 { font-size: 22px; }
.toasts { position: fixed; z-index: 60; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100% - 32px)); }
.toast { background: var(--ink); color: var(--surface); padding: 12px 16px; border-radius: 10px; font-weight: 500; box-shadow: 0 8px 24px rgba(42, 26, 15, 0.25); }
.toast-error { background: var(--neg); }

/* ---------- телефон и планшет ---------- */
@media (max-width: 1100px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .set-row { grid-template-columns: minmax(0, 1fr); gap: 10px; }
}
@media (max-width: 859px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .main { padding: 20px 16px calc(88px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar .nav-link { flex-direction: column; justify-content: center; gap: 2px; height: 52px; padding: 0; font-size: 12px; }
  .tabbar .nav-link.is-active { background: none; color: var(--accent-ink); }
  .tabbar .nav-link .icon { width: 22px; height: 22px; }
  .page-head .btn-primary { min-height: 44px; }
  .btn, .segmented button, input[type=text], input[type=password], input[type=date], input[type=datetime-local], select { min-height: 44px; }
  .segmented button { min-height: 38px; }
  input, select { font-size: 16px; } /* иначе iOS увеличивает страницу при вводе */
  .filters { width: 100%; }
  .filter-location { flex: 1 1 100%; }
  .filters .segmented { flex: 1 1 100%; }
  .filters .segmented button { flex: 1; padding: 0 6px; }
  .filter-custom { flex: 1 1 100%; }
  .filter-custom input { flex: 1; width: auto; }
  .toolbar { display: grid; grid-template-columns: minmax(0, 1fr); }
  .toolbar-actions { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px; scrollbar-width: none; }
  .tabs-row .segmented { flex: 1 1 100%; }
  .card { padding: 16px; }
  .card-flush { padding: 0; }
  .card-flush .row, .card-pad { padding-left: 16px; padding-right: 16px; }
  .profit-value { font-size: 38px; }
  .hide-m { display: none; }
  .show-m { display: block; }
  span.show-m { display: block; }
  .table th:first-child, .table td:first-child { padding-left: 16px; }
  .table th:last-child, .table td:last-child { padding-right: 16px; }
  .table td .pill { margin: 4px 0 0; }
  .table-compact th:first-child, .table-compact td:first-child { padding-left: 0; }
  .table-compact th:last-child, .table-compact td:last-child { padding-right: 0; }
  .table-foot { padding: 12px 16px; }
  .chart-cols, .chart-x { gap: 2px; }
  .backdrop { align-items: flex-end; }
  .sheet, .sheet-wide { width: 100%; height: auto; max-height: 94dvh; border-radius: 16px 16px 0 0; box-shadow: 0 -12px 32px rgba(42, 26, 15, 0.16); }
  .sheet-head { padding: 16px 12px 8px 16px; }
  .sheet-body { padding: 8px 16px 20px; }
  .sheet-foot { padding-left: 16px; padding-right: 16px; }
  .sheet-foot .btn { flex: 1; }
  .sheet-foot .btn-danger { flex: 0 1 auto; }
  .map-grid { grid-template-columns: minmax(0, 1fr); }
  .kpis:not(.kpis-5) { grid-template-columns: minmax(0, 1fr); }
  .kpis:not(.kpis-5) > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 14px; }
  .kpis:not(.kpis-5) > div + div { border-left: 0; border-top: 1px solid var(--rule); }
  .kpis:not(.kpis-5) strong { font-size: 20px; white-space: nowrap; }
  .kpis-5 { grid-template-columns: repeat(2, 1fr); }
  .kpis-5 > div { border-left: 0 !important; border-top: 1px solid var(--rule); }
  .kpis-5 > div:nth-child(-n+2) { border-top: 0; }
  .kpis-5 > div:nth-child(even) { border-left: 1px solid var(--rule) !important; }
  .kpis-5 > div:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .kpis-5 strong { font-size: 22px; }
  .tabbar .nav-link { font-size: 11px; }
  .line-row, .line-head { grid-template-columns: minmax(0, 1fr) 52px 72px 72px 36px; gap: 6px; }
  .line-row .icon-btn { width: 36px; }
  .inv-row { grid-template-columns: minmax(0, 1fr) 88px 84px; }
  .toasts { bottom: calc(80px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
