@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700;900&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --bg-dark: #070814;
    --bg-cosmic: radial-gradient(circle at 50% 50%, #15102a 0%, #070814 100%);
    --nebula-purple: rgba(138, 43, 226, 0.15);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-glow: rgba(212, 175, 55, 0.15);
    
    --gold: #d4af37;
    --gold-glow: #ffdf7a;
    --gold-dark: #aa8522;
    --text-light: #f0f0f5;
    --text-muted: #a0a0c0;
    --text-dark: #121212;
    --indigo: #4f46e5;
    
    --font-astro: 'Cinzel', serif;
    --font-ui: 'Outfit', sans-serif;
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background: var(--bg-dark);
    background-image: var(--bg-cosmic);
    color: var(--text-light);
    font-family: var(--font-ui);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Background Stars Animation */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 40px),
        radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 30px),
        radial-gradient(white, rgba(255,255,255,.1) 2px, transparent 40px);
    background-size: 550px 550px, 350px 350px, 250px 250px;
    background-position: 0 0, 40px 60px, 130px 270px;
    opacity: 0.18;
    z-index: -1;
    animation: starsMovement 120s linear infinite;
}

@keyframes starsMovement {
    from { background-position: 0 0, 40px 60px, 130px 270px; }
    to { background-position: 550px 1100px, 350px 700px, 250px 500px; }
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--gold-dark);
}

/* Typographical Styles */
h1, h2, h3, .brand-title {
    font-family: var(--font-astro);
    letter-spacing: 1px;
}

/* Container */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Glass Card */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    padding: 2.5rem;
    transition: var(--transition);
}

.glass-card:hover {
    border-color: rgba(212, 175, 55, 0.25);
    box-shadow: 0 8px 32px 0 rgba(138, 43, 226, 0.1), 0 0 15px var(--glass-glow);
}

/* Golden Headers */
.gold-text {
    background: linear-gradient(135deg, var(--gold-glow) 0%, var(--gold) 50%, var(--gold-dark) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.2);
}

/* Form Styles */
.form-group {
    margin-bottom: 1.5rem;
    position: relative;
}

label {
    display: block;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-weight: 500;
}

input, select, textarea {
    width: 100%;
    padding: 0.8rem 1rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-light);
    font-family: var(--font-ui);
    font-size: 1rem;
    outline: none;
    transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.25);
    background: rgba(0, 0, 0, 0.5);
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.8rem 2rem;
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--gold-glow) 0%, var(--gold) 100%);
    color: var(--text-dark);
    border: none;
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.5), 0 0 10px rgba(255, 223, 122, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    color: var(--text-light);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--text-muted);
}

.btn-danger {
    background: rgba(220, 38, 38, 0.2);
    color: #f87171;
    border: 1px solid rgba(220, 38, 38, 0.4);
}

.btn-danger:hover {
    background: rgba(220, 38, 38, 0.4);
    border-color: #f87171;
}

/* Header/Navbar */
.cosmic-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: rgba(7, 8, 20, 0.6);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.logo-icon {
    font-size: 1.8rem;
    color: var(--gold);
    text-shadow: 0 0 10px var(--gold-glow);
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav-welcome {
    color: var(--text-light);
    font-weight: 500;
    font-size: 0.9rem;
}

.nav-logout-btn {
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    transition: var(--transition);
    font-weight: 500;
    font-size: 0.95rem;
}

.nav-link:hover, .nav-link.active {
    color: var(--gold);
}

/* Card Grid for Profiles */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.profile-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.profile-card::after {
    content: "🪐";
    position: absolute;
    right: -10px;
    bottom: -15px;
    font-size: 4rem;
    opacity: 0.05;
    transition: var(--transition);
}

.profile-card:hover {
    border-color: var(--gold);
    transform: translateY(-5px);
    box-shadow: 0 8px 24px rgba(212, 175, 55, 0.15);
}

.profile-card:hover::after {
    opacity: 0.15;
    right: 5px;
    bottom: -5px;
}

.profile-card h3 {
    margin-bottom: 0.8rem;
    font-size: 1.25rem;
    color: var(--text-light);
}

.profile-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.profile-card-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

.btn-delete-profile {
    background: transparent;
    border: none;
    color: #f87171;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    opacity: 0.6;
    transition: var(--transition);
}

.btn-delete-profile:hover {
    opacity: 1;
    background: rgba(248, 113, 113, 0.1);
}

/* Chat Layout */
.chat-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: calc(100vh - 73px); /* 100vh minus navbar height */
    overflow: hidden;
}

