/* Reset y variables */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-dark: #1e293b;
    --bg-darker: #0f172a;
    --bg-card: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #475569;
}

/* Tema claro */
body.light-mode {
    --bg-dark: #f8fafc;
    --bg-darker: #e2e8f0;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #cbd5e1;
}

body.light-mode .header {
    background: linear-gradient(135deg, #ffffff 0%, #f1f5f9 100%);
    border-bottom-color: #e2e8f0;
}

body.light-mode .header h1 {
    background: linear-gradient(135deg, var(--primary) 0%, #2563eb 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

body.light-mode .sidebar {
    background-color: #ffffff;
    border-right-color: #e2e8f0;
}

body.light-mode .filter-input {
    background-color: #f8fafc;
    border-color: #e2e8f0;
    color: #1e293b;
}

body.light-mode .filter-input:focus {
    border-color: var(--primary);
    background-color: #ffffff;
}

body.light-mode .btn-view {
    background-color: #f1f5f9;
    border-color: #e2e8f0;
    color: #475569;
}

body.light-mode .btn-view:hover {
    background-color: #e2e8f0;
}

body.light-mode .btn-view.active {
    background-color: var(--primary);
    color: white;
}

body.light-mode .stat-box {
    background-color: #f1f5f9;
    border: 1px solid #e2e8f0;
}

body.light-mode .btn-header {
    background-color: #f1f5f9;
    border-color: #e2e8f0;
}

body.light-mode .btn-header:hover {
    background-color: var(--primary);
    border-color: var(--primary);
}

body.light-mode .modal {
    background-color: #ffffff;
}

body.light-mode .modal-header {
    background-color: #f8fafc;
    border-bottom-color: #e2e8f0;
}

body.light-mode .stat-card {
    background-color: #f1f5f9;
}

body.light-mode .ventas-table th {
    background-color: #f1f5f9;
}

body.light-mode .ventas-table tr:hover {
    background-color: #f8fafc;
}

body.light-mode .producto-dropdown {
    background-color: #ffffff;
    border-color: #e2e8f0;
}

body.light-mode .producto-dropdown .producto-item:hover {
    background-color: #f1f5f9;
}

body.light-mode .map-message {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border-color: #e2e8f0;
    color: #64748b;
}

body.light-mode .toast {
    background-color: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body.light-mode #zona-stats-panel {
    background-color: #ffffff;
}

body.light-mode .zona-stat {
    background-color: #f1f5f9;
}

body.light-mode .header-farmacia {
    background-color: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.3);
}

body.light-mode .header-farmacia:hover {
    background-color: rgba(34, 197, 94, 0.2);
}

body.light-mode .config-info {
    background-color: #f1f5f9;
}

body.light-mode .resumen-card,
body.light-mode .chart-container {
    background-color: #f1f5f9;
}

body.light-mode .tab-btn {
    color: #64748b;
}

body.light-mode .tab-btn:hover {
    background-color: #f1f5f9;
    color: #1e293b;
}

body.light-mode .filter-section {
    border-bottom-color: #e2e8f0;
}

body.light-mode .filter-section h3 {
    color: #475569;
}

body.light-mode .filter-group label {
    color: #334155;
}

body.light-mode .top-list li {
    border-bottom-color: #e2e8f0;
}

body.light-mode .top-list .familia-nombre {
    color: #1e293b;
}

body.light-mode .geo-bar {
    background-color: #e2e8f0;
}

body.light-mode #geo-text {
    color: #64748b;
}

body.light-mode .zona-item {
    background-color: #f1f5f9;
}

body.light-mode .zona-item-nombre {
    color: #1e293b;
}

body.light-mode .zona-item-desc {
    color: #64748b;
}

body.light-mode .zona-item-actions button {
    color: #64748b;
}

body.light-mode .zona-item-actions button:hover {
    background-color: #e2e8f0;
}

body.light-mode .zona-empty {
    color: #64748b;
}

body.light-mode .btn-secondary {
    background-color: #f1f5f9;
    border-color: #e2e8f0;
    color: #334155;
}

body.light-mode .btn-secondary:hover {
    background-color: #e2e8f0;
}

body.light-mode .modal-header h2 {
    color: #1e293b;
}

body.light-mode .modal-body {
    color: #334155;
}

body.light-mode .cliente-datos h3 {
    color: var(--primary);
}

body.light-mode .cliente-datos p {
    color: #64748b;
}

body.light-mode .ventas-table td {
    color: #334155;
    border-bottom-color: #e2e8f0;
}

body.light-mode .zona-stats-header {
    border-bottom-color: #e2e8f0;
}

body.light-mode .zona-stats-header h4 {
    color: #1e293b;
}

body.light-mode .zona-clientes {
    background-color: #e0f2fe;
}

body.light-mode .zona-stat {
    background-color: #f1f5f9;
}

body.light-mode .zona-stat-label {
    color: #64748b;
}

body.light-mode .zona-top h5 {
    color: #64748b;
}

body.light-mode .zona-top li {
    border-bottom-color: #e2e8f0;
}

body.light-mode .zona-top .item-name {
    color: #334155;
}

body.light-mode #zona-stats-panel {
    background-color: #ffffff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

body.light-mode .analisis-stats .stat-card {
    background-color: #f1f5f9;
}

body.light-mode .analisis-stats .stat-label {
    color: #64748b;
}

body.light-mode .modal-tabs {
    border-bottom-color: #e2e8f0;
}

body.light-mode .modal-actions {
    border-top-color: #e2e8f0;
}

body.light-mode .range-inputs span {
    color: #64748b;
}

body.light-mode .spinner {
    border-color: #e2e8f0;
    border-top-color: var(--primary);
}

body.light-mode .map-loading {
    color: #64748b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-darker);
    color: var(--text);
    line-height: 1.5;
}

/* Layout principal */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-darker) 100%);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, #60a5fa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-farmacia {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background-color: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.header-farmacia:hover {
    background-color: rgba(34, 197, 94, 0.25);
    border-color: var(--success);
}

