/* =========================================================
   Аналітика · демо-адмінка
   Акцентний колір проєкту — фіолетовий #7b5cff
   ========================================================= */

:root {
  --accent: #7b5cff;
  --accent-soft: rgba(123, 92, 255, .12);
  --accent-hover: #6a48f5;

  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --text: #1e2233;
  --text-muted: #6b7180;
  --border: #e6e8ef;
  --shadow: 0 1px 2px rgba(23, 26, 42, .05), 0 8px 24px rgba(23, 26, 42, .06);
  --shadow-lg: 0 12px 40px rgba(23, 26, 42, .16);

  --up: #12a06a;
  --down: #e0475b;
  --up-soft: rgba(18, 160, 106, .12);
  --down-soft: rgba(224, 71, 91, .12);

  --grid: rgba(30, 34, 51, .08);
  --radius: 12px;
  --radius-sm: 10px;
  --sidebar-w: 244px;
  --sidebar-w-collapsed: 68px;
  --header-h: 62px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #14161d;
  --surface: #1b1e27;
  --surface-2: #21242f;
  --text: #e8eaf2;
  --text-muted: #9aa1b4;
  --border: #2c303c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);

  --accent-soft: rgba(123, 92, 255, .2);
  --up: #2ecc8f;
  --down: #ff6b7d;
  --up-soft: rgba(46, 204, 143, .14);
  --down-soft: rgba(255, 107, 125, .14);
  --grid: rgba(232, 234, 242, .1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }
svg[hidden], [hidden] { display: none !important; }

/* ---------------- Розмітка ---------------- */
.layout { display: flex; min-height: 100vh; }

/* ---------------- Бокове меню ---------------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width .22s ease, flex-basis .22s ease, transform .22s ease;
  z-index: 40;
}

.app.collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
  flex-basis: var(--sidebar-w-collapsed);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  overflow: hidden;
}

.brand-mark {
  width: 32px; height: 32px;
  flex: 0 0 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #a88bff);
  display: grid; place-items: center;
  color: #fff;
}

.brand-text { font-weight: 650; letter-spacing: -.2px; white-space: nowrap; }
.brand-text small { display: block; font-weight: 400; font-size: 11px; color: var(--text-muted); }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); padding: 12px 10px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px;
  border: 0; background: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  width: 100%; text-align: left;
  white-space: nowrap;
  transition: background-color .15s ease, color .15s ease;
}
.nav-item svg { flex: 0 0 18px; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .badge-count {
  margin-left: auto;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 600;
  border-radius: 20px; padding: 1px 7px;
}

.app.collapsed .brand-text,
.app.collapsed .nav-title,
.app.collapsed .nav-item span,
.app.collapsed .nav-item .badge-count,
.app.collapsed .sidebar-foot { display: none; }
.app.collapsed .nav-item { justify-content: center; padding: 10px; }

.sidebar-foot {
  margin-top: auto; padding: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}
.sidebar-foot .link-btn { display: block; margin-top: 6px; padding: 2px 0; }

/* ---------------- Основна частина ---------------- */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  position: sticky; top: 0; z-index: 30;
}

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid transparent; background: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  position: relative;
  transition: background-color .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.page-title { font-size: 16px; font-weight: 650; margin: 0; letter-spacing: -.2px; }
.page-title small { display: block; font-size: 12px; font-weight: 400; color: var(--text-muted); }

.topbar-spacer { flex: 1 1 auto; }

.dot {
  position: absolute; top: 6px; right: 6px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 10px; background: var(--down); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 650; font-size: 13px;
  flex: 0 0 34px;
}

.user-chip { display: flex; align-items: center; gap: 9px; padding-left: 6px; }
.user-chip div { line-height: 1.25; }
.user-chip b { display: block; font-size: 13px; font-weight: 600; }
.user-chip span { display: block; font-size: 11px; color: var(--text-muted); }

/* Випадаюче меню сповіщень */
.dropdown {
  position: absolute; top: calc(var(--header-h) - 8px); right: 16px;
  width: 320px; max-width: calc(100vw - 24px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 60; overflow: hidden;
}
.dropdown[hidden] { display: none; }
.dropdown-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.link-btn {
  background: none; border: 0; color: var(--accent);
  font-size: 12px; font-weight: 600; padding: 2px 4px; border-radius: 6px;
}
.link-btn:hover { background: var(--accent-soft); }
.notif { display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.notif:last-child { border-bottom: 0; }
.notif.unread { background: var(--accent-soft); }
.notif-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-top: 6px; flex: 0 0 7px; }
.notif.read .notif-dot { background: var(--border); }
.notif b { display: block; font-size: 13px; font-weight: 600; }
.notif p { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.notif time { font-size: 11px; color: var(--text-muted); }

/* ---------------- Контент ---------------- */
.content { padding: 20px 20px 52px; display: flex; flex-direction: column; gap: 18px; }
.view[hidden] { display: none; }
.view { display: flex; flex-direction: column; gap: 18px; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
}

.seg {
  display: inline-flex; background: var(--surface); padding: 4px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  gap: 2px; flex-wrap: wrap;
}
.seg button {
  border: 0; background: none; color: var(--text-muted);
  padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 550;
  transition: background-color .15s ease, color .15s ease;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--accent); color: #fff; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 8px 14px;
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 550;
  transition: background-color .15s ease, border-color .15s ease, transform .08s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; }

.field {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0 10px; color: var(--text-muted);
}
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input {
  border: 0; background: none; outline: none; padding: 9px 0;
  min-width: 0; width: 210px;
}
select.input, input.input, textarea.input {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 10px; outline: none; width: 100%;
}
select.input:focus, input.input:focus, textarea.input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------------- Плитки KPI ---------------- */
.kpi-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
}

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kpi { padding: 16px; display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.kpi-head { display: flex; align-items: center; gap: 9px; color: var(--text-muted); font-size: 13px; }
.kpi-ico {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; flex: 0 0 30px;
}
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -.5px; }
.kpi-bottom { display: flex; flex-direction: column; align-items: stretch; gap: 8px; min-width: 0; }
.trend {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 650;
  padding: 3px 8px; border-radius: 20px;
}
.trend.up { color: var(--up); background: var(--up-soft); }
.trend.down { color: var(--down); background: var(--down-soft); }
.trend-note { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.spark { width: 100%; height: 34px; color: var(--accent); }

/* ---------------- Графіки ---------------- */
.chart-grid { display: grid; gap: 14px; grid-template-columns: 2fr 1fr; }
.chart-grid > *, .kpi-grid > * { min-width: 0; }
.chart-card { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 14px; font-weight: 650; }
.card-head span { font-size: 12px; color: var(--text-muted); }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 280px; }
.chart-fallback {
  display: none; align-items: center; justify-content: center; height: 100%;
  color: var(--text-muted); font-size: 13px; text-align: center; padding: 20px;
}
.no-charts .chart-box canvas { display: none; }
.no-charts .chart-fallback { display: flex; }

