:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-alt: #eef4f1;
  --text: #16202a;
  --muted: #657384;
  --line: #d8e0e8;
  --primary: #116a73;
  --primary-strong: #0b4e55;
  --accent: #b95c2b;
  --danger: #b3261e;
  --danger-bg: #fff0ee;
  --success: #187445;
  --shadow: 0 16px 40px rgba(20, 36, 54, 0.09);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 1120px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  min-height: 38px;
  padding: 8px 12px;
  cursor: pointer;
  transition: 120ms ease;
}

button:hover {
  border-color: #9eb0bf;
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

button.primary:hover {
  background: var(--primary-strong);
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(17, 106, 115, 0.14);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

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

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  display: grid;
  gap: 16px;
  width: min(400px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 2px;
}

.login-heading {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.login-heading h2 {
  margin: 0;
  font-size: 22px;
}

.form-error {
  margin: 0;
  padding: 9px 10px;
  border-left: 3px solid var(--danger);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.app-shell.report-mode {
  grid-template-columns: 300px minmax(0, 1fr);
}

.app-shell.report-mode .inspector {
  display: none;
}

.app-shell.report-mode .workspace {
  max-width: 1600px;
}

.app-shell.report-mode .topbar-actions {
  display: none;
}

.sidebar,
.workspace,
.inspector {
  min-width: 0;
}

.sidebar,
.inspector {
  position: sticky;
  top: 18px;
  height: calc(100vh - 36px);
  overflow: auto;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.brand h1,
.brand p,
.panel h2,
.panel h3,
.topbar h2,
.eyebrow {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p,
.hint,
.eyebrow {
  color: var(--muted);
  font-size: 13px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.nav-tab {
  justify-content: flex-start;
  text-align: left;
}

.nav-tab.active {
  background: #e2f1ee;
  border-color: #9ccac2;
  color: var(--primary-strong);
  font-weight: 700;
}

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

.connection-panel,
.account-panel,
.action-form,
.result-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.account-email {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.operator-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.operator-list-panel {
  min-width: 0;
  padding: 16px;
}

.operator-table {
  margin-top: 14px;
  overflow: auto;
  border: 1px solid var(--line);
}

.operator-table table {
  min-width: 760px;
}

.operator-table select {
  min-width: 132px;
}

.table-subtext {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-title h2 {
  font-size: 18px;
}

.panel-title h3 {
  font-size: 16px;
}

.method,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
}

.method {
  background: var(--surface-alt);
  color: var(--primary-strong);
}

.method.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.status-pill.muted {
  background: #eef1f4;
  color: var(--muted);
}

.status-pill.ok {
  background: #e8f6ee;
  color: var(--success);
}

.status-pill.bad {
  background: var(--danger-bg);
  color: var(--danger);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 70px;
  padding: 12px 2px 18px;
}

.topbar h2 {
  font-size: 28px;
}

.topbar-actions,
.button-row,
.two-col {
  display: flex;
  gap: 10px;
}

.two-col > * {
  flex: 1;
  min-width: 0;
}

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

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

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

.compact {
  gap: 12px;
}

.wide {
  grid-column: 1 / -1;
}

.tab-view {
  display: none;
}

.tab-view.active {
  display: block;
}

.report-workspace {
  min-width: 0;
}

.report-toolbar {
  position: sticky;
  z-index: 5;
  top: 0;
  display: grid;
  grid-template-columns: auto minmax(560px, 1fr);
  gap: 12px 22px;
  align-items: end;
  margin-bottom: 18px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(246, 248, 251, 0.96);
}

.report-tabs,
.date-presets {
  display: inline-flex;
  align-items: center;
}

.report-tabs button,
.date-presets button {
  min-height: 36px;
  border-radius: 0;
  margin-left: -1px;
}

.report-tabs button:first-child,
.date-presets button:first-child {
  margin-left: 0;
  border-radius: 6px 0 0 6px;
}

.report-tabs button:last-child,
.date-presets button:last-child {
  border-radius: 0 6px 6px 0;
}

.report-tab.active,
.date-presets button.active {
  position: relative;
  z-index: 1;
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.report-filters {
  display: grid;
  grid-template-columns: auto minmax(140px, 180px) minmax(140px, 180px) auto;
  gap: 10px;
  align-items: end;
  justify-content: end;
}

.report-context {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 26px;
  color: var(--muted);
  font-size: 13px;
}

.report-context > :first-child {
  color: var(--text);
  font-weight: 700;
}

.timezone-label {
  margin-left: auto;
}

.report-pane {
  display: none;
}

.report-pane.active {
  display: grid;
  gap: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.kpi-item {
  display: grid;
  gap: 8px;
  min-width: 0;
  min-height: 94px;
  padding: 16px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.kpi-item span {
  color: var(--muted);
  font-size: 13px;
}

.kpi-item strong {
  overflow-wrap: anywhere;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.report-section {
  min-width: 0;
  padding: 16px 0 4px;
  border-top: 1px solid var(--line);
  background: transparent;
}

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

.report-section-title h3 {
  margin: 0;
  font-size: 16px;
}

.report-meta {
  color: var(--muted);
  font-size: 12px;
}

.report-layout.two-up {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.8fr);
  gap: 24px;
}

.report-chart {
  width: 100%;
  min-height: 320px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
}

.report-chart svg {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 5;
  min-height: 270px;
}

.chart-grid-line {
  stroke: #dde4eb;
  stroke-width: 1;
}

.chart-axis-label {
  fill: #657384;
  font-size: 11px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  min-height: 40px;
  padding: 12px 16px 4px;
  color: var(--muted);
  font-size: 12px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 18px;
  height: 3px;
  background: #0f766e;
}

.legend-1 { background: #2563a5; }
.legend-2 { background: #b45309; }
.legend-3 { background: #7c3f8c; }

.report-table {
  max-width: 100%;
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--surface);
}

.report-table th,
.report-table td {
  min-width: 100px;
  max-width: none;
  padding: 10px 12px;
  white-space: nowrap;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.report-empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.bar-list,
.funnel-list {
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 320px;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 0.7fr) minmax(120px, 1.6fr) 56px;
  gap: 10px;
  align-items: center;
  font-size: 12px;
}

.bar-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row strong {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

progress {
  width: 100%;
  height: 9px;
  overflow: hidden;
  border: 0;
  border-radius: 4px;
  background: #e8edf2;
}

progress::-webkit-progress-bar {
  background: #e8edf2;
}

progress::-webkit-progress-value {
  background: var(--primary);
}

progress::-moz-progress-bar {
  background: var(--primary);
}

.funnel-row {
  display: grid;
  gap: 7px;
}

.funnel-row div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.funnel-row strong {
  font-variant-numeric: tabular-nums;
}

.funnel-step-1::-webkit-progress-value { background: #2563a5; }
.funnel-step-2::-webkit-progress-value { background: #b45309; }
.funnel-step-3::-webkit-progress-value { background: #15803d; }
.funnel-step-1::-moz-progress-bar { background: #2563a5; }
.funnel-step-2::-moz-progress-bar { background: #b45309; }
.funnel-step-3::-moz-progress-bar { background: #15803d; }

.monetization-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px;
  gap: 14px;
  align-items: start;
}

.currency-filter {
  align-self: start;
}

.danger-form {
  border-color: #f0bbb5;
}

.confirm-row,
.switch {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.confirm-row input,
.switch input {
  width: 16px;
  min-height: 16px;
}

.config-rows {
  display: grid;
  gap: 10px;
}

.config-row {
  display: grid;
  grid-template-columns: 1.2fr 1.6fr 92px 72px;
  gap: 10px;
  align-items: center;
}

.result-panel {
  height: 100%;
}

.toast {
  border-radius: 7px;
  padding: 10px 12px;
  background: #fff4e8;
  color: #743800;
  border: 1px solid #f2c28c;
}

.table-host {
  overflow: auto;
  max-height: 42vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: none;
}

.table-host.active {
  display: block;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
  max-width: 220px;
  overflow-wrap: anywhere;
}

th {
  position: sticky;
  top: 0;
  background: #f7fafc;
  color: var(--muted);
  font-weight: 800;
}

pre {
  flex: 1;
  min-height: 280px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: #111820;
  color: #d7f3e3;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 1240px) {
  body {
    min-width: 0;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar,
  .inspector {
    position: static;
    height: auto;
  }

  .grid.two,
  .grid.four {
    grid-template-columns: 1fr;
  }

  .app-shell.report-mode {
    grid-template-columns: minmax(0, 1fr);
  }

  .report-toolbar {
    position: static;
    grid-template-columns: 1fr;
  }

  .report-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }

  .date-presets {
    align-self: end;
  }

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

  .report-layout.two-up,
  .monetization-head,
  .operator-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .app-shell {
    gap: 12px;
    padding: 12px;
  }

  .sidebar {
    display: contents;
  }

  .brand {
    order: 0;
    margin-bottom: 0;
  }

  .nav-tabs {
    order: 1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 0;
  }

  .workspace {
    order: 2;
  }

  .connection-panel,
  .account-panel {
    order: 3;
  }

  .inspector {
    order: 4;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    min-height: 58px;
    padding-bottom: 10px;
  }

  .topbar-actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .topbar h2 {
    font-size: 24px;
  }

  .report-tabs,
  .date-presets {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
  }

  .report-tabs button,
  .date-presets button,
  .report-tabs button:first-child,
  .report-tabs button:last-child,
  .date-presets button:first-child,
  .date-presets button:last-child {
    margin: -1px 0 0 -1px;
    border-radius: 0;
    min-width: 0;
  }

  .report-filters,
  .kpi-grid {
    grid-template-columns: 1fr;
    width: 100%;
    min-width: 0;
  }

  .report-toolbar > *,
  .report-filters > *,
  .report-pane,
  .kpi-item {
    min-width: 0;
  }

  .timezone-label {
    margin-left: 0;
  }

  .report-context {
    flex-wrap: wrap;
  }
}
