/* ===== Anvaya Intelligence - Sovereign Design System ===== */

/* ===== Theme Variables (RGB channels for Tailwind opacity support) ===== */
:root, [data-theme="dark"] {
    --surface: 11 19 38;
    --surface-tint: 173 198 255;
    --surface-dim: 11 19 38;
    --surface-variant: 45 52 73;
    --surface-bright: 49 57 77;
    --surface-container-lowest: 6 14 32;
    --surface-container-low: 19 27 46;
    --surface-container: 23 31 51;
    --surface-container-high: 34 42 61;
    --surface-container-highest: 45 52 73;
    --on-surface: 218 226 253;
    --on-surface-variant: 194 198 214;
    --on-background: 218 226 253;
    --background: 11 19 38;
    --primary: 173 198 255;
    --primary-container: 77 142 255;
    --primary-fixed: 216 226 255;
    --on-primary: 0 46 106;
    --on-primary-container: 0 40 93;
    --secondary: 78 222 163;
    --secondary-container: 0 165 114;
    --on-secondary: 0 56 36;
    --tertiary: 255 185 95;
    --tertiary-container: 202 129 0;
    --on-tertiary: 71 42 0;
    --error: 255 180 171;
    --error-container: 147 0 10;
    --on-error: 105 0 5;
    --on-error-container: 255 218 214;
    --outline: 140 144 159;
    --outline-variant: 66 71 84;
    --inverse-surface: 218 226 253;
    --inverse-on-surface: 40 48 68;
    --inverse-primary: 0 90 194;

    /* Non-RGB vars */
    --glass-bg: rgba(23, 31, 51, 0.8);
    --glass-panel-bg: rgba(34, 42, 61, 0.8);
    --gradient-from: rgb(173 198 255);
    --gradient-to: rgb(77 142 255);
    --scrollbar-thumb: rgb(45 52 73);
    --scrollbar-hover: rgb(66 71 84);
}

[data-theme="light"] {
    --surface: 248 250 252;
    --surface-tint: 59 130 246;
    --surface-dim: 241 245 249;
    --surface-variant: 226 232 240;
    --surface-bright: 255 255 255;
    --surface-container-lowest: 255 255 255;
    --surface-container-low: 248 250 252;
    --surface-container: 255 255 255;
    --surface-container-high: 241 245 249;
    --surface-container-highest: 203 213 225;
    --on-surface: 30 41 59;
    --on-surface-variant: 71 85 105;
    --on-background: 30 41 59;
    --background: 248 250 252;
    --primary: 59 130 246;
    --primary-container: 219 234 254;
    --primary-fixed: 219 234 254;
    --on-primary: 255 255 255;
    --on-primary-container: 30 58 138;
    --secondary: 5 150 105;
    --secondary-container: 209 250 229;
    --on-secondary: 255 255 255;
    --tertiary: 217 119 6;
    --tertiary-container: 254 243 199;
    --on-tertiary: 255 255 255;
    --error: 220 38 38;
    --error-container: 254 226 226;
    --on-error: 255 255 255;
    --on-error-container: 153 27 27;
    --outline: 148 163 184;
    --outline-variant: 226 232 240;
    --inverse-surface: 30 41 59;
    --inverse-on-surface: 248 250 252;
    --inverse-primary: 59 130 246;

    /* Non-RGB vars */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-panel-bg: rgba(241, 245, 249, 0.9);
    --gradient-from: rgb(59 130 246);
    --gradient-to: rgb(37 99 235);
    --scrollbar-thumb: rgb(203 213 225);
    --scrollbar-hover: rgb(148 163 184);
}

/* Material Symbols */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
}

/* Glass Effect */
.glass-effect {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
}

[data-theme="light"] .glass-effect {
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 8px 32px rgba(0,0,0,0.04);
}

.glass-panel {
    background: var(--glass-panel-bg);
    backdrop-filter: blur(12px);
}

/* Primary Gradient Button */
.primary-gradient {
    background: linear-gradient(135deg, var(--gradient-from) 0%, var(--gradient-to) 100%);
}

/* Login animation */
.login-card-animate {
    animation: fadeInUp 0.4s ease;
}

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

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

/* ===== Sidebar Navigation ===== */
.nav-link {
    color: rgb(var(--outline));
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
    transition: all 0.2s;
    cursor: pointer;
    text-decoration: none;
}

