/* Estilo inspirado en iPadOS: barra lateral, títulos grandes, listas agrupadas,
   colores del sistema y modo oscuro automático. */
:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f9f9fb;
  --fill: rgba(120, 120, 128, 0.12);
  --sep: rgba(60, 60, 67, 0.18);
  --label: #000000;
  --secondary: #8e8e93;
  --tint: #007aff;
  --green: #34c759;
  --red: #ff3b30;
  --radius: 12px;
  --radius-lg: 20px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --fill: rgba(120, 120, 128, 0.36);
    --sep: rgba(84, 84, 88, 0.65);
    --label: #ffffff;
    --secondary: #8e8e93;
    --tint: #0a84ff;
    --green: #30d158;
    --red: #ff453a;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 17px/1.4 var(--font); background: var(--bg); color: var(--label); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.grow { flex: 1; }
.muted { color: var(--secondary); font-size: 15px; }
.err { color: var(--red); min-height: 1.2em; margin: 8px 0 0; font-size: 15px; }
code { font: 14px ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }

/* ---------- Disposición ---------- */
.shell { display: flex; min-height: 100%; }
body:not(.in) .sidebar, body:not(.in) .topbar { display: none; }
.sidebar {
  width: 280px; flex: 0 0 280px; padding: 20px 14px; display: flex; flex-direction: column; gap: 22px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-right: 1px solid var(--sep);
  position: sticky; top: 0; height: 100vh;
}
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 14px 28px 10px; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.topbar h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.4px; margin: 0; }
main { padding: 8px 28px 48px; max-width: 1100px; width: 100%; }

/* ---------- Barra lateral ---------- */
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; }
.brand strong { display: block; font-size: 17px; }
.brand small { display: block; color: var(--secondary); font-size: 13px; margin-top: 2px; }
.app-icon {
  width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(145deg, #5ac8fa, #007aff); color: #fff; flex: 0 0 42px;
  box-shadow: 0 2px 6px rgba(0, 122, 255, 0.35);
}
.app-icon svg, nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border: 0; border-radius: 10px;
  background: transparent; color: var(--label); font: 17px var(--font); text-align: left; cursor: pointer;
}
nav button svg { color: var(--tint); flex: 0 0 22px; }
nav button:hover { background: var(--fill); }
nav button.on { background: color-mix(in srgb, var(--tint) 16%, transparent); color: var(--tint); font-weight: 600; }
nav button.on svg { color: var(--tint); }

/* ---------- Botones ---------- */
button { font: 17px var(--font); border-radius: 10px; padding: 9px 16px; cursor: pointer; border: 0; background: var(--tint); color: #fff; font-weight: 600; transition: opacity .15s, transform .05s; }
button:active { transform: scale(0.98); }
button.btn { background: var(--tint); }
button.ghost { background: transparent; color: var(--tint); font-weight: 500; padding-left: 8px; padding-right: 8px; }
button.danger { background: transparent; color: var(--red); font-weight: 500; padding-left: 8px; padding-right: 8px; }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--tint) 45%, transparent); outline-offset: 2px; }

/* ---------- Tarjetas y listas agrupadas ---------- */
.card { background: var(--surface); border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card.narrow { max-width: 420px; margin: 56px auto; }
.card.key { border: 2px solid color-mix(in srgb, var(--tint) 40%, transparent); }
section { margin-bottom: 8px; }
h2 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.2px; }
h3 { font-size: 17px; font-weight: 600; margin: 18px 0 8px; color: var(--secondary); text-transform: uppercase; font-size: 13px; letter-spacing: .4px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 14px 4px 12px; flex-wrap: wrap; }
.toolbar h2 { font-size: 22px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--secondary); margin-bottom: 14px; font-weight: 500; }
input, select {
  font: 17px var(--font); color: var(--label); background: var(--fill); border: 0; border-radius: 10px;
  padding: 10px 12px; min-width: 0; width: 100%; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--secondary) 50%), linear-gradient(135deg, var(--secondary) 50%, transparent 50%); background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
