/* --- Modern & Polished UI Theme (Enhanced Readability & Focus) --- */

:root {
    --color-bg: #0f0f1a; /* Dark Navy Background */
    --color-surface: #1a1a2e; /* Slightly Lighter Surface for Cards/Containers */
    --color-text-primary: #e0e0ff; /* Light Lavender Text */
    --color-text-secondary: #a0a0c0; /* Muted Lavender */
    --color-accent: #7b61ff; /* Vibrant Purple/Blue Accent (Modern Pop) */
    --color-border: #3a3a5a; /* Subtle Border */
    --font-main: 'Inter', sans-serif;
    --shadow-subtle: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 15px rgba(123, 97, 255, 0.1);
    --transition-fast: all 0.3s ease-out;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition-fast);
}

/* --- Utility Classes & Global Elements --- */
.hidden {
    display: none !important;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition-fast);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.95rem;
}

.btn.primary {
    background-color: var(--color-accent);
    color: var(--color-bg); 
    box-shadow: 0 4px 10px rgba(123, 97, 255, 0.4);
}

.btn.primary:hover {
    background-color: #6a50e6;
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(123, 97, 255, 0.6);
}

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

.btn.secondary:hover {
    color: var(--color-text-primary);
    border-color: var(--color-accent);
    transform: translateY(-1px);
}

.btn.small {
    padding: 6px 12px;
    font-size: 0.8rem;
    text-transform: none;
    border-radius: 6px;
}

.message {
    margin-top: 10px;
    font-size: 0.9rem;
    min-height: 1.2em;
    text-align: center;
    opacity: 0;
    animation: fadeInText 0.5s forwards;
}

@keyframes fadeInText { 
    to { opacity: 1; } 
}

/* --- Authentication Container --- */
.auth-container {
    width: 100%;
    max-width: 450px;
    padding: 20px;
}

.auth-card {
    background-color: var(--color-surface);
    padding: 50px;
    border-radius: 16px;
    box-shadow: var(--shadow-subtle);
    border: 1px solid var(--color-border);
    animation: scaleUp 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes scaleUp {
    from { opacity: 0; transform: scale(0.95) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.logo {
    font-size: 2.8rem;
    text-align: center;
    color: var(--color-accent);
    margin-bottom: 10px;
    font-weight: 900;
    letter-spacing: -1px;
}

.tagline {
    text-align: center;
    color: var(--color-text-secondary);
    margin-bottom: 35px;
    font-size: 1rem;
}

/* Tab Switching */
.tab-switcher {
    display: flex;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--color-border);
}

.tab-button {
    flex-grow: 1;
    padding: 15px 0;
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    font-weight: 600;
    transition: color 0.3s, border-bottom 0.3s;
    font-size: 1.05rem;
}

.tab-button.active {
    color: var(--color-text-primary);
    border-bottom: 3px solid var(--color-accent);
}

.tab-button:hover:not(.active) {
    color: #c0c0e0;
}

/* Forms */
.auth-form input[type="email"],
.auth-form input[type="password"] {
    width: 100%;
    padding: 16px 15px;
    margin-bottom: 18px;
    border: 1px solid var(--color-border);
    background-color: #111;
    color: var(--color-text-primary);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s, background-color 0.3s;
}

.auth-form input:focus {
    border-color: var(--color-accent);
    outline: none;
    background-color: #171725;
}

.auth-form button[type="submit"] {
    width: 100%;
    padding: 14px;
    margin-top: 10px;
}

/* --- Chat Container (Modern Layout) --- */

.chat-container {
    width: 100%;
    max-width: 1400px;
    height: 95vh;
    max-height: 900px;
    display: flex;
    flex-direction: column;
    background-color: var(--color-surface);
    border-radius: 16px;
    box-shadow: var(--shadow-subtle);
    border: 1px solid var(--color-border);
    overflow: hidden;
    animation: scaleUp 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 30px;
    border-bottom: 1px solid var(--color-border);
    background-color: #151525;
}

.logo-small {
    font-size: 1.7rem;
    color: var(--color-accent);
    font-weight: 800;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 0.95rem;
    color: var(--color-text-secondary);
}

.chat-main {
    display: grid;
    grid-template-columns: 250px 1fr; /* Sidebar slightly narrower */
    flex-grow: 1;
    overflow: hidden;
}

/* --- Sidebar (User List) --- */
.chat-sidebar {
    padding: 25px;
    border-right: 1px solid var(--color-border);
    background-color: #11111f;
    overflow-y: auto;
}

.chat-sidebar h2 {
    font-size: 1.2rem;
    margin-bottom: 18px;
    color: var(--color-text-primary);
    border-bottom: 2px solid rgba(123, 97, 255, 0.2);
    padding-bottom: 10px;
}

#user-list {
    list-style: none;
}

#user-list li {
    padding: 12px 0;
    border-bottom: 1px dotted #303045;
    cursor: default;
    transition: color 0.2s;
    font-size: 0.98rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

#user-list li::before {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--color-accent);
    box-shadow: 0 0 8px var(--color-accent);
    animation: pulseDot 2s infinite ease-in-out;
}

