/* ============================================================
   ESPACE D'AIDE - SSN BÉNIN - PLATFORM STYLES
   ============================================================ */

body.app-layout {
    background-color: var(--bg-body);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
    flex-grow: 1;
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2.5rem;
}

/* Responsive Utilities */
.dashboard-banner {
    background: linear-gradient(135deg, var(--bg-surface) 0%, var(--primary-light) 100%);
    padding: 2rem;
    border-radius: var(--radius-xl);
    border: 1px solid var(--primary);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
}
.dashboard-hero {
    background: linear-gradient(to right, var(--primary), #4338CA);
    color: white;
    padding: 3rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
}
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}
.dashboard-card {
    background: var(--bg-surface);
    padding: 2rem;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    min-width: 0; /* prevent overflow in grid */
}
.flex-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

/* Quota Badge (compact version in banner) */
.quota-badge {
    background: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    text-align: center;
    flex-shrink: 0;
    min-width: 80px;
}
.quota-badge-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; font-weight: 700; letter-spacing: 0.05em; }
.quota-badge-count { font-size: 1.75rem; font-weight: 800; line-height: 1; }
.quota-badge-count small { font-size: 1rem; font-weight: 600; }

/* Sidebar */
.app-sidebar {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    height: calc(100vh - 120px);
    position: sticky;
    top: 100px;
    display: flex;
    flex-direction: column;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-user img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}
.sidebar-user-info {
    flex: 1;
    min-width: 0;
}
.sidebar-user-info h4 { 
    font-size: 1rem; 
    margin-bottom: 0.15rem; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
}
.sidebar-user-info p { 
    font-size: 0.85rem; 
    color: var(--text-muted); 
    margin-bottom: 0.25rem; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
}
.sidebar-user-info .badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    font-size: 0.65rem;
    border-radius: 4px;
}

.sidebar-nav {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex-grow: 1;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    color: var(--text-muted);
    font-weight: 500;
    transition: var(--transition);
}
.sidebar-nav a:hover, .sidebar-nav a.active {
    background: var(--primary-light);
    color: var(--primary);
}
.sidebar-nav a i { font-size: 1.125rem; width: 24px; text-align: center; }
.sidebar-nav a .badge-new {
    margin-left: auto;
    font-size: 0.65rem;
    padding: 0.2rem 0.45rem;
    border-radius: 6px;
    background: var(--accent);
    color: white;
    font-weight: 800;
}

.sidebar-quota {
    margin-top: auto;
    background: #F1F5F9;
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}
.quota-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: flex-start;
    font-size: 0.725rem; 
    font-weight: 700; 
    margin-bottom: 0.75rem;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    gap: 0.5rem;
}
.quota-header span:first-child { flex: 1; }
.quota-header span:last-child { white-space: nowrap; flex-shrink: 0; color: var(--primary); }
.quota-bar { height: 8px; background: #E2E8F0; border-radius: 999px; overflow: hidden; margin-bottom: 0.75rem; }
.quota-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.5s ease-out; }

/* Main Content Area */
.app-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Auth Pages */
.auth-container {
    max-width: 450px;
    margin: 4rem auto;
    width: 100%;
    padding: 2rem;
}
.auth-box {
    background: var(--bg-surface);
    padding: 3rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}
