:root {
  --bg: #f3f4f6;
  --card: #fff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --orange-bg: #fff4e6;
  --orange: #e8590c;
  --indigo-bg: #eef2ff;
  --indigo: #4f46e5;
  --green-bg: #e6f6ea;
  --green: #2b8a3e;
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1260px; margin: 0 auto; padding: 0 20px; }
.sub { font-size: 12px; color: var(--muted); }
.r { text-align: right; }
.c { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }

/* ---------- top bar ---------- */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 60px; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.tabs a:hover { background: #f3f4f6; color: var(--text); text-decoration: none; }
.tabs a.active { background: var(--indigo-bg); color: var(--indigo); }

.toolbar { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.filters { display: flex; gap: 8px; align-items: center; }
.filters input, .filters select {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
.filters input { width: 340px; }
.filters input:focus, .filters select:focus { outline: 2px solid #bfdbfe; border-color: #93c5fd; }

.icon-btn {
  height: 36px;
  min-width: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: #f9fafb; color: var(--text); text-decoration: none; }

.btn {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }

/* ---------- site cards ---------- */
main.wrap { padding-top: 18px; padding-bottom: 8px; }

.page-bar { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin: 2px 2px 14px; }
.page-bar h1 { margin: 0; font-size: 18px; }
.page-bar .sub { font-size: 13px; }

.site {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  margin-bottom: 18px;
  overflow: hidden;
}
.site-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
}
.site-head:hover { background: #fafafa; }
.site-head:focus-visible { outline: 2px solid #bfdbfe; outline-offset: -2px; }

.caret { font-size: 11px; color: var(--muted); width: 14px; transition: transform .15s; }
.site.open .caret { transform: rotate(90deg); }
.site-name { font-weight: 700; font-size: 16px; }
.spacer { flex: 1; }

.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge-count { background: var(--orange-bg); color: var(--orange); }
.badge-count.err { background: #fdecec; color: #c92a2a; cursor: help; }
.badge-count.zero { background: #f1f3f5; color: var(--muted); }
.badge-note { background: #c6e1c6; color: #2c5f13; }

.chip {
  font-size: 12px;
  background: var(--indigo-bg);
  color: var(--indigo);
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.meta { font-size: 13px; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }

.site-body { border-top: 1px solid var(--border); }
.loading, .empty, .error { padding: 18px 20px; color: var(--muted); }
.error { color: #c92a2a; }
.error .btn { margin-left: 10px; }

/* ---------- orders table ---------- */
.table-wrap { overflow-x: auto; }
table.orders { width: 100%; border-collapse: collapse; font-size: 13px; }
.orders th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 9px 12px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.orders th.r { text-align: right; }
.orders th.c { text-align: center; }
.orders td { padding: 9px 12px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }

.order-row { cursor: pointer; }
.order-row:hover td { background: #fafbff; }
.order-row.open td { background: #f3f6ff; }
.order-row:focus-visible { outline: 2px solid #bfdbfe; outline-offset: -2px; }
.caret-sm { display: inline-block; color: var(--muted); transition: transform .15s; }
.order-row.open .caret-sm { transform: rotate(90deg); }

.status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.st-pending    { background: #e5e5e5; color: #555; }
.st-processing { background: #c6e1c6; color: #2c5f13; }
.st-on-hold    { background: #f8dda7; color: #7a5307; }
.st-completed  { background: #c8d7e1; color: #2e4453; }
.st-cancelled,
.st-failed     { background: #eba3a3; color: #761919; }
.st-refunded   { background: #e5e5e5; color: #777; }
.st-default    { background: #eef0f3; color: #444; }

.order-detail > td { background: #fcfcfd; padding: 16px 20px 18px; }
.detail { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 24px; }
.detail h4 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.detail h4.mt { margin-top: 14px; }
.items { width: 100%; border-collapse: collapse; }
.items td { padding: 5px 8px 5px 0; border-bottom: 1px dashed #e9eaee; }
.note { background: #fffbea; border: 1px solid #f5e6a8; border-radius: 6px; padding: 8px 10px; white-space: pre-wrap; }

.more-wrap { padding: 12px; text-align: center; display: flex; gap: 12px; justify-content: center; align-items: center; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 20px 30px; }

/* ---------- analytics ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  padding: 16px;
  margin-bottom: 18px;
  min-width: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-head h2 .sub { font-weight: 400; margin-left: 4px; }

.an-filters { display: flex; flex-direction: column; gap: 10px; }
.f-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.f-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  min-width: 96px;
}
.f-label-inline { min-width: 0; margin-left: 8px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #fff; }
.seg button {
  border: 0;
  border-left: 1px solid var(--border);
  background: none;
  padding: 6px 11px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.seg button:first-child { border-left: 0; }
.seg button:hover { background: #f9fafb; color: var(--text); }
.seg button.active { background: var(--indigo-bg); color: var(--indigo); font-weight: 600; }

.date-in { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.date-in input, #product {
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  font: inherit;
  color: var(--text);
  background: #fff;
}
#product { width: 280px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 4px 11px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.chip-btn:hover { border-color: #c7d2fe; }
.chip-btn[aria-pressed="true"] { border-color: #c7d2fe; background: var(--indigo-bg); color: var(--text); }
.chip-btn[aria-pressed="false"] .dot { opacity: .3; }
.chip-btn.link { border-style: dashed; background: none; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; vertical-align: 0; }
.dots { display: inline-flex; gap: 3px; }

.load-status { display: flex; flex-wrap: wrap; gap: 8px; margin: -6px 0 14px; font-size: 12px; color: var(--muted); }
.load-status .ls {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.load-status .ls.err { color: #c92a2a; border-color: #f5c2c2; cursor: help; }

.an-note { font-size: 12px; color: var(--muted); background: #fff; border: 1px dashed var(--border); border-radius: var(--radius); padding: 8px 12px; margin: -4px 0 14px; }

.site-tabs { display: flex; gap: 8px; overflow-x: auto; margin: 0 0 16px; padding-bottom: 2px; }
.site-tab {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 150px;
  padding: 9px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.site-tab:hover { border-color: #c7d2fe; }
.site-tab.active { border-color: var(--indigo); box-shadow: inset 0 -3px 0 var(--indigo); }
.site-tab .st-name { font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.site-tab .st-meta { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.site-tab.err .st-meta { color: #c92a2a; }
.grid-2.single { grid-template-columns: minmax(0, 1fr); }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.kpi .k-label { font-size: 12px; color: var(--muted); }
.kpi .k-value { font-size: 21px; font-weight: 650; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.hero { border-color: #c7d2fe; }
.kpi.hero .k-value { font-size: 26px; }
.kpi .k-delta { font-size: 12px; margin-top: 4px; color: var(--muted); }
.kpi .k-delta.up { color: #006300; }
.kpi .k-delta.down { color: #d03b3b; }

.chart-box { position: relative; height: 320px; }
.chart-box.short { height: 200px; margin-bottom: 14px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 18px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
.data th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 8px 10px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data td { padding: 8px 10px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data tfoot td { font-weight: 600; background: #f9fafb; border-top: 1px solid var(--border); border-bottom: 0; }
.data tr.zero td { color: #b0b4bb; }
.data tr.click { cursor: pointer; }
.data tr.click:hover td { background: #fafbff; }

.meter-cell { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.meter { flex: 1; height: 8px; background: #f1f3f5; border-radius: 4px; overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 4px; }
.meter-cell .pct { width: 48px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }

.share-bar { display: flex; gap: 2px; height: 14px; margin-bottom: 14px; border-radius: 4px; overflow: hidden; background: #f1f3f5; }
.share-bar span { display: block; height: 100%; min-width: 2px; }

.panel .more-wrap { padding: 12px 0 0; }
.empty-note { color: var(--muted); padding: 10px 0; }

@media (max-width: 1150px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .f-label { min-width: 0; width: 100%; }
  .f-label-inline { margin-left: 0; }
  #product { flex: 1; width: auto; }
}

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .06);
  padding: 28px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card .brand { justify-content: center; }
.login-card input { height: 40px; border: 1px solid var(--border); border-radius: 6px; padding: 0 12px; font: inherit; }
.login-card .btn { height: 40px; }
.login-error { background: #fdecec; color: #c92a2a; border-radius: 6px; padding: 8px 10px; font-size: 13px; }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .topbar-inner { flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .tabs { margin-left: auto; }
  .toolbar { width: 100%; margin-left: 0; }
  .filters { flex: 1; min-width: 0; }
  .filters input { flex: 1; width: auto; min-width: 0; }
  .site-head { flex-wrap: wrap; }
  .spacer { display: none; }
  .detail { grid-template-columns: 1fr; }
}
