/**
 * Unified Design System
 * Based on Budget Reallocation Interstitial Design Patterns
 * Applies consistent styling across the entire application
 */

/* ===== CSS VARIABLES ===== */
:root {
    /* Brand Colors */
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --primary-blue: #667eea;
    --primary-purple: #764ba2;
    --primary-dark: #5a6fd8;
    
    /* Semantic Colors */
    --success: #28a745;
    --success-light: #d4edda;
    --success-border: #c3e6cb;
    --warning: #ffc107;
    --warning-light: #fff3cd;
    --warning-border: #ffeaa7;
    --danger: #dc3545;
    --danger-light: #f8d7da;
    --danger-border: #f5c6cb;
    --info: #667eea;
    --info-light: #e3f2fd;
    --info-border: #bbdefb;
    
    /* Neutral Colors */
    --white: #ffffff;
    --gray-50: #f8f9fa;
    --gray-100: #f1f3f4;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #6c757d;
    --gray-700: #495057;
    --gray-800: #343a40;
    --gray-900: #212529;
    --black: #000000;
    
    /* Text Colors */
    --text-primary: #333333;
    --text-secondary: #555555;
    --text-muted: #6c757d;
    --text-light: #ffffff;
    
    /* Background Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --bg-overlay: rgba(0, 0, 0, 0.5);
    
    /* Border Colors */
    --border-light: #e0e0e0;
    --border-medium: #dee2e6;
    --border-dark: #ced4da;
    
    /* Font Family */
    --font-family: Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif;
    
    /* Font Sizes */
    --font-xs: 11px;
    --font-sm: 13px;
    --font-base: 14px;
    --font-lg: 16px;
    --font-xl: 18px;
    --font-2xl: 20px;
    --font-3xl: 24px;
    --font-4xl: 32px;
    
    /* Font Weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;
    
    /* Line Heights */
    --leading-tight: 1.1;
    --leading-normal: 1.4;
    --leading-relaxed: 1.6;
    
    /* Spacing Scale */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 20px;
    --space-2xl: 24px;
    --space-3xl: 30px;
    --space-4xl: 40px;
    
    /* Border Radius */
    --radius-sm: 3px;
    --radius-md: 4px;
    --radius-lg: 6px;
    --radius-xl: 8px;
    --radius-full: 50%;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 4px 12px rgba(102, 126, 234, 0.4);
    --shadow-xl: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-focus: 0 0 0 3px rgba(102, 126, 234, 0.1);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;
    
    /* Z-Index Scale */
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-popover: 1060;
    --z-tooltip: 1070;
}

/* ===== BASE STYLES ===== */

/* Reset and Base */
* {
    box-sizing: border-box;
}

html {
    font-family: var(--font-family);
    font-size: var(--font-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--bg-secondary);
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--space-lg) 0;
    font-weight: var(--font-semibold);
    line-height: var(--leading-tight);
    color: var(--text-primary);
}

h1 { font-size: var(--font-3xl); }
h2 { font-size: var(--font-2xl); }
h3 { font-size: var(--font-xl); }
h4 { font-size: var(--font-lg); }
h5 { font-size: var(--font-base); }
h6 { font-size: var(--font-sm); }

p {
    margin: 0 0 var(--space-lg) 0;
    color: var(--text-secondary);
}

/* Links */
a {
    color: var(--primary-blue);
    text-decoration: none;
    transition: color var(--transition-base);
}

a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

a:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

/* ===== COMPONENT STYLES ===== */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md) var(--space-2xl);
    font-size: var(--font-base);
    font-weight: var(--font-medium);
    line-height: 1;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-base);
    user-select: none;
    white-space: nowrap;
}

.btn:focus {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Button Variants */
.btn-primary {
    background: var(--primary-gradient);
    color: var(--text-light);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background-color: var(--gray-600);
    color: var(--text-light);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--gray-700);
}

.btn-success {
    background-color: var(--success);
    color: var(--text-light);
}

.btn-success:hover:not(:disabled) {
    background-color: #218838;
    transform: translateY(-1px);
}

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

.btn-warning:hover:not(:disabled) {
    background-color: #e0a800;
    transform: translateY(-1px);
}

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

.btn-danger:hover:not(:disabled) {
    background-color: #c82333;
    transform: translateY(-1px);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--primary-blue);
    color: var(--primary-blue);
}

.btn-outline:hover:not(:disabled) {
    background-color: var(--primary-blue);
    color: var(--text-light);
}

/* Button Sizes */
.btn-sm {
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--font-sm);
}

