@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --surface-light: #f7f8fa;
    --surface-muted: #eef1f5;
    --surface-card: #ffffff;
    --surface-dark: #0D1426;
    --surface-dark-mid: #14263F;
    --surface-dark-elevated: #1a2d45;
    /* iOS App Colors - Exact match */
    --brand-accent: #3399F2;
    --brand-accent-deep: #2673CC;
    --brand-gold: #FF9933;
    --brand-star-blue: #80BFFF;
    --brand-twilight: #408CE6;
    --brand-accent-soft: rgba(51, 153, 242, 0.12);
    --brand-glow: rgba(51, 153, 242, 0.25);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-inverse: #e2e8f0;
    --border-strong: rgba(15, 23, 42, 0.12);
    --border-soft: rgba(148, 163, 184, 0.25);
    --shadow-soft: 0 16px 40px -24px rgba(51, 153, 242, 0.4);
    --shadow-card: 0 18px 65px -32px rgba(51, 153, 242, 0.15);
    --radius-lg: 24px;
    --radius-md: 18px;
    --radius-sm: 12px;
    --transition: all 0.2s ease;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    scroll-behavior: smooth;
    /* iOS Safari viewport fix */
    height: 100%;
}

@supports (-webkit-touch-callout: none) {
    html {
        height: -webkit-fill-available;
    }
    
    body {
        min-height: -webkit-fill-available;
    }
}

/* Global Navigation Tabs */
.nav-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark .nav-tabs {
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.tab-link {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: white;
    opacity: 0.7;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.tab-link.active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

.tab-link:hover {
    opacity: 0.9;
    background: rgba(255, 255, 255, 0.15);
}

body {
    margin: 0;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--surface-dark) 0%, var(--surface-dark-mid) 50%, var(--surface-dark) 100%);
    color: white;
}

body.dark {
    background: linear-gradient(135deg, var(--surface-dark) 0%, var(--surface-dark-mid) 50%, var(--surface-dark) 100%);
    color: var(--text-inverse);
}

.app-shell {
    width: min(1200px, 100%);
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

@supports (min-height: 100dvh) {
    .app-shell {
        min-height: 100dvh;
    }
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.6rem 2rem 1.2rem;
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(16px);
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark .app-header {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--brand-accent), var(--brand-accent-deep));
    display: grid;
    place-items: center;
    color: white;
    font-weight: 700;
    letter-spacing: 0.04em;
    box-shadow: 0 10px 30px -18px rgba(51, 153, 242, 0.9);
}

.brand-copy h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
}

.brand-copy p {
    margin: 0.15rem 0 0;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
}

body.dark .brand-copy p {
    color: rgba(255, 255, 255, 0.8);
}

.header-toolbar {
    gap: 0.75rem;
}

.model-selection {
    position: relative;
}

.model-dropdown {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    color: white;
    transition: var(--transition);
}

.model-dropdown:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

body.dark .model-dropdown {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: white;
}

.header-icon-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.auth-controls {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding-left: 0.6rem;
    border-left: 1px solid var(--border-soft);
}

.auth-status {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.85);
}

body.dark .auth-status {
    color: rgba(255, 255, 255, 0.85);
}

.auth-button {
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.15);
    color: white;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    transition: var(--transition);
    cursor: pointer;
}

.auth-button:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

body.dark .auth-button {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

body.dark .auth-button:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.icon-button {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    transition: var(--transition);
}

.icon-button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

body.dark .icon-button {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

body.dark .icon-button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.mobile-toolbar-toggle {
    display: none;
    margin-left: auto;
}

.mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 8;
}

body.dark .mobile-overlay {
    background: rgba(2, 6, 19, 0.55);
}

.mobile-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 2rem 2rem;
}

.chat-scroll-container {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    overflow: hidden;
    position: relative;
}

body.dark .chat-scroll-container {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}

.chat-message-list {
    height: 100%;
    overflow-y: auto;
    padding: 1.8rem 2rem 6rem;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

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

.chat-message-list::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.45);
    border-radius: 999px;
}

body.dark .chat-message-list::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.25);
}

.empty-state {
    text-align: center;
    margin: 7rem auto;
    max-width: 480px;
    color: white;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    display: grid;
    place-items: center;
    font-size: 1.6rem;
    margin: 0 auto;
    color: var(--brand-accent);
}

