:root {
    --bg: #0f1115;
    --bg-panel: #171a21;
    --bg-elevated: #1e222b;
    --border: #272c37;
    --text: #e6e9ef;
    --text-muted: #9aa3b2;
    --primary: #4f7cff;
    --primary-hover: #3f68e0;
    --danger: #ef4444;
    --ok: #22c55e;
    --radius: 10px;
    --topbar-height: 56px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body.app {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Cabecera ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    height: var(--topbar-height);
    padding: 0 24px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar__brand { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

.topbar__nav { display: flex; align-items: center; gap: 4px; }

.topbar__link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.topbar__link:hover { background: var(--bg-elevated); color: var(--text); }

.topbar__link.is-active {
    background: var(--primary);
    color: #fff;
}

.topbar__icono { font-size: 15px; }

/* ---------- Layout ---------- */
.main {
    min-width: 0;
    padding: 28px 32px;
}

/* ---------- Página ---------- */
.page__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.page__title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.page__subtitle { margin: 4px 0 0; color: var(--text-muted); font-size: 14px; }

/* ---------- Paneles ---------- */
.split {
    display: grid;
    grid-template-columns: minmax(260px, 340px) 1fr;
    gap: 20px;
    align-items: start;
}

.split[hidden] { display: none; }

/* Sin lista visible (guion seleccionado), el editor ocupa todo el ancho. */
.split:has(.panel--list[hidden]) { grid-template-columns: 1fr; }

.panel {
    overflow: hidden;
}

.panel--center { padding: 32px; text-align: center; max-width: 640px; margin: 48px auto; }

.panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.panel__title { margin: 0; font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

.panel__note { margin: 0; padding: 14px 16px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 13px; }

/* ---------- Lista ---------- */
.list { list-style: none; margin: 0; padding: 6px; min-height: 120px; max-height: calc(100vh - var(--topbar-height) - 120px); overflow-y: auto; }

.list__item + .list__item { margin-top: 2px; }

.list__button {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.list__button:hover { background: var(--bg-elevated); }
.list__item.is-selected .list__button { background: var(--bg-elevated); box-shadow: inset 2px 0 0 var(--primary); }
.list__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }

.list__meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list__fecha { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.list__empty {
    padding: 28px 16px;
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
}

/* ---------- Tablero (guiones agrupados por estado) ---------- */
.board {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    align-items: start;
}

.board[hidden] { display: none; }

.board__column {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.board__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.board__title { margin: 0; font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

.board__list {
    list-style: none;
    margin: 0;
    padding: 6px;
    min-height: 60px;
    max-height: calc(100vh - var(--topbar-height) - 220px);
    overflow-y: auto;
}

.board__list .list__item + .list__item { margin-top: 2px; }

.board__empty {
    padding: 20px 12px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

/* ---------- Editor ---------- */
.editor { display: block; padding: 32px clamp(16px, 4vw, 64px); max-width: 860px; margin: 0 auto; }

.editor--vacio {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 320px;
}

.editor[hidden], .editor--vacio[hidden] { display: none; }

.editor__volver {
    display: inline-block;
    margin-bottom: 16px;
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: none;
}

.editor__volver:hover { color: var(--text); }

.editor__head {
    display: flex;
    align-items: center;
    gap: 16px;
}

.editor__titulo {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0;
    background: transparent;
    border: 0;
    color: var(--text);
    font: inherit;
    font-size: 50px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.editor__titulo:hover { border-bottom-color: var(--border); }
.editor__titulo:focus { outline: none; border-bottom-color: var(--primary); }

.editor__titulo:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    font-weight: 700;
}

.editor__acciones { display: flex; align-items: center; gap: 6px; flex-shrink: 0; padding-top: 6px; }

.editor__body {
    margin-top: 24px;
}

.editor__placeholder { color: var(--text-muted); margin: 0; }
.editor__hint { font-size: 13px; opacity: 0.75; }

/* ---------- Párrafos ---------- */
.parrafos { display: flex; flex-direction: column; }

.parrafos__vacio {
    margin: 0 0 14px;
    padding: 28px 0;
    color: var(--text-muted);
    text-align: center;
}

.parrafos__vacio[hidden] { display: none; }

.parrafo {
    padding: 0 0 20px 0;
}

.parrafo:last-child { border-bottom: 0; }

.parrafo__pie {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
    opacity: 0.6;
}

.parrafo__meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.parrafo__contadores { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.parrafo__acciones { display: flex; gap: 2px; }

.icon-btn {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}

.icon-btn svg { width: 18px; height: 18px; }

.icon-btn:hover:not(:disabled) { color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.icon-btn--danger:hover:not(:disabled) { color: #fca5a5; }

.parrafo__texto {
    display: block;
    width: 100%;
    padding: 0;
    background: transparent;
    border: 0;
    color: var(--text);
    font: inherit;
    line-height: 1.3;
    font-size: 22px;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.parrafo__texto:focus { outline: none; }

.parrafo__texto:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
}

.parrafo__plataformas { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-width: 0; }

.parrafo__sin-plataformas { font-size: 12px; color: var(--text-muted); }

.check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    border: 0;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}

.check:hover { color: var(--text); }

.check--on { color: var(--primary); }

.check:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }

.check__input { position: absolute; width: 1px; height: 1px; margin: -1px; opacity: 0; }

.icono { display: inline-flex; width: 16px; height: 16px; }
.icono svg { width: 100%; height: 100%; }

/* ---------- Interruptor ---------- */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch__input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch__track {
    position: relative;
    width: 34px;
    height: 20px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 999px;
    transition: background 0.15s, border-color 0.15s;
}

.switch__track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: transform 0.15s, background 0.15s;
}

.switch__input:checked + .switch__track { background: var(--primary); border-color: var(--primary); }
.switch__input:checked + .switch__track::after { transform: translateX(14px); background: #fff; }
.switch__input:focus-visible + .switch__track { outline: 2px solid var(--primary); outline-offset: 2px; }

.switch__label { font-size: 12px; color: var(--text-muted); min-width: 52px; }

.input--inline {
    padding: 6px 10px;
    background: transparent;
    border-color: transparent;
    max-width: 280px;
}

.input--inline:hover { border-color: var(--border); }
.input--inline:focus { background: var(--bg-elevated); border-color: var(--primary); }

.table__acciones { width: 1%; text-align: right; white-space: nowrap; }
.table tbody tr.is-inactiva .input--inline { color: var(--text-muted); }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Estadísticas ---------- */
.stats {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 0;
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 13px;
}

.stat { display: inline-flex; align-items: baseline; gap: 4px; min-width: 0; }
.stat + .stat::before { content: '·'; margin: 0 8px; opacity: 0.5; }

.stat__value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.stat__value--sm { font-weight: 500; color: var(--text-muted); }
.stat__label { font-size: 13px; }

/* ---------- Indicador de guardado ---------- */
.saver { font-size: 12px; color: var(--text-muted); min-width: 70px; }
.saver--pending { color: var(--text-muted); }
.saver--ok { color: var(--ok); }
.saver--error { color: var(--danger); }

.field-error { margin: 6px 2px 0; color: var(--danger); font-size: 13px; }
.field-error[hidden] { display: none; }

/* ---------- Modal ---------- */
.modal {
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-panel);
    color: var(--text);
    width: min(440px, calc(100vw - 32px));
}

.modal::backdrop { background: rgba(0, 0, 0, 0.6); }

.modal__form { padding: 22px; }
.modal__title { margin: 0 0 14px; font-size: 18px; font-weight: 700; }
.modal__text { margin: 0 0 10px; font-size: 14px; color: var(--text-muted); }
.modal__text--warning { color: #fca5a5; }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.field { display: block; }
.field__label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-muted); }

.input {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}

.input:focus { outline: none; border-color: var(--primary); }

/* ---------- Vista previa ---------- */
.page--preview { max-width: 820px; margin: 0 auto; }

.preview__bar {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.preview__filtro { display: flex; flex-direction: column; gap: 4px; }
.preview__acciones { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.preview__cabecera { padding: 22px 26px 0; }
.preview__titulo { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.preview__meta { margin: 6px 0 0; font-size: 13px; color: var(--text-muted); }

.preview__texto { padding: 18px 26px 26px; }

.preview__texto p {
    margin: 0 0 1.1em;
    font-size: 17px;
    line-height: 1.75;
    /* Conserva los saltos de línea escritos dentro de cada párrafo. */
    white-space: pre-wrap;
}

.preview__texto p:last-child { margin-bottom: 0; }
.preview__vacio { color: var(--text-muted); font-size: 14px; text-align: center; padding: 24px 0; }

/* ---------- Teleprompter ---------- */
.tp-body { background: #000; overflow: hidden; }

.tp {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: #000;
    color: #f5f7fa;
}

.tp__cabecera {
    flex: 0 0 auto;
    padding: 14px 20px 10px;
    border-bottom: 1px solid #1c1c1c;
    transition: opacity 0.2s;
}

.tp__titulo { margin: 0; font-size: 15px; font-weight: 600; color: #cbd5e1; }
.tp__meta { margin: 2px 0 0; font-size: 12px; color: #7a828f; }

.tp__viewport {
    flex: 1 1 auto;
    /* Sin esto el flex item no se encoge y los controles quedan fuera de pantalla. */
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: none;
    cursor: pointer;
    outline: none;
    scroll-behavior: auto;
    overscroll-behavior: contain;
}

.tp__viewport::-webkit-scrollbar { width: 0; height: 0; }

.tp__texto {
    max-width: 22em;
    margin: 0 auto;
    /* Espacio para leer el inicio y poder llegar al final del texto. */
    padding: 30vh 24px 70vh;
    font-size: 48px;
    line-height: 1.45;
    font-weight: 600;
    text-align: center;
    text-wrap: balance;
}

.tp__texto p { margin: 0 0 0.9em; white-space: pre-wrap; }
.tp__texto p:last-child { margin-bottom: 0; }
.tp__vacio { font-size: 0.5em; color: #7a828f; font-weight: 400; }

.tp.is-espejo .tp__texto { transform: scaleX(-1); }

.tp__progreso { flex: 0 0 auto; height: 3px; background: #141414; }
.tp__progreso span { display: block; height: 100%; width: 0; background: var(--primary); }

.tp__controles {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    padding: 12px 20px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: #0b0b0b;
    border-top: 1px solid #1c1c1c;
    transition: opacity 0.2s, transform 0.2s;
}

.tp__grupo { display: flex; align-items: center; gap: 8px; }
.tp__campo { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.tp__campo--auto { margin-left: auto; }
.tp__etiqueta { font-size: 11px; color: #7a828f; text-transform: uppercase; letter-spacing: 0.05em; }
.tp__etiqueta b { color: #cbd5e1; font-variant-numeric: tabular-nums; }

.tp__campo input[type='range'] { width: 100%; accent-color: var(--primary); cursor: pointer; }

.tp-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 8px 14px;
    background: #17181d;
    border: 1px solid #2a2d35;
    border-radius: 8px;
    color: #e6e9ef;
    font: inherit;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
}

.tp-btn:hover { background: #21232a; }
.tp-btn.is-on { background: var(--primary); border-color: var(--primary); color: #fff; }
.tp-btn--principal { min-width: 118px; justify-content: center; font-weight: 600; }

.tp__ayuda {
    flex: 0 0 auto;
    margin: 0;
    padding: 0 20px 10px;
    background: #0b0b0b;
    font-size: 11px;
    color: #555c68;
    text-align: center;
    transition: opacity 0.2s;
}

/* Durante la lectura los controles se apartan tras unos segundos sin uso. */
.tp.is-inactivo .tp__cabecera,
.tp.is-inactivo .tp__controles,
.tp.is-inactivo .tp__ayuda {
    opacity: 0;
    pointer-events: none;
}

.tp.is-fullscreen .tp__cabecera,
.tp.is-fullscreen .tp__ayuda {
    display: none;
}

/* En pantalla completa manda la altura del elemento, no la del viewport previo. */
.tp.is-fullscreen { height: 100%; width: 100%; }

.tp.is-fullscreen .tp__texto { padding-top: 35vh; padding-bottom: 75vh; }

@media (max-width: 768px) {
    .tp__texto { padding-left: 16px; padding-right: 16px; }
    .tp__controles { gap: 12px; padding: 10px 12px; }
    .tp__campo { min-width: 110px; flex: 1 1 110px; }
    .tp__campo--auto { margin-left: 0; }
    .tp__grupo { flex: 1 1 100%; }
    .tp-btn { flex: 1 1 auto; justify-content: center; }
    .tp__ayuda { display: none; }
}

/* ---------- Tabla ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.table tbody tr:last-child td { border-bottom: 0; }
.table__empty { color: var(--text-muted); text-align: center; padding: 24px 16px; }

/* ---------- Elementos ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-elevated);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.btn:hover { background: #262b36; }

.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn--danger { color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); }
.btn--danger:hover { background: rgba(239, 68, 68, 0.15); }

.btn--sm { padding: 6px 12px; font-size: 13px; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.select {
    padding: 6px 10px;
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    font-size: 13px;
}

.select:disabled { opacity: 0.5; }

.badge {
    min-width: 24px;
    padding: 2px 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

.tag {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    white-space: nowrap;
}

.tag--ok { color: var(--ok); border-color: rgba(34, 197, 94, 0.35); }
.tag--off { color: var(--text-muted); }

/* Estados de guion (los códigos provienen de la tabla `estados`). */
.tag--borrador { color: #cbd5e1; }
.tag--en_proceso { color: #fbbf24; border-color: rgba(251, 191, 36, 0.35); }
.tag--terminado { color: #38bdf8; border-color: rgba(56, 189, 248, 0.35); }
.tag--publicado { color: var(--ok); border-color: rgba(34, 197, 94, 0.35); }

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 14px;
}

.alert--error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

.code {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    overflow: auto;
    text-align: left;
    font-size: 13px;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .split { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .topbar { gap: 12px; padding: 0 14px; }
    .topbar__link { padding: 7px 10px; }
    .main { padding: 20px 16px; }
}
