/* 전역 스타일 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border: #334155;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 사이드바 */
.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

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

.sidebar-header h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
}

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

.new-chat-btn:hover {
    background: var(--accent-hover);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.history-item {
    padding: 0.875rem;
    margin-bottom: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.history-item:hover {
    background: #475569;
}

.history-item.active {
    background: var(--accent);
}

.history-coin {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.history-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.history-delete {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: var(--error);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

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

/* 메인 콘텐츠 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    padding: 2rem;
    min-height: 0; /* Flexbox 스크롤 fix */
    height: 100%;
}

.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 0;
    scroll-behavior: smooth;
    max-height: 100%;
    min-height: 0; /* Flexbox 스크롤 fix */
}

/* 환영 메시지 */
.welcome-message {
    text-align: center;
    padding: 4rem 2rem;
}

.welcome-message h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.welcome-message p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.welcome-message .subtitle {
    font-size: 0.95rem;
    margin-bottom: 2rem;
}

.example-coins {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.coin-tag {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.coin-tag:hover {
    background: var(--accent);
    transform: translateY(-2px);
}

/* 메시지 */
.message {
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease;
}

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

.message-user {
    background: var(--bg-tertiary);
    padding: 1rem 1.25rem;
    border-radius: 12px;
    display: inline-block;
    max-width: 80%;
    margin-left: auto;
}

.message-assistant {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

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

/* 진행 상황 메시지 */
.progress-message {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    border-left: 3px solid var(--accent);
}

.progress-message.info {
    border-left-color: #3b82f6;
    background: rgba(59, 130, 246, 0.15);
    font-weight: 500;
    padding: 1rem 1.25rem;
}

.progress-message.phase1 {
    border-left-color: #3b82f6;
}

.progress-message.phase3 {
    border-left-color: #f59e0b;
}

.progress-message.final {
    border-left-color: #8b5cf6;
}

.progress-message.complete {
    border-left-color: var(--success);
}

.spinner {
    display: inline-block;
    font-size: 1.2rem;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { content: '⣾'; }
    12.5% { content: '⣽'; }
    25% { content: '⣻'; }
    37.5% { content: '⢿'; }
    50% { content: '⡿'; }
    62.5% { content: '⣟'; }
    75% { content: '⣯'; }
    87.5% { content: '⣷'; }
    100% { content: '⣾'; }
}

/* 입력 영역 */
.input-container {
    padding: 1rem 0;
    border-top: 1px solid var(--border);
}

.input-form {
    display: flex;
    gap: 0.75rem;
    background: var(--bg-secondary);
    padding: 0.75rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

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

#coinInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    padding: 0.5rem;
}

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

#sendBtn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#sendBtn:hover:not(:disabled) {
    background: var(--accent-hover);
}

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

/* 마크다운 스타일 */
.message-content h1 {
    font-size: 1.8rem;
    margin: 1.5rem 0 1rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.5rem;
}

.message-content h2 {
    font-size: 1.4rem;
    margin: 1.25rem 0 0.75rem;
    color: var(--accent);
}

.message-content h3 {
    font-size: 1.1rem;
    margin: 1rem 0 0.5rem;
}

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

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

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

.message-content code {
    background: var(--bg-tertiary);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1rem;
    max-width: 100%;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    display: block;
    overflow-x: auto;
    max-width: 100%;
}

.message-content thead,
.message-content tbody,
.message-content tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.message-content th, .message-content td {
    border: 1px solid var(--border);
    padding: 0.75rem;
    text-align: left;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.message-content th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.message-content blockquote {
    border-left: 4px solid var(--accent);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--text-secondary);
}

.message-content strong {
    color: var(--accent);
    font-weight: 600;
}

/* 스크롤바 */
::-webkit-scrollbar {
    width: 8px;
}

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

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

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

/* 안내 메시지 */
.notice-message {
    background: rgba(59, 130, 246, 0.1);
    border: 2px solid var(--accent);
    border-radius: 12px;
    padding: 1.5rem;
    margin: 1rem 0;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.notice-icon {
    font-size: 2rem;
    line-height: 1;
}

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

.notice-content strong {
    color: var(--accent);
}

.notice-content em {
    color: var(--text-secondary);
    font-style: normal;
}

/* 에러 메시지 */
.error-message-box {
    background: rgba(239, 68, 68, 0.1);
    border: 2px solid var(--error);
    border-radius: 12px;
    padding: 1.5rem;
    margin: 1rem 0;
}

.error-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--error);
    margin-bottom: 0.75rem;
}

.error-content {
    color: var(--text-primary);
    line-height: 1.6;
    white-space: pre-wrap;
}

/* 반응형 */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 1000;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .chat-container {
        padding: 1rem;
    }

    .welcome-message h1 {
        font-size: 2rem;
    }
}

