:root {
  --bg: #0d0e10;
  --bg-elevated: #17191c;
  --bg-hover: #212429;
  --surface: #131518;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);
  --text: #ececf1;
  --text-dim: #8b8f98;
  --text-muted: #6b6f78;
  --accent: #ff7a1a;
  --accent-hover: #ff9442;
  --accent-soft: rgba(255,122,26,0.14);
  --accent-glow: rgba(255,122,26,0.35);
  --user-bubble: #1d2024;
  --assistant-bubble: transparent;
  --danger: #ff5a5a;
  --radius: 12px;
  --radius-lg: 16px;
  --sidebar-w: 264px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 8px 28px rgba(0,0,0,0.45);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.55);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: var(--accent-hover); }

button {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), transform .08s var(--ease);
}
button:hover { background: var(--bg-hover); border-color: var(--border-strong); }
button:active { transform: scale(0.97); }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff; border-color: transparent;
  box-shadow: 0 2px 12px var(--accent-glow);
}
button.primary:hover { filter: brightness(1.06); box-shadow: 0 4px 18px var(--accent-glow); }
button.danger { color: var(--danger); }
button.danger:hover { background: rgba(255,90,90,0.12); border-color: rgba(255,90,90,0.4); }
button.icon { padding: 6px 8px; }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

input, textarea, select {
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; font: inherit; outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---- Scrollbars ---- */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.14) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); background-clip: padding-box; }

