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

/* Radix Colors: slate (gray) + blue (accent) + red (danger) */
:root, [data-theme="github-dark"] {
  --bg-chat: #0f0f0f;       /* near-black — pure black causes OLED smearing on scroll */
  --bg-sidebar: #0a0a0a;    /* near-black */
  --bg-input: #111111;      /* input area */
  --bg-msg-user: #0a3d6e;   /* blue — 3.2:1 on bg-chat */
  --bg-msg-assistant: #181818;
  --bg-hover: #1a1a1a;
  --bg-code: #000000;       /* static — pure black OK */
  --bg-code-inline: #1a1a1a;
  --border: #3a3a3a;         /* 3:1 on bg-chat for WCAG non-text contrast */
  --text: #edeef0;          /* slate-12 */
  --text-muted: #b0b4ba;    /* slate-11 */
  --accent: #0090ff;        /* blue-9 */
  --accent-hover: #3b9eff;  /* blue-10 */
  --accent-text: #70b8ff;   /* blue-11 */
  --btn-accent-text: #111113; /* slate-1 */
  --danger: #e5484d;        /* red-9 */
  --danger-hover: #dc3e42;  /* red-10 (light) / #ec5d5e (dark) — using light for stop btn contrast */
  --error-text: #ff9592;    /* red-11 dark */
  --text-tertiary: #8b8f96; /* metadata (timestamps, model tags) — 4.6:1 on bg-chat */
  --sidebar-width: 280px;
  --header-h: 48px;
  --pad-x: 0.75rem;
  --pad-y: 0.75rem;
  --msg-gap: 0.75rem;
  --fs-xs: 0.6875rem;    /* 11px — quota counters, code labels */
  --fs-sm: 0.75rem;      /* 12px — timestamps, badges, meta */
  --fs-base: 0.875rem;   /* 14px — sidebar items, menus */
  --fs-md: 1rem;         /* 16px — message body, inputs */
  --fs-lg: 1.125rem;     /* 18px — headings */
  --font-mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  /* Motion durations — decorative (subject to prefers-reduced-motion).
     State-conveying animations (pulse-dot, cursorBlink, pulse-opacity) keep
     literal durations because they communicate active processing — exempt
     by W3C "essential motion" guidance. */
  --motion-decorative: 0.16s;
}

[data-theme="github-light"] {
  --bg-chat: #ffffff;
  --bg-sidebar: #f2f2f2;
  --bg-input: #eaeaea;
  --bg-msg-user: #dce8f0;    /* muted blue-gray — e-ink: light gray */
  --bg-msg-assistant: #f5f5f5;
  --bg-hover: #d8d8d8;
  --bg-code: #efefef;
  --bg-code-inline: #e5e5e5;
  --border: #aaaaaa;
  --text: #000000;
  --text-muted: #555555;     /* 7.5:1 on white */
  --accent: #1a5a9e;         /* dark blue — 7.3:1 on white, e-ink: dark gray */
  --accent-hover: #144a84;
  --accent-text: #1a5a9e;
  --btn-accent-text: #ffffff;
  --danger: #9e2a2a;         /* dark red — 8.6:1 on white, e-ink: dark gray */
  --danger-hover: #7a2020;
  --error-text: #8a2020;     /* 7.8:1 on white */
  --text-tertiary: #666666;  /* 5.7:1 on white */
  --sidebar-width: 280px;
}