.farmacia-icon {
    color: var(--success);
    font-weight: bold;
}

.farmacia-nombre {
    font-size: 0.8rem;
    color: var(--text);
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-stats {
    display: flex;
    gap: 1rem;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 1rem;
    background-color: var(--bg-card);
    border-radius: 8px;
    min-width: 90px;
}

.stat-box .stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-box .stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-header {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background-color: var(--bg-dark);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1rem;
}

.filter-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.filter-section:last-child {
    border-bottom: none;
}

.filter-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
}

.filter-group {
    margin-bottom: 1rem;
}

.filter-group label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.filter-input {
    width: 100%;
    padding: 0.625rem;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.filter-input:focus {
    outline: none;
    border-color: var(--primary);
}

.range-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.range-inputs .filter-input {
    margin-bottom: 0;
}

.range-inputs span {
    color: var(--text-muted);
}

.filter-hint {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Botones */
.btn {
    display: inline-block;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    margin-bottom: 0.5rem;
}

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

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

.btn-secondary {
    background-color: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
}

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

.btn-warning {
    background-color: var(--warning);
    color: black;
}

.btn-warning:hover {
    background-color: #d97706;
}

.btn-info {
    background-color: #0ea5e9;
    color: white;
}

.btn-info:hover {
    background-color: #0284c7;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* View buttons */
.view-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.btn-view {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-view.active {
    background-color: var(--primary);
    border-color: var(--primary);
}

.btn-view .icon {
    font-size: 1.1rem;
}

/* Geo status */
.geo-status {
    margin-bottom: 1rem;
}

.geo-bar {
    height: 8px;
    background-color: var(--bg-card);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.geo-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    transition: width 0.3s;
}

#geo-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Top list */
.top-list {
    list-style: none;
}

.top-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.top-list li:last-child {
    border-bottom: none;
}

.top-list li.loading {
    color: var(--text-muted);
    justify-content: center;
}

.top-list .familia-nombre {
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 1rem;
}

.top-list .familia-total {
    color: var(--primary);
    font-weight: 500;
}

/* Penetración de Mercado */
.penetracion-stats {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.penetracion-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.penetracion-row:last-child {
    border-bottom: none;
}

.penetracion-label {
    color: var(--text-muted);
}

.penetracion-value {
    color: var(--text);
    font-weight: 500;
}

.penetracion-highlight {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.1), rgba(59, 130, 246, 0.05));
    margin: 0.25rem -0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 0.5rem;
    border-bottom: none;
}

.penetracion-highlight .penetracion-label {
    color: var(--primary);
    font-weight: 600;
}

.penetracion-highlight .penetracion-value {
    color: var(--primary);
    font-weight: 700;
    font-size: 1.1rem;
}

body.light-mode .penetracion-label {
    color: #64748b;
}

body.light-mode .penetracion-value {
    color: #1e293b;
}

body.light-mode .penetracion-highlight {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.05));
}

body.light-mode .penetracion-highlight .penetracion-label,
body.light-mode .penetracion-highlight .penetracion-value {
    color: #2563eb;
}

/* Ventana flotante de Penetración */
.floating-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 280px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    overflow: hidden;
    border: 1px solid var(--border);
    cursor: default;
    transition: box-shadow 0.2s;
}

