* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #080808; --surface: #101010; --surface2: #181818; --surface3: #222222;
  --border: #2a2a3a; --border-hover: #3a3a5a;
  --text: #e8e8f0; --text-dim: #8888a0; --text-muted: #5a5a70;
  --accent: #E02020; --accent-dim: rgba(224,32,32,0.15);
  --gold: #ffd93d; --gold-dim: rgba(255,217,61,0.15);
  --red: #ff6b6b; --red-dim: rgba(255,107,107,0.15);
  --blue: #45b7d1; --blue-dim: rgba(69,183,209,0.15);
  --green: #4ecdc4; --green-dim: rgba(78,205,196,0.15);
  --radius: 10px;
}
body { background: var(--bg); color: var(--text); font-family: 'DM Sans', sans-serif; min-height: 100vh; }

/* ── Login Screen ── */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 40px; width: 100%; max-width: 380px; }
.login-box h1 { font-family: 'JetBrains Mono', monospace; font-size: 1.4rem; color: var(--accent); text-align: center; letter-spacing: 3px; margin-bottom: 4px; }
.login-box .subtitle { text-align: center; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 30px; }
.login-box input { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; color: var(--text); font-size: 0.9rem; font-family: 'DM Sans', sans-serif; margin-bottom: 12px; }
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box .login-btn { width: 100%; padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: 6px; font-size: 0.9rem; font-weight: 600; cursor: pointer; margin-top: 8px; font-family: 'DM Sans', sans-serif; }
.login-box .login-btn:hover { background: #c41a1a; }
.login-error { color: var(--red); font-size: 0.75rem; text-align: center; margin-top: 10px; display: none; }

/* ── App Shell ── */
.app { display: none; }
.header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 24px; display: flex; align-items: center; justify-content: space-between; }
.header h1 { font-family: 'JetBrains Mono', monospace; font-size: 0.9rem; font-weight: 700; color: var(--accent); }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-user { font-size: 0.75rem; color: var(--text-dim); }
.header-tenant { font-size: 0.65rem; color: var(--accent); background: var(--accent-dim); padding: 2px 8px; border-radius: 4px; }
.header-logout { font-size: 0.7rem; color: var(--text-muted); cursor: pointer; background: none; border: 1px solid var(--border); padding: 4px 10px; border-radius: 4px; font-family: 'DM Sans', sans-serif; }
.header-logout:hover { border-color: var(--red); color: var(--red); }

