/* fiksusähkö – minimal design system */

:root {
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-border: #dee2e6;
  --color-text: #212529;
  --color-text-muted: #6c757d;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-success: #16a34a;
  --color-error: #dc2626;
  --color-warn: #d97706;
  --color-price-cheap: #2563eb;
  --color-price-mid: #f59e0b;
  --color-price-expensive: #800000;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-border: #334155;
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-primary: #60a5fa;
    --color-primary-hover: #93c5fd;
    --color-price-cheap: #60a5fa;
    --color-price-expensive: #c0392b;
  }
}

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  background: var(--color-bg);
  color: var(--color-text);
}

a { color: var(--color-primary); }
a:hover { color: var(--color-primary-hover); }

/* ── Layout ─────────────────────────────────────────── */

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
}

header.site-header {
  border-bottom: 1px solid var(--color-border);
  padding: .75rem 0;
  background: var(--color-surface);
}

header.site-header .inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -.02em;
}

.site-logo span { color: var(--color-primary); }

.header-nav { display: flex; gap: 1rem; font-size: .9rem; }

main { padding: 1rem 0 3rem; }

/* ── Hero ────────────────────────────────────────────── */

.hero {
  text-align: center;
  margin-bottom: .75rem;
}

.hero h1 {
  font-size: clamp(1.4rem, 3.2vw, 2rem);
  font-weight: 800;
  letter-spacing: -.03em;
  margin: 0;
}

/* ── Daily summary (weather-report style) ────────────── */

.summary-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .6rem .9rem .7rem;
  margin-bottom: .75rem;
}

.summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .25rem;
}

.summary-label {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--color-warn);
}

.summary-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.summary-text {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-text);
}

/* ── Ask form ────────────────────────────────────────── */

.ask-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  box-shadow: var(--shadow);
  margin-bottom: .75rem;
}

/* Answer area sits inside the ask-form card so the "chat dialog" feels unified. */
.ask-form #answer:empty { display: none; }
.ask-form #answer { margin-top: .75rem; }
.ask-form #answer .answer-text,
.ask-form #answer .answer-error {
  margin-bottom: 0;
}

.ask-row {
  display: flex;
  gap: .5rem;
  align-items: flex-end;
}

.ask-input {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .65rem 1rem;
  font-size: 1rem;
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
  transition: border-color .15s;
  resize: none;
  overflow: hidden;
  line-height: 1.4;
  min-height: 2.75rem;
}

.ask-input:focus { border-color: var(--color-primary); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem 1.2rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

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

.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary[disabled], .btn-primary.htmx-request { opacity: .6; cursor: default; }

.spinner {
  display: none;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

.htmx-request .spinner { display: inline-block; }
.htmx-request .btn-label { display: none; }

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

/* ── Suggestion chips ────────────────────────────────── */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .75rem;
}

.chip {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 100px;
  padding: .3rem .85rem;
  font-size: .85rem;
  color: var(--color-text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.chip:hover {
  border-color: var(--color-primary);
  background: var(--color-surface);
}

/* ── Answer area ─────────────────────────────────────── */

#answer { min-height: 2rem; }

.answer-text {
  background: var(--color-surface);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  font-size: 1.05rem;
}

.answer-text p { margin: 0 0 .5rem; }
.answer-text p:last-child { margin-bottom: 0; }

.answer-error {
  background: var(--color-surface);
  border: 2px solid var(--color-error);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  color: var(--color-error);
}

.cache-badge {
  display: inline-block;
  font-size: .7rem;
  background: var(--color-border);
  color: var(--color-text-muted);
  padding: .1rem .45rem;
  border-radius: 100px;
  margin-left: .5rem;
  vertical-align: middle;
}

/* ── Price chart ──────────────────────────────────────── */

:root {
  --ch: 68px;    /* bar area height */
  --bw: 4px;     /* bar width (one 15-min slot) */
  --bg: 1px;     /* bar gap  */
  --bc: 5px;     /* bar column = bw + bg */
  --dr: 26px;    /* date row height */
}

.price-strip-section {
  margin-top: 0;
  margin-bottom: .5rem;
}

.price-strip-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: .25rem;
}

.price-strip-header h2 {
  font-size: .9rem;
  font-weight: 600;
  margin: 0;
}

.price-strip-header .fetch-time {
  font-size: .78rem;
  color: var(--color-text-muted);
}

/* ── Two-column wrapper: [y-axis] [scrollable chart] ─── */

.chart-outer {
  display: flex;
  gap: 0;
  overflow: hidden;
}

/* ── Y-axis (fixed, non-scrolling left column) ────────── */

.chart-yaxis {
  flex: 0 0 34px;
  height: var(--ch);
  position: relative;
  /* align with bars area (skip date row) */
  margin-top: var(--dr);
  border-right: 1px solid var(--color-border);
  background: var(--color-bg);
  z-index: 2;
}

.ya-tick {
  position: absolute;
  right: 5px;
  font-size: 9px;
  color: var(--color-text-muted);
  line-height: 1;
  /* center label on grid line */
  transform: translateY(50%);
  white-space: nowrap;
}

/* ── Scrollable chart body (right column) ─────────────── */

.chart-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  cursor: grab;
  padding: 0 6px 4px 4px;
}

.chart-scroll:active { cursor: grabbing; }

/* ── Date row ─────────────────────────────────────────── */

.chart-dates {
  display: flex;
  gap: var(--bg);
  height: var(--dr);
  align-items: flex-end;
  padding-bottom: 3px;
}

.chart-dc {
  flex: 0 0 var(--bw);
  font-size: 8px;
  line-height: 1.25;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: visible;
  min-width: 0;
}

.chart-dc.past { opacity: .5; }
.chart-dc.cur span { color: var(--color-primary); font-weight: 700; }

/* ── Bar area ─────────────────────────────────────────── */

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: var(--bg);
  height: var(--ch);
  position: relative;   /* for hgrid absolute positioning */
}

