/* 가족 AI 허브 — Hermes 데스크톱의 토큰 체계를 그대로 따릅니다.
   규칙: 평평하게(flat), 카드 중첩 금지, 1px 헤어라인, 작은 모서리(2~4px), 13px 본문. */

:root {
  color-scheme: light;

  --fg: #17171a;
  --accent: #0053fd;
  --accent-fill: color-mix(in srgb, #0053fd 6%, #ffffff);
  --accent-soft: color-mix(in srgb, #0053fd 9%, #ffffff);
  --accent-line: color-mix(in srgb, #0053fd 24%, transparent);

  --bg-chrome: #f8faff;
  --bg-sidebar: #f3f7ff;
  --bg-editor: #ffffff;
  --bg-card: #fcfcfc;
  --bg-quaternary: color-mix(in srgb, #17171a 5%, transparent);
  --bg-quinary: color-mix(in srgb, #17171a 3%, transparent);

  --text-primary: color-mix(in srgb, #17171a 94%, transparent);
  --text-secondary: color-mix(in srgb, #17171a 74%, transparent);
  --text-tertiary: color-mix(in srgb, #17171a 54%, transparent);
  --text-quaternary: color-mix(in srgb, #17171a 36%, transparent);

  --stroke-primary: color-mix(in srgb, #0053fd 24%, rgba(23, 23, 26, 0.1));
  --stroke-secondary: color-mix(in srgb, #0053fd 16%, rgba(23, 23, 26, 0.07));
  --stroke-tertiary: color-mix(in srgb, #0053fd 10%, rgba(23, 23, 26, 0.05));

  --danger: #cf2d56;
  --danger-soft: color-mix(in srgb, #cf2d56 8%, #ffffff);
  --ok: #1f8a65;

  --font: 'Segoe WPC', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Malgun Gothic', system-ui, sans-serif;
  --mono: Menlo, Monaco, 'SF Mono', 'Cascadia Mono', Consolas, monospace;

  --r-xs: 2px;
  --r-sm: 3px;
  --r-md: 4px;
  --r-lg: 6px;

  --shadow-composer: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-menu: 0 0 0 1px rgba(23, 23, 26, 0.08), 0 4px 16px rgba(0, 0, 0, 0.08), 0 16px 32px -24px rgba(0, 0, 0, 0.18);

  --side-width: 268px;
  --thread-width: 760px;
}

[data-theme='dark'] {
  color-scheme: dark;

  --fg: #ededed;
  --accent: #4d8bff;
  --accent-fill: color-mix(in srgb, #4d8bff 12%, #161618);
  --accent-soft: color-mix(in srgb, #4d8bff 16%, #161618);

  --bg-chrome: #0d0d0e;
  --bg-sidebar: #0a0a0b;
  --bg-editor: #161618;
  --bg-card: #1b1b1e;
  --bg-quaternary: color-mix(in srgb, #ffffff 7%, transparent);
  --bg-quinary: color-mix(in srgb, #ffffff 4%, transparent);

  --text-primary: color-mix(in srgb, #ffffff 92%, transparent);
  --text-secondary: color-mix(in srgb, #ffffff 70%, transparent);
  --text-tertiary: color-mix(in srgb, #ffffff 48%, transparent);
  --text-quaternary: color-mix(in srgb, #ffffff 32%, transparent);

  --stroke-primary: color-mix(in srgb, #ffffff 18%, transparent);
  --stroke-secondary: color-mix(in srgb, #ffffff 11%, transparent);
  --stroke-tertiary: color-mix(in srgb, #ffffff 7%, transparent);

  --danger: #e75e78;
  --danger-soft: color-mix(in srgb, #e75e78 14%, #161618);
  --ok: #55a583;

  --shadow-composer: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-menu: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 6px 20px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden], .hidden { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-editor);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ───────── 부팅 ───────── */
.boot {
  position: fixed; inset: 0; display: grid; place-content: center; gap: 6px;
  text-align: center; background: var(--bg-chrome);
}
.boot-mark { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.boot-sub { font-size: 12px; color: var(--text-tertiary); }

/* ───────── 로그인 ───────── */
.auth {
  min-height: 100dvh; display: grid; place-items: center;
  background: var(--bg-chrome); padding: 24px;
}
.auth-panel {
  width: 100%; max-width: 340px; background: var(--bg-editor);
  border: 1px solid var(--stroke-tertiary); border-radius: var(--r-md);
  padding: 22px 22px 18px; box-shadow: var(--shadow-menu);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth-logo { width: 30px; height: 30px; border-radius: var(--r-sm); }
.auth-brand h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.auth-brand p { margin: 1px 0 0; font-size: 11.5px; color: var(--text-tertiary); }

.auth-form { display: grid; gap: 10px; }
.auth-alt { margin: 2px 0 0; font-size: 11.5px; color: var(--text-tertiary); text-align: center; }
.link {
  border: 0; background: none; padding: 0; color: var(--accent);
  font-size: inherit; text-decoration: none;
}
.link:hover { text-decoration: underline; }
.setup-note {
  margin: 0 0 2px; font-size: 11.5px; color: var(--text-secondary);
  background: var(--bg-quinary); border-left: 2px solid var(--accent-line);
  padding: 7px 9px; border-radius: 0 var(--r-xs) var(--r-xs) 0;
}
.form-error { margin-top: 10px; font-size: 11.5px; color: var(--danger); min-height: 16px; }

.field { display: grid; gap: 4px; }
.field > span { font-size: 11.5px; color: var(--text-secondary); }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg-editor); color: var(--text-primary);
  border: 1px solid var(--stroke-secondary); border-radius: var(--r-sm);
  padding: 6px 8px; font-size: 12.5px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 14%, transparent);
}

/* ───────── 아이콘 ───────── */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i {
  display: inline-block; width: 15px; height: 15px; flex: none;
  fill: currentColor; vertical-align: -3px;
}
.i.sm { width: 12px; height: 12px; vertical-align: -2px; }
.send-btn .i { width: 15px; height: 15px; vertical-align: 0; }
.send-btn .busy-dots { font-size: 13px; line-height: 1; }
.mini-btn .i { width: 12px; height: 12px; vertical-align: 0; }
.session-item .more .i { width: 13px; height: 13px; vertical-align: 0; }
.icon-btn .i { vertical-align: -3px; }

/* ───────── 버튼 ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  height: 28px; padding: 0 10px; border-radius: var(--r-sm);
  border: 1px solid var(--stroke-secondary); background: var(--bg-quaternary);
  color: var(--text-primary); font-size: 12.5px; white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: color-mix(in srgb, var(--accent) 7%, var(--bg-quaternary)); }
.btn.primary {
  background: var(--accent); border-color: transparent; color: #ffffff; font-weight: 500;
}
.btn.primary:hover { background: color-mix(in srgb, #000 8%, var(--accent)); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 26%, transparent); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.wide { width: 100%; height: 30px; }
.btn.icon-only { padding: 0 8px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 24px; min-width: 24px; padding: 0 6px;
  border: 1px solid transparent; border-radius: var(--r-xs);
  background: transparent; color: var(--text-tertiary); font-size: 12px;
}
.icon-btn:hover { background: var(--bg-quaternary); color: var(--text-primary); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.ghost-btn {
  height: 24px; padding: 0 8px; font-size: 11.5px; color: var(--text-secondary);
  background: transparent; border: 1px solid transparent; border-radius: var(--r-xs);
}
.ghost-btn:hover { background: var(--bg-quaternary); color: var(--text-primary); }

/* ───────── 앱 골격 ───────── */
.app {
  display: grid; grid-template-columns: var(--side-width) minmax(0, 1fr);
  height: 100dvh; overflow: hidden; background: var(--bg-editor);
}

/* ───────── 사이드바 ───────── */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-sidebar); border-right: 1px solid var(--stroke-tertiary);
}
.side-head { padding: 8px 8px 4px; display: grid; gap: 7px; }
.side-brand { display: flex; align-items: center; gap: 7px; padding: 1px 2px 3px; }
.side-logo { width: 20px; height: 20px; border-radius: var(--r-xs); }
.side-title { font-size: 12.5px; font-weight: 600; letter-spacing: -0.01em; }
.side-sub { font-size: 10.5px; color: var(--text-quaternary); }
.side-brand > div { min-width: 0; flex: 1; }
.side-brand .icon-btn { margin-left: auto; }

.new-chat-row { display: flex; gap: 4px; }
.new-chat-row .btn.primary {
  flex: 1; justify-content: flex-start; height: 28px; padding: 0 9px;
  background: var(--bg-editor); color: var(--text-primary);
  border-color: var(--stroke-secondary); font-weight: 500;
}
.new-chat-row .btn.primary:hover { background: var(--accent-fill); border-color: var(--accent-line); }
.new-chat-row .btn.icon-only {
  height: 28px; background: var(--bg-editor); border-color: var(--stroke-secondary);
  color: var(--text-tertiary); border-radius: var(--r-sm);
}
.plus { color: var(--accent); font-size: 13px; line-height: 1; }

.side-search { position: relative; }
.side-search input {
  width: 100%; height: 26px; padding: 0 52px 0 8px;
  background: var(--bg-editor); color: var(--text-primary);
  border: 1px solid var(--stroke-secondary); border-radius: var(--r-sm);
  font-size: 12px; outline: none;
}
.side-search input::placeholder { color: var(--text-quaternary); }
.side-search input:focus { border-color: var(--accent); }
.search-kbd {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font-family: var(--font); font-size: 9.5px; color: var(--text-quaternary);
  border: 1px solid var(--stroke-tertiary); border-radius: var(--r-xs);
  padding: 0 3px; line-height: 14px; pointer-events: none;
}

.side-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 2px 6px 10px; display: grid; align-content: start; gap: 10px; }
.side-scroll::-webkit-scrollbar { width: 8px; }
.side-scroll::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--fg) 12%, transparent); border-radius: 4px; }
.side-scroll::-webkit-scrollbar-track { background: transparent; }

.side-section { display: grid; gap: 1px; }
.side-section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 6px 2px; font-size: 10.5px; font-weight: 600;
  color: var(--text-quaternary); letter-spacing: 0.04em; text-transform: uppercase;
}
.mini-btn {
  width: 18px; height: 18px; border: 0; border-radius: var(--r-xs);
  background: transparent; color: var(--text-quaternary); font-size: 13px; line-height: 1;
}
.mini-btn:hover { background: var(--bg-quaternary); color: var(--text-primary); }

.project-list { display: grid; gap: 1px; }
.project-item {
  display: flex; align-items: center; gap: 7px; width: 100%;
  height: 26px; padding: 0 6px; border: 0; border-radius: var(--r-xs);
  background: transparent; text-align: left; font-size: 12.5px; color: var(--text-secondary);
}
.project-item:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); color: var(--text-primary); }
.project-item.active { background: color-mix(in srgb, var(--accent) 8%, transparent); color: var(--text-primary); }
.project-dot { width: 6px; height: 6px; border-radius: 1px; flex: none; }
.project-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-count { font-size: 10.5px; color: var(--text-quaternary); }

.session-list { display: grid; gap: 1px; }
.session-item {
  position: relative; display: grid; gap: 0;
  padding: 4px 22px 5px 7px; border-radius: var(--r-xs);
  cursor: pointer; border-left: 2px solid transparent;
}
.session-item:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.session-item.active { background: color-mix(in srgb, var(--accent) 8%, transparent); border-left-color: var(--accent); }
.session-item .t {
  font-size: 12.5px; color: var(--text-primary); line-height: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.session-item .p {
  font-size: 10.5px; color: var(--text-quaternary); line-height: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.session-item .more {
  position: absolute; right: 2px; top: 3px; width: 18px; height: 18px;
  border: 0; border-radius: var(--r-xs); background: transparent;
  color: var(--text-tertiary); font-size: 12px; line-height: 1; opacity: 0;
}
.session-item:hover .more, .session-item.active .more { opacity: 1; }
.session-item .more:hover { background: var(--bg-quaternary); color: var(--text-primary); }
.pin {
  display: inline-block; margin-right: 4px; padding: 0 3px;
  font-size: 9px; line-height: 13px; vertical-align: 1px;
  color: var(--accent); background: var(--accent-fill); border-radius: 1px;
}
.pin.temp { color: var(--danger); background: var(--danger-soft); }
.date-label {
  padding: 8px 7px 2px; font-size: 10.5px; font-weight: 600;
  color: var(--text-quaternary); letter-spacing: 0.04em; text-transform: uppercase;
}
.side-hint { padding: 2px 7px 4px; font-size: 11px; color: var(--text-quaternary); line-height: 1.45; }

.side-foot {
  border-top: 1px solid var(--stroke-tertiary); padding: 4px 6px 6px;
  display: grid; gap: 1px;
}
.side-link {
  display: flex; align-items: center; height: 24px; padding: 0 7px;
  border: 0; border-radius: var(--r-xs); background: transparent;
  color: var(--text-tertiary); font-size: 11.5px; text-align: left;
}
.side-link:hover { background: var(--bg-quaternary); color: var(--text-primary); }
.side-nav { display: grid; gap: 1px; padding-bottom: 3px; margin-bottom: 3px; border-bottom: 1px solid var(--stroke-tertiary); }
.nav-link { gap: 8px; height: 26px; font-size: 12px; color: var(--text-secondary); }
.nav-link .i { color: var(--text-quaternary); }
.nav-link:hover .i { color: var(--text-secondary); }
.nav-link.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); font-weight: 500; }
.nav-link.active .i { color: var(--accent); }
.side-user {
  display: flex; align-items: center; gap: 7px;
  margin-top: 4px; padding: 5px 6px 3px; border-top: 1px solid var(--stroke-tertiary);
}
.side-user-text { flex: 1; min-width: 0; }
.side-user-name { font-size: 12px; line-height: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-role { font-size: 10px; color: var(--text-quaternary); line-height: 13px; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--accent); }

/* ───────── 본문 ───────── */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-editor); }

.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 42px; flex: none; padding: 0 10px 0 12px;
  border-bottom: 1px solid var(--stroke-tertiary); background: var(--bg-editor);
}
.topbar-title { flex: 1; min-width: 0; display: grid; gap: 0; }
.title-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
#chat-title {
  margin: 0; font-size: 13px; font-weight: 600; letter-spacing: -0.005em;
  line-height: 18px; padding: 1px 3px; border-radius: var(--r-xs);
  outline: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#chat-title:focus { background: var(--bg-quaternary); box-shadow: 0 0 0 1px var(--stroke-secondary); }
.chat-meta { font-size: 10.5px; color: var(--text-quaternary); line-height: 13px; }
.chip-project {
  border: 1px solid var(--stroke-secondary); background: var(--bg-quinary);
  color: var(--text-tertiary); border-radius: var(--r-xs);
  font-size: 10px; line-height: 15px; padding: 0 5px; max-width: 130px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip-project:hover { color: var(--text-primary); border-color: var(--accent-line); }
.chip-temp {
  font-size: 10px; line-height: 15px; padding: 0 5px; border-radius: var(--r-xs);
  background: var(--danger-soft); color: var(--danger);
}
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.model-select {
  height: 24px; max-width: 220px; padding: 0 4px;
  background: transparent; color: var(--text-secondary);
  border: 1px solid transparent; border-radius: var(--r-xs); font-size: 11.5px;
}
.model-select:hover { background: var(--bg-quaternary); color: var(--text-primary); }

/* ───────── 뷰 ───────── */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.thread-banner {
  flex: none; margin: 8px auto 0; width: calc(100% - 32px); max-width: var(--thread-width);
  font-size: 11.5px; color: var(--text-secondary); background: var(--bg-quinary);
  border-left: 2px solid var(--accent-line); border-radius: 0 var(--r-xs) var(--r-xs) 0;
  padding: 6px 10px;
}
.thread-banner.temp { color: var(--danger); border-left-color: var(--danger); background: var(--danger-soft); }

.thread { flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth; }
.thread::-webkit-scrollbar { width: 10px; }
.thread::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--fg) 10%, transparent); border-radius: 5px; }
.thread-inner {
  max-width: var(--thread-width); margin: 0 auto; padding: 18px 20px 140px;
  display: grid; gap: 6px; align-content: start;
}

/* 메시지 */
.msg { position: relative; display: grid; gap: 3px; }
.msg.user { justify-items: end; padding-top: 10px; }
.msg.assistant { padding: 2px 0 6px; }
.msg.user .bubble {
  max-width: 78%; background: var(--accent-fill); color: var(--text-primary);
  border: 1px solid var(--stroke-tertiary); border-radius: var(--r-md);
  padding: 7px 10px; font-size: 13px; line-height: 18px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.error .bubble {
  max-width: 100%; background: var(--danger-soft); color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 22%, transparent);
  border-radius: var(--r-sm); padding: 7px 10px; font-size: 12.5px;
}
.msg .meta { font-size: 10px; color: var(--text-quaternary); padding: 0 2px; }
.msg.user .meta { text-align: right; }

.who { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-tertiary); }
.avatar {
  display: inline-grid; place-items: center; width: 16px; height: 16px;
  border-radius: var(--r-xs); background: var(--accent); color: #ffffff;
  font-size: 8.5px; font-weight: 600; letter-spacing: 0;
}

.md { font-size: 13px; line-height: 18px; color: var(--text-primary); overflow-wrap: anywhere; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.7rem; }
.md h2, .md h3, .md h4, .md h5 { margin: 0.9rem 0 0.4rem; line-height: 1.3; font-weight: 600; }
.md h2 { font-size: 15px; }
.md h3 { font-size: 14px; }
.md h4, .md h5 { font-size: 13px; }
.md ul, .md ol { margin: 0 0 0.7rem; padding-left: 1.15rem; }
.md li { margin: 0 0 0.2rem; }
.md blockquote {
  margin: 0 0 0.7rem; padding: 2px 0 2px 9px;
  border-left: 2px solid var(--stroke-secondary); color: var(--text-secondary);
}
.md hr { border: 0; border-top: 1px solid var(--stroke-tertiary); margin: 0.9rem 0; }
.md strong { font-weight: 600; }
.md code {
  font-family: var(--mono); font-size: 11.5px;
  background: var(--bg-quaternary); border-radius: var(--r-xs); padding: 1px 4px;
}
.md pre {
  position: relative; margin: 0 0 0.8rem; padding: 9px 10px;
  background: var(--bg-card); border: 1px solid var(--stroke-tertiary);
  border-radius: var(--r-sm); overflow-x: auto;
}
[data-theme='dark'] .md pre { background: #1b1b1e; }
.md pre code { background: none; padding: 0; font-size: 11.5px; line-height: 17px; }
.md pre .code-lang {
  display: block; margin-bottom: 4px; font-size: 10px;
  color: var(--text-quaternary); text-transform: lowercase;
}
.md pre .copy {
  position: absolute; top: 5px; right: 5px; height: 18px; padding: 0 5px;
  font-size: 10px; color: var(--text-tertiary); background: var(--bg-editor);
  border: 1px solid var(--stroke-tertiary); border-radius: var(--r-xs); opacity: 0;
}
.md pre:hover .copy { opacity: 1; }
.md table { border-collapse: collapse; font-size: 12px; margin: 0 0 0.7rem; }
.md th, .md td { border: 1px solid var(--stroke-tertiary); padding: 3px 7px; text-align: left; }

.typing { display: inline-flex; gap: 3px; padding: 4px 0; }
.typing i {
  width: 3px; height: 3px; border-radius: 50%; background: var(--text-quaternary);
  animation: blink 1.1s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

.msg-actions {
  position: absolute; right: 0; top: -10px; display: flex; gap: 2px;
  opacity: 0; transition: opacity 0.1s ease;
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
.msg-actions button {
  height: 19px; padding: 0 5px; font-size: 10.5px;
  color: var(--text-tertiary); background: var(--bg-editor);
  border: 1px solid var(--stroke-tertiary); border-radius: var(--r-xs);
}
.msg-actions button:hover { color: var(--text-primary); background: var(--bg-quaternary); }

/* 빈 화면 */
.empty {
  flex: 1; display: grid; place-content: center; justify-items: center;
  gap: 4px; padding: 20px; text-align: center; color: var(--text-tertiary);
}
.empty h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text-primary); }
.empty p { margin: 0; font-size: 12px; max-width: 380px; line-height: 1.5; }
.empty-mark {
  width: 42px; height: 42px; border-radius: 10px; margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.empty.small { flex: none; padding: 26px 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-top: 12px; }
.chip {
  height: 24px; padding: 0 9px; font-size: 11.5px;
  color: var(--text-secondary); background: var(--bg-editor);
  border: 1px solid var(--stroke-secondary); border-radius: var(--r-sm);
}
.chip:hover { color: var(--text-primary); border-color: var(--accent-line); background: var(--accent-fill); }

/* 컴포저 */
.composer {
  flex: none; width: 100%; max-width: var(--thread-width);
  margin: 0 auto; padding: 6px 20px 10px;
}
.composer-box {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg-card); border: 1px solid var(--stroke-secondary);
  border-radius: var(--r-md); padding: 5px 5px 5px 9px;
  box-shadow: var(--shadow-composer);
}
.composer-box:focus-within { border-color: var(--accent-line); }
.composer-box textarea {
  flex: 1; min-height: 20px; max-height: 180px; resize: none;
  border: 0; outline: none; background: transparent;
  font-size: 13px; line-height: 20px; padding: 2px 0; color: var(--text-primary);
}
.composer-box textarea::placeholder { color: var(--text-quaternary); }
.send-btn {
  flex: none; width: 26px; height: 26px; border: 0; border-radius: var(--r-sm);
  background: var(--accent); color: #ffffff; font-size: 13px; line-height: 1;
  display: grid; place-items: center;
}
.send-btn:hover { background: color-mix(in srgb, #000 8%, var(--accent)); }
.send-btn:disabled { background: var(--bg-quaternary); color: var(--text-quaternary); cursor: default; }

.composer-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 4px 2px 0;
}
.composer-meta { display: flex; align-items: center; gap: 10px; min-width: 0; }
.remember { display: flex; align-items: center; gap: 4px; font-size: 10.5px; color: var(--text-quaternary); }
.remember select {
  height: 19px; border: 1px solid transparent; border-radius: var(--r-xs);
  background: transparent; color: var(--text-tertiary); font-size: 10.5px; padding: 0 2px;
}
.remember select:hover { background: var(--bg-quaternary); color: var(--text-primary); }
.hint { font-size: 10.5px; color: var(--text-quaternary); }

/* ───────── 페이지(기억·관리·설정) ───────── */
.page {
  flex: 1; min-height: 0; overflow-y: auto;
  width: 100%; max-width: var(--thread-width); margin: 0 auto; padding: 18px 20px 40px;
}
.page.narrow { max-width: 620px; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--stroke-tertiary);
}
.page-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.page-head p { margin: 2px 0 0; font-size: 11.5px; color: var(--text-tertiary); }
.section-title {
  margin: 18px 0 6px; font-size: 11px; font-weight: 600;
  color: var(--text-quaternary); letter-spacing: 0.04em; text-transform: uppercase;
}
.card { padding: 12px 0; border-top: 1px solid var(--stroke-tertiary); }
.card:first-of-type { border-top: 0; }
.card h3 { margin: 0 0 6px; font-size: 12.5px; font-weight: 600; }
.card .field { margin-top: 8px; }
.row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; }
.inline { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-secondary); }
.inline select { height: 24px; border: 1px solid var(--stroke-secondary); border-radius: var(--r-sm); background: var(--bg-editor); font-size: 11.5px; }
.build-note { margin: 22px 0 0; font-size: 10.5px; color: var(--text-quaternary); text-align: center; }

.segmented { display: inline-flex; border: 1px solid var(--stroke-secondary); border-radius: var(--r-sm); overflow: hidden; }
.seg {
  height: 24px; padding: 0 9px; border: 0; background: transparent;
  color: var(--text-tertiary); font-size: 11.5px;
}
.seg + .seg { border-left: 1px solid var(--stroke-tertiary); }
.seg:hover { background: var(--bg-quaternary); color: var(--text-primary); }
.seg.active { background: var(--accent-fill); color: var(--accent); font-weight: 500; }

/* 기억 */
.memory-form { display: grid; gap: 6px; margin-top: 12px; }
.memory-form textarea {
  width: 100%; resize: vertical; background: var(--bg-editor);
  border: 1px solid var(--stroke-secondary); border-radius: var(--r-sm);
  padding: 7px 9px; font-size: 12.5px; line-height: 18px; outline: none;
}
.memory-form textarea:focus { border-color: var(--accent); }
.memory-form-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.memory-form-foot .row { margin-top: 0; }
.memory-list { display: grid; margin-top: 8px; }
.memory-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 9px 2px; border-top: 1px solid var(--stroke-tertiary);
}
.memory-item .body { flex: 1; min-width: 0; }
.memory-item .text { font-size: 12.5px; line-height: 18px; overflow-wrap: anywhere; }
.memory-item .sub { display: flex; align-items: center; gap: 8px; margin-top: 2px; font-size: 10.5px; color: var(--text-quaternary); }
.badge {
  padding: 0 4px; font-size: 9.5px; line-height: 14px; border-radius: var(--r-xs);
  background: var(--bg-quaternary); color: var(--text-tertiary);
}
.badge.family { background: var(--accent-fill); color: var(--accent); }
.badge.project { background: var(--bg-quinary); color: var(--text-secondary); border: 1px solid var(--stroke-tertiary); }

/* 관리 */
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 12px 0 4px; }
.stat { padding: 8px 0; border-top: 1px solid var(--stroke-tertiary); }
.stat .n { font-size: 17px; font-weight: 600; line-height: 22px; letter-spacing: -0.02em; }
.stat .l { font-size: 10.5px; color: var(--text-quaternary); }

.invite-list { display: grid; gap: 1px; }
.invite-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-top: 1px solid var(--stroke-tertiary);
}
.invite-item:first-child { border-top: 0; }
.invite-code {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em;
  background: var(--bg-quaternary); border-radius: var(--r-xs); padding: 2px 6px;
}

.provider-list { display: grid; }
.provider-card { padding: 11px 0; border-top: 1px solid var(--stroke-tertiary); }
.provider-head { display: flex; align-items: center; gap: 8px; }
.provider-head .name { font-size: 12.5px; font-weight: 600; }
.provider-head .type { font-size: 10.5px; color: var(--text-quaternary); }
.provider-head .spacer { flex: 1; }
.provider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.provider-card .field { margin-top: 8px; }
.provider-card textarea {
  width: 100%; resize: vertical; font-family: var(--mono); font-size: 11px;
  background: var(--bg-editor); border: 1px solid var(--stroke-secondary);
  border-radius: var(--r-sm); padding: 6px 8px; outline: none;
}
.provider-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.key-state { font-size: 10.5px; color: var(--text-quaternary); }
.key-state.on { color: var(--ok); }

.switch { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-tertiary); }
.switch input { accent-color: var(--accent); }

.member-list { display: grid; }
.member-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-top: 1px solid var(--stroke-tertiary);
}
.member-item .grow { flex: 1; min-width: 0; }
.member-item .sub { font-size: 10.5px; color: var(--text-quaternary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 프로젝트 화면 */
.project-sessions { display: grid; }
.project-session {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  padding: 8px 2px; border: 0; border-top: 1px solid var(--stroke-tertiary);
  background: transparent; text-align: left;
}
.project-session:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.ps-title { flex: 1; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-meta { font-size: 10.5px; color: var(--text-quaternary); flex: none; }

/* ───────── 메뉴·토스트 ───────── */
.menu-pop {
  position: fixed; z-index: 60; min-width: 168px; padding: 3px;
  background: var(--bg-editor); border: 1px solid var(--stroke-secondary);
  border-radius: var(--r-md); box-shadow: var(--shadow-menu);
  display: grid; gap: 1px;
}
.menu-pop button {
  height: 25px; padding: 0 8px; text-align: left; font-size: 12px;
  color: var(--text-primary); background: transparent; border: 0; border-radius: var(--r-xs);
}
.menu-pop button:hover { background: var(--bg-quaternary); }
.menu-pop button.danger { color: var(--danger); }
.menu-pop button.danger:hover { background: var(--danger-soft); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 8px);
  background: var(--fg); color: var(--bg-editor);
  font-size: 11.5px; padding: 6px 11px; border-radius: var(--r-sm);
  opacity: 0; pointer-events: none; transition: opacity 0.16s ease, transform 0.16s ease;
  z-index: 70; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
[data-theme='dark'] .toast { background: #f2f2f2; color: #111111; }

/* ───────── 모바일 ───────── */
.scrim { position: fixed; inset: 0; background: rgba(10, 10, 12, 0.32); z-index: 40; }
.only-mobile { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 50; inset: 0 auto 0 0; width: min(84vw, 300px);
    transform: translateX(-102%); transition: transform 0.18s ease;
    box-shadow: var(--shadow-menu);
  }
  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: inline-flex; }
  .only-desktop { display: none; }
  .topbar { height: 44px; padding: 0 8px; }
  .thread-inner { padding: 14px 14px 104px; }
  .composer { padding: 4px 12px calc(6px + env(safe-area-inset-bottom)); }
  .composer-foot { padding-bottom: 2px; }
  .page { padding: 14px 14px 28px; }
  .view { padding-bottom: 0; }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .provider-grid { grid-template-columns: 1fr; }
  .msg.user .bubble { max-width: 88%; }
  .topbar-actions .model-select { max-width: 120px; }
}

/* 사이드바 접기(데스크톱) */
body.sidebar-collapsed .app { grid-template-columns: 0 minmax(0, 1fr); }
body.sidebar-collapsed .sidebar { width: 0; overflow: hidden; border-right: 0; }


/* 키보드 사용자를 위한 포커스 표시 */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ───────── 로그인: Google + 인증번호 ───────── */
.auth-google { display: grid; gap: 10px; }
.google-btn {
  justify-content: center; gap: 8px; height: 38px; font-size: 13px;
  text-decoration: none; letter-spacing: -0.01em;
}
.google-btn .g-mark { width: 16px; height: 16px; flex: none; }
.google-btn.disabled { opacity: 0.45; pointer-events: none; }
.auth-note { text-align: center; line-height: 17px; }
.auth-note.warn { color: var(--danger); }
.code-input {
  width: 100%; height: 46px; text-align: center;
  font-size: 22px; letter-spacing: 10px; font-variant-numeric: tabular-nums;
  padding: 0 0 0 10px; margin-bottom: 10px;
  border: 1px solid var(--stroke-secondary); border-radius: var(--r-md);
  background: var(--bg-card); color: var(--text-primary);
}
.code-input:focus { border-color: var(--accent-line); outline: none; }
.verify-lead { font-size: 13px; line-height: 19px; color: var(--text-secondary); margin-bottom: 10px; }
.verify-dev { color: var(--accent); font-variant-numeric: tabular-nums; min-height: 16px; }

/* ───────── 관리자: 로그인 설정 · 승인 ───────── */
.sub-block { border-top: 1px solid var(--stroke-tertiary); margin-top: 4px; padding-top: 10px; }
.sub-title { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field-row .field.short { flex: 0 0 84px; }
.pending-list { display: grid; gap: 1px; border: 1px solid var(--stroke-tertiary); border-radius: var(--r-sm); overflow: hidden; }
.pending-item {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 12px; background: var(--bg-card);
  border-bottom: 1px solid var(--stroke-tertiary);
}
.pending-item:last-child { border-bottom: 0; }
.pending-main { flex: 1; min-width: 160px; }
.pending-who { font-size: 13px; }
.pending-meta { font-size: 11.5px; color: var(--text-quaternary); margin-top: 2px; }
.pending-actions { display: flex; gap: 6px; align-items: center; }
.pending-name { width: 140px; height: 28px; font-size: 12.5px; }
@media (max-width: 860px) {
  .field-row { flex-direction: column; gap: 0; }
  .pending-name { flex: 1; width: auto; }
}

/* 관리자: 비밀번호 재설정 */
.pw-reset {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding: 8px 12px; background: var(--bg-secondary);
  border-bottom: 1px solid var(--stroke-tertiary);
}
.pw-reset input { flex: 1; min-width: 160px; height: 28px; font-size: 12.5px; }

/* ───────── 첨부 ───────── */
.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 0 6px 30px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 4px 0 8px; border-radius: 3px;
  background: var(--bg-quaternary); border: 1px solid var(--stroke-tertiary);
  font-size: 11.5px; max-width: 240px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.attach-chip button { border: 0; background: transparent; color: var(--text-quaternary); font-size: 13px; line-height: 1; padding: 0 2px; }
.attach-chip button:hover { color: var(--danger); }
.attach-btn { flex: none; width: 26px; height: 26px; color: var(--text-tertiary); }
.attach-btn:hover { color: var(--text-primary); background: var(--bg-quaternary); }
.composer-box.dragging { border-color: var(--accent-line); background: color-mix(in srgb, var(--accent) 4%, var(--bg-card)); }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.attachments img {
  max-width: 220px; max-height: 220px; border-radius: 4px;
  border: 1px solid var(--stroke-secondary); display: block;
}
.file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 9px; border-radius: 3px;
  border: 1px solid var(--stroke-secondary); background: var(--bg-secondary);
  font-size: 11.5px; color: var(--text-secondary); text-decoration: none;
}
.file-chip:hover { border-color: var(--accent-line); color: var(--text-primary); }
.msg.user .attachments { justify-content: flex-end; }

/* 응답 모드 */
.mode-seg { display: inline-flex; border: 1px solid var(--stroke-tertiary); border-radius: 3px; overflow: hidden; }
.mode-seg button {
  border: 0; background: transparent; font-size: 11.5px; height: 22px; padding: 0 10px;
  color: var(--text-tertiary); cursor: pointer;
}
.mode-seg button + button { border-left: 1px solid var(--stroke-tertiary); }
.mode-seg button.active { background: var(--accent); color: #fff; }
.mode-seg button:not(.active):hover { background: var(--bg-quaternary); color: var(--text-primary); }
