:root {
  --bg: #eef0f3;
  --surface: #ffffff;
  --sunken: #f6f7f9;
  --ink: #1d2233;
  --muted: #5b6275;
  --faint: #8a90a0;
  --line: #dde1e8;
  --flame: #e8672a;
  --flame-strong: #c4501a;
  --flame-soft: #fdeadf;
  --test: #4b5a9c;
  --test-soft: #e7eaf6;
  --ok: #2c7a57;
  --ok-soft: #e1f2ea;
  --warn: #9a6a12;
  --warn-soft: #fbf0d9;
  --danger: #b4352a;
  --danger-soft: #fbe5e2;
  --focus: #3b5bdb;
  --radius-control: 8px;
  --radius-panel: 14px;
  --shadow-float: 0 10px 30px rgba(29, 34, 51, 0.16);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11131a;
    --surface: #1a1d27;
    --sunken: #151821;
    --ink: #eceef4;
    --muted: #a9afc0;
    --faint: #7c8296;
    --line: #2b3040;
    --flame: #f2894c;
    --flame-strong: #f6a274;
    --flame-soft: #3a2418;
    --test: #9eabe6;
    --test-soft: #232945;
    --ok: #6cc69c;
    --ok-soft: #173327;
    --warn: #e2b55c;
    --warn-soft: #362b14;
    --danger: #f08a7f;
    --danger-soft: #3a1c19;
    --focus: #8ea6ff;
    --shadow-float: 0 10px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--flame-strong); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Estructura ---------- */
.shell { min-height: 100vh; display: grid; grid-template-columns: 240px 1fr; }
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 28px;
  padding: 28px 20px; border-right: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.brand img { width: 26px; height: auto; }
