@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ========== Layout Variables ========== */

:root {
    --primary: #0d6efd;
    --primary-hover: #0b5ed7;
    --primary-active: #0a58ca;
    --primary-light: #e8f0fe;
    --primary-rgb: 13, 110, 253;
    --sidebar-width: 260px;
    --sidebar-bg: #0d6efd;
    --content-bg: #f5f6fa;
    --nav-link-color: rgba(255, 255, 255, 0.8);
    --nav-active-bg: rgba(255, 255, 255, 0.18);
    --nav-active-color: #ffffff;
}

[data-bs-theme="dark"] {
    --sidebar-bg: #0a58ca;
    --content-bg: #16181d;
    --nav-link-color: rgba(255, 255, 255, 0.75);
    --nav-active-bg: rgba(255, 255, 255, 0.15);
    --nav-active-color: #ffffff;
    --primary-light: rgba(13, 110, 253, 0.12);
}

/* ========== Global ========== */

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--content-bg);
    min-height: 100vh;
}

/* ========== Bootstrap Primary Color Overrides ========== */

.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-hover);
    --bs-btn-hover-border-color: var(--primary-hover);
    --bs-btn-active-bg: var(--primary-active);
    --bs-btn-active-border-color: var(--primary-active);
    --bs-btn-focus-shadow-rgb: var(--primary-rgb);
}

.btn-outline-primary {
    --bs-btn-color: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary);
    --bs-btn-hover-border-color: var(--primary);
    --bs-btn-active-bg: var(--primary);
    --bs-btn-active-border-color: var(--primary);
}

.text-primary { color: var(--primary) !important; }
.bg-primary { background-color: var(--primary) !important; }
.border-primary { border-color: var(--primary) !important; }
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

.badge.bg-primary { background-color: var(--primary) !important; }

/* ========== Cards ========== */

.card {
    border: none !important;
    border-radius: 16px !important;
    box-shadow: 0 2px 14px rgba(0, 0, 0, .06);
}

[data-bs-theme="dark"] .card {
    box-shadow: 0 2px 14px rgba(0, 0, 0, .25);
}

/* ========== Sidebar ========== */

.sidebar {
    display: none;
    flex-direction: column;
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--bs-border-color);
    padding: 20px 16px;
    overflow-y: auto;
    z-index: 1040;
    transition: transform 0.3s ease;
}

body.authenticated .sidebar {
    display: flex;
}

/* Sidebar Brand / Logo */

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 4px 18px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px solid var(--bs-border-color);
    margin-bottom: 10px;
}

.sidebar-brand:hover {
    color: var(--primary-hover);
    text-decoration: none;
}

.sidebar-brand i {
    font-size: 1.5rem;
}

/* Sidebar Nav Links */

.sidebar .nav-link {
    color: var(--nav-link-color);
    border-radius: 10px;
    margin-bottom: 3px;
    padding: 9px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.875rem;
    font-weight: 400;
    transition: background 0.15s, color 0.15s;
}

.sidebar .nav-link i {
    font-size: 1rem;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar .nav-link:hover {
    background: var(--nav-active-bg);
    color: var(--nav-active-color);
}

.sidebar .nav-link.active {
    background: var(--nav-active-bg);
    color: var(--nav-active-color);
    font-weight: 500;
}

/* Sidebar Nav grows to push footer down */
.sidebar > .nav.flex-column {
    flex: 1;
    overflow-y: auto;
}

/* Sidebar Footer */

.sidebar-footer {
    padding-top: 14px;
    border-top: 1px solid var(--bs-border-color);
    flex-shrink: 0;
}

.sidebar-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--primary-light);
    margin-bottom: 10px;
    min-width: 0;
}

.sidebar-user-info .user-avatar {
    font-size: 2rem;
    color: var(--primary);
    line-height: 1;
    flex-shrink: 0;
}

.user-avatar-img {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}

.sidebar-user-info .user-name {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--bs-body-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-info .user-email {
    font-size: 0.7rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 155px;
}

/* ========== Content Area ========== */

.content {
    padding: 24px;
    min-height: 100vh;
    font-size: 0.875rem;
    font-family: 'Inter', system-ui, sans-serif;
}

.content h1 { font-size: 1.5rem; }
.content h2 { font-size: 1.25rem; }
.content h3 { font-size: 1.1rem; }
.content h4 { font-size: 1rem; }
.content h5, .content .card-title { font-size: 0.9375rem; }
.content h6 { font-size: 0.875rem; }

body.authenticated .content {
    margin-left: var(--sidebar-width);
}

body:not(.authenticated) .content {
    padding-top: 6vh;
}

.content-footer {
    text-align: center;
    padding: 1.5rem 0 0.5rem;
    color: var(--bs-secondary-color);
    font-size: 0.75rem;
    margin-top: 2rem;
    border-top: 1px solid var(--bs-border-color);
}

/* ========== Mobile Topbar ========== */

.mobile-topbar {
    display: flex;
    align-items: center;
    background: var(--sidebar-bg);
    padding: 12px 16px;
    border-radius: 14px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .06);
    margin-bottom: 18px;
    border: 1px solid var(--bs-border-color);
}

/* ========== Sidebar Overlay (mobile) ========== */

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1039;
}

.sidebar-overlay.show {
    display: block;
}

/* ========== Theme Toggle ========== */

