/* ============================================================
   표쌤 AI 친구 — Kids-friendly purple theme
   ============================================================ */

:root {
  --bg: #F7F5FF;
  --bg-elev: #FFFFFF;
  --sidebar-bg: #EFEBFF;
  --panel: #FFFFFF;
  --panel-strong: #FFFFFF;
  --text: #1F1A35;
  --text-strong: #0F0A20;
  --muted: #7A7398;
  --line: #E5DFFB;
  --line-strong: #CEC3F3;
  --accent: #7C5CFF;
  --accent-strong: #5E3FE0;
  --accent-soft: #E9E2FF;
  --assistant-bg: transparent;
  --user-bg: #F0EDE6;
  --user-text: #1F1F1F;
  --chip: #EFEAE0;
  --chip-text: #5C534B;
  --soft-card: #FBF9F4;
  --code-bg: #F5F2EB;
  --code-text: #1F1F1F;
  --code-block-bg: #1F1E1B;
  --code-block-text: #E8E3D8;
  --shadow-sm: 0 1px 2px rgba(20, 18, 14, 0.04);
  --shadow-md: 0 4px 16px rgba(20, 18, 14, 0.06);
  --shadow-lg: 0 16px 48px rgba(20, 18, 14, 0.10);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --font-sans: "Inter", "IBM Plex Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-serif: "Source Serif 4", "Source Serif Pro", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #1F1E1B;
  --bg-elev: #28261F;
  --sidebar-bg: #1A1916;
  --panel: #28261F;
  --panel-strong: #2F2D26;
  --text: #ECE6DA;
  --text-strong: #FFFFFF;
  --muted: #8E867B;
  --line: #3A3731;
  --line-strong: #4A463E;
  --accent: #9B82FF;
  --accent-strong: #B8A4FF;
  --accent-soft: #2E2555;
  --assistant-bg: transparent;
  --user-bg: #36322A;
  --user-text: #ECE6DA;
  --chip: #36322A;
  --chip-text: #D6CFC0;
  --soft-card: #28261F;
  --code-bg: #2F2D26;
  --code-text: #ECE6DA;
  --code-block-bg: #161410;
  --code-block-text: #E8E3D8;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  transition: background 0.25s ease, color 0.25s ease;
}

::selection {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* ----- Layout shell ----- */

.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px 12px;
  gap: 4px;
  scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

.chat-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  background: var(--bg);
  overflow: hidden;
  /* 사이드바가 display:none일 때도 chat-panel이 1fr 컬럼(두 번째)에 고정되어
     0폭 컬럼에 밀려들어가 화면이 비는 것을 방지 */
  grid-column: 2;
}

/* 사이드바가 접힌 상태에서는 .shell의 첫 컬럼 폭을 0으로 */
[data-sidebar="collapsed"] .chat-panel { grid-column: 2; }

/* ----- Brand ----- */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.brand-badge {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.78rem;
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
}

.brand-text { flex: 1; min-width: 0; }
.brand-text strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-strong);
  line-height: 1.2;
}
.brand-text p { display: none; }

.theme-toggle {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.95rem;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
}

.theme-toggle:hover {
  background: var(--chip);
  color: var(--text);
}

/* ----- Sidebar cards (flattened) ----- */

.sidebar-card {
  padding: 8px 4px;
  border: 0;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
}

.hero-card { display: none; }
.compact-card { display: none; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding: 0 8px;
}

