:root {
    --primary: #C62828;
    --primary-dark: #9e2020;
    --primary-light: #FFEBEE;
    --ink: #141414;
    --muted: #667085;
    --bg: #F3F5F8;
    --white: #fff;
    --line: #E6E9EF;
    --ok: #059669;
    --warn: #D97706;
    --info: #2563EB;
    --run: #7C3AED;
    --radius: 20px;
    --radius-sm: 14px;
    --shadow: 0 10px 30px rgba(20, 20, 20, 0.06);
    --shadow-lg: 0 22px 50px rgba(198, 40, 40, 0.12);
    --font: 'Inter', system-ui, sans-serif;
    --pad: clamp(16px, 3vw, 44px);
    --kpi-size: clamp(1.7rem, 3vw, 2.45rem);
    --title-size: clamp(1.4rem, 2.5vw, 2.1rem);
    --card-gap: clamp(12px, 1.5vw, 18px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body.painel-body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    min-height: 100vh;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

.painel-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(ellipse 70% 45% at 0% -5%, rgba(198, 40, 40, 0.14), transparent 55%),
        radial-gradient(ellipse 50% 35% at 100% 5%, rgba(198, 40, 40, 0.07), transparent 50%),
        linear-gradient(180deg, #ffffff 0%, var(--bg) 32%, #e9eef3 100%);
}

/* ——— Top ——— */
.painel-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px var(--pad);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 50;
}
.painel-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}
.painel-brand img { height: clamp(38px, 4vw, 50px); display: block; }
.painel-eyebrow {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--primary);
}
.painel-brand h1 {
    font-size: var(--title-size);
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.1;
}
.painel-top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.painel-live {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 650;
    font-size: 0.9rem;
    color: var(--muted);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 14px;
}
.painel-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.16);
    animation: pulse 1.6s ease infinite;
}
@keyframes pulse {
    50% { transform: scale(1.2); opacity: 0.65; }
}
.painel-btn {
    appearance: none;
    border: none;
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-weight: 700;
    font-size: 0.88rem;
    padding: 10px 18px;
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    box-shadow: 0 8px 18px rgba(198, 40, 40, 0.28);
}
.painel-btn:hover { background: var(--primary-dark); }
.painel-btn-ghost {
    background: transparent;
    color: var(--ink);
    border: 1.5px solid var(--line);
    box-shadow: none;
}
.painel-btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

/* ——— Main / sections ——— */
.painel-main {
    padding: 24px var(--pad) 56px;
    max-width: 1560px;
    margin: 0 auto;
    display: grid;
    gap: 28px;
}
.sec {
    display: grid;
    gap: 16px;
}
.sec-hoje {
    padding: 22px;
    border-radius: calc(var(--radius) + 6px);
    background:
        linear-gradient(145deg, rgba(255,255,255,0.95), rgba(255,235,238,0.55)),
        #fff;
    border: 1px solid #f0c8c8;
    box-shadow: var(--shadow-lg);
}
.sec-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}
.sec-head h2 {
    font-size: clamp(1.25rem, 2.2vw, 1.75rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-top: 2px;
}
.sec-sub {
    color: var(--muted);
    font-size: 0.92rem;
    margin-top: 4px;
    font-weight: 500;
}
.sec-head-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.mini-stat {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--muted);
}
.mini-stat b { color: var(--ink); }