/* Syntax highlighting — GitHub Dark (on Radix bg-code) */
:root .hljs, [data-theme="github-dark"] .hljs { background: transparent; color: #c9d1d9; }
[data-theme="github-dark"] .hljs-keyword,
[data-theme="github-dark"] .hljs-doctag,
[data-theme="github-dark"] .hljs-type,
[data-theme="github-dark"] .hljs-variable.language_ { color: #ff7b72; }
[data-theme="github-dark"] .hljs-title,
[data-theme="github-dark"] .hljs-title.class_,
[data-theme="github-dark"] .hljs-title.function_ { color: #d2a8ff; }
[data-theme="github-dark"] .hljs-attr,
[data-theme="github-dark"] .hljs-attribute,
[data-theme="github-dark"] .hljs-literal,
[data-theme="github-dark"] .hljs-number,
[data-theme="github-dark"] .hljs-operator,
[data-theme="github-dark"] .hljs-variable,
[data-theme="github-dark"] .hljs-selector-attr,
[data-theme="github-dark"] .hljs-selector-class,
[data-theme="github-dark"] .hljs-selector-id { color: #79c0ff; }
[data-theme="github-dark"] .hljs-string,
[data-theme="github-dark"] .hljs-regexp,
[data-theme="github-dark"] .hljs-meta .hljs-string { color: #a5d6ff; }
[data-theme="github-dark"] .hljs-built_in,
[data-theme="github-dark"] .hljs-symbol { color: #ffa657; }
[data-theme="github-dark"] .hljs-comment,
[data-theme="github-dark"] .hljs-code,
[data-theme="github-dark"] .hljs-formula { color: #8b949e; }
[data-theme="github-dark"] .hljs-name,
[data-theme="github-dark"] .hljs-quote,
[data-theme="github-dark"] .hljs-selector-tag,
[data-theme="github-dark"] .hljs-selector-pseudo { color: #7ee787; }
[data-theme="github-dark"] .hljs-section { color: #1f6feb; font-weight: 700; }
[data-theme="github-dark"] .hljs-bullet { color: #f2cc60; }
[data-theme="github-dark"] .hljs-addition { color: #aff5b4; background: #033a16; }
[data-theme="github-dark"] .hljs-deletion { color: #ffdcd7; background: #67060c; }

/* Syntax highlighting — GitHub Light */
[data-theme="github-light"] .hljs { background: transparent; color: #24292e; }
[data-theme="github-light"] .hljs-keyword,
[data-theme="github-light"] .hljs-doctag,
[data-theme="github-light"] .hljs-type,
[data-theme="github-light"] .hljs-variable.language_ { color: #d73a49; }
[data-theme="github-light"] .hljs-title,
[data-theme="github-light"] .hljs-title.class_,
[data-theme="github-light"] .hljs-title.function_ { color: #6f42c1; }
[data-theme="github-light"] .hljs-attr,
[data-theme="github-light"] .hljs-attribute,
[data-theme="github-light"] .hljs-literal,
[data-theme="github-light"] .hljs-number,
[data-theme="github-light"] .hljs-operator,
[data-theme="github-light"] .hljs-variable,
[data-theme="github-light"] .hljs-selector-attr,
[data-theme="github-light"] .hljs-selector-class,
[data-theme="github-light"] .hljs-selector-id { color: #005cc5; }
[data-theme="github-light"] .hljs-string,
[data-theme="github-light"] .hljs-regexp,
[data-theme="github-light"] .hljs-meta .hljs-string { color: #032f62; }
[data-theme="github-light"] .hljs-built_in,
[data-theme="github-light"] .hljs-symbol { color: #e36209; }
[data-theme="github-light"] .hljs-comment,
[data-theme="github-light"] .hljs-code,
[data-theme="github-light"] .hljs-formula { color: #6a737d; }
[data-theme="github-light"] .hljs-name,
[data-theme="github-light"] .hljs-quote,
[data-theme="github-light"] .hljs-selector-tag,
[data-theme="github-light"] .hljs-selector-pseudo { color: #22863a; }
[data-theme="github-light"] .hljs-section { color: #005cc5; font-weight: 700; }
[data-theme="github-light"] .hljs-bullet { color: #735c0f; }
[data-theme="github-light"] .hljs-addition { color: #22863a; background: #f0fff4; }
[data-theme="github-light"] .hljs-deletion { color: #b31d28; background: #ffeef0; }

/* UI chrome — monospace (ASCII 전용 요소만) */
.cmd-picker-item .cmd-name,
.auth-box h1 {
  font-family: var(--font-mono);
}

body {
  font-family: "PretendardVariable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg-chat);
  color: var(--text);
  height: var(--app-h, 100svh);
  overflow: hidden;
}

/* 스크롤바 (Webkit) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* 스크롤바 (Firefox) */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Focus-visible — keyboard navigation */
.header-icon-btn:focus-visible,
.action-btn:focus-visible,
.send-btn:focus-visible,
.attach-btn:focus-visible,
.quota-chip:focus-visible,
.chat-title:focus-visible,
.session-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Auth */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-sidebar);
}
.auth-box {
  text-align: center;
}
.auth-box h1 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.auth-box input {
  display: block;
  width: 280px;
  padding: 0.6rem 1rem;
  margin-bottom: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text);
  font-size: var(--fs-md);
}
.auth-box button {
  padding: 0.6rem 2rem;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--btn-accent-text);
  font-weight: 600;
  cursor: pointer;
  font-size: var(--fs-md);
  width: 280px;
}
.auth-error {
  color: var(--error-text);
  font-size: var(--fs-sm);
  margin-top: 0.5rem;
}

/* App layout */
.app {
  display: flex;
  height: var(--app-h, 100svh);
}

/* Sidebar */
.sidebar {
  position: relative;
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--pad-x);
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
}
.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.sidebar-title {
  font-weight: 600;
  font-size: var(--fs-base);
}
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0;
}
.session-item {
  position: relative;
  padding: 0.5rem var(--pad-x);
  cursor: pointer;
  border-left: 3px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-left-color: var(--accent);
}
.session-item.processing::after {
  content: "";
  position: absolute;
  right: var(--pad-x);
  top: 0.85rem;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}
.session-item.processing .name { padding-right: 14px; }
.session-item.has-unread .name { font-weight: 600; }
.session-item.has-unread .time { color: var(--accent-text); }
.session-item .name {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--fs-base);
  font-weight: 500;
}
.session-item .meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.session-item .time {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
}
/* Session menu (... button + dropdown) */
.session-menu-wrap {
  position: relative;
  flex-shrink: 0;
}
.session-menu-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  letter-spacing: -1px;
}
.session-item:hover .session-menu-btn,
.session-menu-btn[aria-expanded="true"] { opacity: 0.7; }
.session-menu-btn:hover { opacity: 1; background: var(--bg-hover); }

.session-menu {
  z-index: 500;
  min-width: 110px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 0.3rem 0;
}
.session-menu-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  color: var(--text);
  font-size: var(--fs-base);
  text-align: left;
  cursor: pointer;
}
.session-menu-item + .session-menu-item {
  border-top: 1px solid var(--border);
}
.session-menu-item:hover { background: var(--bg-hover); }
.session-menu-item.danger { color: var(--danger); }
.session-menu-item.danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); }

/* Session empty state */
.session-empty {
  padding: 1.5rem 0.75rem;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  text-align: center;
}

/* Archive entry (inside session-list, sticky bottom) */
.archive-entry {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem var(--pad-x);
  background: var(--bg-sidebar);
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  cursor: pointer;
  text-align: left;
}
.archive-entry:hover { color: var(--text); background: var(--bg-hover); }
.archive-entry svg { flex-shrink: 0; }

/* Archive view header (back button) */
.archive-view-header {
  padding: 0.4rem var(--pad-x);
  border-bottom: 1px solid var(--border);
}
.archive-back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: var(--fs-base);
  cursor: pointer;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
}
.archive-back-btn:hover { background: var(--bg-hover); }

/* Toast — overlays above footer, no layout shift */
.sidebar-toast {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem var(--pad-x);
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
  font-size: var(--fs-base);
  color: var(--text);
  position: absolute;
  bottom: 48px;
  left: 0.5rem;
  right: 0.5rem;
  z-index: 60;
}
.sidebar-toast.show { display: flex; }
.toast-undo {
  background: none;
  border: none;
  color: var(--accent);
  font-size: var(--fs-base);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  padding: 0.4rem 0.5rem;
  min-height: 36px;
}
.toast-undo:hover { text-decoration: underline; }

/* Legacy action-btn — kept for compatibility */
.action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--fs-md);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.action-btn:hover { opacity: 1; background: var(--bg-hover); }
.action-btn.del:hover { color: var(--danger); }

/* Sidebar resize handle */
.sidebar-resize {
  width: 8px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  transition: background 0.15s;
}
.sidebar-resize:hover,
.sidebar-resize.active {
  background: var(--accent);
}

/* Chat area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-header {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 var(--pad-x);
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
}
.chat-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* Header icon button — shared style for all header areas */
.header-icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--fs-md);
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-icon-btn:hover { color: var(--text); background: var(--bg-hover); border-color: var(--border); }

/* Quota chip */
.quota-chip {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 8px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.2s, background 0.2s;
}
.quota-chip:hover { color: var(--text); background: var(--bg-hover); }
.quota-chip.warning { border-color: #f0a030; background: color-mix(in srgb, #f0a030 12%, transparent); }
.quota-chip.critical { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.quota-chip-label {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
  font-family: var(--font-mono);
}
.quota-chip-label:empty { display: none; }

/* Quota popover */
.quota-popover {
  position: absolute;
  top: 100%;
  right: 0.5rem;
  width: 320px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  z-index: 200;
  padding: 0.4rem 0;
  margin-top: 4px;
}
.quota-section { padding: 0.35rem 0.75rem; }
.quota-section + .quota-section,
.quota-section + .quota-details,
.quota-details + .quota-section {
  border-top: 1px solid var(--border);
  margin-top: 0.15rem;
  padding-top: 0.4rem;
}
.quota-section-title {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
}
/* Collapsible API details */
.quota-details {
  padding: 0.35rem 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: 0.15rem;
  padding-top: 0.4rem;
}
.quota-summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0;
}
.quota-summary::-webkit-details-marker { display: none; }
.quota-summary::after {
  content: "\25B8";
  font-size: 0.6rem;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.quota-details[open] > .quota-summary::after {
  transform: rotate(90deg);
}
.quota-details[open] > .quota-summary {
  margin-bottom: 0.25rem;
}
.quota-count {
  font-weight: 400;
  opacity: 0.7;
}
/* Issues section */
.quota-issue-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0;
  font-size: var(--fs-sm);
}
.quota-issue-row .q-issue-name {
  color: var(--text);
  flex-shrink: 0;
}
.quota-issue-row .q-issue-detail {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  flex: 1;
  text-align: right;
}
.quota-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0;
  font-size: var(--fs-sm);
}
.quota-row .q-name {
  min-width: 5.2rem;
  color: var(--text);
  flex-shrink: 0;
}
.quota-row .q-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.quota-row .q-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}
.quota-row .q-val {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  min-width: 5.5rem;
  text-align: right;
  flex-shrink: 0;
  white-space: nowrap;
}
.quota-row .q-period {
  font-size: var(--fs-xs);
  opacity: 0.7;
  margin-left: 1px;
}
.quota-row .q-status {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  flex: 1;
  text-align: right;
}
.quota-footer {
  padding: 0.3rem 0.75rem 0.2rem;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-align: right;
  border-top: 1px solid var(--border);
  margin-top: 0.2rem;
}
.chat-title {
  font-weight: 600;
  font-size: var(--fs-lg);
  line-height: 28px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0 0.4rem;
}
.chat-title:hover { background: var(--bg-hover); }
.chat-title-input {
  font-weight: 600;
  font-size: var(--fs-md);
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.4rem;
  outline: none;
  min-width: 120px;
  max-width: 320px;
}
/* Sidebar footer (theme + refresh) */
.sidebar-footer {
  padding: var(--pad-y) var(--pad-x);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.theme-select {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.6rem 0.5rem;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.theme-select:focus { outline: none; border-color: var(--accent); }
.sidebar-refresh-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-input);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.sidebar-refresh-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}
.sidebar-restart-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  border-radius: var(--radius-lg);
  background: var(--bg-input);
  color: color-mix(in srgb, var(--danger) 60%, var(--text-muted));
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.sidebar-restart-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}
.sidebar-restart-btn.waiting {
  color: var(--accent);
  border-color: var(--accent);
  animation: pulse-opacity 1s ease-in-out infinite;
}

/* Effort slider (input-area 내부) */
.effort-inline {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 0 0;
}
.effort-inline input[type="range"] {
  width: 96px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  /* background은 JS로 동적 제어 */
}
.effort-inline input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.effort-inline input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}
.effort-label {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  min-width: 3.2rem;
  text-align: right;
}

/* Model toggle */
.model-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.model-opt {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
}
.model-opt[aria-pressed="true"] {
  background: var(--accent);
  color: var(--btn-accent-text);
}
.model-opt:not([aria-pressed="true"]):hover {
  background: color-mix(in srgb, var(--text-muted) 12%, transparent);
}
.model-toggle.disabled {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.5);
}

/* Model badge (chat header) */
.msg-model-tag {
  display: block;
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  margin-top: 0.25rem;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--pad-y) var(--pad-x);
  display: flex;
  flex-direction: column;
  gap: var(--msg-gap);
  background: radial-gradient(
    ellipse 70% 55% at 8% 18%,
    color-mix(in srgb, var(--accent) 5%, var(--bg-chat)),
    var(--bg-chat) 55%
  );
}
.msg {
  max-width: min(85%, 54rem);
  padding: 0.85rem 1rem;
  border-radius: var(--radius-lg);
  line-height: 1.55;
  font-size: var(--fs-md);
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: msgIn var(--motion-decorative) ease-out both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.msg.user {
  align-self: flex-end;
  background: var(--bg-msg-user);
  border-bottom-right-radius: 2px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bg-msg-assistant);
  border-bottom-left-radius: 2px;
}
.msg.assistant.streaming::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  border-radius: 1px;
  animation: cursorBlink 1.1s ease-in-out infinite;
}
@keyframes cursorBlink {
  0%, 40% { opacity: 1; }
  60%, 100% { opacity: 0; }
}

.msg pre {
  background: var(--bg-code);
  padding: 2.1rem 1rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow-x: auto;
  margin: 0.4rem 0;
  font-size: var(--fs-base);
  line-height: 1.5;
  position: relative;
}
.msg .code-lang {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0.28rem 1rem;
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: lowercase;
  letter-spacing: 0.03em;
  pointer-events: none;
}
.msg .code-copy-btn {
  position: absolute;
  top: 0.28rem;
  right: 0.4rem;
  padding: 0.35rem 0.6rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  line-height: 1.4;
}
.msg .code-copy-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.msg code {
  background: var(--bg-code-inline);
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
}
.msg pre code {
  background: none;
  padding: 0;
}
.msg table {
  border-collapse: collapse;
  margin: 0.4rem 0;
  font-size: var(--fs-base);
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.msg th, .msg td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
  text-align: left;
  white-space: normal;
  word-break: keep-all;
}
.msg th {
  background: var(--bg-hover);
}
.msg ul, .msg ol {
  padding-left: 1.5rem;
  margin: 0.35rem 0;
}
.msg li {
  margin: 0.18rem 0;
}
.msg blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 0.9rem;
  margin: 0.4rem 0;
  color: var(--text-muted);
}
.msg h1, .msg h2, .msg h3 {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin: 0.5rem 0 0.25rem;
}
.msg h4, .msg h5, .msg h6 {
  font-size: var(--fs-md);
  font-weight: 600;
  margin: 0.4rem 0 0.2rem;
}
.msg hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75rem 0;
}
.msg kbd {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.4rem;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}
.msg p {
  margin: 0.35rem 0;
}
.msg a {
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg a:hover { color: var(--accent); }

.tool-use {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  padding: 0.18rem 0.5rem;
  border-left: 2px solid var(--accent);
  margin: 0.2rem 0;
  background: color-mix(in srgb, var(--accent) 4%, transparent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-use::before {
  content: "> ";
  color: var(--accent);
  opacity: 0.8;
}

/* 도구 접기 그룹 */
.tool-use-group {
  margin: 0.3rem 0 0.5rem;
}
.tool-use-group-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.tool-use-group-toggle:hover {
  background: color-mix(in srgb, var(--text-muted) 10%, transparent);
}
.tool-use-group-toggle::before {
  content: ">";
  display: inline-block;
  font-size: var(--fs-xs);
  transition: transform 0.15s ease;
}
.tool-use-group.expanded .tool-use-group-toggle::before {
  transform: rotate(90deg);
}
.tool-use-group-items {
  display: none;
  padding: 0.15rem 0 0;
}
.tool-use-group.expanded .tool-use-group-items {
  display: block;
}

.error-notice {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  border-top: 1px dashed var(--border);
  margin-top: 0.8rem;
  padding-top: 0.5rem;
}
.error-notice::before { content: "-- "; }
.error-notice::after  { content: " --"; }

/* Image preview area (above input) */
.image-preview-area {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 var(--pad-x) 0.4rem;
}
.image-preview-area:empty { display: none; }
.img-preview-item {
  position: relative;
  width: 60px;
  height: 60px;
  flex-shrink: 0;
}
.img-preview-item img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  display: block;
}
.img-preview-item .remove-img {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
}
.img-preview-item .remove-img:hover { color: var(--danger); }

/* Attach button (+) */
.attach-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.attach-btn:hover { color: var(--text); background: var(--bg-hover); border-color: var(--text-muted); }
.attach-btn.open { color: var(--text); border-color: var(--text-muted); }
.attach-btn.active-location { color: var(--accent); animation: pulse-opacity 1s ease-in-out infinite; }
.attach-btn.active-voice { color: var(--danger); }

/* Attach panel */
.attach-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding-bottom: 0.5rem;
}
.attach-panel-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
}
.attach-panel-item:hover { color: var(--text); background: var(--bg-hover); }
.attach-panel-item input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

/* Images inside messages */
.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}
.msg-images img {
  max-width: min(240px, 100%);
  max-height: 180px;
  border-radius: var(--radius-md);
  object-fit: contain;
  display: block;
  border: 1px solid var(--border);
  cursor: pointer;
}
.msg-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  display: block;
  margin: 0.4rem 0;
}

