/* Climate dashboard. Colour-blind safe: state via text chips + glyphs, not colour alone. */
* { box-sizing: border-box; }
body { margin: 0; background: #14171c; color: #e7eaee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
header { padding: 16px 20px; background: #1b1f26; border-bottom: 1px solid #2a2f38;
  display: flex; align-items: baseline; gap: 14px; position: sticky; top: 0; z-index: 5; }
h1 { margin: 0; font-size: 20px; }
.updated { color: #7f8894; font-size: 13px; }

.cards { display: grid; gap: 14px; padding: 16px; max-width: 1200px; margin: 0 auto;
  grid-template-columns: 1fr; }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .cards { grid-template-columns: 1fr 1fr 1fr; } }

.card { background: #1b1f26; border: 1px solid #2a2f38; border-radius: 12px; padding: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card-head h2 { margin: 0; font-size: 17px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 12px; border: 1px solid #3a4150; background: #232833; }
.chip.ok::before { content: "✓ "; }
.chip.bad::before { content: "✗ "; }

.readout { display: flex; gap: 22px; margin: 14px 0 8px; }
.metric { display: flex; align-items: baseline; gap: 4px; }
.metric .v { font-size: 34px; font-weight: 600; }
.metric .u { color: #8a93a0; font-size: 14px; }
.ac { font-size: 14px; color: #cbd2da; margin-bottom: 6px; }
.meta { color: #8a93a0; }
.small { font-size: 12px; }
.muted { color: #7f8894; }

.chart { margin-top: 12px; border-top: 1px solid #23272f; padding-top: 10px; }
.chart-title { font-size: 12px; color: #8a93a0; margin: 8px 0 2px; }
.chart-svg { width: 100%; height: auto; display: block; }
.axlbl { font-size: 9px; fill: #7f8894; }

/* ---- AC controls ---- */
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0 2px; }
.ctrl { background: #232833; color: #e7eaee; border: 1px solid #3a4150; border-radius: 8px;
  padding: 8px 12px; font-size: 14px; cursor: pointer; }
.ctrl.pwr { background: #2f6feb; border-color: #2f6feb; color: #fff; }
.ctrl:disabled { opacity: .5; }
.temp-ctrl { display: flex; align-items: center; gap: 8px; }
.temp-ctrl .t { min-width: 42px; text-align: center; font-size: 16px; }
.ctrl-mode, .ctrl-fan, .ctrl-swing { background: #12151a; color: #e7eaee; border: 1px solid #333a45;
  border-radius: 8px; padding: 7px 8px; font-size: 13px; max-width: 108px; }
.ctrl-swing { max-width: 88px; }

/* ---- direct temp entry + swing ---- */
.t-input { width: 58px; background: #12151a; color: #e7eaee; border: 1px solid #333a45;
  border-radius: 8px; padding: 8px 6px; font-size: 16px; text-align: center; }
.deg { color: #8a93a0; margin-left: -2px; }
.ctrl-wrap { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #8a93a0; }
/* keep all cards even: fixed control-area height so the graphs line up across cards */
.controls { min-height: 82px; align-content: flex-start; }

/* ---- control-failure banner (meaning carried by the ✗ glyph + text, not colour,
   since the owner is red/green/yellow colour-blind) ---- */
.ctrl-err { position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 9999; max-width: 560px; width: calc(100% - 28px);
  background: #12151a; color: #fff; border: 2px solid #2f6feb; border-left: 8px solid #2f6feb;
  border-radius: 10px; padding: 12px 14px; font-size: 15px; line-height: 1.4;
  box-shadow: 0 6px 24px rgba(0,0,0,.55); }
.ctrl-err strong { font-size: 16px; }
.ctrl-err .det { margin: 6px 0 8px; font-size: 12px; color: #aab2bd; word-break: break-word; }
.ctrl-err button { background: #2f6feb; color: #fff; border: none; border-radius: 8px;
  padding: 6px 14px; font-size: 14px; cursor: pointer; }

/* ===== Routines ===== */
.routines { max-width: 1200px; margin: 0 auto; padding: 0 16px 28px; }
.routines-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 12px; }
.routines-head h2 { margin: 0; font-size: 18px; }
.routine-list { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .routine-list { grid-template-columns: 1fr 1fr; } }
.routine { background: #1b1f26; border: 1px solid #2a2f38; border-radius: 12px; padding: 14px; }
.routine.disabled { opacity: .6; }
.routine-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.rt-trig { color: #8a93a0; font-size: 12px; white-space: nowrap; }
.routine-steps { margin: 8px 0; padding-left: 18px; color: #cbd2da; font-size: 13px; }
.routine-steps li { margin: 2px 0; }
.routine-actions { display: flex; gap: 6px; flex-wrap: wrap; }
button { background: #2b3444; color: #e7eaee; border: 1px solid #3a4557; border-radius: 7px;
  padding: 6px 12px; cursor: pointer; font: inherit; }
button:hover { background: #35415a; }
button.danger { background: #3a2a2e; border-color: #5a3a40; }
.runs { margin-top: 16px; border-top: 1px solid #2a2f38; padding-top: 10px; }
.runs-title { color: #8a93a0; font-size: 12px; margin-bottom: 6px; }
.run-row { font-size: 13px; color: #cbd2da; padding: 3px 0; }
.run-g { display: inline-block; width: 16px; }
.routine-form { background: #171b21; border: 1px solid #2a2f38; border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.routine-form input, .routine-form select { background: #12151a; color: #e7eaee; border: 1px solid #333a45;
  border-radius: 6px; padding: 6px 8px; font: inherit; }
.routine-form > input { width: 100%; max-width: 320px; margin-bottom: 10px; }
.rf-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.rf-days { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; color: #cbd2da; }
.rf-step { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.rf-step input[type=number] { width: 74px; }
.rf-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }

/* ===== Routine condition builder (nested AND/OR) ===== */
.rf-step { flex-direction: column; align-items: stretch; border: 1px solid #262b35; border-radius: 8px; padding: 8px; }
.rf-step-main { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.s-when-l { font-size: 12px; color: #cbd2da; display: inline-flex; gap: 4px; align-items: center; }
.s-cond { margin-top: 8px; }
.cond-group { border: 1px solid #2a2f38; border-radius: 8px; padding: 8px; margin: 6px 0; background: #14171c; }
.cond-grp-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.cond-grp-head .cg-op { font-weight: 600; }
.cond-children { display: flex; flex-direction: column; gap: 6px; padding-left: 12px; border-left: 2px solid #3a4150; }
.cond-leaf { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cond-leaf input[type=number] { width: 86px; }
