/* ============================================================
   PRAGYA AI — style.css  v4.0
   Dark, refined, fully mobile-responsive
   ============================================================ */

/* --- RESET & VARIABLES --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-deep:    #0a0f1e;
    --bg-sidebar: #0d1424;
    --bg-main:    #0f172a;
    --bg-header:  #111827;
    --bg-input:   #1e293b;
    --bg-user:    #2563eb;
    --bg-ai:      #1e293b;
    --text-main:  #e2e8f0;
    --text-muted: #94a3b8;
    --text-ai:    #e2e8f0;
    --accent:     #3b82f6;
    --accent-2:   #6366f1;
    --border:     #1e293b;
    --danger:     #ef4444;
    --success:    #22c55e;
    --radius:     14px;
    --radius-sm:  8px;
    --shadow:     0 4px 24px rgba(0,0,0,0.4);
    --sidebar-w:  270px;
    --font:       'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body { height: 100%; overflow: hidden; }

body {
    font-family: var(--font);
    background: var(--bg-deep);
    color: var(--text-main);
}

/* ============================================================
   APP LAYOUT
   ============================================================ */

#app {
    display: flex;
    height: 90vh;
    overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease, min-width 0.3s ease;
    z-index: 200;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 14px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-icon {
    color: var(--accent);
    font-size: 18px;
}

.sidebar-header h2 {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: 0.3px;
}

#new-chat-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: white;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    flex-shrink: 0;
}

#new-chat-btn:hover { background: #1d4ed8; transform: scale(1.08); }

/* Group that holds + and ✕ buttons */
.sidebar-header-btns {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

#close-sidebar-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #1e293b;
    border: 1px solid #334155;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    flex-shrink: 0;
}
#close-sidebar-btn:hover { background: #374151; color: #fff; transform: scale(1.08); }

#user-status {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

