:root {
    /* Color Palette - Modern & Sophisticated */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-accent: #38bdf8;
    /* Sky Blue */

    --border-color: #334155;

    --accent-color: #0ea5e9;
    --accent-hover: #0284c7;

    --msg-user-bg: #0ea5e9;
    --msg-user-text: #ffffff;
    --msg-ai-bg: #1e293b;
    --msg-ai-text: #f1f5f9;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Layout */
.app-container {
    display: grid;
    /* Sidebar | Main Chat | Resizer | Side Panel */
    grid-template-columns: 280px 1fr 0px 0px;
    position: fixed; /* ログイン後に全画面オーバーレイとして機能 */
    inset: 0;
}

.resizer {
    width: 5px;
    background-color: transparent;
    cursor: col-resize;
    transition: background-color 0.2s;
    z-index: 100;
}

.resizer:hover,
.resizer.active {
    background-color: var(--accent-color);
}

.resizer.hidden {
    display: none;
}


/* Sidebar */
.sidebar {
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

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

.brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand-icon {
    color: var(--accent-color);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

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

/* Thread List */
.thread-list {
    list-style: none;
}

.thread-item {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: 0.375rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.thread-item.active {
    background-color: rgba(14, 165, 233, 0.1);
    /* Low opacity accent */
    color: var(--accent-color);
    font-weight: 500;
}

.thread-delete-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    opacity: 0;
    /* Hidden by default */
    transition: opacity 0.2s, color 0.2s;
}

.thread-delete-btn svg {
    width: 16px;
    height: 16px;
}

.thread-item:hover .thread-delete-btn {
    opacity: 1;
    /* Show on hover */
}

.thread-delete-btn:hover {
    color: #ff4d4d;
    /* Red on hover */
}

/* Main Chat Area */
.chat-area {
    display: flex;
    flex-direction: column;
    background-color: var(--bg-primary);
    position: relative;
    position: relative;
    height: 100vh;
    height: 100dvh;
    /* Ensure full height */
    overflow: hidden;
    /* Prevent body scroll */
}

.chat-header {
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    z-index: 10;
}

.chat-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 0; /* Allow shrinking for flex container */
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 1rem;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    position: relative;
    margin-bottom: 1.5rem; /* Add vertical space below message for buttons */
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.375rem;
    /* Slight rounded square */
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background-color: var(--accent-color);
}

.message-content {
    background-color: var(--msg-ai-bg);
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    border-top-left-radius: 0;
    color: var(--msg-ai-text);
    box-shadow: var(--shadow-sm);
    line-height: 1.6;
    position: relative;
    white-space: pre-wrap;
}

.message.user .message-content {
    background-color: var(--msg-user-bg);
    color: var(--msg-user-text);
    border-radius: 0.75rem;
    border-top-right-radius: 0;
}

/* Branch Button */
.branch-btn {
    position: absolute;
    bottom: -1.8rem;
    /* Move down slightly to clear bubble better */
    left: 0;
    font-size: 0.8rem;
    /* Slightly larger */
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.7;
    /* Default visible */
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0;
}

.message:hover .branch-btn {
    opacity: 1;
}

.edit-msg-btn {
    position: absolute;
    bottom: -1.8rem;
    right: 0; 
    opacity: 1; /* Default visible */
    background: transparent;
    border: none;
    color: #ffffff; /* White text by default */
    padding: 0.2rem 0;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.edit-msg-btn:hover {
    color: var(--accent-color);
    /* Remove padding and background changes to prevent movement */
}

/* Always visible for touch or ease of access, or keep opacity 0.8? 
   User requested "More visible". Let's make it always visible but subtle. */
.branch-btn {
    opacity: 0.7;
    /* Visible but not distracting */
}

.branch-btn:hover {
    opacity: 1;
    color: var(--accent-color);
    background-color: rgba(14, 165, 233, 0.1);
    /* Light highlighting */
    padding: 0.2rem 0.5rem;
    /* Add touch target */
    border-radius: 4px;
}

.branch-btn:hover {
    color: var(--accent-color);
}

/* Input Area */
.input-area {
    padding: 1.5rem 2rem;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    background-color: var(--bg-secondary);
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    transition: border-color 0.2s;
}

.input-container:focus-within {
    border-color: var(--accent-color);
}

textarea.chat-input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 0.75rem 0.75rem 1.5rem;
    resize: none;
    min-height: 56px;
    max-height: 280px;
    overflow-y: auto;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    outline: none;
}

.send-btn {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    background-color: var(--accent-color);
    color: white;
    border: none;
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.send-btn:hover {
    background-color: var(--accent-hover);
}

/* Utility */
.hidden {
    display: none !important;
}

/* --- Landing Page (LP) Styles --- */
.lp-container {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--bg-primary);
    position: relative;
    z-index: 1;
}

/* Scrollbar for LP */
.lp-container::-webkit-scrollbar {
    width: 8px;
}
.lp-container::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
.lp-container::-webkit-scrollbar-thumb {
    background-color: var(--bg-tertiary);
    border-radius: 4px;
}

/* Hero Section */
.hero {
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    overflow: hidden;
}

.hero-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    pointer-events: none; /* 装飾要素はタッチ/クリックイベントを受け取らない */
}

.aurora-blob {
    position: absolute;
    pointer-events: none; /* blur合成レイヤーがタッチイベントを横取りするのを防ぐ */
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: drift 20s infinite alternate ease-in-out;
}

.blob-1 {
    width: 50vw;
    height: 50vw;
    background: rgba(14, 165, 233, 0.3); /* Sky blue */
    top: -10%;
    left: -10%;
    animation-delay: 0s;
}

.blob-2 {
    width: 40vw;
    height: 40vw;
    background: rgba(56, 189, 248, 0.2); /* Lighter blue */
    bottom: -10%;
    right: -10%;
    animation-delay: -5s;
}

.blob-3 {
    width: 30vw;
    height: 30vw;
    background: rgba(14, 165, 233, 0.2);
    top: 40%;
    left: 40%;
    animation-delay: -10s;
}

@keyframes drift {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(10%, 10%) scale(1.1); }
}

