:root {
    --primary: #4f46e5; /* Indigo 600 */
    --primary-dark: #4338ca;
    --secondary: #10b981;
    --accent: #ec4899;
    --bg-main: #f1f5f9; /* Slate 100 */
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --glass: rgba(255, 255, 255, 0.8);
    --glass-border: #e2e8f0; /* Slate 200 */
    --text-main: #1e293b; /* Slate 900 */
    --text-muted: #64748b; /* Slate 500 */
    --danger: #ef4444;
    --warning: #f59e0b;
    --success: #10b981;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

/* Global Scrollbars */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; border: 2px solid var(--bg-main); }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-body);
    overflow: hidden;
    height: 100vh;
    display: flex;
}

/* Sidebar Navigation */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 30px 0;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.brand {
    padding: 0 30px 40px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--primary);
}

.brand span { color: var(--text-main); }

.nav-links {
    flex: 1;
    padding: 0 15px;
    overflow-y: auto; /* Fix: Ensure last items aren't cut off */
}

/* Scrollbar for nav-links */
.nav-links::-webkit-scrollbar { width: 4px; }
.nav-links::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 10px; }

.nav-group {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding: 25px 15px 10px;
    font-weight: 700;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 12px;
    transition: all 0.2s ease;
    margin-bottom: 5px;
    border: none;
    background: transparent;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.nav-btn:hover, .nav-btn.active {
    background: #f1f5f9;
    color: var(--primary);
}

.nav-btn.active {
    background: #eef2ff;
    color: var(--primary);
    font-weight: 600;
}

.nav-btn i { font-size: 1.1rem; width: 24px; text-align: center; }

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--glass-border);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
}

.user-info { display: flex; flex-direction: column; }
.user-name { font-size: 0.85rem; font-weight: 700; color: var(--text-main); }
.user-role { font-size: 0.7rem; color: var(--text-muted); }

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

.view-section {
    display: none;
    max-width: 1400px;
    margin: 0 auto;
}

.view-section.active { display: block; animation: fadeIn 0.4s ease-out; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Typography */
.section-header { margin-bottom: 30px; display: flex; justify-content: space-between; align-items: center; }
.section-header h1 { font-family: var(--font-heading); font-size: 2.2rem; font-weight: 800; color: var(--text-main); }
.section-header h1 span { color: var(--primary); font-weight: 400; }
.section-header p { color: var(--text-muted); font-size: 1rem; }

/* Dashboard Cards */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 25px;
    margin-bottom: 30px;
}

.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 24px;
    transition: box-shadow 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.glass-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary); }

.glass-card h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 20px;
}

/* Global Stats Card */
.stats-banner {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.stat-item { padding: 20px; text-align: center; }
.stat-item .label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; font-weight: 800; letter-spacing: 1px; display: block; margin-bottom: 8px; }
.stat-item .value { font-size: 1.5rem; font-weight: 800; font-family: var(--font-heading); color: var(--text-main); }

/* Clause Performance */
.clause-list { display: flex; flex-direction: column; gap: 12px; }
.clause-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: #f8fafc;
    border-radius: 14px;
    border: 1px solid var(--glass-border);
}

