/* =========================================================================
   DESIGN TOKENS & VARIABLES
   ========================================================================= */
:root {
    /* Color Palette - Dark High-Tech Theme */
    --clr-bg-base: #0a0f1c; /* Deep slate/navy */
    --clr-bg-subtle: #131b2f; 
    --clr-bg-glass: rgba(19, 27, 47, 0.6);
    --clr-primary: #3b82f6; /* Blue 500 */
    --clr-primary-glow: rgba(59, 130, 246, 0.5);
    --clr-accent: #10b981; /* Emerald 500 */
    --clr-text-main: #f8fafc; /* Slate 50 */
    --clr-text-muted: #94a3b8; /* Slate 400 */
    --clr-border: rgba(255, 255, 255, 0.08);
    
    /* Status Colors */
    --clr-status-open: #3b82f6;      /* Blue */
    --clr-status-assigned: #f59e0b;  /* Amber */
    --clr-status-progress: #8b5cf6;  /* Violet */
    --clr-status-billing: #ec4899;   /* Pink */
    --clr-status-closed: #10b981;    /* Emerald */

    /* Typography */
    --font-main: 'Outfit', sans-serif;
    
    /* Shadows & Effects */
    --shadow-glass: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    --blur-glass: blur(16px);
    --transition-fast: 0.2s ease;
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Layout */
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    
    /* Layout Sizes */
    --sidebar-collapsed-w: 80px;
    --sidebar-expanded-w: 240px;
    --topbar-h: 70px;
    --content-pad: 2rem;
}

/* =========================================================================
   LIGHT MODE OVERRIDES
   ========================================================================= */
body.light-mode {
    --clr-bg-base: #f8fafc;
    --clr-bg-subtle: #ffffff;
    --clr-bg-glass: rgba(255, 255, 255, 0.75);
    --clr-primary: #2563eb;
    --clr-primary-glow: rgba(37, 99, 235, 0.25);
    --clr-accent: #059669;
    --clr-text-main: #0f172a;
    --clr-text-muted: #475569;
    --clr-border: rgba(0, 0, 0, 0.06);
    --shadow-glass: 0 10px 30px -10px rgba(0, 0, 0, 0.1);
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(219, 234, 254, 0.6), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(209, 250, 229, 0.6), transparent 25%);
}

body.light-mode .bg-blur.top-left { background: rgba(37, 99, 235, 0.15); }
body.light-mode .bg-blur.bottom-right { background: rgba(5, 150, 105, 0.15); }

/* ---- Theme toggle switch ---- */
.theme-toggle {
    display: flex; align-items: center; gap: 0.4rem; cursor: pointer; user-select: none;
}
.theme-toggle input[type="checkbox"] { display: none; }
.theme-toggle .toggle-track {
    position: relative; width: 44px; height: 24px;
    background: var(--clr-bg-subtle); border: 1px solid var(--clr-border);
    border-radius: var(--radius-full); transition: background 0.3s;
}
.theme-toggle .toggle-thumb {
    position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
    border-radius: 50%; background: var(--clr-primary);
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
    font-size: 10px; display: flex; align-items: center; justify-content: center;
}
.theme-toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); }

/* =========================================================================
   RESET & BASE
   ========================================================================= */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: var(--font-main); }