.btn-lg {
    padding: var(--space-lg) var(--space-3xl);
    font-size: var(--font-lg);
}

/* Form Elements */
.form-group {
    margin-bottom: var(--space-xl);
}

.form-label {
    display: block;
    margin-bottom: var(--space-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
}

.form-control {
    display: block;
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-base);
    font-family: var(--font-family);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: var(--shadow-focus);
}

.form-control:disabled {
    background-color: var(--gray-100);
    opacity: 0.6;
    cursor: not-allowed;
}

.form-control.is-invalid {
    border-color: var(--danger);
}

.form-control.is-valid {
    border-color: var(--success);
}

/* Select Elements */
.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m1 6 7 7 7-7'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right var(--space-md) center;
    background-size: 16px 12px;
    padding-right: var(--space-4xl);
}

/* Tables */
.table {
    width: 100%;
    margin-bottom: var(--space-xl);
    border-collapse: collapse;
    font-size: var(--font-base);
}

.table th,
.table td {
    padding: var(--space-md) var(--space-sm);
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-medium);
}

.table th {
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    border-bottom: 2px solid var(--border-medium);
    white-space: nowrap;
}

.table tbody tr {
    transition: background-color var(--transition-base);
}

.table tbody tr:hover {
    background-color: var(--bg-secondary);
}

.table-striped tbody tr:nth-child(odd) {
    background-color: var(--bg-primary);
}

.table-striped tbody tr:nth-child(even) {
    background-color: var(--bg-secondary);
}

/* Table Variants */
.table-primary th {
    background: var(--primary-gradient);
    color: var(--text-light);
}

.table-success tbody tr {
    background-color: var(--success-light);
}

.table-warning tbody tr {
    background-color: var(--warning-light);
}

.table-danger tbody tr {
    background-color: var(--danger-light);
}

/* Cards */
.card {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: var(--space-xl) var(--space-3xl);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-medium);
}

.card-header.card-header-primary {
    background: var(--primary-gradient);
    color: var(--text-light);
}

.card-body {
    padding: var(--space-3xl);
}

.card-footer {
    padding: var(--space-xl) var(--space-3xl);
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-medium);
}

/* Alerts */
.alert {
    padding: var(--space-lg);
    margin-bottom: var(--space-xl);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
}

.alert-success {
    color: #155724;
    background-color: var(--success-light);
    border-color: var(--success-border);
}

.alert-warning {
    color: #856404;
    background-color: var(--warning-light);
    border-color: var(--warning-border);
}

.alert-danger {
    color: #721c24;
    background-color: var(--danger-light);
    border-color: var(--danger-border);
}

.alert-info {
    color: #0c5460;
    background-color: var(--info-light);
    border-color: var(--info-border);
}

/* Badges */
.badge {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-xs);
    font-weight: var(--font-semibold);
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: var(--radius-sm);
}

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

.badge-success {
    color: var(--text-light);
    background-color: var(--success);
}

.badge-warning {
    color: var(--text-primary);
    background-color: var(--warning);
}

.badge-danger {
    color: var(--text-light);
    background-color: var(--danger);
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    z-index: var(--z-modal-backdrop);
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-overlay);
    opacity: 0;
    transition: opacity var(--transition-slow);
}

.modal-backdrop.show {
    opacity: 1;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    z-index: var(--z-modal);
    display: none;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    outline: 0;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-dialog {
    position: relative;
    width: auto;
    max-width: 500px;
    margin: var(--space-xl);
    pointer-events: none;
}

.modal-dialog-lg {
    max-width: 800px;
}

.modal-dialog-xl {
    max-width: 1140px;
}

.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    pointer-events: auto;
    background-color: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    animation: modalSlideIn var(--transition-slow) ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xl) var(--space-3xl);
    border-bottom: 2px solid var(--border-light);
    background: var(--primary-gradient);
    color: var(--text-light);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.modal-title {
    margin: 0;
    font-size: var(--font-3xl);
    font-weight: var(--font-semibold);
}

.modal-close {
    background: none;
    border: none;
    font-size: var(--font-4xl);
    color: var(--text-light);
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    transition: background-color var(--transition-base);
}

.modal-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.modal-body {
    position: relative;
    flex: 1 1 auto;
    padding: var(--space-3xl);
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-md);
    padding: var(--space-xl) var(--space-3xl);
    border-top: 1px solid var(--border-light);
}

/* Collapsible Sections */
.collapsible-toggle {
    margin: 0;
    padding: 0;
    color: var(--text-secondary);
    font-size: var(--font-lg);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    transition: color var(--transition-base);
    border: none;
    background: none;
}

