/* ═══════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════ */
:root {
    --orange:       #FF5500;
    --orange-2:     #FF7A00;
    --orange-3:     #FFAA44;
    --orange-pale:  rgba(255, 85, 0, 0.08);
    --orange-glow:  rgba(255, 85, 0, 0.22);
    --orange-ring:  rgba(255, 85, 0, 0.18);

    --bg:       #F0EDE8;
    --bg-noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.025'/%3E%3C/svg%3E");

    --glass-bg:     rgba(255, 255, 255, 0.72);
    --glass-border: rgba(255, 255, 255, 0.55);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0,0,0,0.04);

    --surface:   #FFFFFF;
    --surface-2: rgba(240, 237, 232, 0.7);

    --text-1: #0F0F10;
    --text-2: #52525B;
    --text-3: #A1A1AA;

    --border: rgba(0, 0, 0, 0.07);

    --header-h: 64px;
    --r-pill:   9999px;
    --r-msg:    20px;
    --r-card:   16px;
    --r-avatar: 14px;

    --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
}

/* ═══════════════════════════════════════
   BASE
═══════════════════════════════════════ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background:
        var(--bg-noise),
        radial-gradient(ellipse 120% 60% at 80% -10%, rgba(255, 122, 0, 0.12) 0%, transparent 60%),
        radial-gradient(ellipse 80% 50% at -10% 110%, rgba(255, 85, 0, 0.08) 0%, transparent 55%),
        var(--bg);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: var(--text-1);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ═══════════════════════════════════════
   HEADER — glassmorphism
═══════════════════════════════════════ */
header {
    height: var(--header-h);
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--glass-shadow);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 11px;
}

.logo-icon {
    width: 38px;
    height: 38px;
    min-width: 38px;
    background: linear-gradient(135deg, var(--orange-2), var(--orange));
    border-radius: var(--r-avatar);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.95rem;
    box-shadow: 0 4px 14px var(--orange-glow), 0 0 0 1px rgba(255,255,255,0.15) inset;
    position: relative;
    overflow: hidden;
}

.logo-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(160deg, rgba(255,255,255,0.25) 0%, transparent 55%);
    border-radius: inherit;
}

.logo-text h1 {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-1);
    line-height: 1.2;
}

.logo-text span {
    font-size: 0.68rem;
    color: var(--text-3);
    font-weight: 400;
    letter-spacing: 0.02em;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-2);
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    padding: 5px 12px;
    border-radius: var(--r-pill);
    border: 1px solid var(--glass-border);
    letter-spacing: 0.02em;
}

.status-dot {
    width: 6px;
    height: 6px;
    min-width: 6px;
    background: #22C55E;
    border-radius: 50%;
    animation: pulse-green 2.5s ease infinite;
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3); }
    50%       { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.08); }
}

/* ═══════════════════════════════════════
   CHAT AREA
═══════════════════════════════════════ */
#chat-container {
    flex: 1;
    padding: 24px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

#chat-container::-webkit-scrollbar { width: 3px; }
#chat-container::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.08);
    border-radius: 3px;
}

/* ═══════════════════════════════════════
   MESSAGES
═══════════════════════════════════════ */
.message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 86%;
    animation: msgIn 0.36s var(--ease-spring) both;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.96);
        filter: blur(2px);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

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

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

/* ─ Avatar ─ */
.avatar {
    width: 30px;
    height: 30px;
    min-width: 30px;
    background: linear-gradient(135deg, var(--orange-2), var(--orange));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.72rem;
    box-shadow: 0 3px 10px var(--orange-glow);
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.avatar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(145deg, rgba(255,255,255,0.22) 0%, transparent 60%);
}

/* ─ Content wrapper ─ */
.msg-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message.user .msg-content { align-items: flex-end; }

/* ─ Bubbles ─ */
.bubble {
    padding: 11px 15px;
    border-radius: var(--r-msg);
    font-size: 0.9rem;
    line-height: 1.72;
    position: relative;
    word-break: keep-all;
}

.message.bot .bubble {
    background: var(--glass-bg);
    backdrop-filter: blur(16px) saturate(1.6);
    -webkit-backdrop-filter: blur(16px) saturate(1.6);
    color: var(--text-1);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

.message.user .bubble {
    background: linear-gradient(140deg, var(--orange-2) 0%, var(--orange) 60%, #D94400 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 18px var(--orange-glow), 0 0 0 1px rgba(255,255,255,0.12) inset;
    position: relative;
    overflow: hidden;
}

.message.user .bubble::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255,255,255,0.12) 0%, transparent 100%);
    border-radius: inherit;
}

/* ─ Timestamp ─ */
.timestamp {
    font-size: 0.67rem;
    color: var(--text-3);
    padding: 0 2px;
    letter-spacing: 0.01em;
}