/* Share session picker */
.share-picker-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
}
.share-picker-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  width: min(340px, 90vw);
  display: flex; flex-direction: column; gap: 0.8rem;
}
.share-picker-preview {
  width: 100%; max-height: 160px;
  object-fit: cover; border-radius: var(--radius-lg);
}
.share-picker-title {
  font-size: var(--fs-md); font-weight: 600; color: var(--text);
  text-align: center;
}
.share-picker-list {
  display: flex; flex-direction: column; gap: 0.4rem;
  max-height: 240px; overflow-y: auto;
}
.share-picker-item {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-lg); border: 1px solid var(--border);
  background: var(--bg-sidebar); color: var(--text);
  font-size: var(--fs-base); text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.share-picker-item:hover { background: var(--bg-hover); }
.share-picker-new { color: var(--accent); border-color: var(--accent); }
.share-picker-cancel {
  padding: 0.5rem; border-radius: var(--radius-lg); border: none;
  background: none; color: var(--text-muted);
  font-size: var(--fs-sm); cursor: pointer; text-align: center;
}
.share-picker-cancel:hover { color: var(--text); }

/* 긴 사용자 메시지 접기 */
.msg-collapsed {
  max-height: 6rem;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
}
.msg-expand-btn {
  display: block;
  margin-top: 0.3rem;
  background: none;
  border: none;
  color: var(--accent);
  font-size: var(--fs-sm);
  cursor: pointer;
  padding: 0.25rem 0.4rem;
}
.msg-expand-btn:hover { text-decoration: underline; }

