/* =================================================================
   SOFUN TRACKER - MAIN CSS
   Core layout, variables, and foundational styles
   ================================================================= */

/* ---------- CSS Reset & Variables ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-color: #f8f9fa;
    --text-color: #2c3e50;
    --card-bg: rgba(255, 255, 255, 0.95);
    --shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

/* ---------- Core Layout ---------- */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--primary-gradient);
    min-height: 100vh;
    padding: 20px;
    transition: all 0.3s ease;
    position: relative;
    overflow-x: hidden;
}

/* ---------- Decorative Background ---------- */
#decorative-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: auto;
    opacity: 0.4;
    transition: opacity 0.3s ease;
}

body.dark-mode #decorative-background {
    opacity: 0.3;
}

/* Reduce intensity on mobile for better performance */
@media (max-width: 768px) {
    #decorative-background {
        opacity: 0.2;
    }
    
    body.dark-mode #decorative-background {
        opacity: 0.15;
    }
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: var(--card-bg);
    border-radius: 20px;
    padding: 30px;
    box-shadow: var(--shadow);
}

/* ---------- Header Section ---------- */
.header {
    text-align: center;
    margin-bottom: 30px;
    color: var(--text-color);
    position: relative;
}

.header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    background: linear-gradient(45deg, #3498db, #2980b9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header p {
    font-size: 1.1em;
    opacity: 0.8;
    margin-bottom: 10px;
}

/* ---------- Main Sections ---------- */
.import-section {
    background: var(--bg-color);
    padding: 25px;
    border-radius: 15px;
    margin-bottom: 30px;
    border: 2px dashed #ced4da;
}

.import-section h3 {
    color: var(--text-color);
    margin-bottom: 15px;
    font-size: 1.2em;
}

.search-filter-section {
    background: var(--bg-color);
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 30px;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: end;
}

.charts-section {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 15px;
    margin-bottom: 30px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.charts-section h2 {
    color: var(--text-color);
    margin-bottom: 20px;
    font-size: 1.8em;
}

/* ---------- Chart Selection Panel ---------- */
.chart-selection-panel {
    background: rgba(52, 152, 219, 0.05);
    border: 2px solid rgba(52, 152, 219, 0.2);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 25px;
}

.chart-selection-panel h3 {
    color: var(--text-color);
    margin-bottom: 15px;
    font-size: 1.2em;
    font-weight: 600;
}

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

.chart-selection-group {
    background: white;
    border-radius: 8px;
    padding: 15px;
    border: 1px solid #e9ecef;
}

.chart-selection-group h4 {
    color: var(--text-color);
    margin-bottom: 12px;
    font-size: 1em;
    font-weight: 600;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 8px;
}

.chart-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chart-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s ease;
    padding: 5px;
    border-radius: 4px;
}

.chart-option:hover {
    background: rgba(52, 152, 219, 0.1);
}

.chart-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #3498db;
    cursor: pointer;
}

.chart-option span {
    color: var(--text-color);
    font-weight: 500;
}

.chart-selection-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    border-top: 1px solid #e9ecef;
    padding-top: 15px;
}

.chart-selection-actions .btn {
    font-size: 0.85em;
    padding: 8px 16px;
}

.chart-wrapper {
    transition: all 0.3s ease;
}

.chart-wrapper.hidden {
    display: none !important;
}

.tables-section {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.tables-section h2 {
    color: var(--text-color);
    margin-bottom: 20px;
    font-size: 1.8em;
}

/* ---------- Grid Layouts ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
}

/* ---------- Statistics Cards ---------- */
.stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-card h3 {
    font-size: 1.1em;
    margin-bottom: 10px;
    opacity: 0.9;
}

.stat-card .number {
    font-size: 2.2em;
    font-weight: bold;
}

/* ---------- Charts ---------- */
.chart-container {
    position: relative;
    height: 300px;
}

.chart-title {
    text-align: center;
    color: var(--text-color);
    margin-bottom: 15px;
    font-weight: 600;
    font-size: 1.1em;
}

/* ---------- Search & Filters ---------- */
.search-box {
    flex: 1;
    min-width: 300px;
}

.search-box input {
    width: 100%;
    padding: 12px 20px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    font-size: 1em;
    transition: border-color 0.3s ease;
}

.search-box input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.filter-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-select {
    padding: 10px 15px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 0.9em;
    transition: border-color 0.3s ease;
}

.filter-select:focus {
    outline: none;
    border-color: #3498db;
}

/* ---------- Controls ---------- */
.controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9em;
}