.tabs { display: flex; gap: 0; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 24px; }
.tab { padding: 12px 20px; font-size: 0.8rem; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s; font-family: 'DM Sans', sans-serif; background: none; border-top: none; border-left: none; border-right: none; }
.tab:hover { color: var(--text-dim); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.main { max-width: 1100px; margin: 0 auto; padding: 24px; }
.panel { display: none; }
.panel.active { display: block; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-family: 'JetBrains Mono', monospace; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); }
.btn { font-family: 'DM Sans', sans-serif; font-size: 0.78rem; font-weight: 600; padding: 8px 16px; border-radius: 6px; cursor: pointer; border: 1px solid; transition: all 0.2s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--accent-dim); color: var(--accent); border-color: rgba(224,32,32,0.3); }
.btn-primary:hover { background: rgba(224,32,32,0.25); }
.btn-danger { background: var(--red-dim); color: var(--red); border-color: rgba(255,107,107,0.3); }
.btn-danger:hover { background: rgba(255,107,107,0.25); }
.btn-secondary { background: var(--surface2); color: var(--text-dim); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface3); }
.btn-sm { padding: 5px 10px; font-size: 0.7rem; }
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 40px 20px; text-align: center; cursor: pointer; transition: all 0.3s; margin-bottom: 16px; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--accent); background: var(--accent-dim); }
.upload-zone p { color: var(--text-muted); font-size: 0.85rem; }
.upload-zone .big { font-size: 2rem; margin-bottom: 8px; }
.file-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.file-item { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; transition: border-color 0.2s; }
.file-item:hover { border-color: var(--border-hover); }
.file-item .preview { width: 100%; height: 120px; border-radius: 6px; overflow: hidden; background: #000; margin-bottom: 8px; display: flex; align-items: center; justify-content: center; position: relative; }
.file-item .preview img { width: 100%; height: 100%; object-fit: cover; }
.file-item .preview video { width: 100%; height: 100%; object-fit: cover; }
.file-item .preview .icon { font-size: 2rem; color: var(--text-muted); }
.file-item .preview .res-badge { position: absolute; bottom: 4px; right: 4px; font-family: 'JetBrains Mono', monospace; font-size: 0.55rem; padding: 2px 5px; border-radius: 3px; background: rgba(0,0,0,0.8); color: var(--accent); }
.file-item .name { font-size: 0.75rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-item .meta { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }
.file-item .actions { display: flex; gap: 4px; margin-top: 8px; }
.playlist-list { display: flex; flex-direction: column; gap: 8px; }
.playlist-row { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; transition: border-color 0.2s; }
.playlist-row:hover { border-color: var(--border-hover); }
.playlist-row .info { display: flex; flex-direction: column; gap: 2px; }
.playlist-row .pl-name { font-size: 0.85rem; font-weight: 600; }
.playlist-row .pl-meta { font-size: 0.7rem; color: var(--text-muted); }
.editor { margin-top: 16px; }
.editor-header { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.editor-header input { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; color: var(--text); font-size: 0.85rem; font-family: 'DM Sans', sans-serif; flex: 1; min-width: 200px; }
.editor-header input:focus { outline: none; border-color: var(--accent); }
.playlist-items { display: flex; flex-direction: column; gap: 6px; min-height: 60px; }
.playlist-item { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; display: flex; align-items: center; gap: 12px; cursor: grab; transition: all 0.2s; }
.playlist-item:active { cursor: grabbing; background: var(--surface3); }
.playlist-item.dragging { opacity: 0.4; }
.playlist-item .grip { color: var(--text-muted); font-size: 1rem; user-select: none; }
.playlist-item .item-info { flex: 1; }
.playlist-item .item-name { font-size: 0.8rem; font-weight: 500; }
.playlist-item .item-type { font-size: 0.6rem; font-family: 'JetBrains Mono', monospace; padding: 2px 6px; border-radius: 3px; text-transform: uppercase; }
.type-video { background: var(--blue-dim); color: var(--blue); }
.type-image { background: var(--gold-dim); color: var(--gold); }
.type-html { background: var(--green-dim); color: var(--green); }
.playlist-item .item-duration { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 4px 8px; color: var(--text); font-size: 0.75rem; width: 55px; text-align: center; font-family: 'JetBrains Mono', monospace; }
.playlist-item .item-duration:focus { outline: none; border-color: var(--accent); }
.dur-label { font-size: 0.6rem; color: var(--text-muted); margin-right: 4px; }
.content-picker { border: 1px dashed var(--border); border-radius: 8px; padding: 12px; margin-top: 12px; }
.content-picker-title { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 10px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.picker-item { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; transition: all 0.2s; overflow: hidden; }
.picker-item:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.picker-thumb { width: 100%; height: 80px; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.picker-thumb img { width: 100%; height: 100%; object-fit: cover; }
.picker-thumb video { width: 100%; height: 100%; object-fit: cover; }
.picker-thumb .icon { font-size: 1.2rem; color: var(--text-muted); }
.picker-thumb .res-badge { position: absolute; bottom: 2px; right: 2px; font-family: 'JetBrains Mono', monospace; font-size: 0.5rem; padding: 1px 4px; border-radius: 2px; background: rgba(0,0,0,0.8); color: var(--accent); }
.picker-info { padding: 6px 8px; }
.picker-info .picker-name { font-size: 0.65rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-info .picker-type { font-size: 0.55rem; font-family: 'JetBrains Mono', monospace; padding: 1px 5px; border-radius: 3px; text-transform: uppercase; display: inline-block; margin-top: 3px; }
.screen-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 10px; }
.screen-card .screen-name { font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; font-weight: 600; color: var(--accent); }
.screen-card .screen-url { font-size: 0.7rem; color: var(--text-muted); margin-top: 4px; word-break: break-all; user-select: all; }
.screen-card .screen-meta { font-size: 0.75rem; color: var(--text-dim); margin-top: 6px; }
.inline-form { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.inline-form input, .inline-form select { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; color: var(--text); font-size: 0.8rem; font-family: 'DM Sans', sans-serif; flex: 1; }
.inline-form input:focus, .inline-form select:focus { outline: none; border-color: var(--accent); }
.toast { position: fixed; bottom: 20px; right: 20px; padding: 12px 20px; background: var(--surface); border: 1px solid var(--accent); border-radius: 8px; color: var(--accent); font-size: 0.8rem; font-weight: 500; transform: translateY(100px); opacity: 0; transition: all 0.3s; z-index: 999; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border-color: var(--red); color: var(--red); }
.empty-state { text-align: center; padding: 40px; color: var(--text-muted); font-size: 0.85rem; }

/* Tenant management */
.tenant-row { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.tenant-row .t-name { font-size: 0.85rem; font-weight: 600; }
.tenant-row .t-meta { font-size: 0.7rem; color: var(--text-muted); }
.user-row { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.user-row .u-name { font-size: 0.8rem; font-weight: 500; }
.user-row .u-meta { font-size: 0.65rem; color: var(--text-muted); }
.tenant-select { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; color: var(--accent); font-size: 0.75rem; font-family: 'DM Sans', sans-serif; cursor: pointer; }
.tenant-select:focus { outline: none; border-color: var(--accent); }

/* ── Utilidades de visibilidad ──
   El JS alterna clases y el atributo `hidden` en lugar de escribir
   element.style.display, para que toda la presentación viva en esta hoja. */
[hidden] { display: none !important; }
.app.is-active { display: block; }
.login-screen.is-hidden { display: none; }

/* ── Detalles extraídos de atributos style en línea ── */
.hint { font-size: 0.7rem; margin-top: 4px; color: var(--text-muted); }
.card-count { font-size: 0.7rem; color: var(--text-muted); }
.row-actions { display: flex; gap: 6px; }

.duration-label {
  font-size: 0.75rem; color: var(--text-dim);
  display: flex; align-items: center; gap: 4px;
}
.duration-label input {
  width: 56px; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; padding: 4px 6px; color: var(--text);
  font-size: 0.75rem; text-align: center; font-family: 'JetBrains Mono', monospace;
}

.screen-last-seen { font-size: 0.65rem; color: var(--text-muted); }
.screen-unassigned { font-size: 0.7rem; color: var(--red); }
.picker-empty { font-size: 0.7rem; color: var(--text-muted); }
.editor-empty { padding: 20px; }

.status-pill { font-size: 0.6rem; padding: 1px 6px; border-radius: 3px; margin-left: 6px; }
.status-pill.online { background: var(--green-dim); color: var(--green); }
.status-pill.offline { background: var(--red-dim); color: var(--red); }

#newUserTenant { max-width: 200px; }
#newUserRole { max-width: 120px; }

/* ── Pantallas: token de dispositivo ── */
.screen-token {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
}
.token-ok      { color: var(--green); flex: 1; }
.token-missing { color: var(--gold);  flex: 1; }

.screen-url { cursor: pointer; }
.screen-url:hover { color: var(--accent); }

#newScreenPlaylist { max-width: 220px; }

/* ── Pantallas: asignación, telemetría y órdenes ── */
.screen-alias { font-family: 'DM Sans', sans-serif; font-weight: 400; color: var(--text-dim); font-size: 0.75rem; margin-left: 6px; }
.screen-assign { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.75rem; }
.screen-assign label { color: var(--text-dim); }
.screen-assign select {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; color: var(--text); font-size: 0.75rem; font-family: 'DM Sans', sans-serif;
  max-width: 260px;
}
.screen-assign select:focus { outline: none; border-color: var(--accent); }
.screen-items { color: var(--text-muted); font-size: 0.7rem; }
.screen-telemetry { font-size: 0.7rem; color: var(--text-dim); margin-top: 6px; line-height: 1.6; }
.telemetry-warn { color: var(--gold); }
.screen-commands {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 0.7rem;
}
.screen-commands-label { color: var(--text-muted); margin-right: 4px; }
.command-pending { color: var(--gold); margin-left: auto; }