.load-more-btn {
  display: block;
  width: 100%;
  margin: 0.5rem 0 1rem;
  padding: 0.4rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  cursor: pointer;
  text-align: center;
}
.load-more-btn:hover { background: var(--bg-hover); }

/* .msg-error-badge — single definition below (near .msg-meta-row) */


/* Input area */
.input-area {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: var(--pad-y) var(--pad-x);
  padding-bottom: max(var(--pad-y), env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}
.input-area textarea {
  flex: 1;
  min-height: 40px;
  resize: none;
  border: 1px solid color-mix(in srgb, var(--text-muted) 35%, var(--border));
  border-radius: var(--radius-lg);
  background: var(--bg-input);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: var(--fs-md);
  font-family: inherit;
  line-height: 1.5;
  max-height: 150px;
  overflow: hidden;
}
.input-area textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
  transition: border-color 0.15s, box-shadow 0.15s;
}
/* Attach panel item states */
.attach-panel-item.loading { color: var(--accent); animation: pulse-opacity 1s ease-in-out infinite; }
@keyframes pulse-opacity { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.attach-panel-item.recording {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}
.attach-panel-item .icon-mic-off { display: none; }
.attach-panel-item.recording .icon-mic { display: none; }
.attach-panel-item.recording .icon-mic-off { display: block; }

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--accent);
  color: var(--btn-accent-text);
  font-weight: 600;
  cursor: pointer;
  font-size: var(--fs-md);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.send-btn:disabled { background: color-mix(in srgb, var(--accent) 30%, var(--bg-chat)); color: var(--text-muted); cursor: not-allowed; }