@keyframes pulseDot {
    0%, 100% { transform: scale(0.9); opacity: 0.6; }
    50% { transform: scale(1.1); opacity: 1; }
}

/* --- Chat Window --- */
.chat-window {
    display: flex;
    flex-direction: column;
    background-color: var(--color-surface);
}

.message-feed {
    flex-grow: 1;
    padding: 30px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) var(--color-surface);
}

.message-feed::-webkit-scrollbar {
    width: 10px;
}

.message-feed::-webkit-scrollbar-thumb {
    background-color: var(--color-border);
    border-radius: 10px;
}

.message-feed::-webkit-scrollbar-thumb:hover {
    background-color: var(--color-accent);
}

.message-item {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 12px;
    transition: opacity 0.5s cubic-bezier(0.215, 0.610, 0.355, 1), transform 0.5s cubic-bezier(0.215, 0.610, 0.355, 1);
    opacity: 0; 
    transform: translateY(15px);
}

.message-item.visible {
    opacity: 1;
    transform: translateY(0);
}

.message-sender {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 5px;
    color: var(--color-accent);
}

.message-content {
    font-size: 1.05rem;
    line-height: 1.5;
}

.message-timestamp {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    margin-top: 6px;
    text-align: right;
}

/* Self vs Other Messages Styling */
.message-feed .mine {
    align-self: flex-end;
    background-color: #333350; 
    border-radius: 12px 12px 4px 12px; 
    text-align: right;
}

.message-feed .mine .message-sender {
    color: #c0c0ff; /* Slightly lighter for self */
    text-align: right;
}

.message-feed .mine .message-timestamp {
    color: #8888aa;
}

.message-feed .other {
    align-self: flex-start;
    background-color: #25253b;
    border-radius: 12px 12px 12px 4px;
}

.message-feed .other .message-sender {
    color: #a0a0ff; 
}

/* Input Form */
.message-input-form {
    display: flex;
    padding: 20px 30px;
    border-top: 1px solid var(--color-border);
    background-color: #151525;
}

#message-input {
    flex-grow: 1;
    padding: 14px 18px;
    border: 1px solid var(--color-border);
    background-color: #11111f;
    color: var(--color-text-primary);
    border-radius: 8px 0 0 8px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

#message-input:focus {
    border-color: var(--color-accent);
    outline: none;
    background-color: #171725;
}

.message-input-form .btn {
    border-radius: 0 8px 8px 0;
    height: 50px;
    flex-shrink: 0;
    padding: 10px 25px;
}

/* --- Responsive Adjustments (Crucial for Mobile Compatibility) --- */
@media (max-width: 1024px) {
    .chat-container {
        height: 100vh;
        max-height: none;
        border-radius: 0;
    }

    .chat-main {
        grid-template-columns: 1fr; 
    }

    .chat-sidebar {
        border-right: none;
        border-top: 1px solid var(--color-border);
        min-height: 180px; 
    }

    .chat-window {
        min-height: calc(100vh - 180px - 67px); 
    }

    .message-item {
        max-width: 90%;
    }
}

@media (max-width: 550px) {
    .auth-card {
        padding: 40px 25px;
    }

    .logo {
        font-size: 2.4rem;
    }

    .chat-header {
        padding: 15px 20px;
    }

    .message-feed {
        padding: 20px;
        gap: 15px;
    }

    .message-input-form {
        padding: 15px;
    }

    .message-input-form .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    .message-item {
        max-width: 95%;
        padding: 12px 15px;
    }

    .message-sender {
        font-size: 0.8rem;
    }

    .message-content {
        font-size: 0.98rem;
    }
    
    .user-info {
        gap: 10px;
    }
    
    .user-info span {
        display: none; /* Hide full email on tiny screens */
    }
}

/* Karbon Sites Branding */

  #karbon-promo-banner {
      position: fixed;
      bottom: 10px;
      right: 10px;
      background-color: rgba(0, 0, 0, 0.8);
      color: white;
      padding: 8px 16px;
      border-radius: 8px;
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
      font-size: 14px;
      z-index: 10000;
      display: flex;
      align-items: center;
      gap: 10px;
      text-decoration: none;
      box-shadow: 0 4px 6px rgba(0,0,0,0.1);
      transition: transform 0.2s ease-in-out;
  }
  #karbon-promo-banner:hover {
      transform: scale(1.05);
  }
