:root {
  --bg: #f3f6f3;
  --panel: #ffffff;
  --ink: #15241d;
  --muted: #64756c;
  --line: #e1e8e3;
  --line-strong: #cdd8d0;
  --accent: #0f766e;
  --accent-dark: #0b5d57;
  --accent-soft: #e6f4f1;
  --good: #0f7a4a;
  --good-soft: #e7f6ee;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --shadow: 0 12px 30px rgba(16, 42, 32, 0.08);
  --radius: 14px;
  --radius-sm: 9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.warn { color: var(--warn); }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 22px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--accent); color: #fff;
  font-size: 12px; letter-spacing: 0.4px;
}
.brand-sub { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: 0.2px; }
.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.store-switch { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.store-switch select {
  border: 1px solid var(--line-strong); border-radius: 8px; background: #fff;
  padding: 7px 10px; font-size: 13px; color: var(--ink); max-width: 260px;
}
.user { font-size: 13px; color: var(--muted); }
.demo-badge {
  background: var(--warn-soft); color: var(--warn);
  border: 1px solid #f0d3a4; border-radius: 999px;
  padding: 3px 10px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.3px;
}

/* ------------------------------------------------------------------ tabs */
.tabs {
  display: flex; gap: 4px; padding: 0 18px;
  background: #fff; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 11px 14px; color: var(--muted); font-size: 13.5px; font-weight: 600;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

.demo-strip {
  background: linear-gradient(90deg, #fff8ec, #fffdf8);
  border-bottom: 1px solid #f2e2c4;
  color: #7a4a08; font-size: 12.5px;
  padding: 8px 22px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.demo-strip strong { color: #613a05; }
.demo-strip .close-strip {
  margin-left: auto; background: none; border: 0; color: #7a4a08;
  cursor: pointer; font-size: 16px; line-height: 1;
}

/* ----------------------------------------------------------------- layout */
.view { max-width: 1320px; margin: 0 auto; padding: 22px 20px 48px; }
.view:focus, .view:focus-visible { outline: none; }
.page-head {
  display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head h1 { font-size: 23px; margin: 0; letter-spacing: -0.3px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 14px; }
.panel-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-head .sub { color: var(--muted); font-size: 12px; }
.panel-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel-body { padding: 16px 18px; }
.panel-body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); }
.grid.kpi { grid-template-columns: repeat(5, minmax(0, 1fr)); }

/* ------------------------------------------------------------- controls */
.btn {
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
  border-radius: 9px; padding: 8px 13px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: #f1f5f2; }
.btn:disabled { opacity: 0.5; cursor: default; }

.seg { display: inline-flex; background: #eef2ef; border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 11px; border-radius: 7px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

input[type="text"], input[type="date"], input[type="number"], input[type="email"], input[type="password"], select {
  font-family: inherit; font-size: 13.5px; color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 8px 10px; background: #fff;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid rgba(15, 118, 110, 0.35); outline-offset: 1px;
}
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; color: var(--muted); }

.search-box { position: relative; min-width: 260px; flex: 1 1 280px; }
.search-box input { width: 100%; padding-right: 34px; }
.search-box .clear-search {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px;
}
.suggest {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 5px);
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); overflow: hidden;
}
.suggest button {
  display: flex; width: 100%; gap: 10px; align-items: baseline; text-align: left;
  background: #fff; border: 0; border-bottom: 1px solid var(--line);
  padding: 9px 12px; cursor: pointer; font-family: inherit; font-size: 13px; color: var(--ink);
}
.suggest button:last-child { border-bottom: 0; }
.suggest button:hover, .suggest button.active { background: var(--accent-soft); }
.suggest .sku { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.suggest .name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest .empty { padding: 10px 12px; color: var(--muted); font-size: 12.5px; }

/* --------------------------------------------------------------- kpi */
.kpi-card { padding: 14px 16px; }
.kpi-card .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.kpi-card .value { font-size: 24px; font-weight: 700; margin-top: 5px; letter-spacing: -0.4px; font-variant-numeric: tabular-nums; }
.kpi-card .value.sm { font-size: 19px; }
.kpi-card .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* --------------------------------------------------------------- table */
.table-wrap { overflow: auto; max-height: 68vh; }
.table-wrap.short { max-height: none; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.data thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f7faf8; color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data thead th.num { text-align: right; }
table.data tbody td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #fafcfb; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tfoot td {
  padding: 10px 12px; font-weight: 700; border-top: 1px solid var(--line-strong);
  background: #fbfcfb;
}
table.data td.first, table.data th.first { position: sticky; left: 0; background: inherit; }
table.data tbody tr:hover td.first { background: #fafcfb; }

.status {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 600;
  background: #eef2ef; color: var(--muted); white-space: nowrap;
}
.status.forecast { background: var(--warn-soft); color: var(--warn); }
.status.partial { background: #eaf1fd; color: #1d4ed8; }
.status.sold, .status.fact { background: var(--good-soft); color: var(--good); }
.status.returned { background: var(--bad-soft); color: var(--bad); }
.status.cancelled { background: #f1f1f1; color: #555; }
.status.blocked { background: var(--bad-soft); color: var(--bad); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 9px; font-size: 11.5px; color: var(--muted);
}
.chip b { color: var(--ink); font-weight: 600; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #b9c4bd; }
.chip .dot.ok { background: var(--good); }
.chip .dot.err { background: var(--bad); }
.chip .dot.warn { background: var(--warn); }

/* --------------------------------------------------------------- chart */
.chart-wrap { position: relative; padding: 6px 4px 0; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.chart-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 16px; height: 3px; border-radius: 2px; background: var(--accent); }
.chart-legend .swatch.prev { background: #9aa8a0; }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: #12211a; color: #fff; border-radius: 9px;
  padding: 8px 10px; font-size: 12px; line-height: 1.35;
  box-shadow: 0 10px 24px rgba(0,0,0,.2); min-width: 132px;
  transform: translate(-50%, -108%); opacity: 0; transition: opacity .08s;
}
.chart-tooltip.show { opacity: 1; }
.chart-tooltip .t-date { font-weight: 700; margin-bottom: 3px; }
.chart-tooltip .t-row { display: flex; justify-content: space-between; gap: 12px; color: #cfe0d6; }
.chart-tooltip .t-row b { color: #fff; }
.chart-empty { padding: 40px 10px; text-align: center; color: var(--muted); font-size: 13px; }

/* --------------------------------------------------------------- lists */
.notes { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.notes li { margin-bottom: 4px; }
.badge-list { display: flex; flex-wrap: wrap; gap: 6px; }

.empty-state {
  padding: 34px 18px; text-align: center; color: var(--muted); font-size: 13px;
}
.empty-state strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 5px; }

/* --------------------------------------------------------------- modal */
.modal {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: rgba(12, 24, 18, 0.48); padding: 18px;
}
.modal[hidden] { display: none; }
.modal-panel {
  width: min(1180px, 100%); max-height: 92vh; overflow: auto;
  background: #fff; border-radius: 16px; box-shadow: 0 30px 80px rgba(0,0,0,.25);
}
.modal-head {
  position: sticky; top: 0; z-index: 3; background: #fff;
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head .actions { margin-left: auto; }
.modal-body { padding: 18px 20px 26px; }
.modal-close { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.summary-item { background: #f7faf8; border-radius: 10px; padding: 10px 12px; }
.summary-item .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.summary-item .v { font-size: 17px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }

.drill-table td, .drill-table th { font-size: 12px; padding: 6px 8px; }
details.block { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
details.block summary { cursor: pointer; font-size: 13px; font-weight: 600; }
details.block[open] summary { margin-bottom: 8px; }

/* --------------------------------------------------------------- login */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(900px 500px at 15% 0%, #dcefe8 0%, transparent 60%),
    radial-gradient(700px 500px at 90% 100%, #e8f2ff 0%, transparent 55%),
    #f3f6f3;
}
.login-card {
  width: min(430px, 100%); background: #fff; border-radius: 18px;
  box-shadow: 0 24px 60px rgba(16, 42, 32, .16); padding: 26px 26px 22px;
}
.login-card .brand { margin-bottom: 18px; }
.login-card h1 { font-size: 20px; margin: 0 0 6px; }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.login-card form { display: grid; gap: 12px; }
.login-card .btn { width: 100%; padding: 10px; }
.login-hint {
  margin-top: 16px; font-size: 12px; color: var(--muted);
  background: #f7faf8; border-radius: 9px; padding: 10px 12px;
}
.login-hint code { font-family: var(--mono); font-size: 11.5px; color: var(--ink); }
.form-error { color: var(--bad); font-size: 12.5px; min-height: 17px; }

/* --------------------------------------------------------------- stocks */
.cluster-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.cluster-card { border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; }
.cluster-card .name { font-weight: 600; font-size: 13.5px; }
.cluster-card .big { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.cluster-card .meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.source-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px; }
.source-card { border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; }
.source-card .top { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.source-card .title { font-weight: 600; font-size: 13.5px; }
.source-card dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 10px 0 0; font-size: 12px; }
.source-card dt { color: var(--muted); }
.source-card dd { margin: 0; }
.source-card .err {
  margin-top: 8px; font-size: 12px; color: var(--bad); background: var(--bad-soft);
  border-radius: 7px; padding: 6px 8px;
}

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px);
  background: #12211a; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .18s; z-index: 200;
  box-shadow: 0 12px 30px rgba(0,0,0,.25);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot { max-width: 1320px; margin: 0 auto; padding: 0 20px 30px; color: var(--muted); font-size: 11.5px; }

.rnp-cards { display: none; }

.toolbar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.toolbar .seg { margin-bottom: 1px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.sku-head { display: flex; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.sku-head h2 { font-size: 20px; margin: 3px 0 0; letter-spacing: -0.2px; }
.totals-box { text-align: right; min-width: 178px; }
.totals-value { font-size: 27px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.alert {
  background: var(--bad-soft); color: var(--bad); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 12px; font-size: 12.5px;
}
.day-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff; }
.day-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
.day-profit { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.day-profit span { font-size: 12px; font-weight: 500; color: var(--muted); }
.day-meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.day-card .btn { margin-top: 8px; padding-left: 0; }

/* --------------------------------------------------------------- mobile */
@media (max-width: 1080px) {
  .grid.kpi { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  body { font-size: 14px; }
  .topbar { padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .brand { gap: 8px; font-size: 14px; }
  .brand > span:last-child { white-space: nowrap; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 11px; }
  .brand-sub { display: none; }
  .topbar-tools { width: 100%; gap: 8px; justify-content: space-between; }
  .store-switch { flex: 1 1 150px; min-width: 0; }
  .store-switch span { display: none; }
  .store-switch select { width: 100%; max-width: none; min-width: 0; font-size: 12px; }
  .user { display: none; }
  .demo-badge { padding: 2px 8px; font-size: 11px; }
  .tabs { padding: 0 8px; }
  .tabs a { padding: 10px 8px; font-size: 12.5px; }
  .view { padding: 14px 12px 40px; }
  .page-head { gap: 8px; margin-bottom: 12px; }
  .page-head h1 { font-size: 19px; }
  .page-head .actions { margin-left: 0; width: 100%; }
  .panel-head { padding: 12px 14px; }
  .panel-body { padding: 12px 14px; }
  .grid.kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-card .value { font-size: 20px; }
  .search-box { min-width: 0; }
  .demo-strip { padding: 7px 12px; }
  .table-wrap { max-height: none; }
  .rnp-table { display: none; }
  .rnp-cards { display: grid; gap: 10px; padding: 12px; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal { padding: 0; }
  .modal-panel { max-height: 100vh; border-radius: 0; width: 100%; min-height: 100vh; }
  .modal-head { padding: 12px 14px; }
  .modal-body { padding: 14px; }
  .chart-tooltip { transform: translate(-50%, -112%); }
}

@media print {
  .topbar, .tabs, .demo-strip, .actions, .foot { display: none !important; }
  body { background: #fff; }
  .panel { box-shadow: none; }
}
