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

:root {
    --bg-color: #0f172a;
    --sidebar-bg: rgba(30, 41, 59, 0.8);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --accent-primary: #8b5cf6;
    --accent-secondary: #06b6d4;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --table-container-bg: rgba(15, 23, 42, 0.1);
    --sidebar-width: 220px;
    --sidebar-collapsed-width: 60px;
    --header-height: 38px;
    --footer-height: 28px;
    --transition-speed: 0.3s;
}

.text-muted {
    color: var(--text-muted) !important;
}

[data-theme='light'] {
    --bg-color: #f1f5f9;
    --sidebar-bg: rgba(255, 255, 255, 0.8);
    --glass-bg: rgba(0, 0, 0, 0.03);
    --glass-border: rgba(0, 0, 0, 0.1);
    --text-main: #1e293b;
    --text-muted: #64748b;
    --table-container-bg: rgba(255, 255, 255, 0.6);
    --accent-primary: #7c3aed;
    --accent-secondary: #0891b2;
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(at 0% 0%, rgba(139, 92, 246, 0.1) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.1) 0px, transparent 50%);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* Layout Containers */
.main-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--glass-border);
    padding: 0.5rem 0.4rem;
    z-index: 1000;
    transition: width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1), transform var(--transition-speed);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.content-area {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0; /* Critical for flex child overflow */
    transition: margin-left var(--transition-speed) ease;
    overflow-x: hidden;
}

.sidebar.collapsed+.content-area {
    margin-left: var(--sidebar-collapsed-width);
}

.header {
    height: var(--header-height);
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 900;
}

.header-user-text {
    color: inherit;
}

.header-user-link {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-speed);
}

.header-user-link:hover {
    color: var(--accent-secondary);
}


.page-container {
    padding: 0.5rem 1rem;
    flex: 1;
}

.footer {
    height: var(--footer-height);
    background: var(--glass-bg);
    border-top: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Sidebar Elements */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    padding: 0 0.25rem;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
}

.sidebar.collapsed .sidebar-title {
    display: none;
}

.nav-link-custom {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.6rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 0.15rem;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .nav-link-custom {
    padding: 0.6rem 0;
    justify-content: center;
}

.sidebar.collapsed .nav-link-custom span {
    display: none;
}

.sidebar.collapsed .nav-link-custom i {
    margin: 0 !important;
    font-size: 1.1rem;
}

.nav-link-custom:hover {
    background: var(--glass-bg);
    color: var(--text-main);
}

.nav-link-custom.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

.sidebar-footer {
    border-top: 1px solid var(--glass-border);
    height: var(--footer-height);
    margin-top: auto;
    margin-left: -0.4rem;
    margin-right: -0.4rem;
    margin-bottom: -0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.2s;
}

.theme-toggle-container:hover {
    color: var(--text-main);
}

.sidebar.collapsed .theme-toggle-text {
    display: none;
}

/* Sidebar Collapse Button */
.collapse-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.collapse-btn:hover {
    background: var(--glass-bg);
    color: var(--text-main);
}

/* Header Elements */
.btn-premium {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: none;
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.btn-premium:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 0.3rem 0.8rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.btn-secondary:hover {
    background: rgba(148, 163, 184, 0.25);
    color: var(--text-main);
    border-color: var(--text-muted);
}

.btn-danger {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    border: none;
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.btn-danger:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

/* Cards and Tables */
.card-glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

h2,
h3,
h4,
h5 {
    margin-top: 0;
}

.mb-4 {
    margin-bottom: 0.75rem !important;
}

.mb-3 {
    margin-bottom: 0.5rem !important;
}

.mb-2 {
    margin-bottom: 0.25rem !important;
}

/* Global Compact Form Elements */
.form-control:not(textarea),
.form-input-custom,
.dbc-input,
.sidebar-dropdown-custom .Select-control {
    height: 30px !important;
    padding: 0.2rem 0.5rem !important;
    font-size: 1rem !important;
    border-radius: 6px !important;
    background: var(--glass-bg) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--text-main) !important;
}

/* Global placeholder readability — dark & light mode */
::placeholder {
    color: var(--text-muted) !important;
    opacity: 1 !important; /* Firefox reduces opacity by default */
}

::-webkit-input-placeholder {
    color: var(--text-muted) !important;
}

::-moz-placeholder {
    color: var(--text-muted) !important;
    opacity: 1 !important;
}

:-ms-input-placeholder {
    color: var(--text-muted) !important;
}

/* Dash dcc.Dropdown placeholder (including disabled state) */
.Select-placeholder {
    color: var(--text-muted) !important;
}

/* Global Dash Dropdown Compactness */
.Select-control {
    height: 30px !important;
    min-height: 30px !important;
    background: var(--glass-bg) !important;
    border: 1px solid var(--glass-border) !important;
    font-size: 1rem !important;
    color: var(--text-main) !important;
}

.Select-placeholder {
    line-height: 28px !important;
    color: var(--text-muted) !important;
}

.Select-value {
    line-height: 28px !important;
    color: var(--text-main) !important;
}

/* Premium Disabled Select Dropdown Styling */
.Select.is-disabled {
    opacity: 0.65 !important;
}

.Select.is-disabled .Select-control {
    background: rgba(255, 255, 255, 0.02) !important;
    border-color: rgba(255, 255, 255, 0.05) !important;
}

[data-theme='light'] .Select.is-disabled .Select-control {
    background: rgba(0, 0, 0, 0.02) !important;
    border-color: rgba(0, 0, 0, 0.05) !important;
}

.Select.is-disabled .Select-placeholder {
    color: var(--text-muted) !important;
}

.Select--single>.Select-control .Select-value {
    padding-left: 8px !important;
}

.has-value.Select--single>.Select-control .Select-value .Select-value-label, 
.has-value.is-pseudo-focused.Select--single>.Select-control .Select-value .Select-value-label {
    color: var(--text-main) !important;
}

.Select-input {
    height: 28px !important;
    font-size: 1rem !important;
}

.Select-menu-outer {
    background-color: var(--bg-color) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--text-main) !important;
    z-index: 9999 !important;
}

.Select.is-open {
    z-index: 10050 !important;
}

/* Elevate parent containers when a dropdown is open to resolve backdrop-filter stacking context layering bugs */
.card-glass:has(.Select.is-open),
.col:has(.Select.is-open),
[class*="col-"]:has(.Select.is-open),
.table-dark-custom tbody tr:has(.Select.is-open) {
    z-index: 10060 !important;
    position: relative !important;
}

.Select-option {
    background-color: var(--bg-color) !important;
    color: var(--text-main) !important;
}

.Select-option.is-focused,
.Select-option.is-selected {
    background-color: var(--accent-primary) !important;
    color: white !important;
}

/* Table Compact Styling */
.table-dark-custom {
    color: var(--text-main) !important;
    background: transparent !important;
    border-collapse: separate;
    border-spacing: 0;
}

.table-dark-custom thead th {
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--glass-border) !important;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 6px 10px !important;
}