.floating-panel:hover {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
}

.floating-panel.minimized .floating-panel-body {
    display: none;
}

.floating-panel.minimized {
    width: auto;
}

.floating-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: linear-gradient(135deg, var(--primary), #1d4ed8);
    color: white;
    cursor: move;
    user-select: none;
}

.floating-panel-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.floating-panel-actions {
    display: flex;
    gap: 4px;
}

.floating-panel-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.floating-panel-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.floating-panel-body {
    padding: 14px;
}

.floating-panel .penetracion-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.floating-panel .penetracion-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.floating-panel .penetracion-row:last-child {
    border-bottom: none;
}

.floating-panel .penetracion-divider {
    height: 1px;
    background: var(--border);
    margin: 8px -14px;
}

.floating-panel .penetracion-ventas {
    color: #10b981;
    font-weight: 600;
}

body.light-mode .floating-panel .penetracion-ventas {
    color: #059669;
}

.floating-panel .penetracion-renta {
    color: #f59e0b;
    font-weight: 600;
}

body.light-mode .floating-panel .penetracion-renta {
    color: #d97706;
}

.floating-panel .penetracion-highlight {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.05));
    margin: 4px -14px;
    padding: 10px 14px;
    border-radius: 0;
    border-bottom: none;
}

.floating-panel .penetracion-highlight .penetracion-value {
    font-size: 1.2rem;
    font-weight: 700;
}

