:root {
  --bg: #fffbf3;
  --card: #ffffff;
  --border: #ebe3d8;
  --text: #1a1a1a;
  --muted: #8a7f72;
  --accent: #dc0913;
  --accent-deep: #b8070f;
  --pos: #5a7a3a;
  --neg: #c4522a;
  --neutral: #8a7f72;
  --serif: 'Cormorant Garamond', Garamond, serif;
  --sans: 'DM Sans', system-ui, sans-serif;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.03);
  --shadow-md: 0 4px 12px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-hover: 0 8px 24px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.04);
  --ease: cubic-bezier(.25,.46,.45,.94);
  --ease-out-expo: cubic-bezier(.16,1,.3,1);
  --transition-base: 200ms cubic-bezier(.25,.46,.45,.94);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── Grain Overlay ── */
.grain-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: .03;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
  background-repeat: repeat;
}

/* ── Page Loader ── */
.page-loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity 400ms var(--ease), visibility 400ms;
}

.page-loader.loaded {
  opacity: 0;
  visibility: hidden;
}

.loader-griffin {
  height: 48px;
  width: auto;
  animation: pulse 1.6s ease-in-out infinite;
}

.loader-text {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}

@keyframes pulse {
  0%, 100% { opacity: .4; transform: scale(1); }
  50% { opacity: .8; transform: scale(1.04); }
}

/* ── Header ── */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 24px 48px;
  background: rgba(255,251,243,.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 0 var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
}

.seraya-mark {
  height: 32px;
  width: auto;
  opacity: .6;
  transition: opacity var(--transition-base);
}

.seraya-mark:hover { opacity: 1; }

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

.client-logo {
  height: 44px;
  width: auto;
}

.client-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 28px;
  letter-spacing: .01em;
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.month-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.month-select {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-base);
}

.month-select:focus {
  border-color: var(--accent);
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 48px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.tab-indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  transition: transform 300ms var(--ease-out-expo), width 300ms var(--ease-out-expo);
  will-change: transform, width;
  z-index: 2;
}

.tab-btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--muted);
  background: none;
  border: none;
  padding: 14px 18px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition-base);
  position: relative;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--text);
  font-weight: 600;
}

/* ── Main ── */
#main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 36px 48px 60px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: panelEnter 350ms var(--ease-out-expo) both;
}

@keyframes panelEnter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Section headings ── */
.section-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 22px;
  margin-bottom: 20px;
  color: var(--text);
}

.section-subtitle {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: 16px;
}

/* ── KPI Cards ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 16px;
  margin-bottom: 40px;
}

.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
  animation: cardEnter 400ms var(--ease-out-expo) both;
  animation-delay: calc(var(--i, 0) * 60ms);
}

.kpi:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

@keyframes cardEnter {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.kpi-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
}

.kpi-value {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 32px;
  line-height: 1.1;
  color: var(--text);
}

.kpi-delta {
  font-size: 11px;
  font-weight: 500;
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  width: fit-content;
}

.delta-pos { color: var(--pos); background: rgba(90,122,58,.08); }
.delta-neg { color: var(--neg); background: rgba(196,82,42,.08); }
.delta-neutral { color: var(--neutral); background: rgba(138,127,114,.06); }
.delta-na { color: var(--muted); background: none; padding: 0; }

/* ── Comparison Table ── */
.comparison-wrap {
  margin-bottom: 40px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  background: var(--card);
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.comparison-table th {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  text-align: left;
  padding: 12px 16px;
  background: rgba(0,0,0,.02);
  border-bottom: 1px solid var(--border);
}

.comparison-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  transition: background var(--transition-base);
}

.comparison-table tbody tr {
  animation: cardEnter 300ms var(--ease-out-expo) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

.comparison-table tbody tr:hover td {
  background: rgba(220,9,19,.025);
}

.comparison-table tr:nth-child(even) td {
  background: rgba(0,0,0,.015);
}

.comparison-table tr:nth-child(even):hover td {
  background: rgba(220,9,19,.035);
}

.comparison-table tr:last-child td {
  border-bottom: none;
}

.comparison-table .campaign-name {
  font-weight: 600;
  color: var(--text);
}

.best-value {
  color: var(--accent);
  font-weight: 600;
  background: rgba(220,9,19,.06);
  border-radius: 4px;
  padding: 2px 6px;
}

/* ── Funnel (static decorative shape) ── */
.funnel {
  margin-bottom: 40px;
}

.funnel-stages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  max-width: 720px;
  margin: 0 auto;
}

