/* Modern Dashboard Redesign */

:root {
    /* Refined Palette (Light Theme) */
    --dashboard-bg: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-primary: #6366f1;
    /* Indigo */
    --accent-secondary: #8b5cf6;
    /* Violet */
    --success-green: #10b981;
    --warning-amber: #f59e0b;
    --danger-red: #ef4444;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Grid */
    --grid-gap: 1.5rem;
}

body.dashboard-modern {
    background-color: var(--dashboard-bg);
    color: var(--text-primary);
}

/* --- Layout Structure --- */

.dashboard-container {
    display: grid;
    grid-template-columns: 1fr 340px;
    /* Main Content | Sidebar */
    gap: var(--grid-gap);
    max-width: 1600px;
    margin: 0 auto;
    padding-bottom: 2rem;
}

.dashboard-main {
    display: flex;
    flex-direction: column;
    gap: var(--grid-gap);
    min-width: 0;
    /* Prevent overflow */
}

.dashboard-sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--grid-gap);
    min-width: 0;
}

/* Mobile Responsive */
@media (max-width: 1200px) {
    .dashboard-container {
        grid-template-columns: 1fr;
    }
}

/* --- Components --- */

/* 1. Briefing Card (Header) */
.briefing-card {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border-radius: 16px;
    padding: 2rem;
    color: white;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.briefing-content {
    position: relative;
    z-index: 2;
}

.briefing-date {
    opacity: 0.9;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.briefing-title {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 1rem 0;
}

.briefing-stats {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.briefing-stat-pill {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    padding: 0.5rem 1rem;
    border-radius: 99px;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* 2. KPI Grid (Top Stats) */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

@media (max-width: 768px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.kpi-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.kpi-value {
    color: var(--text-primary);
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    line-height: 1.2;
}

.kpi-trend {
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.kpi-trend.up {
    color: var(--success-green);
}

.kpi-trend.down {
    color: var(--danger-red);
}

/* 3. Section Headers */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* 4. Control Center (Sidebar) */
.control-panel {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.control-group {
    margin-bottom: 1.5rem;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 0.75rem;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem 0.5rem;
    background: #f1f5f9;
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    gap: 0.5rem;
}

.action-btn i {
    font-size: 1.25rem;
    color: var(--accent-primary);
}

.action-btn:hover {
    background: #e2e8f0;
    transform: translateY(-1px);
}

.action-btn.primary {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

.action-btn.primary i {
    color: white;
}

/* 5. Lists & Tables (Balances, Milestones) */
.list-card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    padding: 0;
    overflow: hidden;
}

.list-item {
    padding: 1rem;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-item:last-child {
    border-bottom: none;
}

.list-main-text {
    font-weight: 600;
    color: var(--text-primary);
}

.list-sub-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.list-value {
    font-weight: 700;
    text-align: right;
}

/* 6. Chart Container */
.chart-container-modern {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    height: 350px;
    position: relative;
}

/* 7. Partner Balance Chips (Injected by JS) */
.partner-balance-chip {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: #f8fafc;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.partner-balance-chip:hover {
    background: #e2e8f0;
}

.partner-chip-avatar {
    width: 40px;
    height: 40px;
    background: var(--accent-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.partner-chip-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.partner-chip-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.partner-chip-units {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.partner-chip-amount {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}

/* 8. Milestone Items (Injected by JS) */
.milestone-item-compact {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-left: 3px solid transparent;
    background: #f8fafc;
    margin-bottom: 0.5rem;
    border-radius: 4px;
}

.milestone-item-compact.overdue {
    border-left-color: var(--danger-red);
    background: #fef2f2;
}

.milestone-item-compact.upcoming {
    border-left-color: var(--accent-secondary);
}

.milestone-item-compact.urgent {
    border-left-color: var(--warning-amber);
}

.milestone-info {
    display: flex;
    flex-direction: column;
}

.milestone-unit {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.milestone-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.milestone-details {
    text-align: right;
}

.milestone-amount {
    display: block;
    font-weight: 700;
    font-size: 0.9rem;
}

.milestone-days {
    font-size: 0.75rem;
    font-weight: 500;
}

.milestone-days.overdue {
    color: var(--danger-red);
}

.milestone-days.urgent {
    color: var(--warning-amber);
}

/* ========================================
   DARK MODE OVERRIDES
   ======================================== */

[data-theme='dark'] {
    --dashboard-bg: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
}

[data-theme='dark'] .kpi-card {
    background: var(--card-bg) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-theme='dark'] .control-panel {
    background: var(--card-bg) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

[data-theme='dark'] .action-btn {
    background: rgba(51, 65, 85, 0.8) !important;
    color: var(--text-primary) !important;
}

[data-theme='dark'] .action-btn:hover {
    background: rgba(71, 85, 105, 0.9) !important;
}

[data-theme='dark'] .action-btn.primary {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%) !important;
    color: white !important;
}

[data-theme='dark'] .list-card {
    background: var(--card-bg) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

[data-theme='dark'] .list-item {
    border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-theme='dark'] .partner-balance-chip {
    background: rgba(51, 65, 85, 0.6) !important;
}

[data-theme='dark'] .partner-balance-chip:hover {
    background: rgba(71, 85, 105, 0.8) !important;
}

[data-theme='dark'] .milestone-item-compact {
    background: rgba(51, 65, 85, 0.6) !important;
}

[data-theme='dark'] .milestone-item-compact.overdue {
    background: rgba(127, 29, 29, 0.3) !important;
}

[data-theme='dark'] .chart-container-modern {
    background: var(--card-bg) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

/* Ensure all nested text follows Dark Mode colors */
[data-theme='dark'] .kpi-label,
[data-theme='dark'] .kpi-trend,
[data-theme='dark'] .control-group-title,
[data-theme='dark'] .list-sub-text,
[data-theme='dark'] .partner-chip-units,
[data-theme='dark'] .milestone-desc {
    color: var(--text-secondary) !important;
}

[data-theme='dark'] .kpi-value,
[data-theme='dark'] .list-main-text,
[data-theme='dark'] .list-value,
[data-theme='dark'] .partner-chip-name,
[data-theme='dark'] .partner-chip-amount,
[data-theme='dark'] .milestone-unit,
[data-theme='dark'] .milestone-amount {
    color: var(--text-primary) !important;
}

/* ============================================
   Command Palette (#29)
   ============================================ */
.cmd-palette-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.cmd-palette-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.cmd-palette {
    position: fixed;
    top: 20%;
    left: 50%;
    transform: translateX(-50%) scale(0.95);
    width: 560px;
    max-width: 90vw;
    background: var(--card-bg, #fff);
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    z-index: 10001;
    opacity: 0;
    pointer-events: none;
    transition: all 0.15s ease;
}

.cmd-palette.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) scale(1);
}

.cmd-palette-input-wrap {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.cmd-palette-icon {
    font-size: 18px;
    margin-right: 10px;
    opacity: 0.5;
}

.cmd-palette-input-wrap input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    background: transparent;
    color: inherit;
}

.cmd-palette-esc {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-secondary);
}

.cmd-palette-results {
    max-height: 340px;
    overflow-y: auto;
    padding: 8px 0;
}

.cmd-palette-category {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding: 8px 16px 4px;
    opacity: 0.7;
}

.cmd-palette-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.1s;
}

.cmd-palette-item:hover,
.cmd-palette-item.selected,
.cmd-palette-item.hover {
    background: rgba(99, 102, 241, 0.08);
}

.cmd-palette-item-icon {
    margin-right: 10px;
    font-size: 16px;
}

.cmd-palette-item-label {
    flex: 1;
}

.cmd-palette-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
}

/* ============================================
   Shortcuts Help (#11)
   ============================================ */
.shortcuts-help-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
}

.shortcuts-help {
    background: var(--card-bg, #fff);
    border-radius: 12px;
    padding: 24px;
    min-width: 320px;
    box-shadow: var(--shadow-lg);
}

.shortcuts-help h3 {
    margin: 0 0 16px;
}

.shortcuts-grid {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.shortcut-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.shortcut-row kbd {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 12px;
    font-family: monospace;
}

.shortcuts-pages {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.shortcuts-pages kbd {
    font-size: 11px;
    padding: 1px 5px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 3px;
}

.shortcuts-close {
    margin: 12px 0 0;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
}

/* ============================================
   Top Loading Progress Bar (#35)
   ============================================ */
#page-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-primary, #6366f1), var(--accent-secondary, #8b5cf6));
    z-index: 99999;
    width: 0;
    opacity: 0;
    transition: width 0.3s ease, opacity 0.2s ease;
}

#page-progress-bar.active {
    opacity: 1;
}

/* ============================================
   Empty State Illustrations (#31)
   ============================================ */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.empty-state-desc {
    font-size: 14px;
    max-width: 360px;
    margin: 0 auto 16px;
}

.empty-state .btn {
    margin-top: 8px;
}

/* ============================================
   Export Button (#13)
   ============================================ */
.export-csv-btn {
    font-size: 13px;
    padding: 6px 12px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 6px;
    cursor: pointer;
    background: transparent;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.export-csv-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
}

/* ============================================
   Print Styles (#34)
   ============================================ */
@media print {

    .sidebar,
    .top-header,
    .page-header-actions,
    .btn,
    .modal-overlay,
    .toast-container,
    .fab,
    #command-palette,
    #command-palette-overlay,
    #page-progress-bar,
    .export-csv-btn,
    .search-bar,
    .filter-controls,
    .nav-item,
    [onclick],
    button:not(.no-print-hide) {
        display: none !important;
    }

    body {
        background: white !important;
        color: black !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }

    .page-section {
        box-shadow: none !important;
        border: none !important;
    }

    table {
        width: 100% !important;
        border-collapse: collapse;
        font-size: 12px;
    }

    th,
    td {
        border: 1px solid #ddd !important;
        padding: 6px 8px !important;
    }

    th {
        background: #f5f5f5 !important;
        font-weight: bold;
    }

    .stat-card {
        border: 1px solid #ddd;
        break-inside: avoid;
    }

    .chart-container {
        break-inside: avoid;
    }

    @page {
        margin: 1.5cm;
    }

    h1,
    h2,
    h3 {
        page-break-after: avoid;
    }
}