:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --header-gradient: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
    --send-bg: #667eea;
    --send-color: white;
    --receive-bg: #f0f2f5;
    --receive-text: #1a1a2e;
    --page-background: #f8f9fa;
    --card-bg: #ffffff;
    --accent-color: #667eea;
    --border-radius: 20px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.15);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    font-weight: 400;
    background: var(--page-background);
    color: var(--receive-text);
}

/* 채팅 컨테이너 */
#chat-container {
    width: 100%;
    height: 100vh;
    max-width: none;
    background: var(--card-bg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* 헤더 */
#chat-header {
    background: linear-gradient(135deg, #1565c0 0%, #0d47a1 50%, #1a237e 100%);
    color: white;
    padding: 10px 20px;
    text-align: center;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(13, 71, 161, 0.3);
    position: relative;
    z-index: 10;
}

.header-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding-right: 36px;
}

.header-content h1 {
    margin: 0;
    font-size: 1.1em;
    font-weight: 500;
    letter-spacing: -0.2px;
    color: rgba(255, 255, 255, 0.95);
}

.header-content h1 .brand {
    font-weight: 700;
    color: #fff;
    margin-left: 4px;
}

.header-content .languages {
    margin: 0;
    font-size: 0.65em;
    opacity: 0.7;
    letter-spacing: 0.2px;
    color: rgba(255, 255, 255, 0.8);
}

/* 메뉴 버튼 */
#menu-btn {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#menu-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* 메뉴 드롭다운 */
#menu-dropdown {
    position: absolute;
    top: 100%;
    right: 16px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    overflow: hidden;
    min-width: 160px;
    margin-top: 4px;
}

#menu-dropdown.hidden {
    display: none;
}

#menu-dropdown button {
    display: block;
    width: 100%;
    padding: 12px 18px;
    background: none;
    border: none;
    text-align: left;
    font-size: 0.88em;
    font-family: inherit;
    color: var(--receive-text);
    cursor: pointer;
    transition: background 0.15s;
}

#menu-dropdown button:hover {
    background: rgba(102, 126, 234, 0.08);
}

#menu-dropdown button.share-menu-btn {
    color: var(--accent-color);
    font-weight: 600;
}

#menu-dropdown button:not(:last-child) {
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

/* 토스트 알림 */
.toast {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 0.85em;
    z-index: 300;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.toast.hidden {
    opacity: 0;
}

/* 모달 오버레이 */
#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

#modal-overlay.hidden {
    display: none;
}

#modal-content {
    background: var(--card-bg);
    border-radius: 16px;
    width: 100%;
    max-width: 440px;
    max-height: 75vh;
    overflow-y: auto;
    padding: 28px 24px;
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

#modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
}

#modal-close:hover {
    color: #333;
    background: rgba(0, 0, 0, 0.06);
}

#modal-body {
    line-height: 1.7;
    font-size: 0.9em;
    color: var(--receive-text);
}

#modal-body h2 {
    margin: 0 0 16px 0;
    font-size: 1.15em;
    font-weight: 700;
    color: #1565c0;
}

#modal-body h3 {
    margin: 18px 0 8px 0;
    font-size: 0.95em;
    font-weight: 600;
    color: #333;
}

#modal-body p {
    margin: 0 0 12px 0;
}

#modal-body ul {
    margin: 0 0 12px 0;
    padding-left: 20px;
}

#modal-body li {
    margin-bottom: 6px;
}

#modal-body .highlight {
    background: rgba(102, 126, 234, 0.08);
    border-left: 3px solid var(--accent-color);
    padding: 10px 14px;
    border-radius: 0 8px 8px 0;
    margin: 12px 0;
    font-size: 0.92em;
}

/* 빠른 질문 버튼 */
#quick-questions {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    overflow-x: auto;
    background: linear-gradient(180deg, rgba(21, 101, 192, 0.06) 0%, transparent 100%);
    flex-shrink: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#quick-questions::-webkit-scrollbar {
    display: none;
}

.quick-btn {
    flex-shrink: 0;
    padding: 8px 14px;
    background: var(--card-bg);
    border: 1px solid rgba(21, 101, 192, 0.2);
    border-radius: 18px;
    font-size: 0.8em;
    font-weight: 500;
    color: #1565c0;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
}

.quick-btn:hover {
    background: #1565c0;
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.quick-btn:active {
    transform: translateY(0);
}

/* 채팅 박스 */
#chat-box {
    flex: 1 1 0;
    min-height: 0;
    padding: 16px 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
}

/* 메시지 버블 */
#chat-box p {
    max-width: 85%;
    word-wrap: break-word;
    margin-bottom: 12px;
    line-height: 1.65;
    position: relative;
    padding: 12px 18px;
    border-radius: 20px;
    flex-shrink: 0;
    font-size: 0.95em;
    animation: fadeInUp 0.3s ease;
}

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

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