.section-head h2 {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.muted, .eyebrow {
  color: var(--muted);
  margin: 0;
}

.eyebrow {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #d99a2b;
}
.status-dot.ok { background: #5ea975; }
.status-dot.error { background: #c95542; }

#status-text, #status-meta {
  font-size: 0.78rem;
  padding: 0 8px;
  margin: 2px 0;
}

/* ----- Sidebar form fields ----- */

.field-label {
  display: block;
  margin: 14px 8px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar-card label,
label {
  color: var(--muted);
}

select, textarea, input[type="text"], input[type="search"], input[type="password"], #message-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select:focus, textarea:focus, input:focus, #message-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; }

input[type="range"] {
  width: calc(100% - 16px);
  margin: 6px 8px 0;
  accent-color: var(--accent);
}

/* ----- Buttons ----- */

button { font: inherit; }

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 0 4px;
  margin-top: 10px;
}

.ghost-btn, .send-btn, .copy-btn, .attach-btn {
  border: 0;
  cursor: pointer;
  border-radius: var(--radius-md);
  font-weight: 500;
  transition: background 0.15s, color 0.15s, transform 0.05s, border-color 0.15s;
}

.ghost-btn {
  padding: 8px 12px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 0.82rem;
}

.ghost-btn:hover {
  background: var(--chip);
  border-color: var(--line-strong);
}

.send-btn {
  padding: 9px 18px;
  color: #fff;
  background: var(--accent);
  font-size: 0.88rem;
  font-weight: 600;
}

.send-btn:hover { background: var(--accent-strong); }
.send-btn:active { transform: translateY(1px); }

.image-btn {
  width: calc(100% - 8px);
  margin: 10px 4px 0;
}

/* ----- Sidebar lists ----- */

.url-list {
  display: grid;
  gap: 4px;
  padding: 0 4px;
}

.url-item {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--soft-card);
  border: 1px solid var(--line);
  font-size: 0.78rem;
}

.url-item code {
  word-break: break-all;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.copy-btn {
  padding: 4px 9px;
  background: var(--chip);
  color: var(--chip-text);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 500;
}

.copy-btn:hover { background: var(--line-strong); }

/* ----- Session list ----- */

/* memory list */
.memory-list {
  display: grid;
  gap: 4px;
  padding: 0 4px;
  max-height: 180px;
  overflow-y: auto;
}

.memory-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--soft-card);
  border: 1px solid var(--line);
  font-size: 0.78rem;
}

.memory-item span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.memory-item button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.memory-item:hover button { opacity: 0.7; }
.memory-item button:hover { color: var(--accent-strong); opacity: 1 !important; }

.memory-add {
  margin-top: 6px;
  padding: 0 4px;
}

.memory-add input {
  width: 100%;
  padding: 7px 11px;
  font-size: 0.8rem;
}

.session-search {
  margin: 0 4px 6px;
  width: calc(100% - 8px);
  padding: 7px 11px;
  font-size: 0.82rem;
}

.session-tools { margin-top: 6px; }
.session-tools .ghost-btn { padding: 6px 8px; font-size: 0.74rem; }

.session-list {
  display: grid;
  gap: 1px;
  max-height: 320px;
  overflow-y: auto;
  padding: 0 4px;
  scrollbar-width: thin;
}

.session-list::-webkit-scrollbar { width: 6px; }
.session-list::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

.session-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s;
}

.session-item:hover { background: var(--chip); }

.session-item.active {
  background: var(--accent-soft);
  border-color: transparent;
}

.session-title {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0;
  font-weight: 500;
  font-size: 0.82rem;
}

.session-item.active .session-title { color: var(--accent-strong); }

.session-remove {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 5px;
  font-size: 0.85rem;
  opacity: 0;
  border-radius: 4px;
  transition: opacity 0.15s, color 0.15s;
}

.session-item:hover .session-remove,
.session-item.active .session-remove { opacity: 0.7; }
.session-remove:hover { color: var(--accent-strong); opacity: 1 !important; }

/* ----- Preset chips ----- */

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 4px;
  margin-bottom: 6px;
}

.preset-chip {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.preset-chip:hover { background: var(--chip); color: var(--text); }
.preset-chip.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: transparent;
}

/* ----- Chat panel header ----- */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.chat-header h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.01em;
}

.chat-header .eyebrow { display: none; }

.header-pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
  white-space: nowrap;
}

/* ----- Intro strip / suggestions ----- */

.intro-strip { display: none; }

.prompt-suggestions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px 20px 6px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.prompt-card-draw {
  background: linear-gradient(135deg, #FFE0F0 0%, #E9E2FF 100%) !important;
  border-color: var(--accent) !important;
}
.prompt-card-draw strong { color: var(--accent-strong) !important; }

.prompt-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  font: inherit;
  color: var(--text);
  min-width: 0;
}

