/**
 * Dashboard Enhanced Styles
 * REQ-1.x: Dashboard styles with theme support
 */

/* ========================================
   THEME VARIABLES
   ======================================== */
:root {
    --theme-primary: #0a5fb3;
    --theme-secondary: #4a90e2;
    --theme-accent: #00c9ff;
    --theme-success: #10b981;
    --theme-warning: #f59e0b;
    --theme-danger: #ef4444;
}

/* ========================================
   DASHBOARD SPECIFIC OVERRIDES
   Note: Base structure styles are in page-structure.css
   ======================================== */
/* Dashboard header uses standard page-header from page-structure.css */
/* Dashboard controls uses standard page-controls from page-structure.css */
/* Dashboard content uses standard page-content from page-structure.css */

.calendar-selector .card,
.tema-filter .card {
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: box-shadow 0.2s;
}

.calendar-selector .card:hover,
.tema-filter .card:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.stat-box {
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 6px;
    transition: transform 0.2s;
}

.stat-box:hover {
    transform: translateY(-2px);
    background: #e9ecef;
}

.stat-value {
    font-size: 1.15rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ========================================
   WIDGETS GRID - Usar flexbox en lugar de grid
   ======================================== */
.widgets-grid {
    width: 100%;
    margin-bottom: 2rem;
}

.widgets-grid .row {
    margin-left: -0.75rem;
    margin-right: -0.75rem;
}

.widgets-grid .card {
    min-width: 250px; /* Asegurar ancho mínimo para 3 columnas */
    max-width: 100%;
    word-wrap: break-word;
}

/* Forzar 3 columnas en desktop */
.widgets-grid .col-md-4 {
    flex: 0 0 33.333333%;
    max-width: 33.333333%;
}

@media (min-width: 768px) {
    .widgets-grid .row > div {
        flex: 0 0 33.333333% !important;
        max-width: 33.333333% !important;
    }
}

.widgets-grid .card-header h5 {
    white-space: normal; /* Permitir que el texto se ajuste */
    word-break: break-word;
    font-size: 1rem;
    font-weight: 600;
}

/* ========================================
   WIDGET CARD
   ======================================== */
.widget-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    height: 100%;
    min-height: 280px;
}

.widget-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.widget-card .card-header {
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid #e9ecef;
    background-color: #f8f9fa;
}

.widget-card .card-header h5 {
    font-size: 0.8rem;
    font-weight: 600;
    margin: 0;
    color: #212529;
    white-space: normal;
    line-height: 1.3;
}

.widget-title {
    font-size: 0.8rem;
    font-weight: 600;
    margin: 0;
    color: #212529;
    display: block;
    width: 100%;
}

/* ========================================
   FEATURED MENTIONS
   ======================================== */
.featured-mentions-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.featured-mention-item {
    padding: 1rem;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.featured-mention-item:hover {
    border-color: #0d6efd;
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.1);
}

.mention-header {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.mention-title {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #212529;
}

.mention-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: #6c757d;
}

.medio-nombre {
    font-weight: 500;
    color: #495057;
}

/* ========================================
   INTELLIGENT SUMMARY
   ======================================== */
.summary-content .lead {
    font-size: 0.9rem;
    line-height: 1.6;
    color: #495057;
}

.summary-bullets {
    list-style-type: none;
    padding-left: 0;
}

.summary-bullets li {
    padding-left: 1.5rem;
    position: relative;
    margin-bottom: 0.4rem;
    line-height: 1.5;
    font-size: 0.85rem;
}

.summary-bullets li:before {
    content: "•";
    position: absolute;
    left: 0;
    color: #667eea;
    font-weight: bold;
    font-size: 1.2rem;
}

.summary-meta {
    border-top: 1px solid #e9ecef;
    padding-top: 1rem;
    display: flex;
    gap: 1rem;
}

.widget-actions button {
    padding: 0.25rem 0.5rem;
    color: #6c757d;
}

.widget-actions button:hover {
    color: var(--theme-primary);
}