.hero-content {
    position: relative;
    z-index: 1;
    max-width: 800px;
    animation: fadeInUp 1s ease-out forwards;
}

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

.brand-large {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.hero-title {
    font-size: clamp(2.5rem, 5vw, 4rem);
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, #ffffff 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: clamp(1rem, 2vw, 1.25rem);
    color: var(--text-secondary);
    margin-bottom: 3rem;
    line-height: 1.6;
}

.hero-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.4);
}

.hero-btn:hover {
    background-color: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.6);
}

/* Features Section */
.features {
    padding: 6rem 2rem;
    background-color: var(--bg-primary);
    position: relative;
    z-index: 1;
}

.section-title {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 4rem;
    color: var(--text-primary);
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.feature-card {
    background: rgba(30, 41, 59, 0.5); /* Semi-transparent bg for glassmorphism */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 2.5rem;
    border-radius: 1rem;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
}

.feature-card:hover {
    transform: translateY(-10px);
    background: rgba(30, 41, 59, 0.8);
    border-color: rgba(14, 165, 233, 0.3);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.feature-card:hover .feature-icon {
    transform: scale(1.1) translateY(-5px);
    color: var(--accent-color);
}

.feature-icon {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    transition: transform 0.3s ease, color 0.3s ease;
}

.feature-card h3 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.feature-card p {
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Auth Section (CTA) */
.auth-section {
    padding: 6rem 2rem;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: center;
}

.auth-card-container {
    width: 100%;
    max-width: 450px;
}

/* Override existing auth-card styles for LP context */
.lp-container .auth-card {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* Scroll Reveal Classes */
.reveal {
    opacity: 0;
    transform: translateY(40px);
    transition: all 0.8s ease-out;
}

.reveal.active {
    opacity: 1;
    transform: translateY(0);
}

.reveal-delay-1 { transition-delay: 0.2s; }
.reveal-delay-2 { transition-delay: 0.4s; }

/* Keep modal auth-overlay styles unchanged for Profile Modal */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.95);
    z-index: 1000; /* Ensure it stays above LP (z-index 200) */
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    background-color: var(--bg-secondary);
    padding: 2.5rem;
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-input-group {
    margin-bottom: 1rem;
}

.auth-input {
    width: 100%;
    padding: 0.75rem;
    border-radius: 0.375rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.auth-input:focus {
    border-color: var(--accent-color);
    outline: none;
}

.auth-btn {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 1rem;
    transition: background-color 0.2s;
}

.auth-btn:hover {
    background-color: var(--accent-hover);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-md);
    min-width: 300px;
    animation: slideIn 0.3s ease-out;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toast.success {
    border-left: 4px solid #22c55e;
    /* Green */
}

.toast.error {
    border-left: 4px solid #ef4444;
    /* Red */
}

.toast.info {
    border-left: 4px solid #3b82f6;
    /* Blue */
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* --- Thread Side Panel --- */
.thread-panel {
    /* Removed fixed width, now handled by Grid */
    border-left: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    height: 100%;
    /* transition: width 0.3s ease; Grid transition is tricky */
    overflow: hidden;
}

.thread-panel.hidden {
    /* Grid handles width, but display none ensures clean hide */
    display: none;
    opacity: 0;
    display: none;
    /* Fully hide to prevent layout issues if using auto grid */
}

/* Revert display none if we want animation, but grid makes it tricky. 
   Simple approach: .hidden removes from flow or 0 width. */
.thread-panel.hidden {
    display: none;
}

.thread-panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-secondary);
}

.thread-panel-title {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.close-panel-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 0.5rem;
    transition: color 0.2s;
}

/* --- UI Refactoring Additions --- */
/* ログアウトボタンのコントラスト調整 */
#logout-btn {
    color: #ef4444; /* 赤系のアラート色に変更してコントラスト強化 */
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s, background-color 0.2s;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}
#logout-btn:hover {
    background-color: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

/* カスタムモーダル追加スタイル */
.thread-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(15, 23, 42, 0.95);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-panel-btn:hover {
    color: var(--text-primary);
}

/* Adjust side messages container to match main but maybe smaller padding */
#side-messages-container {
    padding: 1rem;
    background-color: var(--bg-primary);
    /* Slight contrast */
    flex: 1;
    /* Take remaining height */
    overflow-y: auto;
    /* Enable scroll */
}

/* Responsive adjustment for small screens? 
   Not priority but good to have: over 1000px shows panel, under might overlay? */
@media (max-width: 1000px) {
    .app-container {
        grid-template-columns: 280px 1fr 0;
        /* Hide by default or overlay? */
        /* Complex. Let's keep simple static grid for now. */
    }

    .thread-panel:not(.hidden) {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 50;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.5);
    }
}

