:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1220;
  --panel: #171d31;
  --line: #2a3154;
  --line-soft: rgba(42, 49, 84, 0.65);
  --text: #e8ecff;
  --muted: #9fb2ff;
  --accent: #4a8bff;
  --danger: #ff7f9f;
  --danger-border: #5a3040;
  --user: #22345f;
  --assistant: #1a243f;
  --system: #3a2040;
  --system-fg: #ffc7d4;
  --chrome: #12182b;
  --input-bg: #11162a;
  --control-bg: #1a1f36;
  --menu-bg: #171d31;
  --hover-bg: #222a46;
  --active-bg: #243058;
  --elevated: #1a2238;
  --code-bg: #0c1020;
  --footer-fg: #7d8ec8;
  --link: #8fb4ff;
  --link-soft: #8ab4ff;
  --select-action-bg: #2a3960;
  --ok: #7dffb0;
  --stream-fg: #bff7d7;
  --ref-tag-fg: #b8ccff;
  --ref-head-fg: #9dffc4;
  --graph-fg: #6b7db8;
  --shadow: rgba(0, 0, 0, 0.45);
  --overlay: rgba(0, 0, 0, 0.45);
  --loading-overlay: rgba(11, 14, 26, 0.55);
  --select-bar-bg: rgba(23, 29, 49, 0.96);
  --toast-bg: rgba(26, 34, 56, 0.95);
  --speak-btn-bg: rgba(18, 24, 43, 0.92);
  --chip-bg: rgba(255, 255, 255, 0.02);
  --code-inline-bg: rgba(255, 255, 255, 0.06);
  --th-bg: rgba(255, 255, 255, 0.05);
  --img-bg: rgba(255, 255, 255, 0.04);
  --hover-soft: rgba(255, 255, 255, 0.04);
  --btn-on-accent: #fff;
  --badge-live: #6ee7a8;
  --badge-new: #7dd3fc;
  --diff-del: #ff9fb8;
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%239fb2ff' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1.5 1.5L6 6l4.5-4.5'/%3E%3C/svg%3E");
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f4f8;
  --panel: #ffffff;
  --line: #d5dbe8;
  --line-soft: rgba(90, 106, 138, 0.28);
  --text: #1a2336;
  --muted: #5a6a8a;
  --accent: #2f6fed;
  --danger: #d63d6a;
  --danger-border: #f0b4c4;
  --user: #d9e6ff;
  --assistant: #ffffff;
  --system: #fde8ee;
  --system-fg: #9b2d4a;
  --chrome: #ffffff;
  --input-bg: #ffffff;
  --control-bg: #eef1f7;
  --menu-bg: #ffffff;
  --hover-bg: #e8ecf5;
  --active-bg: #dce6f8;
  --elevated: #ffffff;
  --code-bg: #eef1f6;
  --footer-fg: #7a879e;
  --link: #2a5fd4;
  --link-soft: #2f6fed;
  --select-action-bg: #d6e4ff;
  --ok: #1f9d5c;
  --stream-fg: #1a7a4c;
  --ref-tag-fg: #2a5fd4;
  --ref-head-fg: #1a7a4c;
  --graph-fg: #7a879e;
  --shadow: rgba(26, 35, 54, 0.16);
  --overlay: rgba(26, 35, 54, 0.35);
  --loading-overlay: rgba(242, 244, 248, 0.72);
  --select-bar-bg: rgba(255, 255, 255, 0.96);
  --toast-bg: rgba(255, 255, 255, 0.96);
  --speak-btn-bg: rgba(255, 255, 255, 0.94);
  --chip-bg: rgba(26, 35, 54, 0.03);
  --code-inline-bg: rgba(26, 35, 54, 0.06);
  --th-bg: rgba(26, 35, 54, 0.04);
  --img-bg: rgba(26, 35, 54, 0.04);
  --hover-soft: rgba(26, 35, 54, 0.04);
  --btn-on-accent: #fff;
  --badge-live: #1a7a4c;
  --badge-new: #2a5fd4;
  --diff-del: #c23a5a;
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%235a6a8a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1.5 1.5L6 6l4.5-4.5'/%3E%3C/svg%3E");
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-weight: 300;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* small = current UI; medium/large scale the whole app (px-based stylesheet) */
html[data-font-size="medium"] {
  zoom: 1.125;
}