.brand strong { display: block; font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 9px 12px; border: 0; border-radius: var(--radius-control);
  background: none; text-align: left; font-weight: 600; color: var(--muted); cursor: pointer;
}
.nav button:hover { background: var(--sunken); color: var(--ink); }
.nav button[aria-current="page"] { background: var(--flame-soft); color: var(--flame-strong); }
.nav .count { font-size: 12px; font-weight: 700; padding: 0 7px; border-radius: 99px; background: var(--flame); color: #fff; }
.side-foot { margin-top: auto; font-size: 13px; color: var(--muted); display: grid; gap: 10px; }
.side-foot button { justify-self: start; }

.main { min-width: 0; padding: 32px 40px 140px; }
.page { max-width: 880px; }
.page-head { margin-bottom: 24px; }
.page-head h1 { margin: 0 0 4px; font-size: 26px; line-height: 1.2; font-weight: 800; letter-spacing: -0.02em; }
.page-head p { margin: 0; color: var(--muted); max-width: 62ch; }

.topbar { display: none; }

section.block { margin: 0 0 40px; }
section.block > h2 { margin: 0 0 4px; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
section.block > .lead { margin: 0 0 16px; color: var(--muted); max-width: 64ch; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-panel); }

/* ---------- Estado y pausa ---------- */
.status-line { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; background: var(--faint); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.off { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot.wait { background: var(--warn); }

.switchboard { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 16px; padding: 20px 22px; }
.switchboard h2 { margin: 0; font-size: 18px; }
.switchboard p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.switchboard.paused { border-color: var(--warn); background: var(--warn-soft); }

.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--radius-control); margin-bottom: 20px; font-size: 14px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner strong { color: inherit; }

.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin: 16px 0 0; }
.facts div { padding: 16px 22px; border-top: 1px solid var(--line); }
.facts div + div { border-left: 1px solid var(--line); }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.facts dd small { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; }

/* ---------- Envíos ---------- */
.day { margin-bottom: 18px; }
.day h3 { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.sends { list-style: none; margin: 0; padding: 0; }
.send { display: grid; grid-template-columns: 64px 1fr auto; gap: 4px 14px; padding: 14px 18px; border-top: 1px solid var(--line); align-items: start; }
.send:first-child { border-top: 0; }
.send time { font-weight: 800; font-size: 16px; padding-top: 1px; }
.send .what { min-width: 0; }
.send .what strong { display: block; font-weight: 700; }
.send .where { font-size: 13px; color: var(--muted); }
.send .note { font-size: 13px; color: var(--muted); margin-top: 4px; }
.send .error { font-size: 13px; color: var(--danger); margin-top: 4px; }
.send details { margin-top: 6px; font-size: 13px; }
.send summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.send .preview { white-space: pre-wrap; background: var(--sunken); border-radius: var(--radius-control); padding: 10px 12px; margin-top: 6px; line-height: 1.55; }
.send .links { display: flex; gap: 12px; margin-top: 6px; font-size: 13px; font-weight: 600; }
.send.past { opacity: 0.62; }

.pill { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--sunken); color: var(--muted); }
.pill.propuesto { background: var(--warn-soft); color: var(--warn); }
.pill.aprobado, .pill.enviando { background: var(--flame-soft); color: var(--flame-strong); }
.pill.enviado { background: var(--ok-soft); color: var(--ok); }
.pill.fallido { background: var(--danger-soft); color: var(--danger); }
.tag-test { color: var(--test); font-weight: 600; }
.tag-live { color: var(--flame-strong); font-weight: 600; }

.empty { padding: 28px 22px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 2px; }

/* ---------- Controles ---------- */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { flex: none; width: 42px; height: 24px; border-radius: 99px; background: var(--line); position: relative; transition: background 0.15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s; }
.switch input:checked + .track { background: var(--flame); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch .label { font-size: 14px; font-weight: 600; }
.switch.big .track { width: 52px; height: 30px; }
.switch.big .track::after { width: 24px; height: 24px; }
.switch.big input:checked + .track::after { transform: translateX(22px); }

select, input[type="text"], input[type="url"], input[type="number"], input[type="time"], input[type="password"] {
  height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-control);
  background: var(--surface); min-width: 0;
}
select { padding-right: 28px; }
input[type="number"] { width: 64px; text-align: right; }
input.emoji { width: 56px; text-align: center; font-size: 18px; }
input.wide { width: 100%; }
.changed { border-color: var(--flame) !important; box-shadow: 0 0 0 3px var(--flame-soft); }
.invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px var(--danger-soft); }
.field-error { color: var(--danger); font-size: 13px; margin-top: 4px; }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--flame); }
.reset { border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 600; text-decoration: underline; cursor: pointer; padding: 0; }
.duration { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.duration input { color: var(--ink); }

.btn { height: 38px; padding: 0 16px; border-radius: var(--radius-control); border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.flame { background: var(--flame); color: #fff; border-color: var(--flame); }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }

.seg { display: inline-flex; padding: 3px; background: var(--sunken); border: 1px solid var(--line); border-radius: 10px; gap: 2px; margin-bottom: 14px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; font-size: 13px; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

/* ---------- Canales ---------- */
.group { margin-bottom: 28px; }
.group-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.group-head h2 { margin: 0; font-size: 18px; }
.group-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.group.off .rows { opacity: 0.55; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) 220px 150px; gap: 8px 16px; align-items: center; padding: 14px 18px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row.live { box-shadow: inset 3px 0 0 var(--flame); }
.row .name { font-weight: 700; }
.row .name .hash { color: var(--faint); font-weight: 600; }
.row .purpose { font-size: 13px; color: var(--muted); }
.row .flag { display: inline-block; font-size: 12px; font-weight: 600; color: var(--warn); margin-top: 2px; }
.row .extras { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; padding: 10px 12px; background: var(--sunken); border-radius: var(--radius-control); }
.row select { width: 100%; }
.row .state { font-size: 12px; font-weight: 700; display: block; margin-top: 2px; }

/* ---------- Día de clase (riel) ---------- */
.rail-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; padding: 18px 22px 6px; }
.rail-head h3 { margin: 0; font-size: 15px; }
.rail-head p { margin: 0; font-size: 13px; color: var(--muted); }
.rail { list-style: none; margin: 0; padding: 10px 22px 22px; position: relative; }
.stop { display: grid; grid-template-columns: 58px 28px minmax(0, 1fr); gap: 0 10px; position: relative; }
.stop .t { font-weight: 800; font-size: 15px; text-align: right; padding-top: 12px; }
.stop .t small { display: block; font-size: 11px; font-weight: 600; color: var(--faint); }
.stop .axis { position: relative; display: flex; justify-content: center; }
.stop .axis::before { content: ""; position: absolute; top: 0; bottom: 0; width: 2px; background: var(--line); }
.stop:first-child .axis::before { top: 18px; }
.stop:last-child .axis::before { bottom: calc(100% - 18px); }
.stop .axis i { position: relative; margin-top: 15px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--flame); }
.stop.off .axis i { border-color: var(--line); }
.stop.off .t { color: var(--faint); text-decoration: line-through; }
.stop .body { padding: 8px 0 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "txt controls onoff"; gap: 8px 16px; align-items: center; min-width: 0; }
.stop .body .txt { grid-area: txt; }
.stop .body .controls { grid-area: controls; }
.stop .body .onoff { grid-area: onoff; }
.stop.class .body { display: block; }
.stop .body .txt { min-width: 0; }
.stop .body strong { display: block; }
.stop .body span { font-size: 13px; color: var(--muted); }
.stop .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.stop.class .axis::before { background: var(--flame); width: 6px; border-radius: 3px; }
.stop.class .axis i { display: none; }
.stop.class .body { margin: 6px 0; padding: 12px 16px; background: var(--flame-soft); border-radius: var(--radius-control); }
.stop.class .body strong { color: var(--flame-strong); }
.stop.class .t { padding-top: 16px; }

.setting-rows { list-style: none; margin: 0; padding: 0; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px 20px; flex-wrap: wrap; padding: 14px 22px; border-top: 1px solid var(--line); }
.setting:first-child { border-top: 0; }
.setting .txt { min-width: 0; flex: 1 1 260px; }
.setting .txt strong { display: block; font-weight: 700; }
.setting .txt span { font-size: 13px; color: var(--muted); }
.setting .controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting.stack .controls { flex: 1 1 100%; }

.programs { display: flex; flex-wrap: wrap; gap: 12px 28px; padding: 16px 22px; border-bottom: 1px solid var(--line); }

/* ---------- Historial ---------- */
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: grid; grid-template-columns: 150px 1fr; gap: 4px 16px; padding: 12px 18px; border-top: 1px solid var(--line); font-size: 14px; }
.log li:first-child { border-top: 0; }
.log time { color: var(--muted); font-size: 13px; }
.log .from { color: var(--muted); text-decoration: line-through; }

/* ---------- Barra de cambios y diálogo ---------- */
.savebar {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 18px;
  background: var(--ink); color: var(--surface); border-radius: 12px; box-shadow: var(--shadow-float);
  width: min(560px, calc(100% - 32px)); z-index: 20;
}
.savebar span { flex: 1; font-weight: 600; font-size: 14px; }
.savebar .btn.ghost { color: var(--surface); opacity: 0.8; }
.savebar .btn.flame { border-color: var(--flame); }

dialog { border: 0; padding: 0; border-radius: var(--radius-panel); background: var(--surface); color: var(--ink); width: min(560px, calc(100% - 32px)); box-shadow: var(--shadow-float); }
dialog::backdrop { background: rgba(17, 19, 26, 0.45); }
.dlg { padding: 22px; }
.dlg h2 { margin: 0 0 6px; font-size: 19px; }
.dlg > p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.dlg ul { margin: 0 0 18px; padding: 0; list-style: none; max-height: 50vh; overflow: auto; }
.dlg li { padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.dlg li.risk { color: var(--flame-strong); }
.dlg li small { display: block; color: var(--muted); }
.dlg .actions { display: flex; justify-content: flex-end; gap: 10px; }

#toast {
  position: fixed; top: 16px; left: 50%; transform: translate(-50%, -140%); transition: transform 0.25s ease;
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; z-index: 30;
  max-width: calc(100% - 32px);
}
#toast.show { transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- Entrada ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: min(380px, 100%); display: grid; gap: 14px; padding: 32px 28px; }
.login img { width: 44px; height: auto; justify-self: center; }
.login .wordmark { text-align: center; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; margin: -4px 0 10px; }
.login h1 { margin: 0; font-size: 20px; text-align: center; }
.login p { margin: 0 0 6px; font-size: 14px; color: var(--muted); text-align: center; }
.login label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; }
.login input { width: 100%; height: 42px; }
.login .btn { height: 44px; }
.login .error { color: var(--danger); font-size: 14px; text-align: center; min-height: 1.5em; margin: 0; }

