/* ============================================================
   VASAP TV — Carrossel de Indicadores
   Redesign tema claro com a linguagem visual do shadcn/ui
   (preset "slate": neutros levemente azulados, cards brancos
   com borda fina + sombra sutil, radius ~10–14px, fonte Inter).

   tv.js gera todo o markup com as classes .tv-* — este arquivo
   apenas as re-estiliza. Variáveis sobrescritas no topo para
   não depender do tema escuro do tokens.css.
   ============================================================ */

/* ===================== TOKENS (shadcn slate, light) ===================== */
:root,
[data-theme="light"],
[data-theme="dark"] {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

    /* Superfícies — fundo branco, cards brancos separados por borda */
    --bg:             #ffffff;   /* fundo da tela: branco */
    --surface:        #ffffff;   /* cards */
    --surface-sunken: #f8fafc;   /* slate-50  — heads / trilhas */
    --surface-hover:  #f1f5f9;   /* slate-100 */

    /* Texto (slate) */
    --text:    #020617;          /* slate-950 */
    --text-2:  #334155;          /* slate-700 */
    --text-3:  #64748b;          /* slate-500 — muted-foreground */

    /* Bordas */
    --border:        #e2e8f0;    /* slate-200 */
    --border-strong: #cbd5e1;    /* slate-300 */

    /* Primary (near-black do shadcn) — chrome: marca, dots, progress */
    --primary:       #0f172a;    /* slate-900 */
    --primary-hover: #1e293b;    /* slate-800 */
    --primary-fg:    #ffffff;
    --primary-soft:  #f1f5f9;

    /* Accent de dados (barras de throughput / ritmo neutro) */
    --accent:        #2563eb;    /* blue-600 */
    --accent-2:      #4f46e5;    /* indigo-600 */

    /* Status ISA-101 — vivos e legíveis no branco */
    --st-ok:        #16a34a;     /* green-600  */
    --st-ok-soft:   #dcfce7;
    --st-info:      #2563eb;     /* blue-600   */
    --st-info-soft: #dbeafe;
    --st-warn:      #d97706;     /* amber-600  */
    --st-warn-soft: #fef3c7;
    --st-degraded:  #ea580c;     /* orange-600 */
    --st-degraded-soft: #ffedd5;
    --st-crit:      #dc2626;     /* red-600    */
    --st-crit-soft: #fee2e2;

    /* Radii — escala shadcn (--radius ~0.625rem) */
    --r-xs: 6px;
    --r-sm: 8px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-pill: 999px;

    /* Sombras suaves (estilo shadcn) */
    --shadow-sm: 0 1px 2px rgba(2, 6, 23, 0.04), 0 1px 3px rgba(2, 6, 23, 0.05);
    --shadow-md: 0 4px 12px rgba(2, 6, 23, 0.06), 0 2px 4px rgba(2, 6, 23, 0.04);
    --shadow-lg: 0 12px 32px rgba(2, 6, 23, 0.10);

    color-scheme: light;
}

/* ===================== BASE ===================== */
/* Canvas fixo 1920×1080 — fitTV() (tv.js/tv2.js) escala uniformemente
   pra resolução real da tela (TVs HD Ready 1366×768, Full HD, 4K…),
   centralizando com letterbox quando o aspecto difere. */
html {
    height: 100%;
    overflow: hidden;
    background: #020617;
}
body {
    width: 1920px;
    height: 1080px;
    overflow: hidden;
    transform-origin: 0 0;
}
body {
    display: flex;
    flex-direction: column;
    font-family: var(--font-sans);
    font-size: 16px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===================== HEADER ===================== */
.tv-header {
    flex: 0 0 76px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 var(--sp-8);
    display: flex;
    align-items: center;
    gap: var(--sp-6);
}
.tv-brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}
.tv-brand-mark {
    width: 44px;
    height: 44px;
    border-radius: var(--r-md);
    background: var(--primary);
    color: var(--primary-fg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--fw-bold);
    font-size: 24px;
    letter-spacing: -0.5px;
}
.tv-brand-name {
    font-size: 19px;
    font-weight: var(--fw-bold);
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.2px;
}
.tv-brand-sub {
    font-size: 12px;
    color: var(--text-3);
    font-weight: var(--fw-medium);
    text-transform: uppercase;
    letter-spacing: 1.4px;
    margin-top: 3px;
}
.tv-slide-title {
    flex: 1;
    text-align: center;
    font-size: 22px;
    font-weight: var(--fw-semi);
    color: var(--text);
    letter-spacing: -0.2px;
}
.tv-clock {
    text-align: right;
    line-height: 1;
}
.tv-time {
    font-family: var(--font-mono);
    font-size: 26px;
    font-weight: var(--fw-bold);
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.5px;
}
.tv-date {
    font-size: 11px;
    color: var(--text-3);
    font-weight: var(--fw-medium);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-top: 5px;
}

