:root {
    --bg: #f6efe3;
    --sidebar: #efe5d3;
    --panel: #fffaf1;
    --panel-2: #f3e9d7;
    --border: #e2d3b8;
    --text: #4a3626;
    --soft: #7d664f;
    --faint: #a8927a;
    --accent: #a8764a;
    --accent-2: #c79a68;
    --accent-ink: #fffaf1;
    --onsen: #8fcfc4;
    --onsen-2: #6fb9ae;
    --user-bg: #ead6b6;
    --danger: #b3503f;
    --danger-bg: #f8e1da;
    --code-bg: #3b2d22;
    --shadow: 0 10px 30px rgba(120, 85, 50, 0.12);
}
:root[data-theme="dark"] {
    --bg: #1d1814;
    --sidebar: #241e19;
    --panel: #2a231d;
    --panel-2: #342b23;
    --border: #3f342a;
    --text: #f0e5d4;
    --soft: #bba78e;
    --faint: #8a7860;
    --accent: #d9a870;
    --accent-2: #e8c08e;
    --accent-ink: #1d1814;
    --onsen: #4f9a90;
    --onsen-2: #3f857b;
    --user-bg: #4a3a2b;
    --danger: #ff9f8d;
    --danger-bg: #3d2520;
    --code-bg: #14100d;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Noto Sans KR', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
    transition: background .3s, color .3s;
}
button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, strong.title, .brand-text strong { font-family: 'Gowun Dodum', 'Pretendard', sans-serif; }

.app { display: flex; height: 100vh; }

/* ---------- 사이드바 ---------- */
.sidebar {
    width: 262px; flex-shrink: 0;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    padding: 22px 16px;
    display: flex; flex-direction: column; gap: 18px;
    transition: background .3s;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand-mark {
    width: 44px; height: 44px; border-radius: 16px;
    background: var(--onsen);
    display: grid; place-items: center;
    overflow: hidden;
}
.brand-mark svg { width: 40px; height: 34px; margin-top: 6px; }
.brand-text strong { display: block; font-size: 1.15em; font-weight: 400; }
.brand-text span { font-size: 0.8em; color: var(--soft); }

.new-chat {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px;
    background: var(--accent); color: var(--accent-ink);
    border: none; border-radius: 999px;
    font-weight: 600;
    transition: transform .1s, opacity .2s;
}
.new-chat:hover { opacity: .92; }
.new-chat:active { transform: scale(.98); }

.tabs { display: flex; flex-direction: column; gap: 4px; }
.tab-button {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 16px;
    background: none; border: none; border-radius: 999px;
    color: var(--soft); font-weight: 500; text-align: left;
    transition: background .2s, color .2s;
}
.tab-button:hover { background: var(--panel-2); color: var(--text); }
.tab-button.active { background: var(--panel); color: var(--accent); box-shadow: 0 2px 8px rgba(120, 85, 50, 0.1); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 6px; font-size: 0.78em; color: var(--faint); }
.theme-toggle {
    align-self: flex-start;
    padding: 6px 14px; border-radius: 999px;
    background: var(--panel); border: 1px solid var(--border);
    color: var(--soft); font-size: 1.05em;
}
.theme-toggle:hover { color: var(--text); }
:root:not([data-theme="dark"]) .t-dark, :root[data-theme="dark"] .t-light { display: none; }

/* ---------- 본문 ---------- */
.main { flex: 1; min-width: 0; height: 100vh; overflow: hidden; }
.tab-content { display: none; height: 100%; }
.tab-content.active { display: block; }

/* ---------- 채팅 ---------- */
.chat-container {
    height: 100%; max-width: 820px; margin: 0 auto;
    padding: 0 24px 18px;
    display: flex; flex-direction: column;
}
.empty-state {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; gap: 8px;
}
.mascot { width: 170px; height: auto; margin-bottom: 8px; overflow: visible; }
.mascot use { animation: bob 5s ease-in-out infinite; transform-origin: center; }
.mascot .water { fill: var(--onsen); opacity: .9; }
.mascot .water-2 { fill: var(--onsen-2); opacity: .9; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(3px); } }

.empty-state h2 { font-size: 2em; font-weight: 400; letter-spacing: -0.02em; }
.empty-state p { color: var(--soft); }
.chips { margin-top: 24px; width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chip {
    text-align: left; padding: 14px 18px;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 20px; color: var(--text); line-height: 1.5;
    transition: transform .15s, border-color .2s, box-shadow .2s;
}
.chip small { display: block; color: var(--accent); font-size: 0.78em; font-weight: 650; margin-bottom: 2px; }
.chip:hover { border-color: var(--accent-2); box-shadow: var(--shadow); transform: translateY(-1px); }

.chat-messages { flex: 1; overflow-y: auto; padding: 28px 4px 12px; display: none; }
.chat-container:not(.is-empty) .chat-messages { display: block; }
.chat-container:not(.is-empty) .empty-state { display: none; }

.message { display: flex; gap: 12px; margin-bottom: 22px; }
.message .avatar {
    width: 36px; height: 36px; flex-shrink: 0; border-radius: 50%;
    display: grid; place-items: center; overflow: hidden;
    font-size: 0.8em; font-weight: 650;
    background: var(--user-bg); color: var(--soft);
}
.message.assistant .avatar { background: var(--onsen); }
.message.assistant .avatar svg { width: 32px; height: 27px; margin-top: 6px; }
.message .body { min-width: 0; max-width: calc(100% - 48px); }
.message.user { flex-direction: row-reverse; }
.message.user .body {
    background: var(--user-bg);
    padding: 10px 18px; border-radius: 22px 6px 22px 22px;
    white-space: pre-wrap; word-break: break-word;
}
.message.assistant .body {
    background: var(--panel); border: 1px solid var(--border);
    padding: 10px 18px; border-radius: 6px 22px 22px 22px;
    word-break: break-word;
}
.message-content { line-height: 1.8; }
.message-content p { margin-bottom: 10px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 6px 0 10px 22px; }
.message-content code {
    background: var(--panel-2); padding: 2px 6px; border-radius: 6px;
    font-family: ui-monospace, 'SF Mono', Consolas, monospace; font-size: 0.9em;
}
.message-content pre {
    background: var(--code-bg); color: #f0e5d4;
    border-radius: 14px; padding: 14px 16px; margin: 10px 0; overflow-x: auto;
}
.message-content pre code { background: none; padding: 0; color: inherit; }
.usage-info { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); font-size: 0.78em; color: var(--faint); }

