﻿/* ============================================
   Chat Interface - Styles
   @task S2F3
   ============================================ */

/* 모바일 브라우저 body 스크롤 방지 */
html.chat-page {
    height: 100%;
    overflow: hidden;
}

.chat-body {
    background: #0f0f1a;
    height: 100vh;
    height: 100dvh; /* 모바일 주소창 고려 */
    max-height: 100vh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
}

/* === Header === */
.chat-header {
    display: flex;
    flex-direction: column;
    padding: var(--space-3) var(--space-4);
    background: rgba(15, 15, 26, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(20px);
    z-index: 10;
    gap: 6px;
}

.chat-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.chat-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.chat-avatar {
    display: none;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    display: none !important;
}

.chat-bot-name {
    color: white;
    font-size: var(--font-size-base);
    font-weight: 700;
}

.chat-status {
    font-size: 0.7rem;
    color: var(--success-500);
}

.chat-header-right {
    display: flex;
    gap: var(--space-2);
}

/* Voice selector */
.voice-select {
    height: 30px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.7rem;
    padding: 0 6px;
    outline: none;
    cursor: pointer;
}

.voice-select option {
    background: #1e293b;
    color: #f1f5f9;
}

.chat-header-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.06);
    border: none;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* === Messages === */
.chat-messages {
    flex: 1;
    min-height: 0; /* flex 자식 overflow 보장 */
    overflow-y: auto;
    padding: var(--space-3) var(--space-4) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.chat-welcome {
    text-align: center;
    padding: var(--space-3) var(--space-4);
}

.chat-welcome-avatar {
    font-size: 3rem;
    margin-bottom: var(--space-4);
}

.chat-welcome h2 {
    color: white;
    margin-bottom: var(--space-2);
}

.chat-welcome p {
    color: rgba(255, 255, 255, 0.5);
    font-size: var(--font-size-sm);
}

/* FAQ buttons */
.chat-faq-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: center;
    padding: 0 var(--space-4);
}

.faq-btn {
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: var(--primary-300);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
    max-width: 200px;
    text-align: center;
}

.faq-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--primary-400);
}

/* Message bubbles */
.message {
    display: flex;
    gap: var(--space-2);
    max-width: 85%;
    animation: slideUp 0.3s ease;
}

.message-bot {
    align-self: flex-start;
}

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

.message-system {
    align-self: center;
    max-width: 90%;
    justify-content: center;
}

.message-system .message-bubble {
    background: transparent;
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.78rem;
    text-align: center;
    padding: var(--space-2);
}

.message-system .message-bubble.cpc-result {
    color: #7dd3fc;
    font-size: 0.82rem;
    background: rgba(56, 189, 248, 0.08);
    border-radius: 8px;
    padding: 6px 12px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

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

.message-bubble {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-xl);
    font-size: var(--font-size-sm);
    line-height: 1.6;
    max-width: 100%;
    word-wrap: break-word;
}

.message-bot .message-bubble {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.9);
    border-bottom-left-radius: var(--radius-sm);
}

.message-user .message-bubble {
    background: var(--primary-500);
    color: white;
    border-bottom-right-radius: var(--radius-sm);
}

.message-time {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.3);
    margin-top: var(--space-1);
}

.message-bot .message-time {
    text-align: left;
}

.message-user .message-time {
    text-align: right;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: var(--space-3) var(--space-4);
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

@keyframes typingBounce {

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

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

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

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

/* === Input Area === */
.chat-input-area {
    flex-shrink: 0; /* 모바일에서 밀려나지 않게 */
    padding: var(--space-3) var(--space-4);
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
    background: rgba(15, 15, 26, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-2xl);
    padding: var(--space-1) var(--space-2);
}

.chat-voice-btn,
.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.chat-voice-btn {
    background: transparent;
    font-size: 1.2rem;
}

.chat-voice-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.chat-voice-btn.recording {
    background: rgba(239, 68, 68, 0.2);
    animation: pulse-record 1.5s infinite;
}

.chat-send-btn {
    background: var(--primary-500);
    color: white;
}

.chat-send-btn:hover {
    background: var(--primary-600);
}

.chat-send-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-size: var(--font-size-sm);
    padding: var(--space-2) 0;
    resize: none;
    max-height: 120px;
    min-height: 40px;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
}

.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.chat-header-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    margin-top: 4px;
}

