:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --text: #2b2620;
  --muted: #7a7166;
  --line: #e7e0d5;
  --accent: #d9672b;
  --accent-ink: #ffffff;
  --soft: #f3ede4;
  --ok: #2f855a;
  --ok-bg: #e3f4ea;
  --off: #9a3412;
  --off-bg: #fde8e1;
  --shadow: 0 1px 3px rgba(0, 0, 0, .07), 0 4px 16px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171411; --card: #221e1a; --text: #f1ebe3; --muted: #a59a8c; --line: #3a332c;
    --soft: #2c2620; --ok: #6ee7a8; --ok-bg: #173a29; --off: #fca98a; --off-bg: #44221a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: .2em 0 .6em; }
h2 { font-size: 1.1rem; margin: 0 0 .6em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
img { max-width: 100%; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.top nav { display: flex; gap: 16px; }
.top nav a { color: var(--muted); text-decoration: none; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

.card { background: var(--card); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.narrow { max-width: 400px; margin: 40px auto; }
.muted { color: var(--muted); font-size: .9em; }
.center { text-align: center; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .1em; text-transform: uppercase; }
.alert { background: var(--off-bg); color: var(--off); padding: 10px 12px; border-radius: 10px; }

label { display: block; font-weight: 600; font-size: .9em; margin: 12px 0; }
input:not([type=checkbox]), select { display: block; width: 100%; margin-top: 6px; padding: 11px 12px; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; font: inherit; font-weight: 600; color: var(--text); background: var(--soft); border: 0; border-radius: 10px; cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--off-bg); color: var(--off); }
.btn.block { width: 100%; margin-top: 12px; }
.btn.big { padding: 16px; font-size: 1.1rem; }
.btn.small { padding: 6px 12px; font-size: .9em; }

.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row .grow { flex: 1 1 180px; margin: 0; }

.pill { display: inline-block; font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 99px; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.off { background: var(--off-bg); color: var(--off); }

/* Dashboard */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.devcard { display: block; padding: 0; overflow: hidden; color: inherit; text-decoration: none; margin: 0; }
.devcard .thumb { aspect-ratio: 4/3; background: var(--soft); display: grid; place-items: center; font-size: 2.5rem; }
.devcard .thumb img { width: 100%; height: 100%; object-fit: cover; }
.devinfo { padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.devinfo small { width: 100%; }
.steps { padding-left: 1.2em; color: var(--muted); }
.steps li { margin: .3em 0; }

/* Panel del alimentador */
.head-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.head-row h1 { margin: 0; }
.layout { display: grid; grid-template-columns: 1fr; gap: 16px; }
.layout .card { margin: 0; }
@media (min-width: 860px) {
  .layout { grid-template-columns: 1.4fr 1fr; }
  .layout .cam { grid-row: span 2; }
  .layout .span2 { grid-column: 1 / -1; }
}
.viewer { position: relative; aspect-ratio: 4/3; background: #000; border-radius: 12px; overflow: hidden; margin-bottom: 12px; display: grid; place-items: center; }
.viewer img { width: 100%; height: 100%; object-fit: contain; }
.placeholder { color: #aaa; font-size: 2.5rem; text-align: center; }
.placeholder small { font-size: .9rem; }
.badge { position: absolute; top: 10px; left: 10px; background: #dc2626; color: #fff; font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 6px; }
.imgtime { position: absolute; bottom: 8px; right: 10px; color: #fff; font-size: .8rem; text-shadow: 0 1px 3px #000; }

.stepper { display: inline-flex; align-items: center; background: var(--soft); border-radius: 12px; }
.stepper button { width: 44px; height: 44px; font-size: 1.3rem; background: none; border: 0; color: var(--text); cursor: pointer; }
.stepper output { min-width: 32px; text-align: center; font-weight: 700; font-size: 1.2rem; }
.stepper.sm button { width: 34px; height: 36px; font-size: 1.1rem; }
.stepper.sm output { min-width: 22px; font-size: 1rem; }

.slot { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.slot input[type=time] { width: auto; margin: 0; flex: 1; max-width: 140px; }
.slot.disabled { opacity: .5; }
.slot .icon { margin-left: auto; background: none; border: 0; font-size: 1.1rem; cursor: pointer; padding: 6px; }
#slots { margin-bottom: 12px; }

.switch { position: relative; width: 42px; height: 24px; margin: 0; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }

.events { list-style: none; padding: 0; margin: 0; max-height: 330px; overflow: auto; }
.events li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.events time { color: var(--muted); font-size: .85em; white-space: nowrap; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.shot { position: relative; padding: 0; border: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 4/3; background: var(--soft); cursor: pointer; }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot span { position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 6px; font-size: .72rem; color: #fff; text-align: left; background: linear-gradient(transparent, rgba(0, 0, 0, .65)); }

details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary h2 { display: inline; }
details summary::after { content: " ▾"; color: var(--muted); }
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; }
.settings .full, .settings label.check { grid-column: 1 / -1; }

#lightbox { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .85); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px; }
#lightbox[hidden] { display: none; }
#lightbox img { max-height: 80vh; border-radius: 8px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; background: #2b2620; color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); max-width: calc(100% - 32px); }
#toast.bad { background: #b91c1c; }
[hidden] { display: none !important; }