/* ——— Hoje KPIs ——— */
.hoje-kpi-grid {
    display: grid;
    grid-template-columns: 1.35fr repeat(5, minmax(0, 1fr));
    gap: var(--card-gap);
}
.hkpi {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 16px 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 108px;
    box-shadow: var(--shadow);
}
.hkpi-main {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    background: linear-gradient(145deg, var(--primary) 0%, #8a1717 100%);
    border: none;
    color: #fff;
    box-shadow: 0 14px 32px rgba(198, 40, 40, 0.3);
}
.hkpi-main .hkpi-label,
.hkpi-main small { color: rgba(255,255,255,0.78); }
.hkpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: rgba(255,255,255,0.16);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    position: relative;
}
.hkpi-icon::before {
    content: '';
    width: 18px;
    height: 16px;
    border: 2px solid #fff;
    border-radius: 3px;
    box-shadow: 0 -3px 0 #fff;
}
.hkpi-label {
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}
.hkpi strong {
    font-size: var(--kpi-size);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
}
.hkpi small {
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 500;
}
.hkpi-ok { border-color: #a7f3d0; background: linear-gradient(180deg, #fff, #ecfdf5); }
.hkpi-ok strong { color: var(--ok); }
.hkpi-warn { border-color: #fde68a; background: linear-gradient(180deg, #fff, #fffbeb); }
.hkpi-warn strong { color: var(--warn); }
.hkpi-info { border-color: #bfdbfe; background: linear-gradient(180deg, #fff, #eff6ff); }
.hkpi-info strong { color: var(--info); }
.hkpi-run { border-color: #ddd6fe; background: linear-gradient(180deg, #fff, #f5f3ff); }
.hkpi-run strong { color: var(--run); }

.hoje-split {
    display: grid;
    grid-template-columns: 1.4fr 0.9fr;
    gap: var(--card-gap);
}
.hoje-side { display: grid; gap: var(--card-gap); }

.panel-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-width: 0;
}
.panel-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, #fff, #fafbfc);
}
.panel-card-head h3 {
    font-size: 0.98rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.pill {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-size: 0.75rem;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 999px;
}

.hoje-fila {
    max-height: 420px;
    overflow: auto;
    padding: 10px;
    display: grid;
    gap: 8px;
}
.fila-item {
    display: grid;
    grid-template-columns: 72px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 12px 12px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: #fbfcfd;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.fila-item:hover {
    background: #fff;
    border-color: #f0b4b4;
}
.fila-item.is-done { opacity: 0.72; }
.fila-hora {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.03em;
}
.fila-nome { font-weight: 800; font-size: 0.95rem; }
.fila-det {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 2px;
}
.status-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px 16px 18px;
}
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    background: #f8fafc;
    border: 1px solid var(--line);
    font-size: 0.82rem;
    font-weight: 700;
}
.status-pill b { font-size: 1rem; }

/* ——— Overview KPIs ——— */
.painel-kpis {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--card-gap);
}
.kpi {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 18px 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 108px;
}
.kpi-label {
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}
.kpi strong {
    font-size: var(--kpi-size);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
}
.kpi small {
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 500;
}
.kpi-hoje {
    background: linear-gradient(145deg, var(--primary) 0%, #8f1a1a 100%);
    border-color: transparent;
    color: #fff;
}
.kpi-hoje .kpi-label,
.kpi-hoje small { color: rgba(255, 255, 255, 0.78); }
.kpi-legado { border-color: #f1c7c7; background: var(--primary-light); }

/* ——— Charts ——— */
.painel-charts {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: var(--card-gap);
}
.chart-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    min-width: 0;
}
.chart-card-wide { grid-column: 1 / -1; }
.chart-card header { margin-bottom: 14px; }
.chart-card h2 {
    font-size: 1.02rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.chart-card header p {
    color: var(--muted);
    font-size: 0.84rem;
    margin-top: 2px;
}

.chart-bars { display: grid; gap: 10px; }
.chart-bars.compact { padding: 12px 14px 16px; gap: 8px; }
.bar-row {
    display: grid;
    grid-template-columns: minmax(90px, 160px) 1fr auto;
    gap: 10px;
    align-items: center;
}
.chart-bars.compact .bar-row {
    grid-template-columns: minmax(70px, 1fr) 1.2fr auto;
}
.bar-label {
    font-size: 0.8rem;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bar-track {
    height: 11px;
    background: #eef1f5;
    border-radius: 999px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), #ef9a9a);
    width: 0;
    transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.bar-val { font-weight: 800; font-size: 0.88rem; min-width: 1.5rem; text-align: right; }

.chart-donut-wrap {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 16px;
    align-items: center;
}
.chart-donut { width: 140px; height: 140px; }
.chart-legend { list-style: none; display: grid; gap: 8px; }
.chart-legend li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    font-weight: 650;
}
.leg-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

.chart-timeline {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    min-height: 140px;
    overflow-x: auto;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
}
.day-col {
    flex: 0 0 clamp(28px, 3.2vw, 42px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.day-col.is-hoje .day-stem { background: var(--primary); }
.day-col.is-passado .day-stem { background: #94a3b8; }
.day-col.is-futuro .day-stem { background: #ef9a9a; }
.day-stem {
    width: 100%;
    border-radius: 8px 8px 4px 4px;
    min-height: 4px;
    transition: height 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.day-n { font-size: 0.72rem; font-weight: 800; }
.day-d {
    font-size: 0.65rem;
    font-weight: 650;
    color: var(--muted);
    text-align: center;
    line-height: 1.15;
}

/* ——— Filters / timeline ——— */
.painel-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}
.filter-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px;
    box-shadow: var(--shadow);
}
.filter-tab {
    appearance: none;
    border: none;
    background: transparent;
    font: inherit;
    font-weight: 700;
    font-size: 0.84rem;
    padding: 10px 16px;
    border-radius: 999px;
    color: var(--muted);
    cursor: pointer;
}
.filter-tab.active {
    background: var(--primary);
    color: #fff;
}
.filter-search {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1;
    justify-content: flex-end;
    min-width: 220px;
}
.filter-search input,
.filter-search select {
    font: inherit;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 12px;
    padding: 11px 14px;
    min-width: min(100%, 220px);
    box-shadow: var(--shadow);
}
.filter-search input:focus,
.filter-search select:focus {
    outline: 2px solid rgba(198, 40, 40, 0.22);
    border-color: var(--primary);
}

.painel-esp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--card-gap);
}
.esp-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.esp-card h3 { font-size: 1rem; font-weight: 800; }
.esp-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--primary-light);
    color: var(--primary-dark);
}
.esp-list {
    list-style: none;
    display: grid;
    gap: 8px;
    max-height: 260px;
    overflow: auto;
}
.esp-list li {
    font-size: 0.84rem;
    padding: 8px 10px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px solid #eef2f6;
}
.esp-list strong { display: block; font-size: 0.9rem; }
.esp-list span { color: var(--muted); font-size: 0.78rem; }

.painel-timeline { display: grid; gap: 14px; }
.painel-loading,
.painel-empty {
    text-align: center;
    padding: 36px 20px;
    color: var(--muted);
    font-weight: 650;
    background: #fff;
    border-radius: var(--radius);
    border: 1px dashed var(--line);
}
.painel-empty.soft {
    border: none;
    background: transparent;
    box-shadow: none;
    padding: 28px 12px;
}

.day-block {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.day-block.is-passado { opacity: 0.92; }
.day-block.is-hoje {
    border-color: #f0b4b4;
    box-shadow: 0 14px 40px rgba(198, 40, 40, 0.12);
}
.day-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    background: linear-gradient(180deg, #fff, #fafbfc);
    border-bottom: 1px solid var(--line);
}
.day-head h3 {
    font-size: 1.02rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.day-head .badge {
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 5px 10px;
    border-radius: 999px;
    background: #eef2f6;
    color: var(--muted);
}
.day-block.is-hoje .badge { background: var(--primary); color: #fff; }
.day-block.is-passado .badge { background: #e2e8f0; }
.day-block.is-futuro .badge { background: #fee2e2; color: var(--primary-dark); }

.appt-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    padding: 14px;
}
.appt-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
    background: #fff;
    display: grid;
    gap: 8px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.appt-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(26, 26, 26, 0.08);
}
.appt-time {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--primary);
}
.appt-name { font-weight: 800; font-size: 1rem; }
.appt-meta {
    display: grid;
    gap: 3px;
    font-size: 0.82rem;
    color: var(--muted);
}
.appt-meta b { color: var(--ink); font-weight: 700; }
.appt-status {
    justify-self: start;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 4px 9px;
    border-radius: 999px;
}
.st-pendente { background: #FEF3C7; color: #92400E; }
.st-confirmado { background: #DBEAFE; color: #1E40AF; }
.st-na_recepcao { background: #E0E7FF; color: #3730A3; }
.st-em_atendimento { background: #D1FAE5; color: #065F46; }
.st-concluido { background: #E5E7EB; color: #374151; }
.st-cancelado { background: #FEE2E2; color: #991B1B; }

/* ——— Legado ——— */
.painel-legado {
    background: #fff;
    border: 1px solid #f0b4b4;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    gap: 0;
}
.legado-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    padding: 22px;
    background:
        linear-gradient(135deg, rgba(198, 40, 40, 0.08), transparent 55%),
        #fff;
    border-bottom: 1px solid var(--line);
}
.legado-head h2 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-top: 2px;
}
.legado-desc {
    color: var(--muted);
    font-size: 0.9rem;
    margin-top: 8px;
    max-width: 60ch;
}
.legado-count {
    font-size: clamp(1.8rem, 3vw, 2.4rem);
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
    background: var(--primary-light);
    border-radius: 16px;
    min-width: 64px;
    text-align: center;
    padding: 14px 16px;
}
.legado-table-wrap {
    overflow: auto;
    max-height: min(70vh, 640px);
}
.legado-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
    min-width: 980px;
}
.legado-table th,
.legado-table td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.legado-table th {
    position: sticky;
    top: 0;
    background: #fafbfc;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    z-index: 1;
}
.legado-table tr:hover td { background: #fff8f8; }
.legado-empty {
    padding: 28px;
    text-align: center;
    color: var(--muted);
    font-weight: 650;
}

.painel-foot {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 18px var(--pad) 28px;
    color: var(--muted);
    font-size: 0.82rem;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.75);
}
.painel-foot a { color: var(--primary); font-weight: 700; }

/* —— Mobile —— */
@media (max-width: 1100px) {
    .hoje-kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .hkpi-main { grid-column: 1 / -1; }
    .hoje-split { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .painel-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi:last-child { grid-column: 1 / -1; }
    .painel-charts { grid-template-columns: 1fr; }
    .chart-donut-wrap { grid-template-columns: 120px 1fr; }
    .painel-top { flex-direction: column; align-items: flex-start; }
    .bar-row { grid-template-columns: 1fr; gap: 4px; }
    .filter-tabs { width: 100%; border-radius: 16px; }
    .filter-search { width: 100%; justify-content: stretch; }
    .filter-search input,
    .filter-search select { width: 100%; min-width: 0; }
    .sec-hoje { padding: 16px; }
    .fila-item { grid-template-columns: 64px 1fr; }
    .fila-item .appt-status { grid-column: 2; justify-self: start; }
}
@media (max-width: 560px) {
    .hoje-kpi-grid { grid-template-columns: 1fr 1fr; }
    .painel-kpis { grid-template-columns: 1fr 1fr; }
    .appt-grid { grid-template-columns: 1fr; }
    .legado-head { flex-direction: column; }
}

/* —— Smart TV —— */
@media (min-width: 1600px) and (min-height: 900px) {
    :root {
        --pad: 48px;
        --kpi-size: 3rem;
        --title-size: 2.35rem;
        --radius: 22px;
    }
    body.painel-body { font-size: 18px; }
    .painel-brand img { height: 58px; }
    .fila-hora { font-size: 1.4rem; }
    .appt-time { font-size: 1.7rem; }
}
body.tv-mode {
    --pad: 56px;
    --kpi-size: 3.4rem;
    --title-size: 2.6rem;
    font-size: 20px;
}
body.tv-mode .appt-grid {
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
}
body.tv-mode .hoje-fila { max-height: 520px; }