.loading { min-height: 100vh; display: grid; place-items: center; }
.loading img { width: 36px; opacity: 0.8; }

/* ---------- Móvil ---------- */
@media (max-width: 860px) {
  .shell { display: block; }
  .side { display: none; }
  .topbar {
    display: block; position: sticky; top: 0; z-index: 10;
    background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .topbar .bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px 8px; }
  .topbar .brand img { width: 20px; }
  .topbar .brand strong { font-size: 16px; }
  .topbar .who { font-size: 13px; color: var(--muted); }
  .topbar nav { display: flex; gap: 4px; overflow-x: auto; padding: 0 12px 8px; scrollbar-width: none; }
  .topbar nav button { flex: none; border: 0; background: none; padding: 7px 12px; border-radius: 99px; font-weight: 700; font-size: 14px; color: var(--muted); }
  .topbar nav button[aria-current="page"] { background: var(--flame-soft); color: var(--flame-strong); }
  .topbar nav .count { margin-left: 4px; font-size: 11px; padding: 0 6px; border-radius: 99px; background: var(--flame); color: #fff; }
  .main { padding: 20px 16px 130px; }
  .page-head h1 { font-size: 22px; }
  .facts { grid-template-columns: 1fr 1fr; }
  .facts div:nth-child(3) { grid-column: 1 / -1; border-left: 0; }
  .facts dd { font-size: 19px; }
  .switchboard { padding: 16px; }
  .send { grid-template-columns: 52px 1fr; padding: 12px 14px; }
  .send .pill { grid-column: 2; justify-self: start; }
  .row { grid-template-columns: 1fr auto; padding: 14px; }
  .row .mode { grid-column: 1 / -1; grid-row: 2; }
  .row .live-ctl { grid-column: 2; grid-row: 1; }
  .rail { padding: 6px 14px 18px; }
  .rail-head { padding: 16px 16px 4px; }
  .stop { grid-template-columns: 46px 22px minmax(0, 1fr); gap: 0 8px; }
  .stop .t { font-size: 14px; }
  .stop .body { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "txt onoff" "controls controls"; align-items: start; }
  .setting { padding: 14px 16px; }
  .programs { padding: 14px 16px; }
  .log li { grid-template-columns: 1fr; padding: 12px 14px; }
}

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

.btn.flush { padding: 0; height: auto; }
section.block.spaced { margin-top: 36px; }
.full { grid-column: 1 / -1; width: 100%; }
.setting-rows.ruled { border-top: 1px solid var(--line); }

/* Categorías: qué hace Bela sola */
.cats { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.cat { display: flex; flex-direction: column; gap: 12px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-panel); }
.cat.off { background: var(--sunken); }
.cat.temp { border-color: var(--warn); }
.cat-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.cat-head h3 { margin: 0; font-size: 17px; }
.cat-now { margin: 4px 0 0; font-size: 14px; font-weight: 600; }
.cat-help { margin: 0; color: var(--muted); font-size: 14px; }
.cat-row { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.cat-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.cat-temp { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cat-temp input[type="datetime-local"] { min-height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--surface); color: var(--ink); font: inherit; max-width: 100%; }
.cat .duration input[type="number"] { width: 4.5em; }
.btn.small { height: 32px; padding: 0 10px; font-size: 13px; }
.cat .hint { color: var(--faint); font-size: 12px; }
.cat input.changed { border-color: var(--flame); }
.cat input.invalid { border-color: var(--danger); }