.chat-sidebar {
    background: rgba(7, 8, 20, 0.4);
    border-right: 1px solid var(--glass-border);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.chat-list {
    margin-top: 1.5rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    overflow-y: auto;
}

.chat-item {
    padding: 0.9rem 1rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.chat-item:hover, .chat-item.active {
    background: rgba(212, 175, 55, 0.05);
    border-color: var(--gold);
}

.chat-item h4 {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Chat Area */
.chat-area {
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    height: 100%;
    overflow: hidden;
}

#active-chat-view {
    height: 100%;
    width: 100%;
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.chat-header {
    background: rgba(7, 8, 20, 0.6);
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-profile-info h3 {
    font-size: 1.2rem;
    margin-bottom: 0.2rem;
}

.chat-profile-info p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Messages Container */
.messages-container {
    flex-grow: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.message-bubble {
    max-width: 75%;
    padding: 1rem 1.25rem;
    border-radius: 12px;
    line-height: 1.5;
    position: relative;
    animation: bubbleSlide 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

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

.message-user {
    align-self: flex-end;
    background: rgba(79, 70, 229, 0.2);
    border: 1px solid rgba(79, 70, 229, 0.3);
    border-bottom-right-radius: 2px;
}

.message-ai {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-left: 3px solid var(--gold);
    border-bottom-left-radius: 2px;
}

.message-time {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
    text-align: right;
}

/* Chat Input Area */
.chat-input-container {
    padding: 1.5rem 2rem;
    background: rgba(7, 8, 20, 0.8);
    border-top: 1px solid var(--glass-border);
}

.chat-input-form {
    display: flex;
    gap: 1rem;
}

.chat-input-form input {
    flex-grow: 1;
    border-radius: 24px;
    padding: 0.8rem 1.5rem;
}

.chat-input-form button {
    border-radius: 24px;
    padding: 0 1.8rem;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    align-self: flex-start;
    display: none; /* Controlled by JS */
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--gold);
    border-radius: 50%;
    animation: typingBounce 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 typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Admin Dashboard Table */
.admin-table-container {
    overflow-x: auto;
    margin-top: 2rem;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.admin-table th, .admin-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

.admin-table th {
    font-family: var(--font-astro);
    color: var(--gold);
    font-weight: 600;
}

.admin-table tr:hover {
    background: rgba(255, 255, 255, 0.01);
}

/* Auth Form Toggle */
.auth-toggle {
    display: flex;
    border-bottom: 1px solid var(--glass-border);
    margin-bottom: 2rem;
}

.auth-toggle-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 1rem;
    font-family: var(--font-astro);
    font-size: 1.1rem;
    cursor: pointer;
    transition: var(--transition);
}

.auth-toggle-btn.active {
    color: var(--gold);
    border-bottom: 2px solid var(--gold);
}

/* Notification/Toast */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 1rem 1.5rem;
    background: rgba(20, 20, 35, 0.95);
    border-left: 4px solid var(--gold);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    color: var(--text-light);
    z-index: 1000;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    border-left-color: #f87171;
}

/* TTS Button Styling */
.tts-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 0.3rem 0.8rem;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: var(--transition);
}

.tts-btn:hover {
    background: rgba(212, 175, 55, 0.08);
    border-color: rgba(212, 175, 55, 0.3);
    color: var(--gold);
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.1);
}

.tts-btn.playing {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.4);
    color: #f87171;
    animation: soundwave 1.5s infinite ease-in-out;
}

@keyframes soundwave {
    0%, 100% { box-shadow: 0 0 4px rgba(239, 68, 68, 0.1); }
    50% { box-shadow: 0 0 12px rgba(239, 68, 68, 0.3); }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .chat-layout {
        grid-template-columns: 1fr;
    }
    
    .chat-sidebar {
        display: none; /* Responsive toggle in mobile if needed, or overlay */
    }
    
    .app-container {
        padding: 1rem;
    }
}