.funnel-stage {
  width: var(--w, 100%);
  height: 56px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(220,9,19,.18), inset 0 1px 0 rgba(255,255,255,.12);
  animation: funnelStageIn 450ms var(--ease-out-expo) both;
  animation-delay: calc(var(--i, 0) * 80ms);
}

@keyframes funnelStageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.funnel-stage-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: #fff;
  white-space: nowrap;
}

.funnel-stage-value {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 20px;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.funnel-dropoff {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  padding: 4px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.funnel-dropoff svg { flex-shrink: 0; }

/* ── Creative Cards ── */
.creatives-section {
  margin-bottom: 40px;
}

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

.creative-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
  animation: cardEnter 400ms var(--ease-out-expo) both;
  animation-delay: calc(var(--i, 0) * 60ms);
  position: relative;
}

.creative-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.creative-card.creative-best {
  border-left: 4px solid var(--accent);
  background: #fff8f8;
  box-shadow: var(--shadow-md);
}

.creative-card.creative-best::after {
  content: 'Bäst';
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  background: rgba(220,9,19,.08);
  padding: 2px 8px;
  border-radius: 10px;
}

.creative-campaign {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
}

.creative-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.creative-stat {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}

.creative-stat-value {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.creative-best .creative-stat-value.cpl-val {
  color: var(--accent);
}

/* ── Chart Cards ── */
.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.chart-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 16px;
}

.chart-wrap {
  position: relative;
  height: 280px;
}

.trend-note {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
  margin-top: 12px;
}

/* ── Nästa Steg ── */
.nasta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.nasta-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
  animation: cardEnter 400ms var(--ease-out-expo) both;
  animation-delay: calc(var(--i, 0) * 60ms);
}

.nasta-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.nasta-card h3 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 18px;
  color: var(--accent);
  margin-bottom: 12px;
  padding-top: 16px;
  position: relative;
}

.nasta-card h3::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 28px;
  height: 2px;
  background: var(--accent);
}

.nasta-card ul {
  list-style: none;
  padding: 0;
}

.nasta-card li {
  font-size: 14px;
  color: var(--muted);
  padding: 8px 0 8px 0;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  transition: border-color var(--transition-base), padding-left var(--transition-base), color var(--transition-base);
}

.nasta-card li:hover {
  border-left-color: var(--accent);
  padding-left: 10px;
  color: var(--text);
}

.nasta-card li:last-child {
  border-bottom: none;
}

/* ── Campaign Heading ── */
.campaign-heading {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 34px;
  margin-bottom: 28px;
  color: var(--text);
}

/* ── Error ── */
.error-msg {
  text-align: center;
  padding: 60px 20px;
  color: var(--neg);
  font-size: 16px;
}

.error-msg button {
  display: inline-block;
  margin-top: 16px;
  padding: 8px 20px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition-base);
}

.error-msg button:hover { border-color: var(--accent); }

/* ── Loading ── */
.loading {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
  font-size: 15px;
}

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 24px 48px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* ── Month crossfade ── */
.content-crossfade {
  animation: crossfade 250ms var(--ease);
}

@keyframes crossfade {
  0% { opacity: .4; }
  100% { opacity: 1; }
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  .topbar { padding: 20px 32px; }
  #main-content { padding: 28px 32px 48px; }
  .tabs { padding: 0 32px; }

  .kpi-row {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px 20px;
    text-align: center;
  }

  .topbar-left,
  .topbar-center,
  .topbar-right {
    justify-content: center;
  }

  .tabs { padding: 0 20px; }
  #main-content { padding: 24px 20px 48px; }

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

  .kpi-value { font-size: 26px; }
  .campaign-heading { font-size: 26px; }

  .funnel-step-label {
    width: 80px;
    font-size: 11px;
  }

  .funnel-bar { height: 36px; }
  .funnel-dropoff { margin-left: 100px; }

  .footer { padding: 20px; }
}

@media (max-width: 480px) {
  .kpi-row { grid-template-columns: 1fr; }
  .nasta-grid { grid-template-columns: 1fr; }
  .creatives-grid { grid-template-columns: 1fr; }

  .client-name { font-size: 22px; }
  .kpi-value { font-size: 24px; }

  .comparison-wrap { overflow-x: auto; }
  .comparison-table { min-width: 600px; }

  .grain-overlay { display: none; }
}

/* ── Print ── */
@media print {
  .topbar, .tabs, .footer, .page-loader, .grain-overlay { display: none !important; }
  .tab-panel { display: block !important; animation: none !important; }
  .tab-panel + .tab-panel { page-break-before: always; }
  .kpi, .creative-card, .nasta-card, .chart-card, .comparison-wrap {
    box-shadow: none !important;
    break-inside: avoid;
  }
  body { background: #fff; }
}
