/* CSS Variables for Theming */
:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --bg-hover: #2d2d2d;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #6b6b6b;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --border: #2d2d2d;
    --message-user: #6366f1;
    --message-ai: #252525;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* iOS Safe Areas */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #e8e8e8;
    --bg-hover: #e0e0e0;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border: #e0e0e0;
    --message-ai: #f0f0f0;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.15);
}

/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: var(--transition);
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* Sidebar Styles */
.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    padding-top: var(--safe-area-top);
    padding-left: var(--safe-area-left);
}

.sidebar.hidden {
    margin-left: -280px;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px var(--accent-glow);
    overflow: hidden;
}

.logo-icon svg {
    width: 22px;
    height: 22px;
    color: white;
}

.logo-icon .lirv-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Lirv profile image - used across the app */
.lirv-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.new-chat-btn {
    margin: 16px;
    padding: 14px 20px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: var(--transition);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px var(--accent-glow);
}

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

.chat-history {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}

.chat-history h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item {
    padding: 12px 14px;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.history-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.user-profile:hover {
    background: var(--bg-hover);
}

.avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: white;
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 16px 24px;
    padding-top: calc(16px + var(--safe-area-top));
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 10;
    min-height: 56px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.menu-toggle:hover {
    background: var(--bg-hover);
}

.menu-toggle svg {
    width: 24px;
    height: 24px;
}

.chat-header h1 {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 10px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

/* Welcome Screen */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    animation: fadeIn 0.5s ease;
}

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

.welcome-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    box-shadow: 0 8px 30px var(--accent-glow);
    animation: pulse 3s infinite;
    overflow: hidden;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.welcome-icon svg {
    width: 40px;
    height: 40px;
    color: white;
}

.welcome-icon .lirv-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
}

.welcome-screen h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-screen p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 40px;
}

.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    max-width: 600px;
    width: 100%;
}

.suggestion-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.suggestion-card:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
    transform: translateY(-4px);
    box-shadow: var(--shadow);
}

.card-icon {
    font-size: 1.5rem;
    margin-bottom: 12px;
}

.suggestion-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