.control-group input, 
.control-group select {
    padding: 10px 15px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    font-size: 0.9em;
    transition: border-color 0.3s ease;
}

.control-group input:focus,
.control-group select:focus {
    outline: none;
    border-color: #3498db;
}

/* File Upload Container */
.file-upload-container {
    display: flex;
    gap: 12px;
    align-items: stretch;
    margin: 10px 0;
}

.file-upload-container input[type="file"] {
    flex: 1;
    min-width: 250px;
    padding: 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-color);
    color: var(--text-color);
    font-size: 0.9em;
    height: auto;
}

.file-upload-container input[type="file"]:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.file-upload-container .btn {
    height: auto;
    padding: 10px 20px;
    white-space: nowrap;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* File Status Display */
.file-status {
    margin: 8px 0;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 500;
    transition: all 0.3s ease;
}

.file-status.ready {
    background: rgba(52, 152, 219, 0.1);
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

.file-status.processing {
    background: rgba(243, 156, 18, 0.1);
    color: #f39c12;
    border: 1px solid #f39c12;
}

.file-status.success {
    background: rgba(39, 174, 96, 0.1);
    color: var(--success-color);
    border: 1px solid var(--success-color);
}

.file-status.error {
    background: rgba(231, 76, 60, 0.1);
    color: var(--error-color);
    border: 1px solid var(--error-color);
}



/* ---------- Tables ---------- */
.table-container {
    overflow-x: auto;
    margin-top: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    background: white;
}

th, td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #e9ecef;
    font-size: 0.9em;
}

th {
    background: var(--bg-color);
    font-weight: 600;
    color: var(--text-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

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

tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.01);
}

.phase-header {
    background: #e9ecef !important;
    text-align: center !important;
    font-weight: bold !important;
    color: #495057 !important;
}

/* ---------- Category Tabs ---------- */
.category-tabs {
    display: flex;
    background: var(--bg-color);
    border-radius: 10px;
    padding: 5px;
    margin-bottom: 20px;
}

.category-tab {
    flex: 1;
    padding: 15px 20px;
    text-align: center;
    background: transparent;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    color: #6c757d;
    font-size: 0.95em;
}

.category-tab.active {
    background: linear-gradient(45deg, #3498db, #2980b9);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.category-tab:hover:not(.active) {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
}

.category-content {
    display: none;
}

.category-content.active {
    display: block;
}

.category-content h3 {
    color: var(--text-color);
    margin-bottom: 15px;
    font-size: 1.3em;
}

/* ---------- Bulk Actions ---------- */
.bulk-actions {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    display: none;
    border: 2px solid #3498db;
}

.bulk-actions.active {
    display: block;
}

.bulk-actions h4 {
    color: var(--text-color);
    margin-bottom: 10px;
    font-size: 1.1em;
}

#selectedCount {
    margin-left: 15px;
    font-weight: 600;
    color: #3498db;
}

/* ---------- Audit Log ---------- */
.audit-log {
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-color);
    padding: 15px;
    border-radius: 8px;
    margin-top: 20px;
    font-size: 0.85em;
    border: 1px solid #e9ecef;
}

.audit-entry {
    padding: 5px 0;
    border-bottom: 1px solid #e9ecef;
    color: var(--text-color);
}

.audit-entry:last-child {
    border-bottom: none;
}

/* ---------- Advanced Audit Log ---------- */
.audit-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(52, 152, 219, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(52, 152, 219, 0.2);
    flex-wrap: wrap;
    gap: 10px;
}

.audit-filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.audit-filters select {
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    background: white;
    font-size: 0.9em;
    min-width: 120px;
}

.audit-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.audit-actions .btn {
    font-size: 0.85em;
    padding: 8px 12px;
}

.advanced-audit-log {
    background: #1e1e1e;
    border-radius: 8px;
    padding: 15px;
    max-height: 600px;
    overflow-y: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85em;
    color: #d4d4d4;
    border: 1px solid #3e3e3e;
}

.advanced-audit-entry {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 6px;
    border-left: 4px solid #666;
    background: rgba(255, 255, 255, 0.02);
    transition: all 0.2s ease;
}

