/* Styl: prosty, systemowy (jak CurrentDrive), turkus i granat z kuplodz.pl. */
:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --card-2: #f4f6f8;
  --text: #0f2533;
  --muted: #5b6b78;
  --line: #e2e8ee;
  --track: #e5e7eb;
  --brand: #0b8290;
  --brand-dark: #096d78;
  --brand-ink: #ffffff;
  --accent: #0b8290;
  --ok: #16a34a;
  --warn: #d97706;
  --crit: #dc2626;
  --input: #ffffff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --card: #1a1d24; --card-2: #22262e; --text: #f3f4f6; --muted: #9ca3af;
    --line: #2c313b; --track: #2c313b; --accent: #0fa6b4;
    --brand: #0fa6b4; --brand-dark: #12bccb; --brand-ink: #04262a;
    --ok: #34c759; --warn: #ffcc00; --crit: #ff453a; --input: #14171c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --card: #1a1d24; --card-2: #22262e; --text: #f3f4f6; --muted: #9ca3af;
  --line: #2c313b; --track: #2c313b; --accent: #0fa6b4;
    --brand: #0fa6b4; --brand-dark: #12bccb; --brand-ink: #04262a;
  --ok: #34c759; --warn: #ffcc00; --crit: #ff453a; --input: #14171c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* nagłówek */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 640px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px 12px;
}
.title { min-width: 0; }
h1 { font-size: 20px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h2 { font-size: 15px; font-weight: 650; margin: 0 0 10px; }
h3 { font-size: 13px; font-weight: 600; margin: 18px 0 8px; color: var(--muted); }
.conn { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.conn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.conn.ok .dot { background: var(--ok); }
.conn.warn .dot { background: var(--warn); }
.conn.bad { color: var(--crit); }
.conn.bad .dot { background: var(--crit); }
.icon-btn {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: var(--card); color: var(--muted);
}
.icon-btn svg { width: 20px; height: 20px; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px; }
#controls { display: grid; gap: 12px; }
#controls[hidden] { display: none; }
.card { background: var(--card); border-radius: 14px; padding: 14px 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* komunikaty */
.alerts { display: grid; gap: 8px; }
.alerts:empty { display: none; }
.alert { background: var(--card); border-radius: 12px; padding: 10px 14px; font-size: 14px; border-left: 4px solid var(--warn); }
.alert.bad { border-left-color: var(--crit); }

/* panel główny */
.hero { border-left: 5px solid var(--line); }
.hero.heating { border-left-color: var(--brand); }
.hero-row { display: flex; justify-content: space-between; gap: 12px; }
.readout .label { font-size: 13px; color: var(--muted); }
.readout.right { text-align: right; }
.big { font-size: 44px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.big small { font-size: 16px; font-weight: 400; margin-left: 3px; color: var(--muted); }
.big.stale { color: var(--muted); }
.readout .sub { font-size: 13px; color: var(--muted); }
.readout .sub b { font-weight: 600; color: var(--text); }
.gauge { position: relative; height: 8px; border-radius: 4px; background: var(--track); margin: 14px 0 16px; }
.gauge-fill { height: 100%; border-radius: 4px; background: var(--brand); transition: width .4s; }
.gauge-target { position: absolute; top: -4px; width: 2px; height: 16px; background: var(--text); opacity: .55; transform: translateX(-1px); transition: left .3s; }
.power {
  width: 100%; padding: 13px; border-radius: 12px; border: 0;
  font-size: 16px; font-weight: 600;
  background: var(--brand); color: var(--brand-ink);
}
.power:hover { background: var(--brand-dark); }
.power.on { background: var(--card-2); color: var(--text); }
.power.pending { opacity: .6; }

/* nastawy */
.setting + .setting { margin-top: 16px; }
.setting-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 14px; }
.setting-head b { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper input { flex: 1; min-width: 0; }
.range-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 2px 52px 0; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; font-size: 14px; }
.btn.round { width: 40px; height: 40px; border-radius: 10px; padding: 0; font-size: 20px; line-height: 1; flex: none; background: var(--card-2); border-color: transparent; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.danger { color: var(--crit); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.active { border-color: var(--brand); }

input[type=range] { -webkit-appearance: none; appearance: none; height: 6px; border-radius: 3px; background: var(--track); outline: none; margin: 10px 0; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 1px solid #c7ced6; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 1px solid #c7ced6; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
input[type=range]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); }
input.hue { background: linear-gradient(90deg, #d33, #dd3, #3d3, #3dd, #33d, #d3d, #d33); }

/* wyjścia – lista z przełącznikami */
.tiles { display: grid; }
.tile {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 0; border: 0; border-top: 1px solid var(--line); background: none; text-align: left;
}
.tile:first-child { border-top: 0; padding-top: 2px; }
.tile-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-state { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sw { width: 44px; height: 26px; border-radius: 13px; background: var(--track); position: relative; flex: none; transition: background .15s; }
.sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s; }
.tile.on .sw { background: var(--brand); }
.tile.on .sw::after { transform: translateX(18px); }
.tile.pending .sw { opacity: .5; }

/* oświetlenie */
.tabs { display: flex; gap: 2px; background: var(--card-2); padding: 3px; border-radius: 10px; margin-bottom: 12px; }
.tab { flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.tab[aria-selected=true] { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.color-preview { height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 13px; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); margin-bottom: 8px; }
.color-preview.off { background: var(--card-2) !important; color: var(--muted); text-shadow: none; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; flex: 1; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.field > span b { font-weight: 500; color: var(--text); }
.slider-field { margin-bottom: 2px; }
.slider-field input { width: 100%; }
.field input:not([type=range]):not([type=checkbox]), .field select, #rawCmd {
  width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--input);
}
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.preset { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; }
.preset i { width: 12px; height: 12px; border-radius: 50%; display: block; }
.preset.active { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.row > .btn { flex: 1; }
.row.end { justify-content: flex-end; }
.row.end > .btn { flex: none; }

/* harmonogram */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.toggle { -webkit-appearance: none; appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--track); position: relative; flex: none; margin: 0; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s; }
.toggle:checked { background: var(--brand); }
.toggle:checked::after { transform: translateX(18px); }
.toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sched-list { list-style: none; padding: 0; margin: 8px 0; }
.sched-list li + li { border-top: 1px solid var(--line); }
.sched-item { width: 100%; text-align: left; display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: baseline; padding: 10px 0; border: 0; background: none; }
.sched-item b { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sched-item span { font-size: 13px; color: var(--muted); }
.sched-item em { font-style: normal; font-size: 12px; color: var(--muted); }
.sched-item.active em { color: var(--brand); }
.sched-item.empty { display: block; color: var(--muted); font-size: 14px; }
.days { border: 0; padding: 0; margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.days legend { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.days label { position: relative; }
.days input { position: absolute; opacity: 0; }
.days span { display: inline-block; min-width: 40px; text-align: center; padding: 7px 4px; border-radius: 8px; border: 1px solid var(--line); font-size: 14px; }
.days input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.days input:focus-visible + span { outline: 2px solid var(--accent); }
.error { color: var(--crit); font-size: 14px; min-height: 1em; }

/* diagnostyka */
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details > summary h2 { display: inline; margin: 0; }
#diagDetails > summary { display: flex; justify-content: space-between; color: var(--muted); }
#diagDetails > summary::after { content: "pokaż"; font-size: 13px; }
#diagDetails[open] > summary::after { content: "ukryj"; }
.diag-grid { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; font-size: 13px; margin: 12px 0; }
.diag-grid dt { color: var(--muted); }
.diag-grid dd { margin: 0; word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
#rawForm { flex-wrap: nowrap; }
#rawForm input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
#rawForm .btn { flex: none; }
.log { background: var(--card-2); border-radius: 10px; padding: 10px; font-size: 11.5px; max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 10px 0 0; }

/* okna dialogowe */
dialog { background: var(--card); color: var(--text); border: 0; border-radius: 14px; padding: 16px; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(15, 17, 21, .5); }
dialog h2 { font-size: 17px; }
dialog details summary { color: var(--accent); margin: 14px 0 8px; font-size: 14px; }
.btn-config { display: grid; gap: 8px; }
.btn-config-row { display: flex; align-items: center; gap: 10px; }
.btn-config-row input[type=text] { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--input); }
.btn-config-row small { color: var(--muted); width: 54px; }

.welcome p { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; visibility: hidden; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px;
  max-width: calc(100vw - 32px); font-size: 14px;
  transition: transform .2s, opacity .2s, visibility .2s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
