:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #18202a;
  --muted: #647282;
  --line: #dbe1e8;
  --accent: #146ef5;
  --accent-dark: #0d4fb3;
  --good: #157f5b;
  --warn: #9b5b00;
  --soft-blue: #eaf2ff;
  --soft-green: #e7f6ef;
  --shadow: 0 18px 50px rgba(18, 34, 54, 0.08);
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.locked {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(17, 25, 35, 0.96), rgba(24, 32, 42, 0.9)),
    #111923;
}

.auth-screen.hidden {
  display: none;
}

.auth-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: #f7f9fb;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.auth-brand {
  margin-bottom: 8px;
}

.auth-hint {
  margin: 0;
  color: #aeb9c5;
  font-size: 13px;
  line-height: 1.45;
}

.auth-hint code {
  color: #fff;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
}

.check-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #111923;
  color: #f7f9fb;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.note {
  color: #aeb9c5;
  font-size: 13px;
}

.panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.panel-body {
  display: grid;
  gap: 14px;
}

.collapsible.collapsed .panel-body {
  display: none;
}

.panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.panel-toggle::after {
  content: "⌃";
  font-size: 14px;
}

.collapsible.collapsed .panel-toggle::after {
  content: "⌄";
}

.panel-toggle:hover {
  background: transparent;
}

.light-panel {
  display: grid;
  gap: 14px;
}

.light-toggle {
  color: var(--ink);
  padding: 0;
}

.panel h2,
.section-heading h2 {
  margin: 0;
  font-size: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: inherit;
  font-size: 13px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

select[multiple] {
  height: auto;
  padding: 8px;
}

.account-check-list {
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: #dbe4ee;
  background: rgba(0, 0, 0, 0.12);
}

.account-option {
  font-size: 12px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 110, 245, 0.16);
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 750;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary {
  background: rgba(255, 255, 255, 0.12);
}

button.secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 104px;
  gap: 8px;
}

.note {
  line-height: 1.55;
  margin: 0;
}

.note code {
  color: #fff;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  margin: 0 0 6px;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

.status-pill {
  flex: 0 0 auto;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--warn);
  background: #fff3dd;
  font-weight: 750;
  font-size: 13px;
}

.status-pill.connected {
  color: var(--good);
  background: var(--soft-green);
}

.status-stack {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.stored-period {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.report-link {
  border: 1px solid #c7d6e8;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  padding: 9px 12px;
}

.report-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.metrics-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.metrics-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.metric-card,
.chart-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 96px;
  padding: 16px;
}

.metric-card span,
.section-heading span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  font-size: 24px;
  line-height: 1;
}

.metric-card small {
  color: var(--muted);
  font-size: 12px;
}

.content-grid {
  display: grid;
  gap: 16px;
}

.chart-panel,
.table-panel {
  padding: 18px;
  min-width: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 20px;
}

#spendChart {
  display: block;
  width: 100%;
  height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

#searchInput {
  max-width: 260px;
}

.search-tools,
.chart-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.column-filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.chart-controls label {
  min-width: 150px;
}

.chart-controls .check-row {
  width: auto;
  min-height: 42px;
}

.audience-viz-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.audience-viz-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.audience-viz-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.audience-viz-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.mini-bar {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.mini-bar:last-child {
  border-bottom: 0;
}

.mini-bar span,
.mini-bar strong {
  position: relative;
  z-index: 1;
  font-size: 12px;
}

.mini-bar i {
  position: absolute;
  left: 0;
  bottom: 4px;
  height: 4px;
  border-radius: 4px;
  background: var(--accent);
}

.compact-button {
  min-height: 42px;
  color: var(--ink);
  border: 1px solid var(--line);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.tag-button,
.tag-remove {
  min-height: 32px;
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.tag-remove {
  border-left: 1px solid var(--line);
  color: var(--muted);
}

.tag-button:hover,
.tag-remove:hover {
  background: var(--soft-blue);
  color: var(--accent-dark);
}

.view-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}

.tab-button {
  min-height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.tab-button:hover,
.tab-button.active {
  border-color: var(--accent);
  background: var(--soft-blue);
  color: var(--accent-dark);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 2060px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
}

th {
  background: #f7f9fc;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

th[data-sort] {
  cursor: pointer;
}

th[data-sort]:hover {
  color: var(--accent-dark);
}

td:first-child {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
}

tr:last-child td {
  border-bottom: 0;
}

.summary-row td {
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: #eef4fb;
  color: var(--ink);
  font-weight: 800;
  border-top: 1px solid var(--line);
}

.is-hidden {
  display: none;
}

.url-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delta-up {
  color: #9a3412;
  font-weight: 750;
}

.delta-down {
  color: var(--good);
  font-weight: 750;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: none;
  max-width: 360px;
  border-radius: 8px;
  padding: 13px 15px;
  color: #fff;
  background: #18202a;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.toast.show {
  display: block;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .metrics-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }
}

@media (max-width: 700px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .status-stack {
    align-items: stretch;
  }

  .stored-period {
    text-align: left;
  }

  h1 {
    font-size: 24px;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #searchInput {
    max-width: none;
  }
}
