:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #e2e7ee;
  --text: #16202c;
  --muted: #5d6b7c;
  --accent: #1f72d6;
  --accent-strong: #1659ad;
  --accent-soft: #e6f0fc;
  --ok: #15803d;
  --ok-soft: #e3f5e9;
  --warn: #b45309;
  --warn-soft: #fdf1df;
  --bad: #b91c1c;
  --bad-soft: #fde8e8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1218;
    --surface: #141b23;
    --surface-2: #1b242e;
    --border: #26313d;
    --text: #e5ebf2;
    --muted: #93a1b2;
    --accent: #4b9bf2;
    --accent-strong: #79b5f6;
    --accent-soft: #15283d;
    --ok: #4ade80;
    --ok-soft: #132a1c;
    --warn: #f5b04c;
    --warn-soft: #2d2213;
    --bad: #f87171;
    --bad-soft: #2f1717;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1218;
  --surface: #141b23;
  --surface-2: #1b242e;
  --border: #26313d;
  --text: #e5ebf2;
  --muted: #93a1b2;
  --accent: #4b9bf2;
  --accent-strong: #79b5f6;
  --accent-soft: #15283d;
  --ok: #4ade80;
  --ok-soft: #132a1c;
  --warn: #f5b04c;
  --warn-soft: #2d2213;
  --bad: #f87171;
  --bad-soft: #2f1717;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 600; }
code, .mono { font-family: "Cascadia Code", "SF Mono", Consolas, monospace; font-size: 12.5px; }
svg.i { width: 17px; height: 17px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Layout */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center;
}
.brand-mark svg { width: 19px; height: 19px; stroke: #fff; }
.brand b { display: block; font-size: 14px; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent-strong); }
.nav .count {
  margin-left: auto; background: var(--accent); color: #fff; border-radius: 99px;
  font-size: 11px; padding: 0 7px; line-height: 18px; font-weight: 600;
}
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.side-foot { margin-top: auto; display: flex; gap: 6px; padding: 8px; }
.main { min-width: 0; }
.content > *, .grid > * { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 22px 32px 0; flex-wrap: wrap;
}
.topbar .sub { color: var(--muted); margin-top: 4px; }
.content { padding: 20px 32px 48px; display: grid; gap: 20px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.grid { display: grid; gap: 20px; }
.grid.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid.halves { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 6px; letter-spacing: -.02em; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* Banners */
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); border: 1px solid; }
.banner.info { background: var(--accent-soft); border-color: transparent; color: var(--text); }
.banner.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.banner.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.banner.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.banner p { margin: 2px 0 0; color: var(--muted); }
.banner.compact { padding: 8px 14px; font-size: 13px; align-items: center; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.wrap { white-space: normal; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.thumb { width: 44px; height: 30px; border-radius: 6px; object-fit: cover; background: var(--surface-2); display: block; }
.cell-product { display: flex; align-items: center; gap: 12px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 550; background: var(--surface-2); color: var(--muted); }
.badge.paid, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.pending, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.refunded, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent-strong); }

/* Buttons and forms */
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
form.inline { display: inline; }
.field { display: grid; gap: 6px; }
.field label, .label-text { font-weight: 550; font-size: 13px; }
.field .help { color: var(--muted); font-size: 12.5px; }
.fields { display: grid; gap: 16px; }
.fields.cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields.cols3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=search],
input[type=datetime-local], select, textarea {
  width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { height: auto; min-height: 96px; padding: 9px 11px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=file] { font: inherit; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.variant-row { display: grid; grid-template-columns: 1fr 160px; gap: 10px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { width: 240px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 4px 12px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); font-weight: 500; background: var(--surface); }
.pill.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg { display: none; }
.seg.on { display: grid; }

/* Chart */
.chart svg { width: 100%; height: 200px; display: block; }
.chart rect { fill: var(--accent); opacity: .85; }
.chart rect:hover { opacity: 1; }
.chart .axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 8px; }
.bar-list { display: grid; gap: 12px; }
.bar-item .row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.bar-item .track { height: 6px; background: var(--surface-2); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.bar-item .fill { height: 100%; background: var(--accent); border-radius: 99px; }

/* Detail lists */
dl.meta { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; margin: 0; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.payload { background: var(--surface-2); border-radius: 6px; padding: 2px 8px; display: inline-block; max-width: 100%; overflow-wrap: anywhere; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }

/* Chat thread */
.thread { display: grid; gap: 10px; }
.bubble { max-width: 78%; padding: 9px 13px; border-radius: 12px; background: var(--surface-2); white-space: pre-wrap; }
.bubble.out { justify-self: end; background: var(--accent); color: #fff; }
.bubble time { display: block; font-size: 11px; opacity: .7; margin-top: 4px; }

/* Bot preview on the product page */
.tg-preview { background: var(--surface-2); border-radius: 12px; padding: 14px; }
.tg-msg { background: var(--surface); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.tg-msg img { width: 100%; display: block; aspect-ratio: 16/10; object-fit: cover; }
.tg-msg .txt { padding: 10px 12px; white-space: pre-wrap; }
.tg-btn { margin-top: 6px; background: var(--surface); border-radius: 8px; text-align: center; padding: 7px; font-weight: 550; color: var(--accent); font-size: 13px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; }

.menu-toggle { display: none; }

@media (max-width: 1100px) {
  .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.halves { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 16px 16px 0; }
  .content { padding: 16px 16px 40px; }
  .fields.cols, .fields.cols3 { grid-template-columns: 1fr; }
  .grid.kpis { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kpi .value { font-size: 20px; }
  th, td { padding: 9px 12px; }
  .filters input[type=search] { width: 100%; }
  dl.meta { grid-template-columns: 1fr; gap: 2px 0; }
  dl.meta dd { margin-bottom: 8px; }
  .hide-sm { display: none; }
}