/* 마크다운 스타일링 */
#chat-box p strong {
    font-weight: 600;
    color: inherit;
}

#chat-box p strong.heading {
    display: block;
    font-size: 1.05em;
    margin-top: 10px;
    margin-bottom: 6px;
    color: var(--accent-color);
}

#chat-box p .list-number {
    font-weight: 600;
    color: var(--accent-color);
}

#chat-box p .list-bullet {
    color: var(--accent-color);
    margin-right: 4px;
}

#chat-box p em {
    font-style: italic;
}

/* 다운로드 링크 스타일 */
#chat-box p a.form-link {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid rgba(102, 126, 234, 0.3);
    transition: all 0.2s ease;
}

#chat-box p a.form-link:hover {
    color: #764ba2;
    border-bottom-color: #764ba2;
}

#chat-box p:before,
#chat-box p:after {
    content: "";
    position: absolute;
    bottom: 0;
    height: 20px;
}

.send {
    color: var(--send-color);
    background: var(--primary-gradient);
    align-self: flex-end;
    margin-left: auto;
    box-shadow: var(--shadow-sm);
}

.send:before {
    right: -7px;
    width: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-bottom-left-radius: 16px 14px;
}

.send:after {
    right: -26px;
    width: 26px;
    background-color: var(--card-bg);
    border-bottom-left-radius: 10px;
}

.receive {
    background: var(--receive-bg);
    color: var(--receive-text);
    align-self: flex-start;
    margin-right: auto;
}

.receive:before {
    left: -7px;
    width: 20px;
    background-color: var(--receive-bg);
    border-bottom-right-radius: 16px 14px;
}

.receive:after {
    left: -26px;
    width: 26px;
    background-color: var(--card-bg);
    border-bottom-right-radius: 10px;
}

/* 입력 영역 */
#input-container {
    display: flex;
    align-items: flex-end;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
    background: var(--card-bg);
    padding: 12px 16px;
    gap: 10px;
}

#user-input {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 20px;
    outline: none;
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: var(--receive-bg);
    resize: none;
    min-height: 44px;
    max-height: 100px;
    line-height: 1.4;
    overflow-y: auto;
}

#user-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

#user-input::placeholder {
    color: #888;
    font-size: 13px;
}

#send-button {
    padding: 14px 24px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

#send-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

#send-button:active {
    transform: translateY(0);
}

/* 광고 배너 */
#ad-banner {
    flex-shrink: 0;
    width: 100%;
    height: 90px !important;
    min-height: 90px !important;
    max-height: 90px !important;
    background: #fafafa;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

/* 푸터 */
#footer {
    flex-shrink: 0;
    padding: 10px 16px;
    background: #f5f5f5;
    text-align: center;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

#footer p {
    margin: 0;
    font-size: 0.7em;
    color: #888;
    line-height: 1.4;
}

#footer .update-date {
    margin-top: 4px;
    font-size: 0.65em;
    color: #aaa;
}

/* 타이핑 인디케이터 */
@keyframes typing {
    0% {
        opacity: 0.3;
    }

    20% {
        opacity: 1;
    }

    100% {
        opacity: 0.3;
    }
}

.typing-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 20px;
}

.typing-indicator div {
    background: var(--accent-color);
    border-radius: 50%;
    width: 8px;
    height: 8px;
    margin: 0 3px;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator div:nth-child(1) {
    animation-delay: 0s;
}

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

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

/* 모바일 최적화 */
@media (max-width: 768px) {
    #chat-header {
        padding: 14px 16px;
    }

    .header-content h1 {
        font-size: 1.3em;
    }

    #quick-questions {
        padding: 10px 12px;
    }

    .quick-btn {
        padding: 8px 14px;
        font-size: 0.8em;
    }

    #chat-box {
        padding: 12px 16px;
    }

    #chat-box p {
        max-width: 88%;
        padding: 10px 14px;
        font-size: 0.9em;
    }

    #input-container {
        padding: 10px 12px;
    }

    #user-input {
        padding: 12px 16px;
        font-size: 16px;
        /* iOS 줌 방지 */
    }

    #send-button {
        padding: 12px 20px;
    }
}

/* PC/태블릿 - 중앙 정렬 */
@media (min-width: 769px) {
    body {
        background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ec 100%);
    }

    #chat-container {
        max-width: 500px;
        margin: 0 auto;
        height: 100vh;
        box-shadow: var(--shadow-lg);
        border-radius: 0;
    }
}

/* iframe 대응 */
@media (max-height: 500px) {
    #chat-header {
        padding: 10px 16px;
    }

    .header-content h1 {
        font-size: 1.1em;
    }

    .header-content .subtitle,
    .header-content .languages {
        display: none;
    }

    #quick-questions {
        padding: 8px 12px;
    }

    .quick-btn {
        padding: 6px 12px;
        font-size: 0.75em;
    }
}