/**
 * Main Stylesheet (styles.css)
 * Morgan White Group ChatBot - Glassmorphism Redesign
 *
 * Features:
 * - Glassmorphism UI with frosted glass panels
 * - Chat bubbles with avatars (ChatGPT/Claude-inspired)
 * - Smooth message animations
 * - Light/dark theme via CSS custom properties
 * - Responsive design (1024px, 768px, 480px breakpoints)
 */

/* ===== CSS Variables - Light Theme ===== */
:root {
    /* Core colors */
    --primary-bg: #f0f2f5;
    --secondary-bg: #ffffff;
    --primary-text: #1a1a2e;
    --secondary-text: #64748b;
    --accent-color: #1B4B8F;
    --accent-light: #2563b0;
    --accent-glow: rgba(27, 75, 143, 0.25);
    --border-color: rgba(0, 0, 0, 0.06);

    /* Chat-specific */
    --chat-bot-bg: rgba(255, 255, 255, 0.72);
    --chat-user-bg: rgba(27, 75, 143, 0.88);
    --chat-user-text: #ffffff;
    --input-bg: rgba(255, 255, 255, 0.75);

    /* Glass effect */
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(255, 255, 255, 0.35);
    --glass-blur: 18px;
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);

    /* Shadows & effects */
    --shadow-color: rgba(0, 0, 0, 0.06);
    --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.06);
    --shadow-large: 0 8px 40px rgba(0, 0, 0, 0.1);
    --error-color: #ef4444;

    /* Layout */
    --max-width: 52rem;
    --header-height: 4rem;
    --footer-height: 4.5rem;
    --border-radius-sm: 0.75rem;
    --border-radius-md: 1.25rem;
    --border-radius-lg: 1.5rem;

    /* Typography */
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-heading: 'Outfit', 'DM Sans', sans-serif;

    /* Animation */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Dark Theme Variables ===== */
.dark-mode {
    --primary-bg: #0f172a;
    --secondary-bg: #1e293b;
    --primary-text: #f1f5f9;
    --secondary-text: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.08);
    --chat-bot-bg: rgba(30, 41, 59, 0.8);
    --chat-user-bg: rgba(37, 99, 176, 0.85);
    --chat-user-text: #ffffff;
    --input-bg: rgba(30, 41, 59, 0.85);
    --glass-bg: rgba(15, 23, 42, 0.75);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-color: rgba(0, 0, 0, 0.25);
    --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.2);
    --error-color: #f87171;
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background-color: var(--primary-bg);
    color: var(--primary-text);
    line-height: 1.6;
    transition: background-color var(--transition-normal), color var(--transition-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Background Image */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('https://morganwhite.com/common/img/bg.jpg') no-repeat center center;
    background-size: cover;
    opacity: 0.55;
    z-index: -1;
    transition: opacity var(--transition-normal);
}

.dark-mode body::before {
    opacity: 0.2;
}

/* Root Container */
#root {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: transparent;
    transition: background var(--transition-normal);
}

.dark-mode #root {
    background: linear-gradient(160deg, rgba(15, 23, 42, 0.8) 0%, rgba(15, 23, 42, 0.75) 100%);
}

/* ===== Header - Glassmorphism ===== */
header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    z-index: 1000;
    background: var(--glass-bg);
    border-bottom: 1px solid var(--glass-border);
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--glass-shadow);
    transition: all var(--transition-normal);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-logo {
    display: flex;
    align-items: center;
}

.header-logo img {
    height: calc(var(--header-height) - 1rem);
    width: auto;
    transition: all 0.2s ease;
}

header h1 {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
    transition: color var(--transition-normal);
}

/* Dark Mode Toggle */
#toggle-dark-mode {
    background: rgba(27, 75, 143, 0.1);
    color: var(--accent-color);
    border: 1px solid var(--glass-border);
    padding: 0.5rem 0.875rem;
    border-radius: 2rem;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: var(--font-body);
    transition: all var(--transition-fast);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#toggle-dark-mode:hover {
    background: rgba(27, 75, 143, 0.18);
    transform: translateY(-1px);
    box-shadow: 0 2px 12px var(--accent-glow);
}

.dark-mode #toggle-dark-mode {
    background: rgba(255, 255, 255, 0.08);
    color: var(--primary-text);
    border-color: rgba(255, 255, 255, 0.12);
}

.dark-mode #toggle-dark-mode:hover {
    background: rgba(255, 255, 255, 0.14);
}

/* Theme icons */
.theme-icon { display: inline-flex; }
.theme-icon-dark { display: none; }
.dark-mode .theme-icon-light { display: none; }
.dark-mode .theme-icon-dark { display: inline-flex; }

/* ===== Main Content ===== */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: var(--max-width);
    margin: calc(var(--header-height) + 2rem) auto 0;
    width: 100%;
    padding: 1rem 1.5rem;
    position: relative;
    height: calc(100vh - var(--header-height) - var(--footer-height) - 2rem);
}

