@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=Syne:wght@600;700&display=swap");

:root {
  --bg: #f4f0e6;
  --bg-2: #e6f2ea;
  --panel: #fffdf8;
  --text: #1b2227;
  --muted: #5d6971;
  --ink-soft: #2f3f49;
  --line: #d6dddf;
  --accent: #0f9f8f;
  --accent-2: #ff7a45;
  --accent-3: #24558d;
  --shadow: 0 16px 48px rgba(31, 40, 44, 0.12);
  --radius: 20px;
  --bg-3: #f6ede2;
  --orb-a: #f6b083;
  --orb-b: #7bd6c7;
  --noise-rgb: 20 24 28;
  --surface-rgb: 255 255 255;
  --surface-2-rgb: 250 253 250;
  --warm-rgb: 255 253 248;
  --tint-rgb: 237 247 244;
  --tint-2-rgb: 237 241 241;
  --line-rgb: 214 221 223;
  --line-2-rgb: 191 205 211;
  --line-3-rgb: 160 176 184;
  --ink-rgb: 47 63 73;
  --bg-rgb: 241 238 228;
  --field: #fff;
  --field-disabled: #f1f5f3;
  --btn-secondary: #edf2f1;
  --danger-text: #8d2d2d;
  --positive-text: #087869;
  --status-info: #2e4f62;
  --status-ok: #0a7c5f;
  --status-error: #b03a1d;
  --faint: #a6b1b6;
  --kpi-rule: #eef2f3;
  --table-rule: #edf2f3;
  --table-head: #f6faf8;
  --table-head-text: #354450;
  --table-stripe: #fcfefb;
  --table-hover: #eef8f4;
  color-scheme: light dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: linear-gradient(140deg, var(--bg) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
  position: relative;
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.2;
  background-image: radial-gradient(rgb(var(--noise-rgb) / 0.12) 0.5px, transparent 0.5px);
  background-size: 3px 3px;
}

.bg-orb {
  position: fixed;
  width: 360px;
  height: 360px;
  border-radius: 999px;
  filter: blur(58px);
  opacity: 0.4;
  pointer-events: none;
}

.orb-a {
  top: -120px;
  right: -100px;
  background: var(--orb-a);
}

.orb-b {
  bottom: -120px;
  left: -80px;
  background: var(--orb-b);
}

.app-shell {
  width: min(1240px, 96vw);
  margin: 24px auto 48px;
  display: grid;
  gap: 16px;
}

.auth-gate {
  width: min(520px, 92vw);
  margin: 18vh auto 0;
  display: grid;
  gap: 18px;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.auth-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 11px;
  color: var(--text);
  background: var(--field);
}

.auth-form input:focus {
  outline: 2px solid rgba(15, 159, 143, 0.25);
  border-color: var(--accent);
}

.auth-message {
  min-height: 1.25em;
}

.app-shell > * {
  min-width: 0;
}

.panel {
  background: linear-gradient(180deg, rgb(var(--surface-rgb) / 0.86), rgb(var(--surface-rgb) / 0.95));
  border: 1px solid rgb(var(--surface-rgb) / 0.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.reveal {
  opacity: 0;
  transform: translateY(8px);
  animation: slide-up 460ms ease forwards;
}

.reveal:nth-child(2) {
  animation-delay: 40ms;
}

.reveal:nth-child(3) {
  animation-delay: 80ms;
}

.reveal:nth-child(4) {
  animation-delay: 120ms;
}

@keyframes slide-up {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h1,
h2 {
  margin: 0;
  font-family: "Syne", "Space Grotesk", sans-serif;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(1.6rem, 3vw, 2.45rem);
}

h2 {
  font-size: 1.08rem;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 700;
  font-size: 0.72rem;
  color: var(--accent-3);
}

.subtitle {
  margin: 8px 0 0;
  color: var(--ink-soft);
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: clamp(154px, 17vw, 230px);
  aspect-ratio: 25 / 8;
  flex: 0 0 auto;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.chip {
  background: linear-gradient(135deg, #0f9f8f, #24558d);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.72rem;
  padding: 8px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.setup-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(280px, 0.9fr) minmax(520px, 1.1fr);
  align-items: stretch;
}

.setup-card {
  height: 100%;
}

.setup-card h2 {
  margin-bottom: 14px;
}

.uploader {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px dashed rgba(36, 85, 141, 0.26);
  border-radius: 14px;
  background: linear-gradient(160deg, rgb(var(--surface-rgb) / 0.72), rgb(var(--tint-rgb) / 0.7));
}

.uploader-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

#csvFile {
  display: none;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 0.92rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  cursor: wait;
  opacity: 0.58;
  transform: none;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #1b7786);
  box-shadow: 0 8px 20px rgba(19, 106, 118, 0.25);
}

.btn-secondary {
  background: var(--btn-secondary);
  color: var(--ink-soft);
}

.secure-mode-btn[aria-pressed="true"],
.secure-mode-btn.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-3), #1b7786);
  box-shadow: 0 8px 20px rgba(36, 85, 141, 0.2);
}

.btn-danger {
  background: rgba(180, 58, 58, 0.1);
  color: var(--danger-text);
}

.btn-danger:hover:not(:disabled) {
  box-shadow: 0 8px 20px rgba(141, 45, 45, 0.12);
}

.btn-danger.is-confirming {
  color: #fff;
  background: #a53a3a;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  flex: 0 0 auto;
}

.icon-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn[aria-busy="true"] {
  opacity: 0.7;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.assumption-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.assumption-grid label {
  display: grid;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.assumption-grid input,
.assumption-grid select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 11px;
  color: var(--text);
  background: var(--field);
}

.assumption-grid input[readonly] {
  background: rgb(var(--tint-rgb) / 0.72);
  color: var(--ink);
  cursor: default;
}

.assumption-grid label.is-disabled,
.revenuecat-grid .option-toggle.is-disabled {
  color: var(--muted);
  opacity: 0.62;
}

.assumption-grid input:disabled,
.assumption-grid select:disabled {
  background: rgb(var(--tint-2-rgb) / 0.78);
  cursor: not-allowed;
}

.assumption-grid input:focus,
.assumption-grid select:focus {
  outline: 2px solid rgba(15, 159, 143, 0.25);
  border-color: var(--accent);
}

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

.revenuecat-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.revenuecat-grid label {
  display: grid;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.provider-field {
  grid-column: span 3;
}

.saved-credential-field {
  grid-column: span 4;
}

.api-key-field,
.project-id-field,
.adapty-app-name-field {
  grid-column: span 3;
}

.date-range-field,
.resolution-field {
  grid-column: span 2;
}

.revenuecat-grid input,
.revenuecat-grid select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 11px;
  color: var(--text);
  background: var(--field);
}

.revenuecat-grid input:focus,
.revenuecat-grid select:focus {
  outline: 2px solid rgba(15, 159, 143, 0.25);
  border-color: var(--accent);
}

.revenuecat-grid input:disabled,
.revenuecat-grid select:disabled {
  color: rgb(var(--ink-rgb) / 0.62);
  background: var(--field-disabled);
  cursor: not-allowed;
}

.checkbox-field {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
  min-height: 42px;
}

.revenuecat-control-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 2px;
}

.revenuecat-options {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  flex: 1 1 auto;
  min-width: 0;
}

.revenuecat-grid .option-toggle {
  display: inline-flex;
  align-items: center;
  width: auto;
  min-height: 36px;
  padding: 7px 11px 7px 9px;
  border: 1px solid rgb(var(--line-rgb) / 0.86);
  border-radius: 999px;
  background: rgb(var(--tint-rgb) / 0.62);
  color: var(--ink-soft);
  font-size: 0.8rem;
  line-height: 1;
  white-space: nowrap;
}

.checkbox-field input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.checkbox-field span {
  min-width: 0;
}

.checkbox-field small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.28;
}

.app-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(var(--bg-rgb) / 0.64);
  backdrop-filter: blur(5px);
}

.app-loading-overlay.is-hidden {
  display: none;
}

.app-loading-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(420px, 100%);
  padding: 18px 20px;
  border: 1px solid rgb(var(--line-rgb) / 0.9);
  border-radius: 18px;
  color: var(--text);
  background: rgb(var(--surface-rgb) / 0.94);
  box-shadow: 0 20px 50px rgba(32, 46, 55, 0.16);
}

