/* ── Tokens ──────────────────────────────────── */
:root {
  --bg:      #0f172a;
  --surface: #1e293b;
  --border:  #334155;
  --text:    #f1f5f9;
  --muted:   #94a3b8;
  --accent:  #3b82f6;
  --green:   #22c55e;
  --radius:  12px;
  --font:    system-ui, -apple-system, 'Segoe UI', sans-serif;
}

html[data-theme="light"] {
  --bg:      #f1f5f9;
  --surface: #ffffff;
  --border:  #e2e8f0;
  --text:    #0f172a;
  --muted:   #64748b;
  --accent:  #2563eb;
  --green:   #16a34a;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-text-size-adjust: none;
}

/* ── Header ─────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  height: 52px;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  flex: 1;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.home-btn {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  min-width: 60px;
}
.home-btn:hover { opacity: 0.8; }

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--muted);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover { background: var(--border); color: var(--text); }

/* ── Nav tabs ────────────────────────────────── */
nav.tabs {
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

nav.tabs a {
  flex-shrink: 0;
  padding: 0.75rem 1.1rem;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
nav.tabs a:hover  { color: var(--text); }
nav.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* ── Main ────────────────────────────────────── */
main {
  padding: 1rem;
  max-width: 900px;
  margin: 0 auto;
}

/* ── MQTT status bar ─────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.85rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #ef4444;
  flex-shrink: 0;
  transition: background 0.4s;
}
.status-dot.connected { background: var(--green); }
.status-dot.pulse     { animation: blink 0.6s ease-in-out; }
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0.3; } }

/* ── Gauge grid ──────────────────────────────── */
.gauge-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.gauge-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.5rem 0.5rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
  cursor: pointer;
}
.gauge-card:hover { border-color: var(--accent); }

.gauge-note {
  font-size: 0.65rem;
  color: var(--muted);
  font-style: italic;
  text-align: center;
  margin-top: 0.4rem;
  line-height: 1.4;
}

.gauge-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

/* ── Date picker form ────────────────────────── */
.date-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  margin-bottom: 1rem;
}
.date-form label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.date-form input[type="date"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.45rem 0.75rem;
  font-size: 16px; /* iOS Safari auto-zooms on focus below 16px */
  font-family: var(--font);
  color-scheme: dark;
  outline: none;
}
html[data-theme="light"] .date-form input[type="date"] { color-scheme: light; }
.date-form input[type="date"]:focus { border-color: var(--accent); }

/* ── Chart card ──────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.chart-card .no-data {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
  font-size: 0.9rem;
}

/* ── Yr weather page ─────────────────────────── */
.yr-now {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 0.75rem;
}
.yr-now img { flex-shrink: 0; }
.yr-now-info { flex: 1; }
.yr-big-temp { font-size: 2.8rem; font-weight: 700; line-height: 1; }
.yr-desc { color: var(--muted); font-size: 0.9rem; margin: 0.2rem 0 0.5rem; }
.yr-meta { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; font-size: 0.82rem; color: var(--muted); }

.yr-sea-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  margin-bottom: 0.75rem;
}
.yr-sea-label { color: var(--muted); font-size: 0.85rem; }
.yr-sea-temp  { font-size: 1.4rem; font-weight: 700; color: var(--text); }

.yr-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0.85rem 0 0.35rem;
}
.yr-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.yr-loading { padding: 1.5rem; text-align: center; color: var(--muted); font-size: 0.85rem; }

.yr-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.yr-row:last-child { border-bottom: none; }
.yr-hour { color: var(--muted); min-width: 2.8rem; font-size: 0.78rem; flex-shrink: 0; }
.yr-icon-gap { display: inline-block; width: 28px; flex-shrink: 0; }
.yr-row img  { flex-shrink: 0; }
.yr-row-main { flex: 1; min-width: 0; }
.yr-row-line1 { display: flex; align-items: center; gap: 0.5rem; }
.yr-row-line2 { display: flex; gap: 0.75rem; margin-top: 0.15rem; }
.yr-row-temp { font-weight: 700; min-width: 2.5rem; font-size: 0.9rem; }
.yr-row-wind { color: var(--muted); flex: 1; font-size: 0.82rem; }
.yr-row-gust { opacity: 0.7; font-size: 0.75rem; }
.yr-row-rain { color: var(--text); min-width: 3.5rem; text-align: right; font-size: 0.82rem; }
.yr-marine   { color: var(--muted); font-size: 0.75rem; }

