:root {
  --bg: #0f1115; --card: #181b22; --line: #262a33; --text: #eef0f4; --muted: #8b919e;
  --on: #f5b942; --ok: #3ecf8e; --danger: #ef5b5b; --accent: #5b8cff;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; }
body { padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 24px); max-width: 560px; margin: 0 auto; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }

header { display: flex; align-items: center; justify-content: space-between; padding: 18px 2px 8px; }
h1 { font-size: 28px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 4px 10px; font-weight: 600; }
.icon { width: 40px; height: 40px; border-radius: 50%; background: var(--card); font-size: 20px; }
.icon.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 14px; }
.row .info { flex: 1; min-width: 0; }
.name { font-weight: 600; }
.sub { color: var(--muted); font-size: 14px; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.badge.off { background: #3a2222; color: #f39a9a; }
.glyph { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--line); font-size: 22px; flex: none; }
.card.is-on .glyph { background: color-mix(in srgb, var(--on) 22%, transparent); }

/* interruptor */
.toggle { width: 56px; height: 34px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .2s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle[aria-pressed="true"] { background: var(--on); }
.toggle[aria-pressed="true"]::after { transform: translateX(22px); }
.toggle:disabled { opacity: .5; }

.extra { margin-top: 14px; display: grid; gap: 12px; }
input[type=range] { width: 100%; accent-color: var(--on); height: 28px; }
.chips { display: flex; gap: 8px; }
.chips button { flex: 1; padding: 9px 0; border-radius: 12px; background: var(--line); font-size: 14px; }
.chips button.sel { outline: 2px solid var(--on); }

/* portón */
.garage-state { font-size: 15px; margin-top: 2px; }
.garage-state.open { color: var(--danger); font-weight: 600; }
.garage-state.closed { color: var(--ok); }
.hold { margin-top: 14px; width: 100%; padding: 16px; border-radius: 14px; background: var(--line); position: relative; overflow: hidden; font-weight: 600; user-select: none; -webkit-user-select: none; touch-action: none; }
.hold .fill { position: absolute; inset: 0; width: 0; background: color-mix(in srgb, var(--accent) 45%, transparent); }
.hold span { position: relative; }
.hold-row { display: flex; gap: 10px; }

details { margin-top: 18px; }
summary { color: var(--muted); padding: 8px 4px; cursor: pointer; }
#histList { list-style: none; padding: 0 4px; margin: 0; font-size: 13px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
#histList li { padding: 4px 0; border-bottom: 1px solid var(--line); }
footer { text-align: center; margin-top: 18px; }
.link { background: none; color: var(--muted); text-decoration: underline; }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translate(-50%, 120px);
  background: #2b303b; padding: 12px 18px; border-radius: 12px; transition: transform .25s; max-width: 90vw; }
#toast.show { transform: translate(-50%, 0); }
#toast.bad { background: #5a2626; }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: 100%; max-width: 320px; display: grid; gap: 12px; text-align: center; }
.logo { font-size: 44px; }
.login-card input { padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 17px; }
.login-card button { padding: 14px; border-radius: 12px; background: var(--accent); font-weight: 600; }
.err { color: var(--danger); min-height: 1.4em; margin: 0; }