.advanced-audit-entry:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(2px);
}

.advanced-audit-entry.audit-level-error {
    border-left-color: #f85149;
    background: rgba(248, 81, 73, 0.1);
}

.advanced-audit-entry.audit-level-warn {
    border-left-color: #d29922;
    background: rgba(210, 153, 34, 0.1);
}

.advanced-audit-entry.audit-level-info {
    border-left-color: #58a6ff;
    background: rgba(88, 166, 255, 0.1);
}

.advanced-audit-entry.audit-level-debug {
    border-left-color: #8b949e;
    background: rgba(139, 148, 158, 0.05);
}

.audit-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-weight: 600;
    flex-wrap: wrap;
}

.audit-icon {
    font-size: 1.1em;
}

.audit-category {
    color: #58a6ff;
    font-weight: bold;
}

.audit-level {
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.8em;
    font-weight: bold;
    text-transform: uppercase;
    color: white;
    background: #666;
}

.audit-time {
    color: #7d8590;
    font-size: 0.9em;
    font-family: monospace;
}

.audit-timestamp {
    color: #7d8590;
    font-size: 0.8em;
    margin-left: auto;
}

.audit-message {
    color: #e6edf3;
    margin-bottom: 8px;
    line-height: 1.4;
}

.audit-details, .audit-stack {
    margin-top: 8px;
}

.audit-details summary, .audit-stack summary {
    color: #58a6ff;
    cursor: pointer;
    font-size: 0.9em;
    margin-bottom: 5px;
}

.audit-details-content, .audit-stack-content {
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 4px;
    font-size: 0.8em;
    line-height: 1.3;
    color: #d4d4d4;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    border: 1px solid #30363d;
}

.audit-stack-content {
    color: #f85149;
    background: rgba(248, 81, 73, 0.1);
}

.audit-summary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.audit-summary h4 {
    margin-bottom: 15px;
    font-size: 1.2em;
}

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

.audit-summary-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 12px;
    border-radius: 6px;
    text-align: center;
}

.audit-summary-item .number {
    font-size: 1.5em;
    font-weight: bold;
    display: block;
}

.audit-summary-item .label {
    font-size: 0.9em;
    opacity: 0.8;
}

.audit-loading {
    text-align: center;
    padding: 40px;
    color: #7d8590;
    font-style: italic;
}

.legacy-audit-section {
    margin-top: 20px;
    padding: 15px;
    background: rgba(139, 148, 158, 0.05);
    border-radius: 8px;
}

.legacy-audit-section summary {
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    margin-bottom: 10px;
}

/* Mobile responsiveness for audit controls */
@media (max-width: 768px) {
    .audit-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .audit-filters {
        justify-content: center;
        margin-bottom: 10px;
    }
    
    .audit-actions {
        justify-content: center;
    }
    
    .advanced-audit-log {
        max-height: 400px;
        font-size: 0.8em;
    }
    
    .audit-header {
        font-size: 0.9em;
    }
}

/* ---------- Print Styles ---------- */
@media print {
    body {
        background: white !important;
        padding: 0;
    }
    
    .container {
        box-shadow: none;
        padding: 20px;
        background: white !important;
    }
    
    .btn, 
    .controls, 
    .search-filter-section, 
    .import-section, 
    .dark-mode-toggle,
    .bulk-actions {
        display: none !important;
    }
    
    .charts-section {
        page-break-inside: avoid;
    }
    
    table {
        page-break-inside: avoid;
    }
    
    .stat-card {
        break-inside: avoid;
    }
}

/* ---------- Mobile Responsive ---------- */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 15px;
    }
    
    .header h1 {
        font-size: 2em;
    }
    
    .controls {
        flex-direction: column;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
    
    th, td {
        padding: 6px 8px;
        font-size: 0.8em;
    }
    
    .search-filter-section {
        flex-direction: column;
    }
    
    .search-box {
        min-width: 100%;
    }
    
    .filter-controls {
        justify-content: stretch;
    }
    
    .filter-select {
        flex: 1;
    }
    
    .category-tabs {
        flex-direction: column;
        gap: 5px;
    }
    
    .stat-card .number {
        font-size: 1.8em;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.8em;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    .stat-card h3 {
        font-size: 0.9em;
    }
    
    .stat-card .number {
        font-size: 1.5em;
    }
}