/* --- Markdown Styles --- */
.message-content {
    /* Overwrite white-space for markdown rendering */
    white-space: normal;
}

.message-content p {
    margin-bottom: 0.8rem;
}

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

.message-content pre {
    background-color: #0d1117;
    margin: 0.8rem 0;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    border: 1px solid var(--border-color);
}

.message-content code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-size: 0.9em;
}

.message-content pre code {
    background-color: transparent;
    padding: 0;
    font-size: 0.95em;
    color: inherit;
    white-space: pre;
    /* Code blocks need pre spacing */
}

/* Fix for highlight.js background conflict */
.hljs {
    background: transparent !important;
    padding: 0 !important;
}

.message-content ul,
.message-content ol {
    margin-bottom: 0.8rem;
    padding-left: 1.5rem;
}

.message-content li {
    margin-bottom: 0.4rem;
}

.message-content blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 1rem;
    margin-bottom: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    background-color: rgba(255, 255, 255, 0.02);
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    border-radius: 0 4px 4px 0;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.8rem;
    display: block;
    /* For scroll on small screens */
    overflow-x: auto;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border-color);
    padding: 0.6rem;
    text-align: left;
}

.message-content th {
    background-color: rgba(255, 255, 255, 0.05);
    font-weight: 600;
}

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

/* User Message Specific Adjustments */
.message.user .message-content p {
    margin-bottom: 0;
}

/* AI Message - Add space for branch button */
.message.ai {
    margin-bottom: 2.5rem;
    /* Space for absolute button + breathing room */
}

/* Breadcrumbs in Chat Header */
.breadcrumb-container {
    display: flex;
    align-items: center;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    /* Hide scrollbar for cleaner look */
}