html[data-font-size="large"] {
  zoom: 1.28;
}

body {
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.app {
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--chrome);
}

.topbar-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: block;
}

.topbar-title {
  flex: 1;
  min-width: 0;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--chrome);
  font-size: 11px;
  color: var(--footer-fg);
  letter-spacing: 0.02em;
}

.app.in-chat .app-footer {
  display: none;
}

.app.in-chat .main {
  overflow: hidden;
}

.app-footer-logo {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  display: block;
}

.app-footer-sep {
  opacity: 0.6;
}

.title {
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--btn-on-accent);
  padding: 10px 14px;
  font-size: 15px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--control-bg);
  color: var(--text);
  font-size: 15px;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

button.danger {
  color: var(--danger);
  border-color: var(--danger-border);
  background: var(--control-bg);
}

button:disabled {
  opacity: 0.5;
}

.main {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.panel {
  padding: 16px;
}

.auth-panel {
  max-width: 420px;
  margin: 0 auto;
}

.install-hint {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.install-hint-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.install-hint-steps {
  margin: 10px 0 0;
  padding-left: 1.25rem;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.install-hint-steps li + li {
  margin-top: 6px;
}

.install-hint-steps kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  font: inherit;
  font-size: 12px;
}

/* Список / настройки / чат — не растягивать поля на весь широкий экран */
.list-panel,
.settings-panel {
  max-width: 640px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.chat-panel .messages,
.chat-panel .composer {
  max-width: 880px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
  font-size: 13px;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--text);
  padding: 12px;
  font: inherit;
}

textarea {
  resize: vertical;
  min-height: 44px;
  max-height: 160px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.muted.small {
  font-size: 13px;
  margin-bottom: 12px;
}

.error {
  color: var(--danger);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.library-section {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.library-title {
  margin: 0 0 6px;
  font-size: 16px;
}

.library-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.library-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--chip-bg);
}

.library-name {
  font-size: 14px;
  word-break: break-word;
}

.primary-block {
  width: 100%;
  margin-top: 8px;
}

.project-card {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.chat-list-item {
  position: relative;
  display: flex;
  align-items: stretch;
  padding: 0;
  overflow: visible;
}

.chat-list-main {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 14px;
  padding: 14px;
  color: inherit;
}

.chat-list-menu-btn {
  flex-shrink: 0;
  align-self: flex-start;
  margin: 8px 8px 0 0;
  width: 36px;
  height: 36px;
  font-size: 18px;
  line-height: 1;
}

.chat-list-menu {
  position: absolute;
  top: 44px;
  right: 8px;
  z-index: 12;
  min-width: 190px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--menu-bg);
  box-shadow: 0 8px 24px var(--overlay);
  padding: 4px;
}

.chat-list-menu-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 14px;
}

.chat-list-menu-item.danger {
  color: var(--danger);
}

.chat-list-menu-item:hover {
  background: var(--hover-bg);
}

.project-card h3,
.chat-list-main h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.project-card p,
.chat-list-main p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.project-card .meta,
.chat-list-main .meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--footer-fg);
}

.streaming-badge {
  color: var(--badge-live);
  font-weight: 600;
}

.new-badge {
  color: var(--badge-new);
  font-weight: 600;
}

.project-card.missing {
  opacity: 0.55;
}

.project-card.other-hub-card {
  border-color: rgba(127, 212, 255, 0.35);
  background: linear-gradient(135deg, rgba(74, 139, 255, 0.12), rgba(127, 212, 255, 0.08));
}

.project-card.other-session-card h3,
.chat-list-item.other-session-card h3 {
  font-size: 16px;
}

.other-help {
  margin: 10px 0 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--chip-bg);
  overflow: hidden;
}

.other-help summary {
  cursor: pointer;
  list-style: none;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

.other-help summary::-webkit-details-marker {
  display: none;
}

.other-help summary::after {
  content: "▾";
  float: right;
  color: var(--muted);
  font-weight: 400;
  transition: transform 0.15s ease;
}

.other-help[open] summary::after {
  transform: rotate(-180deg);
}

.other-help-body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--line-soft);
}

