:root {
    --bg: #eef2f5;
    --panel: #ffffff;
    --panel-soft: #f7f9fb;
    --text: #152126;
    --muted: #66777f;
    --line: #dce5e9;
    --green: #15b884;
    --green-dark: #08785b;
    --green-soft: #e8f8f2;
    --teal: #2f706d;
    --blue: #2d73d5;
    --blue-soft: #eef4ff;
    --red: #e15261;
    --red-soft: #fff0f2;
    --yellow: #d69a1f;
    --yellow-soft: #fff7e5;
    --orange: #d97820;
    --purple: #7b55d9;
    --shadow: 0 10px 30px rgba(29, 49, 58, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: Inter, Segoe UI, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}
button { font: inherit; }
.hidden { display: none !important; }
.app-shell { min-height: 100vh; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 17px 28px;
    background: linear-gradient(112deg, #263236, #465155);
    color: #fff;
    box-shadow: 0 5px 22px rgba(0,0,0,.16);
}
.brand-block { display: flex; align-items: center; gap: 14px; }
.brand-mark {
    width: 56px; height: 56px; border-radius: 15px;
    display: grid; place-items: center;
    font-weight: 950; letter-spacing: -2px;
    color: #ddfff4;
    background: linear-gradient(135deg, #11b17e, #135948);
    border: 1px solid rgba(255,255,255,.28);
}
h1 { margin: 0; font-size: 24px; letter-spacing: -.45px; }
.brand-block p { margin: 4px 0 0; color: #d7dfe2; font-size: 13px; }
.header-actions { display: flex; gap: 15px; align-items: center; }
.update-meta { display: flex; align-items: center; gap: 9px; min-width: 190px; }
.update-meta small { display: block; color: #cbd4d7; font-size: 11px; }
.update-meta strong { display: block; margin-top: 2px; font-size: 13px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #aab3b7; box-shadow: 0 0 0 4px rgba(255,255,255,.06); }
.status-dot.ok { background: #31d99a; box-shadow: 0 0 0 4px rgba(49,217,154,.15); }
.status-dot.loading { background: #f5bd4f; animation: pulse 1s infinite; }
.status-dot.error { background: #ff6374; }
@keyframes pulse { 50% { opacity: .45; } }

.btn { border: 0; border-radius: 12px; padding: 11px 16px; cursor: pointer; font-weight: 800; transition: .18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .6; cursor: wait; transform: none; }
.btn-primary { background: #17be88; color: #fff; box-shadow: 0 7px 18px rgba(23,190,136,.25); }
.btn-soft { background: var(--green-soft); color: var(--green-dark); }
.btn-ghost { background: #eef3f5; color: #40535b; }

.tabs {
    display: flex; gap: 8px; padding: 14px 28px 0;
    position: sticky; top: 90px; z-index: 20;
    background: var(--bg);
}
.tab { border: 0; padding: 10px 16px; border-radius: 11px 11px 0 0; background: transparent; color: var(--muted); font-weight: 900; cursor: pointer; }
.tab.active { background: var(--panel); color: var(--green-dark); box-shadow: 0 -3px 10px rgba(20,50,60,.04); }
main { padding: 0 28px 38px; }

.empty-state {
    max-width: 780px; margin: 60px auto; padding: 42px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
    text-align: center; box-shadow: var(--shadow);
}
.empty-icon { width: 72px; height: 72px; display: grid; place-items: center; margin: 0 auto 16px; border-radius: 50%; background: var(--green-soft); color: var(--green-dark); font-size: 34px; }
.empty-state h2 { margin: 0 0 10px; }
.empty-state p { color: var(--muted); line-height: 1.55; }
.rule-pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 20px; }
.rule-pills span { padding: 8px 11px; border-radius: 999px; background: var(--panel-soft); border: 1px solid var(--line); color: #4d5f67; font-size: 12px; }
.error-box { background: var(--red-soft); border: 1px solid #f2c1c7; color: #8a3340; padding: 14px; border-radius: 12px; margin-top: 18px; white-space: pre-wrap; text-align: left; }

.view-panel { display: none; padding-top: 18px; }
.view-panel.active { display: block; }
.section-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin: 2px 0 13px; }
.section-head h2 { margin: 0; font-size: 22px; }
.section-head p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.section-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cutoff-badge { background: #e6ecee; color: #42535a; padding: 8px 11px; border-radius: 999px; font-size: 12px; font-weight: 800; }

.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-height: 118px; overflow: hidden; position: relative; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: #cfd9dd; }
.kpi.accent-green::before { background: var(--green); }
.kpi.accent-blue::before { background: var(--blue); }
.kpi.accent-purple::before { background: var(--purple); }
.kpi.accent-yellow::before { background: var(--yellow); }
.kpi.accent-red::before { background: var(--red); }
.kpi .label { color: var(--muted); font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: .58px; }
.kpi .value { margin-top: 8px; font-size: 29px; font-weight: 950; letter-spacing: -.8px; line-height: 1.05; }
.kpi .sub { margin-top: 8px; font-size: 11px; color: var(--muted); line-height: 1.35; }
.delta { display: inline-flex; align-items: center; gap: 4px; font-weight: 900; }
.delta.pos { color: var(--green-dark); }
.delta.neg { color: var(--red); }
.delta.neutral { color: var(--yellow); }

.super-strip { margin-top: 14px; display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 10px; }
.super-stat { background: linear-gradient(160deg, #263236, #3d4b50); color: #fff; border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.super-stat span { display: block; color: #cdd9dc; font-size: 10px; text-transform: uppercase; font-weight: 850; letter-spacing: .5px; }
.super-stat strong { display: block; font-size: 24px; margin-top: 7px; letter-spacing: -.5px; }
.super-stat small { display: block; margin-top: 5px; color: #b9c6ca; font-size: 10px; }

.unit-cards { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; margin-top: 14px; }
.unit-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.unit-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.unit-title h3 { margin: 0; font-size: 17px; }
.light { width: 10px; height: 10px; border-radius: 50%; }
.light.green { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.light.yellow { background: #e1a729; box-shadow: 0 0 0 4px var(--yellow-soft); }
.light.red { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.unit-main { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 15px 0; }
.metric-mini { background: var(--panel-soft); border: 1px solid #e8edef; border-radius: 12px; padding: 10px 12px; }
.metric-mini span { display: block; color: var(--muted); font-size: 10px; }
.metric-mini strong { display: block; margin-top: 4px; font-size: 19px; }
.unit-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }

.content-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 14px; margin-top: 14px; }
.content-grid.equal { grid-template-columns: 1fr 1fr; }
.content-grid.wide-narrow { grid-template-columns: 1.4fr .6fr; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px; box-shadow: var(--shadow); min-width: 0; }
.panel h3 { margin: 0; font-size: 16px; }
.panel-sub { color: var(--muted); font-size: 11px; margin-top: 4px; line-height: 1.45; }
.panel-actions { display: flex; gap: 8px; align-items: center; }

.subsection-title { display: flex; justify-content: space-between; gap: 12px; align-items: end; margin: 24px 0 10px; }
.subsection-title h2 { margin: 0; font-size: 20px; }
.subsection-title p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.subsection-tag { background: #e8f8f2; color: var(--green-dark); padding: 7px 10px; border-radius: 999px; font-size: 10px; font-weight: 900; letter-spacing: .4px; }

.table-wrap { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th { text-align: left; color: var(--muted); background: var(--panel-soft); padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid #edf1f3; white-space: nowrap; }
tbody tr:hover { background: #fafcfd; }
tr.clickable { cursor: pointer; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px; border-radius: 999px; font-size: 9px; font-weight: 900; }
.status-pill.pause { background: var(--yellow-soft); color: #8a620d; }
.status-pill.ok { background: var(--green-soft); color: var(--green-dark); }
.status-pill.warn { background: var(--red-soft); color: #a03a49; }

.state-bars { margin-top: 15px; display: grid; gap: 11px; }
.state-row { display: grid; grid-template-columns: 145px 1fr 98px; gap: 10px; align-items: center; font-size: 11px; }
.state-name { color: #425159; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 11px; border-radius: 999px; background: #edf2f4; overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #18bf89, #2e706d); }
.bar-fill.blue { background: linear-gradient(90deg, #4b8ae9, #275eb3); }
.bar-fill.orange { background: linear-gradient(90deg, #efaa48, #d97820); }
.state-value { text-align: right; font-weight: 900; }

.svg-chart { width: 100%; height: 245px; margin-top: 10px; display: block; }
.chart-legend { display: flex; gap: 16px; align-items: center; margin-top: 4px; color: var(--muted); font-size: 10px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.legend-dot.today { background: var(--green); }
.legend-dot.yesterday { background: var(--teal); }

.insights { display: grid; gap: 9px; margin-top: 12px; }
.insight { border-radius: 12px; padding: 11px 12px; border-left: 4px solid; background: var(--panel-soft); }
.insight strong { display: block; font-size: 11px; }
.insight span { display: block; color: #55656c; margin-top: 4px; font-size: 11px; line-height: 1.45; }
.insight.success { border-color: var(--green); background: var(--green-soft); }
.insight.info { border-color: var(--blue); background: var(--blue-soft); }
.insight.warning { border-color: var(--yellow); background: var(--yellow-soft); }
.insight.danger { border-color: var(--red); background: var(--red-soft); }

.progress-sla { display: flex; align-items: center; gap: 16px; margin-top: 14px; }
.sla-ring { --p: 0; width: 118px; height: 118px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--green) calc(var(--p) * 1%), #e7edef 0); position: relative; flex: 0 0 auto; }
.sla-ring::after { content: ''; position: absolute; width: 82px; height: 82px; background: #fff; border-radius: 50%; }
.sla-ring strong { position: relative; z-index: 1; font-size: 22px; }
.sla-detail { flex: 1; }
.sla-detail .line { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid #eef2f4; font-size: 11px; }

/* Podio ejecutivo */
.ranking-panel { overflow: hidden; }
.ranking-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.ranking-tag { display: inline-flex; align-items: center; justify-content: center; padding: 7px 10px; border-radius: 999px; background: #e8faf4; color: #087b5b; font-size: 10px; font-weight: 950; letter-spacing: .4px; }
.podium { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); align-items: end; gap: 12px; margin-top: 18px; }
.podium-card { position: relative; border: 1px solid #e2e9ec; border-radius: 18px 18px 10px 10px; padding: 18px 14px 14px; text-align: center; background: linear-gradient(180deg,#fff,#f8fbfc); min-height: 192px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; box-shadow: 0 8px 24px rgba(26,48,58,.07); }
.podium-card.rank-1 { min-height: 225px; border-color: #e9cf71; background: linear-gradient(180deg,#fffdf3,#fff9dc); box-shadow: 0 10px 28px rgba(165,127,10,.13); }
.podium-card.rank-2 { background: linear-gradient(180deg,#fff,#f2f6f8); }
.podium-card.rank-3 { background: linear-gradient(180deg,#fffaf6,#f9eee4); }
.medal { font-size: 29px; line-height: 1; margin-bottom: 4px; }
.podium-rank { position: absolute; top: 10px; right: 12px; font-size: 29px; font-weight: 950; color: #d0d7da; }
.rank-1 .podium-rank { color: #d5a600; font-size: 36px; }
.podium-name { width: 100%; font-size: 12px; font-weight: 950; color: #24343b; margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.podium-sede { font-size: 9px; color: #74858c; margin-top: 4px; min-height: 13px; }
.podium-score { margin-top: 12px; font-size: 34px; font-weight: 950; line-height: 1; letter-spacing: -1px; color: #0d8f69; }
.rank-1 .podium-score { font-size: 42px; color: #9d7600; }
.podium-score-label { margin-top: 4px; font-size: 9px; text-transform: uppercase; color: #7a8a90; font-weight: 900; letter-spacing: .45px; }
.podium-metrics { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 13px; }
.podium-metrics span { border-radius: 9px; background: rgba(255,255,255,.78); border: 1px solid rgba(220,228,231,.85); padding: 7px 5px; font-size: 9px; color: #748188; }
.podium-metrics b { display: block; margin-top: 2px; color: #26363c; font-size: 11px; }
.ranking-list { margin-top: 14px; border-top: 1px solid #e8edef; }
.ranking-row { display: grid; grid-template-columns: 38px minmax(180px,1fr) 105px 105px 100px; gap: 9px; align-items: center; padding: 10px 4px; border-bottom: 1px solid #edf1f3; }
.ranking-row:hover { background: #f8fbfb; }
.ranking-pos { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: #eef3f5; font-weight: 950; color: #53656d; }
.ranking-person { min-width: 0; }
.ranking-person strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
.ranking-person small { display: block; color: #839198; margin-top: 3px; font-size: 9px; }
.ranking-metric { text-align: right; }
.ranking-metric span { display: block; color: #849198; font-size: 8px; text-transform: uppercase; letter-spacing: .35px; }
.ranking-metric b { display: block; margin-top: 2px; font-size: 11px; }

/* Productividad */
.productivity-grid { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 10px; margin-top: 12px; }
.productivity-card { background: linear-gradient(160deg,#fff,#f7fafb); border: 1px solid var(--line); border-radius: 15px; padding: 14px; }
.productivity-card span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; font-weight: 900; letter-spacing: .45px; }
.productivity-card strong { display: block; margin-top: 7px; font-size: 23px; }
.productivity-card small { display: block; color: #89979d; margin-top: 5px; font-size: 9px; }

.pause-open { color: #8f650d; font-weight: 900; }
.anomaly { color: #a33c49; font-weight: 900; }
.good { color: var(--green-dark); font-weight: 900; }

/* Modal asesor */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(17,26,30,.48); display: grid; place-items: center; padding: 22px; backdrop-filter: blur(3px); }
.modal-card { width: min(880px, 96vw); max-height: 90vh; overflow: auto; background: #fff; border-radius: 22px; box-shadow: 0 30px 80px rgba(0,0,0,.28); padding: 24px; position: relative; }
.modal-close { position: absolute; top: 12px; right: 14px; border: 0; width: 34px; height: 34px; border-radius: 50%; background: #edf2f4; cursor: pointer; font-size: 22px; line-height: 1; }
.agent-hero { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; padding-right: 40px; }
.agent-hero h2 { margin: 0; font-size: 23px; }
.agent-hero p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.agent-ext { background: #253338; color: #fff; border-radius: 12px; padding: 10px 13px; font-weight: 900; }
.agent-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; margin-top: 18px; }
.agent-stat { border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: #fbfcfd; }
.agent-stat span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; font-weight: 900; }
.agent-stat strong { display: block; margin-top: 5px; font-size: 18px; }
.agent-note { margin-top: 16px; padding: 12px; border-radius: 12px; background: #f3f7f8; color: #56666d; font-size: 11px; line-height: 1.5; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 150; background: #202d32; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1300px) {
    .kpi-grid, .super-strip, .productivity-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 950px) {
    .content-grid, .content-grid.equal, .content-grid.wide-narrow, .unit-cards { grid-template-columns: 1fr; }
    .podium { grid-template-columns: 1fr; align-items: stretch; }
    .podium-card, .podium-card.rank-1 { min-height: auto; }
    .ranking-row { grid-template-columns: 34px minmax(130px,1fr) 88px; }
    .ranking-row .ranking-metric:nth-last-child(-n+2) { display: none; }
}
@media (max-width: 760px) {
    .topbar { position: static; flex-direction: column; align-items: stretch; }
    .header-actions { justify-content: space-between; }
    .tabs { position: static; overflow-x: auto; padding-left: 14px; padding-right: 14px; }
    main { padding-left: 14px; padding-right: 14px; }
    .kpi-grid, .super-strip, .productivity-grid { grid-template-columns: 1fr 1fr; }
    .state-row { grid-template-columns: 112px 1fr 78px; }
    .agent-grid { grid-template-columns: 1fr 1fr; }
}
