:root {
    --bg-color: #0f111a;
    --panel-bg: rgba(25, 28, 41, 0.65);
    --panel-border: rgba(255, 255, 255, 0.08);
    --primary: #7b2cbf;
    --primary-hover: #9d4edd;
    --accent: #00f5d4;
    --text-main: #f8f9fa;
    --text-muted: #adb5bd;
    --danger: #ef233c;
    --success: #38b000;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    overflow: hidden; /* The main chat app needs fixed height */
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(123, 44, 191, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(0, 245, 212, 0.1), transparent 25%);
    background-attachment: fixed;
}

/* Pages that need scrolling (profile, admin, auth) override body */
body.scrollable-page {
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Cairo', sans-serif;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-width: 1600px;
    margin: 0 auto;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: rgba(15, 17, 26, 0.8);
    backdrop-filter: blur(10px);
    border-left: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    padding: 2rem 1rem;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 3rem;
    padding: 0 1rem;
}

.brand i {
    font-size: 2rem;
    color: var(--accent);
    filter: drop-shadow(0 0 8px rgba(0, 245, 212, 0.5));
}

.brand h1 {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(90deg, var(--text-main), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    background: transparent;
    border: none;
    padding: 1rem 1.2rem;
    color: var(--text-muted);
    font-family: 'Cairo', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: right;
}

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

.nav-item:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(-4px);
}

.nav-item.active {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    box-shadow: 0 4px 15px rgba(123, 44, 191, 0.4);
}

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

.content-section {
    display: none;
    animation: fadeIn 0.4s ease forwards;
    height: 100%;
    flex-direction: column;
}

.content-section.active {
    display: flex;
}

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

.section-header {
    margin-bottom: 2rem;
}

.section-header h2 {
    font-size: 2.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.section-header p {
    color: var(--text-muted);
    font-size: 1.05rem;
}

/* Buttons & Inputs */
.btn {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-family: 'Cairo', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(123, 44, 191, 0.3);
}

.btn-icon {
    background: var(--primary);
    color: #fff;
    padding: 0.8rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
}

.btn-icon:hover {
    background: var(--primary-hover);
}

input[type="text"], input[type="password"] {
    width: 100%;
    padding: 1rem 1.2rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    color: var(--text-main);
    font-family: 'Cairo', sans-serif;
    font-size: 1rem;
    transition: all 0.3s ease;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(123, 44, 191, 0.25);
}

/* Forms */
.input-group {
    display: flex;
    gap: 1rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-group label i {
    color: var(--accent);
    cursor: help;
}

/* Knowledge Base */
.kb-input-area {
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.kb-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.kb-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--panel-border);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.kb-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.kb-text {
    font-weight: 500;
    word-break: break-word;
}

.delete-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s;
}

.delete-btn:hover {
    color: var(--danger);
    background: rgba(239, 35, 60, 0.1);
}

/* Chat/Practice Area */
.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    padding: 1rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--panel-border) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background-color: var(--panel-border);
    border-radius: 10px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.msg-name {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 5px;
    margin-right: 5px;
    margin-left: 5px;
}

.msg-bubble-container {
    display: flex;
    flex-direction: column;
}

.msg-bubble {
    padding: 1rem 1.2rem;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 1.05rem;
}

.system-msg {
    align-self: center;
    max-width: 90%;
    text-align: center;
}

.system-msg .msg-bubble {
    background: rgba(0, 245, 212, 0.1);
    color: var(--accent);
    border: 1px solid rgba(0, 245, 212, 0.2);
    font-size: 0.95rem;
}

.user-msg {
    align-self: flex-end;
}

.user-msg .msg-name {
    align-self: flex-end;
}

.user-msg .msg-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-left-radius: 4px;
}

.ai-msg {
    align-self: flex-start;
}

.ai-msg .msg-name {
    align-self: flex-start;
}

.ai-msg .msg-bubble {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--panel-border);
    border-bottom-right-radius: 4px;
}

.ai-msg.loading-msg .msg-bubble {
    display: flex;
    align-items: center;
    gap: 8px;
}

.typing-indicator span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: #fff;
    border-radius: 50%;
    animation: typing 1.4s infinite cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

@keyframes typing {
    0%, 100% { transform: translateY(0); opacity: 0.3; }
    50% { transform: translateY(-4px); opacity: 1; }
}

/* Quick Prompts Chat */
.quick-prompts {
    display: flex;
    gap: 0.8rem;
    padding: 0.5rem 1rem;
    overflow-x: auto;
    scrollbar-width: none;
    margin-top: 0.5rem;
}
.quick-prompts::-webkit-scrollbar {
    display: none;
}
.quick-btn {
    background: rgba(123, 44, 191, 0.2);
    border: 1px solid var(--primary);
    color: var(--text-main);
    padding: 0.6rem 1.2rem;
    border-radius: 20px;
    white-space: nowrap;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}
.quick-btn:hover {
    background: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(123, 44, 191, 0.3);
}

.chat-input-area {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    margin-top: 1rem;
}

.chat-input-area input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
}

.chat-input-area input:focus {
    box-shadow: none;
}

/* Settings Form */
.settings-form {
    padding: 2rem;
    max-width: 600px;
}