/* ═══════════════════════════════════════
   FOOTER — glass panel
═══════════════════════════════════════ */
footer {
    background: var(--glass-bg);
    backdrop-filter: blur(24px) saturate(1.8);
    -webkit-backdrop-filter: blur(24px) saturate(1.8);
    border-top: 1px solid var(--glass-border);
    box-shadow: 0 -8px 32px rgba(0,0,0,0.05);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ─ Category Bar ─ */
.category-bar {
    display: flex;
    gap: 6px;
    padding: 12px 16px 8px;
    overflow-x: auto;
    scrollbar-width: none;
}

.category-bar::-webkit-scrollbar { display: none; }

.cat-btn {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: var(--r-pill);
    border: 1px solid rgba(0,0,0,0.08);
    background: rgba(255, 255, 255, 0.55);
    color: var(--text-2);
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    font-family: inherit;
    white-space: nowrap;
    letter-spacing: 0.01em;
    backdrop-filter: blur(8px);
    position: relative;
    isolation: isolate;
    overflow: hidden;
}

.cat-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--orange-2), var(--orange));
    opacity: 0;
    transition: opacity 0.2s;
    z-index: -1;
    border-radius: inherit;
}

.cat-btn:hover {
    border-color: transparent;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px var(--orange-glow);
}

.cat-btn:hover::before { opacity: 1; }

.cat-btn:active { transform: scale(0.94) translateY(0); }

/* ─ Input Area ─ */
.input-area {
    display: flex;
    align-items: center;
    padding: 8px 16px 14px;
    gap: 10px;
}

#user-input {
    flex: 1;
    height: 48px;
    border: 1.5px solid rgba(255, 255, 255, 0.6);
    border-radius: var(--r-pill);
    padding: 0 20px;
    font-size: 0.92rem;
    font-family: inherit;
    outline: none;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(10px);
    color: var(--text-1);
    transition: all 0.22s var(--ease-out);
    caret-color: var(--orange);
    letter-spacing: -0.01em;
}

#user-input::placeholder {
    color: var(--text-3);
    font-weight: 400;
}

#user-input:focus {
    border-color: var(--orange);
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 0 0 4px var(--orange-ring), 0 4px 16px rgba(0,0,0,0.06);
}

#send-btn {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--orange-2) 0%, var(--orange) 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s var(--ease-spring);
    box-shadow: 0 4px 14px var(--orange-glow), 0 0 0 1px rgba(255,255,255,0.15) inset;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

#send-btn::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 50%;
    background: rgba(255,255,255,0.18);
}

#send-btn:hover {
    transform: scale(1.08) translateY(-1px);
    box-shadow: 0 8px 22px var(--orange-glow);
}

#send-btn:active {
    transform: scale(0.92);
    box-shadow: 0 2px 8px var(--orange-glow);
}

#send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ═══════════════════════════════════════
   LOADING — shimmer dots
═══════════════════════════════════════ */
.loading-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
}

.loading-text {
    font-size: 0.78rem;
    color: var(--text-3);
    font-weight: 500;
}

.loading {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 4px 0;
}

.dot {
    width: 6px;
    height: 6px;
    background: linear-gradient(135deg, var(--orange-2), var(--orange));
    border-radius: 50%;
    opacity: 0.3;
    animation: dotBounce 1.2s var(--ease-out) infinite;
}

.dot:nth-child(2) { animation-delay: 0.18s; }
.dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes dotBounce {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.3; }
    30%            { transform: translateY(-6px); opacity: 1;   }
}

/* ═══════════════════════════════════════
   MARKDOWN IN BUBBLES
═══════════════════════════════════════ */
.bubble strong { font-weight: 700; }

.message.bot .bubble strong {
    color: var(--orange);
    background: linear-gradient(90deg, var(--orange) 0%, var(--orange-2) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.bubble ul, .bubble ol {
    margin-left: 18px;
    margin-block: 6px;
}

.bubble li { margin-block: 3px; }

.bubble hr {
    border: none;
    border-top: 1px solid var(--border);
    margin-block: 12px;
    opacity: 0.5;
}

/* ─ Source Badge ─ */
.source-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.67rem;
    background: var(--orange-pale);
    color: var(--orange);
    padding: 3px 9px;
    border-radius: 8px;
    margin-top: 10px;
    font-weight: 700;
    letter-spacing: 0.03em;
    border: 1px solid rgba(255, 85, 0, 0.14);
    text-transform: uppercase;
}

/* ═══════════════════════════════════════
   SCROLL-TO-BOTTOM FAB (optional glow ring)
═══════════════════════════════════════ */
.scroll-fab {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s var(--ease-spring);
}

.scroll-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0,0,0,0.14);
}

/* ═══════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════ */
@media (max-width: 430px) {
    #chat-container { padding: 18px 12px; }
    .input-area     { padding: 8px 12px 14px; }
    .category-bar   { padding: 10px 12px 6px; }
}

@media (min-width: 431px) {
    body {
        max-width: 430px;
        margin: 0 auto;
        border-radius: 0;
        box-shadow: 0 0 0 1px rgba(0,0,0,0.06), 0 24px 64px rgba(0,0,0,0.12);
        height: 100vh;
    }
}
