:root {
  --bg: #ffffff;
  --sidebar: #f7f7f8;
  --surface: #ffffff;
  --elevated: #ffffff;
  --text: #171717;
  --muted: #696969;
  --faint: #929292;
  --line: #e6e6e6;
  --line-strong: #d1d1d1;
  --hover: #ececed;
  --active: #e4e4e5;
  --user-bubble: #f1f1f1;
  --code-bg: #171717;
  --code-text: #f4f4f4;
  --accent: #0b7564;
  --accent-soft: #e4f4ef;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, .12), 0 2px 8px rgba(0, 0, 0, .06);
  --sidebar-width: 280px;
  color-scheme: light;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

:root[data-resolved-theme="dark"] {
  --bg: #212121;
  --sidebar: #171717;
  --surface: #2f2f2f;
  --elevated: #2b2b2b;
  --text: #ececec;
  --muted: #b4b4b4;
  --faint: #8d8d8d;
  --line: #3a3a3a;
  --line-strong: #555555;
  --hover: #2b2b2b;
  --active: #303030;
  --user-bubble: #303030;
  --code-bg: #0d0d0d;
  --code-text: #f4f4f4;
  --accent: #5cc5ad;
  --accent-soft: #173b33;
  --danger: #ff8c82;
  --danger-soft: #45231f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .22);
  --shadow-md: 0 14px 36px rgba(0, 0, 0, .38), 0 2px 10px rgba(0, 0, 0, .24);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 320px; height: 100%; }
html { background: var(--bg); }
body { margin: 0; overflow: hidden; background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  top: 8px;
  left: 50%;
  z-index: 100;
  padding: 8px 12px;
  transform: translate(-50%, -160%);
  border-radius: 8px;
  color: var(--surface);
  background: var(--text);
  text-decoration: none;
  transition: transform .15s ease;
}
.skip-link:focus { transform: translate(-50%, 0); }

.app-shell {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  min-width: 0;
  height: 100dvh;
  padding: 10px 9px 8px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  z-index: 30;
}
.sidebar-header {
  min-height: 42px;
  padding: 0 4px 7px 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.wordmark {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
}
.brand-logo { width: 88px; height: 34px; display: block; object-fit: contain; object-position: left center; }
.wordmark span {
  padding-left: 8px;
  border-left: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}
:root[data-resolved-theme="dark"] .brand-logo,
:root[data-resolved-theme="dark"] .hero-mark img,
:root[data-resolved-theme="dark"] .wess-avatar img { filter: brightness(0) invert(1); }

.icon-button {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  font-size: 20px;
  line-height: 1;
}
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:hover { color: var(--text); background: var(--hover); }
.sidebar-close { display: none; }

.new-chat {
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  text-align: left;
  font-size: 14px;
  font-weight: 560;
}
.new-chat:hover { background: var(--hover); }
.new-chat svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.new-chat kbd { margin-left: auto; color: var(--faint); font-family: inherit; font-size: 10px; font-weight: 500; }

.history-search-wrap {
  min-height: 38px;
  margin: 3px 2px 5px;
  padding: 0 9px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
}
.history-search-wrap:hover { background: var(--hover); }
.history-search-wrap:focus-within { border-color: var(--line-strong); background: var(--surface); box-shadow: var(--shadow-sm); }
.history-search-wrap svg { width: 17px; height: 17px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.history-search-wrap input { min-width: 0; flex: 1; padding: 7px 0; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 13px; }
.history-search-wrap input::placeholder { color: var(--muted); }
.history-search-wrap input::-webkit-search-cancel-button { opacity: .55; }
.history-search-wrap kbd { color: var(--faint); font-family: inherit; font-size: 10px; }

.conversation-list { flex: 1; min-height: 0; overflow-y: auto; padding: 1px 1px 8px; scrollbar-width: thin; scrollbar-color: transparent transparent; }
.conversation-list:hover { scrollbar-color: var(--line-strong) transparent; }
.history-group-label {
  margin: 18px 9px 6px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 620;
  letter-spacing: .01em;
}
.history-group-label:first-child { margin-top: 8px; }
.history-empty { margin: 15px 11px; color: var(--faint); font-size: 12px; line-height: 1.55; }
.history-row {
  min-height: 43px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  border-radius: 9px;
}
.history-row:hover, .history-row.active { background: var(--hover); }
.history-row.active { background: var(--active); }
.history-item {
  min-width: 0;
  height: 43px;
  padding: 4px 3px 4px 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  overflow: hidden;
  border: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
}
.history-item span { width: 100%; overflow: hidden; font-size: 13px; font-weight: 490; white-space: nowrap; text-overflow: ellipsis; }
.history-item small { color: var(--faint); font-size: 10px; }
.history-more {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  opacity: 0;
}
.history-more svg { width: 18px; height: 18px; fill: currentColor; }
.history-row:hover .history-more, .history-row.active .history-more, .history-more:focus-visible, .history-more[aria-expanded="true"] { opacity: 1; }
.history-more:hover, .history-more[aria-expanded="true"] { color: var(--text); background: var(--surface); }

.sidebar-footer { flex: 0 0 auto; padding-top: 8px; border-top: 1px solid var(--line); }
.service-state { min-height: 27px; padding: 0 10px; display: flex; align-items: center; gap: 7px; color: var(--faint); font-size: 11px; }
.service-state i { width: 7px; height: 7px; display: block; border-radius: 50%; background: #9e9e9e; }
.service-state.ok i { background: #15803d; box-shadow: 0 0 0 3px rgba(21, 128, 61, .12); }
.service-state.error i { background: var(--danger); }
.settings-button {
  width: 100%;
  min-height: 54px;
  padding: 7px 8px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  text-align: left;
}
.settings-button:hover { background: var(--hover); }
.settings-avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: #252525; font-size: 13px; font-weight: 700; }
:root[data-resolved-theme="dark"] .settings-avatar { color: #171717; background: #ececec; }
.settings-button > span:nth-child(2) { min-width: 0; display: grid; gap: 2px; }
.settings-button strong { overflow: hidden; font-size: 12px; font-weight: 620; white-space: nowrap; text-overflow: ellipsis; }
.settings-button small { color: var(--faint); font-size: 10px; }
.settings-button svg { width: 19px; height: 19px; fill: none; stroke: var(--faint); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-scrim { display: none; }

.chat-area { min-width: 0; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.chat-header {
  min-height: 60px;
  padding: 8px 18px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  z-index: 10;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.header-left { min-width: 0; display: flex; align-items: center; gap: 5px; }
.menu-button { display: none; }
.chat-title-wrap { min-width: 0; }
.chat-title-wrap h1 { max-width: min(42vw, 520px); margin: 0; overflow: hidden; color: var(--text); font-size: 15px; font-weight: 650; letter-spacing: -.018em; white-space: nowrap; text-overflow: ellipsis; }
.chat-title-wrap p { margin: 2px 0 0; color: var(--faint); font-size: 10px; white-space: nowrap; }
.header-controls { display: flex; align-items: center; gap: 5px; }
.header-action {
  min-height: 34px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 560;
}
.header-action svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.header-action:hover:not(:disabled) { color: var(--text); background: var(--hover); }
.header-action:disabled { opacity: .35; }
.control-label { display: flex; align-items: center; gap: 5px; color: var(--faint); font-size: 11px; }
.control-label select { max-width: 108px; padding: 6px 23px 6px 8px; border: 1px solid transparent; border-radius: 8px; color: var(--text); background: var(--sidebar); font-size: 11px; }
.control-label select:hover { border-color: var(--line); }

.conversation {
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 34px max(22px, calc((100% - 820px) / 2)) 42px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.empty-state {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 0 68px;
  text-align: center;
}
.hero-mark { width: 138px; height: 54px; margin: 0 0 18px; display: grid; place-items: center; }
.hero-mark img { width: 128px; max-height: 48px; object-fit: contain; }
.empty-state h2 { margin: 0; font-size: clamp(25px, 3.1vw, 31px); line-height: 1.18; letter-spacing: -.043em; }
.empty-state > p { max-width: 530px; margin: 13px 0 28px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.suggestion-grid { width: min(100%, 660px); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; }
.suggestion-grid button {
  min-width: 0;
  min-height: 72px;
  padding: 12px 38px 12px 14px;
  display: grid;
  align-content: center;
  gap: 4px;
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: transparent;
  text-align: left;
  transition: border-color .15s ease, background .15s ease;
}
.suggestion-grid button:hover { border-color: var(--line-strong); background: var(--sidebar); }
.suggestion-grid strong { overflow: hidden; font-size: 13px; font-weight: 620; white-space: nowrap; text-overflow: ellipsis; }
.suggestion-grid span { overflow: hidden; color: var(--muted); font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }
.suggestion-grid i { position: absolute; top: 13px; right: 14px; color: var(--faint); font-size: 13px; font-style: normal; }

.message { width: 100%; max-width: 820px; margin: 0 auto 30px; display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 14px; }
.message.user { grid-template-columns: minmax(0, 1fr) 32px; }
.message.user .bubble { grid-column: 1; justify-self: end; max-width: min(80%, 650px); padding: 10px 15px; border-radius: 20px; background: var(--user-bubble); white-space: pre-wrap; }
.message.user .avatar { grid-column: 2; grid-row: 1; color: var(--muted); background: var(--hover); }
.avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: #202020; font-size: 11px; font-weight: 750; }
.wess-avatar { overflow: hidden; border: 1px solid var(--line); background: var(--surface); }
.wess-avatar img { width: 27px; height: 22px; display: block; object-fit: contain; }
.bubble { min-width: 0; max-width: 100%; color: var(--text); font-size: 15px; line-height: 1.72; overflow-wrap: anywhere; }
.message.assistant .bubble { padding-top: 3px; }
.message.error .bubble { color: var(--danger); }
.message p { margin: 0; }
.message-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.message-attachment { max-width: 270px; padding: 5px 9px; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: var(--surface); font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.message-actions { min-height: 30px; margin-top: 9px; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.message-action { min-height: 28px; padding: 3px 8px; border: 0; border-radius: 7px; color: var(--faint); background: transparent; font-size: 10px; }
.message-action:hover { color: var(--text); background: var(--hover); }
.message-action.selected { color: var(--accent); background: var(--accent-soft); font-weight: 680; }
.stream-status { color: var(--muted); animation: status-pulse 1.25s ease-in-out infinite; }
@keyframes status-pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }

.markdown-body { min-width: 0; white-space: normal; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p { margin: 0 0 13px; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 24px 0 10px; color: var(--text); line-height: 1.35; letter-spacing: -.015em; }
.markdown-body h1 { font-size: 20px; }
.markdown-body h2 { font-size: 17px; }
.markdown-body h3 { font-size: 15px; }
.markdown-body strong { font-weight: 720; }
.markdown-body ul, .markdown-body ol { margin: 7px 0 15px; padding-left: 24px; }
.markdown-body li { margin: 5px 0; padding-left: 2px; }
.markdown-body blockquote { margin: 12px 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--line-strong); color: var(--muted); }
.markdown-body hr { margin: 24px 0; border: 0; border-top: 1px solid var(--line); }
.markdown-body a { color: var(--accent); text-underline-offset: 3px; }
.markdown-body code { padding: 2px 5px; border-radius: 5px; color: var(--text); background: var(--hover); font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .87em; }
.code-block { margin: 14px 0 17px; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--code-bg); }
.code-header { min-height: 36px; padding: 0 10px 0 13px; display: flex; align-items: center; justify-content: space-between; color: #b9b9b9; background: rgba(255, 255, 255, .06); font-size: 10px; }
.code-header button { padding: 5px 7px; border: 0; border-radius: 6px; color: #d3d3d3; background: transparent; font-size: 10px; }
.code-header button:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.code-block pre { max-width: 100%; margin: 0; padding: 14px; overflow-x: auto; color: var(--code-text); background: transparent; line-height: 1.55; }
.code-block pre code { padding: 0; color: inherit; background: transparent; font-size: 12px; white-space: pre; }
.table-wrap { max-width: 100%; margin: 14px 0 18px; overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; }
.markdown-body table { width: 100%; border-collapse: collapse; font-size: 12px; }
.markdown-body th, .markdown-body td { padding: 9px 11px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.markdown-body th { background: var(--sidebar); font-weight: 680; }
.markdown-body tr:last-child td { border-bottom: 0; }
.markdown-body th:last-child, .markdown-body td:last-child { border-right: 0; }

.source-gallery { margin-top: 18px; white-space: normal; }
.source-gallery-title { margin: 0 0 9px !important; color: var(--text); font-size: 12px; font-weight: 680; }
.source-gallery-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 9px; }
.source-figure { min-width: 0; margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--sidebar); }
.source-figure a { display: block; background: var(--surface); }
.source-preview { display: block; width: 100%; height: 220px; object-fit: contain; background: var(--surface); }
.source-figure figcaption { padding: 7px 9px 8px; overflow: hidden; color: var(--muted); font-size: 10px; line-height: 1.35; white-space: nowrap; text-overflow: ellipsis; }
.source-box { margin-top: 12px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; white-space: normal; }
.source-box summary { cursor: pointer; color: var(--muted); font-size: 11px; font-weight: 620; }
.source-list { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.source-list li { margin: 7px 0; }

.composer-region { width: 100%; flex: 0 0 auto; padding: 8px max(20px, calc((100% - 820px) / 2)) 14px; background: var(--bg); }
.composer { width: 100%; padding: 10px 11px 8px; border: 1px solid var(--line-strong); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow-sm); transition: border-color .15s ease, box-shadow .15s ease; }
.composer:focus-within { border-color: color-mix(in srgb, var(--line-strong) 72%, var(--text)); box-shadow: 0 3px 12px rgba(0, 0, 0, .08); }
textarea { width: 100%; min-height: 29px; max-height: 190px; padding: 3px 7px; display: block; resize: none; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 15px; line-height: 1.55; }
textarea::placeholder { color: var(--faint); }
textarea:disabled { opacity: .62; }
.composer-bottom { min-height: 32px; display: flex; align-items: center; gap: 7px; padding: 1px; }
.composer-tool { min-height: 30px; padding: 0 9px; display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: transparent; font-size: 10px; font-weight: 620; white-space: nowrap; }
.composer-tool svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.composer-tool:hover:not(:disabled) { color: var(--text); background: var(--hover); }
.composer-tool:disabled { opacity: .45; }
.attachment-preview:empty { display: none; }
.attachment-preview { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 3px 8px; }
.attachment-card { max-width: 190px; height: 50px; display: grid; grid-template-columns: 44px minmax(0, 1fr) 24px; align-items: center; gap: 6px; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--sidebar); }
.attachment-card img { width: 44px; height: 48px; object-fit: cover; background: var(--hover); }
.pdf-attachment-icon { width: 44px; height: 48px; display:grid; place-items:center; color:#fff; background:#c23b32; font-size:11px; font-weight:800; letter-spacing:.4px; }
.attachment-card span { overflow: hidden; color: var(--muted); font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.attachment-card button { width: 22px; height: 28px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; }
.attachment-card button:hover { color: var(--danger); background: var(--hover); }
.composer-product { min-width: 0; padding: 2px 6px 2px 9px; display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: transparent; font-size: 10px; font-weight: 620; }
.composer-product select { max-width: 112px; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 11px; font-weight: 680; cursor: pointer; }
.composer-hint { margin-right: auto; padding: 0 7px; color: var(--faint); font-size: 10px; }
.send-button { width: 32px; height: 32px; flex: 0 0 auto; display: grid; place-items: center; border: 0; border-radius: 50%; color: var(--surface); background: var(--text); transition: opacity .15s ease, transform .15s ease; }
.send-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.send-button:hover:not(:disabled) { transform: scale(1.04); }
.send-button:disabled { color: var(--faint); background: var(--hover); }
.stop-button { min-height: 32px; padding: 0 11px; display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 16px; color: var(--surface); background: var(--text); font-size: 10px; }
.stop-button:hover { opacity: .82; }
.disclaimer { max-width: 780px; margin: 8px auto 0; color: var(--faint); font-size: 10px; line-height: 1.35; text-align: center; }
.privacy-note { max-width: 780px; margin: 3px auto 0; color: color-mix(in srgb, var(--faint) 74%, transparent); font-size: 9px; line-height: 1.35; text-align: center; }
.composer-status { min-height: 0; margin: 5px 7px 0; color: var(--muted); font-size: 10px; line-height: 1.3; }
.composer-status:empty { display: none; }
.composer-status.error { color: var(--danger); }
.composer-status.success { color: var(--accent); }

.popup-menu {
  width: 210px;
  padding: 6px;
  position: fixed;
  z-index: 80;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--elevated);
  box-shadow: var(--shadow-md);
}
.popup-menu button { width: 100%; min-height: 38px; padding: 0 9px; display: flex; align-items: center; gap: 8px; border: 0; border-radius: 7px; color: var(--text); background: transparent; text-align: left; font-size: 12px; }
.popup-menu button:hover, .popup-menu button:focus-visible { background: var(--hover); }
.popup-menu button kbd, .popup-menu button small { margin-left: auto; color: var(--faint); font-family: inherit; font-size: 9px; }
.popup-menu button.danger { color: var(--danger); }

.modal { width: min(92vw, 520px); max-height: min(86dvh, 700px); padding: 0; overflow: visible; border: 1px solid var(--line); border-radius: 14px; color: var(--text); background: var(--elevated); box-shadow: var(--shadow-md); }
.modal.compact { width: min(92vw, 430px); }
.modal::backdrop { background: rgba(0, 0, 0, .44); backdrop-filter: blur(2px); }
.modal-card { max-height: min(86dvh, 700px); margin: 0; padding: 0; overflow-y: auto; color: inherit; background: inherit; border-radius: inherit; }
.modal-card header { padding: 20px 20px 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.modal-card h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.modal-card header p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.settings-section { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.settings-row, .settings-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.settings-row > span, .settings-heading > span { min-width: 0; display: grid; gap: 4px; }
.settings-row strong, .settings-heading strong { font-size: 12px; font-weight: 650; }
.settings-row small, .settings-heading small { color: var(--muted); font-size: 10px; line-height: 1.4; }
.settings-row select { min-width: 105px; padding: 7px 8px; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--text); background: var(--surface); font-size: 11px; }
.settings-actions { margin-top: 13px; display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.settings-actions button { min-height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: transparent; font-size: 11px; text-align: left; }
.settings-actions button:hover { background: var(--hover); }
.settings-actions button small { float: right; color: var(--faint); }
.settings-actions button.danger { grid-column: 1 / -1; color: var(--danger); }
.modal-note { margin: 0; padding: 13px 20px; color: var(--faint); background: var(--sidebar); font-size: 10px; line-height: 1.5; }
.modal-card footer { padding: 13px 20px; display: flex; justify-content: flex-end; gap: 7px; border-top: 1px solid var(--line); }
.modal-card footer button { min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: transparent; font-size: 11px; font-weight: 600; }
.modal-card footer button:hover { background: var(--hover); }
.modal-card footer button.primary { color: var(--surface); border-color: var(--text); background: var(--text); }
.modal-card footer button.danger { color: #fff; border-color: #b42318; background: #b42318; }
.rename-field { padding: 18px 20px; display: grid; gap: 7px; color: var(--muted); font-size: 10px; }
.rename-field input { width: 100%; padding: 10px 11px; border: 1px solid var(--line-strong); border-radius: 9px; outline: 0; color: var(--text); background: var(--surface); font-size: 13px; }
.rename-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }

.toast { max-width: min(90vw, 420px); padding: 10px 14px; position: fixed; left: 50%; bottom: 108px; z-index: 100; transform: translate(-50%, 12px); border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--elevated); box-shadow: var(--shadow-md); font-size: 11px; opacity: 0; transition: opacity .18s ease, transform .18s ease; }
.toast.visible { transform: translate(-50%, 0); opacity: 1; }
.toast.success { color: var(--accent); }
.toast.error { color: var(--danger); }

.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; }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar {
    width: min(86vw, 316px);
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 15px 0 34px rgba(0, 0, 0, .16);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-close, .menu-button { display: inline-grid; }
  .new-chat kbd, .history-search-wrap kbd { display: none; }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .42); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .sidebar-scrim.visible { display: block; opacity: 1; pointer-events: auto; }
  .chat-header { min-height: 56px; padding: 7px 10px; }
  .chat-title-wrap h1 { max-width: 42vw; }
  .header-action { width: 34px; padding: 0; justify-content: center; }
  .header-action span { display: none; }
  .control-label > span { display: none; }
  .control-label select { max-width: 92px; }
  .conversation { padding: 25px 15px 28px; }
  .empty-state { padding: 26px 0 42px; justify-content: center; }
  .hero-mark { width: 112px; margin-bottom: 12px; }
  .hero-mark img { width: 106px; }
  .empty-state h2 { font-size: 25px; }
  .empty-state > p { margin: 11px 8px 22px; font-size: 12px; }
  .suggestion-grid { width: 100%; grid-template-columns: 1fr; gap: 7px; }
  .suggestion-grid button { min-height: 62px; padding-top: 10px; padding-bottom: 10px; }
  .message { grid-template-columns: 28px minmax(0, 1fr); gap: 9px; margin-bottom: 25px; }
  .message.user { grid-template-columns: minmax(0, 1fr) 28px; }
  .message.user .bubble { max-width: 88%; }
  .avatar { width: 28px; height: 28px; font-size: 10px; }
  .wess-avatar img { width: 24px; }
  .bubble { font-size: 14px; line-height: 1.68; }
  .markdown-body h1 { font-size: 18px; }
  .markdown-body h2 { font-size: 16px; }
  .source-preview { height: 190px; }
  .composer-region { padding: 7px 11px calc(9px + env(safe-area-inset-bottom)); }
  .composer { border-radius: 22px; }
  .composer-hint { display: none; }
  .composer-tool span { display: none; }
  .composer-tool { width: 31px; padding: 0; justify-content: center; }
  .composer-product { margin-right: auto; }
  .privacy-note { display: none; }
  .disclaimer { font-size: 9px; }
  .toast { bottom: calc(95px + env(safe-area-inset-bottom)); }
}

@media (max-width: 430px) {
  .chat-title-wrap p { display: none; }
  .chat-title-wrap h1 { max-width: 38vw; font-size: 13px; }
  .header-controls { gap: 0; }
  .control-label select { max-width: 84px; padding-left: 5px; padding-right: 17px; }
  .conversation { padding-left: 11px; padding-right: 11px; }
  .empty-state h2 { font-size: 23px; }
  .composer-bottom { gap: 5px; }
  .composer-product { padding-left: 6px; gap: 3px; }
  .composer-product > span { display: none; }
  .composer-product select { max-width: 98px; }
  .settings-actions { grid-template-columns: 1fr; }
  .settings-actions button.danger { grid-column: auto; }
}

@media (max-height: 620px) and (min-width: 761px) {
  .empty-state { justify-content: flex-start; padding-top: 30px; }
  .hero-mark { margin-bottom: 8px; }
  .empty-state > p { margin-bottom: 18px; }
}

.history-mode {
  margin: 0 2px 7px;
  padding: 3px;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 65%, transparent);
}
.history-mode button {
  min-height: 30px;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 650;
}
.history-mode button:hover { color: var(--text); background: var(--hover); }
.history-mode button[aria-selected="true"] { color: var(--text); background: var(--surface); box-shadow: var(--shadow-sm); }

.evidence-warning {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, #c98200 35%, var(--line));
  border-radius: 10px;
  color: color-mix(in srgb, #9b6200 75%, var(--text));
  background: color-mix(in srgb, #fff3cd 60%, var(--surface));
  font-size: 12px;
  line-height: 1.55;
}
:root[data-resolved-theme="dark"] .evidence-warning { color: #f4cf77; background: #3c321d; }
.source-preview-button {
  padding: 2px 0;
  border: 0;
  color: var(--accent);
  background: transparent;
  text-align: left;
  line-height: 1.55;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.variant-navigation {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}
.variant-navigation .message-action { min-width: 30px; padding: 3px 8px; font-size: 18px; line-height: 1; }

.form-grid { max-height: min(760px, calc(100dvh - 32px)); overflow: auto; }
.form-grid > label,
.rename-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.form-grid input,
.form-grid select,
.form-grid textarea,
.rename-field input {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  outline: 0;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  font-size: 14px;
  font-weight: 450;
}
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus,
.rename-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.consent-row { grid-template-columns: auto 1fr !important; align-items: start; line-height: 1.5; }
.consent-row input { width: 18px; height: 18px; margin: 1px 0 0; }

.bulk-list {
  min-height: 120px;
  max-height: min(440px, 55dvh);
  overflow: auto;
  display: grid;
  gap: 4px;
}
.bulk-row {
  padding: 9px 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border-radius: 9px;
}
.bulk-row:hover { background: var(--hover); }
.bulk-row input { width: 17px; height: 17px; }
.bulk-row span { min-width: 0; display: grid; gap: 2px; }
.bulk-row strong, .bulk-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulk-row strong { font-size: 13px; }
.bulk-row small { color: var(--muted); font-size: 11px; }
.bulk-actions { flex-wrap: wrap; }

.source-preview-modal .modal-card { width: min(760px, calc(100vw - 28px)); }
.source-preview-modal img {
  width: 100%;
  max-height: 65dvh;
  display: block;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.source-preview-modal footer a { margin-right: auto; color: var(--accent); font-size: 13px; }

@media (max-width: 760px) {
  .history-mode { grid-template-columns: 1fr 1fr auto; }
  .form-grid { max-height: calc(100dvh - 20px); }
  .bulk-actions button { flex: 1 1 110px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