.collapsible-toggle:hover {
    color: var(--primary-blue);
}

.collapsible-toggle .toggle-icon {
    display: inline-block;
    margin-right: var(--space-sm);
    font-size: var(--font-base);
    transition: transform var(--transition-base);
    width: 16px;
}

.collapsible-content {
    display: block;
    overflow: hidden;
}

/* Status Indicators */
.status-indicator {
    padding: var(--space-sm) var(--space-md);
    margin: var(--space-sm) 0;
    border-radius: var(--radius-md);
    font-size: var(--font-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-increase {
    background-color: var(--success-light);
    border-left: 4px solid var(--success);
}

.status-decrease {
    background-color: var(--danger-light);
    border-left: 4px solid var(--danger);
}

.status-neutral {
    background-color: var(--gray-100);
    border-left: 4px solid var(--gray-400);
}

/* Loading States */
.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--gray-300);
    border-top: 2px solid var(--primary-blue);
    border-radius: var(--radius-full);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Utility Classes */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-warning { color: #856404; }
.text-danger { color: var(--danger); }
.text-info { color: var(--primary-blue); }

.bg-primary { background-color: var(--bg-primary); }
.bg-secondary { background-color: var(--bg-secondary); }
.bg-success { background-color: var(--success-light); }
.bg-warning { background-color: var(--warning-light); }
.bg-danger { background-color: var(--danger-light); }

.border { border: 1px solid var(--border-medium); }
.border-top { border-top: 1px solid var(--border-medium); }
.border-bottom { border-bottom: 1px solid var(--border-medium); }
.border-left { border-left: 1px solid var(--border-medium); }
.border-right { border-right: 1px solid var(--border-medium); }

.rounded { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

.m-0 { margin: 0; }
.m-1 { margin: var(--space-xs); }
.m-2 { margin: var(--space-sm); }
.m-3 { margin: var(--space-md); }
.m-4 { margin: var(--space-lg); }
.m-5 { margin: var(--space-xl); }

.p-0 { padding: 0; }
.p-1 { padding: var(--space-xs); }
.p-2 { padding: var(--space-sm); }
.p-3 { padding: var(--space-md); }
.p-4 { padding: var(--space-lg); }
.p-5 { padding: var(--space-xl); }

.d-none { display: none; }
.d-block { display: block; }
.d-flex { display: flex; }
.d-inline { display: inline; }
.d-inline-block { display: inline-block; }

.flex-column { flex-direction: column; }
.flex-row { flex-direction: row; }
.justify-content-start { justify-content: flex-start; }
.justify-content-center { justify-content: center; }
.justify-content-end { justify-content: flex-end; }
.justify-content-between { justify-content: space-between; }
.align-items-start { align-items: flex-start; }
.align-items-center { align-items: center; }
.align-items-end { align-items: flex-end; }

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

.font-weight-normal { font-weight: var(--font-normal); }
.font-weight-medium { font-weight: var(--font-medium); }
.font-weight-semibold { font-weight: var(--font-semibold); }
.font-weight-bold { font-weight: var(--font-bold); }

/* ===== RESPONSIVE DESIGN ===== */

/* Tablet */
@media (max-width: 768px) {
    .modal-dialog {
        max-width: 100%;
        margin: 0;
    }
    
    .modal-content {
        border-radius: 0;
        height: 100vh;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--space-lg);
    }
    
    .btn {
        padding: var(--space-lg) var(--space-xl);
    }
    
    .table {
        font-size: var(--font-sm);
    }
    
    .table th,
    .table td {
        padding: var(--space-sm) var(--space-xs);
    }
}

/* Mobile */
@media (max-width: 480px) {
    :root {
        --font-base: 13px;
        --font-lg: 15px;
        --font-xl: 17px;
        --font-2xl: 19px;
        --font-3xl: 22px;
    }
    
    .btn {
        width: 100%;
        margin-bottom: var(--space-sm);
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
    }
}

/* ===== ACCESSIBILITY ===== */

/* Focus Styles */
*:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

.btn:focus,
.form-control:focus {
    outline: none;
    box-shadow: var(--shadow-focus);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --border-light: #000000;
        --border-medium: #000000;
        --border-dark: #000000;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .btn,
    .modal,
    .modal-backdrop {
        display: none !important;
    }
    
    .table {
        border-collapse: collapse;
    }
    
    .table th,
    .table td {
        border: 1px solid #000;
    }
}