/* ================================================================
   Solar Savings Data — Stylesheet
   No framework. No build step. Just CSS.
   ================================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --navy: #0f172a;
  --navy-light: #1e293b;
  --slate: #475569;
  --slate-light: #94a3b8;
  --amber: #f59e0b;
  --amber-light: #fbbf24;
  --amber-dim: #92400e;
  --green: #22c55e;
  --red: #ef4444;
  --white: #ffffff;
  --offwhite: #f8fafc;
  --border: #e2e8f0;
  --radius: 8px;
  --radius-lg: 12px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", "Fira Code", monospace;
}

html {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--navy);
  background: var(--white);
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--amber-dim);
  text-decoration: none;
  transition: color 0.15s;

  &:hover {
    color: var(--amber);
  }
}

/* --- Layout --- */
.container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

main {
  flex: 1;
}

/* --- Navigation --- */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--white) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--navy);
  text-decoration: none;
}

.nav-brand svg {
  width: 24px;
  height: 24px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  list-style: none;
}

.nav-links a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--slate);
  transition: color 0.15s;

  &:hover {
    color: var(--navy);
  }
}

/* --- Hero --- */
.hero {
  padding: 5rem 0 4rem;
  text-align: center;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.03em;
  text-wrap: balance;
  color: var(--navy);
  margin-bottom: 1rem;
}

.hero h1 span {
  color: var(--amber);
}

.hero p {
  font-size: 1.125rem;
  color: var(--slate);
  max-width: 540px;
  margin: 0 auto 2rem;
  text-wrap: pretty;
}

.hero-buttons {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1.4;
}

.btn-primary {
  background: var(--navy);
  color: var(--white);

  &:hover {
    background: var(--navy-light);
    color: var(--white);
  }
}

.btn-secondary {
  background: transparent;
  color: var(--navy);
  border: 1.5px solid var(--border);

  &:hover {
    border-color: var(--slate-light);
    color: var(--navy);
  }
}

.btn-amber {
  background: var(--amber);
  color: var(--navy);

  &:hover {
    background: var(--amber-light);
    color: var(--navy);
  }
}

/* --- Section --- */
.section {
  padding: 4rem 0;
}

.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--amber);
  margin-bottom: 0.5rem;
}

.section h2 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}

.section > .container > p {
  color: var(--slate);
  max-width: 540px;
  margin-bottom: 2.5rem;
}

/* --- Steps (How it works) --- */
.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
}

.step {
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: center;
}

.step-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--offwhite);
  border-radius: 50%;
  color: var(--amber);
}

.step-icon svg {
  width: 24px;
  height: 24px;
}

.step h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.step p {
  font-size: 0.875rem;
  color: var(--slate);
  line-height: 1.5;
}

/* --- Endpoint Cards --- */
.endpoint-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.endpoint {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color 0.15s;

  &:hover {
    border-color: var(--slate-light);
  }
}

.method-badge {
  flex-shrink: 0;
  padding: 0.2rem 0.55rem;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--mono);
  border-radius: 4px;
  text-transform: uppercase;
}

.method-get {
  background: #dcfce7;
  color: #166534;
}

.method-post {
  background: #dbeafe;
  color: #1e40af;
}

.endpoint-path {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 0.25rem;
}

.endpoint-desc {
  font-size: 0.8rem;
  color: var(--slate);
}

/* --- Code Block --- */
.code-block {
  background: var(--navy);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.code-tabs {
  display: flex;
  border-bottom: 1px solid var(--navy-light);
}

.code-tab {
  padding: 0.6rem 1.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--slate-light);
  background: transparent;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;

  &.active, &:hover {
    color: var(--white);
    border-bottom-color: var(--amber);
  }
}

.code-content {
  display: none;
  padding: 1.25rem;
  overflow-x: auto;

  &.active {
    display: block;
  }
}

.code-content pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.65;
  color: #e2e8f0;
  white-space: pre;
}

/* Syntax coloring */
.hl-key { color: #7dd3fc; }
.hl-str { color: #86efac; }
.hl-num { color: #fbbf24; }
.hl-comment { color: #64748b; }
.hl-cmd { color: #c4b5fd; }

/* --- Footer --- */
.footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--slate-light);
}

/* ================================================================
   Try-it-out Page Styles
   ================================================================ */

.playground {
  padding: 3rem 0 4rem;
}

.playground h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.playground > .container > p {
  color: var(--slate);
  margin-bottom: 2rem;
}

/* --- Form --- */
.form-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.form-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.form-row:last-child {
  margin-bottom: 0;
}

.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--slate);
}

.form-group input,
.form-group select {
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  font-family: var(--font);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--navy);
  transition: border-color 0.15s;
  outline: none;

  &:focus {
    border-color: var(--amber);
  }

  &::placeholder {
    color: var(--slate-light);
  }
}

.advanced-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--slate);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0.5rem 0;
  font-family: var(--font);
}

.advanced-toggle .chevron {
  transition: transform 0.2s;
  font-size: 0.7rem;
}

.advanced-toggle.open .chevron {
  transform: rotate(90deg);
}

.advanced-body {
  display: none;
  padding-top: 0.75rem;

  &.open {
    display: block;
  }
}

.submit-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

/* --- Results --- */
.results-area {
  display: none;
}

.results-area.visible {
  display: block;
}

.result-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.result-card {
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.result-card .label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate-light);
  margin-bottom: 0.35rem;
}

.result-card .value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -0.02em;
}

.result-card .value.savings {
  color: var(--green);
}

.result-card .sub {
  font-size: 0.75rem;
  color: var(--slate);
  margin-top: 0.2rem;
}

/* Monthly chart */
.monthly-chart {
  margin-bottom: 1.5rem;
}

.monthly-chart h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 140px;
  padding-bottom: 1.5rem;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.chart-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar .bar-pair {
  display: flex;
  gap: 2px;
  width: 100%;
  align-items: flex-end;
}

.chart-bar .bar {
  flex: 1;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height 0.4s ease;
}

.chart-bar .bar.before {
  background: var(--slate-light);
}

.chart-bar .bar.after {
  background: var(--amber);
}

.chart-bar .month-label {
  font-size: 0.6rem;
  color: var(--slate-light);
  margin-top: 0.4rem;
  position: absolute;
  bottom: 0;
}

.chart-legend {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--slate);
}

.chart-legend span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}

.legend-dot.before { background: var(--slate-light); }
.legend-dot.after { background: var(--amber); }

/* Raw JSON */
.raw-json details {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.raw-json summary {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--slate);
  cursor: pointer;
  background: var(--offwhite);
}

.raw-json pre {
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.5;
  background: var(--navy);
  color: #e2e8f0;
  overflow-x: auto;
  max-height: 400px;
}

/* --- Loading / Error States --- */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.loading-state {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem;
  font-size: 0.9rem;
  color: var(--slate);
}

.loading-state.visible {
  display: flex;
}

.error-state {
  display: none;
  padding: 1rem 1.25rem;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  background: #fef2f2;
  color: #991b1b;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.error-state.visible {
  display: block;
}

/* --- Example Section (detailed quote) --- */
.example-section {
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.example-section h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.example-section > p {
  font-size: 0.875rem;
  color: var(--slate);
  margin-bottom: 1.25rem;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .form-row {
    flex-direction: column;
  }

  .nav-links {
    gap: 1rem;
  }

  .footer-inner {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }

  .endpoint {
    flex-direction: column;
  }

  .result-cards {
    grid-template-columns: 1fr 1fr;
  }
}