/* Horizontal grid line */
.hgrid {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--color-border);
  pointer-events: none;
}

/* Bar wrapper */
.bw {
  flex: 0 0 var(--bw);
  height: 100%;
  position: relative;
  display: flex;
  align-items: flex-end;
}

/* Tooltip data nodes (hidden; content read by JS) */
.btip { display: none; }
.btip-vat { opacity: .75; font-size: 10px; }

/* Global fixed tooltip rendered by JS, lives on <body> */
.chart-tooltip {
  position: fixed;
  background: var(--color-text);
  color: var(--color-surface);
  font-size: 11px;
  line-height: 1.6;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 3px 12px rgba(0,0,0,.28);
  display: none;
}

.chart-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--color-text);
}

/* Highlight bar on hover */
.bw:hover .pb { filter: brightness(1.2); }

/* Price bar */
.pb {
  width: 100%;
  border-radius: 2px 2px 0 0;
  transition: filter .1s;
  min-height: 2px;
}

.pb.cheap     { background: var(--color-price-cheap); }
.pb.mid       { background: var(--color-price-mid); }
.pb.expensive { background: var(--color-price-expensive); }

.bw.past .pb  { opacity: .3; }
.bw.past:hover .pb { opacity: .65; }

.bw.cur {
  z-index: 1;
}

.bw.cur .pb {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
  opacity: 1 !important;
}

/* Extra left margin on the first slot of each hour makes hour boundaries
   visible even at 4 px per bar. The same margin is applied to the date and
   hour-label cells so every row in the chart stays pixel-aligned. */
.bw.hr, .chart-dc.hr, .chart-hl.hr { margin-left: 1px; }
.bw.hr:first-child,
.chart-dc.hr:first-child,
.chart-hl.hr:first-child { margin-left: 0; }

/* ── Hour labels ──────────────────────────────────────── */

.chart-hours {
  display: flex;
  gap: var(--bg);
}

.chart-hl {
  flex: 0 0 var(--bw);
  font-size: 8px;
  text-align: left;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: visible;
  margin-top: 2px;
  /* Let label text (e.g. "12:00") escape the 4 px slot without being clipped */
  min-width: 0;
}

.chart-hl.past { opacity: .5; }
.chart-hl.cur  { color: var(--color-primary); font-weight: 700; }

/* ── Legend ───────────────────────────────────────────── */

.price-strip-legend {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .2rem;
  font-size: .72rem;
  color: var(--color-text-muted);
}

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

.legend-dot.cheap     { background: var(--color-price-cheap); }
.legend-dot.mid       { background: var(--color-price-mid); }
.legend-dot.expensive { background: var(--color-price-expensive); }

.legend-past-swatch {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--color-price-mid);
  opacity: .3;
  flex-shrink: 0;
}

/* ── Settings drawer ─────────────────────────────────── */

.settings-section {
  margin-top: .25rem;
  margin-bottom: .5rem;
}

/* ── In-content "Tietoa" link ────────────────────────── */

.tietoa-link {
  margin: .5rem 0 1.25rem;
  text-align: right;
  font-size: .9rem;
}

.tietoa-link a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.tietoa-link a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

details.settings-details {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  box-shadow: var(--shadow);
}

details.settings-details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: .95rem;
  list-style: none;
  user-select: none;
}

details.settings-details summary::-webkit-details-marker { display: none; }

details.settings-details summary::before {
  content: "▶ ";
  font-size: .7rem;
  transition: transform .15s;
}

details[open].settings-details summary::before { content: "▼ "; }

