/* ==========================================================================
   Pogodynka — style
   Paleta żyje w zmiennych CSS; motyw ciemny to podmiana kilkunastu wartości.
   ========================================================================== */

:root {
  --bg: #f4f6fb;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #dbeafe 0%, transparent 55%),
             radial-gradient(900px 500px at 95% 0%, #e0f2fe 0%, transparent 50%);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --grid: #e8edf5;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #7c8aa0;
  --accent: #2563eb;
  --temp: #ef5c3c;
  --hum: #2f9bd6;
  --pres: #7c5cd6;
  --dew: #17a08a;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px -12px rgba(15, 23, 42, .18);
  --radius: 16px;
  --radius-sm: 10px;
  --maxw: 1120px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --bg-grad: radial-gradient(1100px 560px at 12% -12%, #16243f 0%, transparent 55%),
               radial-gradient(900px 500px at 96% -4%, #10263a 0%, transparent 52%);
    --surface: #111a2e;
    --surface-2: #0e1729;
    --border: #223050;
    --grid: #1d2a46;
    --text: #e9eefb;
    --text-2: #aab8d4;
    --muted: #7f8db0;
    --accent: #60a5fa;
    --temp: #ff7a5c;
    --hum: #4db8f0;
    --pres: #a78bfa;
    --dew: #2dd4bf;
    --good: #34d399;
    --warn: #fbbf24;
    --bad: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -16px rgba(0, 0, 0, .7);
  }
}

:root[data-theme="dark"] {
  --bg: #0b1120;
  --bg-grad: radial-gradient(1100px 560px at 12% -12%, #16243f 0%, transparent 55%),
             radial-gradient(900px 500px at 96% -4%, #10263a 0%, transparent 52%);
  --surface: #111a2e;
  --surface-2: #0e1729;
  --border: #223050;
  --grid: #1d2a46;
  --text: #e9eefb;
  --text-2: #aab8d4;
  --muted: #7f8db0;
  --accent: #60a5fa;
  --temp: #ff7a5c;
  --hum: #4db8f0;
  --pres: #a78bfa;
  --dew: #2dd4bf;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -16px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

.skip {
  position: absolute; left: -9999px; top: 0; background: var(--accent); color: #fff;
  padding: 10px 16px; border-radius: 0 0 8px 0; z-index: 100;
}
.skip:focus { left: 0; }

/* ---------- Nagłówek ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 12px; color: #fff;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--temp)));
  box-shadow: var(--shadow);
}
.brand strong { display: block; font-size: 16px; letter-spacing: -.01em; }
.brand small { display: block; color: var(--muted); font-size: 12px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.live.is-live i { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.live.is-stale i { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 22%, transparent); }
.live.is-error i { background: var(--bad); }

.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; flex: none;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  color: var(--text-2); cursor: pointer; transition: border-color .15s, color .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.ico-moon { display: none; }
:root[data-theme="dark"] .ico-sun { display: none; }
:root[data-theme="dark"] .ico-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ico-sun { display: none; }
  :root:not([data-theme="light"]) .ico-moon { display: block; }
}

/* ---------- Zakładki ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 10px 14px 12px; font: inherit; font-weight: 500; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text-2); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Układ ---------- */
main { padding-top: 20px; padding-bottom: 32px; }
.panel { display: none; }
.panel.is-active { display: block; }
.panel > * + * { margin-top: 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2, .card header h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .01em; color: var(--text-2); }
.card-head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-summary { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card-summary b { color: var(--text-2); font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- Komunikaty ---------- */
.notice {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: var(--radius-sm); padding: 14px 16px;
}
.notice p { margin: 6px 0 0; color: var(--text-2); font-size: 13.5px; }
.notice code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.notice-warn { border-left-color: var(--warn); }

/* ---------- Hero ---------- */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }

.hero-main { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.hero-temp { display: flex; align-items: flex-start; line-height: 1; }
.big {
  font-size: clamp(56px, 12vw, 88px); font-weight: 250; letter-spacing: -.04em;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.hero-temp .unit { font-size: clamp(20px, 4vw, 28px); color: var(--muted); margin-top: .45em; margin-left: 4px; font-weight: 400; }
.hero-meta { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--text-2); }
.hero-feels b, .hero-time time { color: var(--text); font-weight: 600; }
.chip {
  align-self: flex-start; padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
}
.chip[data-comfort="hot"] { background: color-mix(in srgb, var(--temp) 15%, transparent); color: var(--temp); }
.chip[data-comfort="cold"] { background: color-mix(in srgb, var(--hum) 15%, transparent); color: var(--hum); }
.chip[data-comfort="humid"] { background: color-mix(in srgb, var(--dew) 15%, transparent); color: var(--dew); }
.chip[data-comfort="dry"] { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.chip[data-comfort="ok"] { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }

.hero-forecast {
  display: flex; gap: 14px; align-items: center; max-width: 380px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px;
}
.forecast-text { font-size: 14px; font-weight: 500; margin: 2px 0 3px; }
.forecast-icon { width: 40px; height: 40px; flex: none; color: var(--accent); }
.forecast-icon svg { width: 100%; height: 100%; }

/* ---------- Kafle pomiarowe ---------- */
.metric header { display: flex; align-items: baseline; justify-content: space-between; }
.metric-unit { font-size: 12px; color: var(--muted); }
.metric-value {
  font-size: 38px; font-weight: 300; letter-spacing: -.03em; line-height: 1.15;
  font-variant-numeric: tabular-nums; margin-top: 6px;
}
.metric[data-metric="t"] .metric-value { color: var(--temp); }
.metric[data-metric="h"] .metric-value { color: var(--hum); }
.metric[data-metric="p"] .metric-value { color: var(--pres); }
.metric-trend { font-size: 12.5px; color: var(--muted); min-height: 19px; font-variant-numeric: tabular-nums; }
.metric-trend .up { color: var(--temp); }
.metric-trend .down { color: var(--hum); }
.metric-foot { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.metric-foot b { color: var(--text-2); font-weight: 600; }
.spark { margin: 8px -6px -6px; height: 54px; }

/* ---------- Wielkości wyprowadzone ---------- */
.derived { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 20px; margin: 0; }
@media (max-width: 760px) { .derived { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) { .derived { grid-template-columns: 1fr; } }
.derived dt { font-size: 12px; color: var(--muted); }
.derived dd { margin: 2px 0 0; font-size: 17px; font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- Kontrolki ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg-btn {
  appearance: none; border: 0; background: none; cursor: pointer; font: inherit; font-size: 13px;
  padding: 6px 12px; border-radius: 7px; color: var(--text-2); white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.06); }

.btn {
  appearance: none; cursor: pointer; font: inherit; font-size: 13px; font-weight: 500;
  padding: 8px 14px; border-radius: 9px; border: 1px solid transparent;
  background: var(--accent); color: #fff;
  /* Ten sam wygląd dla <button> i dla <a> użytego jako przycisk. */
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn-ghost { background: var(--surface); color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; filter: none; }

.field { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.field input, .field select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
}
.field input:focus, .field select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); }

/* ---------- Wykresy ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .grid-v { stroke-dasharray: 2 4; opacity: .7; }
.chart .grid-zero { stroke: var(--muted); stroke-dasharray: 4 3; opacity: .5; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .chart-empty { fill: var(--muted); font-size: 13px; font-family: var(--font); }
.chart .chart-cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .bar { transition: opacity .12s; }
.chart .bar:hover { opacity: .78; }
.chart .cell { transition: stroke .12s; }
.chart .cell:hover { stroke: var(--text); stroke-width: 1.5; }

.chart-tip {
  position: absolute; top: 4px; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 8px 10px; font-size: 12.5px; min-width: 120px;
}
.tip-time { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tip-row i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tip-label { color: var(--muted); }
.tip-row b { margin-left: auto; font-weight: 600; }
.tip-range { color: var(--muted); font-size: 11.5px; }

.legend { margin: 8px 0 0; font-size: 12px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.key-t { background: var(--temp); }
.key-band { background: color-mix(in srgb, var(--temp) 30%, transparent); height: 10px; border-radius: 3px; }

.scale-legend { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.scale-legend i { width: 18px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- Tabele ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
.table td { font-variant-numeric: tabular-nums; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table-dense th, .table-dense td { padding: 6px 10px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table .num { text-align: right; }
.table .t-val { color: var(--temp); font-weight: 600; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }

/* ---------- Karty statystyk ---------- */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { margin-bottom: 4px; }
.stat .val { font-size: 26px; font-weight: 300; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Stopka ---------- */
.footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 20px; padding-bottom: 28px; border-top: 1px solid var(--border); margin-top: 8px; }
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ---------- Informacja o danych lokalnych ---------- */
.storage-notice {
  position: fixed; z-index: 60;
  left: 16px; right: 16px; bottom: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(15, 23, 42, .08), 0 24px 48px -20px rgba(15, 23, 42, .35);
  animation: notice-in .28s ease-out;
}
.storage-notice-text { flex: 1 1 280px; font-size: 13px; line-height: 1.5; color: var(--text-2); }
.storage-notice-text strong { color: var(--text); }
.storage-notice-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

@keyframes notice-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Strona offline ---------- */
.offline-page { max-width: 520px; padding-top: 80px; }
.offline-card { text-align: center; }
.offline-card h1 { font-size: 20px; margin: 0 0 8px; }
.offline-card p { color: var(--text-2); margin: 0 0 10px; }
.offline-card p:last-child { margin: 18px 0 0; }

/* ---------- Strona prywatności ---------- */
.prose { max-width: 760px; }
.prose > .card + .card { margin-top: 16px; }
.prose h1 { font-size: 22px; letter-spacing: -.02em; margin: 0 0 10px; }
.prose h2 { font-size: 16px; margin: 0 0 10px; color: var(--text); }
.prose p { margin: 0 0 10px; color: var(--text-2); }
.prose p:last-child { margin-bottom: 0; }
.prose .lead { font-size: 15px; color: var(--text); }
.prose code {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--surface-2); padding: 1px 5px; border-radius: 5px; color: var(--text);
}
.prose a { color: var(--accent); }
.prose .table th code { background: none; padding: 0; }

/* ---------- Stany ---------- */
.is-loading { opacity: .55; transition: opacity .2s; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