/* ===== Chat Container ===== */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
    scroll-behavior: smooth;
    margin-bottom: calc(var(--footer-height) + 10rem);
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
}

/* Message List */
#dialogue {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    list-style: none;
    padding: 0 0.25rem;
}

/* ===== Message Items - Chat Bubble Layout ===== */
#dialogue li {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0;
    width: 100%;
    background: none;
    box-shadow: none;
    border-radius: 0;
    opacity: 0;
    transform: translateY(10px);
    animation: messageSlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Bot messages - left aligned */
#dialogue li.bot-message {
    flex-direction: row;
    justify-content: flex-start;
}

/* User messages - right aligned */
#dialogue li.user-message {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

/* ===== Message Avatars ===== */
.message-avatar {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.125rem;
    transition: transform var(--transition-fast);
}

.message-avatar:hover {
    transform: scale(1.05);
}

.bot-avatar {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.bot-avatar .avatar-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 3px;
}

.user-avatar {
    background: var(--accent-color);
    color: white;
    font-family: var(--font-heading);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px var(--accent-glow);
}

/* ===== Message Bubbles ===== */
.message-bubble {
    max-width: 78%;
    position: relative;
    transition: transform var(--transition-fast);
}

/* Bot message bubble - glass effect */
.bot-message .message-bubble {
    background: var(--chat-bot-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) var(--border-radius-lg) 0.375rem;
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow-medium);
    padding: 0.875rem 1.125rem;
}

/* User message bubble */
.user-message .message-bubble {
    background: var(--chat-user-bg);
    color: var(--chat-user-text);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0.375rem var(--border-radius-lg);
    padding: 0.875rem 1.125rem;
    box-shadow: var(--shadow-medium);
}

/* ===== Message Content ===== */
.message-content {
    flex: 1;
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 0.9375rem;
    line-height: 1.65;
}

.message-content p {
    margin-bottom: 0.5rem;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* Links in messages */
.message-content a {
    color: var(--accent-light);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color var(--transition-fast);
}

.message-content a:hover {
    color: var(--accent-color);
}

.user-message .message-content a {
    color: rgba(255, 255, 255, 0.9);
}

/* Code in messages */
.message-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    font-family: 'Consolas', 'Monaco', monospace;
}

.dark-mode .message-content code {
    background: rgba(255, 255, 255, 0.1);
}

/* ===== Message Meta (timestamp + copy) ===== */
.message-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.375rem;
    justify-content: flex-end;
}

.message-timestamp {
    font-size: 0.7rem;
    color: var(--secondary-text);
    opacity: 0.6;
    font-variant-numeric: tabular-nums;
}

.user-message .message-timestamp {
    color: rgba(255, 255, 255, 0.55);
}

/* ===== Copy Button ===== */
.copy-button {
    background: transparent;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    opacity: 0;
    transition: all var(--transition-fast);
    border-radius: 0.375rem;
    color: var(--secondary-text);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-bubble:hover .copy-button {
    opacity: 0.5;
}

.copy-button:hover {
    opacity: 1 !important;
    background: rgba(0, 0, 0, 0.05);
}

.dark-mode .copy-button:hover {
    background: rgba(255, 255, 255, 0.08);
}

.user-message .copy-button {
    color: rgba(255, 255, 255, 0.7);
}

.user-message .copy-button:hover {
    background: rgba(255, 255, 255, 0.15);
}

.copy-button svg {
    width: 0.9rem;
    height: 0.9rem;
    stroke: currentColor;
    fill: none;
    transition: transform var(--transition-fast);
}

.copy-button.copied {
    opacity: 1 !important;
    color: #22c55e;
}

.copy-button.copied svg {
    transform: scale(1.1);
}

/* Copy tooltip */
.copy-button::after {
    content: 'Copy';
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    background: var(--secondary-bg);
    color: var(--primary-text);
    padding: 0.2rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.65rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-family: var(--font-body);
    font-weight: 500;
}

.copy-button:hover::after {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

.copy-button.copied::after {
    content: 'Copied!';
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* Touch devices: always show copy button */
@media (hover: none) {
    .copy-button {
        opacity: 0.4;
    }
}

/* ===== Input Form - Floating Glass Bar ===== */
#prompt-form {
    position: fixed;
    bottom: calc(var(--footer-height) + 5.5rem);
    left: 50%;
    transform: translateX(-50%);
    padding: 0 1.5rem;
    max-width: var(--max-width);
    width: 100%;
    transition: bottom var(--transition-normal);
}

.input-container {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 0.375rem;
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--glass-shadow);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    transition: all var(--transition-normal);
    padding: 0.25rem;
}

.input-container:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-glow), var(--glass-shadow);
}

.input-container.invalid {
    border-color: var(--error-color);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

#prompt-input {
    flex-grow: 1;
    background: transparent;
    border: none;
    padding: 0.75rem 1rem;
    color: var(--primary-text);
    font-size: 0.9375rem;
    font-family: var(--font-body);
    resize: none;
    max-height: 200px;
    outline: none;
    line-height: 1.5;
    transition: color var(--transition-normal);
}

