/* 유해동팬보이 채팅 에이전트 */
:root {
    --primary: #EA580C;
    --primary-light: #FB923C;
    --primary-dark: #C2410C;
    --accent: #DC2626;
    --bg: #D5D5DE;
    --surface: #FFFFFF;
    --text: #1A1A2E;
    --text-secondary: #6B7280;
    --text-light: #9CA3AF;
    --border: #E5E7EB;
    --user-bubble: #6B9E7D;
    --bot-bubble: #FFFFFF;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
}

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

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ========== 로그인 화면 ========== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100dvh;
    padding: 20px;
    background: linear-gradient(160deg, #FFF7ED 0%, #F0F0F5 50%, #FEF2F2 100%);
}

.login-box {
    background: var(--surface);
    border-radius: 24px;
    padding: 48px 36px;
    max-width: 380px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-box .emoji {
    width: 72px;
    height: 72px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, #FFF7ED, #FFEDD5);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
}

.login-box h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
    letter-spacing: -0.3px;
}

.login-box p {
    color: var(--text-secondary);
    margin-bottom: 28px;
    font-size: 14px;
    line-height: 1.6;
}

.login-box .login-hint {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 8px;
    text-align: left;
}

.login-box input[type="text"] {
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid var(--border);
    border-radius: 14px;
    font-size: 15px;
    outline: none;
    transition: all 0.2s;
    background: #FAFAFA;
}

.login-box input[type="text"]:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.1);
}

.login-box button {
    width: 100%;
    margin-top: 12px;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.3px;
}

.login-box button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(234, 88, 12, 0.3);
}

.login-box button:active { transform: translateY(0); }

/* ========== 채팅 레이아웃 ========== */
.chat-container {
    display: none;
    flex-direction: column;
    height: 100dvh;
    max-width: 720px;
    margin: 0 auto;
    background: #F0F0F5;
}

.chat-container.active { display: flex; }

/* ========== 헤더 ========== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.chat-header .bot-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    background: linear-gradient(135deg, #FFF7ED, #FFEDD5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chat-header .bot-name {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.2px;
}

.chat-header .bot-status {
    font-size: 12px;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-header .bot-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
}

.chat-header .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-header .user-info .logout-btn {
    background: var(--bg);
    border: none;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.chat-header .user-info .logout-btn:hover {
    background: #E5E7EB;
    color: var(--text);
}

/* ========== 메시지 영역 ========== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 4px; }

.message {
    display: flex;
    gap: 10px;
    max-width: 82%;
    animation: fadeIn 0.35s ease;
}

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

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

.message .avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    background: linear-gradient(135deg, #FFF7ED, #FFEDD5);
    margin-top: 2px;
}

.message .bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14.5px;
    line-height: 1.7;
    word-break: break-word;
    white-space: pre-wrap;
}

.message.user .bubble {
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 8px rgba(107, 158, 125, 0.2);
}

.message.bot .bubble {
    background: var(--bot-bubble);
    color: var(--text);
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0,0,0,0.04);
}

/* 이라스토야 일러스트 */
.bubble-illustration {
    display: block;
    width: 120px;
    height: 120px;
    object-fit: contain;
    margin: 0 0 8px 0;
}

@media (min-width: 601px) {
    .bubble-illustration {
        float: left;
        margin: 0 12px 4px 0;
    }
}

/* 마크다운 요소 스타일 */
.message.bot .bubble strong {
    color: var(--accent);
    font-weight: 700;
}

.message.bot .bubble blockquote strong {
    color: #374151;
    font-weight: 600;
}

.message.bot .bubble blockquote {
    margin: 8px 0;
    padding: 10px 14px;
    background: #FFF7ED;
    border-left: 3px solid #FBBF24;
    border-radius: 0 8px 8px 0;
    color: #374151;
    font-size: 13.5px;
    line-height: 1.7;
}

.message.bot .bubble ul {
    margin: 6px 0;
    padding-left: 8px;
    list-style: none;
}