.message.error .body { background: var(--danger-bg); color: var(--danger); border-color: transparent; padding: 10px 18px; border-radius: 6px 22px 22px 22px; }
.message.error .avatar { background: var(--danger-bg); color: var(--danger); }

.typing { display: inline-flex; align-items: center; gap: 6px; color: var(--soft); font-size: 0.92em; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); animation: blink 1.3s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
.typing em { font-style: normal; margin-left: 4px; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.composer {
    display: flex; align-items: flex-end; gap: 10px;
    padding: 10px 10px 10px 22px;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 28px; box-shadow: var(--shadow);
    transition: border-color .2s;
}
.composer:focus-within { border-color: var(--accent-2); }
.composer textarea {
    flex: 1; background: none; border: none; outline: none; resize: none;
    max-height: 160px; padding: 8px 0; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--faint); }
.composer button {
    width: 40px; height: 40px; flex-shrink: 0; border: none; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--accent); color: var(--accent-ink);
    transition: transform .1s, opacity .2s;
}
.composer button:hover { opacity: .9; }
.composer button:active { transform: scale(.94); }
.composer button:disabled { opacity: .4; cursor: default; }
.hint { text-align: center; margin-top: 10px; font-size: 0.76em; color: var(--faint); }

/* ---------- 사진 / 웹 ---------- */
.page { height: 100%; overflow-y: auto; max-width: 1000px; margin: 0 auto; padding: 40px 28px; }
.page-head { margin-bottom: 26px; }
.page-head h2 { font-size: 1.7em; font-weight: 400; letter-spacing: -0.02em; }
.page-head p { color: var(--soft); margin-top: 4px; }

.panel {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 24px; padding: 22px;
    box-shadow: var(--shadow);
}
.multimodal-container { display: grid; grid-template-columns: 1fr 1.1fr; gap: 18px; align-items: start; }
.web-container { display: flex; flex-direction: column; gap: 18px; }
.input-section { display: flex; flex-direction: column; gap: 14px; }

.input-section textarea, .input-section input[type="url"] {
    width: 100%; background: var(--bg);
    border: 1px solid var(--border); border-radius: 16px;
    padding: 12px 16px; outline: none; resize: vertical; line-height: 1.6;
    transition: border-color .2s;
}
.input-section textarea:focus, .input-section input[type="url"]:focus { border-color: var(--accent-2); }
.input-section ::placeholder { color: var(--faint); }

.file-label {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 24px 12px;
    border: 2px dashed var(--border); border-radius: 20px;
    color: var(--accent); text-align: center; font-weight: 600;
    transition: border-color .2s, background .2s;
}
.file-label small { color: var(--faint); font-weight: 400; }
.file-label:hover { border-color: var(--accent-2); background: var(--panel-2); }
input[type="file"] { display: none; }

.image-preview { display: flex; flex-wrap: wrap; gap: 10px; }
.image-preview:empty { display: none; }
.image-preview-item { position: relative; width: 88px; height: 88px; border-radius: 16px; overflow: hidden; border: 1px solid var(--border); }
.image-preview-item img { width: 100%; height: 100%; object-fit: cover; }
.image-preview-item .remove-btn {
    position: absolute; top: 5px; right: 5px; width: 22px; height: 22px;
    border: none; border-radius: 50%;
    background: rgba(60, 40, 25, 0.75); color: #fff; font-size: 14px; line-height: 1;
}

.button-group { display: flex; gap: 10px; }
.primary, .ghost { padding: 12px 20px; border-radius: 999px; font-weight: 600; border: 1px solid transparent; transition: opacity .2s; }
.button-group .primary { flex: 2; }
.button-group .ghost { flex: 1; }
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { opacity: .92; }
.primary:disabled { opacity: .5; }
.ghost { background: var(--panel-2); border-color: var(--border); color: var(--soft); }
.ghost:hover { color: var(--text); }

.multimodal-response, .web-response { line-height: 1.8; min-height: 140px; }
.multimodal-response { max-height: 560px; overflow-y: auto; }
.placeholder, .loading { color: var(--faint); text-align: center; padding: 40px 10px; }
.loading { color: var(--soft); }
.error { background: var(--danger-bg); color: var(--danger); padding: 14px 18px; border-radius: 16px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }

/* ---------- 모바일 ---------- */
@media (max-width: 820px) {
    .app { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 12px 14px; gap: 10px; }
    .brand-text span, .sidebar-foot span { display: none; }
    .new-chat { order: 2; margin-left: auto; padding: 8px 14px; }
    .tabs { order: 3; flex-direction: row; width: 100%; overflow-x: auto; }
    .tab-button { padding: 8px 14px; white-space: nowrap; }
    .sidebar-foot { order: 1; margin: 0 0 0 auto; }
    .main { height: auto; flex: 1; min-height: 0; }
    .tab-content { height: 100%; }
    .chips { grid-template-columns: 1fr; }
    .multimodal-container { grid-template-columns: 1fr; }
    .empty-state h2 { font-size: 1.6em; }
    .mascot { width: 140px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
