/* ======================
   버튼 컴포넌트
   ====================== */

.btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn.primary {
    background: var(--gradient-accent);
    color: var(--text-inverse);
    border: none;
    font-weight: 600;
}

.btn.primary:hover {
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.btn.secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn.secondary:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.btn.small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn.large {
    padding: 14px 28px;
    font-size: 1.1rem;
}

/* 아이콘 버튼 */
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    font-size: 1rem;
    color: var(--text-secondary);
    border-radius: 6px;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--accent-primary);
}

/* ======================
   메시지 말풍선
   ====================== */

.message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 16px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: messageSlideIn 0.3s ease-out;
    position: relative;  /* message-actions 위치 기준점 */
}

/* ==================== 스트리밍 상태 ==================== */
.message.streaming .message-content::after {
    content: '▋';
    animation: cursorBlink 1s infinite;
    color: var(--accent-primary);
    font-weight: bold;
}

@keyframes cursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* 스트리밍 중에는 액션 버튼 숨김 */
.message.streaming .message-actions {
    display: none;
}

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

.message.user,
.message-user {
    align-self: flex-end;
    background: var(--gradient-accent);
    color: var(--text-inverse);
    border-bottom-right-radius: 4px;
}

.message.assistant,
.message-ai {
    align-self: flex-start;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-accent);
    border-bottom-left-radius: 4px;
}

.message-content {
    white-space: pre-wrap;
}

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

.message-content code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

/* Markdown 헤딩 */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    margin: 16px 0 12px 0;
    line-height: 1.3;
    color: var(--text-primary);
}

.message-content h1 { font-size: 1.6em; font-weight: 700; border-bottom: 2px solid var(--border); padding-bottom: 8px; }
.message-content h2 { font-size: 1.4em; font-weight: 700; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.message-content h3 { font-size: 1.2em; font-weight: 600; color: var(--accent-primary); }
.message-content h4 { font-size: 1.1em; font-weight: 600; color: var(--text-secondary); }

/* Markdown 리스트 */
.message-content ul,
.message-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 6px 0;
    line-height: 1.6;
}

.message-content ul li {
    list-style-type: disc;
}

.message-content ol li {
    list-style-type: decimal;
}

/* Markdown 코드 블록 */
.message-content pre {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin: 12px 0;
    overflow-x: auto;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    font-size: 0.9em;
    line-height: 1.5;
    display: block;
}

/* Markdown 표 (Table) */
.message-content .table-wrapper {
    overflow-x: auto;
    margin: 16px 0;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.message-content table thead {
    background: var(--bg-secondary);
}

.message-content table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: var(--accent-primary);
    border-bottom: 2px solid var(--border);
}

.message-content table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.message-content table tbody tr:hover {
    background: var(--bg-secondary);
}

.message-content table tbody tr:last-child td {
    border-bottom: none;
}

/* Markdown 인용구 (Blockquote) */
.message-content blockquote,
.message-content .markdown-quote {
    margin: 16px 0;
    padding: 12px 16px;
    border-left: 4px solid var(--accent-primary);
    background: var(--bg-secondary);
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: var(--text-secondary);
}

.message-content blockquote p,
.message-content .markdown-quote p {
    margin: 0;
}

/* Markdown 링크 */
.message-content a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.message-content a:hover {
    border-bottom-color: var(--accent-primary);
}

/* Markdown 수평선 */
.message-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* Markdown 단락 간격 */
.message-content p {
    margin: 12px 0;
    line-height: 1.7;
}

.message-content p:first-child {
    margin-top: 0;
}

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

/* 중첩 리스트 스타일 개선 */
.message-content li > ul,
.message-content li > ol {
    margin-top: 6px;
    margin-bottom: 6px;
}

.message-content ul ul li {
    list-style-type: circle;
}

.message-content ul ul ul li {
    list-style-type: square;
}

.message-meta {
    font-size: 0.75rem;
    margin-top: 8px;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ======================
   카드 컴포넌트
   ====================== */

.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    transition: all var(--transition-normal);
}

.card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
}

.card h2,
.card h3 {
    color: var(--text-primary);
    margin-bottom: 12px;
}

/* ======================
   그라데이션 요소
   ====================== */

.gradient-accent {
    background: var(--gradient-accent);
}

.gradient-text {
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 600;
}

/* ======================
   상태 표시
   ====================== */

.status {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
}

.status.success {
    background: rgba(0, 255, 0, 0.15);
    color: var(--success);
    border: 1px solid var(--success);
}

.status.warning {
    background: rgba(255, 215, 0, 0.15);
    color: var(--warning);
    border: 1px solid var(--warning);
}

.status.error {
    background: rgba(255, 68, 68, 0.15);
    color: var(--error);
    border: 1px solid var(--error);
}

.status.info {
    background: rgba(0, 191, 255, 0.15);
    color: var(--info);
    border: 1px solid var(--info);
}

/* ======================
   Provider Status (특수)
   ====================== */

.provider-status {
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
}

.provider-status.success {
    background: rgba(0, 255, 0, 0.2);
    color: var(--success);
}

.provider-status.warning {
    background: rgba(255, 215, 0, 0.2);
    color: var(--warning);
}

.provider-status.error {
    background: rgba(255, 68, 68, 0.2);
    color: var(--error);
}

/* ======================
   입력 필드
   ====================== */

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: all var(--transition-fast);
    width: 100%;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-tertiary);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 255, 0, 0.1);
}

.light-mode input:focus,
.light-mode textarea:focus,
.light-mode select:focus {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* ======================
   로딩 스피너
   ====================== */

.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading p {
    color: var(--text-primary);
    margin-top: 16px;
    font-size: 1rem;
}

/* ======================
   모달
   ====================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 1000px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    gap: 16px;
}

.modal-header h2 {
    font-size: 1.25rem;
    margin: 0;
    color: var(--text-primary);
}

.modal-close {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--error);
    color: white;
}

.modal-body {
    flex: 1;
    overflow: hidden;
    padding: 20px 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    gap: 12px;
}

/* ======================
   툴팁
   ====================== */

.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: 100;
}

.tooltip:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-4px);
}