.nav-link:hover {
    background-color: rgb(var(--surface-container));
    color: rgb(var(--on-surface));
}

.nav-link.active {
    background-color: rgb(var(--surface-container-highest));
    color: rgb(var(--primary));
    border-right: 2px solid rgb(var(--primary));
}

/* ===== Status Dots ===== */
.status-dot {
    transition: background-color 0.3s;
}
.status-dot.connected {
    background-color: rgb(var(--secondary)) !important;
    box-shadow: 0 0 8px rgb(var(--secondary) / 0.4);
}
.status-dot.disconnected {
    background-color: rgb(var(--error)) !important;
}

/* ===== Chat Bubbles ===== */
.chat-bubble-user {
    align-self: flex-end;
    max-width: 80%;
    background-color: rgb(var(--surface-container-highest));
    color: rgb(var(--on-surface));
    padding: 1.25rem;
    border-radius: 1rem;
    border-bottom-right-radius: 0.25rem;
    border: 1px solid rgb(var(--outline-variant) / 0.3);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.chat-bubble-assistant {
    align-self: flex-start;
    max-width: 90%;
    background-color: rgb(var(--surface-container-low));
    color: rgb(var(--on-surface-variant));
    padding: 1.5rem;
    border-radius: 1rem;
    border: 1px solid rgb(var(--outline-variant) / 0.2);
}

.chat-bubble-system {
    align-self: center;
    color: rgb(var(--outline));
    font-size: 0.8rem;
    font-style: italic;
    padding: 0.25rem 0;
}

/* ===== Chat Assistant Header ===== */
.chat-assistant-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 1rem 1.5rem;
    align-self: flex-start;
    background-color: rgb(var(--surface-container-low));
    border-radius: 1rem;
    border: 1px solid rgb(var(--outline-variant) / 0.2);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: rgb(var(--outline));
    border-radius: 50%;
    animation: typing 1.4s infinite both;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ===== Markdown Content (Chat & Reports) ===== */
.markdown-content {
    font-size: 0.875rem;
    line-height: 1.7;
    color: rgb(var(--on-surface));
}

.markdown-content p { margin-bottom: 0.75rem; }
.markdown-content p:last-child { margin-bottom: 0; }

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    color: rgb(var(--primary));
}
.markdown-content h1 { font-size: 1.5rem; }
.markdown-content h2 { font-size: 1.25rem; }
.markdown-content h3 { font-size: 1.125rem; color: rgb(var(--on-surface)); }

.markdown-content ul,
.markdown-content ol {
    padding-left: 1.5rem;
    margin: 0.5rem 0;
    color: rgb(var(--on-surface-variant));
}

.markdown-content li {
    margin-bottom: 0.35rem;
}

.markdown-content li::marker {
    color: rgb(var(--secondary));
}

.markdown-content strong { color: rgb(var(--on-surface)); }

.markdown-content blockquote {
    border-left: 3px solid rgb(var(--primary-container));
    padding-left: 0.75rem;
    margin: 0.75rem 0;
    opacity: 0.85;
    color: rgb(var(--on-surface-variant));
}

.markdown-content hr {
    border-color: rgb(var(--outline-variant));
    margin: 1rem 0;
}

/* Markdown tables */
.markdown-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.8125rem;
    background: rgb(var(--surface-container-lowest));
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid rgb(var(--outline-variant) / 0.3);
}

.markdown-content th {
    background-color: rgb(var(--surface-container));
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgb(var(--on-surface-variant));
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 500;
}

.markdown-content td {
    padding: 0.625rem 1rem;
    border-top: 1px solid rgb(var(--outline-variant) / 0.2);
    color: rgb(var(--on-surface));
}

.markdown-content tr:hover td {
    background-color: rgb(var(--surface-container-high));
}

/* Markdown code */
.markdown-content pre {
    background-color: rgb(var(--surface-container-lowest));
    border-radius: 0.5rem;
    padding: 1rem;
    overflow-x: auto;
    margin: 0.75rem 0;
    border: 1px solid rgb(var(--outline-variant) / 0.3);
}

.markdown-content code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

.markdown-content :not(pre) > code {
    background-color: rgb(var(--primary-container) / 0.3);
    padding: 0.125rem 0.4rem;
    border-radius: 0.25rem;
    color: rgb(var(--primary));
}

