/* SPDX-FileCopyrightText: Copyright (c) Mathieu Carbou */
/* SPDX-License-Identifier: MIT */

/* Base reset */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  padding: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body {
  --prep-bg: #ffffff;
  --prep-panel-bg: #ffffff;
  --prep-card-bg: #ffffff;
  --prep-explainer-bg: #fafafa;
  --prep-border: #d9d9d9;
  --prep-text: #444444;
  --prep-heading: #222222;
  --prep-muted: #727272;
  --prep-link: #0a4ea3;
  --prep-control-bg: #ffffff;
  --prep-control-text: #222222;
  --prep-plot-paper: #ffffff;
  --prep-plot-panel: #ffffff;
  --prep-plot-text: #444444;
  --prep-plot-grid: #e5e7eb;
  --prep-plot-zero: #9ca3af;
  --prep-prep-positive: deepskyblue;
  --prep-prep-negative: #ff0000;
  --prep-spot: #1e3a8a;
  --prep-prd3: #ff9800;
  --prep-estimate: #7ee787;
  --prep-positive-text: #2e7d32;
  --prep-negative-text: #c62828;
  background-color: var(--prep-bg);
  color: var(--prep-text);
  overflow-x: hidden;
}

body[data-theme="dark"] {
  --prep-bg: #0f172a;
  --prep-panel-bg: #111827;
  --prep-card-bg: #111827;
  --prep-explainer-bg: #111827;
  --prep-border: #334155;
  --prep-text: #e5e7eb;
  --prep-heading: #f8fafc;
  --prep-muted: #94a3b8;
  --prep-link: #7dd3fc;
  --prep-control-bg: #0f172a;
  --prep-control-text: #f8fafc;
  --prep-plot-paper: #0f172a;
  --prep-plot-panel: #111827;
  --prep-plot-text: #e5e7eb;
  --prep-plot-grid: #334155;
  --prep-plot-zero: #64748b;
  --prep-prep-positive: #38bdf8;
  --prep-prep-negative: #f87171;
  --prep-spot: #93c5fd;
  --prep-prd3: #fbbf24;
  --prep-estimate: #86efac;
  --prep-positive-text: #86efac;
  --prep-negative-text: #fca5a5;
}

body .wrapper,
body section,
.prep-meta,
.prep-card,
#prep-plot,
#prep-source-warnings,
#prep-footer,
#prep-explainer {
  box-sizing: border-box;
  min-width: 0;
}

body .wrapper {
  width: 100%;
  max-width: 1800px;
  margin-left: auto;
  margin-right: auto;
}

#prep-source-warnings {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.prep-source-warning {
  padding: 8px 12px;
  border-left: 4px solid #e65100;
  background: #fff3e0;
  color: #92400e;
  border-radius: 4px;
  font-size: 0.875em;
}

body[data-theme="dark"] .prep-source-warning {
  background: #1c1206;
  color: #fbbf24;
  border-left-color: #f97316;
}

body header {
  display: none;
}

body section {
  width: 100%;
  max-width: 100%;
  float: none;
}

#prep-page-title {
  margin: 0;
  text-align: center;
  color: var(--prep-heading);
}

.prep-page-topbar {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.1rem;
  margin-bottom: 0.75rem;
}

.prep-theme-floating {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--prep-border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--prep-panel-bg) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}

.prep-theme-floating label {
  font-size: 0.72rem;
  line-height: 1;
  color: var(--prep-muted);
}

.prep-theme-floating select {
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.2rem 1.2rem 0.2rem 0.35rem;
  min-height: 1.7rem;
  max-width: 5.5rem;
}

.prep-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.prep-control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
}

.prep-control-row input,
.prep-control-row select,
.prep-control-row button {
  font: inherit;
  padding: 0.35rem 0.55rem;
  color: var(--prep-control-text);
  background: var(--prep-control-bg);
  border: 1px solid var(--prep-border);
  border-radius: 6px;
}

.prep-control-row input[type="date"] {
  color-scheme: light;
}

body[data-theme="dark"] .prep-control-row input[type="date"] {
  color-scheme: dark;
}