/* ---- Login ---- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; position: relative; overflow: hidden;
  background: var(--bg);
}
.login-body::before {
  content: ''; position: absolute; inset: -20%;
  background: radial-gradient(circle at 50% 32%, var(--accent-glow), transparent 42%);
  filter: blur(40px); opacity: 0.55; pointer-events: none;
  animation: loginGlow 8s ease-in-out infinite alternate;
}
@keyframes loginGlow {
  from { transform: translateY(-10px) scale(1); opacity: 0.45; }
  to   { transform: translateY(10px) scale(1.08); opacity: 0.65; }
}
.login-card {
  position: relative; z-index: 1;
  width: 372px; padding: 38px 32px;
  background: linear-gradient(180deg, rgba(28,30,34,0.92), rgba(19,21,24,0.92));
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-strong); border-radius: 20px;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.05);
  animation: cardIn .5s var(--ease);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.login-logo {
  text-align: center; margin-bottom: 16px;
}
.login-logo img {
  width: 88px; height: 88px; object-fit: contain;
  filter: drop-shadow(0 6px 20px var(--accent-glow));
}
.login-card h1 { margin: 0 0 6px; font-size: 23px; font-weight: 700; text-align: center; letter-spacing: -0.3px; }
.login-sub { color: var(--text-dim); text-align: center; margin: 0 0 24px; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card input { padding: 12px 14px; font-size: 15px; border-radius: 10px; }
.login-card button {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white; border: none; padding: 12px;
  border-radius: 10px; font-size: 15px; font-weight: 600;
  box-shadow: 0 4px 16px var(--accent-glow);
  transition: filter .15s var(--ease), transform .08s var(--ease);
}
.login-card button:hover { filter: brightness(1.07); }
.login-card button:active { transform: scale(0.98); }
.login-error { color: var(--danger); margin-top: 14px; font-size: 13px; min-height: 18px; text-align: center; }

/* ---- App layout ---- */
.app {
  display: flex; height: 100vh; width: 100vw;
}
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-header {
  padding: 14px 14px 12px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.brand {
  flex: 1; font-weight: 700; font-size: 15px; color: var(--text);
  display: flex; align-items: center; gap: 9px; letter-spacing: -0.2px;
}
.brand .dot { color: var(--accent); }
.brand-logo {
  width: 26px; height: 26px; object-fit: contain; flex-shrink: 0;
  filter: drop-shadow(0 2px 6px var(--accent-glow));
}
.new-chat-btn {
  width: 100%; color: white; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  padding: 11px; border-radius: 10px; font-weight: 600; cursor: pointer;
  font-size: 14px; box-shadow: 0 2px 12px var(--accent-glow);
  transition: filter .15s var(--ease), transform .08s var(--ease), box-shadow .15s var(--ease);
}
.new-chat-btn:hover,
.new-chat-btn:focus-visible {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border-color: transparent;
  filter: brightness(1.07);
  box-shadow: 0 4px 18px var(--accent-glow);
}
.new-chat-btn:active { transform: scale(0.98); }

.chats-search {
  display: flex; align-items: center; gap: 6px;
  padding: 12px 12px 8px;
}
.chats-search-input {
  flex: 1; padding: 8px 11px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 9px; color: var(--text); font-size: 13px;
  outline: none; transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.chats-search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chats-search-input::placeholder { color: var(--text-muted); }
.chats-search-clear {
  background: transparent; border: none; color: var(--text-dim);
  cursor: pointer; padding: 4px 6px; font-size: 13px;
}
.chats-search-clear:hover { color: var(--text); }

/* Virtual scroll: spacer holds the full virtual height; window is the
   absolutely-positioned slice that's actually rendered. */
.chats-list { flex: 1; overflow-y: auto; padding: 6px; position: relative; }
.chats-spacer { position: relative; width: 100%; }
.chats-window { position: absolute; top: 0; left: 0; right: 0; }
.chats-loading, .chats-empty {
  padding: 12px; text-align: center; color: var(--text-dim); font-size: 13px;
}

.chat-item {
  /* `height` is set inline by the virtual-scroll renderer (= CHAT_ROW_HEIGHT).
     Keep padding tight so content fits comfortably in 38px. */
  position: relative; padding: 0 10px; border-radius: 9px;
  cursor: pointer; display: flex; align-items: center; gap: 8px;
  text-decoration: none;
  color: var(--text-dim); font-size: 14px;
  box-sizing: border-box;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.chat-item:hover { background: var(--bg-hover); color: var(--text); }
.chat-item.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 0 0 0 1px rgba(255,122,26,0.25); }
.chat-item .pin-icon { color: var(--accent); font-size: 13px; }
.chat-item .chat-title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item .chat-menu-btn {
  opacity: 0; background: transparent; border: none; color: var(--text-dim);
  padding: 2px 6px; cursor: pointer; font-size: 16px; line-height: 1;
}
.chat-item:hover .chat-menu-btn, .chat-item.active .chat-menu-btn { opacity: 1; }
.chat-item .chat-menu-btn:hover { color: var(--text); }
.chat-item input.rename-input {
  flex: 1; padding: 4px 6px; font-size: 14px;
}
.popover {
  position: absolute; right: 0; top: 100%; z-index: 30;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 5px; min-width: 140px;
  box-shadow: var(--shadow-md);
  animation: popIn .12s var(--ease);
}
@keyframes popIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.popover button {
  display: block; width: 100%; text-align: left; padding: 8px 11px;
  border: none; background: transparent; border-radius: 7px; color: var(--text); font-size: 14px;
}
.popover button:hover { background: var(--bg-hover); }
.popover button.danger:hover { background: rgba(255,90,90,0.12); color: var(--danger); }

/* ---- Main ---- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.header {
  height: 56px; flex: 0 0 56px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  background: var(--bg);
  position: relative; z-index: 10;
}
.model-picker { position: relative; min-width: 220px; }
.model-picker-btn {
  width: 100%; background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  padding: 8px 12px; border-radius: 9px; font-size: 14px; cursor: pointer; font-weight: 500;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.model-picker-btn:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.model-picker-arrow { color: var(--text-dim); font-size: 11px; }
.model-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 80;
  min-width: 100%; width: max-content; max-width: min(420px, calc(100vw - 28px));
  background: var(--bg-elevated); border: 1px solid var(--border-strong); border-radius: 11px;
  padding: 5px; box-shadow: var(--shadow-md);
  animation: popIn .12s var(--ease);
}
.model-option {
  position: relative; width: 100%; background: transparent; border: 0; color: var(--text);
  padding: 9px 11px; border-radius: 8px; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left;
  transition: background .12s var(--ease);
}
.model-option:hover, .model-option.selected { background: var(--accent-soft); }
.model-option-name { white-space: nowrap; }
.model-info {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; flex: 0 0 auto;
  border: 1px solid var(--border); color: var(--text-muted, #888);
  font-size: 11px; line-height: 1; cursor: help; user-select: none;
}
.model-info .model-info-tip {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 5px 9px; border-radius: 6px; font-size: 12px; white-space: nowrap;
  z-index: 90; box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
.model-info:hover .model-info-tip,
.model-info:focus .model-info-tip,
.model-info .model-info-tip.open { display: block; }
.header .spacer { flex: 1; }
.header .icon-btn {
  background: transparent; border: none; color: var(--text-dim); font-size: 20px;
  cursor: pointer; padding: 6px; border-radius: 6px;
}
.header .icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.header .sound-btn,
.header .settings-btn { display: flex; align-items: center; justify-content: center; position: relative; }
.header .sound-btn svg,
.header .settings-btn svg { width: 19px; height: 19px; display: block; }
/* Custom tooltip — same look as .model-info-tip (the "?" in the model list) */
.header .icon-btn .btn-tip {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 5px 9px; border-radius: 6px; font-size: 12px; white-space: nowrap;
  z-index: 90; box-shadow: 0 4px 12px rgba(0,0,0,.35);
  pointer-events: none;
}
.header .icon-btn:hover .btn-tip,
.header .icon-btn:focus-visible .btn-tip { display: block; }

/* ---- Chat area ---- */
.chat-area {
  flex: 1; overflow-y: auto; padding: 24px 0; min-height: 0;
}
.empty-state {
  height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); flex-direction: column; gap: 10px; padding: 30px;
  animation: cardIn .4s var(--ease);
}
.empty-state h2 {
  color: var(--text); font-weight: 700; margin: 0; font-size: 28px;
  letter-spacing: -0.5px;
  background: linear-gradient(
    100deg,
    #ffffff 0%,
    #ffffff 25%,
    var(--accent) 45%,
    var(--accent-hover) 55%,
    #ffffff 75%,
    #ffffff 100%
  );
  background-size: 220% auto;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmerTitle 5s ease-in-out infinite alternate;
}
@keyframes shimmerTitle {
  from { background-position: 0% center; }
  to   { background-position: 100% center; }
}
@media (prefers-reduced-motion: reduce) {
  .empty-state h2 { animation: none; }
}
.msg-list { max-width: 800px; margin: 0 auto; padding: 0 16px; display: flex; flex-direction: column; gap: 22px; }
.msg-row { display: flex; flex-direction: column; }
.msg-row.user { align-items: flex-end; }
.msg-row.assistant { align-items: flex-start; }
.bubble {
  max-width: 85%; padding: 11px 15px; border-radius: 16px;
  line-height: 1.6; word-wrap: break-word; word-break: break-word;
  position: relative;
}
.msg-row.user .bubble {
  background: var(--user-bubble); border: 1px solid var(--border);
  border-bottom-right-radius: 5px;
  box-shadow: var(--shadow-sm);
}
.msg-row.assistant .bubble {
  background: transparent; border: none;
  padding: 4px 2px; max-width: 100%;
}
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
  background: #0a0b0d; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; overflow-x: auto; font-size: 13px;
  margin: 10px 0; box-shadow: var(--shadow-sm);
}
.bubble code:not(pre code) {
  background: var(--accent-soft); color: #ffc89a; padding: 2px 6px; border-radius: 5px;
  font-size: 0.88em;
}
.bubble pre code { background: transparent; padding: 0; font-size: 13px; }

