@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.css');

:root {
    --bg: #F4F7F5;
    --surface: #FFFFFF;
    --border: #E6ECE8;
    --header-bg: #FFFFFF;
    --header-border: #ECEFEC;
    --bot-bubble: #FFFFFF;
    --bot-bubble-border: #E6ECE8;
    --bot-text: #1F2A24;
    --user-bubble: #4F9C7E;
    --user-text: #FFFFFF;
    --accent: #2F6B53;
    --accent-soft: #E8F1EC;
    --muted: #6B7670;
    --status-ok: #3E8F6B;
    --input-bg: #FFFFFF;
    --input-border: #E6ECE8;
    --chip: #FFFFFF;
    --chip-border: #D8E2DC;
    --chip-text: #2F6B53;
    --chip-hover: #F0F5F1;
    --radius: 18px;
}

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

body {
    font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont,
                 system-ui, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
    font-feature-settings: 'ss06' 1, 'tnum' 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: #ECEAE4;
    height: 100vh;                          /* 폴백 */
    height: 100dvh;                         /* 최신 브라우저 */
    height: var(--app-height, 100dvh);      /* JS 폴백(구형 사파리 등) */
    position: fixed;                        /* 페이지 스크롤·바운스 차단 */
    inset: 0;
    overflow: hidden;
    overscroll-behavior: none;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px;
}

.container {
    width: 100%;
    max-width: 420px;
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    height: calc(var(--app-height, 100dvh) - 24px);
    max-height: 780px;
    background: var(--bg);
    border-radius: 24px;
    box-shadow: 0 18px 50px -16px rgba(20, 18, 16, 0.35), 0 2px 6px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 헤더 */
.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    flex-shrink: 0;
}

.bot-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--accent-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%232F6B53' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 2v3M10.5 2v3'/%3E%3Crect x='3.5' y='5' width='9' height='5' rx='1.5'/%3E%3Cpath d='M8 10v2.5a1.5 1.5 0 0 1-1.5 1.5H6'/%3E%3C/svg%3E") no-repeat center / 16px 16px;
}

.header-avatar {
    width: 32px;
    height: 32px;
    background-size: 18px 18px;
}

.header-info {
    flex: 1;
    min-width: 0;
}

.header-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--bot-text);
    line-height: 1.2;
}

.header-status {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--status-ok);
    display: inline-block;
}

/* 메시지 영역 */
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 14px 14px 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg);
}

/* 날짜 구분선 */
.date-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 2px 0 8px;
    color: var(--muted);
    font-size: 11.5px;
}

.date-divider::before,
.date-divider::after {
    content: none;
}

/* 메시지 스타일 */
.message {
    display: flex;
    animation: fade-in-up 0.25s ease;
}

@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    justify-content: flex-end;
    align-items: flex-end;
    gap: 6px;
}

.message.assistant {
    justify-content: flex-start;
    align-items: flex-end;
    gap: 8px;
}

/* 봇 메시지 좌측 아바타 (모든 assistant 행 공통) */
.message.assistant::before {
    content: '';
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--accent-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%232F6B53' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 2v3M10.5 2v3'/%3E%3Crect x='3.5' y='5' width='9' height='5' rx='1.5'/%3E%3Cpath d='M8 10v2.5a1.5 1.5 0 0 1-1.5 1.5H6'/%3E%3C/svg%3E") no-repeat center / 16px 16px;
}

.message-content {
    max-width: 78%;
    padding: 10px 13px;
    font-size: 14px;
    line-height: 1.5;
    word-break: keep-all;
    overflow-wrap: break-word;
}

.message.user .message-content {
    background: var(--user-bubble);
    color: var(--user-text);
    border-radius: var(--radius) var(--radius) 6px var(--radius);
}

.message.assistant .message-content {
    background: var(--bot-bubble);
    color: var(--bot-text);
    border: 1px solid var(--bot-bubble-border);
    border-radius: var(--radius) var(--radius) var(--radius) 6px;
}

.message.system .message-content {
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 10px;
    max-width: 80%;
}