.settings-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem 1.25rem;
  margin-top: 1rem;
}

@media (max-width: 480px) {
  .settings-form { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: .25rem; }
.field label { font-size: .85rem; font-weight: 500; }

.field input[type="number"],
.field select {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .45rem .75rem;
  font-size: .9rem;
  background: var(--color-bg);
  color: var(--color-text);
  width: 100%;
}

.field-toggle {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .9rem;
  cursor: pointer;
}

.settings-footer {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: .75rem;
}

.btn-sm {
  padding: .4rem .9rem;
  font-size: .9rem;
}

.prefs-saved {
  font-size: .85rem;
  color: var(--color-success);
}

/* ── Ad slot ─────────────────────────────────────────── */

.ad-slot {
  text-align: center;
  margin: 1.5rem 0;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: .8rem;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}

/* In-card inline ad: sits at the bottom of the chat card, below the answer
   area. Tighter margins so it reads as a natural continuation of the card
   rather than a separate section. */
.ad-slot-inline {
  margin: .75rem 0 0;
  min-height: 90px;
}

/* Dev-mode placeholder: same footprint as a real AdSense unit so the layout
   can be previewed without a live ad account. Clearly labeled so nobody
   confuses it with a real ad. */
.ad-placeholder {
  flex-direction: column;
  gap: .25rem;
  padding: 1rem;
  background:
    repeating-linear-gradient(
      45deg,
      var(--color-surface),
      var(--color-surface) 10px,
      var(--color-bg) 10px,
      var(--color-bg) 20px
    );
}

.ad-placeholder-label {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.ad-placeholder-note {
  font-size: .85rem;
  color: var(--color-text-muted);
}

/* ── Footer ──────────────────────────────────────────── */

footer.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 1.5rem 0;
  font-size: .85rem;
  color: var(--color-text-muted);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.5rem;
  align-items: center;
  justify-content: space-between;
}

/* ── Cookie consent ──────────────────────────────────── */

#cc-main { font-family: var(--font) !important; }

/* ── Admin ───────────────────────────────────────────── */

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-card .number {
  font-size: 2rem;
  font-weight: 700;
}

.stat-card .label {
  font-size: .8rem;
  color: var(--color-text-muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

th, td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}

th { font-weight: 600; }

/* ── Server-rendered price snapshot (SEO + first-paint content) ────── */

.price-snapshot {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  font-size: .95rem;
  /* Prevent any stubborn long slot from overflowing the card. */
  overflow-wrap: anywhere;
}

.price-snapshot p {
  margin: .1rem 0;
  line-height: 1.45;
}
.snapshot-now strong { font-size: 1.05rem; color: var(--color-primary); }
.snapshot-vat { color: var(--color-text-muted); font-size: .85rem; }
.snapshot-cheap { color: var(--color-price-cheap); }
.snapshot-expensive { color: var(--color-price-expensive); }
.snapshot-slot { white-space: nowrap; }

/* ── Article teasers on landing page & article list ────────────────── */

.article-teasers {
  margin-top: 2.5rem;
  border-top: 1px solid var(--color-border);
  padding-top: 1.5rem;
}
.article-teasers h2 {
  font-size: 1.1rem;
  margin: 0 0 1rem;
  letter-spacing: -.01em;
}

.article-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 1rem;
}
.article-list li {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
}
.article-list a { text-decoration: none; }
.article-list a:hover { text-decoration: underline; }
.article-list p { margin: .4rem 0 0; color: var(--color-text-muted); font-size: .92rem; }
.article-meta { color: var(--color-text-muted); font-size: .8rem; }

/* ── Article page ──────────────────────────────────────────────────── */

.article-page h1 {
  font-size: clamp(1.5rem, 3.5vw, 2rem);
  letter-spacing: -.02em;
  margin: 0 0 .5rem;
}
.article-page .article-lead {
  font-size: 1.05rem;
  color: var(--color-text);
  margin: 1rem 0 1.5rem;
}
.article-page h2 {
  margin-top: 1.75rem;
  font-size: 1.2rem;
}
.article-page ul,
.article-page ol {
  padding-left: 1.25rem;
}
.article-page li { margin: .25rem 0; }

/* ── Preview / dev mode ─────────────────────────────── */
.tomorrow-note {
  font-size: .8rem;
  color: var(--color-text-muted);
  margin: .5rem 0 0;
}

.preview-banner {
  background: #1e3a5f;
  color: #e0eeff;
  font-size: .85rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.preview-banner a { color: #7ec8f7; }

.dev-launcher {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 480px;
}
.dev-launcher p { margin: 0 0 1rem; color: var(--color-text-muted); font-size: .95rem; }
.dev-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.dev-datetime {
  flex: 1;
  min-width: 200px;
  padding: .5rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: .95rem;
}
