/* Reset & Base */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; background-color: #f4f6f8; color: #333; height: 100vh; overflow: hidden; }

/* Layout */
.app-container { display: flex; flex-direction: column; height: 100vh; }

/* Top Bar */
.top-bar { background-color: #ffffff; height: 60px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 4px rgba(0,0,0,0.05); z-index: 10; }
.top-bar h1 { font-size: 1.25rem; color: #007bff; display: flex; align-items: center; gap: 10px; }
.user-info { display: flex; align-items: center; gap: 20px; font-size: 0.9rem; }
.logout-btn { color: #dc3545; text-decoration: none; display: flex; align-items: center; gap: 5px; }
.logout-btn:hover { text-decoration: underline; }

/* Main Content */
.main-content { display: flex; flex: 1; overflow: hidden; }

/* Sidebar */
.sidebar { width: 250px; background-color: #2c3e50; color: #ecf0f1; display: flex; flex-direction: column; padding-top: 20px; }
.nav-btn { background: none; border: none; color: #bdc3c7; padding: 15px 20px; text-align: left; width: 100%; cursor: pointer; font-size: 1rem; display: flex; align-items: center; gap: 10px; transition: all 0.2s; }
.nav-btn:hover { background-color: #34495e; color: white; }
.nav-btn.active { background-color: #007bff; color: white; border-right: 4px solid #0056b3; }

/* Content Area */
.content-area { flex: 1; padding: 20px; overflow-y: auto; position: relative; }

/* Filters Panel */
.filters-panel { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); margin-bottom: 20px; }
.filters-panel h3 { font-size: 1rem; margin-bottom: 15px; color: #555; border-bottom: 1px solid #eee; padding-bottom: 10px; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; }
.filter-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 5px; color: #666; }
.filter-group input, .filter-group select { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 0.9rem; }
.filter-group select { height: 80px; } /* Multiple select height */
.date-inputs, .range-inputs { display: flex; align-items: center; gap: 5px; }
.separator { color: #999; font-size: 0.8rem; }

.filter-actions { margin-top: 20px; display: flex; gap: 10px; justify-content: flex-end; }
.btn { padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; font-size: 0.9rem; display: inline-flex; align-items: center; gap: 8px; transition: background 0.2s; }
.btn.primary { background-color: #007bff; color: white; }
.btn.primary:hover { background-color: #0069d9; }
.btn.secondary { background-color: #6c757d; color: white; }
.btn.secondary:hover { background-color: #5a6268; }
.btn.calc-btn { background-color: #28a745; color: white; }
.btn.calc-btn:hover { background-color: #218838; }
.btn.export-btn { background-color: #17a2b8; color: white; }
.btn.export-btn:hover { background-color: #138496; }

/* Views */
.view-section { display: none; }
.view-section.active { display: block; animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.section-header h2 { font-size: 1.5rem; color: #333; }
.info-text { font-size: 0.9rem; color: #666; margin-bottom: 10px; background: #e9ecef; padding: 10px; border-radius: 4px; border-left: 4px solid #17a2b8; }

/* Tables */
.table-container { background: white; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); overflow-x: auto; max-height: calc(100vh - 350px); }
.data-table { width: 100%; border-collapse: collapse; min-width: 1000px; }
.data-table th, .data-table td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #eee; font-size: 0.9rem; }
.data-table th { background-color: #f8f9fa; font-weight: 600; color: #555; position: sticky; top: 0; z-index: 1; box-shadow: 0 2px 2px rgba(0,0,0,0.05); }

/* Sortable Headers */
th.sortable {
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: background-color 0.2s;
}
th.sortable:hover {
    background-color: #e2e6ea;
}
th.sortable i {
    font-size: 0.8em;
    margin-left: 5px;
    color: #adb5bd;
}
th.sortable.asc i {
    color: #007bff;
    transform: rotate(0deg); /* Explicit for clarity */
}
th.sortable.desc i {
    color: #007bff;
    transform: rotate(180deg); /* Flip icon if using simple arrow, or just change icon class */
}
/* We use fa-sort, fa-sort-up, fa-sort-down logic in JS, but let's keep basic styling */

.data-table tbody tr:hover { background-color: #f1f3f5; }
.data-table td input { width: 100%; padding: 4px; border: 1px solid transparent; background: transparent; }
.data-table td input:focus { border-color: #007bff; background: white; outline: none; }
.data-table td input:hover { border-color: #ddd; }
.data-table .actions-cell button { background: none; border: none; color: #dc3545; cursor: pointer; padding: 5px; }
.data-table .actions-cell button:hover { background: #fee; border-radius: 4px; }

/* Totals Row */
.data-table tfoot tr { background-color: #e9ecef; font-weight: bold; }
.data-table tfoot td { border-top: 2px solid #dee2e6; }

/* Loading Spinner */
.spinner-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,0.8); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 1000; }
.spinner { border: 4px solid #f3f3f3; border-top: 4px solid #007bff; border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin-bottom: 15px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.alert { padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; }
.alert.warning { color: #856404; background-color: #fff3cd; border-color: #ffeeba; }

/* Responsive */
@media (max-width: 1024px) {
    .filters-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .app-container { flex-direction: column; height: auto; }
    .sidebar { width: 100%; flex-direction: row; overflow-x: auto; padding: 0; }
    .nav-btn { flex: 0 0 auto; width: auto; border-right: none; border-bottom: 4px solid transparent; }
    .nav-btn.active { border-right: none; border-bottom: 4px solid #007bff; }
    .main-content { overflow: visible; display: block; }
    .content-area { padding: 10px; height: auto; overflow-y: visible; }
    
    .filters-grid { grid-template-columns: 1fr; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .section-header .actions { width: 100%; display: flex; gap: 10px; }
    .section-header .actions button { flex: 1; }
    
    .filter-actions { flex-direction: column; }
    .filter-actions button { width: 100%; justify-content: center; }
}
