:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222535;
  --border: #2e3150;
  --text: #e8eaf0;
  --muted: #8b90a8;
  --cs: #3b82f6;
  --cs-light: rgba(59,130,246,0.15);
  --ritz: #DC2626;
  --ritz-light: rgba(220,38,38,0.18);
  --co: #7C3AED;
  --ec: #A855F7;
  --pe: #D946EF;
  --cl: #9333EA;
  --green: #2ecc71;
  --yellow: #f1c40f;
  --red: #e74c3c;
  --purple: #9b59b6;
  --teal: #1abc9c;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; line-height: 1.5; }

/* HEADER */
.header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.header-left { display: flex; align-items: center; gap: 14px; }
.header-logo { width: 36px; height: 36px; background: #7B1FA2; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; font-size: 16px; }
.header-title h1 { font-size: 17px; font-weight: 700; color: var(--text); }
.header-title p { font-size: 12px; color: var(--muted); }
.header-meta { font-size: 12px; color: var(--muted); text-align: right; }

/* BRAND SELECTOR */
.brand-bar { background: var(--surface2); border-bottom: 1px solid var(--border); padding: 10px 24px; display: flex; align-items: center; gap: 10px; }
.brand-label { font-size: 12px; color: var(--muted); margin-right: 6px; }
.brand-btn { padding: 6px 18px; border-radius: 20px; border: 2px solid var(--border); background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 600; transition: all .2s; }
.brand-btn.active-cs { border-color: var(--cs); background: var(--cs-light); color: var(--cs); }
.brand-btn.active-ritz { border-color: var(--ritz); background: var(--ritz-light); color: #ef4444; }
.brand-btn.active-compare { border-color: #8B5CF6; background: rgba(139,92,246,0.15); color: #a78bfa; }
.brand-btn:hover:not(.active-cs):not(.active-ritz) { border-color: var(--muted); color: var(--text); }

/* LAYOUT */
.content { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* KPI CARDS */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; position: relative; overflow: hidden; }
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.kpi-card.co::before { background: var(--co); }
.kpi-card.ec::before { background: var(--ec); }
.kpi-card.pe::before { background: var(--pe); }
.kpi-card.cl::before { background: var(--cl); }
.kpi-country { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.kpi-flag { font-size: 20px; }
.kpi-country-name { font-size: 14px; font-weight: 700; }
.kpi-row { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.kpi-label { font-size: 11px; color: var(--muted); }
.kpi-value { font-size: 22px; font-weight: 800; line-height: 1; }
.kpi-value.accent-cs { color: var(--cs); }
.kpi-value.accent-ritz { color: #ef4444; }
.kpi-value.accent-neutral { color: var(--text); }
.kpi-divider { height: 1px; background: var(--border); margin: 10px 0; }
.kpi-sub { display: flex; justify-content: space-between; margin-bottom: 6px; }
.kpi-sub-label { font-size: 11px; color: var(--muted); }
.kpi-sub-value { font-size: 12px; font-weight: 700; }
.mini-bar-bg { background: var(--border); border-radius: 3px; height: 5px; margin-top: 3px; }
.mini-bar { height: 5px; border-radius: 3px; }

/* KPI 2026 vs 2024 COMPARISON */
.kpi-cmp-header { display: grid; grid-template-columns: 1fr 52px 40px 34px; align-items: center; margin-bottom: 8px; }
.kpi-cmp-hyr { font-size: 10px; color: var(--muted); text-align: right; }
.kpi-cmp-hyr26 { color: var(--text); font-weight: 700; }
.kpi-cmp-row { display: grid; grid-template-columns: 1fr 52px 40px 34px; align-items: center; margin-bottom: 8px; }
.kpi-cmp-label { font-size: 11px; color: var(--muted); line-height: 1.3; }
.kpi-cmp-26 { font-size: 18px; font-weight: 800; text-align: right; line-height: 1; }
.kpi-cmp-24 { font-size: 11px; color: var(--muted); text-align: right; }
.kpi-delta { font-size: 11px; font-weight: 700; text-align: right; }
.kpi-delta-pos { color: #66BB6A; }
.kpi-delta-neg { color: #ef4444; }
.kpi-delta-n { color: var(--muted); }

/* CHART GRID */
.chart-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.chart-card-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.chart-card-sub { font-size: 11px; color: var(--muted); margin-bottom: 16px; }
.chart-wrap { position: relative; }

/* BARRIER SECTION */
.barrier-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.barrier-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.barrier-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.country-pill { padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 700; }
.pill-co { background: rgba(124,58,237,0.15); color: var(--co); }
.pill-ec { background: rgba(168,85,247,0.15); color: var(--ec); }
.pill-pe { background: rgba(217,70,239,0.15); color: var(--pe); }
.pill-cl { background: rgba(147,51,234,0.15); color: var(--cl); }
.barrier-title { font-size: 13px; font-weight: 700; }
.barrier-row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.barrier-cat { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.barrier-text { font-size: 11px; color: var(--text); flex: 1; line-height: 1.3; }
.barrier-pct { font-size: 12px; font-weight: 700; min-width: 36px; text-align: right; }
.barrier-bar-bg { flex: 1; background: var(--border); border-radius: 3px; height: 5px; }
.barrier-bar { height: 5px; border-radius: 3px; }
.cat-precio { background: #26C6DA; }
.cat-salud { background: #66BB6A; }
.cat-disponib { background: #FFCA28; }
.cat-marca { background: #8BC34A; }
.cat-producto { background: #FF9800; }

/* LEGEND */
.legend-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 2px; }

/* COMPARATIVE TABLE */
.compare-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.compare-table th { text-align: left; font-size: 11px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.compare-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 12px; }
.compare-table tr:hover td { background: var(--surface2); }
.compare-table .metric-name { font-weight: 600; color: var(--text); }
.compare-table .metric-cat { font-size: 10px; color: var(--muted); }
.td-bar-wrap { display: flex; align-items: center; gap: 6px; }
.td-bar-bg { width: 80px; background: var(--border); border-radius: 3px; height: 6px; }
.td-bar-fill { height: 6px; border-radius: 3px; }
.td-val { font-weight: 700; font-size: 12px; min-width: 36px; }

/* INSIGHT CARDS */
.insight-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.insight-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.insight-icon { font-size: 22px; margin-bottom: 6px; }
.insight-title { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.insight-text { font-size: 11px; color: var(--muted); line-height: 1.5; }

/* TABS WITHIN SECTION */
.inner-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.inner-tab { padding: 5px 14px; border-radius: 16px; border: 1px solid var(--border); background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 600; transition: all .2s; }
.inner-tab.active { background: var(--surface2); color: var(--text); border-color: var(--muted); }

.hidden { display: none !important; }

/* PENETRACIÓN DETAIL ACCORDION */
.penet-summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.penet-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; cursor: pointer; transition: border-color .2s, background .2s; user-select: none; }
.penet-card:hover { border-color: var(--muted); background: var(--surface2); }
.penet-card.expanded { border-color: var(--muted); border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom-color: var(--surface); }
.penet-card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.penet-card-flag { font-size: 24px; }
.penet-card-chevron { color: var(--muted); font-size: 11px; margin-top: 4px; transition: transform .25s; }
.penet-card.expanded .penet-card-chevron { transform: rotate(180deg); }
.penet-card-name { font-size: 13px; font-weight: 700; margin: 8px 0 4px; }
.penet-card-pct { font-size: 32px; font-weight: 800; line-height: 1; }
.penet-card-sublabel { font-size: 10px; color: var(--muted); margin-top: 4px; }
.penet-pct-compare { display: flex; align-items: center; gap: 12px; margin: 6px 0 4px; }
.penet-pct-col { display: flex; flex-direction: column; }
.penet-pct-sep { width: 1px; height: 38px; background: var(--border); flex-shrink: 0; }
.penet-pct-yr { font-size: 10px; color: var(--muted); margin-top: 3px; }
.penet-pct-prev { font-size: 24px !important; color: var(--muted) !important; }
.penet-pct-delta { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 10px; margin-left: auto; align-self: center; }
.penet-delta-pos { color: #66BB6A; background: rgba(102,187,106,0.12); }
.penet-delta-neg { color: #ef4444; background: rgba(239,68,68,0.12); }

.penet-detail-panel { background: var(--surface); border: 1px solid var(--muted); border-top: none; border-radius: 0 0 12px 12px; padding: 18px 20px; margin-bottom: 24px; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.pt-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.pt-header-country { font-size: 16px; font-weight: 700; }
.pt-header-sub { font-size: 12px; color: var(--muted); }
.pt-scroll { overflow-x: auto; }

.pt-table { width: 100%; border-collapse: collapse; font-size: 11px; white-space: nowrap; }
.pt-table .pt-seg   { text-align: left; padding: 6px 10px; color: var(--muted); font-size: 10px; font-weight: 700; border-bottom: 2px solid var(--border); min-width: 170px; white-space: normal; }
.pt-table .pt-total { text-align: center; padding: 6px 10px; color: var(--text); font-size: 10px; font-weight: 700; border-bottom: 2px solid var(--border); border-right: 2px solid var(--border); }
.pt-table .pt-group { text-align: center; padding: 5px 8px; background: var(--surface2); color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; border-left: 2px solid var(--border); border-bottom: 1px solid var(--border); }
.pt-table .pt-col   { text-align: center; padding: 5px 8px; color: var(--muted); font-size: 10px; font-weight: 600; border-bottom: 2px solid var(--border); }
.pt-table .pt-col.gs { border-left: 2px solid var(--border); }

.pt-table td { padding: 5px 10px; border-bottom: 1px solid var(--border); text-align: center; color: var(--text); font-size: 11px; }
.pt-table .pt-label { text-align: left; padding-left: 10px; white-space: normal; min-width: 170px; }
.pt-table .pt-total-cell { font-weight: 700; border-right: 2px solid var(--border); }
.pt-table td.gs { border-left: 2px solid var(--border); }
.pt-table .pt-base td { color: var(--muted); font-size: 10px; }
.pt-table .pt-section td { background: var(--surface2); color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; text-align: left; padding: 5px 10px; }
.pt-table tr:not(.pt-section):not(.pt-base):hover td { background: var(--surface2); }

.pt-actions { display: flex; gap: 6px; }
.pt-action-btn { padding: 4px 10px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; opacity: 0.35; transition: all .2s; }
.pt-action-btn:hover { opacity: 1; border-color: var(--muted); color: var(--text); background: var(--surface2); }
.pt-action-btn.active { opacity: 1; border-color: #3b82f6; color: #3b82f6; background: rgba(59,130,246,0.1); }
.pt-table.pt-editing td[contenteditable] { background: rgba(59,130,246,0.07); cursor: text; outline: 1px dashed var(--border); }
.pt-table.pt-editing td[contenteditable]:focus { background: rgba(59,130,246,0.15); outline: 1px solid #3b82f6; }

/* Responsive */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid-2 { grid-template-columns: 1fr; }
  .barrier-grid { grid-template-columns: 1fr; }
  .insight-grid { grid-template-columns: repeat(2, 1fr); }
}

/* THEME TOGGLE BUTTON */
.theme-btn { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface2); color: var(--text); cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: border-color .2s, transform .2s; }
.theme-btn:hover { border-color: var(--muted); transform: scale(1.12); }

/* SMOOTH THEME TRANSITIONS */
body,
.header, .brand-bar,
.kpi-card, .chart-card, .penet-card, .penet-detail-panel,
.barrier-card, .insight-card,
.brand-btn, .inner-tab, .section-title::after { transition: background-color .25s ease, border-color .25s ease, color .25s ease; }

/* LIGHT THEME OVERRIDES */
[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --cs-light: rgba(59,130,246,0.10);
  --ritz-light: rgba(220,38,38,0.08);
}
[data-theme="light"] .header { box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
[data-theme="light"] .section-title { color: #475569; }
[data-theme="light"] .pt-action-btn { opacity: 0.6; }
[data-theme="light"] .barrier-bar-bg { background: #e2e8f0; }
[data-theme="light"] .mini-bar-bg { background: #e2e8f0; }
[data-theme="light"] .kpi-divider { background: #e2e8f0; }