.bubble img.msg-img {
  max-width: min(60%, 400px); max-height: 400px;
  object-fit: contain; border-radius: 8px;
  cursor: pointer; display: block; margin: 6px 0;
  border: 1px solid var(--border);
}

.tool-progress {
  font-style: italic; color: var(--text-dim); font-size: 13px;
  margin: 4px 0; padding-left: 4px;
}
.tool-progress.completed { opacity: 0.6; }

.msg-actions {
  display: flex; gap: 6px; margin-top: 4px; opacity: 0;
  transition: opacity .12s ease;
  align-items: center;
}
.msg-row:hover .msg-actions { opacity: 1; }
.msg-actions button {
  font-size: 12px; padding: 3px 8px; color: var(--text-dim);
  background: transparent; border: 1px solid transparent;
}
.msg-actions button:hover { color: var(--text); border-color: var(--border); }

.msg-actions .icon-action {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0;
  border-radius: 6px; cursor: pointer;
}
.msg-actions .icon-action:disabled { opacity: 0.3; cursor: default; }
.msg-actions .icon-action:disabled:hover { color: var(--text-dim); border-color: transparent; }
.msg-timestamp {
  font-size: 11px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  margin-right: 2px;
  user-select: none;
  cursor: default;
}
.version-nav {
  display: inline-flex; align-items: center; gap: 2px;
  margin-left: 4px;
}
.version-nav .icon-action { font-size: 16px; line-height: 1; width: 22px; height: 22px; }
.version-counter {
  font-size: 12px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 28px; text-align: center;
}