.prompt-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.prompt-card strong {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.prompt-card span {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ----- Chat log ----- */

.chat-log {
  padding: 28px 28px 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
  scrollbar-width: thin;
}

.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }

.message {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 0.72rem;
  background: var(--chip);
  color: var(--chip-text);
  flex-shrink: 0;
}

.message.assistant .avatar {
  background: var(--accent);
  color: #fff;
}

.bubble {
  padding: 0;
  background: transparent;
  border: 0;
  line-height: 1.72;
  word-break: break-word;
  color: var(--text);
  font-size: 0.95rem;
}

.message.user .bubble {
  background: var(--user-bg);
  color: var(--user-text);
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  white-space: pre-wrap;
}

.bubble p { margin: 0; }
.bubble p + p { margin-top: 12px; }

.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 {
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 22px 0 8px;
  line-height: 1.3;
  color: var(--text-strong);
}
.bubble h1 { font-size: 1.45rem; }
.bubble h2 { font-size: 1.25rem; }
.bubble h3 { font-size: 1.1rem; }
.bubble h4, .bubble h5, .bubble h6 { font-size: 1rem; }

.bubble ul, .bubble ol {
  margin: 8px 0;
  padding-left: 22px;
}

.bubble li { margin: 4px 0; }

.bubble code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.bubble a {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble .md-image {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  margin: 12px 0;
  display: block;
  background: var(--soft-card);
}

.bubble strong { font-weight: 700; color: var(--text-strong); }
.bubble em { font-style: italic; }

/* ----- Code blocks ----- */

.bubble .code-block {
  position: relative;
  margin: 14px 0;
  padding: 14px 16px;
  background: var(--code-block-bg);
  color: var(--code-block-text);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
}

.bubble .code-block code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
  white-space: pre;
  display: block;
}

.bubble .code-lang {
  position: absolute;
  top: 8px;
  left: 14px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(232, 227, 216, 0.5);
}

.bubble .code-block:has(.code-lang) code { margin-top: 14px; }

.bubble .code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(232, 227, 216, 0.85);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 0.68rem;
  font-weight: 500;
  cursor: pointer;
  opacity: 0;
  transition: all 0.15s;
}

.bubble .code-block:hover .code-copy { opacity: 1; }
.bubble .code-copy:hover { background: rgba(255, 255, 255, 0.16); }

/* ----- Tables ----- */

.bubble .table-wrap {
  margin: 14px 0;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
}

.bubble .md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.bubble .md-table th, .bubble .md-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}

.bubble .md-table th {
  background: var(--soft-card);
  color: var(--text-strong);
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bubble .md-table tbody tr:last-child td { border-bottom: 0; }
.bubble .md-table tbody tr:nth-child(even) td { background: var(--soft-card); }

/* ----- Image result ----- */

.image-result { display: grid; gap: 10px; }

.image-frame {
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--soft-card);
  border: 1px solid var(--line);
}

.image-frame img { display: block; width: 100%; height: auto; }

.image-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.image-meta code {
  font-size: 0.75rem;
  color: var(--muted);
  background: transparent;
  padding: 0;
}

/* ----- Message action buttons ----- */

.msg-copy-btn, .msg-regen-btn, .msg-edit-btn, .msg-speak-btn {
  grid-column: 2;
  justify-self: start;
  margin-top: 4px;
  padding: 4px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.message:hover .msg-copy-btn,
.message:hover .msg-regen-btn,
.message:hover .msg-edit-btn,
.message:hover .msg-speak-btn { opacity: 0.7; }

.msg-copy-btn:hover, .msg-regen-btn:hover, .msg-edit-btn:hover, .msg-speak-btn:hover {
  background: var(--chip);
  color: var(--text);
  opacity: 1 !important;
}

.message.user .msg-copy-btn { display: none; }
.message.user .msg-edit-btn { grid-column: 1; justify-self: end; }

.msg-stats {
  grid-column: 2;
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.55;
}

/* ----- Composer ----- */

.composer {
  padding: 12px 28px 24px;
  background: var(--bg);
  border-top: 1px solid var(--line);
  max-width: 808px;
  width: 100%;
  margin: 0 auto;
  align-self: center;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 500;
}

.attach-btn:hover {
  background: var(--chip);
  color: var(--text);
}

.attach-btn.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
}

.voice-btn { border: 1px solid var(--line); }
.voice-btn.listening {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  animation: voice-pulse 1.4s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201, 99, 66, 0.4); }
  50%      { box-shadow: 0 0 0 8px rgba(201, 99, 66, 0); }
}

.composer-toolbar > .muted {
  font-size: 0.72rem;
  flex: 1;
}