.message.bot .bubble li {
    position: relative;
    padding: 3px 0 3px 16px;
    line-height: 1.6;
}

.message.bot .bubble li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 11px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-light);
}

.message.bot .bubble code {
    background: #FFF7ED;
    color: #C2410C;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* 출처 */
.message .bubble .sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.message .bubble .sources a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.15s;
}

.message .bubble .sources a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* ========== 타이핑 인디케이터 (메시지 흐름 안) ========== */
.typing-indicator {
    display: none;
    gap: 10px;
    align-self: flex-start;
    max-width: 82%;
    animation: fadeIn 0.35s ease;
}

.typing-indicator.active { display: flex; }

.typing-indicator .avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    background: linear-gradient(135deg, #FFF7ED, #FFEDD5);
    margin-top: 2px;
}

.typing-indicator .typing-dots {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 14px 18px;
    background: var(--surface);
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0,0,0,0.04);
}

.typing-indicator .typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary-light);
    animation: typing 1.4s ease-in-out infinite;
}

.typing-indicator .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ========== 입력 영역 ========== */
.chat-input-area {
    padding: 12px 16px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.03);
}

.chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 100%;
    background: var(--bg);
    border-radius: 16px;
    padding: 6px 6px 6px 16px;
    border: 1.5px solid transparent;
    transition: all 0.2s;
}

.chat-input-wrap:focus-within {
    border-color: var(--primary-light);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.08);
}

.chat-input-wrap textarea {
    flex: 1;
    padding: 8px 0;
    border: none;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.5;
    background: transparent;
    color: var(--text);
}

.chat-input-wrap textarea::placeholder { color: var(--text-light); }

.chat-input-wrap button {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: #6B9E7D;
    color: white;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-input-wrap button:hover {
    background: #5A8A6A;
    transform: scale(1.05);
}

.chat-input-wrap button:active { transform: scale(0.95); }
.chat-input-wrap button:disabled { background: #D1D5DB; cursor: not-allowed; transform: none; }

/* ========== 관리자 페이지 ========== */
.admin-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.admin-header h1 { font-size: 22px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* 테이블 */
.video-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.video-table th, .video-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.video-table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.video-table tr:last-child td { border-bottom: none; }
.video-table tr:hover td { background: #FAFBFC; }

.status-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
}

.status-pending { background: #FEF3C7; color: #92400E; }
.status-downloading { background: #DBEAFE; color: #1E40AF; }
.status-downloaded { background: #D1FAE5; color: #065F46; }
.status-processing { background: #E0E7FF; color: #3730A3; }
.status-completed { background: #D1FAE5; color: #065F46; }
.status-failed { background: #FEE2E2; color: #991B1B; }

.stats-bar {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.stat-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    flex: 1;
    min-width: 140px;
}

.stat-card .label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-card .value { font-size: 24px; font-weight: 700; }

.progress-log {
    background: #1E293B;
    color: #94A3B8;
    border-radius: 10px;
    padding: 16px;
    margin-top: 16px;
    max-height: 200px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.8;
    display: none;
}

.progress-log.active { display: block; }
.progress-log .info { color: #60A5FA; }
.progress-log .success { color: #34D399; }
.progress-log .error { color: #F87171; }

/* ========== 반응형 ========== */
@media (max-width: 600px) {
    .chat-header { padding: 12px 14px; }
    .chat-messages { padding: 14px 12px; gap: 14px; }
    .chat-input-area { padding: 10px 12px 14px; }
    .message { max-width: 88%; }
    .message .avatar { display: none; }
    .typing-indicator .avatar { display: none; }
    .message .bubble { font-size: 14px; padding: 11px 14px; }
    .admin-container { padding: 12px; }
    .stats-bar { gap: 8px; }
    .stat-card { padding: 12px; min-width: 100px; }
    .stat-card .value { font-size: 20px; }
    .login-box { padding: 36px 28px; }
}
