/* ===== Home cards layout fixes: prevent clipping, center, responsive ===== */
.main-content .welcome-section {
    max-width: 64rem;
    margin: 0 auto;
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: clamp(3rem, 12vw, 4.75rem);
    overflow: visible;
}

.main-content .template-cards {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: stretch;
    gap: 1rem;
}

.main-content .template-card {
    flex: 1 1 0;
    min-width: 260px;
    max-width: 360px;
}

/* Tablet and small laptop: allow wrapping and graceful shrink */
@media (max-width: 64em) { /* ≤1024px */
    .main-content .template-cards { flex-wrap: wrap; }
    .main-content .template-card { flex: 1 1 260px; }
}

/* Phone sizes: stack; hide on very narrow screens to keep layout clean */
@media (max-width: 40em) { /* ≤640px */
    .main-content .template-card { min-width: 220px; max-width: 1fr; }
    .main-content .welcome-section { padding-top: 4.75rem; }
}

@media (max-width: 22.5em) { /* ≤360px */
    .main-content .template-cards { display: none; }
}
/* Voice recording states for mic button */
.input-btn.recording {
    color: var(--accent-green);
    animation: micPulse 2s ease-in-out infinite;
}

@keyframes micPulse {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    50% {
        opacity: 0.8;
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }
}
/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Text Selection */
::selection {
    background-color: rgba(16, 185, 129, 0.2);
    color: var(--text-primary);
}

::-moz-selection {
    background-color: rgba(16, 185, 129, 0.2);
    color: var(--text-primary);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-green);
}

/* Links */
a {
    color: var(--accent-green);
    text-decoration: none;
    transition: all 0.2s ease;
}

a:hover {
    text-decoration: underline;
}

/* Focus Indicators */
button:focus-visible, 
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent-green);
    outline-offset: 2px;
}

button:focus-visible.primary,
.new-chat-button:focus-visible,
.upgrade-btn:focus-visible {
    outline-color: var(--accent-green);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: var(--font-primary);
    background: #0F0F0F;
    color: #FFFFFF;
    height: 100vh;
    overflow: auto;
    font-weight: 400;
}

.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 4000;
    pointer-events: none;
}

.toast {
    background: rgba(26, 26, 26, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #f7fafc;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
    transform: translateY(-10px);
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: auto;
    max-width: 20rem;
}

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

.toast-success {
    border-color: rgba(21, 204, 150, 0.4);
    color: #d1fae5;
}

.toast-error {
    border-color: rgba(239, 68, 68, 0.5);
    color: #fee2e2;
}

.toast-info {
    border-color: rgba(96, 165, 250, 0.4);
    color: #dbeafe;
}

/* CSS Variables for Consistent Responsive Design */
:root {
    --sidebar-width-mobile: 85vw;
    --sidebar-width-tablet: 15rem;
    --sidebar-width-desktop: 16.25rem;
    --header-height: 3.5rem;
    --touch-target: 2.75rem; /* 44px minimum per Apple HIG */
    --touch-target-large: 3rem; /* 48px for larger devices */
    --touch-target-small: 2.5rem; /* 40px for compact devices */
    --border-radius: 0.5rem;
    --card-gap: 1rem;
    
    /* Safe Area Insets for iPhone with notch/Dynamic Island */
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-right: env(safe-area-inset-right);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
    --safe-area-inset-left: env(safe-area-inset-left);
    
    /* Color Palette */
    --bg-primary: #0F0F0F;
    --bg-secondary: #1A1A1A;
    --bg-surface: #1E1E1E;
    --bg-input: #212121;
    --border-subtle: #2A2A2A;
    --border-default: #333333;
    --text-primary: #FFFFFF;
    --text-secondary: #A1A1A1;
    --text-muted: #777777;
    --accent-green: #10B981;
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    --font-heading: 'DM Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

h1,
h2,
h3,
h4,
h5,
h6,
.section-title,
.welcome-title,
.template-card .card-title,
.legal-title,
.legal-container h2,
.chat-header .upgrade-btn,
.auth-btn,
.new-chat-button,
.trial-btn,
.plan-name,
.plan-price,
.pricing-title,
.model-selector-btn,
.account-menu-item,
.account-trigger .label,
.chat-list .chat-title,
button,
input[type="button"],
input[type="submit"] {
    font-family: var(--font-heading);
}

/* ===========================================
   LAYOUT CONTAINER
   =========================================== */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
    background: var(--bg-primary);
    position: relative;
}

/* Ensure proper scrolling on mobile */
@media (max-width: 768px) {
    .app-container {
        height: 100vh;
        overflow: hidden;
        position: relative;
    }
    
    body {
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
}

/* ===========================================
   SIDEBAR - MOBILE FIRST RESPONSIVE
   =========================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: var(--sidebar-width-mobile);
    max-width: 20rem;
    height: 100vh;
    background: var(--bg-secondary);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: left 0.3s ease;
    overflow-y: auto;
    
    /* Safe area support for devices with notch */
    padding-top: var(--safe-area-inset-top);
    padding-left: var(--safe-area-inset-left);
}

.sidebar.open {
    left: 0;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.sidebar-header {
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-subtle);
}

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

.amz-logo {
    height: clamp(1rem, 2vw, 1.75rem);
    width: auto;
    filter: brightness(1.2);
    transition: all 0.2s ease;
}

.amz-logo:hover {
    filter: brightness(1.4);
    transform: scale(1.05);
}

.sidebar-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 0.875rem;
    cursor: pointer;
    padding: 0.375rem;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.search-container {
    padding: 1rem 1.25rem;
}

.search-box {
    position: relative;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--border-radius);
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    transition: all 0.2s ease;
}

.search-box:focus-within {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.search-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: #FFFFFF;
    font-size: 0.875rem;
}

.search-input {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: var(--font-primary);
    font-weight: 400;
    width: 100%;
    outline: none;
}

.search-input::placeholder {
    color: #666666;
}

.chats-section {
    padding: 0 1.25rem;
    margin-bottom: 1.5rem;
    flex: 1;
    overflow-y: auto;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0;
}

/* Inline New Chat (+) button next to ALL CHATS - mobile-first */
.new-chat-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: none;
    background: transparent;
    color: #999999;
    cursor: pointer;
    border-radius: 0.375rem;
    transition: color 0.2s ease, background 0.2s ease;
}
.new-chat-inline i { font-size: 1.25rem; }
.new-chat-inline:hover { color: #15CC96; background: rgba(21, 204, 150, 0.08); }
.new-chat-inline:focus { outline: 2px solid #15CC96; outline-offset: 2px; }

/* Visibility rules */
/* Mobile (<768px): show inline +, hide bottom button */
.new-chat-inline { display: inline-flex; }
.new-chat-btn { display: none; }

/* Desktop (>=768px): hide inline +, show bottom button */
@media (min-width: 768px) {
    .new-chat-inline { display: none; }
    .new-chat-btn { display: block; }
}

.section-title {
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-primary);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03125em;
}

.section-actions {
    display: flex;
    gap: 0.5rem;
    color: #9ca3af;
    font-size: 0.75rem;
}

.section-actions i {
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.1875rem;
    transition: all 0.2s ease;
}

.section-actions i:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 0.75rem;
    border-radius: var(--border-radius);
    margin-bottom: 0.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: var(--touch-target);
    position: relative;
    overflow: hidden;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-item.active {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid var(--border-default);
}

.chat-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.chat-icon {
    color: #9ca3af;
    font-size: 1rem;
    flex-shrink: 0;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-title {
    font-size: 0.875rem;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-weight: 500;
    margin-bottom: 0.125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-preview {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: var(--font-primary);
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-menu {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    min-width: 1.5rem;
    min-height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-item:hover .chat-menu {
    opacity: 1;
}

.chat-menu:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

/* Navigation Section */
.nav-section {
    padding: 0 1.25rem;
    margin-bottom: 1.5rem;
}

.nav-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--border-radius);
    color: #9ca3af;
    text-decoration: none;
    transition: all 0.2s ease;
    min-height: var(--touch-target);
    position: relative;
    overflow: hidden;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    transform: translateX(4px);
}

.nav-item.active {
    background: linear-gradient(180deg, rgba(21,204,150,0.18), rgba(21,204,150,0.10));
    border: 1px solid rgba(21,204,150,0.35);
    color: #15CC96;
    box-shadow: 0 4px 12px rgba(21,204,150,0.12);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, #19d1a0, #10b981);
    box-shadow: 0 0 10px rgba(21,204,150,0.55);
}

.nav-item i {
    font-size: 1rem;
    flex-shrink: 0;
    width: 1.25rem;
    text-align: center;
}

.nav-item span {
    font-size: 0.875rem;
    font-weight: 500;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Empty state for chat list */
.chat-list:empty::before {
    content: "No chats yet. Click + to start a new conversation.";
    display: block;
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
    padding: 2rem 1rem;
    font-style: italic;
}

.chat-list:empty::after {
    content: "💬";
    display: block;
    text-align: center;
    font-size: 2rem;
    margin-top: 0.5rem;
    opacity: 0.5;
}

.new-chat-btn {
    margin-top: auto;
    padding: 1rem;
    margin-bottom: 0;
    /* Ensure button is always visible above Safari's bottom bar with fallback */
    padding-bottom: max(calc(1rem + var(--safe-area-inset-bottom)), 2rem);
}

.new-chat-button {
    width: 100%;
    background: var(--accent-green);
    border: none;
    color: #000000;
    padding: 0.625rem 0.875rem;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    font-family: var(--font-primary);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    min-height: var(--touch-target);
}

.new-chat-button:hover {
    background: #00e68a;
    transform: translateY(-1px);
}

.new-chat-button:active {
    transform: scale(0.98);
}

/* Mobile account link - visible only on mobile, positioned at bottom of chat history */
.mobile-account-link {
    display: none; /* Hidden by default (desktop) */
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 0.5rem;
}

.mobile-account-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.875rem;
    font-family: var(--font-primary);
    font-weight: 500;
    transition: all 0.2s ease;
    min-height: var(--touch-target);
}

.mobile-account-btn i {
    color: var(--text-secondary);
    width: 1.25rem;
    text-align: center;
}

.mobile-account-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

.mobile-account-btn:active {
    transform: scale(0.98);
}

/* Show mobile account link only on mobile */
@media (max-width: 767px) {
    .mobile-account-link {
        display: block;
    }
}

/* ===========================================
   MAIN CONTENT AREA
   =========================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
    overflow: hidden;
    width: 100%;
    position: relative;
}

.chat-header {
    padding: 1rem;
    background: var(--bg-secondary);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 1rem;
    height: calc(var(--header-height) + var(--safe-area-inset-top));
    flex-shrink: 0;
    position: relative;
    z-index: 1001;
    
    /* Safe area support for devices with notch/Dynamic Island */
    padding-top: calc(1rem + var(--safe-area-inset-top));
    padding-right: calc(1rem + var(--safe-area-inset-right));
    padding-left: calc(1rem + var(--safe-area-inset-left));
}

/* Hamburger Menu */
.hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-target);
    height: var(--touch-target);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: all 0.3s ease;
}

.hamburger-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.hamburger-icon {
    font-size: 1.25rem;
    color: #ffffff;
    transition: all 0.3s ease;
    display: block;
}

.hamburger-btn.active .hamburger-icon {
    transform: rotate(90deg);
    color: var(--accent-green);
}

.back-btn {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.chat-title-header {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
}


.chat-name {
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-primary);
    color: var(--text-primary);
}