/* attachment chips */

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border-radius: var(--radius-md);
  background: var(--soft-card);
  border: 1px solid var(--line);
  color: var(--text);
  max-width: 100%;
  transition: all 0.15s;
}

.attachment-chip.processing { border-color: var(--accent); }
.attachment-chip.processing .attachment-icon { animation: chip-pulse 1.2s ease-in-out infinite; }
.attachment-chip.error {
  background: #fde9e2;
  border-color: #c95542;
  color: #8a3320;
}
[data-theme="dark"] .attachment-chip.error {
  background: #3a1f17;
  color: #ffb09a;
}

@keyframes chip-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.attachment-icon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--chip);
  font-size: 0.95rem;
  flex-shrink: 0;
}

.attachment-thumb {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-elev);
  border: 1px solid var(--line);
}

.attachment-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  max-width: 220px;
}

.attachment-label strong {
  font-size: 0.78rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-meta {
  font-size: 0.68rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip.error .attachment-meta { color: inherit; }

.attachment-chip button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  padding: 2px 4px;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.attachment-chip button:hover { color: var(--accent-strong); }

/* composer textarea container */

.composer-box {
  display: block;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#message-input {
  min-height: 56px;
  max-height: 220px;
  resize: none;
  padding: 14px 16px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  line-height: 1.6;
}

#message-input:focus { box-shadow: none; }

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

#composer-hint {
  font-size: 0.7rem;
  color: var(--muted);
}

.composer-actions .send-btn { min-width: 96px; }

.send-btn.stop-mode { background: #c95542; }
.send-btn.stop-mode::before { content: "■ "; font-size: 0.75em; }

/* ----- Sidebar collapsed (Ctrl+B) ----- */

[data-sidebar="collapsed"] .shell {
  grid-template-columns: 0 minmax(0, 1fr);
}

[data-sidebar="collapsed"] .sidebar {
  display: none;
}

.sidebar-expand {
  position: fixed;
  top: 18px;
  left: 12px;
  z-index: 50;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  cursor: pointer;
  display: none;
}

[data-sidebar="collapsed"] .sidebar-expand {
  display: grid;
  place-items: center;
}

/* ----- Section action button (e.g. macro add +) ----- */

.section-action {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.section-action:hover { background: var(--chip); color: var(--text); }

/* ----- Macro list ----- */

.macro-list {
  display: grid;
  gap: 2px;
  padding: 0 4px;
}

.macro-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 0.12s;
}

.macro-item:hover { background: var(--chip); }

.macro-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
}

.macro-name {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0;
}

.macro-del {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 0.78rem;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.macro-item:hover .macro-del { opacity: 0.6; }
.macro-del:hover { color: var(--accent-strong); opacity: 1 !important; }

/* ----- Modal ----- */

[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 14, 0.5);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  backdrop-filter: blur(6px);
}

[data-theme="dark"] .modal {
  background: rgba(0, 0, 0, 0.6);
}

.modal-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: min(480px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-card h3 {
  font-family: var(--font-serif);
  margin: 0 0 16px;
  color: var(--text-strong);
  font-size: 1.15rem;
}

.modal-card label {
  display: block;
  margin: 12px 0 6px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-card input[type="text"],
.modal-card textarea {
  width: 100%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ----- Global search modal ----- */

.search-card {
  width: min(620px, 100%);
  padding: 16px;
}

#global-search-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
}

.global-search-results {
  display: grid;
  gap: 2px;
  margin-top: 10px;
  max-height: 50vh;
  overflow-y: auto;
}

.global-search-item {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--text);
}

.global-search-item:hover, .global-search-item.active {
  background: var(--accent-soft);
}

.gs-icon { font-size: 1.1rem; flex-shrink: 0; width: 22px; }
.gs-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.gs-body strong { font-size: 0.86rem; font-weight: 600; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-body span { font-size: 0.74rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- Script → Images modal ----- */

.script-card {
  width: min(820px, 100%);
}

.script-controls {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
  margin-top: 14px;
}

.script-controls div { display: flex; flex-direction: column; }
.script-controls label { margin: 0 0 6px; }

.script-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 16px;
  max-height: 50vh;
  overflow-y: auto;
  padding-right: 4px;
}

.script-result-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--soft-card);
}

.script-result-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin: 0;
}

.script-result-caption strong {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-strong);
}