.other-help-body p {
  margin: 12px 0 8px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.other-help-body ul {
  margin: 0;
  padding-left: 1.15em;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.other-help-body li {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
}

.other-help-body li strong {
  font-weight: 600;
  color: var(--link-soft);
}

.other-sessions-list {
  margin-top: 12px;
}

.other-empty {
  padding: 12px 4px;
}

.primary-block {
  width: 100%;
  margin: 12px 0 4px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(74, 139, 255, 0.35);
  background: rgba(74, 139, 255, 0.14);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

#attachFileBtn {
  min-width: 38px;
  padding-inline: 10px;
}

.projects-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.projects-list.is-loading {
  opacity: 0.45;
  pointer-events: none;
}

.chat-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  min-height: 0;
}

.scroll-to-bottom {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 6;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--elevated);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  box-shadow: 0 8px 24px var(--shadow);
}

.scroll-to-bottom.hidden {
  display: none;
}

.chat-panel .scroll-to-bottom {
  bottom: calc(var(--composer-offset, 72px) + 8px);
  right: max(16px, calc((100% - min(100%, 880px)) / 2 + 16px));
}

.messages.is-loading {
  pointer-events: none;
}

.messages-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--loading-overlay);
  z-index: 2;
}

.main-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: min(320px, 50vh);
  padding: 24px;
  color: var(--muted);
  font-size: 15px;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

button.is-loading {
  opacity: 0.65;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes stream-loader-sweep {
  to {
    transform: translateX(100%);
  }
}

@keyframes stream-loader-pulse {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(0.85);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes stream-loader-dot {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.msg {
  position: relative;
  max-width: 92%;
  min-width: 0;
  padding: 10px 36px 10px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  font-weight: 300;
  line-height: 1.45;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.msg.msg-selected {
  box-shadow: 0 0 0 2px rgba(74, 139, 255, 0.85), 0 0 0 6px rgba(74, 139, 255, 0.18);
}

.msg-main {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.msg-body-content {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.msg-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  display: flex;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.msg:hover .msg-actions,
.msg:focus-within .msg-actions,
.msg.msg-selected .msg-actions {
  opacity: 1;
  pointer-events: auto;
}

@media (hover: none) {
  .msg-actions {
    opacity: 0.9;
    pointer-events: auto;
  }
}

.msg-speak-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--speak-btn-bg);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
}

.msg-speak-btn:disabled {
  opacity: 0.4;
}

.msg-select-bar {
  position: absolute;
  left: 50%;
  bottom: calc(var(--composer-offset, 72px) + 14px + env(safe-area-inset-bottom));
  z-index: 9;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 24px);
  transform: translateX(-50%);
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--select-bar-bg);
  box-shadow: 0 10px 28px var(--shadow);
}

.msg-select-copy {
  padding: 8px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--select-action-bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.msg-select-close {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}

.msg-toast {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 8;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--toast-bg);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.msg-toast.visible {
  opacity: 1;
}

.msg.user {
  align-self: flex-end;
  background: var(--user);
}

.msg.assistant {
  align-self: flex-start;
  background: var(--assistant);
  border: 1px solid var(--line);
}

.msg.assistant[data-streaming="1"] {
  border-color: rgba(110, 231, 168, 0.42);
  box-shadow: 0 0 0 1px rgba(110, 231, 168, 0.08), 0 12px 32px rgba(74, 139, 255, 0.1);
}

.msg-stream-loader {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -2px -2px 10px;
  padding: 8px 10px;
  overflow: hidden;
  border: 1px solid rgba(110, 231, 168, 0.18);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(110, 231, 168, 0.11), rgba(74, 139, 255, 0.08));
  color: var(--stream-fg);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.msg-stream-loader-live {
  margin-bottom: 6px;
  padding: 4px 8px;
  font-size: 11px;
  opacity: 0.85;
}

.msg-body-content.is-streaming::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  color: var(--stream-fg);
  animation: stream-loader-pulse 1s ease-in-out infinite;
}

.msg-stream-loader::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #6ee7a8, #7fd4ff, transparent);
  transform: translateX(-100%);
  animation: stream-loader-sweep 1.45s ease-in-out infinite;
}

.msg-stream-loader-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6ee7a8;
  box-shadow: 0 0 12px rgba(110, 231, 168, 0.9);
  animation: stream-loader-pulse 1.1s ease-in-out infinite;
}

.msg-stream-loader-text {
  font-weight: 600;
}

.msg-stream-loader-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: auto;
}

.msg-stream-loader-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: stream-loader-dot 1.2s ease-in-out infinite;
}

