/* CSS Variables for Design System */
:root {
    /* Color Palette */
    --color-primary: #2563eb;
    --color-success: #16a34a;
    --color-warning: #ea580c;
    --color-danger: #dc2626;
    --color-neutral: #6b7280;
    --color-background: #f8fafc;
    --color-text: #1f2937;
    --color-text-light: #6b7280;
    --color-white: #ffffff;
    --color-border: #e5e7eb;
    --color-border-light: #f3f4f6;
    --color-surface-muted: #f1f5f9;
    --color-chart-grid: rgba(0, 0, 0, 0.05);
    --color-chart-text: #1f2937;
    --color-table-row-alt: #f8fafc;
    --color-row-hover: rgba(37, 99, 235, 0.08);
    
    /* Spacing System (8px base unit) */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 48px;
    --spacing-3xl: 64px;
    
    /* Typography Scale */
    --font-family-primary: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs: 12px;
    --font-size-sm: 14px;
    --font-size-base: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 20px;
    --font-size-2xl: 24px;
    --font-size-3xl: 30px;
    --font-size-4xl: 36px;
    
    /* Font Weights */
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    
    /* Line Heights */
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.75;
    
    /* Border Radius */
    --border-radius-sm: 4px;
    --border-radius-md: 8px;
    --border-radius-lg: 12px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body[data-theme="dark"] {
    --color-background: #0f172a;
    --color-white: #1e293b;
    --color-text: #e2e8f0;
    --color-text-light: #94a3b8;
    --color-border: rgba(148, 163, 184, 0.3);
    --color-border-light: rgba(148, 163, 184, 0.15);
    --color-surface-muted: rgba(148, 163, 184, 0.08);
    --color-chart-grid: rgba(148, 163, 184, 0.15);
    --color-chart-text: #cbd5f5;
    --color-table-row-alt: rgba(148, 163, 184, 0.05);
    --color-row-hover: rgba(37, 99, 235, 0.2);
    --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.6);
    --shadow-md: 0 8px 16px -4px rgba(15, 23, 42, 0.7);
    --shadow-lg: 0 16px 32px -6px rgba(15, 23, 42, 0.8);
}

/* Base Reset and Typography */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family-primary);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-normal);
    line-height: var(--line-height-normal);
    color: var(--color-text);
    background-color: var(--color-background);
}

h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
    color: var(--color-text);
}

h1 {
    font-size: var(--font-size-3xl);
}

h2 {
    font-size: var(--font-size-2xl);
}

h3 {
    font-size: var(--font-size-xl);
}

/* Main Grid Layout Structure */
body {
    display: grid;
    grid-template-rows: auto auto 1fr;
    grid-template-areas: 
        "header"
        "metrics"
        "main";
    min-height: 100vh;
    gap: var(--spacing-lg);
    padding: var(--spacing-lg);
}

.header {
    grid-area: header;
}

.metrics-section {
    grid-area: metrics;
}

.main-content {
    grid-area: main;
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: var(--spacing-xl);
    align-items: start;
}

.content-area {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
}

.sidebar {
    position: sticky;
    top: var(--spacing-lg);
}

/* Metrics Cards Layout */
.metrics-container {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-lg);
    justify-content: space-between;
}

.metric-card {
    flex: 1 1 200px;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    background: var(--color-white);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    position: relative;
}

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

.metric-card-icon {
    font-size: var(--font-size-2xl);
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--color-border-light);
}

.metric-card-value {
    font-size: var(--font-size-3xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-xs);
    line-height: var(--line-height-tight);
}

.metric-card-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--spacing-xs);
}

.metric-card-details {
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
    margin-top: var(--spacing-xs);
    line-height: var(--line-height-normal);
    text-align: center;
}

/* Color-coding system for different metric types */
.metric-card.gray .metric-card-icon {
    background-color: rgba(107, 114, 128, 0.1);
    color: var(--color-neutral);
}

