/* ============================================
   LA AREPERIA - DASHBOARD STYLES
   ============================================ */

:root {
    /* Brand */
    --primary: #D97706;
    --primary-light: #FEF3C7;
    --primary-dark: #92400E;
    --primary-hover: #B45309;

    /* Neutrals */
    --bg: #F1F5F9;
    --card-bg: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;
    --border: #E2E8F0;
    --border-light: #F1F5F9;

    /* Sede Colors */
    --novena: #3B82F6;
    --novena-light: #DBEAFE;
    --parque: #10B981;
    --parque-light: #D1FAE5;
    --bulevar: #F59E0B;
    --bulevar-light: #FEF3C7;
    --homecenter: #EF4444;
    --homecenter-light: #FEE2E2;

    /* Functional */
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;

    /* Layout */
    --header-h: 64px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
    --transition: 0.2s ease;
}

/* ---- Dark Mode ---- */
[data-theme="dark"] {
    --bg: #0f172a;
    --card-bg: #1e293b;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --border-light: #1e293b;
    --primary-light: #422006;
    --novena-light: #1e3a5f;
    --parque-light: #064e3b;
    --homecenter-light: #450a0a;
    --bulevar-light: #422006;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -1px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.5), 0 4px 6px -2px rgba(0,0,0,0.3);
}

/* ---- Theme Toggle ---- */
.theme-toggle {
    width: 36px;
    height: 36px;
    background: var(--border-light);
    color: var(--text-secondary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.theme-toggle:hover {
    background: var(--border);
    color: var(--text);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    transition: background 0.3s, color 0.3s;
}

/* ---- Header ---- */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    padding: 0 24px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: 1px;
    flex-shrink: 0;
}

.header-titles h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 400;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background var(--transition);
}

.status-dot.connected { background: var(--success); box-shadow: 0 0 6px rgba(16,185,129,0.4); }
.status-dot.error { background: var(--danger); }

.last-update {
    font-size: 12px;
    color: var(--text-muted);
    display: none;
}

@media (min-width: 768px) {
    .last-update { display: inline; }
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: all var(--transition);
    border-radius: var(--radius-sm);
}

.btn-icon {
    width: 36px;
    height: 36px;
    background: var(--border-light);
    color: var(--text-secondary);
    font-size: 18px;
    border-radius: 8px;
}

.btn-icon:hover {
    background: var(--border);
    color: var(--text);
}

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

.btn-primary {
    background: var(--primary);
    color: white;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: var(--radius-sm);
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
    background: var(--border-light);
    color: var(--text);
    padding: 10px 20px;
    font-size: 14px;
    border-radius: var(--radius-sm);
}
.btn-secondary:hover { background: var(--border); }

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: var(--border-light);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.btn-action:hover { background: var(--border); color: var(--text); }
.btn-action svg { flex-shrink: 0; }
.btn-action-text { white-space: nowrap; }

.btn-send { background: #EFF6FF; color: #3B82F6; border-color: #BFDBFE; }
.btn-send:hover { background: #DBEAFE; color: #2563EB; }

.btn-action.generating {
    pointer-events: none;
    opacity: 0.6;
}

@media (max-width: 600px) {
    .btn-action-text { display: none; }
    .btn-action { padding: 8px; }
}

.btn-icon.refreshing svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---- Modal ---- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.hidden { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 440px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.modal-content h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}

.modal-content > p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.form-group {
    text-align: left;
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition);
    resize: vertical;
    background: var(--card-bg);
    color: var(--text);
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
}

.form-hint {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}
.modal-actions .btn { flex: 1; }

.send-status {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    text-align: center;
}
.send-status.success { background: #D1FAE5; color: #065F46; }
.send-status.error { background: #FEE2E2; color: #991B1B; }
.send-status.loading { background: #FEF3C7; color: #92400E; }

/* ---- Main ---- */
.main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* ---- Loading ---- */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-secondary);
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading p {
    font-size: 14px;
}

/* ---- Error ---- */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    gap: 16px;
    text-align: center;
}

.error-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--homecenter-light);
    color: var(--danger);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 24px;
}

.error-state p {
    color: var(--text-secondary);
    font-size: 14px;
    max-width: 400px;
}

/* ---- Hidden utility ---- */
.hidden { display: none !important; }

/* ---- Period Bar ---- */
.period-bar {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.period-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card-bg);
    padding: 8px 16px;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    border: 1px solid var(--border);
}

.period-icon {
    font-size: 14px;
}

