:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --text: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --brand: #ee7500;
  --brand-soft: #fff1e4;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --info: #2563eb;
  --info-soft: #e9f0fe;
  --violet: #7c3aed;
  --violet-soft: #f1ebfe;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f11;
    --surface: #18181b;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --line: #2c2c31;
    --brand-soft: #3a2410;
    --ok-soft: #12301f;
    --warn-soft: #362712;
    --bad-soft: #3a1717;
    --info-soft: #172443;
    --violet-soft: #2a1d47;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Armenian", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Шапка */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.top img { height: 26px; display: block; }
.login picture { justify-self: center; }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a {
  text-decoration: none; padding: 7px 14px; border-radius: 999px; font-weight: 500; color: var(--muted);
}
.top nav a:hover { color: var(--text); }
.top nav a.active { background: var(--brand-soft); color: var(--brand); }
.top .me { color: var(--muted); font-size: 13px; display: flex; gap: 12px; align-items: center; }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }
h1 { font-size: 24px; margin: 0 0 20px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h2 { font-size: 16px; margin: 0 0 14px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); text-decoration: none; }
.back:hover { color: var(--text); }

/* Карточки и сетки */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); margin-bottom: 16px; }
.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); margin-bottom: 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; overflow-wrap: anywhere; }

/* Таблицы */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card .table-wrap { border: 0; border-radius: 0; margin: 0 -18px -18px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: var(--bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: contain; background: #fff; border: 1px solid var(--line); display: block; }
.breakdown { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

/* Метки */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 550; white-space: nowrap; background: var(--bg); color: var(--muted); }
.pill.new { background: var(--info-soft); color: var(--info); }
.pill.confirmed { background: var(--violet-soft); color: var(--violet); }
.pill.paid, .pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.bought, .pill.warehouse, .pill.shipped, .pill.arrived { background: var(--brand-soft); color: var(--brand); }
.pill.cancelled { background: var(--bad-soft); color: var(--bad); }
.tag { display: inline-block; padding: 0 7px; border-radius: 6px; font-size: 11.5px; font-weight: 600; margin-left: 6px; background: var(--bg); color: var(--muted); vertical-align: 1px; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.brand { background: var(--brand-soft); color: var(--brand); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }

/* Панель фильтров */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs a {
  text-decoration: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 13px; white-space: nowrap;
}
.tabs a.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.tabs a .n { color: var(--muted); margin-left: 4px; }
.tabs a.active .n { color: inherit; }

input[type="search"], input[type="text"], input[type="email"], input[type="password"], select {
  height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.search { flex: 1; min-width: 220px; max-width: 420px; }

.btn {
  height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  background: var(--brand); color: #fff; font-weight: 600; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.link { background: none; color: var(--muted); padding: 0; height: auto; font-weight: 500; }
.btn.link:hover { color: var(--text); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 14px; color: var(--muted); }

/* Графики */
.chart svg { width: 100%; height: 180px; display: block; overflow: visible; }
.chart .bar { fill: var(--brand); }
.chart .bar.alt { fill: var(--info); }
.chart .bar.c3 { fill: var(--violet); }
.chart .bar.c4 { fill: var(--ok); }
.legend i.c1 { background: var(--brand); }
.legend i.alt { background: var(--info); }
.legend i.c3 { background: var(--violet); }
.legend i.c4 { background: var(--ok); }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.meter { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 10px 0 6px; }
.meter > div { height: 100%; background: var(--ok); border-radius: 99px; }
.meter > div.warn { background: var(--brand); }
.center { text-align: center; }
.between { justify-content: space-between; }
.mt { margin-top: 22px; }
.mt-sm { margin-top: 14px; }
.mb { margin-bottom: 16px; }

.statuses { display: grid; gap: 8px; }
.statuses a { display: flex; justify-content: space-between; align-items: center; text-decoration: none; gap: 12px; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }

/* Вход */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login img { height: 34px; justify-self: center; margin-bottom: 8px; }
.login input { width: 100%; height: 44px; }
.login .btn { height: 44px; }

.error { color: var(--bad); }
.notice { padding: 10px 14px; border-radius: 10px; background: var(--bad-soft); color: var(--bad); margin-bottom: 16px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.loading { padding: 60px 16px; text-align: center; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 500;
}

@media (max-width: 720px) {
  .top { padding: 10px 16px; gap: 12px; flex-wrap: wrap; }
  .top nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  main { padding: 16px; }
  .me { margin-left: auto; }
  .me span { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .value { font-size: 19px; }
}