.persona-selection-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 4px;
    width: 100%;
}

.persona-row {
    display: flex;
    gap: 5px;
    width: 100%;
}

.persona-selection-container::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
}

.persona-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 4px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.72rem;
    cursor: pointer;
    white-space: nowrap;
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.persona-chip:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.persona-chip.active {
    background: var(--primary-500);
    border-color: var(--primary-400);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* 대외용 (avatar) — 파란 계열 */
.chip-public {
    background: rgba(99, 130, 241, 0.12);
    border-color: rgba(99, 130, 241, 0.25);
    color: rgba(180, 200, 255, 0.85);
}
.chip-public:hover {
    background: rgba(99, 130, 241, 0.22);
    border-color: rgba(99, 130, 241, 0.4);
}
.chip-public.active {
    background: var(--primary-500);
    border-color: var(--primary-400);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* 대내용 (helper) — 초록 계열 */
.chip-private {
    background: rgba(52, 211, 153, 0.1);
    border-color: rgba(52, 211, 153, 0.2);
    color: rgba(167, 230, 200, 0.85);
}
.chip-private:hover {
    background: rgba(52, 211, 153, 0.2);
    border-color: rgba(52, 211, 153, 0.35);
}
.chip-private.active {
    background: #059669;
    border-color: #34d399;
    color: white;
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
}

.persona-chip-icon {
    font-size: 0.9rem;
}

.persona-chip-name {
    font-weight: 600;
}

/* === CSS Avatar (Legacy Port) === */
.chat-avatar-stage {
    padding: var(--space-3) var(--space-4) var(--space-4);
    background: rgba(15, 15, 26, 0.5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    justify-content: center;
    transition: all 0.3s;
}

.avatar-container {
    width: 120px;
    height: 140px;
    position: relative;
    text-align: center;
}

.avatar-face {
    width: 120px;
    height: 140px;
    margin: 0 auto;
    position: relative;
    transform: scale(0.85);
    transform-origin: top center;
}

.head {
    width: 120px;
    height: 120px;
    background: linear-gradient(135deg, #ffd89b 0%, #19547b 100%);
    border-radius: 50% 50% 45% 45%;
    position: relative;
    animation: float 3s ease-in-out infinite;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-8px);
    }
}

.hair {
    width: 110px;
    height: 60px;
    background: #2c3e50;
    border-radius: 50% 50% 0 0;
    position: absolute;
    top: -5px;
    left: 5px;
    transition: all 0.5s;
}

.eyes {
    position: absolute;
    width: 100%;
    top: 45px;
    display: flex;
    justify-content: center;
    gap: 30px;
}

.eye {
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    position: relative;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.pupil {
    width: 10px;
    height: 10px;
    background: #2c3e50;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.nose {
    width: 6px;
    height: 10px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
}

.mouth {
    width: 40px;
    height: 20px;
    position: absolute;
    top: 85px;
    left: 50%;
    transform: translateX(-50%);
    overflow: hidden;
}

.mouth::after {
    content: '';
    width: 40px;
    height: 40px;
    background: transparent;
    border: 3px solid #e74c3c;
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;
    transition: all 0.3s;
}

.neck {
    width: 40px;
    height: 25px;
    background: linear-gradient(135deg, #ffd89b 0%, #19547b 100%);
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 0 0 8px 8px;
    z-index: -1;
}

/* Emotions */
.avatar-face.happy .mouth::after {
    border-color: #27ae60;
    top: -5px;
}

.avatar-face.happy .head {
    animation: bounce 0.5s ease infinite;
}

@keyframes bounce {

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

    50% {
        transform: scale(1.05);
    }
}

.avatar-face.sad .mouth::after {
    border-color: #3498db;
    top: 12px;
    transform: rotate(180deg);
}

.avatar-face.thinking .pupil {
    transform: translate(-30%, -50%);
}

.avatar-face.thinking .head {
    animation: tilt 2s ease-in-out infinite;
}

@keyframes tilt {

    0%,
    100% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(5deg);
    }
}

/* Accessories (Personas) */
.accessory {
    position: absolute;
    font-size: 24px;
    opacity: 0;
    transition: all 0.5s;
    z-index: 5;
}

/* New 5 Personas Mapping */
/* AI Master */
.avatar-face.persona-ai .accessory {
    content: '?쭬';
    top: -15px;
    right: 0px;
    opacity: 1;
    font-size: 28px;
}

.avatar-face.persona-ai .hair {
    background: #95a5a6;
    height: 50px;
}

/* Startup Accelerator */
.avatar-face.persona-startup .accessory {
    content: '??';
    top: 90px;
    right: -10px;
    opacity: 1;
    font-size: 24px;
}

.avatar-face.persona-startup .hair {
    background: #2c3e50;
    height: 55px;
}

/* CPA */
.avatar-face.persona-cpa .accessory {
    content: '?㎜';
    top: 85px;
    left: 10px;
    opacity: 1;
    font-size: 26px;
}

.avatar-face.persona-cpa .hair {
    background: #34495e;
    height: 45px;
}

/* Star Lover */
.avatar-face.persona-star .accessory {
    content: '?뵯';
    top: 50px;
    left: -15px;
    opacity: 1;
    font-size: 30px;
}

.avatar-face.persona-star .hair {
    background: linear-gradient(to right, #240b36, #c31432);
    height: 70px;
}

/* Pure Lifer */
.avatar-face.persona-life .accessory {
    content: '?뙼';
    top: 95px;
    left: 50%;
    transform: translateX(-50%);
    opacity: 1;
    font-size: 24px;
}

.avatar-face.persona-life .hair {
    background: #8d6e63;
    height: 60px;
}

.emotion-label {
    margin-top: 10px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
}

/* Mobile: 4 per row, 2 rows */
@media (max-width: 600px) {
  .persona-selection-container {
      width: calc(100vw - 32px);
      max-width: none;
  }
  .persona-row {
      gap: 4px;
  }
  .persona-chip {
      flex: 1 1 calc((100% - 12px) / 4);
      max-width: calc((100% - 12px) / 4);
      font-size: 0.6rem;
      padding: 5px 2px;
  }
}


/* Title row + header buttons alignment */
.chat-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

@media (max-width: 600px) {
  .chat-header-right {
      gap: 4px;
  }

  .chat-bot-name {
      padding-right: 0;
  }
}

/* ============================================
   Light Mode Overrides
   ============================================ */
.chat-body.light {
    background: #f5f5fa;
}

.chat-body.light .chat-header {
    background: rgba(255, 255, 255, 0.95);
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

.chat-body.light .chat-bot-name {
    color: #1a1a2e;
}

.chat-body.light .chat-welcome h2 {
    color: #1a1a2e;
}

.chat-body.light .chat-welcome p {
    color: rgba(0, 0, 0, 0.5);
}

.chat-body.light .chat-header-btn {
    background: rgba(0, 0, 0, 0.06);
    color: #333;
}

.chat-body.light .chat-header-btn:hover {
    background: rgba(0, 0, 0, 0.12);
}

.chat-body.light .persona-chip {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
    color: rgba(0, 0, 0, 0.6);
}

.chat-body.light .persona-chip:hover {
    background: rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.2);
}

.chat-body.light .persona-chip.active {
    background: var(--primary-500);
    border-color: var(--primary-400);
    color: white;
}

.chat-body.light .message-bot .message-bubble {
    background: rgba(0, 0, 0, 0.05);
    color: #1a1a2e;
}

.chat-body.light .message-user .message-bubble {
    background: var(--primary-500);
    color: white;
}

.chat-body.light .message-system .message-bubble {
    color: rgba(0, 0, 0, 0.4);
}

.chat-body.light .message-time {
    color: rgba(0, 0, 0, 0.3);
}

.chat-body.light .chat-input-area {
    background: rgba(255, 255, 255, 0.95);
    border-top-color: rgba(0, 0, 0, 0.08);
}

.chat-body.light .chat-input-container {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
}

.chat-body.light .chat-input {
    color: #1a1a2e;
}

.chat-body.light .chat-input::placeholder {
    color: rgba(0, 0, 0, 0.35);
}

.chat-body.light .voice-select {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
    color: #333;
}

.chat-body.light .voice-select option {
    background: #fff;
    color: #333;
}

.chat-body.light .chat-voice-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

.chat-body.light .faq-btn {
    background: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.15);
    color: var(--primary-600);
}

.chat-body.light .faq-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary-400);
}

.chat-body.light .chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
}

