/* ============================================
   카넘버 — Premium Redesign
   ============================================ */

:root {
    --primary:       #1e1458;
    --primary-light: #2d1e7a;
    --accent:        #5f3dc4;
    --chat-bg:       #b8d0de;
    --user-bubble:   #fee500;
    --ai-bubble:     #ffffff;
    --shadow-main:   0 8px 32px rgba(0,0,0,0.18);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    background: #dce6f0;
    font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-text-size-adjust: 100%;
}

/* ─── Container ─────────────────────────────── */
#chat-container {
    position: relative;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 110px);
    height: calc(100dvh - 110px);
    max-width: 540px;
    margin: 0 auto;
    background: var(--chat-bg);
    box-shadow: var(--shadow-main);
    overflow: hidden;
}

/* ─── Header ─────────────────────────────────── */
#chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 16px;
    background: linear-gradient(140deg, #1a1040 0%, #2d1e7a 100%);
    color: #fff;
    flex-shrink: 0;
}

.header-brand { display: flex; flex-direction: column; }

.header-brand h1 {
    margin: 0; padding: 0;
    font-size: 21px;
    font-weight: 700;
    letter-spacing: -0.4px;
}
.header-brand h1 a { color: #fff; text-decoration: none; }

.header-brand h2 {
    margin: 2px 0 0; padding: 0;
    font-size: 11px;
    font-weight: 300;
    opacity: 0.7;
    letter-spacing: 0.6px;
}

#menu-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.16);
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    font-size: 16px;
    flex-shrink: 0;
    transition: background 0.2s;
}
#menu-button:hover { background: rgba(255,255,255,0.22); }

/* ─── Overlay ────────────────────────────────── */
#menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.52);
    z-index: 100;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    animation: overlayIn 0.22s ease;
}
#menu-overlay.show { display: block; }
@keyframes overlayIn { from { opacity:0; } to { opacity:1; } }

/* ─── Side Menu ──────────────────────────────── */
#side-menu {
    position: fixed;
    top: 0; right: 0;
    width: 270px;
    height: 100%;
    background: linear-gradient(180deg, #16102e 0%, #1e1458 100%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    box-shadow: -4px 0 24px rgba(0,0,0,0.4);
}
#side-menu.open { transform: translateX(0); }

.side-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.side-menu-header span {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.closebtn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: rgba(255,255,255,0.8);
    font-size: 15px;
    transition: background 0.2s;
}
.closebtn:hover { background: rgba(255,255,255,0.2); color:#fff; }

#side-menu nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}
#side-menu nav a {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 14px 18px;
    color: rgba(255,255,255,0.78);
    text-decoration: none;
    font-size: 14px;
    border-left: 3px solid transparent;
    transition: background 0.2s, color 0.2s, border-left-color 0.2s;
}
#side-menu nav a:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
    border-left-color: var(--user-bubble);
}
#side-menu nav a i {
    width: 18px;
    text-align: center;
    font-size: 14px;
    opacity: 0.6;
    flex-shrink: 0;
}
#side-menu nav a:hover i { opacity: 1; }

/* ─── Chat Box ───────────────────────────────── */
#chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}
#chat-box::-webkit-scrollbar { width: 3px; }
#chat-box::-webkit-scrollbar-track { background: transparent; }
#chat-box::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

/* ─── Message Bubbles ────────────────────────── */
.message {
    max-width: 75%;
    word-wrap: break-word;
    word-break: break-word;
    font-size: 14px;
    line-height: 1.55;
    padding: 10px 13px;
    border-radius: 18px;
    margin-bottom: 2px;
    animation: msgIn 0.18s ease;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
}

.user-message {
    background: var(--user-bubble);
    color: #1a1a1a;
    align-self: flex-end;
    margin-left: auto;
    border-bottom-right-radius: 5px;
    width: fit-content;
    font-weight: 400;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.ai-message {
    background: var(--ai-bubble);
    color: #1a1a1a;
    border-bottom-left-radius: 5px;
    width: fit-content;
    max-width: 78%;
    margin-left: 46px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: relative;
}
.ai-message::before {
    content: '';
    position: absolute;
    top: 10px;
    left: -7px;
    border-right: 8px solid var(--ai-bubble);
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
}

/* ─── AI Label ───────────────────────────────── */
.ai-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    margin-bottom: 5px;
}
.ai-label img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.9);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    object-fit: cover;
    flex-shrink: 0;
}
.ai-label span {
    font-size: 12px;
    font-weight: 600;
    color: #1a1a2e;
    letter-spacing: 0.2px;
}

/* ─── Markdown inside AI bubbles ─────────────── */
.ai-message p     { margin: 3px 0; }
.ai-message h1,
.ai-message h2,
.ai-message h3,
.ai-message h4,
.ai-message h5    { font-size: 14px; font-weight: 700; margin: 7px 0 3px; }
.ai-message ul,
.ai-message ol    { padding-left: 18px; margin: 4px 0; }
.ai-message li    { margin: 2px 0; }
.ai-message strong { font-weight: 700; }

/* ─── Input Form ─────────────────────────────── */
#chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #eaecf0;
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    min-width: 0;
    padding: 10px 16px;
    background: #f2f3f6;
    border: 1.5px solid transparent;
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    color: #1a1a1a;
    transition: border-color 0.2s, background 0.2s;
}
#chat-input:focus {
    background: #fff;
    border-color: var(--accent);
}
#chat-input::placeholder { color: #aaa; font-size: 13px; }

/* submit button */
#chat-form button[type="submit"] {
    width: 42px;
    height: 42px;
    min-width: 42px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(140deg, #2d1e7a, #5f3dc4);
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 15px;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
    box-shadow: 0 3px 10px rgba(95,61,196,0.45);
}
#chat-form button[type="submit"]:hover {
    transform: scale(1.06);
    box-shadow: 0 4px 14px rgba(95,61,196,0.55);
}
#chat-form button[type="submit"]:disabled {
    opacity: 0.45;
    transform: none;
    box-shadow: none;
    cursor: not-allowed;
}

/* ─── Ad Banner ──────────────────────────────── */
#ad-banner {
    max-width: 540px;
    margin: 0 auto;
    height: 110px;
    background: #e4e4e4;
    overflow: hidden;
}

/* ─── Typing Loader (3 dots) ─────────────────── */
.loader,
.loader::before,
.loader::after {
    all: unset;
}
.loader {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #bbb;
    margin: 3px 2px;
    vertical-align: middle;
    animation: dotPulse 1.2s infinite ease-in-out;
}
.loader:nth-child(2) { animation-delay: 0.2s; }
.loader:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse {
    0%, 80%, 100% { transform: scale(0.55); opacity: 0.45; }
    40%           { transform: scale(1.1);  opacity: 1; }
}

/* ─── Responsive ─────────────────────────────── */
@media (max-width: 540px) {
    body { background: var(--chat-bg); }

    #chat-container {
        max-width: 100%;
        box-shadow: none;
    }
    #ad-banner { max-width: 100%; }

    .message     { max-width: 82%; }
    .ai-message  { max-width: 84%; }
}