.chat-model {
    background: var(--accent-green);
    color: #000000;
    padding: 0.25rem 0.5rem;
    border-radius: 0.75rem;
    font-size: 0.625rem;
    font-family: var(--font-primary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03125em;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.header-btn {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

/* Header auth (right corner) - Display and margin controlled by JavaScript */
.header-auth {
    gap: 0.5rem;
    /* margin-left and display are set by JavaScript based on auth state */
}
.auth-btn {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: #ffffff;
    padding: 0.5rem 0.875rem;
    border-radius: 0.5rem;
    font-weight: 600;
    transition: all 0.2s ease;
    text-decoration: none;
}
.auth-btn.ghost { background: transparent; border-color: rgba(255,255,255,0.18); color: #cbd5e1; }
.auth-btn.primary { background: linear-gradient(135deg, #15CC96, #12B887); border: none; }
.auth-btn:hover { filter: brightness(1.05); }

/* Account dropdown trigger */
.account-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.account-trigger .avatar {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 999px;
    background: rgba(255,255,255,0.2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.account-trigger .avatar-img {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 999px;
    object-fit: cover;
    flex-shrink: 0;
    background: rgba(255,255,255,0.1);
}

/* Account dropdown menu */
.account-menu {
    position: absolute;
    right: 1rem;
    top: calc(var(--header-height) + 0.5rem);
    width: 16rem;
    background: rgba(26,26,26,0.95);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 0.75rem;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 0.5rem;
    display: none;
    z-index: 2000;
}
.account-menu.open { display: block; }
.account-menu-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    color: #e5e7eb;
    text-decoration: none;
    background: transparent;
    border: none;
    cursor: pointer;
}
.account-menu-item i { color: #9ca3af; width: 1rem; text-align: center; }
.account-menu-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.account-menu-item.danger { color: #ef4444; }
.account-menu-item.danger i { color: #ef4444; }

/* Mobile positioning for dropdown */
@media (max-width: 767px) {
    .account-menu { right: 0.5rem; top: calc(var(--header-height) + 0.25rem); width: 90vw; max-width: 20rem; }
}

/* Upgrade button */
.upgrade-btn {
    background: var(--accent-green);
    border: none;
    color: #000000;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-family: var(--font-primary);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.upgrade-btn:hover {
    background: #0FD3A0;
    transform: translateY(-1px);
}

/* Quota Indicator & Plan Badge */
#quotaIndicator {
    font-size: 0.8125rem;
    color: #FFFFFF;
    font-weight: 500;
}

/* Pricing overlay + modal (glassmorphism) */
.pricing-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1500;
}
.pricing-overlay.active { opacity: 1; visibility: visible; }

.pricing-modal {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.98);
    width: min(95vw, 72rem);
    max-width: 95vw;
    max-height: 90vh;
    background: rgba(26, 26, 26, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border-radius: 1rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 1.25rem;
    opacity: 0;
    visibility: hidden;
    transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s ease;
    z-index: 1600;
    overflow-y: auto;
}
.pricing-modal.active { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }

/* Limit Reached Modal */
.limit-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1500;
}
.limit-overlay.active { opacity: 1; visibility: visible; }

.limit-modal {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.98);
    width: min(95vw, 28rem);
    max-width: 95vw;
    background: rgba(26, 26, 26, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border-radius: 1rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 2rem;
    opacity: 0;
    visibility: hidden;
    transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s ease;
    z-index: 1600;
}
.limit-modal.active { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }

.limit-modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1.5rem;
}

.limit-close-btn {
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    color: #cbd5e1;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.875rem;
}
.limit-close-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.limit-icon {
    width: 4rem;
    height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(239, 68, 68, 0.1);
    border: 2px solid rgba(239, 68, 68, 0.3);
    border-radius: 50%;
    color: #ef4444;
    font-size: 2rem;
}

.limit-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0;
    line-height: 1.2;
}

.limit-message {
    font-size: 1rem;
    color: #cbd5e1;
    margin: 0;
    line-height: 1.5;
}

.limit-actions {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    margin-top: 0.5rem;
}

.limit-btn {
    flex: 1;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-family: var(--font-primary);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}
.limit-btn.primary {
    background: linear-gradient(135deg, #15CC96, #12B887);
    color: #000000;
}
.limit-btn.primary:hover {
    background: linear-gradient(135deg, #0FD3A0, #15CC96);
    transform: translateY(-1px);
}
.limit-btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #cbd5e1;
}
.limit-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

@media (max-width: 767px) {
    .limit-modal {
        width: 95vw;
        padding: 1.5rem;
        border-radius: 1rem 1rem 0 0;
        top: auto;
        bottom: 0;
        transform: translate(-50%, 100%);
    }
    .limit-modal.active {
        transform: translate(-50%, 0);
    }
    .limit-actions {
        flex-direction: column;
    }
    .limit-btn {
        width: 100%;
    }
}

/* Auth full-screen */
.auth-overlay {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(1200px 800px at 50% 20%, rgba(21, 204, 150, 0.08), transparent 60%),
        rgba(15, 15, 15, 0.85);
    backdrop-filter: blur(20px) saturate(120%);
    -webkit-backdrop-filter: blur(20px) saturate(120%);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1700;
}
.auth-overlay.active { opacity: 1; visibility: visible; }

.auth-container {
    width: min(92vw, 34rem);
    margin: 8vh auto;
    background: linear-gradient(180deg, rgba(26,26,26,0.65), rgba(26,26,26,0.55));
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 1rem;
    box-shadow: 0 30px 80px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.06);
    padding: 1rem 1rem 1.25rem;
}
.auth-header { display:flex; align-items:center; justify-content:center; position:relative; margin-bottom: 0.75rem; }
.auth-close { position:absolute; right:0.25rem; top:0.25rem; background: rgba(255,255,255,0.08); border:1px solid rgba(255,255,255,0.18); color:#fff; width:2rem; height:2rem; border-radius:0.5rem; }
.auth-tabs { background: rgba(255,255,255,0.05); border:1px solid rgba(255,255,255,0.12); border-radius: 999px; padding: 0.25rem; display:inline-flex; gap:0.25rem; box-shadow: 0 6px 18px rgba(0,0,0,0.25); }
.auth-tab { background: transparent; color:#cbd5e1; padding: 0.375rem 0.875rem; border-radius:999px; font-weight:700; }
.auth-tab.active { background: linear-gradient(135deg, #15CC96, #12B887); color:#ffffff; box-shadow: 0 8px 20px rgba(21,204,150,0.35); }

.auth-body { padding: 0.5rem; }
.auth-form { display:flex; flex-direction:column; gap:0.5rem; }
.auth-form.hidden { display:none; }
.auth-title { font-size: 1.25rem; font-weight: 800; margin: 0.25rem 0 0.5rem; }
.auth-label { font-size: 0.875rem; color:#9ca3af; }
.auth-input { background: rgba(255,255,255,0.06); border:1px solid rgba(255,255,255,0.14); color:#fff; padding:0.625rem 0.75rem; border-radius:0.5rem; outline:none; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.auth-input:focus { border-color: rgba(21,204,150,0.5); box-shadow: 0 0 0 2px rgba(21,204,150,0.18), 0 8px 24px rgba(0,0,0,0.25); }
.auth-row.between { display:flex; justify-content:flex-end; }
.auth-link { color:#15CC96; text-decoration:none; }
.auth-link:hover { text-decoration:underline; }
.auth-primary { background: linear-gradient(135deg, #15CC96, #12B887); color:#ffffff; border:none; padding:0.75rem 1rem; font-weight:800; border-radius:0.625rem; box-shadow: 0 10px 24px rgba(21,204,150,0.25); }
.auth-primary:hover { filter: brightness(1.05); box-shadow: 0 12px 28px rgba(21,204,150,0.32); }
.auth-primary.loading {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    cursor: not-allowed;
    transform: none !important;
    opacity: 0.8;
}
.auth-primary.loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 8px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.auth-check { display:flex; align-items:center; gap:0.5rem; color:#cbd5e1; font-size:0.875rem; margin-top:0.25rem; }
.auth-switch { text-align:center; color:#9ca3af; margin-top:0.25rem; }
.auth-switch a { color:#15CC96; text-decoration:none; }

/* Loading and typing indicator styles */
.ai-message.loading {
    opacity: 0.8;
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--accent-green);
    animation: typing 1.4s infinite ease-in-out;
}

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

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

.typing-indicator span:nth-child(3) {
    animation-delay: 0s;
}

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

.loading-text {
    color: #9ca3af;
    font-style: italic;
}

/* Improved message display - no individual scrolling */
.message-content {
    word-wrap: break-word;
    line-height: 1.5;
}

.message-text {
    white-space: pre-wrap;
    word-break: break-word;
}

/* Mobile scrolling improvements */
@media (max-width: 768px) {
    .app-container {
        height: 100vh;
        overflow: hidden;
    }
    
    .main-content {
        height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .chat-container {
        min-height: calc(100vh - 200px);
        padding-bottom: 2rem;
    }
    
    .welcome-section {
        min-height: calc(100vh - 200px);
        padding: 2rem 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .template-cards {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        margin-top: 2rem;
    }
    
    .template-card {
        width: 100%;
        margin: 0;
    }
}

/* Markdown styling within messages */
.message-text strong {
    font-weight: 600;
    color: #ffffff;
}

.message-text em {
    font-style: italic;
    color: #d1d5db;
}

.message-text ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message-text li {
    margin: 4px 0;
    list-style-type: disc;
}

/* Usage Progress System */
.usage-progress-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.usage-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.usage-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.usage-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.usage-item-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: capitalize;
}

.usage-item-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: #15CC96;
}

.usage-header {
    margin-bottom: 0.5rem;
}

.usage-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.usage-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.usage-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: #15CC96;
    line-height: 1;
}

.usage-label {
    font-size: 0.75rem;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

.progress-bar-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #15CC96, #12B887);
    border-radius: 4px;
    transition: width 0.3s ease;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.progress-text {
    font-size: 0.875rem;
    color: #9ca3af;
    text-align: center;
    font-weight: 500;
}

/* Usage limit warnings */
.usage-warning {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

.usage-warning .warning-text {
    color: #ef4444;
    font-size: 0.875rem;
    font-weight: 500;
}

.usage-critical {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.5);
}

.usage-critical .warning-text {
    color: #dc2626;
    font-weight: 600;
}

/* Legal pages */ 
.legal-overlay {
    min-height: 100vh;
    background: radial-gradient(1000px 700px at 50% 10%, rgba(21,204,150,0.08), transparent 60%), #0f0f0f;
    padding: 2rem 1rem;
}
.legal-container {
    max-width: 56rem;
    margin: 0 auto;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 1rem;
    padding: 1.5rem;
    color: #e5e7eb;
}
.legal-title { font-size: 1.75rem; font-weight: 800; margin-bottom: 1rem; }
.legal-container h2 { font-size: 1.125rem; margin: 1rem 0 0.5rem; }
.legal-container a { color: #15CC96; text-decoration: none; }
.legal-container a:hover { text-decoration: underline; }

.pricing-header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 1rem;
}
.pricing-title {
    font-size: clamp(1.25rem, 3vw, 1.75rem);
    font-weight: 800;
    letter-spacing: -0.02em;
}
.pricing-close {
    position: absolute;
    right: 0.25rem;
    top: 0.25rem;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
}

.pricing-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

/* Mobile-specific pricing modal improvements */
@media (max-width: 767px) {
    .pricing-modal {
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        max-height: 100vh;
        padding: 0;
        border-radius: 0;
        margin: 0;
        top: 0;
        left: 0;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        position: fixed;
        z-index: 1600;
    }
    
    .pricing-modal.active {
        transform: translateY(0);
    }
    
    .pricing-header {
        padding: 1.5rem 1rem 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        flex-shrink: 0;
        background: rgba(26, 26, 26, 0.98);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        margin-bottom: 0;
        position: relative;
    }
    
    .pricing-cards {
        flex: 1;
        padding: 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    .pricing-title {
        font-size: 1.125rem;
        line-height: 1.3;
        text-align: center;
        flex: 1;
    }
    
    .pricing-close {
        width: 2rem;
        height: 2rem;
        top: 1rem;
        right: 1rem;
        position: absolute;
    }
    
    /* Drag handle for mobile drawer */
    .pricing-modal::before {
        content: '';
        position: absolute;
        top: 0.5rem;
        left: 50%;
        transform: translateX(-50%);
        width: 2.5rem;
        height: 0.25rem;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 0.125rem;
        z-index: 1;
    }
    
    .pricing-cards {
        gap: 1rem;
        grid-template-columns: 1fr;
        display: flex;
        flex-direction: column;
    }
    
    .price-card {
        padding: 1.25rem;
        border-radius: 0.75rem;
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.15);
        position: relative;
        min-height: auto;
    }
    
    .price-card.popular {
        border-color: rgba(21, 204, 150, 0.6);
        background: rgba(21, 204, 150, 0.1);
        box-shadow: 0 8px 32px rgba(21, 204, 150, 0.2);
    }
    
    .price-card-head {
        margin-bottom: 1rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-direction: row;
    }
    
    .plan-name {
        font-size: 1rem;
        font-weight: 700;
        color: #ffffff;
    }
    
    .plan-price {
        font-size: 1.5rem;
        font-weight: 800;
        color: #ffffff;
    }
    
    .plan-price .per {
        font-size: 0.875rem;
        color: #9ca3af;
        font-weight: 500;
    }
    
    .plan-features {
        gap: 0.75rem;
        margin-bottom: 1.5rem;
        list-style: none;
        padding: 0;
    }
    
    .plan-features li {
        font-size: 0.875rem;
        line-height: 1.4;
        color: #e5e7eb;
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }
    
    .plan-features i {
        font-size: 0.875rem;
        flex-shrink: 0;
        color: #15CC96;
    }
    
    .trial-btn {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        min-height: 3rem;
        border-radius: 0.625rem;
        font-weight: 600;
        width: 100%;
    }
    
    .trial-btn.primary {
        background: linear-gradient(135deg, #15CC96, #12B887);
        border: none;
        color: #ffffff;
    }
    
    .popular-badge {
        font-size: 0.75rem;
        padding: 0.25rem 0.75rem;
        top: -0.75rem;
        left: 50%;
        transform: translateX(-50%);
        background: linear-gradient(135deg, #15CC96, #12B887);
        color: #ffffff;
        font-weight: 700;
        border-radius: 999px;
        box-shadow: 0 4px 12px rgba(21, 204, 150, 0.4);
    }
}

/* Extra small mobile devices (iPhone SE, etc.) */
@media (max-width: 375px) {
    .pricing-modal {
        width: 100vw;
        max-width: 100vw;
        padding: 0;
        border-radius: 0;
        margin: 0;
    }
    
    .pricing-header {
        padding: 1rem 0.75rem 0.75rem;
    }
    
    .pricing-title {
        font-size: 1rem;
        line-height: 1.2;
    }
    
    .pricing-close {
        width: 2rem;
        height: 2rem;
        top: 0.75rem;
        right: 0.75rem;
    }
    
    .pricing-cards {
        padding: 0.75rem;
        gap: 0.75rem;
    }
    
    .price-card {
        padding: 1rem;
        border-radius: 0.625rem;
    }
    
    .plan-name {
        font-size: 0.875rem;
    }
    
    .plan-price {
        font-size: 1.25rem;
    }
    
    .plan-features li {
        font-size: 0.8125rem;
        line-height: 1.3;
        gap: 0.5rem;
    }
    
    .plan-features i {
        font-size: 0.75rem;
    }
    
    .trial-btn {
        padding: 0.625rem 0.875rem;
        font-size: 0.8125rem;
        min-height: 2.75rem;
    }
    
    .popular-badge {
        font-size: 0.6875rem;
        padding: 0.1875rem 0.5rem;
    }
}

@media (min-width: 48em) {
    .pricing-cards { grid-template-columns: repeat(3, 1fr); }
}

.price-card {
    background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
    border: 1px solid rgba(255,255,255,0.16);
    border-radius: 0.875rem;
    padding: 1rem;
    position: relative;
}
.price-card.popular {
    border-color: rgba(21, 204, 150, 0.6);
    box-shadow: 0 0 0 1px rgba(21,204,150,0.3), 0 20px 40px rgba(0,0,0,0.4);
}
.popular-badge {
    position: absolute;
    top: -0.75rem;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #15CC96, #12B887);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    box-shadow: 0 6px 20px rgba(21,204,150,0.4);
}
.price-card-head { display:flex; align-items: baseline; justify-content: space-between; margin-bottom: 0.75rem; }
.plan-name { font-weight:700; color:#fff; }
.plan-price { font-weight:800; font-size: 1.25rem; }
.plan-price .per { font-weight:600; color:#9ca3af; font-size: 0.875rem; }

.plan-features { list-style:none; display:flex; flex-direction:column; gap:0.5rem; margin:0; padding:0 0 0.75rem 0; }
.plan-features li { color:#cbd5e1; font-size: 0.9rem; display:flex; gap:0.5rem; align-items:center; font-family: var(--font-primary); }
.plan-features i { color: var(--accent-green); }

.trial-btn {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    padding: 0.625rem 0.875rem;
    border-radius: 0.625rem;
    font-family: var(--font-primary);
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: pointer;
    font-size: 0.875rem;
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 10;
}
.trial-btn:hover { 
    background: var(--bg-surface);
    border-color: var(--accent-green);
    color: var(--text-primary);
    transform: translateY(-1px);
}
.trial-btn:active {
    transform: scale(0.98);
}
.trial-btn.primary { 
    background: var(--accent-green);
    color: #000000;
    border: none; 
}
.trial-btn.primary:hover { 
    background: #00e68a;
    transform: translateY(-1px);
}
.trial-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* ===========================================
   CHAT CONTAINER AND WELCOME SECTION
   =========================================== */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Center content by default (for welcome section) */
    padding: 1rem;
    overflow-y: auto;
    min-height: calc(100vh - var(--header-height) - 140px); /* Fill space between header and input */
    padding-bottom: 140px; /* Space for sticky input container */
    width: 100%;
    max-width: 100%;
}

/* When messages are present, align to top */
.chat-container.has-messages,
.chat-container:has(.user-message),
.chat-container:has(.ai-message) {
    align-items: stretch; /* Stretch messages to full width for consistent alignment */
    justify-content: flex-start;
}

.welcome-section {
    text-align: center;
    width: 100%;
    max-width: min(90vw, 48rem);
    padding: 1rem 0;
    overflow: hidden;
}

.welcome-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    transition: all 0.3s ease;
}

.welcome-icon:hover {
    transform: translateY(-0.125rem);
}

.welcome-logo {
    height: clamp(1.75rem, 5vw, 2.5rem);
    width: auto;
    filter: brightness(1.3);
}

.welcome-title {
    font-size: 1.8rem;
    font-weight: 600;
    font-family: var(--font-primary);
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    letter-spacing: -0.02em;
    line-height: 1.2;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: normal;
    text-wrap: balance;
    hyphens: auto;
}

.welcome-subtitle {
    font-size: 0.95rem;
    font-family: var(--font-primary);
    color: var(--text-secondary);
    line-height: 1.6;
    font-weight: 400;
    margin-bottom: 2rem;
    max-width: 95%;
    margin-left: auto;
    margin-right: auto;
}

/* ===========================================
   TEMPLATE CARDS - RESPONSIVE GRID
   =========================================== */
.template-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--card-gap);
    margin-bottom: 0;
    width: 100%;
}

.template-card {
    background: var(--bg-surface);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: var(--touch-target);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.template-card:hover {
    background: var(--bg-input);
    border-color: var(--accent-green);
    transform: translateY(-0.125rem);
}

.template-card:active {
    transform: scale(0.98);
}

.card-icon {
    width: 2.5rem;
    height: 2.5rem;
    background: rgba(16, 185, 129, 0.1);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    color: var(--accent-green);
    margin: 0 auto 0.75rem;
    flex-shrink: 0;
}

.card-title {
    font-size: clamp(0.875rem, 2.5vw, 1rem);
    font-weight: 600;
    font-family: var(--font-primary);
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.card-description {
    font-size: clamp(0.75rem, 2vw, 0.875rem);
    font-family: var(--font-primary);
    color: var(--text-secondary);
    line-height: 1.4;
    font-weight: 400;
    flex-grow: 1;
}

/* ===========================================
   INPUT AREA - RESPONSIVE
   =========================================== */
.input-container {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    background: rgba(26, 26, 26, 0.9);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 50;
    /* Safe area support for devices with home indicator */
    padding-bottom: calc(1rem + var(--safe-area-inset-bottom));
    padding-right: calc(1rem + var(--safe-area-inset-right));
    padding-left: calc(1rem + var(--safe-area-inset-left));
    /* Input expands upward from fixed bottom position (like ChatGPT) */
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.input-wrapper {
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: 1.5rem;
    padding: 0.75rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
    transition: all 0.2s ease;
    min-height: var(--touch-target);
    position: relative;
    /* Allow input to expand upward from fixed bottom */
    align-items: stretch;
}

.input-wrapper.uploading {
    border-color: rgba(21, 204, 150, 0.6);
    border-style: dashed;
}

.input-wrapper.uploading::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(21, 204, 150, 0.08);
    pointer-events: none;
}

.input-wrapper:focus-within {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.input-wrapper.drag-over {
    border-color: var(--accent-green);
    background: rgba(16, 185, 129, 0.05);
    border-style: dashed;
}

/* File upload button on the left */
.file-upload-btn {
    flex-shrink: 0;
    align-self: center;
    margin-top: 0;
    position: relative;
}

.file-upload-count {
    position: absolute;
    top: -0.25rem;
    right: -0.25rem;
    background: var(--accent-green);
    color: #000000;
    border-radius: 999px;
    padding: 0 0.4rem;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1.4;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    min-height: 1.25rem;
}

/* Row container for buttons, textarea, and actions - appears below image preview */
.input-row {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 0.75rem;
    width: 100%;
    flex-shrink: 0;
}

.input-area-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    align-self: stretch;
}

.input-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
    align-self: center;
}



.chat-input {
    flex: 1 1 auto;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    font-family: var(--font-primary);
    line-height: 24px; /* Fixed line height for consistent row calculation */
    font-weight: 400;
    outline: none;
    min-width: 0;
    resize: none; /* Disable manual resize */
    width: 100%;
    padding: 8px 0; /* Top and bottom padding */
    margin: 0;
    min-height: 24px; /* 1 row */
    max-height: 240px; /* ~10 rows: (24px * 10) - allows 5-10 visible lines before scrolling */
    overflow-y: auto; /* Scrollable after max height */
    transition: height 0.2s ease;
}

/* Hide native scrollbars inside the chat input so no vertical bar appears */
.chat-input::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.chat-input {
    -ms-overflow-style: none; /* IE/Edge */
    scrollbar-width: none; /* Firefox */
}

.chat-input::placeholder {
    color: #666666;
    font-weight: 400;
}

/* Input actions already defined above */

.input-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-btn:hover {
    color: var(--accent-green);
    transform: scale(1.05);
}

/* Send button specific styles */
.send-btn {
    background: linear-gradient(135deg, #15CC96, #12B887);
    border: none;
    color: #ffffff;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(21, 204, 150, 0.3);
}

.send-btn:hover:not(.disabled) {
    background: linear-gradient(135deg, #12B887, #0fa67a);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(21, 204, 150, 0.4);
}

.send-btn.disabled,
.send-btn:disabled {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.3);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.send-btn.disabled:hover,
.send-btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

/* Loading state for send button */
.send-btn.loading {
    position: relative;
    color: transparent;
}

.send-btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Send functionality is now handled by the smart input-btn (voice/send toggle) */

/* ===========================================
   MODEL SELECTOR
   =========================================== */
.model-selector-wrapper {
    position: relative;
}

.model-selector-btn {
    background: transparent;
    border: none;
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.875rem;
    font-weight: 400;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    transition: all 0.2s ease;
    min-width: auto;
    min-height: var(--touch-target);
    font-family: var(--font-primary);
    box-shadow: none;
}

.model-selector-btn:hover {
    color: rgba(255, 255, 255, 0.95);
    background: rgba(255, 255, 255, 0.05);
}

.model-selector-btn[aria-expanded="true"]:not([data-model="deep-research"]) {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.95);
}

.model-selector-btn[aria-expanded="true"][data-model="deep-research"] {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-green);
}

.model-selector-label {
    white-space: nowrap;
    color: inherit;
}

.model-selector-chevron {
    font-size: 0.625rem;
    transition: transform 0.3s ease-in-out;
    color: inherit;
    opacity: 0.7;
}

.model-selector-btn[aria-expanded="true"] .model-selector-chevron {
    transform: rotate(180deg);
}

/* Deep Research active state with green glow */
.model-selector-btn[data-model="deep-research"] {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-green);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
    animation: deepResearchGlow 2s ease-in-out infinite;
}

.model-selector-btn[data-model="deep-research"]:hover {
    background: rgba(16, 185, 129, 0.15);
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.4);
}

@keyframes deepResearchGlow {
    0%, 100% {
        box-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
    }
    50% {
        box-shadow: 0 0 16px rgba(16, 185, 129, 0.4);
    }
}

/* Pulsing green glow when researching */
.model-selector-btn[data-model="deep-research"].researching {
    animation: deepResearchPulse 1.5s ease-in-out infinite;
    color: var(--accent-green);
}

@keyframes deepResearchPulse {
    0%, 100% {
        box-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
    }
    50% {
        box-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
    }
}

/* ===========================================
   DEEP RESEARCH INLINE COMPONENT
   =========================================== */

/* Inline Research Message - Stays in Chat Thread */
.ai-message.deep-research-message {
    background: transparent;
    padding: 0;
}

.deep-research-inline {
    width: 100%;
    max-width: 100%;
    padding: 2rem;
    background: transparent;
    animation: fadeIn 0.3s ease-out;
}

/* Inline Progress Card */
.research-inline-card {
    background: #1A1A1A;
    border: 1px solid #2A2A2A;
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.research-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.research-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(16, 185, 129, 0.3);
    border-top-color: var(--accent-green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.research-status-text {
    color: var(--accent-green);
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: var(--font-primary);
}

.research-time-text {
    font-size: 0.875rem;
    color: #9CA3AF;
    margin-bottom: 1rem;
    line-height: 1.4;
}

/* Inline Progress Bar */
.research-progress-bar {
    width: 100%;
    height: 6px;
    background: #2A2A2A;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.research-progress-fill {
    height: 100%;
    background: var(--accent-green);
    border-radius: 3px;
    transition: width 0.5s ease;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

/* Live Updates Feed */
.research-updates-container {
    margin-bottom: 1.5rem;
}

.research-update-item {
    color: #D1D5DB;
    font-size: 0.9375rem;
    line-height: 1.6;
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
    position: relative;
    animation: fadeInUp 0.4s ease-out;
}

.research-update-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.6rem;
    width: 6px;
    height: 6px;
    background: var(--accent-green);
    border-radius: 50%;
}

/* Search Query Chips */
.research-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.research-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 999px;
    color: #FFFFFF;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    animation: chipPopIn 0.3s ease-out;
}

.research-chip:hover {
    background: rgba(16, 185, 129, 0.2);
    border-color: rgba(16, 185, 129, 0.4);
}

/* Research Answer Content */
.research-answer-content {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #2A2A2A;
    animation: fadeIn 0.5s ease-out;
}

.research-answer-content p {
    color: #E5E7EB;
    font-size: 0.9375rem;
    line-height: 1.7;
    margin-bottom: 1rem;
}

.research-answer-content h1,
.research-answer-content h2,
.research-answer-content h3 {
    color: #FFFFFF;
    font-weight: 700;
    margin: 1.5rem 0 1rem 0;
}

.research-answer-content ul,
.research-answer-content ol {
    padding-left: 1.5rem;
    margin: 1rem 0;
    color: #D1D5DB;
}

.research-answer-content li {
    margin-bottom: 0.5rem;
}

.research-answer-content strong {
    color: #FFFFFF;
    font-weight: 600;
}

.research-answer-content code {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-green);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

@keyframes chipPopIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .deep-research-inline {
        padding: 1rem;
    }
    
    .research-inline-card {
        padding: 1.25rem;
    }
    
    .research-status-text {
        font-size: 0.875rem;
    }
    
    .research-update-item {
        font-size: 0.875rem;
    }
    
    .research-answer-content {
        font-size: 0.875rem;
    }
}

/* Ensure it works within existing chat layout */
.chat-container .ai-message.deep-research-message {
    max-width: 100%;
}

.chat-container .ai-message.deep-research-message .message-content {
    background: transparent;
    border: none;
    padding: 0;
}

.deep-research-progress {
    margin-bottom: 1rem;
}

.research-progress-panel {
    background: rgba(26, 26, 26, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.research-progress-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    opacity: 0.4;
    transition: opacity 0.4s ease-in-out, transform 0.3s ease-in-out;
    transform: translateX(-8px);
    font-size: 0.8125rem;
    color: #9ca3af;
    font-style: italic;
    font-family: var(--font-primary);
}

.research-progress-step.completed {
    opacity: 0.6;
    color: #6b7280;
}

.research-progress-step.active {
    opacity: 1;
    color: #ffffff;
    transform: translateX(0);
}

.progress-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(16, 185, 129, 0.3);
    border-top-color: var(--accent-green);
    border-radius: 50%;
    animation: progressSpinner 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes progressSpinner {
    to {
        transform: rotate(360deg);
    }
}

.progress-text {
    flex: 1;
}

.progress-dots {
    display: inline-block;
    width: 1.5em;
    text-align: left;
}

.progress-dots::after {
    content: '...';
    animation: progressDots 1.5s steps(4, end) infinite;
}

@keyframes progressDots {
    0%, 20% {
        content: '.';
    }
    40% {
        content: '..';
    }
    60%, 100% {
        content: '...';
    }
}

.progress-bar-container {
    width: 120px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.6), var(--accent-green));
    border-radius: 2px;
    width: 0%;
    transition: width 2.8s ease-in-out;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.research-complete {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent-green);
    font-size: 0.8125rem;
    font-style: italic;
    font-family: var(--font-primary);
    animation: researchCompleteFade 0.5s ease-in-out;
}

.research-complete i {
    font-size: 1rem;
    animation: researchCompleteCheck 0.4s ease-in-out;
}

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

@keyframes researchCompleteCheck {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.model-selector-dropdown {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    right: 0;
    min-width: 240px;
    background: rgba(26, 26, 26, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.75rem;
    padding: 0.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: all 0.3s ease-in-out;
    z-index: 1000;
    pointer-events: none;
}

.model-selector-dropdown[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.model-option {
    width: 100%;
    background: none;
    border: none;
    border-radius: 0.5rem;
    padding: 0.75rem;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s ease;
    text-align: left;
    font-family: var(--font-primary);
}

.model-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.model-option i:first-child {
    font-size: 1rem;
    color: #9ca3af;
    flex-shrink: 0;
}

.model-option-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.model-option-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #ffffff;
}

.model-option-desc {
    font-size: 0.75rem;
    color: #9ca3af;
    font-weight: 400;
}

.model-option-check {
    font-size: 0.75rem;
    color: var(--accent-green);
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.model-option[data-selected="true"] .model-option-check {
    opacity: 1;
}

.model-option[data-selected="true"] {
    background: rgba(16, 185, 129, 0.1);
}

.model-option[data-selected="true"] i:first-child {
    color: var(--accent-green);
}

/* ===========================================
   FOOTER
   =========================================== */
.chat-footer {
    padding: 0.25rem 1rem;
    background: rgba(26, 26, 26, 0.6);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.footer-branding {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    opacity: 0.8;
    transition: all 0.2s ease;
}

.footer-branding:hover {
    opacity: 1;
    transform: translateY(-1px);
}

.footer-text {
    font-size: 0.6875rem;
    color: #9ca3af;
    font-weight: 400;
}

.footer-logo {
    height: 1.25rem;
    width: auto;
    filter: brightness(1.2);
}

/* ===========================================
   RESPONSIVE BREAKPOINTS - IPHONE OPTIMIZED
   =========================================== */

/* iPhone SE ONLY (375px × 667px) - Precise targeting */
@media only screen 
  and (device-width: 375px) 
  and (device-height: 667px) 
  and (-webkit-device-pixel-ratio: 2),
  /* Fallback for browser testing */
  screen and (max-width: 375px) and (max-height: 667px) {
    
    /* iPhone SE specific optimizations */
    :root {
        --sidebar-width-mobile: 85vw;
        --header-height: 2.75rem;
        --touch-target: 2.5rem; /* 40px - slightly smaller for SE */
        --card-gap: 0.5rem;
    }
    
    /* Sidebar optimizations for small screen */
    .sidebar {
        width: var(--sidebar-width-mobile);
        max-width: 18rem;
    }
    
    .sidebar-header {
        padding: 0.5rem 0.75rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .amz-logo {
        height: 1.5rem;
    }
    
    .action-btn {
        min-width: 2rem;
        min-height: 2rem;
        padding: 0.25rem;
    }
    
    /* Search section */
    .search-container {
        padding: 0.5rem 0.75rem;
    }
    
    .search-box {
        padding: 0.5rem 0.75rem 0.5rem 2rem;
        border-radius: 0.375rem;
    }
    
    .search-icon {
        left: 0.75rem;
        font-size: 0.75rem;
    }
    
    .search-input {
        font-size: 0.75rem;
    }
    
    /* Chat section */
    .chats-section {
        padding: 0 0.75rem;
        margin-bottom: 1rem;
    }
    
    .section-title {
        font-size: 0.6875rem;
    }
    
    /* Mobile account link styling for small screens */
    .mobile-account-link {
        padding: 0.5rem 0.75rem;
        margin-top: 0.25rem;
    }
    
    .mobile-account-btn {
        padding: 0.625rem 0.75rem;
        font-size: 0.8125rem;
    }
    
    .chat-item {
        padding: 0.375rem 0.5rem;
        margin-bottom: 0.125rem;
        border-radius: 0.375rem;
        min-height: var(--touch-target);
    }
    
    .chat-icon {
        font-size: 0.875rem;
    }
    
    .chat-title {
        font-size: 0.75rem;
        margin-bottom: 0.125rem;
    }
    
    .chat-preview {
        font-size: 0.625rem;
        line-height: 1.2;
    }
    
    .chat-menu {
        min-width: 1.25rem;
        min-height: 1.25rem;
        font-size: 0.625rem;
    }
    
    /* New chat button */
    .new-chat-btn {
        padding: 0.75rem;
        margin-top: auto;
        margin-bottom: 0;
        /* Ensure button is always visible above Safari's bottom bar with fallback */
        padding-bottom: max(calc(0.75rem + var(--safe-area-inset-bottom)), 1.5rem);
    }
    
    .new-chat-button {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
        min-height: var(--touch-target);
        border-radius: 0.375rem;
    }
    
    /* Header - Optimized for iPhone SE small width */
    .chat-header {
        padding: 0.375rem 0.5rem;
        height: var(--header-height);
        gap: 0.375rem; /* Reduce gap between elements */
    }
    
    .hamburger-btn {
        width: 2rem; /* Smaller hamburger button */
        height: 2rem;
        padding: 0.25rem;
        flex-shrink: 0;
    }
    
    .hamburger-icon {
        font-size: 1rem;
    }
    
    .back-btn {
        min-width: 2rem; /* Smaller back button */
        min-height: 2rem;
        padding: 0.25rem;
        font-size: 0.75rem;
        flex-shrink: 0;
    }
    
    /* Chat title area - allow it to shrink */
    .chat-title-header {
        flex: 1;
        min-width: 0; /* Allow shrinking */
        display: flex;
        align-items: center;
        gap: 0.25rem;
        overflow: hidden;
    }
    
    .chat-name {
        font-size: 0.75rem;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 6rem; /* Limit width */
    }
    
    .chat-model {
        padding: 0.0625rem 0.25rem;
        font-size: 0.4375rem;
        border-radius: 0.375rem;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    /* Header actions - make more compact */
    .header-actions {
        display: flex;
        gap: 0.125rem; /* Reduce gap between action buttons */
        flex-shrink: 0;
    }
    
    .header-btn {
        min-width: 1.75rem; /* Smaller action buttons */
        min-height: 1.75rem;
        padding: 0.25rem;
        font-size: 0.75rem;
    }
    
    /* Main content area */
    .chat-container {
        padding: 0.75rem 0.5rem;
    }
    
    .welcome-section {
        padding: 0.5rem;
        text-align: center;
    }
    
    .welcome-logo {
        height: 2rem;
        margin-bottom: 0.75rem;
    }
    
    .welcome-title {
        font-size: 1.125rem;
        margin-bottom: 0.5rem;
        line-height: 1.2;
    }
    
    .welcome-subtitle {
        font-size: 0.75rem;
        margin-bottom: 1.25rem;
        line-height: 1.3;
        max-width: 100%;
        padding: 0 0.5rem;
    }
    
    /* Template cards - single column for SE */
    .template-cards {
        gap: 0.5rem;
        grid-template-columns: 1fr;
        margin-bottom: 1rem;
    }
    
    .template-card {
        padding: 0.75rem;
        border-radius: 0.375rem;
        min-height: 5rem;
        text-align: left;
    }
    
    .card-icon {
        width: 1.75rem;
        height: 1.75rem;
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
        border-radius: 0.375rem;
    }
    
    .card-title {
        font-size: 0.75rem;
        margin-bottom: 0.25rem;
        font-weight: 600;
    }
    
    .card-description {
        font-size: 0.625rem;
        line-height: 1.2;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    
    /* Input area */
    .input-container {
        padding: 0.5rem 0.75rem 0.75rem;
    }
    
    .input-wrapper {
        padding: 0.5rem 0.75rem;
        border-radius: 1rem;
        min-height: 2.5rem;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .file-upload-btn {
        margin-top: 0;
        min-width: 2rem;
        min-height: 2rem;
        padding: 0.375rem;
        font-size: 0.875rem;
    }
    
    .input-area-wrapper {
        gap: 0.375rem;
    }
    
    /* Model selector mobile adjustments */
    .model-selector-btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
        gap: 0.25rem;
    }
    
    .model-selector-label {
        display: inline; /* Keep label visible on mobile since we removed the icon */
    }
    
    .model-selector-dropdown {
        min-width: 200px;
        right: 0;
    }
    
    
    
    .chat-input {
        font-size: 0.875rem;
    }
    
    .input-btn {
        min-width: 2rem;
        min-height: 2rem;
        padding: 0.375rem;
        font-size: 0.875rem;
    }
    
    .send-btn {
        min-width: 2rem;
        min-height: 2rem;
        padding: 0.375rem 0.5rem;
        border-radius: 0.5rem;
        font-size: 0.75rem;
    }
    
    /* Footer */
    .chat-footer {
        padding: 0.375rem;
    }
    
    .footer-text {
        font-size: 0.5625rem;
    }
    
    .footer-logo {
        height: 0.875rem;
    }
}

/* iPhone 6/7/8 (375px × 667px) - Standard iPhone Size */
@media (min-width: 23.4375em) and (max-width: 25.9375em) {
    :root {
        --sidebar-width-mobile: 85vw;
        --header-height: 3.25rem;
        --touch-target: 2.75rem;
        --card-gap: 0.875rem;
    }
    
    .sidebar-header {
        padding: 0.875rem 1.125rem;
    }
    
    .amz-logo {
        height: 1.875rem;
    }
    
    .search-container {
        padding: 0.875rem 1.125rem;
    }
    
    .chats-section {
        padding: 0 1.125rem;
    }
    
    .chat-item {
        padding: 0.5625rem 0.75rem;
    }
    
    .chat-title {
        font-size: 0.875rem;
    }
    
    .chat-preview {
        font-size: 0.75rem;
    }
    
    .new-chat-btn {
        padding: 1.125rem;
        margin-bottom: 0;
        /* Ensure button is always visible above Safari's bottom bar with fallback */
        padding-bottom: max(calc(1.125rem + var(--safe-area-inset-bottom)), 1.75rem);
    }
    
    .chat-header {
        padding: 0.875rem;
        height: var(--header-height);
    }
    
    .welcome-section {
        padding: 0.75rem;
    }
    
    .welcome-logo {
        height: 2.75rem;
    }
    
    .welcome-title {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }
    
    .welcome-subtitle {
        font-size: 0.875rem;
        margin-bottom: 1.75rem;
    }
    
    .template-cards {
        gap: 0.75rem;
    }
    
    .template-card {
        padding: 1.125rem;
    }
    
    .card-icon {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 1.0625rem;
        margin-bottom: 0.6875rem;
    }
    
    .card-title {
        font-size: 0.875rem;
        margin-bottom: 0.4375rem;
    }
    
    .card-description {
        font-size: 0.75rem;
    }
    
    .input-container {
        padding: 0.875rem;
    }
    
    .input-wrapper {
        padding: 0.6875rem 1.125rem;
    }
    
    .chat-input {
        font-size: 1rem;
    }
}

/* iPhone 6/7/8 Plus (414px × 736px) - Larger iPhone Size */
@media (min-width: 25.875em) and (max-width: 27.5em) {
    :root {
        --sidebar-width-mobile: 82vw;
        --header-height: 3.5rem;
        --touch-target: 2.875rem;
        --card-gap: 1rem;
    }
    
    .sidebar-header {
        padding: 1rem 1.25rem;
    }
    
    .amz-logo {
        height: 2rem;
    }
    
    .search-container {
        padding: 1rem 1.25rem;
    }
    
    .chats-section {
        padding: 0 1.25rem;
    }
    
    .chat-item {
        padding: 0.625rem 0.75rem;
        min-height: var(--touch-target);
    }
    
    .chat-title {
        font-size: 0.9375rem;
    }
    
    .chat-preview {
        font-size: 0.8125rem;
    }
    
    .new-chat-btn {
        padding: 1.25rem;
        margin-bottom: 0;
        /* Ensure button is always visible above Safari's bottom bar with fallback */
        padding-bottom: max(calc(1.25rem + var(--safe-area-inset-bottom)), 2rem);
    }
    
    .new-chat-button {
        padding: 0.75rem 1rem;
        font-size: 0.9375rem;
        min-height: var(--touch-target);
    }
    
    .chat-header {
        padding: 1rem;
        height: var(--header-height);
    }
    
    .chat-name {
        font-size: 1.0625rem;
    }
    
    .welcome-section {
        padding: 1rem;
    }
    
    .welcome-logo {
        height: 3rem;
    }
    
    .welcome-title {
        font-size: 1.625rem;
        margin-bottom: 0.875rem;
    }
    
    .welcome-subtitle {
        font-size: 0.9375rem;
        margin-bottom: 2rem;
    }
    
    .template-cards {
        gap: 0.875rem;
        grid-template-columns: repeat(2, 1fr);
    }
    
    .template-card {
        padding: 1.25rem;
    }
    
    .card-icon {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.125rem;
        margin-bottom: 0.75rem;
    }
    
    .card-title {
        font-size: 0.9375rem;
        margin-bottom: 0.5rem;
    }
    
    .card-description {
        font-size: 0.8125rem;
    }
    
    .input-container {
        padding: 1rem;
    }
    
    .input-wrapper {
        padding: 0.75rem 1.25rem;
    }
    
    
    .chat-input {
        font-size: 1rem;
    }
    
    .input-btn, .send-btn {
        min-width: var(--touch-target);
        min-height: var(--touch-target);
    }
}

/* iPhone X/XS (375px × 812px) - First iPhone with notch */
@media (min-width: 23.4375em) and (max-width: 25.9375em) and (min-height: 50.75em) {
    :root {
        --sidebar-width-mobile: 85vw;
        --header-height: 3.25rem;
        --touch-target: 2.75rem;
        --card-gap: 0.875rem;
    }
    
    .chat-container {
        padding: 1rem 0.75rem;
        /* Additional padding for longer screen */
        min-height: calc(100vh - var(--header-height) - 8rem);
    }
    
    .welcome-section {
        padding: 1rem 0.75rem;
        max-width: 100%;
    }
    
    .welcome-title {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }
    
    .welcome-subtitle {
        font-size: 0.875rem;
        margin-bottom: 1.75rem;
        line-height: 1.4;
    }
    
    .template-cards {
        gap: 0.75rem;
        margin-bottom: 1rem;
    }
    
    .template-card {
        padding: 1.125rem;
        min-height: 7rem;
    }
    
    .card-icon {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 1.0625rem;
        margin-bottom: 0.6875rem;
    }
    
    /* Optimize for the taller screen */
    .chats-section {
        max-height: calc(100vh - 12rem);
        overflow-y: auto;
    }
    
    /* Better spacing for notch compatibility */
    .sidebar-header {
        padding-top: calc(0.875rem + var(--safe-area-inset-top));
    }
}

/* iPhone XR/11 (414px × 896px) - Mid-size with notch */
@media (min-width: 25.875em) and (max-width: 27.25em) and (min-height: 56em) {
    :root {
        --sidebar-width-mobile: 82vw;
        --header-height: 3.5rem;
        --touch-target: 2.875rem;
        --card-gap: 1rem;
    }
    
    .chat-container {
        padding: 1.25rem 1rem;
        min-height: calc(100vh - var(--header-height) - 8rem);
    }
    
    .welcome-section {
        padding: 1.25rem 1rem;
    }
    
    .welcome-title {
        font-size: 1.625rem;
        margin-bottom: 0.875rem;
    }
    
    .welcome-subtitle {
        font-size: 0.9375rem;
        margin-bottom: 2rem;
    }
    
    .template-cards {
        gap: 0.875rem;
        grid-template-columns: repeat(2, 1fr);
    }
    
    .template-card {
        padding: 1.25rem;
        min-height: 8rem;
    }
    
    .card-icon {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.125rem;
        margin-bottom: 0.75rem;
    }
    
    .card-title {
        font-size: 0.9375rem;
        margin-bottom: 0.5rem;
    }
    
    .card-description {
        font-size: 0.8125rem;
    }
    
    /* Optimize chat list for taller screen */
    .chats-section {
        max-height: calc(100vh - 14rem);
        overflow-y: auto;
    }
}

/* iPhone XS Max/11 Pro Max (414px × 896px) - Largest with notch */
@media (min-width: 25.875em) and (max-width: 27.5em) and (min-height: 56em) {
    :root {
        --sidebar-width-mobile: 81vw;
        --header-height: 3.625rem;
        --touch-target: 2.9375rem;
        --card-gap: 1.0625rem;
    }
    
    .chat-container {
        padding: 1.375rem 1.125rem;
        min-height: calc(100vh - var(--header-height) - 8.5rem);
    }
    
    .welcome-section {
        padding: 1.375rem 1.125rem;
    }
    
    .welcome-title {
        font-size: 1.6875rem;
        margin-bottom: 0.9375rem;
    }
    
    .welcome-subtitle {
        font-size: 0.96875rem;
        margin-bottom: 2.125rem;
    }
    
    .template-cards {
        gap: 0.9375rem;
        grid-template-columns: repeat(2, 1fr);
    }
    
    .template-card {
        padding: 1.3125rem;
        min-height: 8.25rem;
    }
    
    .card-icon {
        width: 2.625rem;
        height: 2.625rem;
        font-size: 1.15625rem;
        margin-bottom: 0.8125rem;
    }
    
    .card-title {
        font-size: 0.96875rem;
        margin-bottom: 0.53125rem;
    }
    
    .card-description {
        font-size: 0.84375rem;
    }
    
    .chats-section {
        max-height: calc(100vh - 14.5rem);
        overflow-y: auto;
    }
    
    .chat-item {
        padding: 0.71875rem 0.90625rem;
        min-height: var(--touch-target);
    }
    
    .chat-title {
        font-size: 0.96875rem;
    }
    
    .chat-preview {
        font-size: 0.84375rem;
    }
    
    .input-wrapper {
        padding: 0.8125rem 1.25rem;
    }
    
    
    .chat-input {
        font-size: 1.03125rem;
    }
}

/* iPhone 12 Mini / 13 Mini (360px × 780px) - Compact modern iPhone */
@media (min-width: 22.5em) and (max-width: 24.375em) and (min-height: 48.75em) {
    :root {
        --sidebar-width-mobile: 88vw;
        --header-height: 3rem;
        --touch-target: 2.75rem;
        --card-gap: 0.625rem;
    }
    
    .sidebar-header {
        padding: 0.75rem 1rem;
    }
    
    .amz-logo {
        height: 1.75rem;
    }
    
    .search-container {
        padding: 0.75rem 1rem;
    }
    
    .chats-section {
        padding: 0 1rem;
        max-height: calc(100vh - 12rem);
        overflow-y: auto;
    }
    
    .chat-item {
        padding: 0.5rem 0.625rem;
        margin-bottom: 0.125rem;
    }
    
    .chat-title {
        font-size: 0.8125rem;
    }
    
    .chat-preview {
        font-size: 0.6875rem;
    }
    
    .new-chat-btn {
        padding: 1rem;
        margin-bottom: 0;
        /* Ensure button is always visible above Safari's bottom bar with fallback */
        padding-bottom: max(calc(1rem + var(--safe-area-inset-bottom)), 1.5rem);
    }
    
    .chat-header {
        padding: 0.75rem;
        height: calc(var(--header-height) + var(--safe-area-inset-top));
    }
    
    .chat-container {
        padding: 0.75rem 0.625rem;
        min-height: calc(100vh - var(--header-height) - 7rem);
    }
    
    .welcome-section {
        padding: 0.75rem 0.5rem;
    }
    
    .welcome-logo {
        height: 2.25rem;
    }
    
    .welcome-title {
        font-size: 1.25rem;
        margin-bottom: 0.625rem;
    }
    
    .welcome-subtitle {
        font-size: 0.8125rem;
        margin-bottom: 1.5rem;
        line-height: 1.3;
    }
    
    .template-cards {
        gap: 0.625rem;
    }
    
    .template-card {
        padding: 0.875rem;
        min-height: 6rem;
    }
    
    .card-icon {
        width: 1.875rem;
        height: 1.875rem;
        font-size: 0.9375rem;
        margin-bottom: 0.5rem;
    }
    
    .card-title {
        font-size: 0.8125rem;
        margin-bottom: 0.375rem;
    }
    
    .card-description {
        font-size: 0.6875rem;
        line-height: 1.2;
    }
    
    .input-container {
        padding: 0.75rem;
    }
    
    .input-wrapper {
        padding: 0.625rem 1rem;
        border-radius: 1.125rem;
    }
    
    
    .chat-input {
        font-size: 0.9375rem;
    }
}

/* iPhone 12/12 Pro/13/13 Pro/14 (390px × 844px) - Standard modern iPhone */
@media (min-width: 24.375em) and (max-width: 26.25em) and (min-height: 52.75em) {
    :root {
        --sidebar-width-mobile: 85vw;
        --header-height: 3.25rem;
        --touch-target: 2.875rem;
        --card-gap: 0.875rem;
    }
    
    .chat-container {
        padding: 1rem 0.875rem;
        min-height: calc(100vh - var(--header-height) - 8rem);
    }
    
    .welcome-section {
        padding: 1rem 0.875rem;
    }
    
    .welcome-logo {
        height: 2.75rem;
    }
    
    .welcome-title {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }
    
    .welcome-subtitle {
        font-size: 0.875rem;
        margin-bottom: 1.75rem;
    }
    
    .template-cards {
        gap: 0.75rem;
        grid-template-columns: repeat(2, 1fr);
    }
    
    .template-card {
        padding: 1.125rem;
        min-height: 7.5rem;
    }
    
    .card-icon {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 1.0625rem;
        margin-bottom: 0.6875rem;
    }
    
    .card-title {
        font-size: 0.875rem;
        margin-bottom: 0.4375rem;
    }
    
    .card-description {
        font-size: 0.75rem;
    }
    
    .chats-section {
        max-height: calc(100vh - 13rem);
        overflow-y: auto;
    }
    
    .chat-item {
        padding: 0.5625rem 0.75rem;
        min-height: var(--touch-target);
    }
    
    .input-wrapper {
        padding: 0.6875rem 1.125rem;
    }
}

/* iPhone 12 Pro Max/13 Pro Max/14 Plus/15 Plus (428px × 926px) - Large modern iPhone */
@media (min-width: 26.75em) and (max-width: 28.75em) and (min-height: 57.875em) {
    :root {
        --sidebar-width-mobile: 80vw;
        --header-height: 3.75rem;
        --touch-target: 3rem;
        --card-gap: 1.125rem;
    }
    
    .chat-container {
        padding: 1.5rem 1.25rem;
        min-height: calc(100vh - var(--header-height) - 9rem);
    }
    
    .welcome-section {
        padding: 1.5rem 1.25rem;
    }
    
    .welcome-logo {
        height: 3.25rem;
    }
    
    .welcome-title {
        font-size: 1.75rem;
        margin-bottom: 1rem;
    }
    
    .welcome-subtitle {
        font-size: 1rem;
        margin-bottom: 2.25rem;
    }
    
    .template-cards {
        gap: 1rem;
        grid-template-columns: repeat(2, 1fr);
    }
    
    .template-card {
        padding: 1.5rem;
        min-height: 9rem;
    }
    
    .card-icon {
        width: 2.75rem;
        height: 2.75rem;
        font-size: 1.25rem;
        margin-bottom: 0.875rem;
    }
    
    .card-title {
        font-size: 1rem;
        margin-bottom: 0.5625rem;
    }
    
    .card-description {
        font-size: 0.875rem;
    }
    
    .chats-section {
        max-height: calc(100vh - 15rem);
        overflow-y: auto;
    }
    
    .chat-item {
        padding: 0.75rem 0.875rem;
        min-height: var(--touch-target);
    }
    
    .chat-title {
        font-size: 1rem;
    }
    
    .chat-preview {
        font-size: 0.875rem;
    }
    
    .input-wrapper {
        padding: 0.875rem 1.375rem;
    }
    
    
    .chat-input {
        font-size: 1.0625rem;
    }
}

/* iPhone 14 Pro/15/15 Pro (393px × 852px) - Pro models with Dynamic Island */
@media (min-width: 24.5625em) and (max-width: 26.4375em) and (min-height: 53.25em) {
    :root {
        --sidebar-width-mobile: 84vw;
        --header-height: 3.375rem;
        --touch-target: 2.875rem;
        --card-gap: 0.9375rem;
    }
    
    /* Extra padding for Dynamic Island */
    .chat-header {
        padding-top: calc(1rem + var(--safe-area-inset-top) + 0.25rem);
    }
    
    .sidebar-header {
        padding-top: calc(0.875rem + var(--safe-area-inset-top) + 0.25rem);
    }
    
    .chat-container {
        padding: 1.125rem 1rem;
        min-height: calc(100vh - var(--header-height) - 8.5rem);
    }
    
    .welcome-section {
        padding: 1.125rem 1rem;
    }
    
    .welcome-title {
        font-size: 1.5625rem;
        margin-bottom: 0.8125rem;
    }
    
    .welcome-subtitle {
        font-size: 0.9375rem;
        margin-bottom: 1.875rem;
    }
    
    .template-cards {
        gap: 0.8125rem;
        grid-template-columns: repeat(2, 1fr);
    }
    
    .template-card {
        padding: 1.1875rem;
        min-height: 7.75rem;
    }
    
    .chats-section {
        max-height: calc(100vh - 13.5rem);
        overflow-y: auto;
    }
}

/* iPhone 14 Pro Max/15 Pro Max (430px × 932px) - Largest Pro models with Dynamic Island */
@media (min-width: 26.875em) and (max-width: 28.9375em) and (min-height: 58.25em) {
    :root {
        --sidebar-width-mobile: 78vw;
        --header-height: 3.875rem;
        --touch-target: 3.125rem;
        --card-gap: 1.1875rem;
    }
    
    /* Extra padding for Dynamic Island */
    .chat-header {
        padding-top: calc(1rem + var(--safe-area-inset-top) + 0.375rem);
    }
    
    .sidebar-header {
        padding-top: calc(1rem + var(--safe-area-inset-top) + 0.375rem);
    }
    
    .chat-container {
        padding: 1.75rem 1.375rem;
        min-height: calc(100vh - var(--header-height) - 9.5rem);
    }
    
    .welcome-section {
        padding: 1.75rem 1.375rem;
    }
    
    .welcome-logo {
        height: 3.5rem;
    }
    
    .welcome-title {
        font-size: 1.875rem;
        margin-bottom: 1.125rem;
    }
    
    .welcome-subtitle {
        font-size: 1.0625rem;
        margin-bottom: 2.5rem;
    }
    
    .template-cards {
        gap: 1.125rem;
        grid-template-columns: repeat(2, 1fr);
    }
    
    .template-card {
        padding: 1.625rem;
        min-height: 9.5rem;
    }
    
    .card-icon {
        width: 3rem;
        height: 3rem;
        font-size: 1.375rem;
        margin-bottom: 1rem;
    }
    
    .card-title {
        font-size: 1.0625rem;
        margin-bottom: 0.625rem;
    }
    
    .card-description {
        font-size: 0.9375rem;
    }
    
    .chats-section {
        max-height: calc(100vh - 16rem);
        overflow-y: auto;
    }
    
    .chat-item {
        padding: 0.8125rem 1rem;
        min-height: var(--touch-target);
    }
    
    .chat-title {
        font-size: 1.0625rem;
    }
    
    .chat-preview {
        font-size: 0.9375rem;
    }
    
    .input-wrapper {
        padding: 1rem 1.5rem;
    }
    
    .chat-input {
        font-size: 1.125rem;
    }
}

/* Large Mobile (430px+) */
@media (min-width: 26.875em) {
    .welcome-title {
        font-size: clamp(1.75rem, 5vw, 2.25rem);
    }
    
    .template-card {
        padding: 1.5rem;
    }
    
    .welcome-logo {
        height: 3.5rem;
    }
}

/* Tablet Portrait (768px+) */
@media (min-width: 48em) {
    :root {
        --card-gap: 1.25rem;
    }
    
    .hamburger-btn { display: none !important; }
    
    .sidebar {
        position: static;
        left: 0;
        width: var(--sidebar-width-tablet);
        max-width: var(--sidebar-width-tablet);
        border-right: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .sidebar-overlay {
        display: none;
    }
    
    .template-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--card-gap);
    }
    
    /* Hide mobile account link on desktop */
    .mobile-account-link {
        display: none !important;
    }
    
    /* On desktop, JavaScript controls headerUser visibility via inline styles */
    /* The mobile rule with display: none !important only applies on mobile (max-width: 767px) */
    /* So on desktop, JavaScript's inline style.display = 'flex' will work correctly */
    
    .welcome-section {
        max-width: 56rem; /* ~896px for tablet/desktop entry */
        margin: 0 auto;
    }
    
    .chat-container {
        padding: 2rem;
    }
    
    .welcome-logo {
        height: 4rem;
    }
    
    .amz-logo {
        height: 2.25rem;
    }
}

/* Ensure hamburger stays hidden on desktop even if other rules load later */
@media (min-width: 768px) {
    .hamburger-btn { display: none !important; }
}

/* Hide feature cards on mobile (cleaner phone layout) */
@media (max-width: 767px) {
    .template-cards { display: none !important; margin: 0 !important; }
}

/* Desktop (1024px+) */
@media (min-width: 64em) {
    :root {
        --card-gap: 1.5rem;
    }
    
    .sidebar {
        width: var(--sidebar-width-desktop);
        max-width: var(--sidebar-width-desktop);
    }
    
    .template-cards {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .welcome-section {
        max-width: 64rem; /* 1024px container for standard desktop */
    }
    
    .input-wrapper {
        max-width: 90%;
        margin: 0 auto;
    }
    
    .welcome-logo {
        height: 4.5rem;
    }
    
    .amz-logo {
        height: 2.5rem;
    }

    /* Desktop header sizing to avoid clipping at 1024px+ */
    .welcome-title {
        font-size: 2rem; /* cap desktop size to avoid overflow */
        line-height: 1.15;
        max-width: 100%;
    }
}

/* =====================
   ACCOUNT DASHBOARD - GLASSMORPHISM
   ===================== */
.account-app { 
    display:flex; 
    min-height:100vh; 
    background: #000000;
    position: relative;
}

.account-sidebar { 
    width: 18rem; 
    background: rgba(18, 18, 18, 0.9); 
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255, 255, 255, 0.1); 
    padding: 2rem 1.5rem; 
    position: sticky; 
    top: 0; 
    height: 100vh;
    z-index: 1;
}

.account-brand { 
    display: flex; align-items: center; justify-content:center;
    margin-bottom: 2rem; padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.account-brand .brand-text { 
    color: #e5e7eb; 
    font-weight: 800; 
    letter-spacing: -0.02em; 
    font-size: 1.125rem;
}

.account-nav { 
    display: flex; 
    flex-direction: column; 
    gap: 0.5rem; 
}

.account-nav .nav-item { 
    display: flex; 
    align-items: center; 
    gap: 0.75rem; 
    padding: 0.875rem 1rem; 
    border-radius: 0.75rem; 
    color: #cbd5e1; 
    text-decoration: none; 
    background: transparent; 
    border: none; 
    width: 100%; 
    text-align: left; 
    font-size: 0.875rem; 
    font-weight: 500;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.account-nav .nav-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(21, 204, 150, 0.1), transparent);
    transition: left 0.5s ease;
}

.account-nav .nav-item:hover::before {
    left: 100%;
}

.account-nav .nav-item:hover { 
    background: rgba(255, 255, 255, 0.08); 
    color: #fff; 
    transform: translateX(4px);
}

.account-nav .nav-item.active { 
    background: transparent;
    color: #10B981;
    border-left: 3px solid #10B981;
    padding-left: calc(1rem - 3px);
}

.account-nav .nav-item.active i {
    color: #10B981;
}

.account-nav .nav-item.signout { 
    color: #ef4444; 
    margin-top: 1rem;
}

.account-nav .nav-item.backto { 
    color: #15CC96; 
    font-weight: 600; 
    background: rgba(21, 204, 150, 0.1);
    border: 1px solid rgba(21, 204, 150, 0.2);
}

.account-main { 
    flex: 1; 
    padding: 2rem 2.5rem; 
    overflow-y: auto; 
    position: relative;
    z-index: 1;
}

.account-header { 
    display:flex; 
    justify-content:space-between; 
    align-items:center; 
    margin-bottom: 2.5rem; 
    padding: 1.5rem 0 0 0; 
    background: transparent; 
    border: none; 
}

.account-header .header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.account-header .header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Account header hamburger (mobile) */
.account-hamburger { display:none; background:transparent; border:none; padding:.5rem; margin-right:.5rem; border-radius:.5rem; }
.account-hamburger .line { display:block; width:20px; height:2px; background:#fff; margin:4px 0; border-radius:2px; }
.account-hamburger:focus { outline:2px solid #15CC96; outline-offset:2px; }

.account-sidebar-overlay{ position:fixed; inset:0; background:rgba(0,0,0,.5); opacity:0; visibility:hidden; transition:all .25s; z-index:998; }
.account-sidebar-overlay.active{ opacity:1; visibility:visible; }

.page-title-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-left: 0.5rem;
}

.page-title { 
    color: #fff; 
    font-size: 2rem; 
    font-weight: 700; 
    margin: 0;
    line-height: 1.2;
}

.page-subtitle {
    display: none;
}

.plan-pill { 
    background: rgba(21, 204, 150, 0.15); 
    color: #15CC96; 
    padding: 0.5rem 1rem; 
    border-radius: 999px; 
    font-size: 0.875rem; 
    font-weight: 600; 
    border: 1px solid rgba(21, 204, 150, 0.3);
    backdrop-filter: blur(10px);
}

.user-chip { 
    display: flex; 
    align-items: center; 
    gap: 1rem; 
    background: rgba(255, 255, 255, 0.08); 
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 0.75rem 1.25rem; 
    border-radius: 1rem; 
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.chip-avatar { 
    width: 2.5rem; 
    height: 2.5rem; 
    border-radius: 50%; 
    object-fit: cover; 
    border: 2px solid rgba(21, 204, 150, 0.3);
    background: #2a2a2a;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9CA3AF;
    font-size: 1rem;
}

.avatar-default-icon {
    color: #9CA3AF;
    font-size: 1rem;
}

.chip-meta { 
    display: flex; 
    flex-direction: column; 
}

.chip-sub { 
    color: #9ca3af; 
    font-size: 0.75rem; 
}

.section { display:none; }
.section.active { display:block; }

.grid { 
    display: grid; 
    gap: 2rem; 
}

.grid.cols-3 { 
    grid-template-columns: 1fr; 
}

.grid.cols-2 { 
    grid-template-columns: 1fr; 
}

@media (min-width: 48em) {
    .grid.cols-2 { 
        grid-template-columns: 1fr 1fr; 
    }
}

@media (min-width: 64em) {
    .grid.cols-3 { 
        grid-template-columns: 1fr 1fr 1fr; 
    }
    .grid.cols-2 { 
        grid-template-columns: 1fr 1fr; 
    }
}

.card { background:#1f1f1f; border:1px solid rgba(255,255,255,0.08); border-radius:0.75rem; padding:1rem; }

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(21, 204, 150, 0.5), transparent);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
    border-color: rgba(21, 204, 150, 0.2);
}

.card-head { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    margin-bottom: 1.5rem; 
}

.card h2 { font-size:1.1rem; font-weight:700; color:#fff; margin:0; }

.profile-card .profile-row { display:flex; gap:1rem; }
.avatar-wrap { display:flex; flex-direction:column; align-items:center; gap:0.5rem; }
.avatar { width:5rem; height:5rem; border-radius:999px; border:1px solid rgba(255,255,255,0.2); object-fit:cover; background:#111; }
.hidden-file { display:none; }
.profile-fields { flex:1; display:flex; flex-direction:column; gap:0.5rem; }
.input { background: rgba(255,255,255,0.06); border:1px solid rgba(255,255,255,0.14); color:#fff; padding:0.5rem 0.75rem; border-radius:0.5rem; }
.meta-row { display:flex; gap:0.75rem; color:#9ca3af; font-size:0.875rem; }
.badge { background: rgba(255,255,255,0.08); border:1px solid rgba(255,255,255,0.14); padding:0.125rem 0.5rem; border-radius:999px; }
.actions-row { display:flex; gap:0.5rem; margin-top:0.25rem; }

.btn { background: rgba(255,255,255,0.08); border:1px solid rgba(255,255,255,0.15); color:#fff; padding:0.5rem 0.875rem; border-radius:0.5rem; font-weight:700; cursor:pointer; text-decoration:none; display:inline-flex; align-items:center; gap:0.375rem; }
.btn.primary { background: linear-gradient(135deg, #15CC96, #12B887); border:none; }
.btn.ghost { background: transparent; border:1px solid rgba(255,255,255,0.2); color:#cbd5e1; }

/* Dashboard darker typography tweaks */
.stat-label { color:#9aa3ad; }
.stat-value { color:#e8eef3; }
.a-value { color:#e8eef3; }

/* Simple dashboard (new) */
.section.simple { background: transparent; }
.simple-grid { display:grid; grid-template-columns:1fr; gap:1rem; }
.mobile-actions { display:none; }
.s-card { background:#1f1f1f; border:1px solid rgba(255,255,255,0.08); border-radius:0.75rem; padding:1rem; color:#e5e7eb; }
.s-card h2 { margin:0 0 .75rem; font-size:1.1rem; color:#fff; }
.s-row { display:flex; gap:1rem; align-items:flex-start; }
.s-row.two { justify-content:space-between; }
.s-col { flex:1; }
.s-avatar { width:64px; height:64px; border-radius:999px; object-fit:cover; border:2px solid rgba(255,255,255,0.12); background:#2a2a2a; display:flex; align-items:center; justify-content:center; color:#9CA3AF; font-size:1.5rem; }
.s-input { width:100%; background:#121212; color:#fff; border:1px solid rgba(255,255,255,0.12); border-radius:0.5rem; padding:0.5rem 0.75rem; margin-bottom:0.5rem; }
.s-meta { display:flex; gap:0.5rem; align-items:center; color:#9aa3ad; font-size:0.85rem; }
.s-badge { background:rgba(255,255,255,0.08); border:1px solid rgba(255,255,255,0.12); border-radius:999px; padding:0.15rem 0.5rem; color:#cbd5e1; }
.s-actions { display:flex; flex-wrap:wrap; gap:0.5rem; margin-top:0.5rem; }
.s-btn { background:#1f1f1f; border:1px solid rgba(255,255,255,0.15); color:#fff; padding:0.5rem 0.875rem; border-radius:0.5rem; cursor:pointer; }
.s-btn.primary { background:#10b981; border:none; color:#0b1f16; font-weight:700; }
.s-grid.two { display:grid; grid-template-columns:1fr 1fr; gap:0.75rem; }
.s-val { font-weight:800; color:#fff; }
.recent-list { list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:0.5rem; }
.recent-list li { padding:0.5rem; background:#151515; border:1px solid rgba(255,255,255,0.06); border-radius:0.5rem; display:flex; justify-content:space-between; align-items:center; }
.recent-list small { color:#9aa3ad; }

/* Usage visuals */
.usage-wrap { display:flex; flex-direction:column; gap:0.75rem; }
.usage-circle { width:120px; height:120px; border-radius:999px; border:6px solid rgba(255,255,255,0.1); display:flex; align-items:center; justify-content:center; margin:0 auto; position:relative; }
.usage-inner { color:#fff; font-weight:800; }
.usage-bar { width:100%; height:8px; background:#151515; border:1px solid rgba(255,255,255,0.06); border-radius:999px; overflow:hidden; }
.usage-bar-fill { height:100%; background:#10b981; width:0%; }
.s-stat strong { font-size:1.1rem; }

/* Responsive simple grid */
@media (min-width: 48em) { .simple-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 64em) { .simple-grid { grid-template-columns: 1fr 1fr 1fr; } }

/* Responsive dashboard layout */
@media (max-width: 767px) {
    .account-sidebar { position:fixed; left:-100%; top:0; height:100vh; z-index:999; padding:1rem; width:80vw; max-width:18rem; }
    .account-sidebar.open { left:0; }
    .account-main { padding: 1rem; }
    .account-header { 
        padding: 1rem 0 0 0; 
        margin-bottom: 1.5rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    .account-header .header-left {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    .account-hamburger { display:inline-flex; }
    .grid { gap: 1rem; }
    .card { padding: 1rem; }
    .grid.cols-3 { grid-template-columns: 1fr; }
    .grid.cols-2 { grid-template-columns: 1fr; }
    .user-chip { gap:.75rem; }
    /* Smaller, simpler title */
    .page-title-container {
        margin-left: 0;
        width: 100%;
    }
    .page-title { font-size: 1.5rem; margin: 0; }
    .page-subtitle { font-size: 0.75rem; }
    /* Hide user chip to avoid duplicate name on mobile */
    .header-right { display:none; }
    /* Mobile actions bar */
    .mobile-actions { position:sticky; top:0.25rem; z-index:10; display:flex !important; gap:0.5rem; justify-content:space-between; margin-bottom:0.75rem; }
    /* Add a bit more breathing room above the hero on mobile */
    .welcome-section { padding-top: 1.5rem; }
    /* Give logo and heading more vertical spacing */
    .welcome-icon { margin: 0 auto 1rem; }
    .welcome-title { margin-top: 0.25rem; padding: 0.25rem 0; line-height: 1.25; }
    .welcome-title + .welcome-subtitle { margin-top: 0.5rem; }
    .welcome-subtitle { margin-bottom: 1.75rem; }
}

@media (min-width: 48em) and (max-width: 63.999em) {
    .grid.cols-3 { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 64em) {
    .grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
    .account-main { max-width: 1200px; margin: 0 auto; }
}

@media (min-width: 90em) {
    .account-main { max-width: 1280px; }
}

.stat-row { display:grid; grid-template-columns: repeat(3,1fr); gap:0.75rem; }
.stat-label { color:#9ca3af; font-size:0.75rem; }
.stat-value { font-weight:800; }
.trial-row { display:flex; align-items:center; justify-content:space-between; padding:0.5rem; background: rgba(255,255,255,0.06); border:1px solid rgba(255,255,255,0.12); border-radius:0.5rem; margin-top:0.5rem; }

.usage-card { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    text-align: center;
}

.usage-circle { 
    width: 8rem; 
    height: 8rem; 
    border-radius: 50%; 
    background: conic-gradient(#15CC96 0deg 270deg, rgba(255, 255, 255, 0.1) 270deg 360deg); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    margin: 0 auto 1.5rem; 
    position: relative; 
    box-shadow: 0 8px 32px rgba(21, 204, 150, 0.2);
}

.usage-circle::before { 
    content: ''; 
    position: absolute; 
    width: 5.5rem; 
    height: 5.5rem; 
    background: rgba(15, 15, 15, 0.8); 
    backdrop-filter: blur(20px);
    border-radius: 50%; 
}

.usage-inner { 
    text-align: center; 
    position: relative;
    z-index: 1;
}

.usage-inner .big { 
    font-size: 2rem; 
    font-weight: 900; 
    background: linear-gradient(135deg, #fff, #15CC96);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.usage-inner .small { 
    color: #9ca3af; 
    font-size: 0.875rem; 
    font-weight: 500;
}

.usage-meta { 
    margin-top: 1rem; 
    color: #cbd5e1; 
    font-size: 0.875rem;
}

.usage-progress {
    width: 100%;
    height: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    overflow: hidden;
    margin: 1rem 0;
}

.usage-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #15CC96, #12B887);
    border-radius: 999px;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(21, 204, 150, 0.3);
}

.usage-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-label {
    color: #9ca3af;
    font-size: 0.75rem;
    font-weight: 500;
}

.stat-value {
    color: #fff;
    font-weight: 700;
    font-size: 1.125rem;
}

.analytics-grid { 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    gap: 1rem; 
    margin-bottom: 1.5rem; 
}

.a-item {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.a-label { 
    color: #9ca3af; 
    font-size: 0.75rem; 
    font-weight: 500;
    margin-bottom: 0.5rem;
    display: block;
}

.a-value { 
    font-weight: 800; 
    font-size: 1.25rem;
    color: #fff;
}

.timeline { 
    display: flex; 
    flex-direction: column; 
    gap: 0.75rem; 
}
.timeline-item { display:flex; align-items:center; gap:0.5rem; color:#cbd5e1; }
.timeline-item .t-dot { width:6px; height:6px; background:#15CC96; border-radius:999px; box-shadow:0 0 10px rgba(21,204,150,.6); }
.timeline-item .t-time { color:#9ca3af; font-size:0.75rem; }

.table-wrap { overflow:auto; }
.table { width:100%; border-collapse: collapse; }
.table th, .table td { padding:0.5rem; border-bottom:1px solid rgba(255,255,255,0.08); text-align:left; }

.settings-grid { display:flex; flex-direction:column; gap:0.75rem; }
.switch { display:flex; align-items:center; gap:0.5rem; color:#cbd5e1; }

/* Large Desktop (1440px+) */
@media (min-width: 90em) {
    .welcome-section {
        max-width: 72rem; /* 1152px container for 1440px */
    }
    
    .input-wrapper {
        max-width: 80%;
    }
    
    .chat-container {
        padding: 3rem;
    }
    
    .template-cards { gap: 1.5rem; grid-auto-rows: 1fr; }
    
    .welcome-logo {
        height: 5rem;
    }

    /* 1440px desktop refinement */
    .welcome-title {
        font-size: 2rem; /* keep at 2rem to prevent cutoffs on 1440 */
        line-height: 1.15;
        max-width: 100%;
    }
}

/* Ultra-wide (1920px+) */
@media (min-width: 120em) {
    .welcome-section {
        max-width: 80rem; /* 1280px container for 1920px */
    }
    
    .input-wrapper {
        max-width: 70%;
    }
    
    .sidebar {
        width: 22rem;
        max-width: 22rem;
    }

    /* 1920px desktop refinement */
    .welcome-title {
        font-size: 2rem; /* keep controlled to avoid overflow on ultrawide too */
        line-height: 1.12;
        max-width: 100%;
    }
}

/* ===========================================
   LANDSCAPE ORIENTATION OPTIMIZATIONS
   =========================================== */

/* iPhone SE Landscape (667px × 375px) */
@media (max-height: 23.4375em) and (orientation: landscape) {
    :root {
        --header-height: 2.5rem;
        --touch-target: 2.5rem;
    }
    
    .sidebar {
        width: 70vw;
        max-width: 16rem;
    }
    
    .chat-header {
        padding: 0.5rem 0.75rem;
        height: var(--header-height);
    }
    
    .chat-container {
        padding: 0.5rem;
    }
    
    .welcome-section {
        padding: 0.5rem;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        min-height: calc(100vh - var(--header-height) - 4rem);
    }
    
    .welcome-logo {
        height: 1.5rem;
        margin-bottom: 0.5rem;
    }
    
    .welcome-title {
        font-size: 1.125rem;
        margin-bottom: 0.375rem;
    }
    
    .welcome-subtitle {
        font-size: 0.75rem;
        margin-bottom: 0.75rem;
        line-height: 1.2;
    }
    
    .template-cards {
        gap: 0.5rem;
        grid-template-columns: repeat(3, 1fr);
        max-width: 100%;
    }
    
    .template-card {
        padding: 0.625rem;
        min-height: 4rem;
    }
    
    .card-icon {
        width: 1.5rem;
        height: 1.5rem;
        font-size: 0.75rem;
        margin-bottom: 0.25rem;
    }
    
    .card-title {
        font-size: 0.6875rem;
        margin-bottom: 0.25rem;
    }
    
    .card-description {
        font-size: 0.625rem;
        line-height: 1.1;
    }
    
    .input-container {
        padding: 0.5rem;
    }
    
    .input-wrapper {
        padding: 0.5rem 0.75rem;
        border-radius: 1rem;
    }
    
    .hamburger-btn {
        width: var(--touch-target);
        height: var(--touch-target);
        padding: 0.25rem;
    }
    
    .hamburger-icon {
        font-size: 1.125rem;
    }
}

/* iPhone 6/7/8 Landscape (667px × 375px) */
@media (min-height: 23.4375em) and (max-height: 25.9375em) and (orientation: landscape) {
    :root {
        --header-height: 2.75rem;
        --touch-target: 2.625rem;
    }
    
    .sidebar {
        width: 68vw;
        max-width: 18rem;
    }
    
    .chat-header {
        padding: 0.625rem 0.875rem;
        height: var(--header-height);
    }
    
    .chat-container {
        padding: 0.625rem;
    }
    
    .welcome-section {
        padding: 0.625rem;
        min-height: calc(100vh - var(--header-height) - 4.5rem);
    }
    
    .welcome-logo {
        height: 1.75rem;
        margin-bottom: 0.625rem;
    }
    
    .welcome-title {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
    }
    
    .welcome-subtitle {
        font-size: 0.8125rem;
        margin-bottom: 1rem;
    }
    
    .template-cards {
        gap: 0.625rem;
        grid-template-columns: repeat(3, 1fr);
    }
    
    .template-card {
        padding: 0.75rem;
        min-height: 4.5rem;
    }
    
    .card-icon {
        width: 1.75rem;
        height: 1.75rem;
        font-size: 0.875rem;
        margin-bottom: 0.375rem;
    }
    
    .card-title {
        font-size: 0.75rem;
        margin-bottom: 0.25rem;
    }
    
    .card-description {
        font-size: 0.6875rem;
    }
}

/* iPhone 6/7/8 Plus Landscape (736px × 414px) */
@media (min-height: 25.875em) and (max-height: 27.5em) and (orientation: landscape) {
    :root {
        --header-height: 3rem;
        --touch-target: 2.75rem;
    }
    
    .sidebar {
        width: 65vw;
        max-width: 20rem;
    }
    
    .chat-header {
        padding: 0.75rem 1rem;
        height: var(--header-height);
    }
    
    .chat-container {
        padding: 0.75rem;
    }
    
    .welcome-section {
        padding: 0.75rem;
        min-height: calc(100vh - var(--header-height) - 5rem);
    }
    
    .welcome-logo {
        height: 2rem;
        margin-bottom: 0.75rem;
    }
    
    .welcome-title {
        font-size: 1.375rem;
        margin-bottom: 0.625rem;
    }
    
    .welcome-subtitle {
        font-size: 0.875rem;
        margin-bottom: 1.25rem;
    }
    
    .template-cards {
        gap: 0.75rem;
        grid-template-columns: repeat(3, 1fr);
    }
    
    .template-card {
        padding: 0.875rem;
        min-height: 5rem;
    }
    
    .card-icon {
        width: 2rem;
        height: 2rem;
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .card-title {
        font-size: 0.8125rem;
        margin-bottom: 0.375rem;
    }
    
    .card-description {
        font-size: 0.75rem;
    }
}

/* iPhone X/XS and newer Landscape (812px+ × 375px+) */
@media (min-height: 50.75em) and (orientation: landscape) {
    :root {
        --header-height: 3.25rem;
        --touch-target: 2.875rem;
    }
    
    .sidebar {
        width: 60vw;
        max-width: 22rem;
        /* Safe area adjustments for landscape with notch */
        padding-left: calc(var(--safe-area-inset-left) + 0.5rem);
    }
    
    .chat-header {
        padding: 0.875rem 1.125rem;
        height: var(--header-height);
        /* Safe area adjustments for landscape */
        padding-left: calc(1.125rem + var(--safe-area-inset-left));
        padding-right: calc(1.125rem + var(--safe-area-inset-right));
    }
    
    .chat-container {
        padding: 0.875rem;
        padding-left: calc(0.875rem + var(--safe-area-inset-left));
        padding-right: calc(0.875rem + var(--safe-area-inset-right));
    }
    
    .welcome-section {
        padding: 0.875rem;
        min-height: calc(100vh - var(--header-height) - 5.5rem);
    }
    
    .welcome-logo {
        height: 2.25rem;
        margin-bottom: 0.875rem;
    }
    
    .welcome-title {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }
    
    .welcome-subtitle {
        font-size: 0.9375rem;
        margin-bottom: 1.5rem;
    }
    
    .template-cards {
        gap: 0.875rem;
        grid-template-columns: repeat(3, 1fr);
        max-width: 100%;
    }
    
    .template-card {
        padding: 1rem;
        min-height: 5.5rem;
    }
    
    .card-icon {
        width: 2.125rem;
        height: 2.125rem;
        font-size: 1.0625rem;
        margin-bottom: 0.5rem;
    }
    
    .card-title {
        font-size: 0.875rem;
        margin-bottom: 0.375rem;
    }
    
    .card-description {
        font-size: 0.75rem;
    }
    
    .input-container {
        padding: 0.875rem;
        /* Safe area adjustments for landscape */
        padding-left: calc(0.875rem + var(--safe-area-inset-left));
        padding-right: calc(0.875rem + var(--safe-area-inset-right));
        padding-bottom: calc(0.875rem + var(--safe-area-inset-bottom));
    }
    
    .input-wrapper {
        padding: 0.75rem 1.125rem;
    }
}

/* Ultra-wide Landscape (Pro Max models in landscape) */
@media (min-height: 57.875em) and (orientation: landscape) {
    .sidebar {
        width: 55vw;
        max-width: 24rem;
    }
    
    .template-cards {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .welcome-section {
        max-width: 90%;
        margin: 0 auto;
    }
}

/* ===========================================
   ACCESSIBILITY & PERFORMANCE
   =========================================== */

/* Ensure all interactive elements meet touch target requirements */
@media (pointer: coarse) {
    .action-btn,
    .hamburger-btn,
    .back-btn,
    .header-btn,
    .input-btn,
    .send-btn,
    .new-chat-button,
    .chat-item,
    .template-card {
        min-width: var(--touch-target);
        min-height: var(--touch-target);
    }
    
    /* Larger touch targets for larger devices */
    @media (min-width: 26.875em) {
        .action-btn,
        .hamburger-btn,
        .back-btn,
        .header-btn,
        .input-btn,
        .send-btn,
        .new-chat-button {
            min-width: var(--touch-target-large);
            min-height: var(--touch-target-large);
        }
    }
    
    /* Smaller touch targets for compact devices */
    @media (max-width: 22.5em) {
        .action-btn,
        .hamburger-btn,
        .back-btn,
        .header-btn,
        .input-btn,
        .send-btn {
            min-width: var(--touch-target-small);
            min-height: var(--touch-target-small);
        }
    }
}

/* Focus management for accessibility */
.action-btn:focus,
.hamburger-btn:focus,
.back-btn:focus,
.header-btn:focus,
.input-btn:focus,
.send-btn:focus,
.new-chat-button:focus,
.chat-item:focus,
.template-card:focus,
.search-input:focus,
.chat-input:focus {
    outline: 2px solid #15CC96;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .sidebar {
        border-right: 2px solid #ffffff;
    }
    
    .chat-header {
        border-bottom: 2px solid #ffffff;
    }
    
    .input-container {
        border-top: 2px solid #ffffff;
    }
    
    .template-card {
        border: 2px solid #ffffff;
    }
    
    .input-wrapper {
        border: 2px solid #ffffff;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .template-card:hover,
    .chat-item:hover,
    .action-btn:hover {
        transform: none !important;
    }
}

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .amz-logo,
    .welcome-logo,
    .footer-logo {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Voice recording functionality removed - microphone feature no longer used */

/* Voice permission modal removed - microphone feature no longer used */


/* ===========================================
   MODERN TYPING FEATURES & BEST PRACTICES
   =========================================== */

/* Character count display */
.character-count {
    position: absolute;
    bottom: -1.5rem;
    right: 0;
    font-size: 0.6875rem;
    font-weight: 500;
    display: none;
    opacity: 0.8;
    transition: all 0.2s ease;
}

/* Auto-resizing input */
.chat-input {
    resize: none;
    transition: height 0.2s ease;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
}

/* Smart button handles both voice and send functionality */

/* Voice/Send dual mode button */
.input-btn[data-mode="send"] {
    background: linear-gradient(135deg, #15CC96, #12B887) !important;
    color: #ffffff !important;
    transition: all 0.3s ease;
}

.input-btn[data-mode="voice"] {
    background: transparent;
    color: #9ca3af;
    transition: all 0.3s ease;
}

/* Typing indicator animation */
@keyframes typingDots {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: #9ca3af;
    padding: 0.5rem;
}

.typing-indicator .dot {
    width: 4px;
    height: 4px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typingDots 1.4s infinite ease-in-out;
}

/* Three-dot typing bubble used in script.js */
.typing-dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    display: inline-block;
    animation: typingDots 1s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

.typing-indicator .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator .dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* Input validation states */
.input-wrapper.error {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.input-wrapper.warning {
    border-color: #f59e0b !important;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

/* Modern focus states */
.chat-input:focus {
    outline: none;
}

.input-wrapper:focus-within {
    border-color: rgba(21, 204, 150, 0.6);
    box-shadow: 0 0 0 2px rgba(21, 204, 150, 0.2);
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .input-btn,
    .chat-input {
        transition: none !important;
    }
    
    .typing-indicator .dot {
        animation: none;
    }
}

/* High contrast mode improvements */
@media (prefers-contrast: high) {
    .input-wrapper {
        border-width: 2px;
    }
    
    .character-count {
        font-weight: 700;
    }
}

/* Mobile-specific improvements */
@media (max-width: 768px) {
    .character-count {
        font-size: 0.625rem;
        bottom: -1.25rem;
    }
    
    .chat-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

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

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: rgba(21, 204, 150, 0.5);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(21, 204, 150, 0.7);
}

/* ===========================================
   MOBILE HEADER RESPONSIVENESS FIXES
   =========================================== */

/* Mobile header: hide plan text, keep Upgrade visible */
@media (max-width: 767px) {

    /* Keep the header container so Upgrade stays visible */
    .chat-title-header {
        display: flex !important;
        align-items: center;
        gap: 0.5rem;
        margin-left: auto; /* push actions to the right on mobile */
    }

    /* Ensure Upgrade button is visible and touch-friendly */
    .chat-header .upgrade-btn {
        display: inline-flex !important;
        align-items: center;
        padding: 0.5rem 0.875rem;
        min-height: var(--touch-target);
        line-height: 1;
    }

    /* Auth buttons spacing and touch targets - margin controlled by JavaScript */
    .header-auth {
        gap: 0.375rem;
        /* margin-left is set by JavaScript */
    }
    
    .auth-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
        min-width: var(--touch-target);
        min-height: var(--touch-target);
    }
    
    /* Account dropdown positioning - all controlled by JavaScript */
    #headerUser {
        position: relative;
    }
    
    /* Compact, clickable header spacing */
    .chat-header {
        padding: 0.75rem 1rem;
        gap: 0.75rem;
        justify-content: space-between;
    }
    
    /* Hide back control on phones (hamburger replaces it) */
    .back-btn { display: none !important; }
}

/* Tablet and larger */
@media (min-width: 768px) {
    
    .chat-title-header {
        display: flex;
        align-items: center;
        gap: 1rem;
    }
    /* Hide back control on tablets/desktops */
    .back-btn { display: none !important; }
    
    /* On desktop, allow JavaScript to control headerUser visibility */
    /* No CSS override needed - JavaScript sets inline style which has highest priority */
}

/* Mobile-specific hamburger sizing */
@media (max-width: 767px) {
    .hamburger-btn {
        width: 2.5rem;
        height: 2.5rem;
        padding: 0.375rem;
    }
    
    .hamburger-icon {
        font-size: 1.25rem;
    }
    
    /* Mobile sidebar improvements */
    .nav-section {
        padding: 0 1rem;
        margin-bottom: 1rem;
    }
    
    .nav-item {
        padding: 0.5rem 0.625rem;
        font-size: 0.8125rem;
        min-height: 2.5rem;
    }
    
    .nav-item i {
        font-size: 0.875rem;
        width: 1rem;
    }
    
    .nav-item span {
        font-size: 0.8125rem;
    }
    
    .chats-section {
        padding: 0 1rem;
        margin-bottom: 1rem;
    }
    
    .chat-item {
        padding: 0.5rem 0.625rem;
        min-height: 2.5rem;
    }
    
    .chat-title {
        font-size: 0.8125rem;
    }
    
    .chat-preview {
        font-size: 0.75rem;
    }
}

/* Authentication Modal Styles */
.auth-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
}

.auth-modal {
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.auth-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.auth-header h2 {
    color: #ffffff;
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.auth-close {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.auth-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    color: #e5e7eb;
    font-size: 0.875rem;
    font-weight: 500;
}

.form-group input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.75rem;
    color: #ffffff;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: #15CC96;
    box-shadow: 0 0 0 3px rgba(21, 204, 150, 0.1);
}

.form-group input::placeholder {
    color: #6b7280;
}

.auth-submit-btn {
    background: linear-gradient(135deg, #15CC96, #10b981);
    border: none;
    border-radius: 8px;
    color: #ffffff;
    font-size: 1rem;
    font-weight: 600;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 0.5rem;
}

.auth-submit-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(21, 204, 150, 0.3);
}

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

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.auth-footer p {
    color: #9ca3af;
    font-size: 0.875rem;
    margin: 0;
}

.auth-switch {
    color: #15CC96;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.auth-switch:hover {
    color: #19d1a0;
}

.auth-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    color: #fca5a5;
    padding: 0.75rem;
    font-size: 0.875rem;
    margin-top: 1rem;
    text-align: center;
}

/* Mobile styles for auth modal */
@media (max-width: 480px) {
    .auth-modal {
        padding: 1.5rem;
        margin: 0.5rem;
    }
    
    .auth-header h2 {
        font-size: 1.25rem;
    }
}

/* Enhanced responsive auth styles */
@media (max-width: 768px) {
    .auth-container {
        width: 95vw;
        margin: 5vh auto;
        padding: 1.5rem 1rem;
    }
    
    .auth-header {
        margin-bottom: 1rem;
    }
    
    .auth-tabs {
        padding: 0.2rem;
    }
    
    .auth-tab {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
    
    .auth-title {
        font-size: 1.5rem;
        margin: 0.5rem 0 1rem;
    }
    
    .auth-form {
        gap: 1rem;
    }
    
    .auth-input {
        padding: 0.75rem;
        font-size: 1rem;
    }
    
    .auth-primary {
        padding: 0.875rem;
        font-size: 1rem;
    }
    
}

@media (max-width: 480px) {
    .auth-container {
        width: 98vw;
        margin: 2vh auto;
        padding: 1rem 0.75rem;
        border-radius: 0.75rem;
        max-height: 95vh;
        overflow-y: auto;
    }
    
    .auth-header {
        padding: 0.5rem 0;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .auth-close {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1rem;
    }
    
    .auth-tabs {
        width: 100%;
        justify-content: center;
        order: 2;
    }
    
    .auth-tab {
        flex: 1;
        text-align: center;
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
        min-height: 2.5rem;
    }
    
    .auth-title {
        font-size: 1.25rem;
        text-align: center;
        margin: 0.5rem 0 1rem;
    }
    
    .auth-form {
        gap: 0.875rem;
    }
    
    .auth-input {
        padding: 0.75rem;
        font-size: 1rem;
        min-height: 2.75rem;
        border-radius: 0.625rem;
    }
    
    .auth-primary {
        padding: 0.875rem;
        font-size: 1rem;
        min-height: 3rem;
        border-radius: 0.75rem;
    }
    
    
    .auth-check {
        font-size: 0.8rem;
        line-height: 1.4;
        margin-top: 0.5rem;
    }
    
    .auth-check input[type="checkbox"] {
        width: 1.25rem;
        height: 1.25rem;
        margin-right: 0.5rem;
    }
    
    .auth-switch {
        font-size: 0.8rem;
        margin-top: 0.75rem;
    }
    
    .auth-link {
        font-size: 0.8rem;
    }
    
}

/* Extra small devices (320px and below) */
@media (max-width: 320px) {
    .auth-container {
        width: 100vw;
        margin: 1vh auto;
        padding: 0.75rem 0.5rem;
        border-radius: 0.5rem;
    }
    
    .auth-tab {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
    }
    
    .auth-title {
        font-size: 1.1rem;
    }
    
    .auth-input {
        padding: 0.625rem;
        font-size: 0.9rem;
    }
    
    .auth-primary {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
    
}

/* AI Chat Messages */
.ai-message {
    display: flex;
    margin-bottom: 1rem;
    animation: fadeInUp 0.3s ease-out;
    justify-content: flex-start;
    padding: 0;
    position: relative;
    width: 100%;
    max-width: 100%;
}

.ai-message .message-content {
    display: flex;
    align-items: flex-start;
    max-width: 80%;
    margin-left: 1rem;
    margin-right: auto;
    position: relative;
}

.ai-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--accent-green);
    color: #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.ai-message .message-text {
    background: transparent;
    border-left: none;
    border-radius: 0;
    padding: 0.75rem 0 0.75rem 0;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: 16px;
    line-height: 1.5;
    font-weight: 400;
    word-wrap: break-word;
    position: relative;
    padding-bottom: 0.25rem; /* Space for copy icon */
    padding-right: 2.25rem; /* Prevent overlap with copy icon */
}

/* Copy Button for AI Messages - Bottom Right Corner */
.ai-message .message-content {
    position: relative;
    padding-bottom: 0.5rem; /* Space for copy icon at bottom */
}

.ai-message .copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 0.25rem 0.375rem;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
    opacity: 0.7;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    z-index: 10;
}

.ai-message .message-content:hover .copy-btn {
    opacity: 1;
    color: rgba(255, 255, 255, 1);
}

.ai-message .copy-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
    opacity: 1;
}

.ai-message .copy-btn.copied {
    color: var(--accent-green);
    opacity: 1;
}

.message-text {
    background: transparent;
    border-left: none;
    padding: 0.75rem 0;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: 16px;
    line-height: 1.5;
    font-weight: 400;
    word-wrap: break-word;
}

/* Loading State */
.ai-message.loading .message-content {
    align-items: center;
}

.typing-indicator {
    display: flex;
    gap: 0.25rem;
    margin-right: 0.5rem;
}

.typing-indicator span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: #15CC96;
    animation: typing 1.4s infinite ease-in-out;
}

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

.loading-text {
    color: #9ca3af;
    font-size: 0.875rem;
    font-style: italic;
}

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

/* Chat item styles */
.chat-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.chat-item.active {
    background: rgba(21, 204, 150, 0.1);
    border: 1px solid rgba(21, 204, 150, 0.2);
}

.chat-content {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
}

/* No chats state */
.no-chats-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    text-align: center;
}

.no-chats-text {
    color: #9ca3af;
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: #ffffff;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-preview {
    font-size: 0.75rem;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-item:hover .chat-actions {
    opacity: 1;
}

.chat-delete {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

/* User message styles */
.user-message {
    display: flex;
    margin-bottom: 1rem;
    animation: fadeInUp 0.3s ease-out;
    justify-content: flex-end;
    padding: 0;
    width: 100%;
    max-width: 100%;
}

.user-message .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-width: 80%;
    margin-left: auto;
    margin-right: 1rem;
}

.user-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--accent-green);
    color: #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.user-message .message-text {
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: 1rem 1rem 0.25rem 1rem;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: 16px;
    line-height: 1.5;
    font-weight: 400;
    word-wrap: break-word;
    margin-bottom: 0;
    width: 100%;
}

.user-message .message-text:has(+ .message-images) {
    border-radius: 1rem 1rem 0 0;
    margin-bottom: 0;
    border-bottom: none;
}

.user-message .message-text:last-child:not(:has(+ .message-files)):not(:has(+ .message-images)) {
    margin-bottom: 0;
}

/* File preview in input area */
/* File preview container - appears above textarea (like ChatGPT) */
.file-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 0 0.5rem 0;
    margin: 0;
    flex-shrink: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    /* Positioned at top of input-wrapper, above textarea */
    animation: slideDown 0.2s ease;
}

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

.file-preview-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.5rem;
    padding: 0.5rem;
    position: relative;
    max-width: 200px;
}

.file-preview-thumbnail {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.375rem;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.file-preview-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-preview-thumbnail i {
    font-size: 1.25rem;
    color: var(--text-secondary);
}

.file-preview-info {
    flex: 1;
    min-width: 0;
}

.file-preview-name {
    font-size: 0.75rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.125rem;
}

.file-preview-size {
    font-size: 0.625rem;
    color: var(--text-secondary);
}

.file-preview-status {
    margin-top: 0.35rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.file-preview-status.uploaded .status-text {
    color: var(--accent-green);
}

.file-preview-status.error .status-text {
    color: #ef4444;
}

.file-preview-progress {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    overflow: hidden;
}

.file-preview-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-green);
    transition: width 0.3s ease;
}

.file-preview-status.uploading .file-preview-progress-fill {
    background: rgba(21, 204, 150, 0.6);
}

.file-preview-status.error .file-preview-progress-fill {
    background: rgba(239, 68, 68, 0.7);
}

.file-preview-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    width: 1.25rem;
    height: 1.25rem;
}

.file-preview-remove:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* Image preview in input area */
.image-preview-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
}

.image-preview-item:hover {
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.image-preview-item.error {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.image-preview-thumbnail {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    background: rgba(255, 255, 255, 0.05);
}

.image-preview-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    padding: 0.5rem;
    color: #ef4444;
    font-size: 0.75rem;
    text-align: center;
    gap: 0.25rem;
}

.image-preview-error i {
    font-size: 1.25rem;
}

.image-preview-remove {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: all 0.2s ease;
    z-index: 10;
}

.image-preview-remove:hover {
    background: rgba(239, 68, 68, 0.9);
    transform: scale(1.1);
}

.image-preview-remove:focus {
    outline: 2px solid #15CC96;
    outline-offset: 2px;
}

/* Drag over state */
.input-wrapper.drag-over {
    border-color: var(--accent-green);
    background: rgba(34, 197, 94, 0.05);
}

/* Images in user messages */
.user-message .message-images {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-top: 0;
    width: 100%;
}

.user-message .message-image-item {
    overflow: hidden;
    max-width: min(100%, 600px);
    border: 1px solid var(--border-default);
    border-top: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    background: var(--bg-input);
}

.user-message .message-image-item:first-child {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.user-message .message-image-item:last-child {
    border-bottom-left-radius: 0.25rem;
    border-bottom-right-radius: 1rem;
}

.user-message .message-image-item:only-child {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-bottom-left-radius: 0.25rem;
    border-bottom-right-radius: 1rem;
}

/* When images are alone (no text), give them full bubble styling */
.user-message .message-content:has(.message-images):not(:has(.message-text)) .message-image-item:first-child {
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
}

.user-message .message-content:has(.message-images):not(:has(.message-text)) .message-image-item:last-child {
    border-bottom-left-radius: 1rem;
    border-bottom-right-radius: 1rem;
}

.user-message .message-image {
    width: 100%;
    height: auto;
    display: block;
    max-height: 400px;
    object-fit: contain;
    border-radius: 0;
}

.user-message .message-image-item:first-child .message-image {
    border-top-left-radius: 0;
}

.user-message .message-image-item:last-child .message-image {
    border-bottom-right-radius: 1rem;
}

.ai-message .message-images {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0.5rem 0 0 1rem;
    max-width: min(100%, 520px);
}

.ai-message .message-image-item {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.75rem;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.02);
}

.ai-message .message-image {
    display: block;
    width: 100%;
    height: auto;
    max-height: 360px;
    object-fit: contain;
}

/* Files in messages */
.message-files {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.message-file-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.5rem;
    padding: 0.75rem;
    max-width: 100%;
}

.message-file-image {
    width: 4rem;
    height: 4rem;
    border-radius: 0.5rem;
    object-fit: cover;
    flex-shrink: 0;
}

.message-file-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-file-icon i {
    font-size: 1.5rem;
    color: var(--accent-green);
}

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

.message-file-name {
    font-size: 0.875rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

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

/* User message files */
.user-message .message-files {
    margin-top: 0.5rem;
}

.user-message .message-file-item {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(1rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Ensure account dropdown works on mobile */
@media (max-width: 767px) {
    /* Position controlled by JavaScript */
    #headerAuth,
    #headerUser {
        position: relative;
    }
    
    /* Make sure dropdowns are touch-friendly */
    .header-auth select,
    .header-auth .auth-btn {
        min-height: var(--touch-target);
        font-size: 0.875rem;
        display: none;
    }
}

/* ===========================================
   SAFARI MOBILE SPECIFIC FIXES
   =========================================== */
/* Ensure New Chat button is always visible above Safari's bottom bar */
@supports (padding: max(0px)) {
    .new-chat-btn {
        /* Use max() for better browser support */
        padding-bottom: max(calc(1.25rem + var(--safe-area-inset-bottom)), 2rem);
    }
}

/* Safari mobile specific adjustments */
@supports (-webkit-touch-callout: none) {
    .new-chat-btn {
        /* Additional padding for Safari mobile */
        padding-bottom: calc(1.25rem + var(--safe-area-inset-bottom) + 0.5rem);
    }
}