/* Messages */
.messages {
    display: none;
    flex-direction: column;
    gap: 24px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

.messages.active {
    display: flex;
}

.message {
    display: flex;
    gap: 16px;
    animation: slideIn 0.3s ease;
}

/* Compact messages (continuation of a message group) */
.message.compact {
    margin-top: -8px;
    animation: none;
}

.message.compact .message-avatar-spacer {
    width: 36px;
    flex-shrink: 0;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
}

.message.ai .message-avatar {
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    overflow: hidden;
}

.message.ai .message-avatar svg {
    width: 18px;
    height: 18px;
    color: white;
}

.message.ai .message-avatar .lirv-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.message-author {
    font-weight: 600;
    font-size: 0.9rem;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.message-text {
    background: var(--message-ai);
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    line-height: 1.7;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.message.user .message-text {
    background: var(--message-user);
    color: white;
}

.message-text p {
    margin-bottom: 12px;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.85em;
}

.message.user .message-text code {
    background: rgba(255, 255, 255, 0.2);
}

.message-text pre {
    background: var(--bg-primary);
    padding: 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 12px 0;
}

.message-text pre code {
    background: none;
    padding: 0;
}

/* Typing Indicator - styled as a message */
.typing-indicator {
    display: none;
    gap: 16px;
    animation: slideIn 0.3s ease;
}

.typing-indicator.active {
    display: flex;
}

.typing-indicator .message-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.typing-indicator .message-avatar svg {
    width: 18px;
    height: 18px;
    color: white;
}

.typing-indicator .message-avatar .lirv-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.typing-indicator .message-content {
    flex: 1;
    min-width: 0;
}

.typing-dots {
    display: inline-flex;
    gap: 6px;
    padding: 16px 20px;
    background: var(--message-ai);
    border-radius: var(--radius-lg);
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.input-area {
    padding: 20px 24px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: var(--transition);
}

.input-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-container textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    padding: 8px 4px;
    resize: none;
    max-height: 150px;
}

.input-container textarea::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.send-btn svg {
    width: 20px;
    height: 20px;
    color: white;
}

.input-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 12px;
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Tablet Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: 260px;
    }

    .sidebar.hidden {
        margin-left: -260px;
    }

    .messages {
        max-width: 100%;
    }

    .input-container {
        max-width: 100%;
    }

    .suggestion-cards {
        max-width: 100%;
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 100;
        box-shadow: var(--shadow-lg);
        width: 280px;
    }

    .sidebar.hidden {
        margin-left: -280px;
    }

    .menu-toggle {
        display: block;
    }

    .suggestion-cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .suggestion-card {
        padding: 16px;
    }

    .card-icon {
        font-size: 1.25rem;
        margin-bottom: 8px;
    }

    .welcome-screen h2 {
        font-size: 1.5rem;
    }

    .welcome-screen p {
        font-size: 0.95rem;
        margin-bottom: 28px;
        padding: 0 10px;
    }

    .welcome-icon {
        width: 64px;
        height: 64px;
        margin-bottom: 20px;
    }

    .welcome-icon svg {
        width: 32px;
        height: 32px;
    }

    .chat-container {
        padding: 16px;
    }

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

    .input-container {
        padding: 6px 10px;
    }

    .input-container textarea {
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 6px 4px;
    }

    .send-btn {
        width: 40px;
        height: 40px;
    }

    .message {
        gap: 12px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
    }

    .message.compact .message-avatar-spacer {
        width: 32px;
    }

    .message-text {
        padding: 12px 16px;
        font-size: 0.9rem;
    }

    .message-header {
        margin-bottom: 6px;
    }

    .message-author {
        font-size: 0.85rem;
    }

    .chat-header {
        padding: 12px 16px;
        padding-top: calc(12px + var(--safe-area-top));
        min-height: calc(48px + var(--safe-area-top));
    }

    .chat-header h1 {
        font-size: 1rem;
    }

    .input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + var(--safe-area-bottom));
    }

    .header-actions {
        gap: 4px;
    }

    .icon-btn {
        padding: 8px;
    }

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

    .typing-indicator .message-avatar {
        width: 32px;
        height: 32px;
    }

    .typing-dots {
        padding: 12px 16px;
    }

    .input-hint {
        font-size: 0.7rem;
        margin-top: 8px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .sidebar {
        width: 100%;
    }

    .sidebar.hidden {
        margin-left: -100%;
    }

    .welcome-screen {
        padding: 20px 16px;
    }

    .welcome-screen h2 {
        font-size: 1.35rem;
    }

    .welcome-screen p {
        font-size: 0.85rem;
        line-height: 1.5;
    }

    .suggestion-card p {
        font-size: 0.85rem;
    }

    .chat-container {
        padding: 12px;
    }

    .message {
        gap: 10px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
    }

    .message.compact .message-avatar-spacer {
        width: 28px;
    }

    .message-text {
        padding: 10px 14px;
        border-radius: var(--radius-md);
    }

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

    .input-container {
        border-radius: var(--radius-md);
    }

    .send-btn {
        width: 36px;
        height: 36px;
        border-radius: var(--radius-sm);
    }

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

    .new-chat-btn {
        padding: 12px 16px;
        font-size: 0.9rem;
    }

    .logo-text {
        font-size: 1.1rem;
    }

    .logo-icon {
        width: 36px;
        height: 36px;
    }
}

/* Landscape mobile - adjust for keyboard */
@media (max-height: 500px) and (orientation: landscape) {
    .welcome-screen {
        padding: 16px;
        justify-content: flex-start;
    }

    .welcome-icon {
        width: 48px;
        height: 48px;
        margin-bottom: 12px;
    }

    .welcome-screen h2 {
        font-size: 1.2rem;
        margin-bottom: 8px;
    }

    .welcome-screen p {
        font-size: 0.8rem;
        margin-bottom: 16px;
    }

    .suggestion-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .suggestion-card {
        padding: 10px 14px;
    }

    .card-icon {
        font-size: 1rem;
        margin-bottom: 4px;
    }

    .suggestion-card p {
        font-size: 0.8rem;
    }

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

    .new-chat-btn {
        margin: 10px 12px;
        padding: 10px 14px;
    }

    .chat-history {
        padding: 10px 12px;
    }
}

/* Touch-friendly adjustments */
@media (hover: none) and (pointer: coarse) {
    .history-item {
        padding: 14px 14px;
    }

    .suggestion-card:hover {
        transform: none;
    }

    .new-chat-btn:hover {
        transform: none;
    }

    .send-btn:hover {
        transform: none;
    }

    .icon-btn:hover {
        background: transparent;
    }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
}
