/* ============================================================
   Media Panel — design tokens
   ============================================================ */
:root {
  --bg: #f5f6fa;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(99, 102, 241, .08), transparent 60%);
  --panel: #ffffff;
  --panel-2: #f8f9fc;
  --text: #0f1222;
  --text-2: #3f4458;
  --muted: #6b7185;
  --line: #e7e9f0;
  --line-2: #eff1f6;
  --hover: #f3f4f9;
  --brand: #5b5bf0;
  --brand-2: #8b5cf6;
  --brand-soft: #eef0ff;
  --brand-text: #4338ca;
  --on-brand: #ffffff;
  --c-blue: #3b82f6;
  --c-green: #10b981;
  --c-amber: #f59e0b;
  --c-violet: #8b5cf6;
  --danger: #e11d48;
  --danger-bg: #fff1f3;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .16);
  --ring: 0 0 0 3px rgba(91, 91, 240, .25);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b10;
    --bg-grad: radial-gradient(1000px 500px at 100% -10%, rgba(99, 102, 241, .14), transparent 60%);
    --panel: #14141c;
    --panel-2: #181822;
    --text: #f1f2f7;
    --text-2: #c9cbd6;
    --muted: #8e92a6;
    --line: #262633;
    --line-2: #1e1e29;
    --hover: #1c1c27;
    --brand: #7c7cff;
    --brand-soft: rgba(124, 124, 255, .14);
    --brand-text: #b4b6ff;
    --danger: #fb7185;
    --danger-bg: rgba(225, 29, 72, .14);
    --shadow-sm: none;
    --shadow: 0 0 0 1px rgba(255, 255, 255, .02);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0b10;
  --bg-grad: radial-gradient(1000px 500px at 100% -10%, rgba(99, 102, 241, .14), transparent 60%);
  --panel: #14141c;
  --panel-2: #181822;
  --text: #f1f2f7;
  --text-2: #c9cbd6;
  --muted: #8e92a6;
  --line: #262633;
  --line-2: #1e1e29;
  --hover: #1c1c27;
  --brand: #7c7cff;
  --brand-soft: rgba(124, 124, 255, .14);
  --brand-text: #b4b6ff;
  --danger: #fb7185;
  --danger-bg: rgba(225, 29, 72, .14);
  --shadow-sm: none;
  --shadow: 0 0 0 1px rgba(255, 255, 255, .02);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; letter-spacing: -.02em; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.center { text-align: center; }
.ic { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ic.xs { width: 12px; height: 12px; vertical-align: -1px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ============================================================
   Controls
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  color: var(--text); background: var(--hover);
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .pills button:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary { color: var(--on-brand); background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 2px 8px rgba(91, 91, 240, .3); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.outline { background: var(--panel); border-color: var(--line); box-shadow: var(--shadow-sm); }
.btn.outline:hover { background: var(--hover); }
.btn.active { border-color: color-mix(in srgb, var(--brand) 45%, transparent); background: var(--brand-soft); color: var(--brand-text); }
.btn.block { width: 100%; }
.btn.lg { height: 46px; font-size: 15px; border-radius: 12px; }
.btn:disabled { opacity: .65; cursor: default; }
.btn.select .chev { margin-left: 2px; opacity: .6; transition: transform .2s; }
.btn.select[aria-expanded="true"] .chev { transform: rotate(180deg); }
.btn.spin .ic { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; }
.link { background: none; border: 0; padding: 0; font: inherit; font-size: 12px; font-weight: 600; color: var(--brand-text); cursor: pointer; }
.link:hover { text-decoration: underline; }

input {
  font: inherit; font-size: 16px; /* ≥16px prevents iOS zoom on focus */
  width: 100%; height: 42px; padding: 0 12px;
  color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
@media (min-width: 768px) { input { font-size: 14px; } }

/* Segmented pills */
.pills {
  display: inline-flex; gap: 2px; padding: 3px; max-width: 100%;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
}
.pills.scroll { overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
.pills.scroll::-webkit-scrollbar { display: none; }
.pills button {
  flex: none; height: 32px; padding: 0 13px; border: 0; border-radius: 9px; background: transparent;
  font: inherit; font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer; scroll-snap-align: start;
  transition: background .15s, color .15s, box-shadow .15s;
}
.pills button:hover { color: var(--text); }
.pills button.on { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 0 0 1px var(--line); }

/* ============================================================
   Login
   ============================================================ */
.login { position: relative; min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px 16px; overflow: hidden; }
.login-glow {
  position: absolute; inset: -20% -10% auto; height: 70%; pointer-events: none;
  background: radial-gradient(closest-side, rgba(99, 102, 241, .22), transparent), radial-gradient(closest-side at 70% 40%, rgba(139, 92, 246, .18), transparent);
  filter: blur(20px);
}
.login-card {
  position: relative; width: 100%; max-width: 400px; display: grid; gap: 18px; padding: 32px 26px;
  background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lg);
}
.login-card h1 { font-size: 24px; margin-bottom: 4px; }
.login-card p { margin: 0; }
.input-label { display: grid; gap: 7px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.pw { position: relative; display: block; }
.pw input { padding-right: 44px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 8px; }
.pw-toggle:hover { color: var(--text); }
.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; color: var(--danger); background: var(--danger-bg); border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand.lg { font-size: 16px; }
.logo {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; flex: none; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 4px 12px rgba(91, 91, 240, .35);
}
.logo svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }

/* ============================================================
   App shell
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-in { max-width: 1240px; margin: 0 auto; height: 60px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.me { display: flex; align-items: center; gap: 4px; min-width: 0; }
.user { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 4px 10px 4px 4px; margin: 0 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
.avatar {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; flex: none;
  font-size: 12px; font-weight: 700; color: #fff; text-transform: uppercase;
  background: linear-gradient(135deg, var(--c-blue), var(--brand-2));
}
.user-email { font-size: 13px; font-weight: 500; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 20px 16px calc(32px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.filters > *, .f-row > * { min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.page-head h1 { font-size: 24px; }
.page-head p { margin: 2px 0 0; font-size: 13px; }
.head-actions { display: flex; gap: 8px; }

/* ---------- filters ---------- */
.filters { padding: 12px; display: grid; gap: 10px; }
.f-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.f-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.f-label { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.dates { justify-content: flex-start; padding: 10px; border-radius: 12px; background: var(--panel-2); border: 1px dashed var(--line); }
.date { display: grid; gap: 4px; flex: 1 1 140px; max-width: 220px; }
.date span { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.date input { height: 38px; }
.date-sep { color: var(--muted); padding-top: 18px; }

/* ---------- offers popover / bottom sheet ---------- */
.pop-wrap { position: relative; }
.pop {
  position: absolute; z-index: 40; top: calc(100% + 8px); right: 0; width: 340px; padding: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: pop-in .14s ease-out;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.pop-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.search { position: relative; display: block; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 36px; height: 38px; }
.pop-list { max-height: 300px; overflow-y: auto; margin: 8px -4px; overscroll-behavior: contain; }
.pop-list label { display: flex; align-items: center; gap: 12px; padding: 9px 8px; border-radius: 10px; cursor: pointer; }
.pop-list label:hover { background: var(--hover); }
.pop-list input { width: 18px; height: 18px; flex: none; accent-color: var(--brand); margin: 0; box-shadow: none; }
.pop-list .o-name { display: block; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-list .o-meta { display: block; font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.pop-list > p { padding: 16px 8px; margin: 0; }
.pop-foot { display: flex; justify-content: space-between; align-items: center; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; }
.scrim { position: fixed; inset: 0; z-index: 35; background: rgba(8, 8, 14, .45); animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kpi {
  position: relative; overflow: hidden; display: grid; gap: 6px; padding: 14px 16px 16px; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.kpi::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--accent); opacity: .9; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-top span { font-size: 12px; font-weight: 600; color: var(--muted); }
.kpi-top i { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); }
.kpi b { font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi small { font-size: 12px; font-variant-numeric: tabular-nums; }
.kpi.hero { background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 9%, var(--panel)), var(--panel) 65%); border-color: color-mix(in srgb, var(--brand) 28%, var(--line)); }

/* ---------- table ---------- */
.table-card { overflow: hidden; }
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.table-head h2 { font-size: 15px; }
.table-head p { margin: 2px 0 0; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; transition: opacity .2s; }
.table-scroll.dim { opacity: .55; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
th, td { padding: 11px 18px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th {
  position: sticky; top: 0; z-index: 1;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  background: var(--panel-2); border-bottom: 1px solid var(--line); cursor: pointer; user-select: none;
}
thead th:hover { color: var(--text); }
thead th .ic { width: 12px; height: 12px; margin-left: 4px; vertical-align: -1px; opacity: 0; transition: opacity .15s, transform .15s; }
thead th:hover .ic { opacity: .5; }
thead th.sorted { color: var(--brand-text); }
thead th.sorted .ic { opacity: 1; }
thead th.sorted.asc .ic { transform: rotate(180deg); }
tbody td { border-bottom: 1px solid var(--line-2); color: var(--text-2); }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: 0; }

.lbl { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 420px; }
.lbl-txt { min-width: 0; flex: 1; }
.lbl-name { display: block; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.share { display: block; height: 4px; margin-top: 6px; border-radius: 4px; background: var(--line-2); overflow: hidden; max-width: 220px; }
.share > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.flag { font-size: 18px; line-height: 1; flex: none; }
.rank { flex: none; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; font-size: 11px; font-weight: 700; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); }
.rev { font-weight: 700; color: var(--text); }
.cvr {
  display: inline-block; min-width: 58px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; text-align: center;
  color: var(--tone); background: color-mix(in srgb, var(--tone) 13%, transparent);
}
.zero { color: color-mix(in srgb, var(--muted) 70%, transparent); }

tfoot td { font-weight: 700; color: var(--text); background: var(--panel-2); border-top: 1px solid var(--line); }
.total-tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--panel); background: var(--text); }

.empty td { padding: 56px 20px; text-align: center; }
.empty-ic { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; margin-bottom: 12px; color: var(--brand-text); background: var(--brand-soft); }
.empty-ic .ic { width: 24px; height: 24px; }
.empty strong { display: block; font-size: 15px; color: var(--text); }
.empty p { margin: 4px 0 0; color: var(--muted); white-space: normal; }

/* Skeleton */
.sk { display: inline-block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--line-2), var(--line), var(--line-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.foot { margin: 4px 0 0; }

/* Loading bar */
.loading { position: fixed; top: 0; left: 0; z-index: 60; height: 3px; width: 0; opacity: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .3s, opacity .4s; }
.loading.on { width: 75%; opacity: 1; transition: width 5s cubic-bezier(.1, .7, .1, 1); }
.loading.done { width: 100%; opacity: 0; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1024px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpi.hero { grid-column: 1 / -1; order: -1; }
  .kpi.hero b { font-size: 30px; }
}

@media (max-width: 720px) {
  .topbar-in { height: 56px; }
  .brand-name { display: none; }
  .user { border: 0; background: none; padding: 0; margin: 0; }
  .user-email { max-width: 46vw; }
  .wrap { padding-top: 14px; gap: 12px; }
  .page-head h1 { font-size: 20px; }
  .hide-sm { display: none; }
  .head-actions .btn { padding: 0 12px; }

  .filters { padding: 10px; }
  /* nowrap matters: a wrapping column-flex sizes each line to its content, not the container */
  .f-row { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .f-row > .pills, .f-group .pills { width: 100%; }
  .f-row > #tz { align-self: flex-start; width: auto; }
  .f-group { flex-direction: column; align-items: stretch; gap: 6px; }
  .dates { flex-direction: row; align-items: flex-end; gap: 8px; }
  .date { flex: 1 1 0; min-width: 0; max-width: none; }
  .date input { min-width: 0; padding: 0 8px; }
  .date-sep { display: none; }
  .pop-wrap > .btn { width: 100%; justify-content: flex-start; }
  .pop-wrap > .btn .chev { margin-left: auto; }

  /* Offers picker becomes a bottom sheet */
  .pop {
    position: fixed; inset: auto 0 0 0; width: auto; max-height: 80vh; display: flex; flex-direction: column;
    border-radius: 20px 20px 0 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    animation: sheet-in .2s ease-out;
  }
  .pop::before { content: ""; align-self: center; width: 38px; height: 4px; border-radius: 4px; background: var(--line); margin: -4px 0 10px; }
  .pop-list { max-height: none; flex: 1; }
  @keyframes sheet-in { from { transform: translateY(100%); } }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 14px 14px; }
  .kpi b { font-size: 22px; }
  .kpi.hero b { font-size: 28px; }

  /* Table → cards */
  .table-head { padding: 12px 14px; }
  .table-scroll { overflow: visible; }
  table, tbody, tfoot { display: block; }
  thead { display: none; }
  tbody tr, tfoot tr {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 8px;
    padding: 14px; border-bottom: 1px solid var(--line-2);
  }
  tbody tr:hover { background: none; }
  tbody tr:last-child { border-bottom: 0; }
  tbody td, tfoot td { display: block; padding: 0; border: 0; text-align: left; white-space: normal; background: none; }
  td[data-l]::before { content: attr(data-l); display: block; margin-bottom: 1px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
  td.c-label { grid-column: 1 / 4; }
  td.c-rev { grid-column: 4; grid-row: 1; text-align: right; align-self: center; font-size: 15px; }
  td.c-rev::before { display: none; }
  .lbl { max-width: none; }
  .share { max-width: none; }
  .cvr { min-width: 0; padding: 1px 7px; }
  tfoot tr { border-top: 2px solid var(--line); background: var(--panel-2); }
  .empty td { grid-column: 1 / -1; padding: 40px 12px; }
}

@media (max-width: 360px) {
  tbody tr, tfoot tr { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  td.c-label { grid-column: 1 / -1; }
  td.c-rev { grid-column: 1 / -1; grid-row: auto; text-align: left; }
}

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