.app-loading-card strong {
  display: block;
  font-size: 1rem;
  font-weight: 800;
}

.app-loading-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.app-loading-spinner {
  width: 30px;
  height: 30px;
  border: 4px solid rgba(15, 159, 143, 0.16);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: app-loading-spin 0.8s linear infinite;
  flex: 0 0 auto;
}

@keyframes app-loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.action-row {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.revenuecat-actions {
  width: auto;
  align-self: center;
  flex: 0 0 auto;
  margin-top: 0;
  justify-content: flex-end;
}

.project-select-wrap,
.credential-meta,
.revenuecat-meta,
.app-store-summary {
  grid-column: 1 / -1;
}

.credential-meta {
  align-self: end;
  grid-column: span 5;
  min-height: 42px;
  padding: 10px 0 0;
  border-top: 1px solid rgb(var(--line-rgb) / 0.58);
  color: rgb(var(--ink-rgb) / 0.76);
  font-size: 0.86rem;
  line-height: 1.35;
}

.app-store-summary {
  display: grid;
  gap: 12px;
  margin-top: 6px;
  padding: 13px;
  border: 1px solid rgb(var(--line-rgb) / 0.86);
  border-radius: 14px;
  background: linear-gradient(160deg, rgb(var(--warm-rgb) / 0.8), rgb(var(--tint-rgb) / 0.76));
}

.app-store-main {
  display: flex;
  gap: 14px;
  justify-content: space-between;
  align-items: center;
}

.app-store-identity {
  display: flex;
  min-width: 0;
  gap: 12px;
  align-items: center;
}

.app-store-icon {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  border: 1px solid rgb(var(--line-rgb) / 0.82);
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  object-fit: cover;
}

.app-store-icon-fallback {
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}

.app-store-eyebrow {
  margin: 0;
  color: var(--accent-3);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-store-title {
  margin: 2px 0 0;
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.app-store-subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.app-store-facts {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 8px;
}

.app-store-fact {
  display: grid;
  min-width: 0;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid rgb(var(--line-rgb) / 0.74);
  border-radius: 10px;
  background: rgb(var(--surface-rgb) / 0.68);
}

.app-store-fact-link {
  color: inherit;
  text-decoration: none;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.app-store-fact-link:hover {
  border-color: rgba(15, 159, 143, 0.36);
  background: rgb(var(--surface-rgb) / 0.9);
  transform: translateY(-1px);
}

.app-store-fact-link:focus-visible {
  outline: 2px solid rgba(15, 159, 143, 0.35);
  outline-offset: 2px;
}

.app-store-fact span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.app-store-fact strong {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.app-store-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}

.app-store-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.is-hidden {
  display: none !important;
}

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

.section-heading h2 {
  margin-bottom: 5px;
}

.training-panel {
  display: grid;
}

.training-controls,
.metric-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.seg-btn,
.metric-tab {
  border: 1px solid rgb(var(--line-3-rgb) / 0.42);
  border-radius: 10px;
  background: rgb(var(--surface-rgb) / 0.74);
  color: var(--ink-soft);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 8px 10px;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.seg-btn:hover,
.metric-tab:hover {
  transform: translateY(-1px);
}

.seg-btn.is-active,
.metric-tab.is-active {
  border-color: rgba(15, 159, 143, 0.55);
  background: rgba(15, 159, 143, 0.1);
  color: var(--positive-text);
}

.training-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 0.27fr);
  gap: 18px;
  align-items: stretch;
}

.training-main {
  min-width: 0;
}

.chart-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.manual-date {
  display: grid;
  gap: 6px;
  min-width: 172px;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 700;
}

.manual-date input {
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 9px 10px;
  background: var(--field);
}

.manual-date input:focus {
  outline: 2px solid rgba(15, 159, 143, 0.25);
  border-color: var(--accent);
}

.retention-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-bottom: 10px;
}

.retention-options .option-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 11px 7px 9px;
  border: 1px solid rgb(var(--line-rgb) / 0.86);
  border-radius: 999px;
  background: rgb(var(--tint-rgb) / 0.62);
  color: var(--ink-soft);
  font-size: 0.8rem;
  line-height: 1;
  white-space: nowrap;
}

.retention-options .option-toggle.is-disabled {
  color: var(--muted);
  opacity: 0.62;
}

.retention-spike-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.training-spike-marker rect {
  fill: none;
  stroke: #b4502a;
  stroke-width: 2;
  stroke-dasharray: 3 2;
}

.training-spike-marker path {
  fill: #b4502a;
}

.training-spike-legend text {
  fill: #b4502a;
  font-size: 11px;
  font-weight: 700;
}

.training-spike-legend path {
  fill: #b4502a;
}

.training-chart {
  height: clamp(300px, 28vw, 380px);
  min-height: 300px;
  border: 1px solid rgb(var(--line-2-rgb) / 0.6);
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(180deg, rgb(var(--surface-rgb) / 0.82), rgb(var(--surface-2-rgb) / 0.92));
}

.training-chart svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.training-hit-area,
.training-marker-hit {
  fill: transparent;
  cursor: ew-resize;
}

.training-marker-line {
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 6 5;
}

.training-marker-label rect {
  fill: var(--field);
  stroke: rgba(15, 159, 143, 0.38);
}

.training-marker-label text {
  fill: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.training-marker-label text + text {
  fill: var(--muted);
  font-size: 10px;
}

.chart-note {
  fill: rgb(var(--ink-rgb) / 0.68);
  font-size: 11px;
  font-weight: 700;
}

.training-summary {
  display: grid;
  align-content: stretch;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 0;
}

.training-summary div {
  display: grid;
  gap: 3px;
  padding: 10px 0;
  border-bottom: 1px solid rgb(var(--line-rgb) / 0.86);
}

.training-summary div:last-child {
  border-bottom: 0;
}

.training-summary dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.training-summary dd {
  margin: 0;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.status-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  padding-bottom: 12px;
}

.status {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.export-btn {
  flex: 0 0 auto;
}

.status-info {
  color: var(--status-info);
}

.status-ok {
  color: var(--status-ok);
}

.status-error {
  color: var(--status-error);
}

.duration-breakdown {
  display: grid;
  gap: 14px;
}

.duration-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.duration-heading h2 {
  margin-bottom: 4px;
}

.duration-total {
  display: grid;
  min-width: 160px;
  gap: 2px;
  text-align: right;
}

.duration-total span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.duration-total strong {
  color: var(--accent);
  font-size: 1.36rem;
  font-weight: 800;
  line-height: 1;
}

.duration-total small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.duration-total small b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.duration-segments {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.duration-segment {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  border: 1px solid rgb(var(--line-rgb) / 0.84);
  border-left: 5px solid var(--segment-color, var(--accent));
  border-radius: 14px;
  background: rgb(var(--surface-rgb) / 0.72);
}

.duration-name {
  margin: 0;
  color: var(--text);
  font-weight: 800;
}

.duration-meta {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.duration-segment dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.duration-segment div {
  min-width: 0;
}

.duration-segment dt {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.1;
}

.duration-segment dd {
  margin: 3px 0 0;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.kpi {
  background: var(--field);
  border: 1px solid var(--kpi-rule);
  border-left: 5px solid var(--accent-2);
  border-radius: 14px;
  padding: 12px 13px;
}

.kpi:nth-child(2n) {
  border-left-color: var(--accent);
}

.kpi:nth-child(3n) {
  border-left-color: var(--accent-3);
}

.kpi-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.kpi-value {
  margin: 6px 0 0;
  font-size: 1.32rem;
  font-weight: 700;
  color: var(--text);
}

.kpi-scenario-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  white-space: nowrap;
}

.kpi-scenario-row-compact {
  gap: 4px;
  font-size: 1.08rem;
}

.kpi-scenario {
  min-width: 0;
  color: var(--muted);
  font: inherit;
  line-height: 1;
}

.kpi-scenario-separator {
  color: var(--faint);
  font-size: 1.05rem;
  font-weight: 600;
}

.kpi-scenario-optimal {
  color: var(--accent);
  font-weight: 800;
}

.kpi-scenario-row-stacked {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  gap: 5px;
  white-space: normal;
  font-size: 0.94rem;
}

.kpi-scenario-row-stacked .kpi-scenario {
  display: grid;
  gap: 2px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.kpi-scenario-row-stacked .kpi-scenario::before {
  content: attr(data-label);
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
}

.kpi-scenario-row-stacked .kpi-scenario-separator {
  display: none;
}

.viz-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.chart {
  height: clamp(320px, 30vw, 420px);
  min-height: 300px;
}

.chart-empty {
  height: 100%;
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.chart svg {
  width: 100%;
  height: 100%;
  display: block;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
  background: var(--field);
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--table-rule);
  font-size: 0.88rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--table-head);
  color: var(--table-head-text);
  font-size: 0.79rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tbody tr:nth-child(even) {
  background: var(--table-stripe);
}

tbody tr:hover {
  background: var(--table-hover);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-pill {
  display: inline-flex;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(15, 159, 143, 0.1);
  color: var(--positive-text);
  font-size: 0.68rem;
  font-weight: 800;
  vertical-align: middle;
}

@media (max-width: 1100px) {
  .setup-grid,
  .viz-grid,
  .training-layout {
    grid-template-columns: 1fr;
  }

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

  .duration-heading {
    flex-direction: column;
  }

  .duration-total {
    text-align: left;
  }

  .duration-segments {
    grid-template-columns: 1fr;
  }

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

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

  .saved-credential-field,
  .provider-field,
  .credential-meta,
  .api-key-field,
  .project-id-field,
  .adapty-app-name-field,
  .date-range-field,
  .resolution-field {
    grid-column: span 1;
  }

  .revenuecat-control-row,
  .revenuecat-actions {
    grid-column: 1 / -1;
  }

  .revenuecat-control-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .revenuecat-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .app-store-main {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-store-links {
    justify-content: flex-start;
  }

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

  .section-heading,
  .chart-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .manual-date {
    width: 100%;
  }

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

@media (max-width: 700px) {
  .app-shell {
    width: 94vw;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

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

  .assumption-grid {
    grid-template-columns: 1fr;
  }

  .revenuecat-grid {
    grid-template-columns: 1fr;
  }

  .saved-credential-field,
  .provider-field,
  .credential-meta,
  .api-key-field,
  .project-id-field,
  .adapty-app-name-field,
  .date-range-field,
  .resolution-field {
    grid-column: 1 / -1;
  }

  .revenuecat-options,
  .revenuecat-actions {
    width: 100%;
  }

  .revenuecat-grid .option-toggle {
    width: 100%;
    justify-content: flex-start;
  }

  .app-store-facts {
    grid-template-columns: 1fr;
  }

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

  .uploader-actions {
    flex-direction: column;
  }

  .topbar {
    gap: 10px;
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    align-items: flex-start;
    justify-content: space-between;
  }

  .status-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar h1 {
    font-size: 1.35rem;
  }

  .brand-mark {
    width: clamp(82px, 23vw, 108px);
  }
}

a.btn {
  text-decoration: none;
}

.brand-mark-filter {
  position: absolute;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1316;
    --bg-2: #0f1c1a;
    --bg-3: #17130f;
    --panel: #161d21;
    --text: #e4eaed;
    --muted: #93a2aa;
    --ink-soft: #c5d1d7;
    --line: #2a353c;
    --accent-3: #6f9fe0;
    --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
    --orb-a: #6b3a20;
    --orb-b: #1b5a51;
    --noise-rgb: 255 255 255;
    --surface-rgb: 24 31 36;
    --surface-2-rgb: 22 29 33;
    --warm-rgb: 26 32 36;
    --tint-rgb: 20 42 39;
    --tint-2-rgb: 32 40 45;
    --line-rgb: 58 71 79;
    --line-2-rgb: 58 71 79;
    --line-3-rgb: 74 88 97;
    --ink-rgb: 197 209 215;
    --bg-rgb: 10 14 16;
    --field: #1b2328;
    --field-disabled: #20292f;
    --btn-secondary: #243038;
    --danger-text: #f19a9a;
    --positive-text: #3fd1bd;
    --status-info: #9cc3dc;
    --status-ok: #4fd6b0;
    --status-error: #f28b6c;
    --faint: #5f6d74;
    --kpi-rule: #26313a;
    --table-rule: #243036;
    --table-head: #1e272c;
    --table-head-text: #c5d1d7;
    --table-stripe: #182024;
    --table-hover: #1c2e2b;
  }

  /* The charts are SVG written by app.js with their chrome colours as attributes; a CSS property outranks an
     attribute, so the dark theme recolours them here and app.js stays as it is. */
  svg [fill="#5d6971"] {
    fill: var(--muted);
  }

  svg [fill="#354450"] {
    fill: var(--ink-soft);
  }

  svg [stroke="#a7b5bc"] {
    stroke: #56646c;
  }

  svg [stroke="#dce4e7"] {
    stroke: #26313a;
  }

  svg [fill="#f2e8df"] {
    fill: #2c2520;
  }

  svg [fill="#cad5d8"] {
    fill: #3a464d;
  }

  /* Navy reads on cream, not on near-black: the monthly and optimistic series get a lighter blue. */
  svg [stroke="#24558d"] {
    stroke: #6f9fe0;
  }

  svg [fill="#24558d"] {
    fill: #6f9fe0;
  }

  .duration-segment-monthly {
    --segment-color: #6f9fe0 !important;
  }

  /* The logo is a PNG with black lettering: the filter in index.html whitens the black and keeps the green. */
  img[src$="approck-logo.png"] {
    filter: url(#liftDarkLettering);
  }
}