/* ---------------- Таблиці ---------------- */
.table-card { padding: 0; overflow: hidden; }
.table-head {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  background: var(--surface-2); position: relative; user-select: none;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
th.sortable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; color: var(--text); }
th .arrow { opacity: .35; margin-left: 5px; font-size: 10px; }
th.sorted { color: var(--accent); }
th.sorted .arrow { opacity: 1; }
tbody tr { transition: background-color .12s ease; }
#ordersBody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill.new       { color: #2f6fed; background: rgba(47, 111, 237, .12); }
.pill.paid      { color: var(--accent); background: var(--accent-soft); }
.pill.shipped   { color: #d08700; background: rgba(208, 135, 0, .14); }
.pill.done      { color: var(--up); background: var(--up-soft); }
.pill.cancelled { color: var(--down); background: var(--down-soft); }
.pill.active    { color: var(--up); background: var(--up-soft); }
.pill.blocked   { color: var(--down); background: var(--down-soft); }
[data-theme="dark"] .pill.new { color: #7ba7ff; }
[data-theme="dark"] .pill.shipped { color: #f0b429; }

.table-foot {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 12px 16px;
}
.muted { color: var(--text-muted); font-size: 12px; }
.pager { display: flex; gap: 4px; flex-wrap: wrap; }
.pager button {
  min-width: 32px; height: 32px; padding: 0 8px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; font-size: 13px; color: var(--text-muted);
}
.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.pager button.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pager button:disabled { opacity: .45; cursor: not-allowed; }

.empty { padding: 46px 20px; text-align: center; color: var(--text-muted); }
.empty svg { margin: 0 auto 10px; color: var(--border); }
.empty b { display: block; color: var(--text); font-size: 14px; margin-bottom: 4px; }

.cell-main { display: flex; align-items: center; gap: 10px; }
.cell-sub { font-size: 11px; color: var(--text-muted); }
.row-link { color: var(--accent); font-weight: 600; }

/* ---------------- Модалки ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 17, 26, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 18px; z-index: 80; backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; max-height: 90vh; overflow: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--border);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row.full { grid-column: 1 / -1; }
.form-row label { font-size: 12px; color: var(--text-muted); font-weight: 550; }
.form-error { color: var(--down); font-size: 12px; min-height: 16px; }
.detail-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.detail-list div { min-width: 0; }
.detail-list dt { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.detail-list dd { margin: 3px 0 0; font-weight: 550; word-break: break-word; }

/* ---------------- Дрібне ---------------- */
.demo-badge {
  position: fixed; right: 14px; bottom: 14px; z-index: 70;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 11px;
  padding: 6px 11px; border-radius: 20px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 6px;
}
.demo-badge i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: block; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 20px; font-size: 13px; font-weight: 550;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  z-index: 90; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.overlay {
  position: fixed; inset: 0; background: rgba(15, 17, 26, .45);
  z-index: 35; display: none;
}

/* ---------------- Адаптив ---------------- */
@media (max-width: 1080px) {
  .chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    width: var(--sidebar-w); flex-basis: var(--sidebar-w);
  }
  .app.collapsed .sidebar { width: var(--sidebar-w); flex-basis: var(--sidebar-w); }
  .app.collapsed .brand-text,
  .app.collapsed .nav-title,
  .app.collapsed .nav-item span,
  .app.collapsed .nav-item .badge-count,
  .app.collapsed .sidebar-foot { display: revert; }
  .app.collapsed .nav-item { justify-content: flex-start; padding: 9px 11px; }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .overlay { display: block; }
  .content { padding: 14px 14px 56px; }
  .user-chip div { display: none; }
  .field input { width: 100%; }
  .topbar { padding: 0 12px; gap: 8px; }
  .page-title { font-size: 15px; }
}

@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 20px; }
  .kpi { padding: 14px; gap: 8px; }
  .spark { height: 30px; }
  .page-title small { display: none; }
  .form-grid, .detail-list { grid-template-columns: 1fr; }
  .toolbar > * { flex: 1 1 auto; }
  .seg { width: 100%; }
  .seg button { flex: 1 1 auto; padding: 7px 8px; }
  .chart-box { height: 220px; }
  .table-head, .table-foot { padding: 12px; }
}

@media (max-width: 360px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
