/* Modern Frameless Chat Interface - Grok-inspired */

/* CSS Variables for theming */
:root {
    --bg-primary: #FFFFFF;
    --bg-bubble: #F0F0F0;
    --text-primary: #1A1A1A;
    --text-secondary: #6B7280;
    --text-placeholder: #9CA3AF;
    --button-bg: #1A1A1A;
    --button-text: #FFFFFF;
    --font-size-base: 16px;
}

[data-theme="dark"] {
    --bg-primary: #0F0F0F;
    --bg-bubble: #2A2A2A;
    --text-primary: #E5E5E5;
    --text-secondary: #9CA3AF;
    --text-placeholder: #6B7280;
    --button-bg: #FFFFFF;
    --button-text: #0F0F0F;
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    font-size: var(--font-size-base);
    line-height: 1.5;
}

body.font-small { --font-size-base: 14px; }
body.font-large { --font-size-base: 18px; }

/* Main container - FRAMELESS */
.chat-container {
    min-height: 100vh;
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-primary);
    overflow: visible;  /* Ensure no scrollbar on container */
    /* NO border, NO shadow */
}

/* Header - MINIMAL */
.chat-header {
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* NO border-bottom, NO background difference */
}

.chat-header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Header buttons container - hidden in new design */
.header-buttons {
    display: none;
}

/* Chat area - page scrolls, not container */
#chat {
    flex: 1;
    padding: 20px;
    padding-bottom: 100vh;  /* Full viewport height so any message can scroll to top */
    overflow: visible;  /* NO container scrolling - page scrolls instead */
}

/* Message containers */
.message-container {
    margin-bottom: 20px;
    display: flex;
    scroll-margin-top: 70px;  /* Account for header when scrollIntoView is used */
}

.message-container.user {
    justify-content: flex-end;
}

.message-container.assistant {
    justify-content: flex-start;
}

/* Message labels - hidden in new design */
.message-label {
    display: none;
}

/* User messages - gray bubble */
.message,
.user-message {
    background-color: var(--bg-bubble);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 20px 20px 4px 20px;
    max-width: 75%;
    text-align: left;
    line-height: 1.5;
    white-space: pre-wrap;
    box-shadow: none;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Assistant messages - NO bubble, just text */
.assistant-message {
    color: var(--text-primary);
    max-width: 90%;
    line-height: 1.6;
    padding: 4px 0;
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
}

/* Input area - FIXED at bottom of screen */
.input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 800px;
    margin: 0 auto;
    padding: 16px 20px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background-color: var(--bg-primary);
    z-index: 100;
}

.message-input-container {
    flex: 1;
    position: relative;
}

#message {
    width: 100%;
    background-color: var(--bg-bubble);
    border: none;
    border-radius: 24px;
    color: var(--text-primary);
    padding: 14px 90px 14px 18px;
    font-size: var(--font-size-base);
    font-family: inherit;
    resize: none;
    min-height: 48px;
    max-height: 200px;
    line-height: 1.4;
}

#message::placeholder {
    color: var(--text-placeholder);
}

#message:focus {
    outline: none;
}

#message:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Send button - positioned inside input on right */
.send-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background-color: var(--button-bg);
    color: var(--button-text);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    z-index: 2;
}

.send-btn:hover {
    opacity: 0.85;
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

/* Loading indicator */
.loading-indicator {
    color: var(--text-secondary);
    font-style: italic;
    padding: 8px 0;
}

.loading-indicator::after {
    content: "...";
    animation: loading 1.5s infinite;
    margin-left: 2px;
}

@keyframes loading {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* Settings dropdown - fixed in top-right corner */
.settings-container {
    position: fixed;
    top: 16px;
    right: 20px;
    z-index: 100;
}

.settings-btn {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    height: auto;
    min-width: auto;
}

.settings-btn:hover {
    background-color: var(--bg-bubble);
    opacity: 1;
}

.settings-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 12px 16px;
    min-width: 180px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 100;
}

.settings-dropdown.open {
    display: block;
}

.settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    color: var(--text-primary);
    font-size: 14px;
}

.settings-item:not(:last-child) {
    border-bottom: 1px solid var(--bg-bubble);
}

.theme-toggle-btn {
    background: var(--bg-bubble);
    border: none;
    border-radius: 20px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 16px;
    width: auto;
    height: auto;
    min-width: auto;
}

.theme-toggle-btn:hover {
    opacity: 0.8;
}

.font-size-btns {
    display: flex;
    gap: 4px;
}

.font-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border: none;
    background: var(--bg-bubble);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.font-btn:hover {
    opacity: 0.8;
}

.font-btn.active {
    background: var(--button-bg);
    color: var(--button-text);
}

/* Completion message */
.completion-container {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px 20px;
    height: 100%;
}

.completion-container h2 {
    color: var(--text-primary);
    margin-bottom: 16px;
}

.completion-container p {
    color: var(--text-secondary);
    max-width: 400px;
    line-height: 1.6;
}

.check-icon {
    font-size: 48px;
    color: #22C55E;
    margin-bottom: 16px;
}

/* Record exists message */
.record-exists-container {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px 20px;
    height: 100vh;
    background-color: var(--bg-primary);
}

.record-exists-container h2 {
    color: var(--text-primary);
    margin-bottom: 16px;
}

.record-exists-container p {
    color: var(--text-secondary);
    max-width: 400px;
    line-height: 1.6;
}

.info-icon {
    font-size: 48px;
    color: #F59E0B;
    margin-bottom: 16px;
}

/* Debug window - hidden by default */
.debug-window {
    display: none;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .chat-container {
        max-width: 100%;
    }

    .chat-header {
        padding: 12px 16px;
    }

    #chat {
        padding: 16px;
        padding-bottom: 100vh;  /* Preserve for scroll behavior */
    }

    .input-area {
        padding: 12px 16px;
    }

    .user-message,
    .message {
        max-width: 85%;
    }
}

/* iOS safe area support */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .input-area {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}