.widget-body {
    padding: 0.85rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* ========================================
   KPI CARDS
   ======================================== */
.kpi-card {
    padding: 1.5rem;
    border-radius: 8px;
    color: white;
    height: 100%;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.kpi-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.kpi-icon {
    font-size: 2rem;
    opacity: 0.9;
}

.kpi-title {
    margin: 0;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.kpi-value {
    font-size: 1.85rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.kpi-change {
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* ========================================
   CHARTS
   ======================================== */
.chart-container {
    position: relative;
    flex-grow: 1;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-legend {
    margin-top: 1rem;
    max-height: 150px;
    overflow-y: auto;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.legend-item:hover {
    background-color: #f8f9fa;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
}

.legend-label {
    flex-grow: 1;
    font-size: 0.75rem;
}

.legend-value {
    font-weight: 600;
    margin-right: 0.5rem;
    font-size: 0.75rem;
}

.legend-percentage {
    color: #6c757d;
    font-size: 0.7rem;
}

/* ========================================
   TOP MEDIOS LIST
   ======================================== */
.top-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.top-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem;
    background: #f8f9fa;
    border-radius: 6px;
    transition: all 0.2s;
}

.top-item:hover {
    background: #e9ecef;
    transform: translateX(4px);
}

.top-rank {
    font-size: 1rem;
    font-weight: 700;
    color: var(--theme-primary);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: 50%;
}

.top-logo {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.top-logo img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.top-info {
    flex-grow: 1;
}

.top-name {
    font-weight: 600;
    margin-bottom: 0.2rem;
    font-size: 0.8rem;
}

.top-value {
    text-align: right;
}

.top-value strong {
    font-size: 1rem;
    color: var(--theme-primary);
}

/* ========================================
   FEATURED MENTIONS
   ======================================== */
.featured-mentions-card {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.mention-card {
    transition: all 0.2s;
}

.mention-card:hover {
    background-color: #f8f9fa;
}

.mention-title-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.badge-tier {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
}

.badge-tier.tier-1 {
    background-color: #ffd700;
    color: #000;
}

.badge-tier.tier-2 {
    background-color: #c0c0c0;
    color: #000;
}

.badge-tier.tier-3 {
    background-color: #cd7f32;
    color: #fff;
}

.metadata-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
}

.metadata-label {
    font-weight: 500;
}

.metadata-value {
    color: #495057;
}

.medio-logo {
    max-width: 24px;
    max-height: 24px;
    object-fit: contain;
}

/* ========================================
   INTELLIGENT SUMMARY
   ======================================== */
.intelligent-summary-card {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.summary-bullets {
    line-height: 1.8;
}

.summary-bullets li {
    position: relative;
    padding-left: 1.5rem;
}

.summary-bullets li i {
    position: absolute;
    left: 0;
    top: 0.25rem;
}

/* ========================================
   WIDGET EDITOR MODAL
   ======================================== */
.widget-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #dee2e6;
    transition: all 0.2s;
}

.widget-item:hover {
    background: #e9ecef;
    border-color: var(--theme-primary);
}

.widget-item input[type="checkbox"] {
    margin-right: 0.75rem;
    cursor: pointer;
}

.widget-drag-handle {
    cursor: grab;
    color: #6c757d;
    margin-right: 0.75rem;
    font-size: 1.25rem;
}

.widget-drag-handle:hover {
    color: var(--theme-primary);
}

.active-widgets-list .widget-item {
    cursor: move;
    background: white;
    border: 2px dashed #dee2e6;
}

.active-widgets-list .widget-item:hover {
    border-color: var(--theme-primary);
}

.sortable-ghost {
    opacity: 0.4;
    background: #e9ecef !important;
}

.sortable-drag {
    cursor: grabbing !important;
}

.widget-item-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.widget-item-category {
    font-size: 0.75rem;
    color: #6c757d;
    text-transform: uppercase;
}

/* ========================================
   LOADING OVERLAY
   ======================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* ========================================
   RESPONSIVE
   ======================================== */
/* Tablets (iPad y similares) */
@media (max-width: 992px) and (min-width: 768px) {
    .widgets-grid .row > div {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }
}

/* Móviles (menor a iPad - 768px) */
@media (max-width: 767px) {
    .page-header {
        padding: 1rem 0;
    }
    
    .page-title {
        font-size: 1.25rem;
    }
    
    .page-header-logo {
        max-height: 36px !important;
        max-width: 140px !important;
    }
    
    /* Widgets en columna completa en móvil */
    .widgets-grid .row > div {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-bottom: 1rem;
    }
    
    .widgets-grid {
        gap: 0.5rem;
    }
    
    .widget-card {
        margin-bottom: 1rem;
    }
    
    /* Ajustar tamaño de gráficas en móvil */
    .widget-content canvas {
        max-height: 250px !important;
        width: 100% !important;
    }
    
    .kpi-value {
        font-size: 1.75rem;
    }
    
    .mention-metadata .row {
        font-size: 0.75rem;
    }
    
    /* Ocultar columnas secundarias en móvil */
    .page-header-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .page-header-actions .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.75rem;
    }
    
    /* Featured mentions en móvil */
    .featured-mentions-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Calendar y filtros en móvil */
    .page-controls .row > div {
        margin-bottom: 0.75rem;
    }
}

/* Móviles muy pequeños (iPhone SE, etc) */
@media (max-width: 576px) {
    .page-title {
        font-size: 1.1rem;
    }
    
    .page-subtitle {
        font-size: 0.8rem;
    }
    
    .page-header-logo {
        max-height: 32px !important;
        max-width: 120px !important;
    }
    
    .widget-content canvas {
        max-height: 220px !important;
    }
    
    .kpi-value {
        font-size: 1.5rem;
    }
    
    .card-header h5 {
        font-size: 0.9rem;
    }
    
    .page-header-actions .btn {
        font-size: 0.75rem;
        padding: 0.35rem 0.6rem;
    }
}

/* ========================================
   ANIMATIONS
   ======================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.widget-card {
    animation: fadeIn 0.3s ease-out;
}

.widget-card:nth-child(1) { animation-delay: 0s; }
.widget-card:nth-child(2) { animation-delay: 0.05s; }
.widget-card:nth-child(3) { animation-delay: 0.1s; }
.widget-card:nth-child(4) { animation-delay: 0.15s; }
.widget-card:nth-child(5) { animation-delay: 0.2s; }
.widget-card:nth-child(6) { animation-delay: 0.25s; }

/* ========================================
   MANUAL LOAD HINTS AND BUTTONS
   ======================================== */
.manual-load-hint {
    text-align: center;
    padding: 20px;
}

.manual-load-hint .alert {
    text-align: left;
    border-left: 4px solid #0dcaf0;
}

.manual-load-hint .alert i {
    margin-right: 8px;
}

.manual-load-btn {
    font-size: 1rem;
    padding: 12px 24px;
    border-radius: 8px;
    transition: all 0.3s ease;
    font-weight: 500;
}

.manual-load-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.manual-load-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.manual-load-btn i {
    margin-right: 8px;
}

.widget-loading {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========================================
   UTILITIES
   ======================================== */
.badge-sentiment.sentiment-positivo {
    background-color: var(--theme-success);
    color: white;
}

.badge-sentiment.sentiment-neutral {
    background-color: var(--theme-warning);
    color: #000;
}

.badge-sentiment.sentiment-negativo {
    background-color: var(--theme-danger);
    color: white;
}

.text-primary {
    color: var(--theme-primary) !important;
}

.btn-primary {
    background-color: var(--theme-primary);
    border-color: var(--theme-primary);
}

.btn-primary:hover {
    background-color: var(--theme-secondary);
    border-color: var(--theme-secondary);
}

.btn-outline-primary {
    color: var(--theme-primary);
    border-color: var(--theme-primary);
}

.btn-outline-primary:hover {
    background-color: var(--theme-primary);
    border-color: var(--theme-primary);
    color: white;
}

/* ========================================
   DATE PICKER CUSTOMIZATION
   ======================================== */
.flatpickr-calendar {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.flatpickr-day.selected {
    background: var(--theme-primary);
    border-color: var(--theme-primary);
}

.flatpickr-day.selected:hover {
    background: var(--theme-secondary);
    border-color: var(--theme-secondary);
}

.flatpickr-day:hover {
    background: rgba(10, 95, 179, 0.1);
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */
.toast-container {
    z-index: 10000;
}

.toast {
    min-width: 300px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .dashboard-header,
    .dashboard-controls,
    .widget-actions,
    .btn {
        display: none;
    }
    
    .widget-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #dee2e6;
    }
}