/* ===================== STAGE ===================== */
.tv-stage {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    background: var(--bg);
}
.tv-loading {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-3);
    color: var(--text-3);
    font-size: 18px;
}
.tv-loading .material-symbols-outlined {
    animation: tv-spin 1.4s linear infinite;
    color: var(--primary);
}
@keyframes tv-spin { to { transform: rotate(360deg); } }

.tv-slide {
    position: absolute;
    inset: 0;
    padding: var(--sp-6) var(--sp-8);
    overflow: hidden;
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
    transition: opacity 0.4s var(--easing, ease), transform 0.4s var(--easing, ease);
    display: flex;
    flex-direction: column;
    gap: var(--sp-5);
}
.tv-slide.active {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

/* ===================== FOOTER ===================== */
.tv-footer {
    flex: 0 0 52px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0 var(--sp-8);
    display: flex;
    align-items: center;
    gap: var(--sp-6);
}
.tv-dots {
    display: flex;
    gap: var(--sp-2);
}
.tv-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--border-strong);
    transition: all 0.3s var(--easing, ease);
}
.tv-dot.active {
    background: var(--primary);
    width: 30px;
    border-radius: var(--r-pill);
}
.tv-progress {
    flex: 1;
    height: 6px;
    background: var(--surface-hover);
    border-radius: var(--r-pill);
    overflow: hidden;
}
.tv-progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    border-radius: var(--r-pill);
    transition: width 0.2s linear;
}
.tv-status {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: 12px;
    color: var(--text-3);
    font-weight: var(--fw-medium);
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}
.tv-status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--st-ok);
    box-shadow: 0 0 0 3px var(--st-ok-soft);
}
.tv-status-dot.warn { background: var(--st-warn); box-shadow: 0 0 0 3px var(--st-warn-soft); }
.tv-status-dot.crit { background: var(--st-crit); box-shadow: 0 0 0 3px var(--st-crit-soft); }

/* ============================================================
   Grids / utilitários
   ============================================================ */
.tv-grid { display: grid; gap: var(--sp-5); }
.tv-grid-2 { grid-template-columns: repeat(2, 1fr); }
.tv-grid-3 { grid-template-columns: repeat(3, 1fr); }
.tv-grid-4 { grid-template-columns: repeat(4, 1fr); }
.tv-grid-5 { grid-template-columns: repeat(5, 1fr); }
.tv-grid-6 { grid-template-columns: repeat(6, 1fr); }
.tv-grid-7 { grid-template-columns: repeat(7, 1fr); }
.tv-row { display: flex; gap: var(--sp-5); }
.tv-row > * { flex: 1; }
.tv-fill { flex: 1; min-height: 0; }

/* ============================================================
   KPI Card — shadcn card (border + radius xl + shadow-sm)
   ============================================================ */
.tv-kpi {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-5) var(--sp-6);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    min-height: 118px;
    overflow: hidden;
}
/* faixa de status no topo (acento ISA-101 discreto, estilo shadcn) */
.tv-kpi::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: transparent;
}
.tv-kpi-label {
    font-size: 12px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: var(--fw-semi);
}
.tv-kpi-value {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 46px;
    font-weight: var(--fw-bold);
    color: var(--text);
    line-height: 1;
    letter-spacing: -1px;
}
.tv-kpi-value.big { font-size: 64px; }
.tv-kpi-value.huge { font-size: 96px; }
.tv-kpi-trend { font-size: 14px; font-weight: var(--fw-semi); color: var(--text-2); }
.tv-kpi-trend.up   { color: var(--st-ok); }
.tv-kpi-trend.down { color: var(--st-crit); }
.tv-kpi-sub { font-size: 12.5px; color: var(--text-3); margin-top: auto; }

