/**
 * Finance Module Unified CSS
 * Based on Dashboard design patterns
 * Extracted from finance-dashboard.tpl
 * 
 * Color Palette:
 * - Primary: #667eea (purple-blue gradient start)
 * - Primary Dark: #764ba2 (purple-blue gradient end)
 * - Success/Green: #4caf50
 * - Danger/Red: #f44336
 * - Warning/Orange: #ff9800
 * - Info/Blue: #2196f3
 * - Purple: #9c27b0
 * 
 * Border Radius: 12px (containers), 6px (inputs/buttons)
 * Box Shadow: 0 2px 8px rgba(0,0,0,0.08) (cards), 0 4px 12px rgba(0,0,0,0.1) (hover)
 */

/* ==========================================================================
   1. BASE & LAYOUT
   ========================================================================== */

.finance-container {
    padding: 20px;
    max-width: 1800px;
    margin: 0 auto;
}

.finance-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

.finance-page-header h1,
.finance-page-header h2 {
    margin: 0;
    color: #333;
    font-size: 24px;
    font-weight: 600;
}

/* ==========================================================================
   2. CARDS & CONTAINERS
   ========================================================================== */

.finance-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.finance-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.finance-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #f0f0f0;
}

.finance-card-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

/* ==========================================================================
   3. KPI CARDS (Dashboard Style)
   ========================================================================== */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.kpi-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    display: flex;
    gap: 15px;
    align-items: flex-start;
    transition: all 0.3s ease;
}

.kpi-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.kpi-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
    flex-shrink: 0;
    font-weight: bold;
}

.kpi-content {
    flex: 1;
}

.kpi-content p {
    margin: 0;
}

.kpi-label {
    color: #666;
    font-size: 14px;
    margin-bottom: 8px !important;
}

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 5px !important;
}

.kpi-sub {
    color: #999;
    font-size: 12px;
}

