* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --success: #10b981;
    --error: #ef4444;
    --user-bg: #4f46e5;
    --assistant-bg: #1e293b;
    --sidebar-width: 280px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ============ ·¹ÀÌ¾Æ¿ô ============ */

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ============ »çÀÌµå¹Ù ============ */

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.2em;
    color: var(--text-primary);
}

.new-chat-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.new-chat-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.conversations-list::-webkit-scrollbar {
    width: 6px;
}

.conversations-list::-webkit-scrollbar-track {
    background: var(--surface);
}

.conversations-list::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 3px;
}

.loading-conversations,
.empty-conversations,
.error-text {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 0.9em;
}

.error-text {
    color: var(--error);
}

.conversation-item {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    overflow: hidden;
    transition: all 0.2s;
}

.conversation-item:hover {
    border-color: var(--primary-color);
    transform: translateX(2px);
}

.conversation-item.active {
    border-color: var(--primary-color);
    background: rgba(79, 70, 229, 0.1);
}

.conversation-main {
    padding: 12px;
    cursor: pointer;
}

.conversation-title {
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75em;
    color: var(--text-secondary);
}

.message-count {
    display: flex;
    align-items: center;
    gap: 4px;
}

.conversation-date {
    font-size: 0.9em;
}

.conversation-actions {
    display: flex;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: all 0.2s ease;
}

.conversation-item:hover .conversation-actions {
    opacity: 1;
    max-height: 50px;
}

.action-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: rgba(79, 70, 229, 0.2);
    color: var(--primary-color);
}

.action-btn.delete:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--error);
}

.action-btn + .action-btn {
    border-left: 1px solid var(--border);
}

/* ============ ¸ÞÀÎ ÄÁÅÙÃ÷ ============ */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mobile-header {
    display: none;
    padding: 15px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    align-items: center;
    gap: 15px;
}

.menu-toggle {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
}

.mobile-header h1 {
    font-size: 1.2em;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.desktop-header {
    text-align: center;
    padding: 20px;
    border-bottom: 2px solid var(--border);
}

.desktop-header h1 {
    font-size: 2em;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar {
    width: 8px;
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 4px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--border);
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.welcome-message h2 {
    font-size: 2em;
    margin-bottom: 10px;
    color: var(--text-primary);
}

/* ============ ¸Þ½ÃÁö ============ */

.message {
    display: flex;
    margin-bottom: 20px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    justify-content: flex-end;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    position: relative;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user .message-content {
    background: var(--user-bg);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--assistant-bg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-role {
    font-size: 0.75em;
    font-weight: bold;
    margin-bottom: 4px;
    opacity: 0.8;
    text-transform: uppercase;
}

.message.user .message-role {
    color: #a5b4fc;
}

.message.assistant .message-role {
    color: var(--success);
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: bounce 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;
}

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

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--surface-light);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--success));
    border-radius: 2px;
    animation: progressAnimation 2s ease-in-out infinite;
}

@keyframes progressAnimation {
    0% {
        width: 0%;
        margin-left: 0%;
    }
    50% {
        width: 70%;
        margin-left: 15%;
    }
    100% {
        width: 0%;
        margin-left: 100%;
    }
}

/* ============ ÀÔ·Â ¿µ¿ª ============ */

.input-container {
    display: flex;
    gap: 12px;
    background: var(--surface);
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    transition: border-color 0.3s;
}

.input-container:focus-within {
    border-color: var(--primary-color);
}

#userInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1em;
    resize: none;
    outline: none;
    font-family: inherit;
    max-height: 120px;
    transition: opacity 0.3s;
}

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

#userInput:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#sendButton {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#sendButton:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.05);
}

#sendButton:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#sendButton svg {
    transform: rotate(45deg);
}

#sendButton.stop-mode {
    background: var(--error);
}

#sendButton.stop-mode:hover {
    background: #dc2626;
}

#sendButton.stop-mode svg {
    transform: rotate(0deg);
}

/* ============ ¿À·ù ¸Þ½ÃÁö ============ */

.error-message {
    background: var(--error);
    color: white;
    padding: 12px;
    border-radius: 8px;
    margin: 10px 0;
    animation: slideIn 0.3s ease;
}

/* ============ ¹ÝÀÀÇü (¸ð¹ÙÀÏ) ============ */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .mobile-header {
        display: flex;
    }

    .desktop-header {
        display: none;
    }

    .message-content {
        max-width: 85%;
    }

    .input-container {
        padding: 12px 15px;
    }

    .chat-container {
        padding: 15px;
    }
}