.yr-day-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.yr-day-row:last-child { border-bottom: none; }
.yr-day-name { min-width: 6.5rem; color: var(--muted); font-size: 0.8rem; text-transform: capitalize; }
.yr-day-desc { flex: 1; color: var(--muted); font-size: 0.78rem; }
.yr-day-range { font-weight: 700; white-space: nowrap; min-width: 5rem; text-align: right; }
.yr-max { color: var(--text); }
.yr-min { color: var(--muted); }
.yr-day-rain { color: var(--text); min-width: 4rem; text-align: right; font-size: 0.78rem; }

/* ── Wind gauge extras ───────────────────────── */
.gauge-sub {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.2rem;
}

.compass-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.compass-dir {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.15rem;
  letter-spacing: 0.04em;
}

/* ── Yr summary card (overview page) ─────────── */
.yr-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-top: 0.75rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}
.yr-summary:hover { border-color: var(--accent); }
.yr-summary img   { flex-shrink: 0; }
.ys-body  { flex: 1; min-width: 0; }
.ys-top   { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.2rem; }
.ys-temp  { font-size: 1.6rem; font-weight: 700; flex-shrink: 0; }
.ys-desc  { color: var(--muted); font-size: 0.88rem; }
.ys-meta  { color: var(--muted); font-size: 0.78rem; }
.ys-arrow { color: var(--muted); font-size: 1.5rem; flex-shrink: 0; line-height: 1; }
.ys-note  { color: var(--muted); font-size: 0.7rem; margin-top: 0.3rem; font-style: italic; }

/* ── Dokumenter page ──────────────────────────── */
.doc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s;
}
.doc-row:last-child { border-bottom: none; }
.doc-row:hover { background: var(--bg); }
.doc-name { flex: 1; min-width: 0; }

/* ── AI weather chat widget ──────────────────── */
.chat-fab {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  z-index: 200;
  transition: transform 0.15s;
}
.chat-fab:hover { transform: scale(1.06); }
.chat-fab svg { width: 24px; height: 24px; }

.chat-panel {
  position: fixed;
  left: 1.1rem;
  right: 1.1rem;
  bottom: 4.6rem;
  width: auto;
  max-width: 360px;
  margin-left: auto;
  height: min(480px, calc(100vh - 7rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 200;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
.chat-panel.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

@media (max-width: 480px) {
  .chat-panel { left: 2.5rem; right: 2.5rem; max-width: 320px; }
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}
.chat-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}
.chat-close:hover { color: var(--text); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.chat-msg {
  max-width: 88%;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.4;
  white-space: pre-wrap;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}
.chat-msg ul { margin: 0.2rem 0 0.3rem; padding-left: 1.2rem; }
.chat-msg li { margin: 0.1rem 0; }
.chat-msg a { color: inherit; text-decoration: underline; }
.chat-msg br:last-child { display: none; }
.chat-msg.loading { color: var(--muted); font-style: italic; }
.chat-msg.hint { align-self: center; color: var(--muted); font-size: 0.78rem; text-align: center; }

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.65rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.5rem 0.65rem;
  font-size: 16px; /* iOS Safari auto-zooms on focus below 16px — this caused the page to "grow" */
  font-family: var(--font);
  outline: none;
}
.chat-input:focus { border-color: var(--accent); }
.chat-send {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 0 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.chat-send:disabled { opacity: 0.5; cursor: default; }

/* ── Footer ──────────────────────────────────── */
footer {
  text-align: center;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.78rem;
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { opacity: 0.8; }

/* ── Pull-to-refresh indicator ──────────────────
   The installed PWA runs in standalone mode, which has no native
   pull-to-refresh (that's a browser-chrome feature). This is the visual
   affordance for the custom gesture in js/pull-to-refresh.js. */
.ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-50px);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  z-index: 300;
  transition: transform 0.2s;
  pointer-events: none;
}
.ptr-indicator.pulling { transition: none; }
.ptr-indicator.spin svg { animation: ptr-spin 0.7s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }
