/* ===================================================================
   APX Analytics — dark-first, responsive theme
   =================================================================== */

:root,
[data-theme="dark"] {
  --bg:          #0a0a0b;
  --bg-elev:     #111113;
  --panel:       #141416;
  --panel-2:     #18181b;
  --ink:         #fafafa;
  --ink-2:       #e4e4e7;
  --muted:       #8b8b94;
  --line:        #26262a;
  --line-soft:   #1d1d20;
  --accent:      #3b82f6;
  --accent-ink:  #ffffff;
  --good:        #22c55e;
  --good-bg:     rgba(34,197,94,.12);
  --bad:         #ef4444;
  --bad-bg:      rgba(239,68,68,.12);
  --flat:        #9ca3af;
  --live:        #22c55e;
  --chart-grid:  rgba(255,255,255,.06);
  --chart-prev:  #6b7280;
  --chart-fill:  rgba(59,130,246,.14);
  --skel-base:   #1b1b1f;
  --skel-shine:  rgba(255,255,255,.07);
  --shadow:      0 1px 2px rgba(0,0,0,.4);
  --radius:      14px;
  --radius-sm:   10px;
}

[data-theme="light"] {
  --bg:          #f6f7f9;
  --bg-elev:     #ffffff;
  --panel:       #ffffff;
  --panel-2:     #f9fafb;
  --ink:         #111827;
  --ink-2:       #1f2937;
  --muted:       #6b7280;
  --line:        #e5e7eb;
  --line-soft:   #eef0f3;
  --accent:      #2563eb;
  --accent-ink:  #ffffff;
  --good:        #16a34a;
  --good-bg:     rgba(22,163,74,.1);
  --bad:         #dc2626;
  --bad-bg:      rgba(220,38,38,.1);
  --flat:        #9ca3af;
  --live:        #16a34a;
  --chart-grid:  rgba(17,24,39,.07);
  --chart-prev:  #9ca3af;
  --chart-fill:  rgba(37,99,235,.1);
  --skel-base:   #e9ebef;
  --skel-shine:  rgba(255,255,255,.65);
  --shadow:      0 1px 2px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans Bengali", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.mb { margin-bottom: 14px; }
.spacer { flex: 1; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center;
  gap: 16px; flex-wrap: wrap;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
  position: sticky; top: 0; z-index: 100;
}
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
}
.brand-title { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.brand-sub { font-size: 12.5px; color: var(--muted); }
.brand-sync {
  display: none; /* desktop keeps the pill on the right; this is the mobile-only sub-line */
  align-items: center; gap: 5px; margin-top: 2px;
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
.brand-sync svg { color: var(--accent); flex: none; }
.brand-sync .js-last-sync { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.top-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.top-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.period {
  display: flex; gap: 2px; padding: 4px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; overflow-x: auto; max-width: 100%;
}
.period-btn {
  text-decoration: none; color: var(--muted); font-size: 13px; font-weight: 500;
  padding: 7px 14px; border-radius: 999px; white-space: nowrap; transition: .15s;
}
.period-btn:hover { color: var(--ink); }
.period-btn.active { background: var(--panel-2); color: var(--ink); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 6px 13px; }
.icon-btn {
  width: 38px; height: 38px; flex: none; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center;
  background: var(--panel); color: var(--muted); border: 1px solid var(--line);
  transition: .15s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--accent); }
.last-sync {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 12.5px; color: var(--muted);
  padding: 7px 11px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.last-sync svg { color: var(--accent); flex: none; }
.last-sync .js-last-sync { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: block; }

/* ---------- Customize (show / hide widgets) menu ---------- */
.customize { position: relative; }
.icon-btn[aria-expanded="true"] { color: var(--ink); border-color: var(--accent); }
.customize-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
  width: 240px; padding: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.customize-menu[hidden] { display: none; }
.customize-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line-soft);
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
.customize-reset {
  border: 0; background: transparent; color: var(--accent); cursor: pointer;
  font: inherit; font-size: 11.5px; font-weight: 600; text-transform: none; letter-spacing: 0; padding: 0;
}
.customize-reset:hover { text-decoration: underline; }
.customize-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--ink-2);
}
.customize-row:hover { background: var(--panel-2); }
.customize-row input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex: none; }
/* Sub-card rows (e.g. the cards inside "Key business metrics") */
.customize-row.is-child {
  margin-left: 15px; padding-left: 12px;
  border-left: 1.5px solid var(--line); border-radius: 0 8px 8px 0;
  font-size: 12.5px;
}
.customize-row.is-disabled { opacity: .4; }
.customize-row.is-disabled input { cursor: not-allowed; }
/* Collapsible parent (a section that owns sub-card toggles) */
.customize-row.is-parent { cursor: default; }
.cz-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; cursor: pointer; }
.customize-collapse {
  flex: none; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 4px; margin: -2px -2px -2px 4px; border-radius: 6px; display: grid; place-items: center;
}
.customize-collapse:hover { color: var(--ink); background: var(--line); }
.customize-collapse svg { display: block; transition: transform .15s; }
.customize-collapse[aria-expanded="false"] svg { transform: rotate(-90deg); }
.customize-row.is-collapsed { display: none; }
@media (prefers-reduced-motion: reduce) { .customize-collapse svg { transition: none; } }