.msg-stream-loader-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.msg-stream-loader-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

.msg-model-label {
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
  margin: -2px 0 8px;
  opacity: 0.9;
}

.msg.system {
  align-self: center;
  background: var(--system);
  color: var(--system-fg);
  font-size: 13px;
}

.msg-streaming-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
}

.settings-panel fieldset,
.settings-group {
  border: 1px solid var(--line);
  border-radius: 14px;
  margin: 14px 0 0;
  padding: 6px 14px 14px;
  background: var(--chip-bg);
}

.settings-panel legend {
  padding: 0 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.settings-lead {
  margin: 0 0 4px;
}

/* Сброс глобального label { column } внутри настроек */
.settings-panel label {
  margin: 0;
  gap: 0;
  font-size: inherit;
  color: inherit;
}

.settings-check {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  font-size: 15px;
  line-height: 1.35;
  color: var(--text);
  cursor: pointer;
}

.settings-check + .settings-check,
.settings-check + .settings-field,
.settings-field + .settings-field {
  border-top: 1px solid var(--line-soft);
  margin-top: 0;
  padding-top: 12px;
}

.settings-check-text {
  flex: 1;
  min-width: 0;
}

.settings-check input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-width: 20px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  padding-top: 0;
}

.settings-label {
  font-size: 13px;
  color: var(--muted);
}

.settings-label code {
  margin-left: 4px;
  font-size: 11px;
  color: var(--link-soft);
}

.settings-panel input[type="text"],
.settings-panel input[type="password"],
.settings-panel input[type="email"],
.settings-panel select {
  width: 100%;
  box-sizing: border-box;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  font-size: 15px;
}

.settings-panel select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 40px;
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
  cursor: pointer;
}

.settings-panel select:focus,
.settings-panel input:focus {
  outline: none;
  border-color: rgba(74, 139, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(74, 139, 255, 0.15);
}

.settings-hint {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.settings-proxy-fields {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line-soft);
}

.settings-proxy-fields.hidden {
  display: none;
}

.settings-env-fields {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-env-fields .settings-field {
  margin-top: 10px;
}

.settings-restart-hint {
  margin-top: 2px;
}

.settings-actions {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-status {
  min-height: 1.2em;
  font-size: 13px;
}

.settings-status.ok {
  color: var(--ok);
}

.settings-status.error {
  color: var(--danger);
}

.msg .md-body {
  white-space: normal;
}

.msg .md-body > :first-child {
  margin-top: 0;
}

.msg .md-body > :last-child {
  margin-bottom: 0;
}

.msg .md-body p {
  margin: 0.45em 0;
}

.msg .md-body h1,
.msg .md-body h2,
.msg .md-body h3,
.msg .md-body h4 {
  margin: 0.75em 0 0.35em;
  line-height: 1.25;
  font-size: 1em;
  font-weight: 700;
}

.msg .md-body h1 {
  font-size: 1.15em;
}

.msg .md-body h2 {
  font-size: 1.08em;
}

.msg .md-body ul,
.msg .md-body ol {
  margin: 0.4em 0;
  padding-left: 1.25em;
}

.msg .md-body li {
  margin: 0.15em 0;
}

.msg .md-body blockquote {
  margin: 0.5em 0;
  padding: 0 0 0 10px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.msg .md-body a {
  color: var(--link);
  word-break: break-word;
}

.msg img,
.msg .md-body img,
.msg .msg-upload-img {
  display: block;
  max-width: min(240px, 100%);
  max-height: 200px;
  width: auto !important;
  height: auto !important;
  object-fit: contain;
  margin: 8px 0;
  border-radius: 8px;
  background: var(--img-bg);
}

.msg img[data-upload-path]:not([data-hydrated]) {
  width: 240px;
  height: 160px;
  max-width: min(240px, 100%);
  max-height: 200px;
}

.msg .md-body pre {
  margin: 8px 0;
  padding: 10px 12px;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.4;
  white-space: pre;
  word-break: normal;
}

.msg .md-body pre code {
  white-space: inherit;
  word-break: normal;
  overflow-wrap: normal;
}

.msg .md-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

.msg .md-body :not(pre) > code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--code-inline-bg);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg .md-body table {
  width: 100%;
  margin: 8px 0;
  border-collapse: collapse;
  font-size: 13px;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.msg .md-body thead,
.msg .md-body tbody,
.msg .md-body tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

.msg .md-body th,
.msg .md-body td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.msg .md-body th {
  background: var(--th-bg);
  font-weight: 600;
}

.msg .md-body hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 10px 0;
}

.composer {
  flex-shrink: 0;
  border-top: 0;
  padding: 4px 10px calc(6px + env(safe-area-inset-bottom));
  background: transparent;
  max-height: min(45vh, 320px);
  overflow: visible;
  z-index: 8;
}

.composer-shell {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--chrome);
  padding: 8px 10px 10px;
  box-shadow: 0 8px 28px var(--shadow);
}

.agent-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.picker-wrap {
  position: relative;
  z-index: 9;
}

.picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--control-bg);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  line-height: 1.2;
}