body.light-mode .floating-panel {
    background: white;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

body.light-mode .floating-panel:hover {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
}

/* ========== Farmacias Cercanas Panel ========== */

.floating-panel-large {
    width: 380px;
    max-height: 70vh;
}

.farmacias-radio-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.farmacias-radio-selector label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.farmacias-radio-selector select {
    flex: 1;
    padding: 0.4rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
}

.farmacias-stats {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.farmacias-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
}

.farmacias-stat-row.farmacias-highlight {
    background: linear-gradient(135deg, var(--primary) 0%, #2563eb 100%);
    margin: -0.25rem -14px;
    padding: 0.75rem 14px;
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.farmacias-stat-row.farmacias-highlight .farmacias-stat-label,
.farmacias-stat-row.farmacias-highlight .farmacias-stat-value {
    color: white;
}

.farmacias-stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.farmacias-stat-value {
    font-weight: 600;
    color: var(--text);
}

.farmacias-divider {
    height: 1px;
    background: var(--border);
    margin: 0.75rem 0;
}

.farmacias-toggle {
    margin-bottom: 0.75rem;
}

.farmacias-lista {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.farmacia-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-darker);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.farmacia-item:hover {
    background: var(--primary);
    transform: translateX(4px);
}

.farmacia-item:hover .farmacia-nombre,
.farmacia-item:hover .farmacia-direccion,
.farmacia-item:hover .farmacia-meta {
    color: white;
}

.farmacia-rank {
    width: 24px;
    height: 24px;
    background: #ef4444;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

.farmacia-info {
    flex: 1;
    min-width: 0;
}

.farmacia-nombre {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.farmacia-direccion {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.farmacia-meta {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.farmacia-distancia {
    color: var(--primary);
    font-weight: 500;
}

.farmacia-rating {
    color: #f59e0b;
}

.farmacias-loading,
.farmacias-error,
.farmacias-empty {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

.farmacias-error {
    color: var(--danger);
}

.farmacias-cache-info {
    text-align: center;
    font-size: 0.75rem;
    padding: 0.5rem;
    margin-top: 0.5rem;
    border-radius: 4px;
}

.farmacias-cache-info.cache {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.farmacias-cache-info.fresh {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
}

.btn-small {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

/* Mapa */
.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

.map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--text-muted);
    z-index: 100;
}

.map-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 3rem;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-darker) 100%);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 1.1rem;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 50;
}

.map-loading .error {
    color: var(--danger);
    text-align: center;
    line-height: 1.8;
}

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

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

/* Info Window */
.info-window {
    padding: 0.75rem;
    min-width: 240px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.info-window h4 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: #1e293b;
}

.info-window .info-direccion {
    font-size: 0.8rem;
    color: #64748b;
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.info-window .info-stats {
    display: flex;
    gap: 1rem;
    padding: 0.5rem 0;
    border-top: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 0.75rem;
}

.info-window .info-stat {
    display: flex;
    flex-direction: column;
    flex: 1;
    text-align: center;
}

.info-window .info-stat .label {
    font-size: 0.65rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.info-window .info-stat .value {
    font-size: 0.95rem;
    font-weight: 700;
    color: #3b82f6;
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background-color: var(--bg-card);
    border-left: 4px solid var(--primary);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: var(--warning);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Modal de historial */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background-color: var(--bg-dark);
    border-radius: 12px;
    width: 90%;
    max-width: 1000px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    background-color: var(--bg-darker);
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* Cliente info en modal */
.cliente-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.cliente-datos h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: var(--primary);
}

.cliente-datos p {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.cliente-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.stat-card {
    background-color: var(--bg-card);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-card .stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Tabs en modal */
.modal-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.tab-btn {
    padding: 0.5rem 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.875rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.tab-btn:hover {
    background-color: var(--bg-card);
    color: var(--text);
}

.tab-btn.active {
    background-color: var(--primary);
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Tabla de ventas */
.ventas-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.ventas-table th,
.ventas-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.ventas-table th {
    background-color: var(--bg-card);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
}

.ventas-table tr:hover {
    background-color: var(--bg-card);
}

.ventas-table .importe {
    font-weight: 600;
    color: var(--primary);
}

/* Resumen cards */
.resumen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.resumen-card {
    background-color: var(--bg-card);
    padding: 1rem;
    border-radius: 8px;
}

.resumen-card .resumen-title {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.resumen-card .resumen-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.resumen-card .resumen-detail {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Grafico evolucion */
.chart-container {
    background-color: var(--bg-card);
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
}

.chart-container h4 {
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 120px;
}

.chart-bar {
    flex: 1;
    background: linear-gradient(to top, var(--primary), var(--primary-dark));
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    position: relative;
}

.chart-bar:hover {
    opacity: 0.8;
}

.chart-bar-label {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Venta expandible */
.venta-row {
    cursor: pointer;
}

.venta-row:hover {
    background-color: var(--bg-card);
}

.venta-productos {
    display: none;
    padding: 0.5rem 0.75rem;
    background-color: var(--bg-darker);
}

.venta-productos.expanded {
    display: table-row;
}

.producto-item {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.ver-historial-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.ver-historial-btn:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.4);
    transform: translateY(-1px);
}

/* Panel de estadísticas de zona */
#zona-stats-panel {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    background-color: var(--bg-dark);
    border-radius: 12px;
    padding: 1rem;
    min-width: 320px;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: none;
}

.zona-stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.zona-stats-header h4 {
    font-size: 1rem;
    font-weight: 600;
}

.zona-clientes {
    font-size: 0.75rem;
    color: var(--primary);
    background-color: var(--bg-card);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.zona-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.zona-stat {
    text-align: center;
    background-color: var(--bg-card);
    padding: 0.75rem;
    border-radius: 8px;
}

.zona-stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.zona-stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.zona-tops {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.zona-top h5 {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.zona-top ul {
    list-style: none;
}

.zona-top li {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--border);
}

.zona-top li:last-child {
    border-bottom: none;
}

.zona-top .item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 0.5rem;
}

.zona-top .item-value {
    color: var(--primary);
    font-weight: 500;
}

.zona-top li.empty {
    color: var(--text-muted);
    justify-content: center;
}

/* Botones de zona */
.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-success:hover {
    background-color: #16a34a;
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

/* Boton de configuracion en header */
.btn-icon {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-icon:hover {
    opacity: 1;
}

/* Modal pequeño */
.modal-small {
    max-width: 500px;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.config-info {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background-color: var(--bg-card);
    border-radius: 4px;
    color: var(--text-muted);
}

/* Toggle tema */
.theme-toggle {
    display: flex;
    align-items: center;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.toggle-label input {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

/* Busqueda de productos */
.producto-search-container {
    position: relative;
}

.producto-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.producto-dropdown .producto-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.producto-dropdown .producto-item:last-child {
    border-bottom: none;
}

.producto-dropdown .producto-item:hover {
    background-color: var(--bg-card);
}

.producto-dropdown .producto-cod {
    font-size: 0.7rem;
    color: var(--primary);
}

.producto-dropdown .producto-desc {
    font-size: 0.8rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.producto-dropdown .no-results {
    padding: 0.75rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Autocomplete dropdown para poblacion */
.autocomplete-container {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.autocomplete-dropdown.active {
    display: block;
}

.autocomplete-dropdown .autocomplete-item {
    padding: 0.6rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text);
}

.autocomplete-dropdown .autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-dropdown .autocomplete-item:hover,
.autocomplete-dropdown .autocomplete-item.selected {
    background-color: var(--primary);
    color: white;
}

.autocomplete-dropdown .autocomplete-item .highlight {
    font-weight: bold;
    color: var(--warning);
}

.autocomplete-dropdown .autocomplete-item:hover .highlight {
    color: white;
}

.autocomplete-dropdown .no-results {
    padding: 0.75rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

body.light-mode .autocomplete-dropdown {
    background-color: #ffffff;
    border-color: #e2e8f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

body.light-mode .autocomplete-dropdown .autocomplete-item:hover,
body.light-mode .autocomplete-dropdown .autocomplete-item.selected {
    background-color: var(--primary);
}

/* Estilos para desplegables de ubicación */
#provincia-select,
#poblacion-select {
    width: 100%;
}

#poblacion-hint {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* Info window farmacia */
.farmacia-info h4 {
    color: var(--success);
}

/* Lista de zonas guardadas */
.zonas-lista {
    margin-top: 0.75rem;
    max-height: 200px;
    overflow-y: auto;
}

.zona-empty {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0.5rem;
}

.zona-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background-color: var(--bg-card);
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

.zona-item-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.zona-item-info {
    flex: 1;
    min-width: 0;
}

.zona-item-nombre {
    font-size: 0.8rem;
    font-weight: 500;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.zona-item-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.zona-item-actions {
    display: flex;
    gap: 0.25rem;
}

.zona-item-actions button {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--text-muted);
    transition: all 0.2s;
}

.zona-item-actions button:hover {
    background-color: var(--bg-darker);
}

.zona-btn-ver:hover {
    color: var(--primary);
}

.zona-btn-analizar:hover {
    color: var(--success);
}

.zona-btn-eliminar:hover {
    color: var(--danger);
}

/* Modal grande */
.modal-large {
    max-width: 900px;
}

/* Estadisticas en analisis */
.analisis-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.analisis-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

/* Color input */
.filter-color {
    height: 38px;
    padding: 4px;
    cursor: pointer;
}

/* Text utilities */
.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
}

/* Dashboard - Diseño Profesional */
.dashboard-filtros {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 12px;
}

.dashboard-filtros .filtro-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.85rem;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.dashboard-filtros .filtro-tag .filtro-label {
    opacity: 0.85;
    font-weight: 400;
}

.dashboard-filtros .filtro-tag.filtro-zona {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3);
}

.dashboard-filtros .filtro-tag.filtro-cp {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    box-shadow: 0 2px 4px rgba(139, 92, 246, 0.3);
}

.dashboard-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}

.dashboard-buttons {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.dashboard-actions .btn {
    width: auto;
    margin-right: 0;
    margin-left: 0;
    padding: 0.5rem 1.25rem;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.btn-campaign {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    border: none;
}

.btn-campaign:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
}

/* Modal Campaña */
.modal-small {
    max-width: 500px;
}

.campana-info {
    text-align: center;
    padding: 1rem;
    background: var(--bg-darker);
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.campana-info p {
    margin: 0;
    font-size: 1.1rem;
}

.campana-info strong {
    font-size: 1.5rem;
    color: var(--primary);
}

.campana-form label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text);
}

.campana-form input[type="text"],
.campana-form textarea {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.95rem;
}

.campana-form input[type="text"]:focus,
.campana-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.campana-tipos {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.campana-tipo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-darker);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
    min-width: 120px;
    justify-content: center;
}

.campana-tipo:hover {
    border-color: var(--primary);
}

.campana-tipo input[type="checkbox"] {
    display: none;
}

.campana-tipo input[type="checkbox"]:checked + .tipo-icon {
    transform: scale(1.2);
}

.campana-tipo:has(input:checked) {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

.tipo-icon {
    font-size: 1.3rem;
    transition: transform 0.2s;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    margin-top: 1rem;
}

/* Buscador rápido en tablas */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
    max-width: 350px;
}

.search-box .search-icon {
    position: absolute;
    left: 12px;
    font-size: 0.9rem;
    pointer-events: none;
    opacity: 0.6;
    z-index: 1;
}

.search-box .search-input {
    width: 100%;
    padding: 0.6rem 2.5rem 0.6rem 2.5rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.search-box .search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.search-box .search-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.search-box .search-clear {
    position: absolute;
    right: 8px;
    width: 22px;
    height: 22px;
    border: none;
    background: var(--bg-darker);
    color: var(--text-muted);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.7rem;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.search-box .search-clear:hover {
    background: var(--primary);
    color: white;
}

.search-box .search-clear.visible {
    display: flex;
}

.search-box .search-input:not(:placeholder-shown) + .search-clear {
    display: flex;
}

/* Fila oculta por búsqueda */
.ventas-table tbody tr.hidden-row {
    display: none;
}

/* Resaltar coincidencias */
.ventas-table tbody tr td mark {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.3) 0%, rgba(139, 92, 246, 0.3) 100%);
    color: var(--text);
    padding: 0 2px;
    border-radius: 3px;
}

/* Mensaje sin resultados */
.no-results-message {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.no-results-message .no-results-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    display: block;
}

/* Light mode */
body.light-mode .search-box .search-input {
    background: #ffffff;
    border-color: #e2e8f0;
}

body.light-mode .search-box .search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

body.light-mode .search-box .search-clear {
    background: #e2e8f0;
}

body.light-mode .ventas-table tbody tr td mark {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(139, 92, 246, 0.2) 100%);
}

/* Botones de acciones en análisis */
.analisis-actions-btns {
    display: flex;
    gap: 0.5rem;
}

.analisis-actions-btns .btn {
    flex-shrink: 0;
}

/* Tablas ordenables */
.sortable-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.5rem;
    transition: background-color 0.2s;
}

.sortable-table th.sortable:hover {
    background-color: var(--bg-darker);
}

.sortable-table th.sortable .sort-icon {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.5;
}

.sortable-table th.sortable .sort-icon::after {
    content: '⇅';
}

.sortable-table th.sortable.sort-asc .sort-icon::after {
    content: '↑';
    opacity: 1;
    color: var(--primary);
}

.sortable-table th.sortable.sort-desc .sort-icon::after {
    content: '↓';
    opacity: 1;
    color: var(--primary);
}

.sortable-table th.sortable.sort-asc,
.sortable-table th.sortable.sort-desc {
    background-color: var(--bg-darker);
}

.sortable-table th.sortable.sort-asc .sort-icon,
.sortable-table th.sortable.sort-desc .sort-icon {
    opacity: 1;
}

body.light-mode .sortable-table th.sortable:hover,
body.light-mode .sortable-table th.sortable.sort-asc,
body.light-mode .sortable-table th.sortable.sort-desc {
    background-color: #e2e8f0;
}

/* Dashboard Charts - Diseño Profesional */
.dashboard-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.chart-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 1.25rem;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.chart-card:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.chart-card.chart-wide {
    grid-column: 1 / -1;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.chart-header h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chart-header h4::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 16px;
    background: linear-gradient(180deg, #3b82f6 0%, #8b5cf6 100%);
    border-radius: 2px;
}

.chart-legend {
    display: flex;
    gap: 1.25rem;
    font-size: 0.7rem;
}

.chart-legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
    font-weight: 500;
}

.chart-legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.chart-body {
    min-height: 180px;
}

/* Gráfica de evolución (barras verticales) - Profesional */
.chart-area {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 160px;
    padding: 0.5rem 0;
    position: relative;
    background: linear-gradient(180deg, transparent 0%, rgba(59, 130, 246, 0.03) 100%);
    border-radius: 8px;
}

.chart-area::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 28px;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--border) 20%, var(--border) 80%, transparent 100%);
}

.chart-bar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    max-width: 50px;
    gap: 0.2rem;
}

.chart-bar-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 120px;
}

.chart-bar-item {
    width: 14px;
    border-radius: 6px 6px 0 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    min-height: 3px;
    cursor: pointer;
}

.chart-bar-item.ventas {
    background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 50%, #2563eb 100%);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.chart-bar-item.unidades {
    background: linear-gradient(180deg, #4ade80 0%, #22c55e 50%, #16a34a 100%);
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.4);
}

.chart-bar-item:hover {
    transform: scaleY(1.05) scaleX(1.1);
    filter: brightness(1.1);
}

.chart-bar-item .bar-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: white;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}

.chart-bar-item .bar-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1e293b;
}

.chart-bar-item:hover .bar-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-4px);
}

.chart-bar-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.4rem;
    font-weight: 500;
}

/* Gráfica de barras horizontales (Top Productos) - Profesional */
.chart-horizontal-bars {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.h-bar-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0.5rem;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.h-bar-item:hover {
    background-color: rgba(59, 130, 246, 0.08);
}

.h-bar-rank {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

.h-bar-item:nth-child(1) .h-bar-rank {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.3);
}

.h-bar-item:nth-child(2) .h-bar-rank {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
    box-shadow: 0 2px 6px rgba(100, 116, 139, 0.3);
}

.h-bar-item:nth-child(3) .h-bar-rank {
    background: linear-gradient(135deg, #cd7f32 0%, #a0522d 100%);
    box-shadow: 0 2px 6px rgba(205, 127, 50, 0.3);
}

.h-bar-info {
    flex: 1;
    min-width: 0;
}

.h-bar-name {
    font-size: 0.75rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.3rem;
    font-weight: 500;
}

.h-bar-track {
    height: 6px;
    background-color: rgba(148, 163, 184, 0.2);
    border-radius: 3px;
    overflow: hidden;
}

.h-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, #3b82f6 0%, #60a5fa 50%, #93c5fd 100%);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.h-bar-value {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--primary);
    min-width: 65px;
    text-align: right;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}

/* Gráfica Donut (Familias) - Profesional */
.chart-donut-container {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0.5rem;
}

.chart-donut {
    position: relative;
    width: 140px;
    height: 140px;
    flex-shrink: 0;
}

.chart-donut svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
}

.chart-donut svg path {
    transition: all 0.3s ease;
    cursor: pointer;
}

.chart-donut svg path:hover {
    filter: brightness(1.1);
    transform-origin: center;
}

.chart-donut-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: var(--bg-card);
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chart-donut-total {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.chart-donut-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.chart-donut-legend {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.donut-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.donut-legend-item:hover {
    background-color: rgba(59, 130, 246, 0.08);
}

.donut-legend-color {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.donut-legend-name {
    flex: 1;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.donut-legend-percent {
    font-weight: 700;
    color: var(--primary);
    min-width: 38px;
    text-align: right;
    font-size: 0.7rem;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}

/* Light mode charts */
body.light-mode .chart-card {
    background-color: #ffffff;
    border-color: #e2e8f0;
}

body.light-mode .chart-card:hover {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.1);
}

body.light-mode .h-bar-track {
    background-color: #e2e8f0;
}

body.light-mode .h-bar-item:hover {
    background-color: rgba(59, 130, 246, 0.06);
}

body.light-mode .donut-legend-item:hover {
    background-color: rgba(59, 130, 246, 0.06);
}

body.light-mode .chart-area {
    background: linear-gradient(180deg, transparent 0%, rgba(59, 130, 246, 0.02) 100%);
}

body.light-mode .dashboard-filtros {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08) 0%, rgba(139, 92, 246, 0.08) 100%);
    border-color: rgba(59, 130, 246, 0.15);
}

/* Dashboard stats 6 columnas - Profesional */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.dashboard-stats .stat-card.stat-large {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.dashboard-stats .stat-card.stat-large::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.dashboard-stats .stat-card.stat-large:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.dashboard-stats .stat-card.stat-large:hover::before {
    opacity: 1;
}

.dashboard-stats .stat-card.stat-large .stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.dashboard-stats .stat-card.stat-large .stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.35rem;
    font-weight: 600;
}

body.light-mode .dashboard-stats .stat-card.stat-large {
    background: #ffffff;
    border-color: #e2e8f0;
}

body.light-mode .dashboard-stats .stat-card.stat-large:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
}

@media (max-width: 900px) {
    .dashboard-stats {
        grid-template-columns: repeat(3, 1fr);
    }

    .dashboard-charts {
        grid-template-columns: 1fr;
    }

    .chart-donut-container {
        flex-direction: column;
    }
}

/* Modal Clientes No Geocodificados */
.no-geocod-resumen {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.no-geocod-resumen .stat-card {
    text-align: center;
}

.no-geocod-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}

.no-geocod-actions .btn {
    width: auto;
    margin: 0;
    padding: 0.5rem 1.25rem;
    font-size: 0.8rem;
    flex-shrink: 0;
}

/* Badges de razón */
.razon-badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.razon-badge.razon-fallido {
    background-color: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.razon-badge.razon-pendiente {
    background-color: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.razon-badge.razon-sin-dir {
    background-color: rgba(100, 116, 139, 0.15);
    color: #64748b;
    border: 1px solid rgba(100, 116, 139, 0.3);
}

/* Celda de dirección con overflow */
.direccion-cell {
    max-width: 350px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Light mode para badges */
body.light-mode .razon-badge.razon-fallido {
    background-color: rgba(239, 68, 68, 0.1);
}

body.light-mode .razon-badge.razon-pendiente {
    background-color: rgba(245, 158, 11, 0.1);
}

body.light-mode .razon-badge.razon-sin-dir {
    background-color: rgba(100, 116, 139, 0.1);
}

/* Modal Ventas por Calle */
.calles-resumen {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.calles-resumen .stat-card {
    text-align: center;
}

/* Responsive */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 40vh;
    }

    .header {
        flex-direction: column;
        gap: 0.5rem;
    }

    .header-stats {
        gap: 1rem;
        font-size: 0.8rem;
    }
}
