/* ===== CSS Custom Properties ===== */
:root {
    --sidebar-bg: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-active: #3b82f6;
    --sidebar-hover: #334155;
    --sidebar-width: 260px;
    --content-bg: #f8fafc;
    --card-bg: #ffffff;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --card-shadow-hover: 0 4px 12px rgba(0,0,0,0.1);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --accent: #3b82f6;
    --accent-light: #dbeafe;
    --success: #10b981;
    --success-light: #d1fae5;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
}

/* ===== Reset ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    color: var(--text-primary);
    background: var(--content-bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ===== Login Overlay ===== */
.login-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color var(--transition);
    outline: none;
}

.form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.login-error {
    background: var(--danger-light);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}

.btn-login {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

.btn-login:hover {
    background: #2563eb;
}

.btn-login:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* ===== Auth Status ===== */
.auth-status {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    padding: 20px 0;
}

.auth-status .spinner {
    margin: 0 auto 16px;
}

.auth-status p {
    margin: 0;
}

/* ===== App Shell ===== */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-header h2 {
    color: #fff;
    font-size: 20px;
    font-weight: 700;
}

.sidebar-subtitle {
    font-size: 12px;
    color: var(--sidebar-text);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-list {
    list-style: none;
    padding: 12px 0;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: var(--sidebar-hover);
    color: #e2e8f0;
}

.nav-link.active {
    background: rgba(59,130,246,0.1);
    color: var(--sidebar-active);
    border-left-color: var(--sidebar-active);
}

.nav-icon {
    font-size: 18px;
    margin-right: 12px;
    width: 24px;
    text-align: center;
}

/* ===== Sidebar Firmen-Filter ===== */
.sidebar-filter {
    padding: 12px 20px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.filter-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--sidebar-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.filter-select {
    width: 100%;
    padding: 7px 10px;
    background: var(--sidebar-hover);
    color: #e2e8f0;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    outline: none;
}

.filter-select:focus {
    border-color: var(--sidebar-active);
}

.filter-select option {
    background: var(--sidebar-bg);
    color: #e2e8f0;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.firma-info {
    font-size: 12px;
    color: var(--sidebar-text);
    margin-bottom: 10px;
}

.btn-logout {
    width: 100%;
    padding: 8px;
    background: transparent;
    color: var(--sidebar-text);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-logout:hover {
    background: rgba(239,68,68,0.15);
    color: var(--danger);
    border-color: var(--danger);
}

/* ===== Menu Toggle (Mobile) ===== */
.menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: var(--sidebar-bg);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 20px;
    cursor: pointer;
}

/* ===== Main Content ===== */
.content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    min-height: 100vh;
}

/* ===== Loading ===== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 0;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Error Toast ===== */
.error-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--danger);
    color: #fff;
    padding: 14px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    z-index: 2000;
    max-width: 400px;
    box-shadow: 0 8px 24px rgba(239,68,68,0.3);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ===== Page Header ===== */
.page-header {
    margin-bottom: 28px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.page-header p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

/* ===== KPI Cards ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.kpi-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--card-shadow);
    transition: box-shadow var(--transition);
}

.kpi-card:hover {
    box-shadow: var(--card-shadow-hover);
}

.kpi-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}

.kpi-delta {
    font-size: 13px;
    font-weight: 600;
    margin-top: 6px;
}

.kpi-delta.positive {
    color: var(--success);
}

.kpi-delta.negative {
    color: var(--danger);
}

/* ===== Cards / Panels ===== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--card-shadow);
    margin-bottom: 24px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.card-grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

/* ===== Chart Container ===== */
.chart-container {
    position: relative;
    width: 100%;
    max-height: 400px;
}

.chart-container-sm {
    position: relative;
    width: 100%;
    max-height: 300px;
}

/* ===== Tables ===== */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.data-table th:hover {
    color: var(--accent);
}

.data-table th.sorted-asc::after {
    content: ' \25B2';
    font-size: 10px;
}

.data-table th.sorted-desc::after {
    content: ' \25BC';
    font-size: 10px;
}

.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.data-table tbody tr {
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: var(--accent-light);
}

.data-table tbody tr.clickable {
    cursor: pointer;
}

.data-table .text-right {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ===== Search Input ===== */
.search-input {
    width: 100%;
    max-width: 360px;
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    margin-bottom: 16px;
    transition: border-color var(--transition);
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* ===== Select ===== */
.select-input {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    background: var(--card-bg);
    cursor: pointer;
    transition: border-color var(--transition);
}

.select-input:focus {
    border-color: var(--accent);
}

/* ===== Growth Cards ===== */
.growth-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.growth-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--card-shadow);
    text-align: center;
}

.growth-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 6px;
}

.growth-value {
    font-size: 24px;
    font-weight: 700;
}

.growth-value.positive {
    color: var(--success);
}

.growth-value.negative {
    color: var(--danger);
}

.growth-value.neutral {
    color: var(--text-muted);
}

/* ===== Toolbar ===== */
.toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

/* ===== Filter Reset Button ===== */
.btn-filter-reset {
    padding: 7px 14px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-filter-reset:hover {
    background: var(--danger-light);
    color: var(--danger);
    border-color: var(--danger);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--danger);
}

.modal-body {
    padding: 24px;
}

/* ===== Badge ===== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-toggle {
        display: block;
    }

    .content {
        margin-left: 0;
        padding: 16px;
        padding-top: 56px;
    }

    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

    .card-grid-3 {
        grid-template-columns: 1fr;
    }

    .modal-content {
        width: 95%;
    }
}

@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr 1fr;
    }

    .kpi-value {
        font-size: 22px;
    }

    .growth-grid {
        grid-template-columns: 1fr 1fr;
    }
}