.picker-icon {
  color: var(--muted);
  font-size: 14px;
}

.picker-chevron {
  color: var(--muted);
  font-size: 11px;
}

.picker-menu {
  position: fixed;
  z-index: 80;
  box-sizing: border-box;
  width: min(300px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: min(420px, 55vh);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--menu-bg);
  box-shadow: 0 8px 28px var(--overlay);
  padding: 6px;
}

.picker-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 14px;
}

.picker-item.has-hint {
  align-items: flex-start;
  padding-top: 9px;
  padding-bottom: 9px;
}

.picker-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border-radius: 8px;
}

.picker-row.active {
  background: var(--active-bg);
}

.picker-row.has-hint .picker-item-main {
  padding-top: 9px;
  padding-bottom: 9px;
}

.picker-item-main {
  flex: 1;
  min-width: 0;
}

.picker-item .item-copy {
  flex: 1;
  min-width: 0;
}

.picker-item.has-hint .item-check {
  margin-top: 2px;
}

.picker-item-main:hover:not(:disabled) {
  background: var(--hover-bg);
}

.picker-item:hover:not(:disabled) {
  background: var(--hover-bg);
}

.picker-item.active {
  background: var(--active-bg);
}

.picker-item:disabled {
  opacity: 0.45;
}

.picker-item .item-icon {
  width: 18px;
  color: var(--muted);
  text-align: center;
}

.picker-item .item-label {
  flex: 1;
  display: block;
  font-weight: 600;
}

.picker-item .item-check {
  color: var(--accent);
  font-size: 12px;
  flex-shrink: 0;
}

.picker-item .item-hint {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
  font-weight: 400;
  white-space: normal;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.composer-row #messageInput {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 140px;
  resize: none;
  border: 0;
  background: transparent;
  padding: 8px 4px;
  border-radius: 0;
  line-height: 1.35;
}

.composer-row #messageInput:focus {
  outline: none;
}

.composer-row .icon-only {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  font-size: 17px;
  border-radius: 50%;
  flex-shrink: 0;
}

.composer-row #sendBtn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

.composer .attachment-preview {
  margin: 0 0 8px;
}

.git-drawer-backdrop,
.side-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 40;
}

.git-drawer-backdrop.hidden,
.side-drawer-backdrop.hidden {
  display: none;
}

.git-drawer,
.side-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--chrome);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px var(--shadow);
}

#questionsDrawer {
  right: auto;
  left: 0;
  border-left: 0;
  border-right: 1px solid var(--line);
  box-shadow: 8px 0 24px var(--shadow);
}

.git-drawer.hidden,
.side-drawer.hidden {
  display: none;
}

.git-drawer-header,
.side-drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: calc(12px + env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid var(--line);
}

.git-drawer-title,
.side-drawer-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.git-drawer-subtitle,
.side-drawer-subtitle {
  margin: 4px 0 0;
}

.git-drawer-toolbar,
.side-drawer-toolbar {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.ghost-icon {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 18px;
}

.git-tabs,
.side-drawer-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.git-tab,
.side-drawer-tab {
  flex: 1;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 8px 6px;
  font-size: 13px;
}

.git-tab.active,
.side-drawer-tab.active {
  background: var(--panel);
  color: var(--text);
  border-color: var(--accent);
}

.git-drawer-body,
.side-drawer-body {
  flex: 1;
  overflow: auto;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  min-height: 0;
}

#gitDrawer .side-drawer-body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

.git-changes-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  gap: 0;
}

.git-changes-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-bottom: 8px;
}