body {
    background-color: var(--clr-bg-base);
    color: var(--clr-text-main);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    /* Soft dark background gradient */
    background-image: 
        radial-gradient(circle at 0% 0%, #111a2d 0%, transparent 40%),
        radial-gradient(circle at 100% 100%, #0d1e36 0%, transparent 40%);
}

/* Abstract Background Glows */
.bg-blur {
    position: fixed; border-radius: 50%; filter: blur(120px);
    z-index: -1; pointer-events: none; opacity: 0.6;
}
.bg-blur.top-left {
    top: -10vw; left: -10vw; width: 45vw; height: 45vw; background: var(--clr-primary-glow);
}
.bg-blur.bottom-right {
    bottom: -10vw; right: -10vw; width: 40vw; height: 40vw; background: rgba(16, 185, 129, 0.2);
}

/* =========================================================================
   UTILITIES & COMPONENTS
   ========================================================================= */
.app-container {
    max-width: 1600px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column;
}

.glass-panel {
    background: var(--clr-bg-glass);
    backdrop-filter: var(--blur-glass); -webkit-backdrop-filter: var(--blur-glass);
    border: 1px solid var(--clr-border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-glass);
}

/* Text Gradients */
.text-gradient {
    background: linear-gradient(135deg, var(--clr-text-main) 0%, var(--clr-primary) 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: 1.2; }
.text-muted { color: var(--clr-text-muted); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.75rem 1.5rem; font-size: 1rem; font-weight: 500;
    border: none; border-radius: var(--radius-sm); cursor: pointer;
    transition: var(--transition-fast); gap: 0.5rem; outline: none;
}
.btn-primary {
    background: linear-gradient(135deg, var(--clr-primary), #2563eb);
    color: #fff; box-shadow: 0 4px 15px var(--clr-primary-glow);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 25px var(--clr-primary-glow); }
.btn-primary:active { transform: translateY(0); box-shadow: 0 2px 10px var(--clr-primary-glow); }

.btn-outline { background: transparent; border: 1px solid var(--clr-border); color: var(--clr-text-main); }
.btn-outline:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(255,255,255,0.2); }

/* Forms & Inputs */
.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; margin-bottom: 0.5rem; font-weight: 500; color: var(--clr-text-muted); font-size: 0.9rem; }
.form-control {
    width: 100%; padding: 0.875rem 1rem; background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--clr-border); border-radius: var(--radius-sm);
    color: var(--clr-text-main); font-size: 1rem; transition: var(--transition-fast);
}
body.light-mode .form-control { background: rgba(255, 255, 255, 0.5); }
.form-control:focus { outline: none; border-color: var(--clr-primary); box-shadow: 0 0 0 3px var(--clr-primary-glow); }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* =========================================================================
   LAYOUT SHELL (Sidebar & Main Content)
   ========================================================================= */

.layout { display: flex; height: 100vh; width: 100%; overflow: hidden; }

/* -- Sidebar (Icon-rail by default, expands on hover) -- */
.sidebar {
    width: var(--sidebar-collapsed-w);
    height: calc(100vh - 2rem);
    margin: 1rem 0 1rem 1rem;
    display: flex; flex-direction: column;
    padding: 1.5rem 0; /* Padding top/bottom only to center icons */
    transition: width var(--transition-smooth);
    overflow: hidden;
    position: relative;
    z-index: 100;
}

.sidebar:hover {
    width: var(--sidebar-expanded-w);
}

.sidebar .brand {
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.5rem; margin-bottom: 2rem; white-space: nowrap;
}
.sidebar .brand-icon {
    font-size: 1.5rem; min-width: 30px; display: flex; justify-content: center;
}
.sidebar .brand-text {
    opacity: 0; transition: opacity 0.2s; font-size: 1.2rem;
}
.sidebar:hover .brand-text { opacity: 1; transition-delay: 0.1s; }
.sidebar .close-sidebar-btn { display: none; } /* Mobile only */

.nav-links { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; padding: 0 0.75rem; }

.nav-links a {
    display: flex; align-items: center; gap: 1rem;
    padding: 0.875rem 0.5rem;
    width: 100%;
    color: var(--clr-text-muted); text-decoration: none;
    border-radius: var(--radius-sm); transition: var(--transition-fast);
    white-space: nowrap; overflow: hidden;
}
.nav-links a .icon {
    min-width: 50px; display: flex; justify-content: center; font-size: 1.3rem;
}
.nav-links a .nav-text {
    opacity: 0; transition: opacity 0.2s; font-weight: 500;
}
.sidebar:hover .nav-links a .nav-text { opacity: 1; transition-delay: 0.1s; }

.nav-links a:hover, .nav-links a.active {
    background: rgba(255, 255, 255, 0.08); color: var(--clr-text-main);
}
.nav-links a.active .icon { color: var(--clr-primary); }
.nav-links a.active {
    box-shadow: inset 4px 0 0 var(--clr-primary);
}

.user-info {
    margin-top: auto; padding: 0 1rem;
    display: flex; flex-direction: column; gap: 1rem;
    white-space: nowrap; overflow: hidden;
}

.user-role-wrap {
    display: flex; justify-content: center;
}
.sidebar:hover .user-role-wrap { justify-content: flex-start; padding-left: 0.5rem; }

.user-role.badge {
    opacity: 0; transition: opacity 0.2s;
    font-size: 0.7rem; padding: 0.2rem 0.5rem;
    background: var(--clr-bg-subtle); color: var(--clr-text-muted);
    border: 1px solid var(--clr-border); border-radius: 4px;
}
.sidebar:hover .user-role.badge { opacity: 1; transition-delay: 0.1s; }

.logout-btn {
    width: 100%; justify-content: flex-start; padding: 0.75rem 0;
    border: none; background: transparent; color: var(--clr-text-muted);
}
.logout-btn:hover { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.logout-btn .icon { min-width: 48px; font-size: 1.2rem; }
.logout-btn .nav-text { opacity: 0; transition: opacity 0.2s; }
.sidebar:hover .logout-btn .nav-text { opacity: 1; transition-delay: 0.1s; }


/* -- Main Content -- */
.main-content {
    flex: 1; display: flex; flex-direction: column;
    overflow: hidden; padding-right: 1rem;
}

.topbar {
    height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between;
    padding: 0 1rem 0 2rem;
}

#hamburger-menu {
    display: none; background: transparent; border: none;
    color: var(--clr-text-main); font-size: 1.5rem; cursor: pointer;
    padding: 0.5rem; border-radius: var(--radius-sm);
}
#hamburger-menu:hover { background: rgba(255,255,255,0.1); }

.avatar-circle {
    width: 40px; height: 40px; border-radius: 50%; background: var(--clr-bg-subtle);
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--clr-border); transition: var(--transition-fast);
}
.avatar-circle:hover { border-color: var(--clr-primary); box-shadow: 0 0 10px var(--clr-primary-glow); }

.content-scroll {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: 0 var(--content-pad) var(--content-pad) var(--content-pad);
}

/* =========================================================================
   RESPONSIVE OVERRIDES (MOBILE FIRST)
   ========================================================================= */

@media (max-width: 768px) {
    :root {
        --topbar-h: 60px;
        --content-pad: 1rem;
    }

    .layout { flex-direction: column; padding: 0; }
    .main-content { padding-right: 0; }

    /* Topbar updates */
    .topbar { padding: 0 1rem; border-bottom: 1px solid var(--clr-border); background: var(--clr-bg-base); }
    #hamburger-menu { display: block; }
    .topbar-date { display: none; } /* Hide date to save space */
    .mobile-brand-text { display: block !important; }

    /* Sidebar becomes a drawer */
    .sidebar {
        position: fixed; top: 0; left: -300px; bottom: 0; height: 100dvh;
        width: 260px !important; margin: 0; border-radius: 0;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: rgba(10, 15, 28, 0.98); border-right: 1px solid var(--clr-border);
        z-index: 999; padding-top: 1rem;
    }
    
    .sidebar.show { left: 0; }
    
    /* Always show sidebar text in drawer */
    .sidebar .brand-text, 
    .sidebar .nav-links a .nav-text, 
    .sidebar .user-role.badge, 
    .sidebar .logout-btn .nav-text {
        opacity: 1 !important; transition: none;
    }
    .sidebar .brand { justify-content: space-between; }
    .sidebar .close-sidebar-btn { 
        display: block; background: transparent; border: none; color: var(--clr-text-main);
        font-size: 1.5rem; padding: 0.5rem; cursor: pointer; 
    }
    
    /* Nav links tighter on mobile */
    .nav-links a { padding: 0.75rem 1rem; }
    .nav-links a .icon { min-width: 35px; }
    .logout-btn .icon { min-width: 35px; }

    /* Sidebar Overlay */
    .sidebar-overlay {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6);
        backdrop-filter: blur(4px); z-index: 998;
    }
    .sidebar-overlay.show { display: block; }

    /* Forms & Inputs mobile stacking */
    .form-group { margin-bottom: 1rem; }
    
    /* Removed destructive generic display:flex override that broke topbar and header layouts */
    
    /* Chat View */
    div[style*="display: grid; grid-template-columns: 1fr 1fr;"] {
        grid-template-columns: 1fr !important; gap: 1rem !important;
    }
    div[style*="height:500px;"] {
        height: calc(100dvh - 200px) !important;
    }

    /* Modal adjustments */
    #modal-root .glass-panel { width: 95%; max-width: none; padding: 1.5rem; }
    
    /* Team & Grid Adjustments */
    div[style*="grid-template-columns: 1fr 300px"], 
    div[style*="grid-template-columns: 1fr 350px"] {
        grid-template-columns: 1fr !important;
    }
}