.send-btn.stop-mode {
  background: var(--danger);
  opacity: 1;
  cursor: pointer;
}
.send-btn.stop-mode:hover { background: var(--danger-hover); }

/* Command picker */
.cmd-picker {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 0 0.5rem 0.3rem;
  overflow: hidden;
  z-index: 50;
}
.cmd-picker-item {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.5rem var(--pad-x);
  cursor: pointer;
  border-left: 3px solid transparent;
}
.cmd-picker-item:hover,
.cmd-picker-item.active {
  background: var(--bg-hover);
  border-left-color: var(--accent);
}
.cmd-picker-item .cmd-name {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--accent);
  min-width: 7rem;
}
.cmd-picker-item .cmd-desc {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* Sidebar collapsed (desktop) */
.sidebar-collapsed .sidebar {
  display: none;
}
.sidebar-collapsed .sidebar-resize {
  display: none;
}

/* Mobile */
.mobile-only { display: none; }
.sidebar-overlay { display: none; }

/* Mobile/tablet breakpoint — KEEP IN SYNC with app.js `DESKTOP_VIEWPORT`. */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: min(72vw, 260px) !important;
    min-width: unset !important;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: flex; }
  .sidebar-resize { display: none; }
  /* Mobile touch targets */
  .header-icon-btn { min-width: 44px; min-height: 44px; }
  .send-btn { min-width: 44px; min-height: 44px; }
  .attach-btn { min-width: 44px; min-height: 44px; }
  .attach-panel-item { min-height: 44px; }
  .quota-chip { min-height: 36px; border-radius: 18px; padding: 0 12px; }
  .input-row { gap: 0.25rem; }
  .input-area textarea { min-height: 44px; }
  /* Slightly larger icons for readability */
  .attach-btn svg { width: 20px; height: 20px; }
  /* Session menu — always visible on mobile (no hover) */
  .session-menu-btn { opacity: 0.6; min-width: 44px; min-height: 44px; }
  .session-menu-item { padding: 0.7rem 0.75rem; font-size: var(--fs-base); min-height: 44px; display: flex; align-items: center; }
  .archive-entry { min-height: 44px; font-size: var(--fs-base); }
  .archive-back-btn { min-height: 44px; font-size: var(--fs-base); padding: 0.5rem 0.6rem; }
  .toast-undo { min-height: 44px; font-size: var(--fs-base); }
  .sidebar-toast { font-size: var(--fs-base); }
  .action-btn { min-width: 44px; min-height: 44px; }
  .sidebar-refresh-btn { width: 44px; height: 44px; }
  .sidebar-restart-btn { width: 44px; height: 44px; }
  .img-preview-item .remove-img { width: 28px; height: 28px; top: -8px; right: -8px; font-size: var(--fs-sm); }
  .msg-tts-btn { min-width: 44px; min-height: 44px; }
  .msg .code-copy-btn { padding: 0.4rem 0.8rem; font-size: var(--fs-sm); min-height: 36px; }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 99;
    background: rgba(0,0,0,0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }
  .sidebar.open ~ .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }
  /* Mobile: compact effort slider */
  .effort-inline {
    gap: 0.25rem;
    padding: 0.5rem 0 0;
  }
  .effort-inline input[type="range"] { width: 88px; }
  .effort-inline input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; }
  .effort-inline input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; }
  .effort-label { font-size: var(--fs-xs); min-width: 2.5rem; }
  .model-opt { padding: 0.35rem 0.6rem; font-size: var(--fs-sm); }
  .retry-btn { min-height: 44px; padding: 0.25rem 0.8rem; }
  .msg-expand-btn { padding: 0.4rem 0.6rem; }
  .load-more-btn { min-height: 44px; }
  .theme-select { min-height: 44px; }
}

.msg-stopped-badge {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-muted) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--text-muted) 18%, transparent);
}

.msg-error-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.msg-error-badge {
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--error-text);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 20%, transparent);
}

.retry-btn {
  padding: 0.25rem 0.6rem;
  min-height: 32px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  color: var(--btn-accent-text);
  background: var(--accent);
  border: none;
  transition: opacity 0.15s;
}
.retry-btn:hover { opacity: 0.85; }

.msg-meta-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.msg-time {
  display: block;
  text-align: right;
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  margin-top: 0.2rem;
}
.msg-meta-row .msg-time,
.msg-meta-row .msg-model-tag {
  display: inline;
  margin-top: 0;
}
.msg-tts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0;
}
.msg-tts-btn:hover { color: var(--text); background: var(--bg-hover); }
.msg-tts-btn.speaking { color: var(--accent); }

/* prefers-reduced-motion — opt-in via --motion-decorative.
   Decorative animations (msgIn etc.) shorten to 0.01ms; transitions globally
   reduced. State-conveying animations use literal durations and are exempt
   per W3C "essential motion" guidance — they communicate processing state
   that can't be conveyed otherwise. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-decorative: 0.01ms;
  }
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
  }
}