#prompt-input::placeholder {
    color: var(--secondary-text);
    opacity: 0.7;
}

/* Send button - circular */
button[type="submit"] {
    background-color: var(--accent-color);
    color: white;
    border: none;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

button[type="submit"]:hover {
    background-color: var(--accent-light);
    transform: scale(1.08);
    box-shadow: 0 2px 12px var(--accent-glow);
}

button[type="submit"]:active {
    transform: scale(0.95);
}

button[type="submit"]:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

button[type="submit"] svg {
    width: 18px;
    height: 18px;
}

/* Error Message */
.error-message {
    color: var(--error-color);
    font-size: 0.8rem;
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius-sm);
    background-color: rgba(239, 68, 68, 0.08);
    opacity: 0;
    height: 0;
    overflow: hidden;
    transition: all var(--transition-normal);
    font-family: var(--font-body);
}

#prompt-form.error .error-message {
    opacity: 1;
    height: auto;
    margin-bottom: 0.5rem;
}

/* ===== Links Container - Glass Pills ===== */
.links-container {
    position: fixed;
    bottom: var(--footer-height);
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--max-width);
    padding: 0.625rem 1.5rem;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.link-button {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.9rem;
    border-radius: 2rem;
    background: var(--glass-bg);
    color: var(--primary-text);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font-body);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all var(--transition-fast);
}

.link-button:hover {
    background: rgba(27, 75, 143, 0.12);
    border-color: rgba(27, 75, 143, 0.3);
    color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.dark-mode .link-button:hover {
    background: rgba(37, 99, 176, 0.2);
    color: var(--primary-text);
}

/* ===== Footer - Glass ===== */
footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-height);
    padding: 0.75rem 1rem;
    text-align: center;
    border-top: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: all var(--transition-normal);
}

.disclaimer {
    font-size: 0.7rem;
    color: var(--secondary-text);
    line-height: 1.4;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem;
    opacity: 0.75;
}

/* ===== Animations ===== */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.typing-dots {
    display: flex;
    gap: 5px;
    padding: 0.75rem 1rem;
    background: var(--chat-bot-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md) var(--border-radius-md) var(--border-radius-md) 0.375rem;
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
}

.typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--accent-color);
    opacity: 0.4;
    animation: typingPulse 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
    0%, 80%, 100% {
        transform: scale(1);
        opacity: 0.4;
    }
    40% {
        transform: scale(1.25);
        opacity: 1;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.22);
}

.dark-mode ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
}

.dark-mode ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* ===== Responsive Design ===== */
@media (max-width: 1024px) {
    :root {
        --max-width: 92%;
    }
}

@media (max-width: 768px) {
    :root {
        --footer-height: 5rem;
    }

    header {
        padding: 0 1rem;
    }

    header h1 {
        font-size: 1rem;
    }

    .header-logo img {
        height: calc(var(--header-height) - 1.5rem);
    }

    main {
        padding: 0.75rem;
    }

    .message-bubble {
        max-width: 85%;
    }

    .message-avatar {
        width: 1.875rem;
        height: 1.875rem;
    }

    #prompt-form {
        padding: 0 1rem;
        bottom: calc(var(--footer-height) + 5rem);
    }

    .links-container {
        padding: 0.5rem 1rem;
        gap: 0.375rem;
    }

    .link-button {
        padding: 0.375rem 0.7rem;
        font-size: 0.75rem;
    }

    .disclaimer {
        font-size: 0.65rem;
    }

    /* Icon-only toggle on tablet */
    #toggle-dark-mode span {
        display: none;
    }

    #toggle-dark-mode {
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    :root {
        --footer-height: 5.5rem;
    }

    header {
        padding: 0 0.75rem;
    }

    header h1 {
        font-size: 0.9rem;
    }

    .header-logo img {
        height: calc(var(--header-height) - 2rem);
    }

    main {
        padding: 0.5rem;
    }

    .message-bubble {
        max-width: 90%;
    }

    .message-avatar {
        width: 1.625rem;
        height: 1.625rem;
        font-size: 0.55rem;
    }

    .message-content {
        font-size: 0.875rem;
    }

    #prompt-form {
        padding: 0 0.75rem;
        bottom: calc(var(--footer-height) + 6.5rem);
    }

    button[type="submit"] {
        width: 2.25rem;
        height: 2.25rem;
    }

    .links-container {
        padding: 0.375rem 0.75rem;
    }

    .link-button {
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }

    .disclaimer {
        font-size: 0.6rem;
        padding: 0 0.5rem;
    }
}

/* ===== Loading History Indicator ===== */
.loading-history {
    text-align: center;
    padding: 0.75rem;
    color: var(--secondary-text);
    font-size: 0.8rem;
    opacity: 0.7;
}

/* ===== Status Messages ===== */
.status-message {
    position: fixed;
    bottom: calc(var(--footer-height) + 1rem);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    font-size: 0.8rem;
    color: var(--primary-text);
    z-index: 999;
    box-shadow: var(--shadow-medium);
}
