/* ==========================================================================
   Meteostanice - administrace
   Barvy: chladná "zamračená" šedomodrá, přístrojový vzhled, čísla jsou hlavní.
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #e9eef2;
  --surface: #ffffff;
  --surface-2: #f2f5f8;
  --ink: #122230;
  --ink-2: #4b5f6f;
  --ink-3: #7f93a2;
  --line: #d3dce3;
  --line-2: #e6ecf0;
  --accent: #0e6c8e;
  --accent-hover: #0b5872;
  --on-accent: #ffffff;
  --accent-soft: #dcedf4;
  --ok: #0ca30c;
  --warn: #c98500;
  --bad: #d03b3b;
  --ok-soft: #e3f4e3;
  --warn-soft: #fbf0d6;
  --bad-soft: #fbe3e3;
  --s-temp: #eb6834;
  --s-hum: #2a78d6;
  --s-light: #c98500;
  --s-rssi: #4a3aa7;
  --radius: 6px;
  --radius-lg: 10px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f171d;
    --surface: #17222a;
    --surface-2: #1d2a33;
    --ink: #eef3f6;
    --ink-2: #a9bac6;
    --ink-3: #6f8391;
    --line: #2a3a45;
    --line-2: #22303a;
    --accent: #3ba7d6;
    --accent-hover: #5cb9e0;
    --on-accent: #062030;
    --accent-soft: #163241;
    --ok-soft: #12301a;
    --warn-soft: #33290f;
    --bad-soft: #3a1a1a;
    --s-temp: #d95926;
    --s-hum: #3987e5;
    --s-light: #eda100;
    --s-rssi: #9085e9;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

/* atribut hidden musí vyhrát i nad display:flex/grid na třídách */
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1, h2, h3 { margin: 0; font-weight: 500; letter-spacing: -0.01em; }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 18px; margin-bottom: 8px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.muted { color: var(--ink-3); }
.small { font-size: 13px; }

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 24px; }
.page { flex: 1; padding-top: 32px; padding-bottom: 48px; }

/* --- Horní lišta ------------------------------------------------------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 16px; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); }
.topnav { display: flex; align-items: center; gap: 20px; font-size: 14px; }
.topnav a { color: var(--ink-2); text-decoration: none; }
.topnav a:hover { color: var(--ink); }
.topnav-user { color: var(--ink-3); }

.footer { display: flex; justify-content: space-between; padding-top: 16px; padding-bottom: 24px; color: var(--ink-3); font-size: 13px; }

/* --- Obecné bloky ------------------------------------------------------ */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 20px 24px; }
.panel + .panel, .charts + .panel, .panel + .settings { margin-top: 16px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; flex-wrap: wrap; }
.crumbs { font-size: 13px; color: var(--ink-3); margin-bottom: 4px; }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.flash-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.flash-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.flash-bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

.status { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); flex: none; }
.status-online .dot { background: var(--ok); }
.status-offline .dot { background: var(--bad); }
.status-waiting .dot { background: var(--warn); }
.status-dot-only { gap: 0; }

/* --- Formuláře a tlačítka --------------------------------------------- */
.form label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 12px; }
.form input[type="text"], .form input[type="password"], .form input[type="url"] {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-size: 15px;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.form input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.form .btn { margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius); border: 1px solid transparent;
  font: inherit; font-size: 14px; font-weight: 500; line-height: 1.2; cursor: pointer; text-decoration: none;
  white-space: nowrap; transition: background-color .12s ease, border-color .12s ease;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink-3); color: var(--ink); }
.btn-danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.btn-danger:hover { background: var(--bad-soft); }

/* --- Přihlášení / instalace ------------------------------------------ */
.page-auth .page { display: flex; align-items: flex-start; justify-content: center; }
.auth-card { width: 100%; max-width: 400px; margin-top: 8vh; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 28px; }
.auth-brand { display: flex; align-items: center; gap: 8px; color: var(--accent); font-weight: 600; margin-bottom: 18px; }
.auth-brand svg { width: 22px; height: 22px; }
.auth-title { font-size: 22px; margin-bottom: 18px; }
.auth-card .btn { width: 100%; margin-top: 8px; }

/* --- Dashboard --------------------------------------------------------- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start; }

.station-row {
  display: grid; grid-template-columns: 16px minmax(0, 1fr) auto 16px; align-items: center; gap: 18px;
  padding: 14px 18px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; color: inherit; text-decoration: none; transition: border-color .12s ease;
}
.station-row:hover { border-color: var(--accent); color: inherit; }
.station-main { display: flex; flex-direction: column; min-width: 0; }
.station-name { font-weight: 500; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.station-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--ink-3); }
.station-vals { display: flex; gap: 28px; }
.station-val { display: flex; flex-direction: column; min-width: 78px; font-variant-numeric: tabular-nums; }
.station-val .l { font-size: 11px; color: var(--ink-3); }
.station-val .v { font-size: 20px; font-weight: 400; line-height: 1.2; }
.station-val .u { font-size: 12px; color: var(--ink-3); margin-left: 3px; }
.chev { color: var(--ink-3); font-size: 22px; line-height: 1; }

.empty { padding: 32px 28px; border: 1px dashed var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.empty h2 { margin-bottom: 6px; }
.empty p { color: var(--ink-2); max-width: 52ch; margin: 0; }

.create-panel h2 { margin-bottom: 2px; }
.create-panel .muted { margin-bottom: 16px; font-size: 14px; }

/* --- Čekání na stanici ------------------------------------------------- */
.wait-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.key-field { margin-bottom: 16px; }
.key-label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.key-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.api-key {
  font-family: var(--mono); font-size: 22px; letter-spacing: 0.05em; padding: 10px 14px;
  background: var(--surface-2); border-radius: var(--radius); user-select: all; word-break: break-all;
}
.api-key-small { font-size: 14px; letter-spacing: 0.02em; }