.breadcrumb-container::-webkit-scrollbar {
    display: none;
}

.breadcrumb-item {
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s;
    font-weight: 500;
}

.breadcrumb-item:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

.breadcrumb-separator {
    color: var(--text-secondary);
    margin: 0 0.5rem;
    font-size: 0.9em;
    opacity: 0.7;
}

.breadcrumb-current {
    font-weight: 700;
    color: var(--text-primary);
    background-color: rgba(14, 165, 233, 0.15);
    padding: 0.1rem 0.6rem;
    border-radius: 4px;
    border: 1px solid rgba(14, 165, 233, 0.3);
    font-size: 0.95em;
}

/* --- Scroll To Top Button --- */
.scroll-top-btn {
    position: absolute;
    bottom: 6rem;
    right: 2rem;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background-color: var(--accent-color);
    color: white;
    border: none;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
    transition: opacity 0.3s, transform 0.3s, visibility 0.3s;
    z-index: 50;
}

.scroll-top-btn:hover {
    background-color: var(--accent-hover);
    transform: translateY(-2px);
    opacity: 1;
}

.scroll-top-btn.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    display: flex !important; /* Override .hidden display:none */
}

/* Ensure relative positioning for absolute child */
.chat-area, .thread-panel {
    position: relative;
}
/* --- Responsive Sidebar (Mobile) --- */
@media (max-width: 768px) {
    .app-container {
        /* Remove sidebar column, keep Main (1fr) | Resizer (0) | Panel (0) */
        grid-template-columns: 1fr 0px 0px !important;
        position: relative;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        left: 0;
    }

    /* Overlay */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 900;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s;
    }

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

    /* Buttons */
    .sidebar-toggle-btn {
        display: flex !important; /* Override .hidden */
        background: none;
        border: none;
        color: var(--text-primary);
        cursor: pointer;
        padding: 0.5rem;
        margin-right: 0.5rem;
    }

    .sidebar-close-btn {
        display: flex !important; /* Override .hidden */
        background: none;
        border: none;
        color: var(--text-secondary);
        cursor: pointer;
        padding: 0.5rem;
        margin-left: auto; /* Push to right */
    }

    .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* Content Width Maximize */
    .message, .input-container {
        max-width: 100%;
    }

    .messages-container {
        padding: 0.5rem; /* Further reduce padding */
    }

    .input-area {
        padding: 0.5rem; /* Further reduce padding */
        /* Increase bottom padding significantly to clear Android gesture bar/home bar */
        /* safe-area-inset-bottom might be 0 on some Androids even with gesture bar */
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)); 
    }

    /* Hide Avatar on Mobile for max space */
    .message-avatar {
        display: none;
    }

    /* Reduce gap since avatar is gone */
    .message {
        gap: 0;
        margin-bottom: 2rem; /* Add some vertical spacing between messages if needed, but .message.ai already has 2.5rem */
    }
    
    /* Ensure message content takes full width */
    .message-content {
        max-width: 100%;
        width: 100%;
        border-radius: 0.75rem !important; /* Reset corner radius since avatar is gone */
    }

    /* Thread Panel (Right Side) Mobile Optimization */
    .thread-panel:not(.hidden) {
        position: fixed !important; /* Override absolute from 1000px media query */
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%; /* Full width for mobile */
        /* max-width: 400px; Remove max-width limit to show full tables if preferred, or keep reasonable */
        max-width: 100%; 
        z-index: 2000; /* Higher than sidebar (1000) */
        border-left: none;
        box-shadow: -2px 0 10px rgba(0,0,0,0.5);
    }

    /* モバイル: aurora ブロブのブラー・アニメーションを軽量化（GPU 負荷軽減） */
    .aurora-blob {
        filter: blur(30px);
        opacity: 0.35;
        animation: none;  /* アニメーション停止でフレームドロップを防ぐ */
    }
}

/* チャット内画像添付 */
.chat-image-attachment {
    max-width: 50%;
    height: auto;
    border-radius: 0.5rem;
    cursor: zoom-in;
    display: block;
}

/* 画像ポップアップモーダル */
#image-popup-modal {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
}
#image-popup-modal.hidden {
    display: none;
}
#image-popup-modal img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 0.5rem;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
    cursor: default;
}