/* Gamification */
.user-progress {
    margin-bottom: 2rem;
    padding: 1.5rem 1rem;
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 16px;
    text-align: center;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.2);
}
.level-badge {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--primary));
    color: #fff;
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 12px;
    box-shadow: 0 4px 15px rgba(0, 245, 212, 0.3);
    border: 3px solid rgba(255,255,255,0.2);
}
.user-title {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: var(--text-main);
}
.progress-track {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.xp-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 8px;
    font-family: 'Courier New', Courier, monospace;
}
/* Flashing XP gain animation */
@keyframes xpGain {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.1); filter: brightness(1.5); }
    100% { transform: scale(1); filter: brightness(1); }
}
.xp-gain-anim .level-badge {
    animation: xpGain 0.5s ease;
}

/* Markdown and Voice Styles */
.markdown-body {
    line-height: 1.6;
}

.markdown-body p {
    margin-bottom: 0.8rem;
}
.markdown-body p:last-child {
    margin-bottom: 0;
}

.markdown-body strong {
    color: var(--accent);
}

.markdown-body ul, .markdown-body ol {
    margin-right: 1.5rem;
    margin-bottom: 0.8rem;
}

.markdown-body pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 1rem 1rem 1rem 3.5rem; 
    border-radius: 8px;
    position: relative;
    margin: 1rem 0;
    direction: ltr; /* English text should be LTR */
    text-align: left;
    border: 1px solid var(--panel-border);
}

.markdown-body code {
    font-family: 'Courier New', Courier, monospace;
    color: #fff;
    font-size: 0.95rem;
}

/* For inline code */
.markdown-body p code {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}

.play-btn {
    position: absolute;
    top: 8px;
    left: 8px; /* Left aligned because the block is LTR */
    background: var(--primary);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.play-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

/* Mic Active Pulse */
.mic-active {
    background: var(--danger) !important;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 35, 60, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(239, 35, 60, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 35, 60, 0);
    }
}

/* =========================================
   Responsive Design for All Screens (Mobile📱 / Tablet)
   ========================================= */
@media screen and (max-width: 900px) {
    .app-container {
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }
    
    .sidebar {
        width: 100%;
        height: 70px;
        flex-direction: row;
        padding: 0 1rem;
        align-items: center;
        justify-content: space-between;
        border-left: none;
        border-bottom: 1px solid var(--panel-border);
        z-index: 100;
        background: rgba(15, 17, 26, 0.95);
        gap: 10px;
    }

    .brand {
        margin-bottom: 0;
        padding: 0;
        flex-shrink: 0;
    }

    .brand h1 {
        font-size: 1.2rem;
    }
    
    .user-progress {
        display: none !important; /* Hide user progress on small headers to save space */
    }

    .nav-menu {
        flex-direction: row;
        gap: 5px;
        overflow-x: auto;
        /* Hide scrollbar */
        scrollbar-width: none;
        flex-wrap: nowrap;
        height: 100%;
        align-items: center;
    }
    
    .nav-menu::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
        white-space: nowrap;
        border-radius: 8px;
    }

    .nav-item i {
        margin-left: 0;
        font-size: 1.1rem;
    }

    .nav-item span {
        display: none; /* Hide text on mobile nav, keep icons */
    }

    .nav-item[id="nav-kb"] span#kb-count-badge {
        display: inline-block;
        position: absolute;
        top: -5px;
        right: -5px;
        font-size: 0.6rem;
        padding: 2px 5px;
    }
    
    .nav-item { position: relative; } /* For the badge positioning */

    .main-content {
        padding: 1rem;
        padding-bottom: 2rem;
        height: calc(100vh - 70px);
        height: calc(100dvh - 70px);
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px !important;
    }

    .section-header h2 {
        font-size: 1.4rem;
    }

    .kb-list {
        grid-template-columns: 1fr;
    }

    .chat-messages {
        padding: 0.5rem;
    }

    .msg-bubble {
        padding: 0.8rem;
        font-size: 0.95rem;
    }
    
    .message {
        max-width: 95%;
    }
    
    .chat-input-area {
        padding: 0.8rem;
        gap: 0.5rem;
        flex-wrap: nowrap;
    }
    
    .input-group {
        flex-wrap: nowrap;
    }

    .btn-icon, .btn-primary {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    
    .btn-icon {
        width: 45px;
        height: 45px;
        padding: 0;
        display: flex;
        justify-content: center;
        align-items: center;
    }
}

@media screen and (max-width: 480px) {
    .settings-form {
        padding: 1rem;
    }
    
    .input-group, #kb-form .input-group {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }

    /* Exceptions where buttons shouldn't be 100% width */
    .chat-input-area .input-group {
        flex-direction: row; /* Keep chat input and send inline */
    }
    .chat-input-area .btn {
        width: auto;
    }
    
    .section-header > div:last-child {
        width: 100%;
        justify-content: space-between;
    }
    
    .section-header .btn {
        flex: 1;
    }
    
    .auth-container {
        padding: 1rem;
    }
    
    .auth-box {
        padding: 1.5rem !important;
    }
    
    .hero-title {
        font-size: 1.8rem !important;
    }
}