/* Acento de status no topo do card */
.tv-kpi.ok::before       { background: var(--st-ok); }
.tv-kpi.info::before     { background: var(--st-info); }
.tv-kpi.warn::before     { background: var(--st-warn); }
.tv-kpi.degraded::before { background: var(--st-degraded); }
.tv-kpi.crit::before     { background: var(--st-crit); }
.tv-kpi.neutro::before   { background: var(--border-strong); }

/* ============================================================
   Card padrão (shadcn card)
   ============================================================ */
.tv-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.tv-card-head {
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    background: var(--surface-sunken);
}
.tv-card-head .material-symbols-outlined {
    font-size: 22px;
    color: var(--text-3);
}
.tv-card-title {
    font-size: 16px;
    font-weight: var(--fw-semi);
    color: var(--text);
    letter-spacing: -0.1px;
    flex: 1;
}
.tv-card-meta {
    font-size: 12px;
    color: var(--text-3);
    font-weight: var(--fw-medium);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.tv-card-body {
    padding: var(--sp-5);
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ============================================================
   Funil de etapas (slide Pipeline)
   ============================================================ */
.tv-funil { display: flex; flex-direction: column; gap: var(--sp-3); }
.tv-funil-row {
    display: grid;
    grid-template-columns: 230px 1fr 130px;
    align-items: center;
    gap: var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--sp-4) var(--sp-5);
}
.tv-funil-etapa { font-size: 22px; font-weight: var(--fw-bold); color: var(--text); letter-spacing: -0.3px; }
.tv-funil-etapa-sub {
    font-size: 12px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-top: 4px;
}
.tv-funil-bar {
    height: 34px;
    background: var(--surface-hover);
    border-radius: var(--r-sm);
    overflow: hidden;
    position: relative;
}
.tv-funil-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    transition: width 0.8s var(--easing, ease);
    border-radius: var(--r-sm);
}
.tv-funil-num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 42px;
    font-weight: var(--fw-bold);
    color: var(--text);
    text-align: right;
    letter-spacing: -1px;
}

/* ============================================================
   Cards de Ritmo Turno × Máquina (slide OEE Roto)
   ============================================================ */
.tv-ritmo-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-4) var(--sp-5);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    min-height: 0;
    overflow: hidden;
}
.tv-ritmo-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--border-strong);
}
.tv-ritmo-card.ok::before       { background: var(--st-ok); }
.tv-ritmo-card.info::before     { background: var(--st-info); }
.tv-ritmo-card.warn::before     { background: var(--st-warn); }
.tv-ritmo-card.degraded::before { background: var(--st-degraded); }
.tv-ritmo-card.crit::before     { background: var(--st-crit); }
.tv-ritmo-card.neutro::before   { background: var(--border-strong); }

.tv-ritmo-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-2);
}
.tv-ritmo-titulo { font-size: 18px; font-weight: var(--fw-bold); color: var(--text); letter-spacing: -0.2px; }
.tv-ritmo-pct {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 23px;
    font-weight: var(--fw-bold);
    letter-spacing: -0.5px;
}
.tv-ritmo-pct.ok       { color: var(--st-ok); }
.tv-ritmo-pct.info     { color: var(--st-info); }
.tv-ritmo-pct.warn     { color: var(--st-warn); }
.tv-ritmo-pct.degraded { color: var(--st-degraded); }
.tv-ritmo-pct.crit     { color: var(--st-crit); }
.tv-ritmo-pct.neutro   { color: var(--text-3); }