.metric-card.gray .metric-card-value {
    color: var(--color-neutral);
}

.metric-card.blue .metric-card-icon {
    background-color: rgba(37, 99, 235, 0.1);
    color: var(--color-primary);
}

.metric-card.blue .metric-card-value {
    color: var(--color-primary);
}

.metric-card.green .metric-card-icon {
    background-color: rgba(22, 163, 74, 0.1);
    color: var(--color-success);
}

.metric-card.green .metric-card-value {
    color: var(--color-success);
}

.metric-card.red .metric-card-icon {
    background-color: rgba(220, 38, 38, 0.1);
    color: var(--color-danger);
}

.metric-card.red .metric-card-value {
    color: var(--color-danger);
}

.metric-card.orange .metric-card-icon {
    background-color: rgba(234, 88, 12, 0.1);
    color: var(--color-warning);
}

.metric-card.orange .metric-card-value {
    color: var(--color-warning);
}

/* Charts Section Layout */
.charts-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.charts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.charts-header h2 {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.data-scope-toggle {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.toggle-label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-light);
}

.toggle-switch {
    display: flex;
    background: var(--color-surface-muted);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-xs);
    border: 1px solid var(--color-border);
}

.toggle-option {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    background: transparent;
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-light);
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-option:hover {
    background: var(--color-white);
    color: var(--color-text);
}

.toggle-option.active {
    background: var(--color-white);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.toggle-icon {
    font-size: var(--font-size-sm);
}

.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-xl);
}

.chart-wrapper {
    background: var(--color-white);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.chart-wrapper h3 {
    margin: 0;
    font-size: var(--font-size-lg);
}

.data-scope-badge {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-light);
    background: var(--color-surface-muted);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--color-border-light);
}

/* Responsive Design for Desktop Optimization */

@media (max-width: 1100px) {
    body {
        padding: var(--spacing-md);
        gap: var(--spacing-md);
    }

    .main-content {
        grid-template-columns: minmax(0, 1fr) 260px;
        gap: var(--spacing-lg);
    }

    .metrics-container {
        gap: var(--spacing-md);
        justify-content: center;
    }

    .metric-card {
        flex: 1 1 180px;
        min-width: 180px;
        padding: var(--spacing-md);
    }

    .chart-wrapper {
        padding: var(--spacing-md);
    }

    .header-content {
        padding: var(--spacing-md) var(--spacing-lg);
    }

    .dashboard-title {
        font-size: var(--font-size-xl);
    }

    .charts-header h2,
    .content-area h2,
    .sidebar-content h2 {
        font-size: var(--font-size-lg);
    }

    .sidebar {
        top: var(--spacing-md);
    }

    .sidebar-content {
        padding: var(--spacing-md);
    }
}

@media (min-width: 1440px) {
    body {
        padding: var(--spacing-xl);
        gap: var(--spacing-xl);
    }
    
    .main-content {
        grid-template-columns: 1fr 360px;
        gap: var(--spacing-2xl);
    }
    
    .metrics-container {
        gap: var(--spacing-xl);
    }
}

@media (min-width: 1920px) {
    body {
        max-width: 1800px;
        margin: 0 auto;
    }
}

/* Header and Branding Styles */
.header {
    background: var(--color-white);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-lg) var(--spacing-xl);
    border-bottom: 1px solid var(--color-border-light);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo-icon {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

.logo-text {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-primary);
}

.dashboard-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-white);
    color: var(--color-text);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.theme-toggle-icon {
    font-size: var(--font-size-base);
    display: inline-flex;
}

.theme-toggle-label {
    letter-spacing: 0.02em;
}

.theme-toggle:hover {
    transform: translateY(-1px);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.theme-toggle:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Customer Details Sidebar Styles */
.sidebar {
    background: var(--color-white);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    height: fit-content;
}

.sidebar-content {
    padding: var(--spacing-lg);
}

.sidebar-content h2 {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--color-border-light);
}