/* Collapsible tool-events block above an assistant bubble. Default collapsed:
   single button "🔧 Used N tools" with a chevron. Expanded: chevron rotates +
   the saved tool list renders below it. */
.tools-collapsible { margin: 0 0 6px 0; }
.tools-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 12px;
  padding: 4px 11px; border-radius: 999px; cursor: pointer;
  transition: color .15s var(--ease), border-color .15s var(--ease), background .15s var(--ease);
}
.tools-toggle:hover {
  color: var(--text); border-color: var(--border-strong);
  background: var(--bg-hover);
}
.tools-toggle .chev {
  display: inline-block; font-size: 10px;
  transition: transform .12s ease;
}
.tools-collapsible.open .tools-toggle .chev { transform: rotate(90deg); }
.tools-list { margin-top: 4px; padding-left: 4px; }

.msg-edit {
  width: 100%;
}
.msg-edit textarea {
  width: 100%; min-height: 80px; resize: vertical;
  field-sizing: content;
}
.msg-edit-actions { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }

.msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg-attachments .att-pill {
  background: var(--bg-elevated); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 14px; font-size: 12px;
  color: var(--text-dim);
}
.msg-attachments img.thumb-img {
  height: 80px; max-width: 200px; object-fit: cover; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border);
}

/* Inline MEDIA:/path images rendered into the markdown bubble via v-html. */
.bubble img.media-attachment {
  max-width: min(60%, 400px); max-height: 400px; object-fit: contain;
  border-radius: 8px; cursor: pointer; border: 1px solid var(--border);
  display: block; margin: 8px 0;
}
.bubble a.att-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 999px; color: var(--accent); text-decoration: none; font-size: 13px;
  margin: 4px 0;
}
.bubble a.att-pill:hover { background: var(--bg-hover); }

.cursor-blink::after {
  content: '▍'; color: var(--accent); animation: blink 1s steps(2) infinite;
  margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---- Input bar ---- */
.reply-floating {
  position: fixed; transform: translate(-50%, -100%);
  background: var(--accent); color: #fff; border: none;
  padding: 5px 12px; border-radius: 14px; font-size: 12px;
  cursor: pointer; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.reply-floating:hover { background: var(--accent-hover); }
.input-bar-wrap {
  padding: 10px 16px 14px; background: var(--bg);
  /* Respect iOS/Android safe-area (home indicator, gesture bar) */
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  flex: 0 0 auto;
  position: relative;
}
.input-bar-wrap::before {
  content: ''; position: absolute; top: -28px; left: 0; right: 0; height: 28px;
  background: linear-gradient(to top, var(--bg), transparent);
  pointer-events: none;
}
.input-bar-inner { max-width: 820px; margin: 0 auto; }
.attachments-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.att-card {
  position: relative;
  display: flex; flex-direction: column; justify-content: space-between;
  width: 140px; height: 95px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px;
  color: var(--text); cursor: pointer; overflow: hidden;
}
.att-card.image { padding: 0; }
.att-card.image img { width: 100%; height: 100%; object-fit: cover; }
.att-card .att-preview {
  font-size: 9px; line-height: 1.25; color: var(--text-dim);
  white-space: pre-wrap; word-break: break-all; overflow: hidden;
  flex: 1; margin-right: 12px;
}
.att-card .att-name {
  font-size: 12px; color: var(--text); flex: 1;
  overflow: hidden; word-break: break-all; margin-right: 12px;
}
.att-card .att-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 10px; color: var(--text-dim); margin-top: 4px;
  text-transform: uppercase;
}
.att-card .att-x {
  position: absolute; top: 2px; right: 2px;
  background: rgba(0,0,0,0.5); border: none; color: #fff;
  cursor: pointer; padding: 0; font-size: 11px;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.att-card .att-x:hover { background: var(--danger); }

.input-bar {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 18px; padding: 9px 9px 9px 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.input-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm);
}
.input-bar textarea {
  flex: 1; background: transparent; border: none; color: var(--text);
  resize: none; outline: none; font: inherit;
  max-height: 20vh; min-height: 24px; padding: 6px 0;
  line-height: 1.5;
}
.input-bar textarea:focus { box-shadow: none; }
.input-bar .icon-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover)); border: none; color: white;
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 0 0 38px;
  box-shadow: 0 2px 10px var(--accent-glow);
  transition: filter .15s var(--ease), transform .08s var(--ease);
}
.input-bar .icon-btn:hover,
.input-bar .icon-btn:focus-visible {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border-color: transparent;
  filter: brightness(1.08);
}
.input-bar .icon-btn:active { transform: scale(0.92); }
.input-bar .icon-btn.attach {
  background: transparent; color: var(--text-dim); box-shadow: none;
  width: 38px; height: 38px;
}
.input-bar .icon-btn.attach:hover { color: var(--text); background: var(--bg-hover); filter: none; }
.input-bar .icon-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.input-bar .icon-btn svg { width: 18px; height: 18px; }