/* 옵션(문의유형 등) 버튼 */
.intent-btn-group {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-btn {
    padding: 10px 14px;
    background: var(--chip);
    color: var(--chip-text);
    border: 1px solid var(--chip-border);
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.12s;
}

.option-btn:hover {
    background: var(--chip-hover);
}

.back-btn {
    color: #6B7670;
}

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

/* 새 문의 유도 드롭다운 (조회/접수 완료 후) */
.followup-dropdown {
    align-self: flex-start;
}

.followup-dropdown summary {
    list-style: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    font-family: inherit;
    align-self: flex-start;
    transition: color 0.2s, border-color 0.2s;
}

.followup-dropdown summary::-webkit-details-marker {
    display: none;
}

.followup-dropdown summary::after {
    content: "▾";
    font-size: 10px;
}

.followup-dropdown[open] summary::after {
    content: "▴";
}

.followup-dropdown summary:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.followup-dropdown .intent-btn-group {
    margin-top: 10px;
}

.followup-dropdown.locked summary {
    pointer-events: none;
    opacity: 0.5;
}

/* 액션 버튼 (동의 / 확인 등) */
.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 9px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    transition: filter 0.12s;
}

.btn-primary:hover {
    filter: brightness(0.95);
}

.btn-secondary {
    background: var(--chip);
    color: var(--muted);
    border: 1px solid var(--chip-border);
    border-radius: 12px;
    padding: 9px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.12s;
}

.btn-secondary:hover {
    background: var(--chip-hover);
}

.btn-primary:disabled,
.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 동의 카드 버튼 — 말풍선 폭을 꽉 채워 크게 노출 */
.consent-btn-group button {
    flex: 1;
    padding: 13px 16px;
    font-size: 15px;
}

/* 개인정보 입력 필드 */
.pi-input {
    padding: 11px 13px;
    border: 1px solid var(--input-border);
    border-radius: 10px;
    font-size: 16px;   /* iOS 포커스 자동확대 방지 (16px 미만 시 줌) */
    font-family: inherit;
    outline: none;
    background: var(--input-bg);
    color: var(--bot-text);
}

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

/* 로딩 인디케이터 */
.loading {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background: var(--bot-bubble);
    border: 1px solid var(--bot-bubble-border);
    border-radius: var(--radius) var(--radius) var(--radius) 6px;
}

.loading span {
    width: 6px;
    height: 6px;
    background: var(--muted);
    border-radius: 50%;
    animation: dot-bounce 1.2s ease-in-out infinite;
}

.loading span:nth-child(2) { animation-delay: 0.15s; }
.loading span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dot-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-3px); opacity: 1; }
}

/* 액션 오버레이 */
#actionOverlay {
    display: none;
    gap: 8px;
    width: 100%;
    margin-bottom: 8px;
}

#actionOverlay button {
    flex: 1;
}

/* 입력 영역 */
.chat-input-area {
    padding: 10px 12px 14px;
    border-top: 1px solid var(--header-border);
    background: var(--header-bg);
    flex-shrink: 0;
}

.input-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 22px;
    padding: 6px 8px 6px 16px;
    transition: border-color 0.15s;
}

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

.input-pill.input-dimmed {
    opacity: 0.6;            /* 상태조회 완료 등 잠금 시 약간 흐리게 */
    pointer-events: none;
}

/* 입력 잠금(문의 유형 선택 전 등) 시 회색 처리 — 비활성 시각 신호 */
.chat-input-area:has(input:disabled) {
    background: #ECEFED;
}
.input-pill:has(input:disabled) {
    background: #ECEFED;
    border-color: #DDE3E0;
}
.chat-input-area input:disabled {
    color: var(--muted);
    cursor: not-allowed;
}

.chat-input-area input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 16px;   /* iOS 포커스 자동확대 방지 (16px 미만 시 줌) */
    color: var(--bot-text);
    font-family: inherit;
    min-width: 0;
}

#sendBtn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    transition: color 0.15s, transform 0.15s;
    flex-shrink: 0;
}

#sendBtn:hover {
    transform: scale(1.08);
}

#sendBtn:active {
    transform: scale(0.95);
}

#sendBtn:disabled {
    color: var(--muted);
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* 스크롤바 스타일 */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* 메시지 시간 */
.message-time {
    font-size: 11px;
    color: #9AA39D;
    align-self: flex-end;
    white-space: nowrap;
    margin: 0 2px 2px;
}

.new-chat-btn {
    padding: 8px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.2s;
}

.new-chat-btn:hover { opacity: 0.88; }

.error {
    color: #b54a4a;
}

.pi-error {
    font-size: 12px;
    color: #b54a4a;
    margin-top: 3px;
    display: none;
}