.form-group { margin-bottom: 1.5rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.5rem; }
.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.alert { padding: 1rem; border-radius: var(--radius-md); margin-bottom: 1.5rem; }
.alert-error { background: #FEE2E2; color: #991B1B; border: 1px solid #F87171; }
.alert-success { background: #D1FAE5; color: #065F46; border: 1px solid #34D399; }

/* Forum UI */
.forum-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.forum-search { display: flex; gap: 1rem; margin-bottom: 2rem; }
.forum-search input { flex-grow: 1; }

.post-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    gap: 1.5rem;
    transition: var(--transition);
}
.post-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.post-stats { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; min-width: 60px; }
.stat-box { display: flex; flex-direction: column; align-items: center; padding: 0.5rem; border-radius: var(--radius-sm); width: 100%; background: #F8FAFC; }
.stat-box.has-answers { background: #ECFDF5; color: var(--secondary); border: 1px solid #A7F3D0; }
.stat-box span { font-size: 1.25rem; font-weight: 700; }
.stat-box small { font-size: 0.75rem; font-weight: 500; text-transform: uppercase; }

.post-content { flex-grow: 1; }
.post-title { font-size: 1.25rem; margin-bottom: 0.5rem; }
.post-title a { color: var(--text-main); }
.post-title a:hover { color: var(--primary); }
.post-meta { display: flex; gap: 1rem; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; align-items: center; }
.post-tags { display: flex; gap: 0.5rem; }
.tag { background: #F1F5F9; color: var(--text-muted); padding: 0.15rem 0.5rem; border-radius: var(--radius-sm); font-size: 0.75rem; }

/* AI Assistant UI */
.chat-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    height: 600px;
    overflow: hidden;
}
.chat-messages {
    flex-grow: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: #ffffff;
}
.message { display: flex; gap: 0.75rem; max-width: 75%; }
.message-ai { align-self: flex-start; }
.message-user { align-self: flex-end; flex-direction: row-reverse; }
.message-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 0.9rem; }
.message-ai .message-avatar { background: #e4e6eb; color: #050505; }
.message-user .message-avatar { display: none; } /* Messenger doesn't show user avatar in chat */
.message-bubble { padding: 0.75rem 1rem; border-radius: 1.25rem; line-height: 1.4; font-size: 0.95rem; word-wrap: break-word; }
.message-ai .message-bubble { background: #e4e6eb; color: #050505; border-bottom-left-radius: 0.25rem; }
.message-user .message-bubble { background: #0084ff; color: white; border-bottom-right-radius: 0.25rem; }

.chat-input { padding: 1rem; background: white; border-top: 1px solid var(--border); }
.chat-form { display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-form textarea { 
    flex-grow: 1; 
    resize: none; 
    border-radius: 1.5rem; 
    padding: 0.75rem 1.25rem; 
    height: 48px; 
    border: none;
    background: #f0f2f5; 
    font-family: inherit; 
    font-size: 0.95rem;
}
.chat-form textarea:focus { outline: none; background: #e4e6eb; }
.chat-btn-send {
    border-radius: 50%;
    width: 48px;
    height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #0084ff;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
    flex-shrink: 0;
}
.chat-btn-send:hover { background: #f0f2f5; }

/* Typing indicator */
.typing-indicator { display: flex; gap: 4px; padding: 0.5rem 0.25rem; }
.typing-dot { width: 6px; height: 6px; background: #8a8d91; border-radius: 50%; animation: typing 1.4s infinite ease-in-out; }
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.chat-options {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

@media (max-width: 1024px) {
    .app-container { padding: 1rem; gap: 1rem; grid-template-columns: 1fr; }
    .auth-box { padding: 1.5rem; }
    
    /* Forum Responsiveness */
    .forum-header { flex-direction: column; align-items: stretch; gap: 1rem; text-align: center; }
    .forum-search { flex-direction: column; }
    .forum-search select { width: 100% !important; }
    .post-card { flex-direction: column; gap: 1rem; }
    .post-stats { flex-direction: row; justify-content: flex-start; gap: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 1rem; }
    .stat-box { flex-direction: row; width: auto; padding: 0.25rem 0.75rem; gap: 0.5rem; }
    
    /* Mobile Sidebar → Horizontal top nav strip (NOT fixed) */
    .app-container {
        display: flex;
        flex-direction: column;
        padding: 0;
        gap: 0;
        grid-template-columns: unset;
    }
    .app-sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        padding: 0;
        border-radius: 0;
        border: none;
        border-bottom: 1px solid var(--border);
        background: white;
        box-shadow: 0 2px 6px rgba(0,0,0,0.05);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        /* hide scrollbar visually */
        scrollbar-width: none;
    }
    .app-sidebar::-webkit-scrollbar { display: none; }
    .sidebar-user, .sidebar-quota { display: none !important; }
    .sidebar-nav {
        flex-direction: row;
        width: 100%;
        gap: 0;
        flex-grow: 0;
    }
    .sidebar-nav li { flex: none; }
    .sidebar-nav a {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 0.6rem 1.1rem;
        border-radius: 0;
        font-size: 0.7rem;
        gap: 0.2rem;
        white-space: nowrap;
        border-bottom: 3px solid transparent;
    }
    .sidebar-nav a.active { background: none; color: var(--primary); border-bottom-color: var(--primary); }
    .sidebar-nav a i { margin: 0; font-size: 1.1rem; }
    .sidebar-nav a span.badge-new { display: none; }

    body.app-layout { padding-bottom: 0; }

    .app-content { padding: 1rem; }
    .chat-container { height: calc(100vh - 200px); border-radius: var(--radius-lg); margin: 0; }
    .chat-messages { padding: 1rem; gap: 0.75rem; }
    .message { max-width: 90%; }
    .message-bubble { padding: 0.65rem 0.85rem; font-size: 0.95rem; }
    .chat-options { flex-direction: row; overflow-x: auto; padding-bottom: 0.5rem; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    .chat-options select { width: auto !important; flex-shrink: 0; font-size: 0.85rem; padding: 0.5rem; }
    .chat-input { padding: 0.75rem; }
    .chat-form textarea { height: 42px; padding: 0.5rem 1rem; }
    .chat-btn-send { height: 42px; width: 42px; font-size: 1.25rem; }
    
    /* Layout Utilities */
    .dashboard-banner { flex-direction: row; align-items: center; gap: 1rem; padding: 1rem; }
    .dashboard-hero { padding: 1.25rem; margin-bottom: 1rem; }
    .dashboard-hero h1 { font-size: 1.5rem !important; }
    .dashboard-hero p { font-size: 0.9rem !important; }
    .grid-2 { grid-template-columns: 1fr; gap: 1rem; }
    .flex-actions { flex-direction: column; gap: 0.75rem; margin-top: 1rem; }
    .flex-actions .btn { text-align: center; width: 100%; }
    .dashboard-card { padding: 1.25rem; }

    /* Auth & Grids on mobile */
    .auth-container { padding-top: 6rem; padding-bottom: 3rem; }
    .auth-box { padding: 2rem 1.5rem; }
    form div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 0 !important;
    }
}
