:root {
  --bg: #0f172a; --card: #1e293b; --border: #334155; --text: #f1f5f9; --muted: #94a3b8;
  --rozetka: #00a046; --prom: #6739b7; --epicentr: #e30613; --accent: #38bdf8;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc; --card: #ffffff; --border: #e2e8f0; --text: #0f172a; --muted: #64748b;
  }
}
* { box-sizing: border-box; }
body {
  background: var(--bg); color: var(--text); font-family: -apple-system, Segoe UI, Roboto, sans-serif;
  margin: 0; padding: 1.5rem 2rem 3rem;
}
h1 { font-size: 1.4rem; margin: 0 0 0.25rem; }
.topbar { margin-bottom: 1.5rem; }
.topbar-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.5rem; }
.sub { color: var(--muted); }
.sub input {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 0.15rem 0.5rem; font-size: 0.9rem; width: 6rem;
}
.sub input.warn { border-color: #f59e0b; }
.sub input.err { border-color: #ef4444; }
#ship-date-status.ok { color: #10b981; }
#ship-date-status { font-size: 0.8rem; margin-left: 0.25rem; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }
.logout-form { margin: 0; margin-left: auto; }
.link-btn {
  background: none; border: none; color: var(--muted); text-decoration: none;
  cursor: pointer; font-size: inherit; font-family: inherit; padding: 0;
}
.link-btn:hover { color: var(--accent); text-decoration: underline; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 1rem; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
.card-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.badge { font-size: 0.7rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; color: #fff; }
.badge-rozetka { background: var(--rozetka); }
.badge-prom { background: var(--prom); }
.badge-epicentr { background: var(--epicentr); }
.order-id { font-weight: 700; }
.meta { color: var(--muted); font-size: 0.8rem; }
.sent-at { color: var(--muted); font-size: 0.75rem; margin-left: auto; }
pre {
  white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 0.85rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem;
  max-height: 260px; overflow-y: auto; margin: 0 0 0.75rem 0;
}
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn {
  flex: 1 1 auto; text-align: center; padding: 0.5rem; border-radius: 8px; border: none; cursor: pointer;
  font-size: 0.85rem; font-weight: 600; text-decoration: none; color: inherit; font-family: inherit;
  min-height: 40px; display: inline-flex; align-items: center; justify-content: center;
}
.btn-copy { background: var(--accent); color: #000; }
.btn-copy.copied { background: #10b981; }
.btn-viber { background: #7360f2; color: #fff; }
.btn-viber.disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sent { background: #334155; color: #fff; }
.btn-sent:hover { background: #475569; }
.btn-undo { background: #334155; color: #fff; }
.btn-undo:hover { background: #475569; }
.btn-sync { background: var(--accent); color: #000; font-weight: 700; padding: 0.5rem 1rem; border-radius: 8px; border: none; cursor: pointer; }
.btn-sync:disabled { opacity: 0.6; cursor: wait; }
.sync-msg { font-size: 0.85rem; }
.sync-ok { color: #10b981; }
.sync-busy { color: var(--muted); }
.sync-error { color: #f59e0b; }
.empty { color: var(--muted); }

@media (max-width: 480px) {
  body { padding: 0.75rem 0.75rem 2rem; }
  .grid { grid-template-columns: 1fr; }
  .btn { flex: 1 1 30%; }
  .btn-sent, .btn-undo { flex-basis: 100%; }
}

/* --- Аналітика --- */
.month-label { font-weight: 700; color: var(--text); }
.freshness-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; font-size: 0.8rem; color: var(--muted); }
.freshness-badge { display: inline-flex; align-items: center; gap: 0.35rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-fresh { background: #10b981; }
.dot-lag { background: #f59e0b; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
.kpi-label { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.35rem; }
.kpi-value { font-size: 1.5rem; font-weight: 700; }
.kpi-delta { font-size: 0.75rem; color: var(--muted); margin-top: 0.35rem; }
.kpi-delta.up { color: #10b981; }
.kpi-delta.down { color: #ef4444; }

.returns-note { color: var(--muted); font-size: 0.85rem; margin-bottom: 1.5rem; }

.section { margin-bottom: 2rem; }
.section h2 { font-size: 1rem; margin: 0 0 0.75rem; }

.category-list { display: flex; flex-direction: column; gap: 0.6rem; }
.category-row { display: grid; grid-template-columns: 9rem 1fr auto; align-items: center; gap: 0.75rem; font-size: 0.85rem; }
.category-bar { background: var(--bg); border-radius: 999px; height: 8px; overflow: hidden; }
.category-bar-fill { background: var(--accent); height: 100%; }
.category-value { color: var(--muted); white-space: nowrap; }

.tabs { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.tab-btn {
  background: var(--card); border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 0.4rem 0.9rem; cursor: pointer; font-size: 0.85rem; font-family: inherit;
}
.tab-btn.active { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.top-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.top-table tr { border-bottom: 1px solid var(--border); }
.top-table td { padding: 0.5rem 0.25rem; }
.top-name { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-qty, .top-revenue { color: var(--muted); white-space: nowrap; text-align: right; }
.top-revenue { color: var(--text); font-weight: 600; }

@media (max-width: 480px) {
  .category-row { grid-template-columns: 1fr; gap: 0.25rem; }
  .top-name { max-width: 55vw; }
}
