:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #121525;
  --muted: #73798a;
  --border: #e8eaf0;
  --purple: #5535ea;
  --purple-soft: #f0ecff;
  --green: #3aa853;
  --green-soft: #eaf7ed;
  --red: #d94b58;
  --red-soft: #fff0f1;
  --amber: #b77809;
  --amber-soft: #fff7df;
  --shadow: 0 10px 30px rgba(22, 25, 46, 0.06);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }

.report-app { max-width: 1540px; margin: 0 auto; padding: 28px; }
.report-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}
.report-brand { display: flex; align-items: center; gap: 13px; }
.report-logo {
  width: 48px; height: 48px; display: grid; place-items: center;
  border-radius: 15px; background: var(--purple); color: #fff;
  font-size: 14px; font-weight: 900; letter-spacing: -.5px;
  box-shadow: 0 8px 24px rgba(85, 53, 234, .22);
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 28px; line-height: 1.05; letter-spacing: -.8px; }
h2 { margin-bottom: 0; font-size: 20px; letter-spacing: -.35px; }
.eyebrow { color: var(--purple); font-size: 11px; font-weight: 900; letter-spacing: 1.15px; margin-bottom: 4px; }
.header-actions, .range-switch, .connection-fields, .table-tools, .live-note { display: flex; align-items: center; gap: 9px; }
.range-switch { padding: 4px; background: #fff; border: 1px solid var(--border); border-radius: 13px; box-shadow: var(--shadow); }
.range-btn { border: 0; background: transparent; color: var(--muted); border-radius: 9px; padding: 8px 11px; font-size: 13px; font-weight: 750; }
.range-btn.active { background: var(--purple-soft); color: var(--purple); }
.primary-btn, .secondary-btn {
  border: 0; border-radius: 12px; padding: 11px 15px; font-weight: 800;
}
.primary-btn { background: var(--purple); color: #fff; box-shadow: 0 7px 18px rgba(85, 53, 234, .18); }
.secondary-btn { background: #151827; color: #fff; }
.primary-btn:disabled, .secondary-btn:disabled { opacity: .55; cursor: wait; }

.connection-card {
  display: grid; grid-template-columns: minmax(210px, .7fr) minmax(560px, 1.3fr); gap: 20px;
  background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 15px 17px; margin-bottom: 25px;
}
.connection-title { font-size: 14px; font-weight: 850; margin-bottom: 3px; }
.connection-copy, .card-copy { color: var(--muted); font-size: 12px; line-height: 1.45; margin-bottom: 0; }
.connection-fields { justify-content: flex-end; flex-wrap: wrap; }
.connection-fields label { display: flex; flex-direction: column; gap: 4px; }
.connection-fields label span { color: var(--muted); font-size: 10px; font-weight: 750; }
.connection-fields input, .table-tools input {
  border: 1px solid var(--border); background: #fafbfc; color: var(--text); outline: none; border-radius: 10px; padding: 9px 11px;
}
.connection-fields input:focus, .table-tools input:focus { border-color: #b9acf8; box-shadow: 0 0 0 3px var(--purple-soft); }
#apiBase { width: 220px; }
#adminKey { width: 185px; }
.connection-status { grid-column: 1 / -1; display: none; padding-top: 8px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.connection-status.show { display: block; }
.connection-status.ok { color: var(--green); }
.connection-status.bad { color: var(--red); }

.section-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 18px; margin-bottom: 12px; }
.compact-heading h2 { font-size: 23px; }
.live-note { color: var(--muted); font-size: 12px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

.kpi-grid { display: grid; grid-template-columns: repeat(7, minmax(135px, 1fr)); gap: 11px; margin-bottom: 22px; }
.kpi-card { min-height: 128px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 17px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 750; }
.kpi-value { font-size: 31px; line-height: 1; font-weight: 900; letter-spacing: -1.25px; margin: 16px 0 10px; }
.kpi-foot { color: var(--muted); font-size: 11px; }
.purple-card { border-color: #ddd5ff; background: linear-gradient(145deg, #fff 35%, #f4f1ff); }
.purple-card .kpi-value { color: var(--purple); }
.success-card .kpi-value { color: var(--green); }
.danger-card .kpi-value { color: var(--red); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(360px, .75fr); gap: 14px; margin-bottom: 14px; }
.data-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 19px 14px; border-bottom: 1px solid var(--border); }
.muted-small { color: var(--muted); font-size: 12px; }
.count-pill { display: inline-flex; align-items: center; justify-content: center; min-height: 28px; padding: 5px 9px; border-radius: 999px; background: #f3f4f7; color: #626879; font-size: 11px; font-weight: 800; white-space: nowrap; }

.snipe-list { padding: 0 14px 8px; }
.snipe-row { display: grid; grid-template-columns: 54px minmax(180px, 1.4fr) minmax(105px, .55fr) 126px 98px 98px; gap: 13px; align-items: center; padding: 13px 5px; border-bottom: 1px solid var(--border); }
.snipe-row:last-child { border-bottom: 0; }
.item-image, .item-fallback { width: 54px; height: 54px; border-radius: 12px; object-fit: cover; background: #eeeeF3; border: 1px solid #e5e6ec; }
.item-fallback { display: grid; place-items: center; background: var(--purple-soft); color: var(--purple); font-size: 11px; font-weight: 900; }
.snipe-title { min-width: 0; }
.snipe-title a { display: block; color: var(--text); text-decoration: none; font-size: 13px; font-weight: 820; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snipe-title a:hover { color: var(--purple); }
.snipe-meta { color: var(--muted); font-size: 10px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-label { display: block; color: #999eaa; font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .55px; margin-bottom: 4px; }
.cell-value { font-size: 12px; font-weight: 800; }
.countdown { color: var(--purple); font-size: 16px; font-variant-numeric: tabular-nums; font-weight: 900; letter-spacing: -.35px; }
.countdown.soon { color: var(--red); }
.status-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 6px 9px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: .35px; white-space: nowrap; }
.status-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-chip.firing { color: var(--purple); background: var(--purple-soft); }
.status-chip.awaiting_result { color: var(--amber); background: var(--amber-soft); }

.result-list { padding: 5px 17px 10px; }
.result-row { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.result-row:last-child { border-bottom: 0; }
.result-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; font-size: 15px; font-weight: 900; }
.result-icon.won { background: var(--green-soft); color: var(--green); }
.result-icon.lost, .result-icon.failed { background: var(--red-soft); color: var(--red); }
.result-icon.cancelled { background: #f1f2f5; color: #727887; }
.result-main { min-width: 0; }
.result-name { color: var(--text); font-size: 12px; font-weight: 820; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-sub { color: var(--muted); font-size: 10px; margin-top: 3px; }
.result-value { text-align: right; font-size: 12px; font-weight: 850; }
.result-badge { display: block; margin-top: 3px; font-size: 9px; font-weight: 900; text-transform: uppercase; }
.result-badge.won { color: var(--green); }
.result-badge.lost, .result-badge.failed { color: var(--red); }
.result-badge.cancelled { color: var(--muted); }

.table-card { margin-bottom: 14px; }
.table-heading { align-items: flex-end; }
.table-heading .card-copy { max-width: 690px; margin-top: 6px; }
.table-tools input { width: 235px; }
.table-wrap { overflow: auto; max-height: 470px; }
.purchases-wrap { max-height: 365px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.report-table th, .report-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.report-table th { position: sticky; top: 0; z-index: 1; background: #fafbfc; color: #858b99; font-size: 10px; text-transform: uppercase; letter-spacing: .45px; }
.report-table tbody tr:hover { background: #fafaff; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10px; }
.user-main { font-weight: 800; }
.user-sub { color: var(--muted); font-size: 9px; margin-top: 2px; }
.ebay-connected { color: var(--green); font-weight: 800; }
.ebay-none { color: #9ca1ad; }
.credit-number { font-weight: 900; }
.empty-state { padding: 34px 18px; color: var(--muted); text-align: center; font-size: 12px; }
.empty-table { text-align: center !important; color: var(--muted); padding: 28px !important; }

.report-footer { display: flex; align-items: center; justify-content: space-between; gap: 18px; color: var(--muted); font-size: 11px; padding: 9px 2px 4px; }
.report-footer a { color: var(--purple); text-decoration: none; font-weight: 800; }

@media (max-width: 1260px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .report-app { padding: 18px; }
  .report-header { align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .connection-card { grid-template-columns: 1fr; }
  .connection-status { grid-column: 1; }
  .connection-fields { justify-content: flex-start; }
  .snipe-row { grid-template-columns: 54px minmax(180px, 1fr) 112px 94px; }
  .snipe-row .current-cell, .snipe-row .max-cell { display: none; }
}
@media (max-width: 680px) {
  .report-app { padding: 13px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-card { min-height: 116px; }
  .range-switch { width: 100%; overflow-x: auto; }
  .range-btn { flex: 1 0 auto; }
  .connection-fields { align-items: stretch; flex-direction: column; }
  #apiBase, #adminKey { width: 100%; }
  .table-heading { align-items: flex-start; flex-direction: column; }
  .table-tools { width: 100%; }
  .table-tools input { flex: 1; min-width: 0; width: auto; }
  .snipe-row { grid-template-columns: 48px minmax(0, 1fr) 104px; }
  .item-image, .item-fallback { width: 48px; height: 48px; }
  .snipe-row .user-cell, .snipe-row .current-cell, .snipe-row .max-cell { display: none; }
  .countdown { font-size: 14px; }
}


/* When Reporting is opened inside the operational Admin tab, keep only the clean report surface. */
body.embedded {
  background: #f5f6fa;
}

body.embedded .report-app {
  max-width: none;
  padding: 18px;
}

body.embedded .report-brand,
body.embedded .connection-card,
body.embedded .report-footer {
  display: none;
}

body.embedded .report-header {
  justify-content: flex-end;
  margin-bottom: 16px;
}

body.embedded main {
  margin: 0;
}

@media (max-width: 680px) {
  body.embedded .report-app { padding: 12px; }
}