.empty-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    text-align: center;
}

.empty-hero h2 {
    color: white;
}

.empty-hero p {
    max-width: 520px;
    color: rgba(255, 255, 255, 0.85);
    margin: 0;
}

body.dark .empty-hero p {
    color: rgba(255, 255, 255, 0.85);
}

.prompt-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-top: 2rem;
    width: 100%;
}

.prompt-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    padding: 1.1rem 1.1rem 1.15rem;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    text-align: left;
    color: white;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.prompt-card h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: white;
}

.prompt-card p {
    margin: 0;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
}

.prompt-card:hover,
.prompt-card:focus-visible {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px 0 rgba(31, 38, 135, 0.5);
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.15);
    outline: none;
}

body.dark .prompt-card {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

body.dark .prompt-card h3 {
    color: white;
}

body.dark .prompt-card p {
    color: rgba(255, 255, 255, 0.8);
}

.message {
    margin-bottom: 1.4rem;
    display: flex;
    gap: 0.9rem;
}

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

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

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    color: white;
    flex-shrink: 0;
    font-size: 0.9rem;
}

.message.user-message .message-avatar {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

.message.assistant-message .message-avatar {
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
}

.message-card {
    max-width: min(640px, 100%);
    background: var(--surface-card);
    border-radius: 20px;
    padding: 1rem 1.25rem;
    box-shadow: 0 8px 30px -24px rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(15, 23, 42, 0.05);
    transition: var(--transition);
}

body.dark .message-card {
    background: rgba(15, 23, 42, 0.75);
    border-color: rgba(148, 163, 184, 0.18);
}

.message-card:hover {
    transform: translateY(-2px);
}

.message-header {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}

.message-header .name {
    font-weight: 600;
    font-size: 0.95rem;
}

.message-header .timestamp {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

body.dark .message-header .timestamp {
    color: rgba(226, 232, 240, 0.55);
}

.message-content {
    color: var(--text-primary);
    line-height: 1.6;
    word-break: break-word;
}

body.dark .message-content {
    color: rgba(226, 232, 240, 0.95);
}

.message-content p { margin: 0.6rem 0; }

.message-content pre {
    background: rgba(15, 23, 42, 0.88);
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 14px;
    overflow-x: auto;
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.message-content pre code { font-size: 0.85rem; }

.message-content code {
    background: rgba(15, 23, 42, 0.08);
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
    font-size: 0.85rem;
}

body.dark .message-content code {
    background: rgba(148, 163, 184, 0.2);
}

.message-content ul,
.message-content ol {
    padding-left: 1.2rem;
    margin: 0.6rem 0;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.9rem;
}

.message-content th,
.message-content td {
    border: 1px solid rgba(148, 163, 184, 0.25);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

body.dark .message-content th,
body.dark .message-content td {
    border-color: rgba(148, 163, 184, 0.2);
}

.message-content a {
    color: var(--brand-accent);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.typing-indicator {
    display: inline-flex;
    gap: 0.4rem;
    padding: 0.5rem 0.8rem;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--brand-accent);
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 1.4s infinite;
}

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

.assistant-thinking {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    color: var(--text-secondary);
}

.assistant-thinking .thinking-label {
    font-size: 0.8rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: inherit;
}

.assistant-thinking .thinking-label i {
    color: var(--brand-accent);
}

.assistant-thinking .typing-indicator {
    padding: 0;
    gap: 0.3rem;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.55; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.search-indicator {
    border-left: 3px solid var(--brand-accent);
}

.search-progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(148, 163, 184, 0.25);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.search-progress-inner {
    width: 40%;
    height: 100%;
    background: linear-gradient(90deg, var(--brand-accent), #0ea5e9);
    animation: searchPulse 1.4s ease-in-out infinite;
}

.search-indicator.search-complete .search-progress-inner,
.search-indicator.search-error .search-progress-inner {
    animation: none;
    transform: translateX(0);
}

.search-indicator.search-error .search-progress-inner {
    background: linear-gradient(90deg, #ef4444, #f97316);
}

.search-indicator .search-status {
    color: var(--text-secondary);
}

body.dark .search-indicator .search-status {
    color: rgba(226, 232, 240, 0.75);
}

.search-indicator .search-results {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.search-result-item {
    padding: 0.55rem 0.65rem;
    border-radius: 12px;
    background: rgba(148, 163, 184, 0.16);
}

body.dark .search-result-item {
    background: rgba(30, 41, 59, 0.6);
}

.search-result-title a {
    color: var(--brand-accent);
    font-weight: 600;
    text-decoration: none;
}

.search-result-title a:hover {
    text-decoration: underline;
}

.search-result-snippet {
    font-size: 0.82rem;
    margin-top: 0.35rem;
    color: var(--text-secondary);
}

body.dark .search-result-snippet {
    color: rgba(226, 232, 240, 0.75);
}

.search-result-source {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 0.2rem;
    color: rgba(15, 23, 42, 0.55);
}

body.dark .search-result-source {
    color: rgba(148, 163, 184, 0.7);
}

@keyframes searchPulse {
    0%, 100% { transform: translateX(-100%); }
    50% { transform: translateX(150%); }
}


.app-footer {
    margin-top: auto;
    position: sticky;
    bottom: 0;
    padding: 1.4rem 2rem calc(1.4rem + var(--safe-bottom));
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10;
}

body.dark .app-footer {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.composer-hint {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 0.5rem;
}

body.dark .composer-hint {
    color: rgba(255, 255, 255, 0.5);
}

.composer {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}

body.dark .composer {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}

.composer-plus {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: none;
    background: rgba(37, 99, 235, 0.12);
    color: var(--brand-accent);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.18s ease;
}

.composer-plus:hover,
.composer-plus:focus-visible {
    background: rgba(37, 99, 235, 0.2);
    transform: translateY(-1px);
    outline: none;
}

body.dark .composer-plus {
    background: rgba(37, 99, 235, 0.18);
    color: rgba(219, 234, 254, 0.92);
}

.composer-input {
    flex: 1;
    display: flex;
    align-items: center;
}

.composer-textarea {
    width: 100%;
    resize: none;
    border: none;
    background: transparent;
    color: white;
    font-size: 1rem;
    line-height: 1.5;
    max-height: 180px;
    padding: 0.25rem 0;
}

.composer-textarea::placeholder {
    color: rgba(255, 255, 255, 0.6);
    opacity: 1;
}

body.dark .composer-textarea::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.composer-textarea:focus { outline: none; }

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--brand-accent), #4f46e5);
    border: none;
    display: grid;
    place-items: center;
    color: white;
    font-size: 1rem;
    transition: transform 0.18s ease;
}

.send-button:hover {
    transform: translateY(-1px) scale(1.02);
}

.send-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.composer-extras {
    position: absolute;
    bottom: calc(100% + 0.65rem);
    left: 0;
    display: grid;
    gap: 0.5rem;
    padding: 0.75rem;
    border-radius: 18px;
    background: rgba(248, 250, 252, 0.98);
    border: 1px solid rgba(148, 163, 184, 0.25);
    box-shadow: 0 20px 45px -26px rgba(15, 23, 42, 0.45);
    min-width: 260px;
    max-width: min(320px, 82vw);
    z-index: 40;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.2s ease;
}

.composer-extras.is-open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

body.dark .composer-extras {
    background: rgba(15, 23, 42, 0.95);
    border-color: rgba(148, 163, 184, 0.22);
    box-shadow: 0 18px 40px -24px rgba(2, 6, 23, 0.8);
}

.composer-extra-button {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 0.8rem;
    border-radius: 14px;
    border: none;
    background: transparent;
    color: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}

.composer-extra-button i {
    width: 1.1rem;
    text-align: center;
    color: var(--brand-accent);
}

.composer-extra-button:hover,
.composer-extra-button:focus-visible {
    background: rgba(37, 99, 235, 0.12);
    outline: none;
}

body.dark .composer-extra-button:hover,
body.dark .composer-extra-button:focus-visible {
    background: rgba(37, 99, 235, 0.22);
}

.composer-extras-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.18);
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}

.composer-extras-overlay:not(.hidden) {
    opacity: 1;
}

.loading-indicator {
    position: fixed;
    right: 1.5rem;
    bottom: 2rem;
    padding: 0.75rem;
    border-radius: 18px;
    background: var(--surface-card);
    border: 1px solid rgba(148, 163, 184, 0.2);
    box-shadow: var(--shadow-card);
    z-index: 20;
}

body.dark .loading-indicator {
    background: rgba(15, 23, 42, 0.92);
    border-color: rgba(148, 163, 184, 0.12);
}

.loading-spinner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid rgba(148, 163, 184, 0.4);
    border-top-color: var(--brand-accent);
    animation: spin 0.8s linear infinite;
}

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


/* Images */
.image-container {
    margin: 1.2rem 0;
    border-radius: 18px;
    overflow: hidden;
    background: rgba(15, 23, 42, 0.05);
}

.generated-image {
    width: 100%;
    display: block;
}

.image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    background: rgba(148, 163, 184, 0.2);
    border-radius: 18px;
}

.image-error {
    color: #b91c1c;
    background: rgba(248, 113, 113, 0.15);
    padding: 0.75rem;
    border-radius: 12px;
}

/* Image Modal */
.image-input-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.65);
    display: grid;
    place-items: center;
    z-index: 50;
}

.image-input-container {
    width: min(560px, 92%);
    background: var(--surface-card);
    border-radius: 22px;
    padding: 1.75rem;
    box-shadow: 0 28px 70px -20px rgba(15, 23, 42, 0.6);
}

body.dark .image-input-container {
    background: rgba(9, 12, 22, 0.95);
}

.image-input-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.2rem;
}

.close-modal {
    border: none;
    background: rgba(148, 163, 184, 0.18);
    border-radius: 12px;
    width: 32px;
    height: 32px;
    cursor: pointer;
}

.image-input-tabs {
    display: inline-flex;
    gap: 0.6rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}


.tab-button {
    border: none;
    background: transparent;
    padding: 0.55rem 0.9rem;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: var(--transition);
}

.tab-button.active {
    color: var(--brand-accent);
    border-bottom-color: var(--brand-accent);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.image-preview {
    margin-top: 1rem;
    border-radius: 16px;
    overflow: hidden;
    background: rgba(148, 163, 184, 0.12);
    min-height: 120px;
    display: grid;
    place-items: center;
}

.image-preview img {
    width: 100%;
    display: block;
}

.image-preview .error {
    color: #b91c1c;
    padding: 0.5rem;
}

.image-input-actions {
    margin-top: 1.4rem;
    display: flex;
    justify-content: flex-end;
}

.image-input-actions button {
    padding: 0.65rem 1.2rem;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--brand-accent), #0ea5e9);
    color: white;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
}

.image-input-actions button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.remove-image-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(15, 23, 42, 0.75);
    color: white;
    cursor: pointer;
}

/* Web search citation styling */
.web-search-citation {
    background: rgba(37, 99, 235, 0.08);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    margin-top: 0.75rem;
    font-size: 0.85rem;
}

.citation-index {
    font-weight: 600;
    margin-right: 0.4rem;
}

/* Responsive */
@media (max-width: 1024px) {
    .app-shell { width: 100%; }
    .app-main { padding: 0 1.4rem 1.7rem; }
    .app-footer { padding: 1.2rem 1.4rem calc(1.8rem + var(--safe-bottom)); }
}

@media (max-width: 768px) {
    body {
        background: linear-gradient(135deg, var(--surface-dark) 0%, var(--surface-dark-mid) 50%, var(--surface-dark) 100%);
        min-height: -webkit-fill-available;
    }

    body.dark {
        background: linear-gradient(135deg, var(--surface-dark) 0%, var(--surface-dark-mid) 50%, var(--surface-dark) 100%);
    }

    body.mobile-toolbar-open {
        overflow: hidden;
    }

    .app-shell {
        width: 100%;
        padding: 0;
    }

    .app-header {
        padding: calc(var(--safe-top) + 0.85rem) 1rem 0.75rem;
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "brand toggle"
            "panel panel";
        gap: 0.6rem;
        border-bottom: none;
        box-shadow: 0 14px 40px -26px rgba(15, 23, 42, 0.35);
        padding-bottom: 0.9rem;
    }

    body.dark .app-header {
        background: rgba(10, 15, 28, 0.82);
        box-shadow: 0 20px 40px -30px rgba(2, 6, 23, 0.8);
    }

    .app-header .brand-block {
        grid-area: brand;
        width: 100%;
        justify-content: space-between;
        gap: 0.75rem;
    }

    .app-header .brand-copy h1 {
        font-size: 1.05rem;
    }

    .app-header .brand-copy p {
        font-size: 0.8rem;
    }

    .mobile-toolbar-toggle {
        grid-area: toggle;
        display: inline-flex;
        width: 42px;
        height: 42px;
    }

    .header-toolbar {
        grid-area: panel;
        position: absolute;
        top: calc(100% + 0.6rem);
        left: 1rem;
        right: 1rem;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        background: rgba(255, 255, 255, 0.96);
        border-radius: 18px;
        border: 1px solid rgba(148, 163, 184, 0.25);
        padding: 0.9rem;
        box-shadow: 0 22px 50px -28px rgba(15, 23, 42, 0.45);
        transform: translateY(-12px);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: transform 0.2s ease, opacity 0.18s ease;
        z-index: 11;
        max-height: min(70vh, 420px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .header-toolbar > * {
        margin-left: 0 !important;
    }

    .header-toolbar.is-open {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    body.dark .header-toolbar {
        background: rgba(11, 18, 33, 0.95);
        border-color: rgba(148, 163, 184, 0.18);
        box-shadow: 0 26px 60px -28px rgba(2, 6, 23, 0.9);
    }

    .header-toolbar .model-dropdown {
        width: 100%;
    }

    .header-toolbar .header-icon-group {
        justify-content: space-between;
    }

    .header-toolbar .auth-controls {
        border-left: none;
        padding-left: 0;
        margin-top: 0.4rem;
        padding-top: 0.9rem;
        border-top: 1px solid rgba(148, 163, 184, 0.2);
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.55rem;
    }

    body.dark .header-toolbar .auth-controls {
        border-color: rgba(148, 163, 184, 0.16);
    }

    .header-toolbar .auth-status {
        width: 100%;
    }

    .header-toolbar .icon-button {
        width: 44px;
        height: 44px;
    }

    .header-toolbar .auth-button {
        width: 100%;
    }

    .app-main {
        padding: 0 0 1rem;
        flex: 1;
    }

    .chat-scroll-container {
        border-radius: 0;
        border: none;
        box-shadow: none;
        background: transparent;
    }

    .chat-message-list {
        padding: 1.05rem 1rem;
        padding-bottom: calc(8rem + env(safe-area-inset-bottom));
    }

    .message {
        margin-bottom: 1rem;
        gap: 0.75rem;
    }

    .message.user-message {
        align-items: flex-end;
        flex-direction: column;
    }

    .message.assistant-message {
        align-items: flex-start;
        flex-direction: column;
    }

    .message-avatar {
        display: none;
    }

    .message-card {
        width: 100%;
        border-radius: 18px;
        padding: 0.85rem 1rem;
        box-shadow: 0 18px 40px -28px rgba(15, 23, 42, 0.35);
    }

    .message.user-message .message-card {
        background: linear-gradient(135deg, var(--brand-accent), #4f46e5);
        color: #f8fafc;
        border: none;
    }

    .message.assistant-message .message-card {
        background: rgba(255, 255, 255, 0.94);
    }

    body.dark .message.assistant-message .message-card {
        background: rgba(15, 23, 42, 0.88);
    }

    .message.user-message .message-header .name {
        color: #ffffff;
    }

    .message.user-message .message-header .timestamp {
        color: rgba(241, 245, 249, 0.7);
    }

    .message.user-message .message-content {
        color: inherit;
    }

    .message.user-message .message-content code {
        background: rgba(15, 23, 42, 0.35);
    }

    .empty-state {
        margin: 3rem 0;
        padding: 0 1rem;
    }

    .empty-hero p {
        font-size: 0.92rem;
    }

    .prompt-grid {
        grid-template-columns: 1fr;
        gap: 0.85rem;
        margin-top: 1.75rem;
    }

    .prompt-card {
        padding: 0.95rem 1rem;
    }

    .composer {
        flex-direction: row;
        align-items: flex-end;
        gap: 0.55rem;
        padding: 0.7rem 0.75rem;
        border-radius: 14px;
    }

    .composer-input {
        flex: 1;
    }

    .composer-textarea {
        min-height: 52px;
        line-height: 1.45;
        font-size: 0.98rem;
    }

    .composer-plus {
        width: 36px;
        height: 36px;
    }

    .composer-extras {
        position: fixed;
        left: 1rem;
        right: 1rem;
        bottom: calc(var(--safe-bottom) + 5.2rem);
        max-width: none;
        min-width: 0;
        padding: 1rem 1.1rem;
        gap: 0.75rem;
        transform: translateY(24px);
        border-radius: 20px;
        box-shadow: 0 28px 50px -20px rgba(15, 23, 42, 0.55);
    }

    .composer-extra-button {
        padding: 0.75rem 0.9rem;
        font-size: 1rem;
    }

    .composer-hint {
        display: none;
    }

    .app-footer {
        padding: 0.75rem 1rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(20px);
        box-shadow: 0 -8px 32px 0 rgba(0, 0, 0, 0.3);
        z-index: 50;
    }

    body.dark .app-footer {
        background: rgba(0, 0, 0, 0.4);
        border-color: rgba(255, 255, 255, 0.1);
        box-shadow: 0 -8px 32px 0 rgba(0, 0, 0, 0.3);
    }

    .composer {
        flex-direction: row;
        align-items: flex-end;
        gap: 0.6rem;
        padding: 0.75rem 0.85rem;
        border-radius: 16px;
    }

    .composer-input {
        flex: 1;
    }

    .composer-textarea {
        min-height: 56px;
        line-height: 1.45;
        font-size: 1rem;
    }

    .composer-plus {
        width: 34px;
        height: 34px;
    }

    .composer-extras {
        left: 0.4rem;
        bottom: calc(100% + 0.5rem);
        min-width: min(240px, 86vw);
    }

    .send-button {
        width: 44px;
        height: 44px;
        font-size: 1.05rem;
    }
}

html.dark {
    background: var(--surface-dark);
    color: var(--text-inverse);
}

html.dark body {
    background: linear-gradient(135deg, var(--surface-dark) 0%, var(--surface-dark-mid) 50%, var(--surface-dark) 100%);
}

html.dark .message-card { color: var(--text-inverse); }

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.auth-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
    backdrop-filter: blur(4px);
}

.auth-modal.hidden {
    display: none;
}

.auth-modal-content {
    width: min(380px, 90vw);
    background: white;
    border-radius: 18px;
    padding: 1.75rem 1.75rem 1.5rem;
    box-shadow: 0 30px 70px -40px rgba(15, 23, 42, 0.7);
    position: relative;
}

body.dark .auth-modal-content {
    background: var(--surface-dark-elevated);
    color: var(--text-inverse);
}

.auth-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.9rem;
    font-size: 1.5rem;
    border: none;
    background: transparent;
    color: #475569;
    cursor: pointer;
}

.auth-modal-close:hover {
    color: #0f172a;
}

body.dark .auth-modal-close {
    color: rgba(226, 232, 240, 0.7);
}

body.dark .auth-modal-close:hover {
    color: white;
}

.auth-modal-content h2 {
    margin: 0 0 0.35rem;
    font-size: 1.45rem;
    color: #0f172a;
}

body.dark .auth-modal-content h2 {
    color: white;
}

.auth-modal-subtitle {
    margin: 0 0 1.25rem;
    color: #475569;
    font-size: 0.9rem;
}

body.dark .auth-modal-subtitle {
    color: rgba(226, 232, 240, 0.8);
}

#authForm {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

#authForm label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #0f172a;
}

body.dark #authForm label {
    color: white;
}