/* ---- Modal ---- */
/* Lag-free blur strategy: instead of backdrop-filter (which re-samples the
   live background every frame while you scroll inside the modal), we blur the
   STATIC background elements (.sidebar/.main) directly via filter. Those
   elements don't change while a modal is open, so the browser rasterizes the
   blur ONCE and never recomputes it during in-modal scrolling. */
.app:has(.modal-backdrop) > .sidebar,
.app:has(.modal-backdrop) > .main {
  filter: blur(7px);
  transition: filter .18s var(--ease);
}
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn .18s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 24px;
  width: 520px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: cardIn .22s var(--ease);
}
.modal h2 { margin: 0 0 16px; font-size: 19px; font-weight: 700; letter-spacing: -0.3px; }
.modal h3 {
  margin: 16px 0 8px; font-size: 12px;
  color: var(--accent); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600;
}
.modal .field { margin-bottom: 10px; }
.modal .field label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-dim); margin-bottom: 4px;
}
.modal .field input {
  width: 100%;
}
.help-tip {
  display: inline-flex; width: 16px; height: 16px; border-radius: 50%;
  background: #333; color: var(--text-dim); align-items: center; justify-content: center;
  font-size: 11px; cursor: help; position: relative;
}
.help-tip:hover { background: var(--accent); color: white; }
.help-tip:hover::after {
  content: attr(data-tip);
  position: absolute; left: 22px; top: -4px;
  background: #111; border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 6px;
  white-space: pre-wrap; width: 240px; font-size: 12px;
  color: var(--text); z-index: 10;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-actions button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff; border: none; font-weight: 600;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.modal-actions button.primary:hover { filter: brightness(1.07); }
.modal .api-key-row { display: flex; gap: 6px; align-items: center; }
.modal .api-key-row input { flex: 1; font-family: monospace; font-size: 13px; }

/* ---- Text preview / editor modal ---- */
.modal.text-preview-modal {
  width: 90vw; max-width: 1100px;
  height: 85vh; max-height: 85vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal.text-preview-modal h2 {
  margin: 0 0 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.text-preview-area {
  flex: 1 1 auto; min-height: 0;
  width: 100%;
  background: #0e0e0e; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.45;
  white-space: pre; /* keep long lines, allow horizontal scroll */
  overflow: auto;
  resize: none;
  tab-size: 2;
  box-sizing: border-box;
}
.text-preview-area:focus { outline: 1px solid var(--accent); outline-offset: -1px; }
.text-preview-area.readonly { margin: 0; }

/* ---- Lightbox ---- */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.lightbox img { max-width: 95vw; max-height: 95vh; object-fit: contain; cursor: pointer; }
.lightbox .lb-close {
  position: absolute; top: 16px; right: 20px;
  background: transparent; color: white; border: none;
  font-size: 30px; cursor: pointer;
}

/* ---- Confirm dialog ---- */
.confirm-modal { width: 380px; }
.confirm-modal p { margin: 0 0 16px; }
/* Confirm sits on top of EVERY other modal — its prompt is the active
   user decision, so it must visually win over settings sub-modals.
   Without this the settings backdrop drew over the confirm dialog and
   click-on-backdrop closed the confirm before the user could act. */
.modal-backdrop:has(> .confirm-modal) { z-index: 200; }

/* ---- Loading dots ---- */
.loading-dots::after {
  content: '...'; animation: dots 1.5s steps(4) infinite;
}
@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ---- Mobile sidebar (drawer) ---- */
/* Specificity .header .hamburger-btn beats .header .icon-btn so display rules win */
.header .hamburger-btn { display: none !important; }
.sidebar-backdrop { display: none; }

@media (max-width: 768px) {
  /* Lift the input bar above the on-screen Android nav / iOS gesture bar.
     We can't rely on env(safe-area-inset-bottom) — many mobile browsers
     (Chrome on Android, Firefox) return 0 even with viewport-fit=cover. */
  .input-bar-wrap {
    padding-bottom: 70px !important;
  }
  .header .hamburger-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin-right: 4px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80%;
    max-width: 320px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.5);
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .app.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .main {
    width: 100%;
    flex: 1 1 100%;
  }
}

/* ---- Error banner ---- */
.error-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0 auto 8px;
  max-width: 760px;
  padding: 10px 14px;
  background: rgba(255, 193, 7, 0.10);
  border: 1px solid rgba(255, 193, 7, 0.55);
  border-radius: 8px;
  color: #ffd97a;
  font-size: 14px;
  line-height: 1.45;
}
.error-banner-body { flex: 1; min-width: 0; }
.error-banner-title { font-weight: 600; color: #ffc107; margin-bottom: 4px; }
.error-banner-detail {
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #f0d68b;
  max-height: 220px;
  overflow-y: auto;
}
.error-banner-close {
  background: transparent; border: none; color: #ffd97a;
  font-size: 16px; cursor: pointer; padding: 2px 6px;
  border-radius: 4px;
}
.error-banner-close:hover { background: rgba(255,255,255,0.08); color: #fff; }

/* info variant of banner — used as a transient toast (e.g. settings saved) */
.error-banner.banner-info {
  background: rgba(72, 187, 120, 0.10);
  border-color: rgba(72, 187, 120, 0.50);
  color: #b9f2cf;
}
.error-banner.banner-info .error-banner-title { color: #6fdc8c; }
.error-banner.banner-info .error-banner-detail { color: #c8e6d4; }
.error-banner.banner-info .error-banner-close { color: #b9f2cf; }

/* ---- Settings hub: tiles + sub-panel sections ---------------------------
   The hub stays a single tall modal; sub-modals stack on top of it via
   higher z-index from being later in the DOM. Reusing existing .modal /
   .modal-backdrop — we only add layout primitives (tiles, hint, sections). */
.modal.settings-hub { width: 600px; }
.modal.modal-wide { width: 720px; }
.modal.tools-modal {
  height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal.tools-modal .tools-list {
  flex: 1 1 auto;
  max-height: none;
  min-height: 0;
}

.settings-section-title {
  margin: 18px 0 6px;
  font-size: 12px; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px;
}
.settings-section-title:first-of-type { margin-top: 4px; }

.settings-hint {
  margin: 0 0 12px;
  font-size: 13px; color: var(--text-dim); line-height: 1.5;
}
.settings-hint a { color: var(--accent); }
.settings-hint code {
  background: rgba(255,255,255,0.05); padding: 1px 5px;
  border-radius: 4px; font-size: 12px;
}
.settings-steps {
  margin: 0 0 14px; padding-left: 22px;
  font-size: 13px; color: var(--text-dim); line-height: 1.55;
}
.settings-steps li { margin-bottom: 6px; }
.settings-steps a { color: var(--accent); }
.settings-steps code {
  background: rgba(255,255,255,0.05); padding: 1px 5px;
  border-radius: 4px; font-size: 12px;
}
.settings-steps strong { color: var(--text); font-weight: 600; }

.settings-tiles {
  display: grid; gap: 8px; margin-bottom: 4px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.settings-tile {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 15px; border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  color: inherit; cursor: pointer;
  text-align: left; font: inherit; width: 100%;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform .08s var(--ease);
}
.settings-tile:hover {
  background: var(--accent-soft);
  border-color: rgba(255,122,26,0.4);
}
.settings-tile:active { transform: scale(0.99); }
.settings-tile .tile-icon { font-size: 22px; line-height: 1; flex: 0 0 auto; }
.settings-tile img.tile-icon { width: 22px; height: 22px; object-fit: contain; }
.settings-tile .tile-body { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.settings-tile .tile-title { font-size: 14px; font-weight: 600; }
.settings-tile .tile-sub { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-tile .tile-badge {
  width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto;
}
.settings-tile .tile-badge.on  { background: #4ade80; box-shadow: 0 0 6px rgba(74,222,128,0.6); }
.settings-tile .tile-badge.off { background: #555; }

/* Messenger tiles get a slight emphasis — they are the headline action. */
.settings-tile.messenger { padding: 14px 16px; }
.settings-tile.messenger .tile-title { font-size: 15px; }

/* Memory / skill preview / skill paste — reuses a tall textarea. */
.memory-editor {
  width: 100%; min-height: 320px; max-height: 60vh;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px; line-height: 1.5;
  background: rgba(0,0,0,0.25); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  resize: vertical;
}
.memory-editor[readonly] { color: var(--text-dim); }

/* Skill list / MCP list — generic row pattern. */
.skills-list {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 50vh; overflow-y: auto;
  margin-bottom: 12px;
}
.skill-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.02);
}
.skill-row:hover { background: rgba(255,255,255,0.05); border-color: var(--border); }
.skill-meta { flex: 1 1 auto; cursor: pointer; min-width: 0; }
.skill-name { font-size: 13px; font-weight: 500; }
.skill-name .skill-cat {
  font-size: 11px; color: var(--text-dim); margin-left: 6px;
  background: rgba(255,255,255,0.06); padding: 1px 6px; border-radius: 4px;
}
.skill-desc { font-size: 12px; color: var(--text-dim); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Disabled skills read dimmer so the off-state is obvious at a glance. */
.skill-row.skill-off .skill-name,
.skill-row.skill-off .skill-desc { opacity: 0.45; }
/* Compact on/off switch for enabling/disabling a skill in place. */
.skill-toggle { position: relative; display: inline-block; width: 38px; height: 22px; flex: 0 0 auto; cursor: pointer; }
.skill-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.skill-toggle-slider {
  position: absolute; inset: 0; border-radius: 22px;
  background: rgba(255,255,255,0.14); transition: background 0.15s ease;
}
.skill-toggle-slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; transition: transform 0.15s ease;
}
.skill-toggle input:checked + .skill-toggle-slider { background: var(--accent, #5b8cff); }
.skill-toggle input:checked + .skill-toggle-slider::before { transform: translateX(16px); }
.skill-toggle input:disabled + .skill-toggle-slider { opacity: 0.5; cursor: default; }
.icon-btn {
  background: transparent; border: none; cursor: pointer;
  padding: 6px 8px; border-radius: 6px; font-size: 14px;
  color: var(--text-dim);
}
.icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.icon-btn.danger:hover { background: rgba(239,68,68,0.15); color: #fca5a5; }

/* Inline action button used inside hint text — looks like a link. */
.link-btn {
  background: transparent; border: none; color: var(--accent);
  cursor: pointer; padding: 0; font: inherit;
}
.link-btn:hover { text-decoration: underline; }

/* Tab bar for skill importer (paste vs github). */
.tab-bar {
  display: flex; gap: 4px; margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.tab-bar button {
  background: transparent; border: none; color: var(--text-dim);
  padding: 8px 14px; cursor: pointer; font: inherit;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-bar button:hover { color: var(--text); }
.tab-bar button.active {
  color: var(--accent); border-bottom-color: var(--accent);
}

/* Tools list — platform tabs + checkboxes with name + label. */
.tool-platform-tabs {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin: 0 0 12px;
}
.tool-platform-tab {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: var(--text-dim);
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.tool-platform-tab:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.tool-platform-tab.active {
  color: var(--text);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}
.tools-list {
  display: flex; flex-direction: column; gap: 2px;
  max-height: 55vh; overflow-y: auto; margin-bottom: 12px;
}
.tool-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px;
  cursor: pointer;
}
.tool-row:hover { background: rgba(255,255,255,0.04); }
.tool-row input[type=checkbox] {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  border: none;
  box-shadow: none;
  background: transparent;
  accent-color: var(--accent);
  transition: none;
}
.tool-row input[type=checkbox]:focus,
.tool-row input[type=checkbox]:checked {
  box-shadow: none;
}
.tool-label { flex: 1 1 auto; font-size: 13px; }
.tool-name {
  font-family: ui-monospace, monospace; font-size: 11px;
  color: var(--text-dim); background: rgba(255,255,255,0.04);
  padding: 1px 6px; border-radius: 4px;
}