.chat-body.light .emotion-label {
    color: rgba(0, 0, 0, 0.5);
}

/* Per-message speaker button */
.msg-tts-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    opacity: 0.4;
    padding: 2px 4px;
    margin-left: 4px;
    transition: opacity 0.2s;
    vertical-align: middle;
}

.msg-tts-btn:hover {
    opacity: 0.8;
}

.msg-tts-btn.playing {
    opacity: 1;
    animation: pulse-speaker 1s infinite;
}

@keyframes pulse-speaker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-body.light .msg-tts-btn {
    color: #333;
}

/* === CPC Platoon Selector Bar === */
.cpc-bar {
    flex-shrink: 0;
    padding: 4px 12px;
    background: rgba(16, 185, 129, 0.08);
    border-top: 1px solid rgba(16, 185, 129, 0.2);
}

.cpc-bar-inner {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 자율모드 토글 버튼 */
.cpc-autonomous-btn {
    padding: 2px 8px;
    border-radius: 6px;
    border: 1px solid rgba(160, 160, 160, 0.3);
    background: transparent;
    color: #999;
    font-size: 1.05rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: auto;
}
.cpc-autonomous-btn:hover { background: rgba(220, 60, 60, 0.1); color: #e05555; }
.cpc-autonomous-btn.autonomous-on {
    background: rgba(220, 40, 40, 0.15);
    border-color: #e04040;
    color: #e04040;
    box-shadow: 0 0 6px rgba(220, 40, 40, 0.35);
}
.chat-body.light .cpc-autonomous-btn { color: #aaa; border-color: rgba(160,160,160,0.3); }
.chat-body.light .cpc-autonomous-btn.autonomous-on { background: rgba(220,40,40,0.1); color: #d03030; }

.cpc-bar-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #10b981;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.cpc-select {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.8rem;
    padding: 3px 6px;
    height: 28px;
    outline: none;
    cursor: pointer;
}

.cpc-select option {
    background: #1e293b;
    color: #f1f5f9;
    font-size: 0.8rem;
}

.cpc-select optgroup {
    background: #0f172a;
    color: #94a3b8;
    font-weight: 600;
    font-size: 0.8rem;
}

.cpc-status {
    font-size: 0.65rem;
    color: #10b981;
    flex-shrink: 0;
    font-weight: 600;
}

.cpc-status.cpc-running {
    color: #f59e0b;
    animation: cpc-pulse 1.5s ease-in-out infinite;
}

.cpc-remote-link {
    color: #60a5fa;
    text-decoration: underline;
    word-break: break-all;
    font-weight: 600;
}
.cpc-remote-link:hover {
    color: #93c5fd;
}

@keyframes cpc-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-body.light .cpc-bar {
    background: rgba(16, 185, 129, 0.06);
    border-top-color: rgba(16, 185, 129, 0.15);
}

.chat-body.light .cpc-select {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(16, 185, 129, 0.2);
    color: #1a1a2e;
}

.chat-body.light .cpc-select option {
    background: #fff;
    color: #1a1a2e;
}

.chat-body.light .cpc-select optgroup {
    background: #f5f5f5;
    color: #666;
}
