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

:root {
    --bg: #121212;
    --surface: #1a1a1f;
    --surface-2: #222228;
    --border: #2c2c33;
    --pink: #FFB6C1;
    --pink-soft: #FFC0CB;
    --pink-dim: rgba(255, 182, 193, 0.1);
    --pink-glow: rgba(255, 182, 193, 0.3);
    --text: #f2f2f4;
    --text-sub: #aaa;
    --text-muted: #666;
    --radius: 18px;
    --radius-sm: 12px;
    --font: 'Nunito', -apple-system, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Top Bar ===== */
.top-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.7rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.top-bar-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    font-weight: 700;
    font-size: 1rem;
    color: var(--pink);
    letter-spacing: -0.01em;
}

.badges {
    display: flex;
    gap: 0.5rem;
}

.badge {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--pink-dim);
    border: 1px solid rgba(255,182,193,0.2);
    color: var(--pink);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.3rem 0.7rem;
    border-radius: 50px;
}

.badge strong {
    color: var(--pink-soft);
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #666;
    transition: all 0.3s;
}

.badge-dot.online {
    background: #4ade80;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
}

/* ===== Main Grid ===== */
.main {
    flex: 1;
    display: grid;
    grid-template-columns: 200px 1fr 1fr;
    gap: 1rem;
    padding: 1rem 1.25rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    min-height: 0;
}

@media (max-width: 1100px) {
    .main { grid-template-columns: 180px 1fr; }
    .upload-card { display: none; }
}

@media (max-width: 700px) {
    .main { grid-template-columns: 1fr; }
    .sidebar { display: none; }
}

/* ===== Sidebar (대화 목록) ===== */
.sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: calc(100vh - 6.5rem);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h3 {
    font-size: 0.82rem;
    font-weight: 700;
}

.new-chat-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--pink);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.new-chat-btn:hover {
    background: var(--pink-dim);
    border-color: var(--pink);
}

.conv-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.conv-list::-webkit-scrollbar { width: 3px; }
.conv-list::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

.conv-list li {
    padding: 0.5rem 0.65rem;
    border-radius: 8px;
    font-size: 0.75rem;
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.12s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}

.conv-list li:hover {
    background: var(--surface-2);
    color: var(--text);
}

.conv-list li.active {
    background: var(--pink-dim);
    color: var(--pink);
    border: 1px solid rgba(255,182,193,0.2);
}

.conv-list li .conv-delete {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.7rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.conv-list li:hover .conv-delete {
    display: flex;
}

.conv-list li .conv-delete:hover {
    background: rgba(255,80,80,0.2);
    color: #ff6b6b;
}

.conv-empty {
    color: var(--text-muted) !important;
    font-style: italic;
    cursor: default !important;
    text-align: center;
    padding: 1.5rem 0.5rem !important;
}

/* ===== Card ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.2rem;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    font-size: 0.92rem;
    font-weight: 700;
}

.tag {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.2rem 0.55rem;
    background: var(--pink-dim);
    color: var(--pink);
    border-radius: 50px;
    border: 1px solid rgba(255,182,193,0.2);
}

/* ===== Chat Card ===== */
.chat-card {
    height: calc(100vh - 6.5rem);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }

.empty {
    margin: auto;
    text-align: center;
    color: var(--text-sub);
}

.empty-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.empty p { font-size: 0.82rem; line-height: 1.6; }

.chips {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.chip {
    padding: 0.35rem 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 50px;
    color: var(--text-sub);
    font-size: 0.75rem;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
}

.chip:hover {
    border-color: var(--pink);
    color: var(--pink);
    background: var(--pink-dim);
}

/* Messages */
.msg {
    display: flex;
    gap: 0.5rem;
    max-width: 85%;
    animation: msgIn 0.2s ease;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.ai { align-self: flex-start; }

.msg-av {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: 700;
    flex-shrink: 0;
}

.msg.user .msg-av { background: var(--pink); color: #121212; }
.msg.ai .msg-av { background: var(--surface-2); color: var(--pink); border: 1px solid var(--border); }

.msg-bubble {
    padding: 0.55rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.83rem;
    line-height: 1.6;
}

.msg.user .msg-bubble {
    background: var(--pink);
    color: #121212;
    border-bottom-right-radius: 4px;
}

.msg.ai .msg-bubble {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg.ai .msg-bubble .word {
    display: inline-block;
    opacity: 0;
    animation: wFade 0.2s ease forwards;
}

@keyframes wFade { to { opacity: 1; } }

/* Chat Bar */
.chat-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.chat-bar input {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 0.55rem 1rem;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.83rem;
    outline: none;
    transition: border-color 0.2s;
}

.chat-bar input:focus { border-color: var(--pink); }
.chat-bar input::placeholder { color: #555; }

.chat-bar button {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: var(--pink);
    color: #121212;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
    box-shadow: 0 2px 10px var(--pink-glow);
}

.chat-bar button:hover { transform: scale(1.08); }
.chat-bar button:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

/* ===== Upload Card ===== */
.upload-card {
    height: calc(100vh - 6.5rem);
}

.upload-body {
    flex: 1;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}

.drop-zone {
    border: 2px dashed #333;
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--pink);
    background: var(--pink-dim);
}

.drop-icon { color: var(--pink); margin-bottom: 0.3rem; }
.drop-title { font-size: 0.88rem; font-weight: 600; }
.drop-sub { font-size: 0.72rem; color: var(--text-muted); }

/* Progress */
.upload-progress {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.prog-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    margin-bottom: 0.5rem;
}

.prog-header span:last-child { color: var(--pink); font-weight: 700; }

.prog-track {
    height: 5px;
    background: #2a2a2a;
    border-radius: 5px;
    overflow: hidden;
}

.prog-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--pink), var(--pink-soft));
    border-radius: 5px;
    transition: width 0.3s;
}

.prog-status {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    text-align: center;
}

/* History */
.upload-history {
    flex: 1;
}

.upload-history h3 {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-sub);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.upload-history ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.upload-history li {
    font-size: 0.78rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface-2);
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-empty {
    color: var(--text-muted);
    font-style: italic;
}

.history-chunks {
    font-size: 0.68rem;
    color: var(--pink);
    font-weight: 700;
}
