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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    height: 100vh;
    display: flex;
    justify-content: center;
}

#app {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    /* [P18-3-2-B] PWA standalone에서 OS 상태바와 헤더 겹침 방지.
       env(safe-area-inset-top)은 일반 브라우저 탭에서는 0px이라 회귀 0. */
    padding: calc(12px + env(safe-area-inset-top, 0px)) 20px 12px 20px;
    background: #16213e;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #0f3460;
}

header h1 {
    font-size: 1.2em;
    color: #e94560;
}

.header-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
}

.badge {
    background: #0f3460;
    color: #a8d8ea;
}

.badge-positive { background: #1b4332; color: #95d5b2; }
.badge-negative { background: #4a1525; color: #f08080; }
.badge-neutral { background: #2d3436; color: #b2bec3; }

select {
    background: #0f3460;
    color: #e0e0e0;
    border: 1px solid #533483;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.8em;
    cursor: pointer;
}

.btn-secondary {
    background: transparent;
    color: #a8d8ea;
    border: 1px solid #533483;
    border-radius: 6px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 0.8em;
}

.btn-secondary:hover {
    background: #533483;
}

/* [P12-5-5] 아이콘 버튼 (카톡 스타일) */
.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.icon-btn:hover {
    background: rgba(83, 52, 131, 0.3);
}
.icon-btn img {
    width: 20px;
    height: 20px;
}

#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

#messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 0.95em;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user {
    align-self: flex-end;
    background: #533483;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: #16213e;
    color: #e0e0e0;
    border-bottom-left-radius: 4px;
    border: 1px solid #0f3460;
}

/* [P17-1-3] assistant 메시지 안의 강조 + 링크 스타일 */
.message.assistant strong {
    font-weight: 700;
    color: #f0c674;       /* 약한 강조 — 본 다크 테마에서 가독성 우수 */
}
.message.assistant a {
    color: #88c0d0;
    text-decoration: underline;
    word-break: break-all;  /* 모바일 좁은 화면에서 긴 URL 줄바꿈 */
}
.message.assistant a:hover,
.message.assistant a:active {
    color: #5e81ac;
}

/* [P17-2] STT 토글 — 듣는 중 빨간 점 깜빡임 */
@keyframes stt-blink {
    0%, 100% { opacity: 1.0; transform: scale(1.0); }
    50%      { opacity: 0.55; transform: scale(1.15); }
}
#stt-toggle.listening {
    animation: stt-blink 1.0s ease-in-out infinite;
}

/* [P12-5-3] 메시지 시간 표시 (카톡 스타일) */
.message-time {
    font-size: 0.65em;
    color: #666;
    margin-top: 4px;
    line-height: 1;
}
.message.user .message-time {
    text-align: right;
}
.message.assistant .message-time {
    text-align: left;
}

.message.system {
    align-self: center;
    background: transparent;
    color: #888;
    font-size: 0.8em;
    font-style: italic;
}

.message.history {
    opacity: 0.7;
}

.message-separator {
    align-self: center;
    color: #666;
    font-size: 0.75em;
    padding: 8px 0;
    text-align: center;
    width: 100%;
    border-bottom: 1px solid #333;
    margin-bottom: 4px;
}

.typing-indicator {
    align-self: flex-start;
    padding: 10px 14px;
    background: #16213e;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    border: 1px solid #0f3460;
    color: #888;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

#input-area {
    /* [P18-3-2-B] PWA standalone에서 홈 인디케이터/제스처 영역 회피 */
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)) 16px;
    background: #16213e;
    display: flex;
    gap: 8px;
    border-top: 1px solid #0f3460;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #0f3460;
    border-radius: 20px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 0.95em;
    outline: none;
    resize: none;
    overflow-y: auto;
    min-height: 40px;
    max-height: 150px;
    line-height: 1.4;
    font-family: inherit;
}

#message-input:focus {
    border-color: #533483;
}

/* [P12-5-7] 전송 버튼: 원형 아이콘 (카톡 스타일) */
#send-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    background: #e94560;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

#send-btn:hover {
    background: #c23152;
}

#send-btn:disabled {
    background: #555;
    cursor: not-allowed;
}

#send-btn img {
    width: 18px;
    height: 18px;
}

#status-bar {
    padding: 6px 16px;
    background: #0f0f23;
    display: flex;
    justify-content: space-between;
    font-size: 0.7em;
    color: #666;
}

#connection-status {
    color: #4ecca3;
}

/* 스크롤바 */
#chat-container::-webkit-scrollbar {
    width: 6px;
}

#chat-container::-webkit-scrollbar-track {
    background: transparent;
}

#chat-container::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}