/* Logged-in state */
.sidebar-user {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.user-name-sidebar {
    color: var(--success);
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    transition: color 0.15s;
}
.user-name-sidebar:hover { color: #4ade80; text-decoration: underline; }

.sidebar-logout-btn {
    display: inline-block;
    background: #374151;
    color: #e2e8f0;
    text-decoration: none;
    padding: 5px 12px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    transition: background 0.2s;
}
.sidebar-logout-btn:hover { background: #ef4444; color: #fff; }

/* Guest state */
.sidebar-guest { display: block; }

.sidebar-login-btn {
    display: block;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    padding: 7px 12px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    transition: background 0.2s;
}
.sidebar-login-btn:hover { background: #1d4ed8; }

#chat-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

#chat-sessions::-webkit-scrollbar { width: 4px; }
#chat-sessions::-webkit-scrollbar-track { background: transparent; }
#chat-sessions::-webkit-scrollbar-thumb { background: #2d3748; border-radius: 4px; }

/* Session item — flex row */
.session-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px 0 4px;
    border-radius: var(--radius-sm);
    margin: 2px 8px;
    font-size: 13.5px;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
    user-select: none;
    position: relative;
    min-height: 38px;
}

.session-item:hover  { background: #1e293b; color: var(--text-main); }
.session-item.active { background: #1e3a5f; color: var(--accent); font-weight: 600; }

/* Chat title — fills remaining space, clips overflow */
.session-label {
    flex: 1;
    min-width: 0;
    padding: 9px 4px 9px 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

/* ⋮ button — hidden until hover/active */
.session-menu-btn {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
}
.session-item:hover  .session-menu-btn,
.session-item.active .session-menu-btn { opacity: 1; }
.session-menu-btn:hover { background: #2d3748; color: #fff; }

/* On touch devices always show the ⋮ button */
@media (hover: none) { .session-menu-btn { opacity: 1; } }

/* Dropdown menu */
.session-menu {
    display: none;
    flex-direction: column;
    position: absolute;
    right: 4px;
    top: calc(100% + 2px);
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 1000;
    min-width: 130px;
    overflow: hidden;
}
.session-menu.open { display: flex; }

.session-menu-item {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 13px;
    padding: 9px 14px;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
    margin: 0;
    width: 100%;
}
.session-menu-item:hover         { background: #2d3748; }
.session-menu-item.danger        { color: var(--danger); }
.session-menu-item.danger:hover  { background: #3b1a1a; }

/* Toast notification */
#pragya-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1e293b;
    color: var(--text-main);
    border: 1px solid #334155;
    border-radius: 22px;
    padding: 10px 20px;
    font-size: 13px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 9999;
    white-space: nowrap;
}
#pragya-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   MAIN AREA
   ============================================================ */

#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-main);
    overflow: hidden;
}

/* ============================================================
   HEADER
   ============================================================ */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 10px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

#toggle-sidebar {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    line-height: 1;
    transition: background 0.15s;
    flex-shrink: 0;
    margin: 0;
}

#toggle-sidebar:hover { background: #1e293b; }

.header-logo {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.header-text h1 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
}

.header-text p {
    font-size: 11px;
    color: var(--text-muted);
}

/* Auth buttons */
.auth-btn {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: opacity 0.2s;
    white-space: nowrap;
}
.auth-btn:hover { opacity: 0.85; }
.login-btn    { background: var(--accent); color: #fff; }
.logout-btn   { background: #475569; color: #fff; }
.register-btn { background: var(--success); color: #fff; }

.user-name {
    font-size: 13px;
    color: var(--success);
    font-weight: 600;
}

/* ============================================================
   CHAT WINDOW
   ============================================================ */

#chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#chat-window::-webkit-scrollbar { width: 5px; }
#chat-window::-webkit-scrollbar-track { background: transparent; }
#chat-window::-webkit-scrollbar-thumb { background: #2d3748; border-radius: 4px; }

/* Welcome message */
.welcome-msg {
    text-align: center;
    color: var(--text-muted);
    font-size: 18px;
    margin: auto;
    padding: 40px 20px;
    line-height: 1.6;
}

/* Message bubbles */
.message {
    max-width: 75%;
    padding: 11px 15px;
    border-radius: var(--radius);
    font-size: 14.5px;
    line-height: 1.6;
    position: relative;
    word-break: break-word;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    padding-bottom: 28px; /* space for copy btn */
}

.message.user {
    background: var(--bg-user);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.message.ai {
    background: var(--bg-ai);
    color: var(--text-ai);      /* ← FIX: was white-on-white */
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid #2d3748;
}

.text-content {
    white-space: pre-wrap;
    word-break: normal;
}

/* Copy button */
.copy-btn {
    position: absolute;
    right: 8px;
    bottom: 6px;
    background: transparent;
    border: 1px solid #4b5563;
    border-radius: 5px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 7px;
    opacity: 0.7;
    transition: opacity 0.2s;
    margin: 0;
}
.copy-btn:hover { opacity: 1; background: #2d3748; }

/* AI image */
.ai-image {
    max-width: 100%;
    border-radius: 10px;
    margin-top: 8px;
    display: block;
    cursor: pointer;
    transition: transform 0.2s;
}
.ai-image:hover { transform: scale(1.02); }

/* ============================================================
   INPUT AREA
   ============================================================ */

#input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px 18px;
    background: var(--bg-header);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#message {
    flex: 1;
    padding: 10px 14px;
    font-size: 14px;
    background: var(--bg-input);
    border: 1px solid #334155;
    border-radius: 22px;
    color: var(--text-main);
    outline: none;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    font-family: var(--font);
    line-height: 1.5;
    transition: border-color 0.2s;
}

#message::placeholder { color: #64748b; }
#message:focus { border-color: var(--accent); }

/* Buttons */
#input-area button {
    height: 42px;
    padding: 0 16px;
    border: none;
    border-radius: 22px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: transform 0.15s, background 0.2s;
    flex-shrink: 0;
    margin: 0;
}

#send-btn {
    background: var(--accent);
    color: white;
    min-width: 46px;
}
#send-btn:hover { background: #1d4ed8; transform: scale(1.05); }

#stop-btn {
    background: var(--danger);
    color: white;
}
#stop-btn:hover { background: #dc2626; transform: scale(1.05); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.6; }
}
#stop-btn { animation: pulse 1.6s infinite; }

#regen-btn {
    background: var(--success);
    color: white;
    display: none;
}
#regen-btn:hover { background: #16a34a; }

/* Desktop sidebar hide/show toggle */
#app.sidebar-hidden #sidebar {
    width: 0;
    min-width: 0;
    overflow: hidden;
    border-right: none;
}

#app.sidebar-hidden #main {
    flex: 1;
}

footer { display:block; width:100%; height: 40px; text-align: center; margin-top: 30px; font-size: 0.9em; color: #666; }


/* Push links to the bottom */
#site-links {
    margin-top: auto; /* This is the "magic" that pushes it down */
    padding: 20px 15px;
    border-top: 1px solid #1e293b; /* subtle line above links */
    display: flex;
    flex-direction: column;
    gap: 8px; /* space between links */
}

/* Style the links */
#site-links a {
    color: #94a3b8; /* subtle grey */
    font-size: 13px;
    text-decoration: none;
    transition: color 0.2s;
}

#site-links a:hover {
    color: #3b82f6; /* blue on hover */
}

/* Social Share Container */
.social-share-row {
    padding: 5px 0 10px 0;
    margin: auto;
}

.social-share-row p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.social-icons {
    display: flex;
    gap: 15px;
    align-items: center;
}

.share-icon {
    font-size: 18px;
    transition: transform 0.2s ease, color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Brand Colors */
.share-icon.whatsapp { color: #25D366; }
.share-icon.facebook { color: #1877F2; }
.share-icon.x-twitter { color: #ffffff; } /* White for X on dark bg */

.share-icon:hover {
    transform: translateY(-3px); /* Pop up effect */
    filter: brightness(1.2);
}

/* Ensure icons don't look like text links */
#site-links .share-icon {
    text-decoration: none !important;
}

.star-rating {
    display: flex;
    gap: 5px;
    margin: 8px 0;
    font-size: 1.2rem;
    color: #fbbf24; /* Gold */
    cursor: pointer;
}

.star-rating i.fas { color: #fbbf24; } /* Filled star */
.star-rating i.far { color: #475569; } /* Empty star */


#rating-status {
    display: block;
    margin-top: 5px;
    font-size: 11px;
    font-weight: bold;
    height: 15px; /* Prevents layout jumping */
    transition: opacity 0.5s ease;
        color: var(--text-muted);
}

.rating-display {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 4px;
}

#rating-container
 {
    margin: auto;
}

#avg-score {
    color: #facc15; /* Star Yellow */
    font-weight: bold;
    font-size: 14px;
}

#vote-count {
    font-weight: 500;
}

/* Sidebar Ad Styling */
.ad-container-sidebar {
    padding: 10px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
}

/* Main Ad Styling (Above Input) */
.ad-container-main {
    text-align: center;
    background: var(--bg-main);
    padding: 5px 0;
    border-top: 1px solid var(--border);
    /* Ensures it doesn't push the input area off-screen on small phones */
    max-height: 60px; 
}

/* Ensure ads don't exceed screen width on mobile */
ins.adsbygoogle {
    max-width: 100% !important;
}

/* ============================================================
   MOBILE RESPONSIVE  (≤ 768px)
   ============================================================ */

@media (max-width: 768px) {
    #app { position: relative; overflow: hidden; }

    /* Sidebar slides in from left as overlay */
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        min-width: unset;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 9999;
        box-shadow: var(--shadow);
    }

    #sidebar.show {
        transform: translateX(0);
    }

    /* Dim overlay when sidebar open */
    #sidebar.show::after {
        content: '';
        position: fixed;
        top: 0; left: 280px; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: -1;
    }

    #main {
        width: 100%;
        height: 94vh;
    }

    #chat-window {
        padding: 12px 10px;
    }

    .message {
        max-width: 90%;
        font-size: 14px;
    }

    #input-area {
        padding: 10px 10px 20px;
        margin-bottom: 40px;
    }

    #message {
        font-size: 14px;
    }

    .header-text p { display: none; }

    .auth-btn {
        padding: 5px 9px;
        font-size: 11px;
    }

    .header-logo {
        width: 32px;
        height: 32px;
    }
    
    /* Cookie Banner */
.cookie-notice {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 500px;
    background: var(--bg-input);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 20px;
    z-index: 10000;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.cookie-content p {
    font-size: 13px;
    margin-bottom: 15px;
    color: var(--text-main);
}

.cookie-content a {
    color: var(--accent);
    text-decoration: underline;
}

.cookie-btns {
    display: flex;
    gap: 10px;
}

.cookie-btns button {
    flex: 1;
    padding: 10px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: opacity 0.2s;
}

.btn-accept { background: var(--success); color: white; }
.btn-reject { background: var(--bg-sidebar); color: var(--text-muted); border: 1px solid var(--border) !important; }

.cookie-btns button:hover { opacity: 0.8; }
    
    footer { display:block; text-align: center; width:auto; height: auto; font-size: 0.9em; color: #666; }
}

.fa-brands, .fab{font-size: 18px}

/* ============================================================
   TABLET  (769px – 1024px)
   ============================================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    :root { --sidebar-w: 220px; }
    .message { max-width: 82%; }
}