.git-diff-panel {
  flex-shrink: 0;
  height: min(42vh, 280px);
  border-top: 1px solid var(--line);
  background: var(--code-bg);
  display: flex;
  flex-direction: column;
  min-height: 120px;
}

.git-diff-panel-empty {
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.git-diff-header {
  flex-shrink: 0;
  padding: 8px 10px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.git-diff-body {
  flex: 1;
  overflow: auto;
  padding: 6px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.45;
}

.git-diff-line {
  padding: 0 10px;
  white-space: pre-wrap;
  word-break: break-all;
}

.git-diff-line.meta {
  color: var(--muted);
}

.git-diff-line.hunk {
  color: var(--link-soft);
}

.git-diff-line.add {
  color: var(--ok);
  background: rgba(76, 175, 125, 0.08);
}

.git-diff-line.del {
  color: var(--diff-del);
  background: rgba(248, 113, 113, 0.08);
}

.git-file-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 8px 6px;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
}

.git-file-item.selected {
  background: rgba(74, 139, 255, 0.15);
  outline: 1px solid rgba(74, 139, 255, 0.35);
}

.git-file-item:hover {
  background: var(--img-bg);
}

.git-file-item.selected:hover {
  background: rgba(74, 139, 255, 0.18);
}
.git-loading,
.git-empty,
.git-error {
  padding: 16px 8px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.git-error {
  color: var(--danger);
}

.git-section-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.git-file-list,
.git-branch-list,
.git-commit-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.git-status-badge {
  flex-shrink: 0;
  min-width: 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(74, 139, 255, 0.12);
}

.git-status-badge.untracked {
  color: var(--badge-new);
}

.git-status-badge.added {
  color: var(--ok);
}

.git-status-badge.deleted {
  color: var(--danger);
}

.git-file-path {
  word-break: break-all;
}

.git-branch-item,
.git-commit-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.35;
}

.git-branch-item:hover,
.git-commit-item:hover {
  background: var(--img-bg);
}

.git-branch-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

.git-branch-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.git-commit-item {
  align-items: stretch;
}

.git-commit-graph {
  flex-shrink: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--graph-fg);
  white-space: pre;
  min-width: 2ch;
}

.git-commit-main {
  min-width: 0;
  flex: 1;
}

.git-commit-subject {
  font-size: 13px;
  word-break: break-word;
}

.git-commit-meta {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}

.git-commit-refs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.git-ref-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(74, 139, 255, 0.18);
  color: var(--ref-tag-fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.git-ref-tag.head {
  background: rgba(125, 255, 176, 0.15);
  color: var(--ref-head-fg);
}

.questions-search-wrap {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.questions-search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
}

.questions-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.question-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 12px 8px;
  border-radius: 0;
  font-size: 14px;
  line-height: 1.4;
}

.question-item:hover {
  background: var(--img-bg);
}

.question-item-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.question-item-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.msg-highlight {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 10px;
  animation: msg-flash 2s ease-out;
}

@keyframes msg-flash {
  0% {
    background: rgba(74, 139, 255, 0.25);
  }
  100% {
    background: transparent;
  }
}

.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.attachment-preview.hidden {
  display: none;
}

.attachment-chip {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--code-bg);
}

.attachment-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attachment-chip-file {
  width: auto;
  min-width: 120px;
  max-width: 180px;
  height: auto;
  min-height: 72px;
  padding: 10px 28px 10px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.attachment-file-icon {
  font-size: 22px;
  line-height: 1;
}

.attachment-file-name {
  font-size: 11px;
  line-height: 1.25;
  word-break: break-all;
  color: var(--muted);
}

.attachment-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  min-width: 0;
  padding: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 14px;
  line-height: 1;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 8px;
  width: min(320px, 92vw);
}

dialog::backdrop {
  background: var(--overlay);
}

dialog button {
  width: 100%;
  margin: 4px 0;
  background: var(--control-bg);
  border: 1px solid var(--line);
  color: var(--text);
}

dialog button.danger {
  color: var(--danger);
  border-color: var(--danger-border);
}

.typing {
  color: var(--muted);
  font-size: 13px;
  padding: 0 4px;
}

.app-version {
  margin: 16px 0 0;
  font-size: 11px;
  color: var(--footer-fg);
  text-align: center;
  letter-spacing: 0.02em;
}

.menu-version {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