input[type=checkbox] { width: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 16px; align-items: end; }
.rule-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px 16px; align-items: end; margin-bottom: 8px; }
.align-end { display: flex; align-items: flex-end; }
label.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; color: var(--label); font-size: 17px; }
label.inline select { width: auto; }
fieldset.days { border: 0; background: var(--fill); border-radius: 10px; display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 10px; margin: 0; }
fieldset.days legend { font-size: 13px; color: var(--secondary); padding: 0 4px; font-weight: 500; }
fieldset.days label { flex-direction: row; align-items: center; gap: 4px; margin: 0; color: var(--label); font-size: 15px; }
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 14px; }

/* Tablas como listas agrupadas */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius-lg); box-shadow: 0 1px 2px rgba(0,0,0,.04); margin-bottom: 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--sep); vertical-align: middle; white-space: nowrap; font-size: 16px; }
tr:last-child td { border-bottom: 0; }
th { color: var(--secondary); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; padding-top: 12px; padding-bottom: 10px; }
tbody tr { cursor: pointer; transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.noclick { cursor: default; }
tbody tr.noclick:hover { background: transparent; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
.dot.off { background: var(--red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 18%, transparent); }
.thumb { width: 64px; height: 40px; object-fit: cover; border-radius: 8px; background: var(--fill); display: block; }
.badge { display: inline-block; padding: 5px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; margin-left: 10px; }
.badge.bad { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }

/* Listas de elementos (playlists, reglas) */
ul.list, ol.list { list-style: none; padding: 0; margin: 6px 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
ul.list li, ol.list li { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--sep); flex-wrap: wrap; }
ul.list li:last-child, ol.list li:last-child { border-bottom: 0; }
ul.list li .grow, ol.list li .grow { flex: 1; min-width: 160px; }
ol.list { counter-reset: n; }
ol.list li::before { counter-increment: n; content: counter(n); width: 26px; height: 26px; border-radius: 50%; background: var(--fill); display: grid; place-items: center; font-size: 13px; font-weight: 600; color: var(--secondary); }
ol.list li input[type=number] { width: 88px; }
ol.steps { margin: 12px 0 0; padding-left: 1.25em; }
ol.steps li { margin: 6px 0; }
#agentCard { margin-top: 18px; }
#agentMeta, #agentMetaKey { word-break: break-all; }

@media (max-width: 1200px) { th.opt, td.opt { display: none; } }

/* ---------- Tablero: búsqueda, filtro y vistas previas ---------- */
.filters { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 0 4px 12px; }
.filters input[type=search] { flex: 1 1 260px; max-width: 420px; }
.segmented { display: inline-flex; background: var(--fill); border-radius: 9px; padding: 2px; }
.segmented button { background: transparent; color: var(--label); font-weight: 500; padding: 6px 12px; border-radius: 7px; }
.segmented button.on { background: var(--surface); color: var(--label); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.preview-screen { position: relative; width: 100%; max-width: 640px; aspect-ratio: 16 / 9; background: #000; border-radius: 14px; overflow: hidden; display: grid; place-items: center; margin: 4px 0 8px; }
.preview-screen img, .preview-screen video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.preview-screen .muted { color: #8e8e93; }
h3 + .preview-screen { margin-top: 4px; }

/* ---------- Pantallas pequeñas: barra inferior, como iPad en vertical ---------- */
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; width: auto; flex: none;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); flex-direction: row; gap: 0; border-right: 0; border-top: 1px solid var(--sep);
    background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); z-index: 10;
  }
  .brand { display: none; }
  nav { flex-direction: row; width: 100%; justify-content: space-around; }
  nav button { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11px; width: auto; flex: 1; text-align: center; }
  nav button span { font-size: 11px; }
  nav button.on { background: transparent; }
  .topbar { padding: 12px 18px 6px; }
  .topbar h1 { font-size: 28px; }
  main { padding: 6px 16px 96px; }
  .grid2 { grid-template-columns: 1fr; }
  .rule-form { grid-template-columns: 1fr 1fr; }
  .toolbar h2 { font-size: 20px; }
}