.theme-toggle {
    background: transparent;
    border: 1px solid var(--bs-border-color);
    color: var(--nav-link-color);
    font-size: 0.95rem;
    padding: 0.3rem 0.55rem;
    border-radius: 8px;
    cursor: pointer;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.theme-toggle:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

/* ========== Responsive (mobile) ========== */

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    body.authenticated .content {
        margin-left: 0;
    }
    body:not(.authenticated) .content {
        padding-top: 4vh;
    }
}

@media (min-width: 992px) {
    .mobile-topbar {
        display: none !important;
    }
    body.authenticated .sidebar {
        transform: none !important;
    }
}

/* ========== Sidebar — blue background overrides ========== */

.sidebar {
    border-right-color: rgba(255, 255, 255, 0.12);
}

.sidebar-brand {
    color: #ffffff;
    border-bottom-color: rgba(255, 255, 255, 0.2);
}

.sidebar-brand:hover {
    color: rgba(255, 255, 255, 0.85);
}

.sidebar-footer {
    border-top-color: rgba(255, 255, 255, 0.2);
}

.sidebar-user-info {
    background: rgba(255, 255, 255, 0.12);
}

.sidebar-user-info .user-name {
    color: #ffffff;
}

.sidebar-user-info .user-email {
    color: rgba(255, 255, 255, 0.65);
}

.sidebar-user-info .user-avatar {
    color: rgba(255, 255, 255, 0.85);
}

.sidebar .theme-toggle {
    border-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.8);
}

.sidebar .theme-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.55);
}

/* Active language button: white pill on blue background */
.sidebar .btn-primary {
    background-color: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(255, 255, 255, 0.9) !important;
    color: var(--primary) !important;
}

.sidebar .btn-primary:hover {
    background-color: #ffffff !important;
    color: var(--primary-hover) !important;
}

/* Outline buttons (profile, logout, inactive lang) on blue background */
.sidebar .btn-outline-secondary,
.sidebar .btn-outline-danger {
    --bs-btn-color: rgba(255, 255, 255, 0.8);
    --bs-btn-border-color: rgba(255, 255, 255, 0.35);
    --bs-btn-hover-bg: rgba(255, 255, 255, 0.15);
    --bs-btn-hover-color: #ffffff;
    --bs-btn-hover-border-color: rgba(255, 255, 255, 0.6);
    --bs-btn-active-bg: rgba(255, 255, 255, 0.2);
    --bs-btn-active-color: #ffffff;
}

/* ========== Upload zone ========== */

.upload-zone {
    border: 3px dashed #dee2e6;
    border-radius: 12px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: #f8f9fa;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary);
    background-color: var(--primary-light);
}

.upload-zone.has-file {
    border-color: #198754;
    background-color: #e8f5e9;
}

/* ========== Results table ========== */

.results-table th {
    white-space: nowrap;
}

.results-table td {
    vertical-align: middle;
}

.table-danger-subtle {
    background-color: #fff0f0 !important;
}

.bg-success-subtle {
    background-color: #e8f5e9 !important;
}

.bg-danger-subtle {
    background-color: #fce4e4 !important;
}

/* ========== Analysis content ========== */

.analysis-content {
    font-size: 1rem;
    line-height: 1.7;
}

.analysis-content h3,
.analysis-content h4,
.analysis-content h5 {
    color: var(--primary);
}

.analysis-content ul {
    padding-left: 1.5rem;
}

.analysis-content li {
    margin-bottom: 0.3rem;
}

/* ========== Trend chart container ========== */

#trendChartContainer {
    min-height: 200px;
}

/* ========== Results summary badges ========== */

.results-summary .badge {
    font-size: 0.75rem;
    font-weight: 500;
}

/* ========== Range bar classes ========== */

.range-bar-bg {
    background: #e9ecef;
}

.range-bar-norm {
    background: #c3e6cb;
}

/* ========== Dark mode overrides ========== */

[data-bs-theme="dark"] .upload-zone {
    background-color: #1a1d21;
    border-color: #495057;
}

[data-bs-theme="dark"] .upload-zone:hover,
[data-bs-theme="dark"] .upload-zone.drag-over {
    border-color: var(--primary);
    background-color: var(--primary-light);
}

[data-bs-theme="dark"] .upload-zone.has-file {
    border-color: #198754;
    background-color: #1a2e1a;
}

[data-bs-theme="dark"] .table-danger-subtle {
    background-color: #2c1215 !important;
}

[data-bs-theme="dark"] .bg-success-subtle {
    background-color: #1a2e1a !important;
}

[data-bs-theme="dark"] .bg-danger-subtle {
    background-color: #2c1215 !important;
}

[data-bs-theme="dark"] .analysis-content h3,
[data-bs-theme="dark"] .analysis-content h4,
[data-bs-theme="dark"] .analysis-content h5 {
    color: #a08cff;
}

[data-bs-theme="dark"] .range-bar-bg {
    background: #495057;
}

[data-bs-theme="dark"] .range-bar-norm {
    background: #2d6a4f;
}

[data-bs-theme="dark"] .mobile-topbar {
    box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
}

/* ========== Responsive tweaks ========== */

@media (max-width: 768px) {
    .upload-zone {
        padding: 2rem 1rem;
    }

    .upload-zone .display-1 {
        font-size: 3rem;
    }

    .results-table {
        font-size: 0.875rem;
    }

    .content {
        padding: 16px;
    }
}

/* ========== Sidebar divider ========== */
.sidebar-divider {
    border-color: rgba(255, 255, 255, 0.2);
    margin: 8px 16px;
}