.prep-meta {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.prep-card {
  position: relative;
  border: 1px solid var(--prep-border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  background: var(--prep-card-bg);
}

.prep-card-info {
  position: absolute;
  top: 0.3rem;
  right: 0.35rem;
  width: 1.05rem;
  height: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--prep-muted);
  color: var(--prep-muted);
  text-decoration: none;
  opacity: 0.45;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
  user-select: none;
}

.prep-card-info:hover {
  opacity: 1;
  color: var(--prep-link);
  border-color: var(--prep-link);
}

.prep-label {
  font-size: 0.85rem;
  opacity: 0.8;
  color: var(--prep-muted);
}

.prep-value {
  font-weight: 700;
  margin-top: 0.2rem;
}

.prep-value-multiline {
  white-space: pre-line;
}

#prep-plot {
  width: 100%;
  height: clamp(400px, 75vh, 1200px);
  min-height: clamp(400px, 75vh, 1200px);
  max-width: 100%;
  overflow: hidden;
}

#prep-plot .js-plotly-plot,
#prep-plot .plot-container,
#prep-plot .svg-container {
  width: 100% !important;
  max-width: 100% !important;
}

#prep-plot .modebar {
  top: 40px !important;
  right: 8px !important;
  z-index: 20;
}

#prep-footer {
  width: 100%;
  margin-top: 0.6rem;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  opacity: 0.8;
  min-height: 1.2rem;
  text-align: center;
  color: var(--prep-muted);
}

#prep-footer span {
  white-space: nowrap;
}

#prep-footer button {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.15rem 0.45rem;
  cursor: pointer;
  opacity: 1;
}

.prep-cache-actions {
  margin-top: 0.4rem;
  margin-bottom: 0.2rem;
}

#prep-explainer {
  width: 100%;
  margin-top: 0.6rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--prep-border);
  border-radius: 8px;
  background: var(--prep-explainer-bg);
  font-size: 0.86rem;
  line-height: 1.45;
  text-align: left;
  max-width: 1000px;
  color: var(--prep-text);
}

#prep-explainer h3 {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
  color: var(--prep-heading);
}

#prep-explainer p {
  margin: 0.45rem 0;
}

#prep-explainer ul {
  margin: 0.4rem 0 0.6rem 1.1rem;
  padding: 0;
}

#prep-explainer li {
  margin: 0.25rem 0;
}

#prep-explainer a {
  color: var(--prep-link);
}

#prep-explainer strong {
  color: var(--prep-heading);
}

#prep-explainer h4 {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  color: var(--prep-heading);
}

#prep-explainer section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--prep-border);
}

#prep-explainer section + section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--prep-border);
}

@media screen and (max-width: 960px) {
  body .wrapper {
    width: 100%;
    max-width: 100%;
  }

  body header,
  body section {
    width: 100%;
    float: none;
  }

  .prep-meta {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .prep-meta > .prep-card:nth-child(-n+3) {
    grid-column: span 2;
  }

  .prep-meta > .prep-card:nth-child(n+4) {
    grid-column: span 2;
  }
}

@media screen and (max-width: 480px) {
  body {
    padding: 12px;
  }
}

@media screen and (max-width: 640px) {
  .prep-page-topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 0.5rem;
    align-items: start;
    min-height: 0;
    padding-right: 0;
  }

  #prep-page-title {
    width: auto;
    max-width: none;
    font-size: 1.45rem;
    line-height: 1.15;
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: center;
  }

  .prep-theme-floating {
    position: static;
    top: auto;
    right: auto;
    transform: none;
    justify-self: end;
    max-width: 4.8rem;
    padding: 0.2rem 0.35rem;
  }

  .prep-theme-floating label {
    display: none;
  }

  .prep-theme-floating select {
    width: 100%;
    font-size: 0.68rem;
    min-height: 1.55rem;
    padding-right: 1rem;
  }

  #prep-plot {
    height: clamp(350px, 70vh, 900px);
    min-height: clamp(350px, 70vh, 900px);
  }

  #prep-plot .modebar {
    top: 90px !important;
    right: 6px !important;
    transform: scale(0.9);
    transform-origin: top right;
  }
}
