:root {
    --bg-dark: #121212;
    --bg-sidebar: #171717;
    --bg-input: #2F2F2F;
    --bg-message-user: #212121;
    --bg-message-ai: transparent;
    --text-primary: #ECECEC;
    --text-secondary: #9B9B9B;
    --accent-color: #4F46E5;
    --accent-hover: #4338CA;
    --border-color: #333333;

    --font-main: 'Inter', 'Noto Sans JP', sans-serif;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-main);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

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

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

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.app-container {
    display: flex;
    height: 100%;
}

/* --- Sidebar --- */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.sidebar-header {
    padding: 16px;
}

.new-chat-btn {
    width: 100%;
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: var(--font-main);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

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

.history-group {
    margin-bottom: 24px;
}

.history-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 8px;
    padding-left: 8px;
}

.history-item-container {
    display: flex;
    align-items: center;
    width: 100%;
    border-radius: 8px;
    transition: background-color 0.2s;
    margin-bottom: 2px;
}

.history-item-container.active,
.history-item-container:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.history-item {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 12px 8px;
    cursor: pointer;
    font-size: 0.9rem;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    /* allows text truncation to work inside flex */
}

.history-item span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.delete-chat-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 10px;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s;
}

.history-item-container:hover .delete-chat-btn {
    opacity: 1;
}

.delete-chat-btn:hover {
    color: #ef4444;
    /* red hover */
}

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

.user-profile {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: 8px;
    text-align: left;
}

.settings-icon {
    color: var(--text-secondary);
    transition: color 0.2s;
}

.settings-icon:hover {
    color: var(--text-primary);
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 500;
}

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

.settings-icon {
    color: var(--text-secondary);
}

/* --- Main Chat Area --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-dark);
    position: relative;
}

.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #e5e5e5;
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-menu-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    position: absolute;
    left: 20px;
}

.badge {
    background-color: var(--accent-color);
    color: white;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    padding: 24px 15%;
    gap: 20px;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

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

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

.ai-message .message-avatar {
    background-color: #10B981;
    color: white;
}

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

.message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 4px;
}

.message-content {
    flex: 1;
    line-height: 1.7;
}

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

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

.uploaded-image-display {
    max-width: 300px;
    max-height: 300px;
    border-radius: 8px;
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
}

/* --- Input Area --- */
.input-area {
    padding: 24px 15%;
    background: linear-gradient(180deg, rgba(18, 18, 18, 0) 0%, rgba(18, 18, 18, 1) 50%);
}

.input-wrapper {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 12px 16px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}

.input-wrapper:focus-within {
    border-color: rgba(79, 70, 229, 0.5);
    box-shadow: 0 0 0 1px rgba(79, 70, 229, 0.5);
}

/* Image Preview inside input */
.image-preview-container {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.preview-item {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

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

.preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.input-controls {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.upload-btn {
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    transition: color 0.2s;
}

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

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    max-height: 200px;
    outline: none;
    padding: 8px 0;
    line-height: 1.5;
}

#chat-input::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

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

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

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

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

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

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

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

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }

    .sidebar {
        position: fixed;
        left: -260px;
        z-index: 100;
        height: 100%;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        left: 0;
    }

    .message,
    .input-area {
        padding-left: 5%;
        padding-right: 5%;
    }

    /* Overlay for when sidebar is open on mobile */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 90;
    }

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

/* --- Modal --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--bg-input);
    margin: 10% auto;
    padding: 32px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    position: relative;
}

.modal-content h2 {
    margin-bottom: 20px;
    font-size: 1.2rem;
}

.close-btn {
    position: absolute;
    top: 20px;
    right: 24px;
    color: var(--text-secondary);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

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

.setting-item {
    margin-bottom: 24px;
}

.setting-item label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.9rem;
}

.setting-item input {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-dark);
    color: var(--text-primary);
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}

.setting-item input:focus {
    border-color: var(--accent-color);
}

.setting-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 8px;
    line-height: 1.5;
}

.save-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    width: 100%;
    font-weight: 600;
    font-size: 1rem;
    transition: background-color 0.2s;
}

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