/* =========================================================================
   RESPONSIVE TABLE TO CARDS (CSS ONLY)
   ========================================================================= */

@media (max-width: 768px) {
    table {
        display: block; width: 100%;
    }
    thead {
        display: none; /* Hide table headers */
    }
    tbody {
        display: block; width: 100%;
    }
    tr {
        display: flex; flex-direction: column; 
        background: rgba(255,255,255,0.03); 
        border: 1px solid var(--clr-border);
        border-radius: var(--radius-md);
        margin-bottom: 1rem; padding: 1rem;
        position: relative;
    }
    td {
        display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
        padding: 0.5rem 0 !important; border: none !important;
        font-size: 0.95rem; text-align: left;
    }
    td::before {
        content: attr(data-label);
        font-weight: 600; color: var(--clr-text-muted);
        font-size: 0.75rem; text-transform: uppercase;
        margin-bottom: 0.25rem; display: block;
    }
    /* Hide the 'Actions' label usually, let the buttons just sit at the bottom */
    td:last-child {
        margin-top: 0.5rem; padding-top: 1rem !important;
        border-top: 1px solid var(--clr-border) !important;
        justify-content: flex-end; width: 100%;
    }
}

/* Animations */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.glass-panel { animation: fadeInUp 0.4s ease forwards; }

/* Donut chart sizing */
.donut-chart-container { display: flex; justify-content: center; position: relative; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; margin-top: 1.5rem; }
.legend-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.legend-color { width: 12px; height: 12px; border-radius: 50%; }