/* Hidden by the customize menu */
.widget-hidden { display: none !important; }
/* A compare-table column hidden because its metric card is hidden */
.col-hidden { display: none !important; }

/* ---------- Layout ---------- */
.container { max-width: 1280px; margin: 0 auto; padding: 26px 28px 8px; }
.block { margin-bottom: 30px; }
.block-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.block-title { font-size: 15px; font-weight: 700; margin: 0; }
.block-meta { font-size: 12.5px; color: var(--muted); }

/* ---------- Site cards ---------- */
.site-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px;
}
.site-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; transition: .15s; position: relative;
}
.site-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.site-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.site-card-top { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 9px;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--panel-2); color: var(--ink-2); border: 1px solid var(--line);
}
.avatar.sm { width: 26px; height: 26px; font-size: 12px; border-radius: 7px; }
.avatar.lg { width: 44px; height: 44px; font-size: 18px; border-radius: 11px; }
.site-id { min-width: 0; flex: 1; }
.site-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-domain { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check {
  width: 22px; height: 22px; flex: none; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: #fff;
}
.site-figure { margin: 14px 0 4px; }
.big-num { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.05; }
.site-spark { color: var(--accent); height: 34px; margin: 4px 0 2px; }
.spark { display: block; width: 100%; height: 34px; }
.site-card-foot { display: flex; align-items: center; gap: 7px; margin-top: 10px; }
.card-error { margin-top: 8px; font-size: 11px; color: var(--bad); }

.live-dot {
  display: inline-block; vertical-align: middle;
  width: 8px; height: 8px; border-radius: 50%; background: var(--live); flex: none;
  box-shadow: 0 0 0 0 rgba(34,197,94,.5); animation: pulse 2s infinite;
}
.live-dot[hidden] { display: none; } /* keep the `hidden` attribute working after display is set */
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34,197,94,.45); }
  70%  { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ---------- Delta badge ---------- */
.delta {
  display: inline-flex; align-items: center; gap: 2px;
  font-size: 11.5px; font-weight: 600; padding: 2px 7px; border-radius: 999px; white-space: nowrap;
}
.delta.good { color: var(--good); background: var(--good-bg); }
.delta.bad  { color: var(--bad);  background: var(--bad-bg); }
.delta.flat { color: var(--flat); background: transparent; }

/* ---------- Detail head ---------- */
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.detail-id { display: flex; align-items: center; gap: 13px; }
.detail-name { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  font-size: 13px; font-weight: 500; color: var(--ink-2);
  padding: 9px 15px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel);
  transition: .15s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--ink); }

/* ---------- KPI cards ---------- */
.kpis {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 22px;
}
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; min-height: 120px;
}
.kpi.live {
  background:
    radial-gradient(120% 90% at 0% 0%, rgba(34,197,94,.14), transparent 60%),
    var(--panel);
  border-color: rgba(34,197,94,.35);
}
.kpi-k { font-size: 12.5px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi.live .kpi-k { color: var(--good); font-weight: 600; }
.kpi-v { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin: 8px 0 4px; line-height: 1.05; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi-change { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.kpi-change .was { color: var(--muted); }

/* ---------- Info tooltip (ⓘ next to a title — reveals descriptive text) ---------- */
.tip {
  position: relative; display: inline-grid; place-items: center;
  vertical-align: middle; cursor: help; color: var(--muted); line-height: 0;
}
.tip:hover, .tip:focus-visible { color: var(--ink-2); outline: none; }
.tip-ic { display: block; opacity: .65; transition: opacity .15s; }
.tip:hover .tip-ic, .tip:focus .tip-ic { opacity: 1; }
.tip-pop {
  position: absolute; bottom: calc(100% + 9px); left: 50%;
  transform: translateX(-50%) translateY(4px);
  z-index: 200; width: max-content; max-width: min(260px, 74vw);
  padding: 9px 11px; border-radius: 10px; text-align: left; white-space: normal;
  background: var(--bg-elev); color: var(--ink-2); border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(0,0,0,.35);
  font-size: 12px; font-weight: 400; line-height: 1.5;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .15s, transform .15s;
}
.tip-pop::after {
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--line);
}
.tip:hover .tip-pop, .tip:focus .tip-pop, .tip:focus-within .tip-pop {
  opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0);
}
@media (prefers-reduced-motion: reduce) {
  .tip-pop { transition: none; }
}

/* ---------- Panels ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-title { font-size: 15px; font-weight: 700; margin: 0 0 2px; }

/* Segmented control */
.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
.seg-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 12.5px; font-weight: 500; padding: 6px 12px; border-radius: 8px; transition: .15s;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }

/* Chart */
.chart-legend { display: flex; gap: 16px; margin-top: 6px; }
.lg-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.lg-line { width: 18px; height: 0; border-top: 2px solid var(--accent); display: inline-block; }
.lg-line.dashed { border-top: 2px dashed var(--chart-prev); }
.chart-wrap { position: relative; height: 320px; }