.clause-icon { width: 44px; height: 44px; border-radius: 10px; background: #eef2ff; color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.clause-info { flex: 1; }
.clause-title { display: block; font-weight: 700; font-size: 0.9rem; color: var(--text-main); }
.clause-desc { font-size: 0.7rem; color: var(--text-muted); }

/* Table styling */
.table-container { overflow-x: auto; }
.audit-table { width: 100%; border-collapse: collapse; text-align: left; }
.audit-table th { padding: 12px 15px; font-size: 0.75rem; text-transform: uppercase; font-weight: 800; color: var(--text-muted); border-bottom: 1px solid var(--glass-border); }
.audit-table td { padding: 15px; font-size: 0.85rem; border-bottom: 1px solid #f1f5f9; color: var(--text-main); }

/* Action Buttons */
.btn {
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    border: none;
    font-family: var(--font-heading);
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: #f1f5f9; color: var(--text-main); border: 1px solid var(--glass-border); }
.btn-secondary:hover { background: #e2e8f0; }

/* AI Advisor Interface */
.ai-advisor-container {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 25px;
    height: calc(100vh - 160px);
    min-height: 500px;
}

.chat-box {
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    overflow: hidden;
}

.message { padding: 15px 24px; border-radius: 12px; font-size: 0.95rem; line-height: 1.6; max-width: 90%; position: relative; }
.bot-msg { background: #f1f5f9; color: #1e293b; align-self: flex-start; border-bottom-left-radius: 2px; }
.user-msg { background: var(--primary); color: white; align-self: flex-end; border-bottom-right-radius: 2px; }

.chat-messages { 
    flex: 1; 
    overflow-y: auto; 
    padding: 24px; 
    display: flex; 
    flex-direction: column; 
    gap: 20px; 
    min-height: 0; /* Critical for flex scrolling */
}

.chat-input-area { 
    padding: 20px; 
    border-top: 1px solid var(--glass-border); 
    display: flex; 
    gap: 15px; 
    background: white;
}

.chat-input { flex: 1; background: #f8fafc; border: 1px solid var(--glass-border); border-radius: 10px; padding: 12px; color: var(--text-main); outline: none; }
.chat-input:focus { border-color: var(--primary); }

/* Mobile Adaptations */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    width: 44px;
    height: 44px;
    background: var(--primary);
    color: white;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
}

@media (max-width: 1024px) {
    .dashboard-grid, .ai-advisor-container { grid-template-columns: 1fr; }
    .stats-banner { grid-template-columns: repeat(2, 1fr); }
    .sidebar { position: fixed; left: -280px; height: 100vh; }
    .sidebar.active { transform: translateX(280px); }
    .content-main { padding: 80px 20px 20px; }
    .mobile-toggle { display: flex; align-items: center; justify-content: center; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 15px; }
    .section-header h1 { font-size: 1.8rem; }
}

@media (max-width: 640px) {
    .stats-banner { grid-template-columns: 1fr; }
    .stat-item { text-align: left; border-bottom: 1px solid var(--glass-border); }
    .stat-item:last-child { border-bottom: none; }
    .btn { width: 100%; justify-content: center; }
}

/* Modal Styling */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal.active { display: flex; }
.modal-content { background: white; width: 95%; max-width: 600px; border-radius: 20px; padding: 30px; }

/* Typing Indicator Animation */
@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

/* Advisor sidebar nav-btn */
.advisor-sidebar .nav-btn {
    width: 100%;
    text-align: left;
    margin-bottom: 6px;
    border-radius: 8px;
    color: var(--text-muted);
}

.advisor-sidebar .nav-btn:hover {
    background: #eef2ff;
    color: var(--primary);
}

/* Chat message list */
.bot-msg ul {
    margin-left: 20px;
    margin-top: 4px;
    color: var(--text-muted);
}

.bot-msg li {
    margin-bottom: 5px;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Tooltip for Structure Elements */
.struct-tooltip-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: help;
}

.struct-tooltip-container .struct-tooltip {
    visibility: hidden;
    width: 240px;
    background-color: var(--text-main);
    color: #fff;
    text-align: left;
    border-radius: 8px;
    padding: 10px 14px;
    position: absolute;
    z-index: 5000;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
    font-size: 0.75rem;
    line-height: 1.5;
    box-shadow: var(--shadow-md);
    pointer-events: none;
    font-weight: 400;
    font-family: var(--font-body);
}

.struct-tooltip-container .struct-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: var(--text-main) transparent transparent transparent;
}

.struct-tooltip-container:hover .struct-tooltip {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

/* Print Media Queries */
@media print {
    body, .content-main { 
        overflow: visible !important; 
        height: auto !important; 
        background: white !important;
    }
    
    .sidebar, .mobile-toggle, .actions, .chat-input-area, .advisor-sidebar, .btn { 
        display: none !important; 
    }
    
    .content-main { 
        padding: 0 !important; 
        margin: 0 !important; 
        width: 100% !important;
    }
    
    .view-section { 
        display: block !important; 
        opacity: 1 !important; 
        transform: none !important;
    }
    
    .glass-card { 
        box-shadow: none !important; 
        border: 1px solid #eee !important;
        break-inside: avoid;
        margin-bottom: 20px !important;
    }
    
    .blueprint-card {
        max-height: none !important;
        overflow: visible !important;
        padding: 0 !important;
        border: none !important;
    }

    .chat-box {
        border: none !important;
        background: transparent !important;
    }

    .chat-messages {
        overflow: visible !important;
        height: auto !important;
    }

    .message {
        max-width: 100% !important;
        background: transparent !important;
        color: black !important;
        padding: 0 !important;
        margin-bottom: 30px !important;
    }
}