#authForm input[type="email"],
#authForm input[type="password"] {
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    padding: 0.65rem 0.85rem;
    background: #f8fafc;
    color: #0f172a;
    font-size: 16px;
}

body.dark #authForm input[type="email"],
body.dark #authForm input[type="password"] {
    background: rgba(148, 163, 184, 0.2);
    color: white;
    border-color: rgba(148, 163, 184, 0.4);
}

#authForm input::placeholder {
    color: #94a3b8;
}

#authForm input:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px var(--brand-accent-soft);
}

.auth-primary-button {
    border: none;
    border-radius: 14px;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, var(--brand-accent), var(--brand-accent-deep));
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.12s ease;
    font-size: 1rem;
}

.auth-primary-button:hover {
    transform: translateY(-1px);
}

.auth-primary-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.auth-secondary-button {
    border: none;
    background: transparent;
    color: var(--brand-accent);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    margin-top: -0.2rem;
    align-self: flex-start;
}

.auth-secondary-button:hover {
    text-decoration: underline;
}

.auth-alert {
    margin: -0.2rem 0 0;
    font-size: 0.85rem;
    border-radius: 10px;
    padding: 0.5rem 0.65rem;
}

.auth-alert.hidden {
    display: none;
}

.auth-alert-error {
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
}

.auth-alert-message {
    background: rgba(34, 197, 94, 0.15);
    color: #15803d;
}

