/* css/main.css */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Roboto:wght@300;400;500&display=swap');

:root {
    /* Blue Morpho / Badal Palette */
    --bg-body: #0f1115;
    /* Deepest Dark */
    --bg-surface: #181b21;
    /* Card Background */
    --bg-surface-hover: #232730;

    --text-primary: #e0e6ed;
    /* Off-white */
    --text-secondary: #94a3b8;
    /* Muted Blue-Grey */

    --primary-color: #2E86AB;
    /* Deep Blue */
    --accent-color: #00d4ff;
    /* Electric Cyan */
    --accent-glow: rgba(0, 212, 255, 0.3);

    --border-color: #2d3748;

    --font-ui: 'Inter', sans-serif;
    --font-body: 'Roboto', sans-serif;
}

body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font-body);
    height: 100svh;
    overflow: hidden;
    margin: 0;
    padding: 0;
    /* App-like feel */
}

.page-wrapper {
    display: flex;
    height: 100%;
}

/* Typography Overrides */
h1,
h2,
h3,
h4,
h5,
h6,
.btn,
.nav-link {
    font-family: var(--font-ui);
}

/* Custom Card Styling */
.card-custom {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Form Controls Dark Mode */
.form-control {
    background-color: #0b0c0f;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px;
}

.form-control:focus {
    background-color: #0b0c0f;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
    color: var(--text-primary);
}

/* Buttons */
.btn-morpho {
    background: linear-gradient(135deg, var(--primary-color), #206a8a);
    border: none;
    color: white;
    font-weight: 500;
    padding: 10px 20px;
    transition: all 0.3s ease;
}

.btn-morpho:hover {
    background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
    box-shadow: 0 0 15px var(--accent-glow);
    color: #000;
}

/* Utilities */
.text-accent {
    color: var(--accent-color);
}

.text-muted {
    color: var(--text-secondary) !important;
}

/* --- Dashboard Layout --- */
.sidebar {
    width: 280px;
    flex-shrink: 0;
    /* Prevents sidebar from shrinking */
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px 15px;
    z-index: 2;
}

.sidebar-brand {
    padding: 0 10px;
    margin-bottom: 1.5rem;
}

.sidebar .nav-pills {
    flex: 1;
    flex-direction: column;
    /* Pushes user section to the bottom */
}

.nav-pills .nav-link {
    color: var(--text-secondary);
    border-radius: 8px;
    margin-bottom: 8px;
    padding: 12px 15px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.nav-pills .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-pills .nav-link.active {
    background: linear-gradient(90deg, var(--primary-color), rgba(46, 134, 171, 0.5));
    color: #fff;
    border-left: 4px solid var(--accent-color);
    padding-left: 11px;
    /* Adjust for border */
}

/* --- Content Area --- */
.main-content {
    flex-grow: 1;
    /* Allows content to scroll independently */
    height: 100svh;
}

.view-section {
    padding-top: 85px !important;
    height: 100% !important;
}

/* --- RESPONSIVE: Mobile & Tablet View --- */
@media (max-width: 767.98px) {
    .page-wrapper {
        flex-direction: column;
        /* Stack sidebar and content */
    }

    /* Sidebar becomes a Top Navbar */
    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        /* Arrange items horizontally */
        align-items: center;
        padding: 10px 15px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .view-section {
        padding-top: 85px !important;
        height: calc(100% -85px) !important;
    }

    .sidebar-brand {
        margin-bottom: 0;
    }

    /* Nav links become a horizontal list */
    .sidebar .nav-pills {
        flex: 1;
        flex-direction: row;
        justify-content: center;
        /* Center the icons */
    }

    .nav-pills .nav-link {
        margin-bottom: 0;
        margin-right: 5px;
        padding: 10px;
        /* Make icons more tappable */
    }

    .nav-pills .nav-link.active {
        border-left: none;
        /* Remove side border */
        border-bottom: 3px solid var(--accent-color);
        /* Add bottom border */
        padding-left: 10px;
    }

    /* Hide text labels on mobile, show only icons */
    .nav-text {
        display: none;
    }

    .sidebar-user {
        margin-left: auto;
        /* Push user info to the right */
    }

    .sidebar-user hr,
    .sidebar-user>div>div:first-child {
        display: none;
        /* Hide hr and "Logged in as" text */
    }

    /* Main content adjusts */
    .main-content {
        height: calc(100% - 60px) !important;
        /* Let it grow to fill remaining space */
        flex-grow: 1;
    }
}

/* --- Graph View Specifics --- */
/* Graph Loader Overlay */
.graph-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 17, 21, 0.8);
    /* Semi-transparent dark */
    backdrop-filter: blur(5px);
    z-index: 20;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
}

#network-container {
    width: 100%;
    height: calc(95% - 40px);
    margin-top: 30px;
    /* Full height minus header */
    background-color: #0f1115;
    /* Match body bg */
    border-radius: 12px;
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

/* Floating Controls for Graph */
.graph-controls {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 10;
    background: rgba(24, 27, 33, 0.8);
    backdrop-filter: blur(5px);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

/* Offcanvas (Side Panel) Dark Mode Override */
.offcanvas-dark {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border-left: 1px solid var(--border-color);
}

.offcanvas-dark .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* --- Chat Interface --- */
.chat-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Match graph height */
    position: relative;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 80px;
    /* Space for input bar */
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Scrollbar styling for chat */
.chat-history::-webkit-scrollbar {
    width: 8px;
}

.chat-history::-webkit-scrollbar-track {
    background: transparent;
}

.chat-history::-webkit-scrollbar-thumb {
    background: #2d3748;
    border-radius: 4px;
}

/* Message Bubbles */
.message-row {
    display: flex;
    width: 100%;
}

.message-row.user {
    justify-content: flex-end;
}

.message-row.bot {
    justify-content: flex-start;
}

.bubble {
    max-width: 75%;
    padding: 15px 20px;
    font-size: 1rem;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.bubble.user {
    background: linear-gradient(135deg, var(--primary-color), #206a8a);
    color: white;
    border-radius: 18px 18px 0 18px;
    /* Sharp bottom-right */
}

.bubble.bot {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 18px 18px 18px 0;
    /* Sharp bottom-left */
}

/* Markdown Styles inside Bot Bubble */
.bubble.bot p {
    margin-bottom: 10px;
}

.bubble.bot p:last-child {
    margin-bottom: 0;
}

.bubble.bot strong {
    color: var(--accent-color);
}

.bubble.bot ul {
    padding-left: 20px;
    margin-bottom: 10px;
}

/* Thinking / Sources Section */
.thinking-accordion {
    margin-top: 10px;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}

.btn-thinking {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-thinking:hover {
    color: var(--accent-color);
}

.thinking-content {
    display: none;
    /* Hidden by default */
    margin-top: 10px;
    background: #0b0c0f;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: #a0aec0;
    max-height: 200px;
    overflow-y: auto;
}

/* Input Area */
.chat-input-container {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 800px;
    background: rgba(24, 27, 33, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 30px;
    padding: 5px 10px;
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
}

/* --- Chat Input Disabled State --- */
.chat-input-container .chat-input:disabled {
    background-color: rgba(0, 0, 0, 0.2);
    cursor: not-allowed;
}

.chat-input-container .btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: scale(1);
    /* Prevent hover effect */
    background-color: var(--primary-color);
}

.chat-input {
    background: transparent;
    border: none;
    color: white;
    resize: none;
    /* No resize handle */
    height: 40px;
    /* Base height */
    max-height: 120px;
    padding: 10px 15px;
    flex: 1;
    overflow: hidden;
}

.chat-input {
    /* For Chrome, Safari, Edge */
    -webkit-appearance: none;
    /* Removes default browser styling including scrollbar arrows */

    /* For Firefox */
    scrollbar-width: none;
    /* Hides the scrollbar track and thumb */

    /* For Internet Explorer and older Edge versions */
    -ms-overflow-style: none;
    /* Hides the scrollbar for these browsers */

    /* Ensure content overflow is handled */
    overflow: auto;
    /* Allows scrolling when content exceeds the textarea height */
}

.chat-input::placeholder {
    color: white;
    opacity: 0.4;
}

.chat-input:focus {
    outline: none;
    box-shadow: none;
    background: transparent;
    color: white;
}

.btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.btn-send:hover {
    transform: scale(1.1);
    background-color: var(--accent-color);
    color: #000;
}

/* Typing Indicator */
.typing-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--text-secondary);
    margin-right: 3px;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* --- Voice Interface --- */
.voice-wrapper {
    height: calc(100svh - 80px);
    background: radial-gradient(circle at center, #1b202b 0%, var(--bg-body) 70%);
}

.visualizer-container {
    width: 600px;
    height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* The Main Button (Orb) */
.voice-orb {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #2d3748, #1a202c);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-size: 2rem;
    z-index: 10;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
}

.voice-orb:hover {
    transform: scale(1.05);
    color: white;
    box-shadow: 0 0 40px rgba(46, 134, 171, 0.4);
}

.voice-orb.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 0 50px var(--accent-glow);
}

.voice-orb.error {
    background: #e53e3e;
    box-shadow: 0 0 30px rgba(229, 62, 62, 0.4);
}

/* Ripples (Simulating Output/Ambience) */
.orb-ripple {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 2px solid var(--accent-color);
    opacity: 0;
    z-index: 1;
    pointer-events: none;
}

.voice-orb.active~.orb-ripple {
    animation: ripple-effect 2s infinite linear;
}

.voice-orb.active~.orb-ripple.delay-1 {
    animation-delay: 1s;
}

@keyframes ripple-effect {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }

    100% {
        transform: scale(3);
        opacity: 0;
    }
}

/* Canvas for Mic Waveform */
#audioCanvas {
    position: absolute;
    bottom: -50px;
    left: 0;
    width: 100%;
    height: 100px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s;
}

.voice-orb.active~#audioCanvas {
    opacity: 1;
}