.table-dark-custom tbody td {
    padding: 4px 10px !important;
    vertical-align: middle;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.85rem;
    overflow: visible !important;
}

.table-dark-custom tbody tr {
    position: relative;
    z-index: 1;
}

.table-dark-custom tbody tr:hover {
    z-index: 2;
    background: rgba(255, 255, 255, 0.02) !important;
}

.table-dark-custom tbody tr:focus-within {
    z-index: 99;
    background: rgba(255, 255, 255, 0.02) !important;
}

/* Compact Dropdown in Table */
.table-dark-custom .Select-control {
    height: 28px !important;
    min-height: 28px !important;
    background: var(--glass-bg) !important;
    border: 1px solid var(--glass-border) !important;
    font-size: 0.8rem;
    color: var(--text-main) !important;
}

.table-dark-custom .Select-placeholder,
.table-dark-custom .Select-value {
    line-height: 26px !important;
    color: var(--text-main) !important;
}

.table-dark-custom .Select--single>.Select-control .Select-value {
    padding-left: 8px !important;
}

.btn-xs {
    padding: 0.15rem 0.4rem;
    font-size: 0.75rem;
    border-radius: 4px;
}

/* Responsiveness */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px !important;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* On mobile, the desktop 'collapsed' state is irrelevant —
       only .open controls visibility. Without this fix, a collapsed
       desktop sidebar would stay hidden even after tapping the hamburger. */
    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .sidebar.open.collapsed {
        transform: translateX(0);
        width: 260px !important;
    }

    .content-area {
        margin-left: 0 !important;
    }

    .sidebar.collapsed+.content-area {
        margin-left: 0 !important;
    }

    /* Backdrop overlay — tap outside to close sidebar */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 999;
        backdrop-filter: blur(2px);
        animation: fadeInBackdrop 0.2s ease;
    }

    .sidebar-backdrop.active {
        display: block;
    }

    @keyframes fadeInBackdrop {
        from { opacity: 0; }
        to   { opacity: 1; }
    }
}

/* AI Diff View Styling */
ins {
    color: var(--bs-success) !important;
    font-weight: bold !important;
    text-decoration: none !important;
}

del {
    color: var(--bs-danger) !important;
    font-weight: bold !important;
    text-decoration: line-through !important;
}
