/* Спокойный светлый интерфейс. Цвет никогда не единственный носитель смысла — рядом всегда текст. */
:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e1e5ea; --text: #1d232b; --muted: #5d6875;
  --accent: #2f6f5e; --accent-soft: #e5f1ed; --pos: #1d7a46; --pos-soft: #e3f4ea; --neg: #b42318; --neg-soft: #fde8e6;
  --amber: #9a5b00; --amber-soft: #fff1d6; --info: #2459a8; --info-soft: #e6eefb; --ozon: #005bff; --wb: #8b1fa9;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --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(--bg); color: var(--text); font: 15px/1.45 var(--font); }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .2rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.2rem 0 .4rem; }
code { font-size: .85em; background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: 1rem; }
:focus-visible { outline: 3px solid #7aa7ff; outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner { max-width: 1280px; margin: 0 auto; padding: .6rem 16px; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: .01em; }
.nav { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.nav a { color: var(--muted); text-decoration: none; padding: .35rem .6rem; border-radius: 8px; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a:hover { color: var(--text); }
.logout { display: flex; align-items: center; gap: .5rem; margin: 0; }
.who { color: var(--muted); font-size: .9rem; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 1rem 16px 3rem; }
.page-head { margin: .5rem 0 1rem; }
.sub { color: var(--muted); margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.notice { background: var(--amber-soft); color: #5b3a00; border: 1px solid #f2d49b; padding: .6rem .8rem; border-radius: 8px; margin-bottom: .75rem; }

.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: .45rem .8rem; cursor: pointer; }
.btn:hover { border-color: #c9d0d8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.link, button.link { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-align: left; }
.icon-btn { font: inherit; background: none; border: 1px solid var(--border); border-radius: 8px; width: 2.2rem; height: 2.2rem; cursor: pointer; }

/* фильтры */
.filters { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; margin-bottom: 1rem; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg-btn { padding: .4rem .85rem; border-radius: 7px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.seg-btn[aria-current="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.store-form { margin: 0; }
select, input { font: inherit; border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem; background: var(--surface); color: var(--text); max-width: 100%; }

.syncbar { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: 1rem; font-size: .9rem; }
.sync-item { display: flex; flex-wrap: wrap; gap: .2rem .8rem; align-items: center; }
.sync-item.is-error { color: var(--neg); }
.sync-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.sync-job { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }

.blocks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.blocks .card { margin: 0; }
.block-stock, .block-profit, .block-supplies { grid-column: 1 / -1; }
.kpi tbody th { width: 40%; }
.loading { color: var(--muted); padding: .75rem 0; display: flex; align-items: center; gap: .5rem; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.foot { color: var(--muted); font-size: .82rem; margin: .6rem 0 0; }
.recon { background: var(--surface-2); border-radius: 8px; padding: .5rem .7rem; font-size: .9rem; }

/* таблицы */
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi tbody th { font-weight: 500; }
.row-note, .cell-note, .t-meta { display: block; font-size: .78rem; color: var(--muted); font-weight: 400; white-space: normal; }
.t-name { display: block; font-weight: 500; }
.table-scroll { overflow-x: auto; }
.val { font-weight: 600; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
tr.risk-red td:first-child { box-shadow: inset 3px 0 0 var(--neg); }
tr.risk-amber td:first-child { box-shadow: inset 3px 0 0 #e0a100; }

.state { font-size: .85rem; color: var(--muted); font-style: italic; }
.state-error { color: var(--neg); }
.state-no_cost, .state-not_connected { color: var(--amber); }
.state-box { border: 1px dashed var(--border); border-radius: 8px; padding: .75rem; color: var(--muted); background: var(--surface-2); margin-bottom: 1rem; }
.state-box.state-error { border-color: #f1b4ae; background: var(--neg-soft); color: var(--neg); font-style: normal; }
.state-box.state-no_cost, .state-box.state-not_connected { border-color: #f2d49b; background: var(--amber-soft); color: #5b3a00; font-style: normal; }
.badge { display: inline-block; font-size: .72rem; line-height: 1.3; padding: .05rem .4rem; border-radius: 999px; margin-left: .3rem; vertical-align: middle; font-style: normal; font-weight: 500; white-space: nowrap; }
.badge-prelim { background: var(--info-soft); color: var(--info); }
.badge-partial, .badge-amber, .badge-stale { background: var(--amber-soft); color: var(--amber); }
.badge-error, .badge-red { background: var(--neg-soft); color: var(--neg); }
.badge-ok { background: var(--pos-soft); color: var(--pos); }
.mp { display: inline-block; font-size: .72rem; font-weight: 700; padding: 0 .35rem; border-radius: 4px; color: #fff; }
.mp-ozon { background: var(--ozon); }
.mp-wb { background: var(--wb); }

/* аналитика */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: 1rem 0; }
.tab { padding: .55rem 1rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.metric-bar { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .6rem; }
.chip { padding: .3rem .7rem; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; color: var(--text); background: var(--surface); font-size: .88rem; }
.chip[aria-current="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.metric-info { font-size: .9rem; padding: .6rem .8rem; }
.cov-line { display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; font-size: .85rem; color: var(--muted); margin-bottom: .6rem; }
.sort-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; font-size: .9rem; }
.pcards { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: .75rem; }
.pcard-btn { display: flex; gap: .75rem; width: 100%; text-align: left; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; cursor: pointer; box-shadow: var(--shadow); height: 100%; }
.pcard-btn:hover { border-color: #c4ccd5; }
.thumb { width: 72px; height: 96px; object-fit: cover; border-radius: 6px; background: var(--surface-2); flex: none; }
.pcard-body { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.pcard-title { font-weight: 600; line-height: 1.25; }
.pcard-meta { font-size: .76rem; color: var(--muted); }
.pcard-value { font-size: 1.05rem; }
.pcard-mlabel { display: block; font-size: .72rem; color: var(--muted); }
.pcard-per { font-size: .78rem; color: var(--muted); }
.spark { fill: #9fc3b7; margin-top: .2rem; }
.side-list { margin-top: 1.25rem; }
.pcards.compact { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.summary-cell h3 { margin-top: 0; }
.summary-cell .big { font-size: 1.35rem; }
.mini { margin: .3rem 0; padding-left: 1.1rem; font-size: .88rem; }
.mode-seg { margin-bottom: 1rem; }
.sub-table summary { cursor: pointer; color: var(--accent); margin-top: .5rem; }
.cap-sources h2 { margin-top: 0; }

/* модальное окно */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--text); }
dialog::backdrop { background: rgba(20, 26, 33, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 1rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 1rem; }
.item-parts { display: flex; flex-wrap: wrap; gap: 1rem; }
.item-part { display: flex; gap: .7rem; align-items: flex-start; flex: 1 1 320px; }
.chart { width: 100%; height: 160px; }
.chart .axis { stroke: #c9d0d8; }
.chart .tick { font-size: 10px; fill: var(--muted); }
.s-orders { fill: #c9d6e6; background: #c9d6e6; }
.s-delivered { fill: #2f6f5e; background: #2f6f5e; }
.s-returned { fill: #d06a5f; background: #d06a5f; }
.s-revenue { fill: #8fb9ab; background: #8fb9ab; }
.s-expenses { fill: #e3a29a; background: #e3a29a; }
.s-result { fill: #2459a8; background: #2459a8; }
.legend { font-size: .8rem; color: var(--muted); }
.sw { display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; margin: 0 .25rem 0 .6rem; vertical-align: -1px; }

/* формы и прочее */
.login { max-width: 380px; margin: 4rem auto; }
.login form, .form-grid { display: grid; gap: .5rem; }
.form-grid { grid-template-columns: max-content minmax(0, 360px); align-items: center; }
.form-grid button { grid-column: 2; justify-self: start; }
form.inline { display: block; margin: .15rem 0; }
.metric-def dl { display: grid; grid-template-columns: 10rem 1fr; gap: .3rem 1rem; margin: 0; }
.metric-def dt { color: var(--muted); }
.metric-def dd { margin: 0; }

@media (max-width: 900px) {
  .blocks { grid-template-columns: minmax(0, 1fr); }
  .summary-grid { grid-template-columns: minmax(0, 1fr); }
  .sync-actions { margin-left: 0; }
}
/* Телефон: колонки таблиц превращаются в подписанные строки */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .kpi thead, .list thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .kpi tr, .list tr { display: block; border-bottom: 1px solid var(--border); padding: .4rem 0; }
  .kpi th, .kpi td, .list td { display: block; border: 0; padding: .15rem 0; text-align: left; white-space: normal; }
  .kpi td[data-label]::before, .list td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .8rem; }
  .table-scroll { overflow: visible; }
  .metric-def dl { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid button { grid-column: 1; }
  .pcards { grid-template-columns: minmax(0, 1fr); }
  .filters { gap: .5rem; }
  .seg { flex-wrap: wrap; }
  .top-inner { gap: .4rem .8rem; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav a { white-space: nowrap; }
  .logout { margin-left: auto; }
  .kpi tbody th { width: auto; }
}
