:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
  --text: #e6e8ec; --muted: #8b93a3; --accent: #4fd1c5; --accent2: #f6ad55; --danger: #fc8181; --ok: #68d391;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* UI local (python ui.py) frente a web desplegada: app.js pone body.local si responde /api/status */
body:not(.local) [data-local], body.local [data-deployed] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, "Segoe UI", sans-serif; }
header { display: flex; align-items: center; gap: 24px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand small { font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 12px; }
.logo { color: var(--accent); }
nav { display: flex; gap: 4px; }
.tab { background: none; border: 0; color: var(--muted); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; }
.tab:hover { color: var(--text); background: var(--panel2); }
.tab.active { color: var(--bg); background: var(--accent); font-weight: 600; }
.status { margin-left: auto; color: var(--muted); font-size: 12px; text-align: right; }
main { padding: 16px 20px 120px; max-width: 1500px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; min-width: 0; }
.panel-title { font-size: 12px; letter-spacing: .08em; font-weight: 700; margin-bottom: 10px; }
.muted { color: var(--muted); font-weight: 400; letter-spacing: 0; }
.toolbar { display: flex; align-items: end; gap: 14px; margin: 10px 0; }
.toolbar.wrap { flex-wrap: wrap; }
.toolbar label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.toolbar label.check { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 8px; }
.spacer { flex: 1; }
select, input { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font: inherit; min-width: 0; }
input[type=number] { width: 110px; }
button { font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--accent); color: #062b28; border-color: var(--accent); font-weight: 600; }
.primary.danger { background: var(--danger); border-color: var(--danger); color: #3a0b0b; }
.secondary { background: var(--panel2); color: var(--text); }
.ghost { background: none; color: var(--muted); border-color: transparent; padding: 4px 8px; }
.ghost:hover { color: var(--text); }
.small { padding: 4px 9px; font-size: 12px; }

.call-grid { display: grid; grid-template-columns: 1fr 300px 1fr; gap: 14px; }
.screen { position: relative; aspect-ratio: 1; background: #000; border-radius: 10px; overflow: hidden; }
.screen video, .screen img, .screen canvas { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
#rec-cam { object-fit: contain; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; pointer-events: none; }
.overlay.big { font-size: 42px; font-weight: 700; color: var(--accent2); }
.overlay:empty { display: none; }
.channel .kv { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.channel .kv span { color: var(--muted); }
.thumb { width: 96px; height: 96px; object-fit: cover; border-radius: 6px; margin: 6px 0; background: #000; display: block; transform: scaleX(-1); }
img.thumb:not([src]), img.thumb[src=""] { visibility: hidden; height: 0; margin: 0; }
.hex { font: 11px/1.5 var(--mono); color: var(--accent); background: #0b0d10; border-radius: 6px; padding: 8px; white-space: pre-wrap; word-break: break-all; margin: 6px 0; max-height: 140px; overflow: auto; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.stats div { background: var(--panel2); border-radius: 8px; padding: 6px 8px; }
.stats span { display: block; font-size: 11px; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }
.audio-info { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 8px 14px; margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.audio-info p { margin: 6px 0; }
#audio-status { color: var(--accent); min-height: 1.5em; }
#code-matrix { display: block; width: 100%; margin: 10px 0; background: #0b0d10; border-radius: 6px; image-rendering: pixelated; }
#tab-call > .toolbar { flex-wrap: wrap; }
#btn-forget-pw { align-self: end; margin-bottom: 4px; }
.models-box { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 10px 14px; margin-bottom: 14px; }
.models-box p { margin: 0; color: var(--accent2); }
.models-box p.error { color: var(--danger); }
.pw-form { display: flex; flex-wrap: wrap; align-items: end; gap: 14px; margin-top: 10px; }
.pw-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.pw-form label.check { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 8px; }
.audio-mode .screen img, .audio-mode .screen canvas { transform: none; }
#recon:not([src]) { visibility: hidden; }
.audio-mode .toolbar label.check { display: none; }
.audio-mode .panel > .kv { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12px; }

.panel-title.row { display: flex; align-items: center; gap: 4px; }
.file-btn { border: 1px solid var(--line); border-radius: 8px; cursor: pointer; letter-spacing: 0; font-weight: 400; }
.file-btn:hover { color: var(--text); }
#tab-record code { font: 12px var(--mono); background: #0b0d10; border-radius: 4px; padding: 1px 5px; overflow-wrap: anywhere; }
#tab-record [data-deployed] p, .steps { color: var(--muted); font-size: 13px; }
.steps { padding-left: 20px; } .steps li { margin: 6px 0; line-height: 1.8; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 14px; }
#tab-record .screen { aspect-ratio: 16/9; }
.progress { height: 6px; background: var(--panel2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--danger); transition: width .3s linear; }
.tips { color: var(--muted); font-size: 13px; padding-left: 18px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.rec { display: grid; grid-template-columns: 120px 1fr; gap: 12px; background: var(--panel2); border-radius: 10px; padding: 10px; }
.rec img { width: 120px; border-radius: 6px; }
.rec .meta { color: var(--muted); font-size: 12px; }
.rec .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel); color: var(--muted); margin-left: 6px; }
.badge.ok { color: var(--ok); }
.badge.run { color: var(--accent2); }

.runs { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 14px; margin-top: 14px; }
.run h3 { margin: 0 0 4px; font-size: 15px; }
.run img.preview { width: 100%; border-radius: 6px; margin: 8px 0; background: #000; image-rendering: auto; }
.run svg { width: 100%; height: auto; background: #0b0d10; border-radius: 6px; }
.run .actions { display: flex; gap: 8px; margin-top: 8px; }
.legend { font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 3px; margin: 0 4px 2px 8px; vertical-align: middle; }

.outputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(600px, 1fr)); gap: 14px; }
.outputs video { width: 100%; border-radius: 8px; background: #000; }
.outputs table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
.outputs td, .outputs th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }

footer { position: fixed; bottom: 0; left: 0; right: 0; background: var(--panel); border-top: 1px solid var(--line); z-index: 10; }
.dock-head { display: flex; align-items: center; gap: 10px; padding: 8px 20px; cursor: pointer; }
.dock-body { display: grid; grid-template-columns: 320px 1fr; height: 300px; border-top: 1px solid var(--line); }
footer.collapsed .dock-body { display: none; }
.jobs-list { overflow: auto; border-right: 1px solid var(--line); }
.job { padding: 8px 14px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.job:hover, .job.sel { background: var(--panel2); }
.job .st { font-size: 11px; }
.st.running { color: var(--accent2); } .st.done { color: var(--ok); } .st.failed { color: var(--danger); } .st.stopped { color: var(--muted); }
.log { margin: 0; padding: 10px 14px; overflow: auto; font: 12px/1.45 var(--mono); color: #c9d1d9; white-space: pre-wrap; word-break: break-word; }

/* línea de tiempo de fases (entrenamiento en Colab) */
.timeline { list-style: none; padding: 0; margin: 10px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.timeline li { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); background: var(--panel2); border-radius: 7px; padding: 6px 8px; }
.timeline li small { margin-left: auto; font-size: 11px; opacity: .8; }
.timeline .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.timeline .done { color: var(--text); } .timeline .done .dot { background: var(--ok); }
.timeline .now { color: var(--accent2); outline: 1px solid var(--accent2); } .timeline .now .dot { background: var(--accent2); animation: pulse 1.2s infinite; }
.timeline .fail { color: var(--danger); } .timeline .fail .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }
.colab-link { display: inline-block; margin: 2px 0 6px; color: var(--accent); font-size: 13px; text-decoration: none; border: 1px solid var(--accent); border-radius: 7px; padding: 5px 10px; }
.colab-link:hover { background: var(--accent); color: var(--bg); }

/* tooltips */
.i { display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; font: 700 10px/1 system-ui;
     font-style: normal; color: var(--bg); background: var(--muted); cursor: help; vertical-align: middle; margin-left: 4px; letter-spacing: 0; }
.i:hover { background: var(--accent); }
[data-tip]:not(.i) { cursor: help; }
button[data-tip], select[data-tip], .tab[data-tip] { cursor: pointer; }
#tip { position: fixed; z-index: 100; max-width: 380px; padding: 10px 12px; border-radius: 8px; background: #252a35; color: var(--text);
       border: 1px solid #4a5263; box-shadow: 0 8px 24px rgba(0,0,0,.6); font-size: 12.5px; line-height: 1.5; white-space: pre-line;
       pointer-events: none; display: none; }
#tip.show { display: block; }

@media (max-width: 1100px) {
  .call-grid, .two-col { grid-template-columns: 1fr; }
  .runs, .outputs { grid-template-columns: 1fr; }
}
@media (max-width: 650px) {
  header { flex-wrap: wrap; gap: 8px; padding: 10px; }
  nav { flex-wrap: wrap; }
  main { padding: 10px 10px 120px; }
  #tab-call > .toolbar label { max-width: 100%; }
  #decoder { max-width: 100%; }
}
.cam-controls { display: grid; gap: 6px; margin: 10px 0 4px; }
.cam-row { display: grid; grid-template-columns: minmax(150px, auto) 1fr 64px auto; align-items: center; gap: 10px; font-size: 13px; }
.cam-row input[type=range] { width: 100%; padding: 0; }
.cam-row b { font-variant-numeric: tabular-nums; text-align: right; }
.cam-row .chk { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