.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; }
.steps li { counter-increment: step; position: relative; padding-left: 38px; margin-bottom: 12px; color: var(--ink-2); }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.steps strong, .steps em { color: var(--ink); font-style: normal; font-weight: 500; }

.wait-status .wait-waiting, .wait-status .wait-connected { display: flex; align-items: center; gap: 18px; }
.wait-status.is-waiting .wait-connected { display: none; }
.wait-status.is-connected .wait-waiting { display: none; }
.wait-status h2 { margin-bottom: 2px; }
.wait-status .status .dot { width: 14px; height: 14px; }
.pulse { width: 14px; height: 14px; border-radius: 50%; background: var(--warn); flex: none; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.75); } }

/* --- Detail stanice --------------------------------------------------- */
.station-head-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.meta-list { display: flex; gap: 24px; margin: 0; }
.meta-list div { display: flex; flex-direction: column; }
.meta-list dt { font-size: 12px; color: var(--ink-3); }
.meta-list dd { margin: 0; font-size: 14px; font-variant-numeric: tabular-nums; }

.readings { display: grid; grid-template-columns: repeat(4, 1fr); padding: 0; overflow: hidden; }
.reading { display: flex; flex-direction: column; padding: 18px 24px 16px; border-left: 1px solid var(--line-2); min-width: 0; }
.reading:first-child { border-left: 0; }
.reading-label { font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 8px; }
.reading-label::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--c, var(--ink-3)); flex: none; }
.reading-value { font-size: 44px; font-weight: 300; line-height: 1.15; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin: 4px 0 2px; white-space: nowrap; }
.reading-unit { font-size: 18px; font-weight: 400; color: var(--ink-2); margin-left: 5px; letter-spacing: 0; }
.reading-sub { font-size: 13px; color: var(--ink-3); min-height: 20px; }

.range-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: 28px 0 12px; flex-wrap: wrap; }
.range-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.range-buttons { display: inline-flex; flex-wrap: wrap; }
.range-buttons button {
  font: inherit; font-size: 14px; padding: 7px 14px; cursor: pointer; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line); margin-left: -1px;
}
.range-buttons button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.range-buttons button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.range-buttons button:hover { color: var(--ink); }
.range-buttons button.is-active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); position: relative; z-index: 1; }

.range-custom { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.range-custom label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.range-custom input[type="date"] {
  font: inherit; font-size: 14px; padding: 5px 8px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); color-scheme: inherit;
}
.range-custom .btn { padding: 6px 12px; }
.range-custom.is-active input[type="date"] { border-color: var(--accent); }
.range-custom.is-active .btn { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.charts { display: grid; gap: 16px; }
.chart-block h3 { margin-bottom: 10px; }
.chart-block .unit { color: var(--ink-3); font-weight: 400; margin-left: 4px; }
.chart-wrap { position: relative; height: 230px; }
.chart-small .chart-wrap { height: 150px; }
.chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ink-3); font-size: 14px; pointer-events: none; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.data-table th { text-align: left; font-weight: 500; font-size: 12px; color: var(--ink-3); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }

.settings summary { cursor: pointer; font-size: 16px; font-weight: 500; list-style: none; display: flex; align-items: center; gap: 8px; }
.settings summary::-webkit-details-marker { display: none; }
.settings summary::before { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(-45deg); transition: transform .15s ease; margin-right: 2px; }
.settings[open] summary::before { transform: rotate(45deg); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-top: 20px; }
.danger-zone { display: flex; gap: 10px; flex-wrap: wrap; border-top: 1px solid var(--line-2); margin-top: 24px; padding-top: 18px; }

/* --- Responzivita ------------------------------------------------------ */
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
  .wait-grid { grid-template-columns: 1fr; }
  .readings { grid-template-columns: 1fr 1fr; }
  .reading:nth-child(3) { border-left: 0; }
  .reading:nth-child(n + 3) { border-top: 1px solid var(--line-2); }
  .settings-grid { grid-template-columns: 1fr; }
  .station-head-meta { align-items: flex-start; }
  .reading-value { font-size: 36px; }
}

@media (max-width: 680px) {
  .wrap { padding: 0 16px; }
  .page { padding-top: 20px; }
  h1 { font-size: 24px; }
  .station-row { grid-template-columns: 16px minmax(0, 1fr) 16px; row-gap: 10px; }
  .station-vals { grid-column: 2 / 3; gap: 20px; }
  .station-val { min-width: 0; }
  .meta-list { flex-wrap: wrap; gap: 14px 20px; }
  .api-key { font-size: 18px; }
  .panel { padding: 16px 18px; }
  .chart-wrap { height: 190px; }
}

@media (prefers-reduced-motion: reduce) {
  .pulse { animation: none; }
  .btn, .station-row, .settings summary::before { transition: none; }
}