.script-result-caption span {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 3px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.scene-img-wrap {
  width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-elev);
}

.scene-prompt {
  width: 100%;
  margin-top: 6px;
  padding: 6px 8px;
  font-size: 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-family: var(--font-mono);
  resize: vertical;
}

.scene-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.scene-mini {
  padding: 5px 9px !important;
  font-size: 0.7rem !important;
  flex: 1;
  min-width: 0;
}

/* ----- Lightbox ----- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 40px;
  cursor: zoom-out;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-md);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

.lightbox-close:hover { background: rgba(255, 255, 255, 0.25); }

.bubble .md-image, .attachment-thumb { cursor: zoom-in; }

/* ----- Toast ----- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--text-strong);
  color: var(--bg);
  font-size: 0.84rem;
  font-weight: 500;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 300;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ----- Library modal ----- */

.library-card {
  width: min(720px, 100%);
}

.library-section {
  margin-bottom: 18px;
}

.library-section h4 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px;
}

.library-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--soft-card);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--text);
  transition: all 0.15s;
}

.library-item:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.library-item.added {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.library-icon { font-size: 1rem; flex-shrink: 0; }
.library-name { font-size: 0.78rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- Stats modal ----- */

.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}

.stats-summary > div {
  background: var(--soft-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
}

.stats-summary strong {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-strong);
  font-family: var(--font-serif);
}

.stats-summary span {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
}

.stats-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.stats-label {
  font-size: 0.78rem;
  font-weight: 500;
  width: 140px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-bar {
  flex: 1;
  position: relative;
  height: 22px;
  background: var(--soft-card);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.stats-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent-soft);
  border-right: 2px solid var(--accent);
}

.stats-bar-text {
  position: relative;
  display: block;
  padding: 4px 8px;
  font-size: 0.7rem;
  color: var(--text);
}

.stats-days {
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  gap: 4px;
  align-items: end;
  height: 80px;
}

.stats-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}

.stats-day-bar {
  width: 100%;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height 0.3s;
}

.stats-day span {
  font-size: 0.62rem;
  color: var(--muted);
}

/* ----- Compare mode ----- */

.compare-message {
  grid-template-columns: 32px minmax(0, 1fr);
  max-width: 1200px;
}
.compare-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.compare-col {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: var(--soft-card);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.compare-col-head {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent-strong);
  text-transform: lowercase;
  letter-spacing: 0.02em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}
.compare-bubble { padding: 0; font-size: 0.88rem; }
.compare-stats { margin-top: 4px; }

/* ----- Mobile ----- */

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 0 minmax(0, 1fr);
    height: 100vh;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 86%;
    max-width: 320px;
    z-index: 80;
    border-right: 1px solid var(--line);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 16px 0 48px rgba(0,0,0,0.25);
  }
  [data-sidebar="open"] .sidebar { transform: translateX(0); }
  [data-sidebar="open"]::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 70;
  }
  .sidebar-expand {
    display: grid !important;
    place-items: center;
    top: 10px;
    left: 10px;
    z-index: 60;
  }
  [data-sidebar="open"] .sidebar-expand { display: none !important; }
  [data-sidebar="collapsed"] .sidebar { display: flex; }
  .chat-header { padding: 12px 16px 12px 56px; }
  .chat-log { padding: 20px 16px 24px; }
  .composer { padding: 12px 16px 18px; }
  .prompt-suggestions { padding: 8px 10px 4px; grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .message { gap: 12px; }
  .compare-cols { grid-template-columns: 1fr; }
}

/* ===== 생각 중 인디케이터 (kids-chat) ===== */
.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--accent-soft);
  border-radius: 20px;
  font-size: 15px;
  color: var(--accent-strong);
  font-weight: 600;
}
.thinking-emoji {
  display: inline-block;
  animation: thinking-wiggle 1.2s ease-in-out infinite;
  font-size: 18px;
}
.thinking-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 2px;
}
.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: thinking-bounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-wiggle {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg); }
}
@keyframes thinking-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ===== 초등 모드: 고급 UI 숨기기 ===== */
.sidebar-card.advanced-hidden,
.attach-btn.advanced-hidden,
.composer-toolbar .advanced-hidden { display: none !important; }

/* composer 힌트 텍스트는 너무 기술적이니 작게 */
.composer-toolbar .muted { font-size: 0.72rem; opacity: 0.7; }