body.dark .auth-alert-error {
    background: rgba(239, 68, 68, 0.22);
    color: #fca5a5;
}

body.dark .auth-alert-message {
    background: rgba(34, 197, 94, 0.25);
    color: #4ade80;
}

/* Settings panel */
#settingsPanel {
    position: fixed;
    top: 6rem;
    right: 2rem;
    width: 320px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.4);
    padding: 1.5rem;
    z-index: 40;
    max-height: min(80vh, 640px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    color: #0f172a;
}

body.dark #settingsPanel {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-color: rgba(255, 255, 255, 0.3);
    color: #0f172a;
}

#settingsPanel.hidden { display: none; }

#settingsPanel h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.05rem;
    color: #0f172a;
}

#settingsPanel label {
    font-size: 0.85rem;
    font-weight: 500;
    display: block;
    margin-bottom: 0.35rem;
    color: #0f172a;
}

#settingsPanel input[type="number"],
#settingsPanel select,
#settingsPanel textarea {
    width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(51, 153, 242, 0.3);
    padding: 0.5rem 0.75rem;
    background: white;
    color: #0f172a;
    font-size: 14px;
}

#settingsPanel input[type="range"] {
    width: 100%;
}

#settingsPanel button {
    border: none;
    padding: 0.5rem 0.9rem;
    border-radius: 12px;
    background: rgba(37, 99, 235, 0.15);
    color: var(--brand-accent);
    cursor: pointer;
    font-size: 0.85rem;
}