/* KPI Icon Gradients */
.kpi-icon.primary { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.kpi-icon.success { background: linear-gradient(135deg, #4caf50 0%, #45a049 100%); }
.kpi-icon.danger { background: linear-gradient(135deg, #f44336 0%, #e53935 100%); }
.kpi-icon.warning { background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%); }
.kpi-icon.info { background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%); }
.kpi-icon.purple { background: linear-gradient(135deg, #9c27b0 0%, #7b1fa2 100%); }

/* ==========================================================================
   4. CHARTS SECTION
   ========================================================================== */

.charts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 30px;
    margin-bottom: 40px;
}

@media (max-width: 1200px) {
    .charts-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

.chart-container {
    background: white;
    padding: 25px;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
}

.chart-container h3 {
    margin: 0 0 20px 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.chart-wrapper {
    position: relative;
    height: 350px;
    width: 100%;
    margin-bottom: 10px;
}

/* ==========================================================================
   5. TABLES
   ========================================================================== */

.finance-table {
    width: 100%;
    border-collapse: collapse;
}

.finance-table thead {
    background: #f5f5f5;
    border-bottom: 2px solid #ddd;
}

.finance-table th {
    padding: 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.finance-table td {
    padding: 12px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
    color: #333;
}

.finance-table tbody tr:hover {
    background: #fafafa;
}

.finance-table th.text-right,
.finance-table td.text-right {
    text-align: right;
}

.finance-table th.text-center,
.finance-table td.text-center {
    text-align: center;
}

/* Analytics Tables (Dashboard) */
.analytics-section {
    background: white;
    padding: 25px;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    margin-bottom: 30px;
}

.analytics-section h3 {
    margin: 0 0 20px 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.analytics-table {
    width: 100%;
    border-collapse: collapse;
}

.analytics-table thead {
    background: #f5f5f5;
}

.analytics-table th {
    padding: 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    border-bottom: 1px solid #e0e0e0;
}

.analytics-table td {
    padding: 12px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}

.analytics-table tr:hover {
    background: #fafafa;
}

/* ==========================================================================
   6. FORMS
   ========================================================================== */

.finance-form {
    display: grid;
    gap: 20px;
}

.finance-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.finance-form-group {
    display: flex;
    flex-direction: column;
}

.finance-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.finance-form-group input,
.finance-form-group select,
.finance-form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.finance-form-group input:focus,
.finance-form-group select:focus,
.finance-form-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.finance-form-group textarea {
    min-height: 120px;
    resize: vertical;
    font-family: inherit;
}

/* ==========================================================================
   7. FILTERS
   ========================================================================== */

.finance-filter-section {
    background: white;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.finance-filter-grid {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.finance-filter-group {
    display: flex;
    flex-direction: column;
}

.finance-filter-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.finance-filter-group input,
.finance-filter-group select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    min-width: 150px;
    font-size: 14px;
}

/* ==========================================================================
   8. BUTTONS
   ========================================================================== */

.finance-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}

.finance-btn:hover {
    transform: translateY(-1px);
}

.finance-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.finance-btn-primary:hover {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.finance-btn-success {
    background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
    color: white;
}

.finance-btn-success:hover {
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

.finance-btn-danger {
    background: linear-gradient(135deg, #f44336 0%, #e53935 100%);
    color: white;
}

.finance-btn-danger:hover {
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.4);
}

.finance-btn-warning {
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
    color: white;
}

.finance-btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.finance-btn-secondary:hover {
    background: #d0d0d0;
}

.finance-btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.finance-btn-lg {
    padding: 14px 28px;
    font-size: 16px;
}

/* Icon-only buttons */
.finance-btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

/* Action link buttons (table actions) */
.finance-action-link {
    color: #667eea;
    margin: 0 5px;
    text-decoration: none;
    transition: color 0.2s ease;
}

.finance-action-link:hover {
    color: #764ba2;
}

.finance-action-link.danger {
    color: #f44336;
}

.finance-action-link.danger:hover {
    color: #e53935;
}

/* Button Groups */
.finance-btn-group {
    display: flex;
    gap: 10px;
}

/* ==========================================================================
   9. STATUS BADGES
   ========================================================================== */

.finance-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.finance-badge-paid,
.finance-badge-success {
    background: rgba(76, 175, 80, 0.15);
    color: #4caf50;
}

.finance-badge-pending,
.finance-badge-warning {
    background: rgba(255, 152, 0, 0.15);
    color: #ff9800;
}

.finance-badge-overdue,
.finance-badge-danger {
    background: rgba(244, 67, 54, 0.15);
    color: #f44336;
}

.finance-badge-draft,
.finance-badge-secondary {
    background: rgba(158, 158, 158, 0.15);
    color: #757575;
}

.finance-badge-sent,
.finance-badge-info {
    background: rgba(33, 150, 243, 0.15);
    color: #2196f3;
}

/* Status text colors (for tables) */
.status-paid { color: #4caf50; font-weight: 600; }
.status-pending { color: #ff9800; font-weight: 600; }
.status-overdue { color: #f44336; font-weight: 600; }

/* ==========================================================================
   10. ALERTS
   ========================================================================== */

.finance-alert {
    padding: 15px 20px;
    border-radius: 6px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.finance-alert i {
    font-size: 18px;
}

.finance-alert-success {
    background: #e8f5e9;
    border: 1px solid #4caf50;
    color: #2e7d32;
}

.finance-alert-danger {
    background: #ffebee;
    border: 1px solid #ef5350;
    color: #c62828;
}

.finance-alert-warning {
    background: #fff3e0;
    border: 1px solid #ff9800;
    color: #e65100;
}

.finance-alert-info {
    background: #e3f2fd;
    border: 1px solid #2196f3;
    color: #1565c0;
}

/* ==========================================================================
   11. EMPTY STATES
   ========================================================================== */

.finance-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.finance-empty-state i {
    font-size: 64px;
    display: block;
    margin-bottom: 20px;
    opacity: 0.5;
}

.finance-empty-state p {
    font-size: 16px;
    margin: 0;
}

/* ==========================================================================
   12. PAGINATION
   ========================================================================== */

.finance-pagination {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-top: 25px;
    flex-wrap: wrap;
}

.finance-pagination a,
.finance-pagination span {
    padding: 8px 14px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
}

.finance-pagination a {
    background: #e0e0e0;
    color: #333;
}

.finance-pagination a:hover {
    background: #667eea;
    color: white;
}

.finance-pagination span.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

/* ==========================================================================
   13. TREND CARDS (Dashboard Monthly Summary)
   ========================================================================== */

.trend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.trend-card {
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid;
}

.trend-card.revenue {
    background: #f0f7ff;
    border-left-color: #2196F3;
}

.trend-card.expenses {
    background: #fff3f0;
    border-left-color: #f44336;
}

.trend-card.profit {
    background: #f0fff3;
    border-left-color: #4caf50;
}

.trend-card.margin {
    background: #fff8f0;
    border-left-color: #ff9800;
}

.trend-label {
    margin: 0 0 8px 0;
    color: #666;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.trend-value {
    margin: 0 0 10px 0;
    font-size: 22px;
    font-weight: 700;
}

.trend-change {
    margin: 0;
    font-size: 12px;
}

.trend-change.positive { color: #4caf50; }
.trend-change.negative { color: #f44336; }

/* ==========================================================================
   14. INVOICE STATUS CARDS
   ========================================================================== */

.invoice-status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.invoice-status-card {
    padding: 20px;
    border-radius: 10px;
    text-align: center;
}

.invoice-status-card.paid {
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.invoice-status-card.pending {
    background: rgba(255, 152, 0, 0.1);
    border: 1px solid rgba(255, 152, 0, 0.3);
}

.invoice-status-card.overdue {
    background: rgba(244, 67, 54, 0.1);
    border: 1px solid rgba(244, 67, 54, 0.3);
}

.invoice-status-count {
    font-size: 32px;
    font-weight: 700;
    margin: 0 0 5px 0;
}

.invoice-status-label {
    font-size: 14px;
    color: #666;
    margin: 0;
}

/* ==========================================================================
   15. RESPONSIVE UTILITIES
   ========================================================================== */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .finance-page-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .finance-filter-grid {
        flex-direction: column;
    }
    
    .finance-filter-group input,
    .finance-filter-group select {
        width: 100%;
    }
    
    .finance-btn-group {
        flex-direction: column;
    }
    
    .kpi-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   16. DARK MODE SUPPORT
   ========================================================================== */

html.dark-mode .finance-card,
html.dark-mode .finance-filter-section,
html.dark-mode .chart-container,
html.dark-mode .analytics-section,
html.dark-mode .kpi-card {
    background: #2d2d2d;
    border-color: #444;
}

html.dark-mode .finance-card-title,
html.dark-mode .chart-container h3,
html.dark-mode .analytics-section h3 {
    color: #fff;
}

html.dark-mode .finance-form-group label,
html.dark-mode .finance-filter-group label {
    color: #ccc;
}

html.dark-mode .finance-form-group input,
html.dark-mode .finance-form-group select,
html.dark-mode .finance-form-group textarea,
html.dark-mode .finance-filter-group input,
html.dark-mode .finance-filter-group select {
    background: #3a3a3a;
    border-color: #555;
    color: #fff;
}

html.dark-mode .finance-table thead {
    background: #1a1a1a;
}

html.dark-mode .finance-table th {
    color: #aaa;
    border-bottom-color: #444;
}

html.dark-mode .finance-table td {
    border-bottom-color: #3a3a3a;
    color: #ccc;
}

html.dark-mode .finance-table tbody tr:hover {
    background: #353535;
}

html.dark-mode .analytics-table thead {
    background: #1a1a1a;
}

html.dark-mode .analytics-table th {
    color: #aaa;
    border-bottom-color: #444;
}

html.dark-mode .analytics-table td {
    border-bottom-color: #3a3a3a;
    color: #ccc;
}

html.dark-mode .analytics-table tr:hover {
    background: #353535;
}

html.dark-mode .kpi-label {
    color: #aaa;
}

html.dark-mode .kpi-value {
    color: #fff;
}

html.dark-mode .kpi-sub {
    color: #777;
}

html.dark-mode .finance-btn-secondary {
    background: #3a3a3a;
    color: #ccc;
}

html.dark-mode .finance-pagination a {
    background: #3a3a3a;
    color: #ccc;
}

html.dark-mode .finance-empty-state {
    color: #777;
}

/* Dark mode trend cards */
html.dark-mode .trend-card.revenue { background: #1a2a3a; }
html.dark-mode .trend-card.expenses { background: #3a1a1a; }
html.dark-mode .trend-card.profit { background: #1a3a1a; }
html.dark-mode .trend-card.margin { background: #3a2a1a; }

html.dark-mode .trend-label { color: #888; }

/* ==========================================================================
   17. PRINT STYLES
   ========================================================================== */

@media print {
    .finance-filter-section,
    .finance-btn,
    .finance-action-link,
    .finance-pagination {
        display: none !important;
    }
    
    .finance-card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    .finance-table {
        font-size: 12px;
    }
}