/* ---- Filters Bar ---- */
.filters-bar {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.filter-buttons {
    display: flex;
    gap: 4px;
    background: var(--card-bg);
    padding: 3px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.filter-btn:hover {
    background: var(--border-light);
    color: var(--text);
}

.filter-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 3px rgba(217, 119, 6, 0.3);
}

.filter-btn .sede-dot {
    width: 8px;
    height: 8px;
    border-radius: 3px;
    flex-shrink: 0;
}

.filter-btn.active .sede-dot {
    box-shadow: 0 0 0 2px rgba(255,255,255,0.5);
}

/* Sede-specific active states */
.filter-btn[data-sede="NOVENA"].active { background: var(--novena); box-shadow: 0 1px 3px rgba(59,130,246,0.3); }
.filter-btn[data-sede="PARQUE"].active { background: var(--parque); box-shadow: 0 1px 3px rgba(16,185,129,0.3); }
.filter-btn[data-sede="BULEVAR"].active { background: var(--bulevar); box-shadow: 0 1px 3px rgba(245,158,11,0.3); }
.filter-btn[data-sede="HOMECENTER"].active { background: var(--homecenter); box-shadow: 0 1px 3px rgba(239,68,68,0.3); }

@media (max-width: 600px) {
    .filters-bar { flex-direction: column; align-items: stretch; }
    .filter-group { flex-direction: column; align-items: flex-start; gap: 6px; }
    .filter-buttons { width: 100%; }
    .filter-btn { flex: 1; justify-content: center; }
}

/* ---- KPI Grid ---- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

@media (max-width: 1024px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
}

.kpi-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border-left: 4px solid transparent;
    transition: transform var(--transition), box-shadow var(--transition);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-ventas { border-left-color: var(--primary); }
.kpi-tickets { border-left-color: var(--novena); }
.kpi-promedio { border-left-color: var(--parque); }
.kpi-plataformas { border-left-color: var(--homecenter); }

.kpi-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.kpi-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.kpi-icon-circle {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.kpi-ventas .kpi-icon-circle { background: var(--primary-light); color: var(--primary); }
.kpi-tickets .kpi-icon-circle { background: var(--novena-light); color: var(--novena); }
.kpi-promedio .kpi-icon-circle { background: var(--parque-light); color: var(--parque); }
.kpi-plataformas .kpi-icon-circle { background: var(--homecenter-light); color: var(--homecenter); }

.kpi-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.kpi-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ---- Cards ---- */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

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

/* ---- Badge ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 600;
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary-dark);
}

/* ---- Progress Card ---- */

.progress-bar-container {
    margin-bottom: 12px;
}

.progress-bar {
    height: 12px;
    background: var(--border-light);
    border-radius: 100px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #F59E0B);
    border-radius: 100px;
    transition: width 1s ease;
    min-width: 0;
}

.progress-info {
    display: flex;
    justify-content: space-between;
}

.progress-stat {
    display: flex;
    flex-direction: column;
}

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

.progress-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

/* ---- Chart Cards ---- */
.chart-container {
    position: relative;
    width: 100%;
}

.chart-lg { height: 340px; }
.chart-md { height: 300px; }

/* Chart.js manages canvas sizing internally via responsive:true.
   Container dimensions (.chart-lg, .chart-md) control the chart size. */

.charts-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 768px) {
    .charts-two-col { grid-template-columns: 1fr; }
}

/* ---- Tables ---- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: var(--border-light);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: var(--border-light);
}

.data-table tfoot td {
    font-weight: 700;
    border-top: 2px solid var(--border);
    background: var(--border-light);
}

.text-right { text-align: right; }

.sede-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.sede-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

.sede-dot.novena { background: var(--novena); }
.sede-dot.parque { background: var(--parque); }
.sede-dot.bulevar { background: var(--bulevar); }
.sede-dot.homecenter { background: var(--homecenter); }

/* ---- Footer ---- */
.footer {
    text-align: center;
    padding: 24px 20px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 20px;
}

/* ---- Animations ---- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.dashboard > * {
    animation: fadeIn 0.4s ease forwards;
}

.dashboard > *:nth-child(1) { animation-delay: 0s; }
.dashboard > *:nth-child(2) { animation-delay: 0.05s; }
.dashboard > *:nth-child(3) { animation-delay: 0.1s; }
.dashboard > *:nth-child(4) { animation-delay: 0.15s; }
.dashboard > *:nth-child(5) { animation-delay: 0.2s; }
.dashboard > *:nth-child(6) { animation-delay: 0.25s; }
.dashboard > *:nth-child(7) { animation-delay: 0.3s; }
.dashboard > *:nth-child(8) { animation-delay: 0.35s; }
.dashboard > *:nth-child(9) { animation-delay: 0.4s; }
.dashboard > *:nth-child(10) { animation-delay: 0.45s; }

/* ---- Print styles ---- */
@media print {
    .header { position: static; }
    .btn-icon, .connection-status, .last-update { display: none; }
    .card { break-inside: avoid; box-shadow: none; border: 1px solid var(--border); }
    body { background: white; }
}