#settingsPanel button:hover {
    background: rgba(37, 99, 235, 0.25);
}

#settingsPanel .settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

#settingsPanel .settings-row label {
    flex: 1;
    font-weight: 500;
}

#settingsPanel input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--brand-accent);
}

#settingsPanel .include-options {
    display: grid;
    gap: 0.35rem;
    padding: 0.25rem 0;
}

#settingsPanel .include-option {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.85rem;
}

#settingsPanel .include-option input {
    width: 16px;
    height: 16px;
}

#settingsPanel .conversation-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#settingsPanel .conversation-actions {
    display: flex;
    gap: 0.5rem;
}

#settingsPanel .conversation-actions button {
    flex: 1;
}

#settingsPanel .settings-hint {
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 0.25rem;
}

body.dark #settingsPanel .settings-hint {
    color: #64748b;
}

#settingsPanel .settings-section {
    margin-bottom: 1.25rem;
}

#settingsPanel .settings-slider {
    width: 100%;
    margin: 0.5rem 0;
    accent-color: var(--brand-accent);
}

#settingsPanel .settings-hint-row {
    display: flex;
    justify-content: space-between;
    margin-top: 0.25rem;
}

#settingsPanel .settings-hint-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 500;
}

body.dark #settingsPanel .settings-hint-label {
    color: rgba(226, 232, 240, 0.6);
}

#settingsPanel label {
    font-size: 0.9rem;
    font-weight: 600;
    display: block;
    margin-bottom: 0.5rem;
}

#settingsPanel label span {
    color: var(--brand-accent);
    font-weight: 700;
}

#settingsPanel .settings-select {
    width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    padding: 0.5rem 0.75rem;
    background: var(--surface-card);
    color: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}

body.dark #settingsPanel .settings-select {
    background: rgba(15, 23, 42, 0.4);
    border-color: rgba(148, 163, 184, 0.2);
}

.model-badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 8px;
    background: var(--brand-accent-soft);
    color: var(--brand-accent);
    font-weight: 600;
    margin-top: 0.25rem;
}

.model-config-summary {
    background: rgba(37, 99, 235, 0.05);
    border-radius: 12px;
    padding: 0.75rem;
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

body.dark .model-config-summary {
    background: rgba(37, 99, 235, 0.1);
}

.config-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.config-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.config-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--brand-accent);
}

body.dark .config-label {
    color: rgba(226, 232, 240, 0.6);
}

.inline-image-preview {
    width: 100%;
    border-radius: 18px;
    overflow: hidden;
    background: rgba(148, 163, 184, 0.18);
    position: relative;
}

.inline-image-preview .generated-image {
    display: block;
    width: 100%;
}