/* ---------- Search ---------- */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; color: var(--muted); min-width: 240px;
}
.search input { border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 13px; outline: none; width: 100%; }
.search input::placeholder { color: var(--muted); }

/* ---------- Empty state ---------- */
.empty-box {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 40px 20px; text-align: center; background: var(--panel-2);
}
.empty-title { font-weight: 600; margin-bottom: 4px; }
.nodata { padding: 18px 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table-wrap.table-scroll { max-height: 440px; overflow-y: auto; }
.table-wrap.table-scroll .tbl thead th { background: var(--panel); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 520px; }
.tbl th, .tbl td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
.tbl thead th {
  color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--line); position: sticky; top: 0;
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--panel-2); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .path { font-family: ui-monospace, "Cascadia Code", "SF Mono", monospace; font-size: 12.5px; color: var(--ink-2); max-width: 420px; overflow: hidden; text-overflow: ellipsis; }

.compare { min-width: 680px; }
.compare tbody tr.is-sel { box-shadow: inset 3px 0 0 var(--accent); }
.cmp-site { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; font-weight: 500; }
.cmp-site:hover { color: var(--accent); }

/* ---------- Breakdown bars ---------- */
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 13px; }
.bar-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 5px; }
.bar-name { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-val { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.bar-track { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar-track span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- All-traffic table ---------- */
.traffic-tbl { min-width: 480px; }
.traffic-tbl th.rank, .traffic-tbl td.rank {
  width: 34px; text-align: right; padding-right: 10px;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.traffic-tbl td.src { color: var(--ink-2); max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.traffic-tbl th.tbar, .traffic-tbl td.tbar { width: 120px; }
.traffic-tbl td.tbar .bar-track { height: 7px; }

/* ---------- Key business metrics (per-site) ---------- */
.exec-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 2px 0 12px; }
.exec-head .panel-title { position: relative; padding-left: 12px; }
.exec-head .panel-title::before {
  content: ""; position: absolute; left: 0; top: 2px; bottom: 2px;
  width: 4px; border-radius: 3px; background: var(--accent);
}
.kpis-exec { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

/* ---------- Footer ---------- */
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; border-top: 1px solid var(--line-soft); margin-top: 20px; }

/* ===================================================================
   Responsive
   =================================================================== */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  .topbar { padding: 14px 16px; row-gap: 12px; }
  .container { padding: 20px 16px 8px; }
  .brand-sub { display: none; }
  .brand-sync { display: inline-flex; } /* replaces the tagline on mobile */
  .top-controls .last-sync { display: none; } /* moved under the brand title */
  .top-actions { order: 1; }
  .top-controls { order: 2; width: 100%; }
  .period { order: 3; width: 100%; justify-content: flex-start; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi { min-height: 108px; }
  .kpi-v { font-size: 26px; }
  .chart-wrap { height: 260px; }
  .panel { padding: 16px; }
  .search { min-width: 0; width: 100%; }
  .panel-head { flex-direction: column; }
  .panel-head .seg, .panel-head .search { width: 100%; }
  .seg { justify-content: space-between; }
  .seg-btn { flex: 1; text-align: center; }
}
@media (max-width: 460px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .big-num { font-size: 26px; }
  .detail-name { font-size: 18px; }
}

/* ===================================================================
   Skeleton loader (shown in #dash while live data is fetched)
   =================================================================== */
.skel {
  position: relative;
  overflow: hidden;
  background: var(--skel-base);
  border-radius: 8px;
}
.skel::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--skel-shine), transparent);
  animation: skel-shimmer 1.3s ease-in-out infinite;
}
@keyframes skel-shimmer { 100% { transform: translateX(100%); } }

.skel-title    { height: 16px; width: 170px; margin-bottom: 14px; }
.skel-line     { height: 11px; border-radius: 6px; }
.skel-line.sm  { height: 9px; }
.skel-line + .skel-line { margin-top: 8px; }

.skel-card, .skel-kpi {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.skel-kpi { min-height: 120px; display: flex; flex-direction: column; gap: 14px; }
.skel-card-top { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.skel-card-id  { flex: 1; }
.skel-avatar   { width: 38px; height: 38px; border-radius: 10px; flex: none; }
.skel-bignum   { height: 30px; width: 55%; border-radius: 8px; margin: 6px 0 14px; }
.skel-kpi .skel-bignum { margin: 2px 0; }
.skel-spark    { height: 34px; width: 100%; border-radius: 8px; margin-bottom: 12px; }
.skel-chart    { height: 320px; width: 100%; border-radius: 10px; margin-top: 14px; }
.skel-panel .skel-row { height: 16px; width: 100%; border-radius: 6px; margin-top: 14px; }

@media (max-width: 760px) {
  .skel-chart { height: 260px; }
  .skel-card, .skel-kpi, .skel-panel { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .skel::after { animation-duration: 2.4s; }
}

.error-panel h3 { margin-top: 0; }