.tv-ritmo-met { display: flex; justify-content: space-between; gap: var(--sp-2); font-size: 13px; }
.tv-ritmo-met-label { color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; font-weight: var(--fw-medium); }
.tv-ritmo-met-val {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--text);
    font-weight: var(--fw-semi);
}
.tv-ritmo-bar {
    height: 7px;
    background: var(--surface-hover);
    border-radius: var(--r-pill);
    overflow: hidden;
}
.tv-ritmo-bar-fill { height: 100%; border-radius: var(--r-pill); transition: width 0.6s var(--easing, ease); }
.tv-ritmo-bar-fill.ok       { background: var(--st-ok); }
.tv-ritmo-bar-fill.info     { background: var(--st-info); }
.tv-ritmo-bar-fill.warn     { background: var(--st-warn); }
.tv-ritmo-bar-fill.degraded { background: var(--st-degraded); }
.tv-ritmo-bar-fill.crit     { background: var(--st-crit); }
.tv-ritmo-bar-fill.neutro   { background: var(--border-strong); }

/* ============================================================
   Tabela (slide Pesagem ranking, CQ, refugo)
   ============================================================ */
.tv-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.tv-table th {
    text-align: left;
    padding: var(--sp-3) var(--sp-3);
    background: transparent;
    border-bottom: 1px solid var(--border);
    color: var(--text-3);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: var(--fw-semi);
}
.tv-table td {
    padding: var(--sp-3);
    border-bottom: 1px solid var(--surface-hover);
    color: var(--text);
}
.tv-table tbody tr:nth-child(even) td { background: var(--surface-sunken); }
.tv-table td.num {
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-weight: var(--fw-semi);
}
.tv-table tbody tr:last-child td { border-bottom: none; }
.tv-table .rank {
    font-family: var(--font-mono);
    color: var(--text-3);
    font-weight: var(--fw-bold);
    text-align: center;
    width: 54px;
}
.tv-table .rank.first { color: #ca8a04; font-size: 18px; }

/* ============================================================
   Big number central (slide transferência etc)
   ============================================================ */
.tv-big {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-3);
    text-align: center;
}
.tv-big-num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 220px;
    font-weight: var(--fw-bold);
    line-height: 1;
    color: var(--text);
    letter-spacing: -6px;
}
.tv-big-label {
    font-size: 26px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 3px;
    font-weight: var(--fw-semi);
}
.tv-big-delta {
    font-size: 22px;
    font-weight: var(--fw-semi);
    padding: 6px 18px;
    border-radius: var(--r-pill);
    background: var(--surface);
    border: 1px solid var(--border);
}
.tv-big-delta.up   { color: var(--st-ok);   border-color: var(--st-ok);   background: var(--st-ok-soft); }
.tv-big-delta.down { color: var(--st-crit); border-color: var(--st-crit); background: var(--st-crit-soft); }

/* Mini bar chart por hora */
.tv-hora-chart {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 7px;
    height: 110px;
    width: 72%;
    max-width: 900px;
    margin-top: var(--sp-6);
}
.tv-hora-col { display: flex; flex-direction: column; align-items: center; flex: 1; gap: 5px; }
.tv-hora-bar {
    width: 100%;
    background: linear-gradient(180deg, var(--accent), var(--accent-2));
    border-radius: var(--r-xs) var(--r-xs) 0 0;
    min-height: 4px;
}
.tv-hora-label { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }

/* ============================================================
   Sem dados / erro
   ============================================================ */
.tv-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-3);
    color: var(--text-3);
}
.tv-empty .material-symbols-outlined { font-size: 64px; opacity: 0.4; }
.tv-empty-text { font-size: 20px; }

/* ============================================================
   Refugo motivos bar list
   ============================================================ */
.tv-motivo-row {
    display: grid;
    grid-template-columns: 1fr 76px;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) 0;
}
.tv-motivo-bar {
    height: 26px;
    background: var(--surface-hover);
    border-radius: var(--r-sm);
    overflow: hidden;
    position: relative;
}
.tv-motivo-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--st-warn), var(--st-crit));
    border-radius: var(--r-sm);
    transition: width 0.6s var(--easing, ease);
}
.tv-motivo-label {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: var(--text);
    font-weight: var(--fw-semi);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 24px);
}
.tv-motivo-qtd {
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 15px;
    font-weight: var(--fw-bold);
    color: var(--text);
}