.customer-info {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.customer-detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--color-surface-muted);
    border-radius: var(--border-radius-sm);
    padding: var(--spacing-md);
    border: 1px solid var(--color-border-light);
}

.customer-detail-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
    font-weight: var(--font-weight-medium);
}

.customer-detail-value {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.customer-detail-value.currency {
    color: var(--color-success);
    font-weight: var(--font-weight-bold);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-badge.draft {
    background-color: rgba(234, 88, 12, 0.1);
    color: var(--color-warning);
    border: 1px solid rgba(234, 88, 12, 0.2);
}

.status-badge.sent {
    background-color: rgba(37, 99, 235, 0.1);
    color: var(--color-primary);
    border: 1px solid rgba(37, 99, 235, 0.2);
}

.status-badge.paid {
    background-color: rgba(22, 163, 74, 0.1);
    color: var(--color-success);
    border: 1px solid rgba(22, 163, 74, 0.2);
}

/* Table Styling */
.table-container {
    background: var(--color-white);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

th {
    background-color: var(--color-surface-muted);
    color: var(--color-text);
    font-weight: var(--font-weight-semibold);
    text-align: left;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
}

td {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--color-border-light);
    color: var(--color-text);
    vertical-align: middle;
}

/* Zebra striping for better readability */
tbody tr:nth-child(even) {
    background-color: var(--color-table-row-alt);
}

tbody tr:hover {
    background-color: var(--color-row-hover);
}

/* Selected customer row highlighting */
tbody tr.selected-customer {
    background-color: rgba(37, 99, 235, 0.08);
    border-left: 3px solid var(--color-primary);
    position: relative;
}

tbody tr.selected-customer:hover {
    background-color: rgba(37, 99, 235, 0.12);
}

/* Add a subtle selected indicator */
tbody tr.selected-customer td:first-child {
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary);
}

tbody tr.selected-customer td:first-child::before {
    content: "👤";
    margin-right: var(--spacing-xs);
    font-size: var(--font-size-xs);
}

/* Right-align currency and numeric values */
.customers-table th:nth-child(2),
.customers-table th:nth-child(3),
.customers-table th:nth-child(4),
.customers-table td:nth-child(2),
.customers-table td:nth-child(3),
.customers-table td:nth-child(4) {
    text-align: right;
}

.events-table th:nth-child(4),
.events-table th:nth-child(5),
.events-table td:nth-child(4),
.events-table td:nth-child(5) {
    text-align: right;
}

.invoices-table th:nth-child(3),
.invoices-table td:nth-child(3) {
    text-align: right;
}

/* Currency formatting */
.currency {
    font-weight: var(--font-weight-semibold);
    color: var(--color-success);
}

/* Number formatting */
.number {
    font-weight: var(--font-weight-medium);
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

/* Section headers */
.content-area h2 {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin-bottom: var(--spacing-md);
}

/* Section spacing */
.top-customers-section,
.charts-section,
.events-log-section,
.invoices-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Ensure proper spacing and alignment */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: var(--spacing-md);
        text-align: center;
    }

    .header-actions {
        flex-direction: column;
    }

    .theme-toggle {
        width: 100%;
        justify-content: center;
    }
    
    .dashboard-title {
        font-size: var(--font-size-xl);
    }

    .main-content {
        grid-template-columns: 1fr;
        gap: var(--spacing-lg);
    }

    .sidebar {
        position: static;
        order: -1;
    }

    /* Charts section responsive adjustments */
    .charts-header {
        flex-direction: column;
        gap: var(--spacing-sm);
        align-items: flex-start;
    }

    .data-scope-toggle {
        align-self: stretch;
        justify-content: center;
    }

    .charts-container {
        grid-template-columns: 1fr;
        gap: var(--spacing-lg);
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-xs);
    }

    /* Responsive table adjustments */
    th, td {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    table {
        font-size: var(--font-size-xs);
    }
}