/* ===== Report Content (Insights page) ===== */
.report-content h2 {
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: rgb(var(--primary));
}
.report-content h3 {
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 1.125rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: rgb(var(--on-surface));
}
.report-content p {
    margin-bottom: 1rem;
    line-height: 1.6;
    color: rgb(var(--on-surface-variant));
}
.report-content ul {
    margin-bottom: 1.5rem;
    list-style-type: none;
    padding-left: 0;
}
.report-content li {
    margin-bottom: 0.5rem;
    padding-left: 1.5rem;
    position: relative;
    color: rgb(var(--on-surface-variant));
}
.report-content li::before {
    content: '\2192';
    position: absolute;
    left: 0;
    color: rgb(var(--secondary));
}
.report-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.8125rem;
    background: rgb(var(--surface-container-lowest));
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid rgb(var(--outline-variant) / 0.3);
}
.report-content th {
    background-color: rgb(var(--surface-container-high));
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgb(var(--on-surface-variant));
    padding: 1rem 1.5rem;
    text-align: left;
}
.report-content td {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgb(var(--outline-variant) / 0.2);
    color: rgb(var(--on-surface));
}

/* ===== Alert System ===== */
.alert-success {
    background-color: rgb(var(--secondary) / 0.1);
    border: 1px solid rgb(var(--secondary) / 0.2);
    color: rgb(var(--secondary));
}

.alert-error {
    background-color: rgb(var(--error) / 0.1);
    border: 1px solid rgb(var(--error) / 0.2);
    color: rgb(var(--error));
}

.alert-warning {
    background-color: rgb(var(--tertiary) / 0.1);
    border: 1px solid rgb(var(--tertiary) / 0.2);
    color: rgb(var(--tertiary));
}

/* ===== Agent Cards ===== */
.agent-card {
    background-color: rgb(var(--surface-container));
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.agent-card:hover {
    background-color: rgb(var(--surface-container-high));
}

.agent-card .status-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
}

/* ===== Quality Score Colors ===== */
.quality-high { color: rgb(var(--secondary)); }
.quality-medium { color: rgb(var(--tertiary)); }
.quality-low { color: rgb(var(--error)); }

/* ===== Sidebar always dark (per design spec) ===== */
#sidebar {
    --surface: 11 19 38;
    --surface-tint: 173 198 255;
    --surface-dim: 11 19 38;
    --surface-variant: 45 52 73;
    --surface-bright: 49 57 77;
    --surface-container-lowest: 6 14 32;
    --surface-container-low: 19 27 46;
    --surface-container: 23 31 51;
    --surface-container-high: 34 42 61;
    --surface-container-highest: 45 52 73;
    --on-surface: 218 226 253;
    --on-surface-variant: 194 198 214;
    --on-background: 218 226 253;
    --background: 11 19 38;
    --primary: 173 198 255;
    --primary-container: 77 142 255;
    --on-primary: 0 46 106;
    --on-primary-container: 0 40 93;
    --secondary: 78 222 163;
    --secondary-container: 0 165 114;
    --on-secondary: 0 56 36;
    --tertiary: 255 185 95;
    --tertiary-container: 202 129 0;
    --on-tertiary: 71 42 0;
    --error: 255 180 171;
    --error-container: 147 0 10;
    --on-error: 105 0 5;
    --on-error-container: 255 218 214;
    --outline: 140 144 159;
    --outline-variant: 66 71 84;
    --inverse-surface: 218 226 253;
    --inverse-on-surface: 40 48 68;
    --inverse-primary: 0 90 194;
}

/* ===== Theme Transition ===== */
html {
    transition: background-color 0.3s ease, color 0.3s ease;
}
html * {
    transition: background-color 0.3s ease, color 0.15s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    #sidebar {
        width: 60px;
        min-width: 60px;
    }
    .nav-label,
    #sidebar .font-label:not(.nav-label) {
        display: none;
    }
    #sidebar .px-6 span:first-child {
        font-size: 1rem;
    }
    main.ml-64 {
        margin-left: 60px;
    }
    .chat-bubble-user { max-width: 95%; }
    .chat-bubble-assistant { max-width: 95%; }
    header.fixed.w-\[calc\(100\%-16rem\)\] {
        width: calc(100% - 60px);
    }
    footer.fixed.w-\[calc\(100\%-16rem\)\] {
        width: calc(100% - 60px);
    }
}
