/* Neribo chat client. Motion tokens follow Emil Kowalski's animation guidance:
   strong ease-out for entrances, short durations, transform and opacity only. */

:root,
html[data-theme="dark"] {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --dur-1: 120ms;
  --dur-2: 200ms;
  --dur-3: 320ms;
  --dur-4: 480ms;

  --bg: #212121;
  --sidebar: #171717;
  --composer: #2f2f2f;
  --pop: #2f2f2f;
  --text: #ececec;
  --text-2: #b6b6b6;
  --text-3: #8f8f8f;
  --border: rgba(255, 255, 255, 0.14);
  --border-soft: rgba(255, 255, 255, 0.08);
  --hover: rgba(255, 255, 255, 0.07);
  --press: rgba(255, 255, 255, 0.12);
  --accent: #ffffff;
  --accent-fg: #0d0d0d;
  --user: #323232;
  --code: #1b1b1b;
  --link: #8ab4ff;
  --danger: #f25656;
  --ok: #7ee2a8;
  --warn: #e0a63f;
  --danger-soft: rgba(242, 86, 86, 0.14);
  --seg-active: #454545;
  --scroll: rgba(255, 255, 255, 0.18);
  --overlay: rgba(0, 0, 0, 0.6);
  --send-idle: rgba(255, 255, 255, 0.12);
  --tok-kw: #cc7fd7;
  --tok-str: #9ece8a;
  --tok-num: #d7a35f;
  --tok-fn: #7fb3e8;
  --tok-com: rgba(255, 255, 255, 0.38);
}

html[data-theme="light"] {
  --bg: #ffffff;
  --sidebar: #f9f9f9;
  --composer: #f4f4f4;
  --pop: #ffffff;
  --text: #0d0d0d;
  --text-2: #5d5d5d;
  --text-3: #8a8a8a;
  --border: rgba(0, 0, 0, 0.14);
  --border-soft: rgba(0, 0, 0, 0.08);
  --hover: rgba(0, 0, 0, 0.05);
  --press: rgba(0, 0, 0, 0.09);
  --accent: #0d0d0d;
  --accent-fg: #ffffff;
  --user: #f4f4f4;
  --code: #f7f7f7;
  --link: #0b57d0;
  --danger: #d92d20;
  --ok: #1e7f4f;
  --warn: #b25e09;
  --danger-soft: rgba(217, 45, 32, 0.1);
  --seg-active: #ffffff;
  --scroll: rgba(0, 0, 0, 0.2);
  --overlay: rgba(0, 0, 0, 0.45);
  --send-idle: rgba(0, 0, 0, 0.08);
  --tok-kw: #8250df;
  --tok-str: #1a7f37;
  --tok-num: #953800;
  --tok-fn: #0550ae;
  --tok-com: rgba(0, 0, 0, 0.45);
}

html[data-theme="warm"] {
  --bg: #faf9f5;
  --sidebar: #f0eee6;
  --composer: #ffffff;
  --pop: #ffffff;
  --text: #262522;
  --text-2: #6f6e66;
  --text-3: #9b9a90;
  --border: rgba(60, 56, 44, 0.22);
  --border-soft: rgba(60, 56, 44, 0.13);
  --hover: rgba(60, 56, 44, 0.06);
  --press: rgba(60, 56, 44, 0.12);
  --accent: #c6613f;
  --accent-fg: #ffffff;
  --user: #ece9dd;
  --code: #f0eee6;
  --link: #a34e2e;
  --danger: #c0362c;
  --ok: #2e7d4f;
  --warn: #a86a12;
  --danger-soft: rgba(192, 54, 44, 0.12);
  --seg-active: #ffffff;
  --scroll: rgba(60, 56, 44, 0.24);
  --overlay: rgba(43, 40, 32, 0.45);
  --send-idle: rgba(60, 56, 44, 0.12);
  --tok-kw: #c37fca;
  --tok-str: #8fae6b;
  --tok-num: #c98d55;
  --tok-fn: #6f9cc7;
  --tok-com: rgba(60, 55, 44, 0.5);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

::selection { background: var(--press); }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

input, textarea {
  font: inherit;
  color: inherit;
}

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 8px;
}

[hidden] { display: none !important; }

/* No tap flash on touch surfaces; press feedback comes from :active states. */
* { -webkit-tap-highlight-color: transparent; }

/* Lucide icons inherit size from context. The <i> tags hold layout
   before the library swaps them, so nothing jumps. */
i[data-lucide] {
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex: none;
}
.lucide { width: 20px; height: 20px; }

/* ---------- layout ---------- */

.app { display: flex; height: 100dvh; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ---------- sidebar ---------- */

.sidebar {
  width: 264px;
  flex: none;
  background: var(--sidebar);
  border-right: 1px solid var(--border-soft);
  overflow: hidden;
  clip-path: inset(0 0 0 0);
  transition: clip-path 220ms var(--ease-drawer);
}
body:not(.nav-open) .sidebar {
  width: 0;
  border-right-color: transparent;
  clip-path: inset(0 100% 0 0);
  visibility: hidden;
  transition: clip-path 220ms var(--ease-drawer), width 0s linear 220ms, border-color 0s linear 220ms, visibility 0s linear 220ms;
}

.sidebar-inner {
  width: 264px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px 10px 8px;
  transition: opacity 180ms var(--ease-out), transform 220ms var(--ease-out);
}
body:not(.nav-open) .sidebar-inner {
  opacity: 0;
  transform: translateX(-16px);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 8px;
}
.sidebar-top-right { display: flex; gap: 2px; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--text-2);
  transition: transform 160ms var(--ease-out), background-color 140ms ease, color 140ms ease;
}
@media (hover: hover) { .icon-btn:hover { background: var(--hover); color: var(--text); } }
.icon-btn:active { transform: scale(0.93); background: var(--press); }
.icon-btn .lucide, .icon-btn i[data-lucide] { width: 20px; height: 20px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 1px; padding-bottom: 6px; }

.side-action {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  transition: transform 160ms var(--ease-out), background-color 140ms ease;
}
@media (hover: hover) { .side-action:hover { background: var(--hover); } }
.side-action:active { transform: scale(0.98); }
.side-action .lucide, .side-action i[data-lucide] { width: 18px; height: 18px; color: var(--text-2); }

.chat-groups {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 0 8px;
  margin: 0 -4px;
}

.group-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  padding: 14px 12px 5px;
  margin: 0;
}

.chat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 38px;
  padding: 0 6px 0 12px;
  margin: 0 4px;
  width: calc(100% - 8px);
  border-radius: 10px;
  font-size: 14px;
  text-align: left;
  transition: background-color 140ms ease;
}
@media (hover: hover) { .chat-row:hover { background: var(--hover); } }
.chat-row.active { background: var(--press); }
.chat-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
.chat-row.active .chat-title { font-weight: 500; }

.row-menu {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-2);
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 140ms ease, background-color 140ms ease, transform 160ms var(--ease-out);
}
.chat-row:hover .row-menu,
.chat-row:focus-within .row-menu,
.row-menu[aria-expanded="true"] { opacity: 1; transform: translateX(0); }
@media (hover: hover) { .row-menu:hover { background: var(--press); color: var(--text); } }
.row-menu:active { transform: scale(0.9); }
.row-menu .lucide, .row-menu i[data-lucide] { width: 16px; height: 16px; }
@media (hover: none) { .row-menu { opacity: 1; } }

.rename-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 14px;
}

.sidebar-foot { border-top: 1px solid var(--border-soft); padding-top: 8px; }

.plan-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  margin-bottom: 6px;
  transition: transform 160ms var(--ease-out), background-color 140ms ease, border-color 140ms ease;
}
@media (hover: hover) { .plan-card:hover { background: var(--hover); border-color: var(--border); } }
.plan-card:active { transform: scale(0.98); }
.plan-card .lucide, .plan-card i[data-lucide] { width: 18px; height: 18px; color: var(--text-2); }
.plan-text { display: flex; flex-direction: column; min-width: 0; }
.plan-text strong { font-size: 13.5px; font-weight: 600; }
.plan-text em { font-style: normal; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.profile-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  transition: transform 160ms var(--ease-out), background-color 140ms ease;
}
@media (hover: hover) { .profile-row:hover { background: var(--hover); } }
.profile-row:active { transform: scale(0.98); }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex: none;
}
.avatar-sm { width: 28px; height: 28px; font-size: 13px; }
.avatar-btn { transition: transform 160ms var(--ease-out); }
@media (hover: hover) { .avatar-btn:hover { transform: scale(1.05); } }
.avatar-btn:active { transform: scale(0.94); }

/* ---------- topbar ---------- */

.topbar {
  height: 60px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
}
.top-left, .top-right { display: flex; align-items: center; gap: 4px; }

.model-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.01em;
  padding: 8px 10px;
  border-radius: 10px;
  transition: background-color 140ms ease;
}
@media (hover: hover) { .model-btn:hover { background: var(--hover); } }
.model-btn .lucide, .model-btn i[data-lucide] { width: 16px; height: 16px; color: var(--text-3); }
.model-btn .chev { transition: transform 180ms var(--ease-out); }
.model-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }

.share-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 500;
  padding: 7px 14px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  transition: transform 160ms var(--ease-out), background-color 140ms ease, border-color 140ms ease;
}
@media (hover: hover) { .share-btn:hover { background: var(--hover); border-color: var(--border); } }
.share-btn:active { transform: scale(0.96); }
.share-btn .lucide, .share-btn i[data-lucide] { width: 15px; height: 15px; }

/* ---------- chat scroll / empty state ---------- */

.chat-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }

.empty {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  gap: 22px;
}

.greeting {
  margin: 0;
  font-size: clamp(26px, 4vw, 32px);
  font-weight: 500;
  letter-spacing: -0.02em;
  text-align: center;
  text-wrap: balance;
}
html[data-theme="warm"] .greeting {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  letter-spacing: -0.01em;
}

.empty-slot { width: 100%; max-width: 768px; }

.chips {
  width: 100%;
  max-width: 768px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (max-width: 640px) { .chips { grid-template-columns: 1fr; } }

.chip {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 13px 15px;
  opacity: 0;
  transform: translateY(8px);
  animation: rise 300ms var(--ease-out) forwards;
  transition: transform 160ms var(--ease-out), background-color 140ms ease, border-color 140ms ease;
}
.chip.d1 { animation-delay: 40ms; }
.chip.d2 { animation-delay: 90ms; }
.chip.d3 { animation-delay: 140ms; }
.chip.d4 { animation-delay: 190ms; }
@keyframes rise { to { opacity: 1; transform: translateY(0); } }
@media (hover: hover) { .chip:hover { background: var(--hover); border-color: var(--border); } }
.chip:active { transform: scale(0.98); }
.chip .lucide, .chip i[data-lucide] { width: 18px; height: 18px; color: var(--text-2); margin-top: 1px; }
.chip span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.chip strong { font-size: 14px; font-weight: 600; }
.chip em { font-style: normal; font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- composer ---------- */

.composer-dock { flex: none; padding: 4px 16px max(10px, env(safe-area-inset-bottom)); }
.dock-slot { max-width: 768px; margin: 0 auto; }

.composer-block { width: 100%; }

.composer {
  background: var(--composer);
  border: 1px solid var(--border-soft);
  border-radius: 28px;
  padding: 10px 10px 8px 20px;
  transition: border-color 160ms ease;
}
.composer:focus-within { border-color: var(--border); }

.composer textarea {
  width: 100%;
  background: transparent;
  border: none;
  resize: none;
  padding: 8px 8px 4px 0;
  font-size: 16px;
  line-height: 1.5;
  max-height: 200px;
  display: block;
  transition: height var(--dur-2) var(--ease-out);
}
.composer textarea::placeholder { color: var(--text-3); }

.composer-row { display: flex; align-items: center; gap: 2px; }
.composer-spacer { flex: 1; }

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--send-idle);
  color: var(--text-3);
  transition: transform 160ms var(--ease-out), background-color 160ms ease, color 160ms ease;
}
.send-btn .lucide, .send-btn i[data-lucide] { width: 18px; height: 18px; }
.send-btn:not(:disabled) { background: var(--accent); color: var(--accent-fg); cursor: pointer; }
@media (hover: hover) { .send-btn:not(:disabled):hover { transform: scale(1.05); } }
.send-btn:not(:disabled):active { transform: scale(0.92); }
.send-btn:disabled { cursor: default; }
#stopBtn { background: var(--accent); color: var(--accent-fg); }
@media (hover: hover) { #stopBtn:hover { transform: scale(1.05); } }
#stopBtn:active { transform: scale(0.92); }
#stopBtn .lucide, #stopBtn i[data-lucide] { width: 15px; height: 15px; }

.disclaimer {
  margin: 9px 0 0;
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
}

/* ---------- messages ---------- */

.messages {
  max-width: 768px;
  margin: 0 auto;
  padding: 26px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.msg { display: flex; flex-direction: column; }
.msg.enter { opacity: 0; transform: translateY(8px); }
.msg.show { opacity: 1; transform: translateY(0); transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out); }

.msg.user { align-items: flex-end; }
.bubble {
  background: var(--user);
  border-radius: 22px;
  padding: 10px 18px;
  max-width: 78%;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.assistant { align-items: stretch; }
.msg-body { min-width: 0; overflow-wrap: break-word; }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }

.msg-actions { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 8px; margin-left: -8px; }
.msg-actions.fresh { animation: act-in 400ms ease-out both; }
.msg-actions button {
  flex: none;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-3);
  transition: transform 160ms var(--ease-out), background-color 140ms ease, color 140ms ease, opacity 160ms ease;
}
@media (hover: hover) { .msg-actions button:hover { background: var(--hover); color: var(--text); } }
.msg-actions button:active { transform: scale(0.9); }
.msg-actions button.on { color: var(--text); }
.msg-actions .lucide, .msg-actions i[data-lucide] { width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) {
  .msg-actions { opacity: 0; }
  .msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
}

/* typing indicator: transform and opacity only */
.dots { display: inline-grid; grid-template-columns: repeat(3, 4px); gap: 1.5px; padding: 12px 2px; vertical-align: middle; }
.dots span { width: 4px; height: 4px; border-radius: 1px; background: var(--text); opacity: 0.15; animation: pixel-on 650ms ease-in-out infinite; }
.dots span:nth-child(1) { animation-delay: 90ms; }
.dots span:nth-child(2) { animation-delay: 180ms; }
.dots span:nth-child(3) { animation-delay: 270ms; }
.dots span:nth-child(4) { animation-delay: 0ms; }
.dots span:nth-child(5) { animation-delay: 90ms; }
.dots span:nth-child(6) { animation-delay: 180ms; }
.dots span:nth-child(7) { animation-delay: 90ms; }
.dots span:nth-child(8) { animation-delay: 180ms; }
.dots span:nth-child(9) { animation-delay: 270ms; }
@keyframes pixel-on { 0%, 100% { opacity: 0.15; } 50% { opacity: 1; } }
html.reduce-motion .dots span { animation: none; opacity: 0.15; }

.cursor {
  display: inline-block;
  width: 2px;
  height: 0.95em;
  margin-left: 2px;
  vertical-align: -1px;
  background: var(--text);
  border-radius: 2px;
  animation: fade-in 150ms ease-out both, cursor-blink 1.1s ease-in-out 200ms infinite;
}
@keyframes cursor-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
html.reduce-motion .cursor { animation: fade-in 150ms ease-out both; }
@media (prefers-reduced-motion: reduce) {
  .cursor { animation: fade-in 150ms ease-out both; }
}


/* ---------- markdown ---------- */

.md-p { margin: 0 0 12px; }
.md-p:last-child { margin-bottom: 0; }

.md-h { font-weight: 600; letter-spacing: -0.01em; margin: 18px 0 8px; }
h2.md-h { font-size: 19px; }
h3.md-h { font-size: 17px; }
h4.md-h, h5.md-h { font-size: 15.5px; }

.md-p a, .md-list a, .md-quote a, td a, th a, li a {
  color: var(--link);
  text-decoration: none;
}
@media (hover: hover) { .md-p a:hover, .md-list a:hover, .md-quote a:hover, td a:hover, li a:hover { text-decoration: underline; } }

.md-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: var(--press);
  border-radius: 6px;
  padding: 2px 6px;
}

.md-list { margin: 0 0 12px; padding-left: 22px; }
.md-list .md-list { margin: 6px 0 2px; }
.md-list li { margin: 4px 0; }
.md-list li::marker { color: var(--text-2); }

.md-quote {
  margin: 0 0 12px;
  padding: 4px 0 4px 14px;
  border-left: 2px solid var(--border);
  color: var(--text-2);
}
.md-quote p { margin: 0 0 6px; }
.md-quote p:last-child { margin-bottom: 0; }

.md-hr { border: none; border-top: 1px solid var(--border-soft); margin: 16px 0; }

.md-table-wrap { overflow-x: auto; margin: 0 0 14px; border: 1px solid var(--border-soft); border-radius: 12px; }
.md-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.md-table th, .md-table td { padding: 9px 13px; text-align: left; border-bottom: 1px solid var(--border-soft); }
.md-table thead th { background: var(--hover); font-weight: 600; }
.md-table tbody tr:last-child td { border-bottom: none; }

/* ---------- code blocks ---------- */

.codeblock {
  margin: 0 0 14px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  overflow: hidden;
  background: var(--code);
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 8px 7px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 12.5px;
  color: var(--text-2);
}
.mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-2);
  padding: 5px 9px;
  border-radius: 8px;
  transition: background-color 140ms ease, color 140ms ease, transform 160ms var(--ease-out);
}
@media (hover: hover) { .mini-btn:hover { background: var(--hover); color: var(--text); } }
.mini-btn:active { transform: scale(0.95); }
.mini-btn .lucide, .mini-btn i[data-lucide] { width: 14px; height: 14px; }
.codeblock pre { margin: 0; padding: 13px 15px; overflow-x: auto; }
.codeblock code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.6;
}

/* ---------- popovers: origin aware, scale from trigger ---------- */

.pop {
  position: fixed;
  z-index: 86; /* above the debug tab (85), under the modals (90+) */
  min-width: 230px;
  min-width: 230px;
  max-width: calc(100vw - 24px);
  background: var(--pop);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  opacity: 0;
  transform: scale(0.95);
  transform-origin: var(--origin, top left);
  transition: opacity 150ms var(--ease-out), transform 180ms var(--ease-out);
  pointer-events: none;
}
.pop.open { opacity: 1; transform: scale(1); pointer-events: auto; }
.pop-sm { min-width: 190px; }

.pop-label { font-size: 12px; color: var(--text-3); font-weight: 500; padding: 7px 10px 5px; margin: 0; }
.pop-sep { height: 1px; background: var(--border-soft); margin: 6px 4px; }

.pop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 14px;
  text-align: left;
  transition: background-color 120ms ease;
}
@media (hover: hover) { .pop-item:hover { background: var(--hover); } }
.pop-item .lucide, .pop-item i[data-lucide] { width: 17px; height: 17px; color: var(--text-2); }
.pop-item.danger, .pop-item.danger .lucide { color: var(--danger); }

.pop-model {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  text-align: left;
  transition: background-color 120ms ease;
}
@media (hover: hover) { .pop-model:hover { background: var(--hover); } }
.pop-model > .lucide, .pop-model > i[data-lucide] { width: 18px; height: 18px; color: var(--text-2); }
.pop-model span { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.pop-model strong { font-size: 14px; font-weight: 600; }
.pop-model em { font-style: normal; font-size: 12.5px; color: var(--text-3); }
.pop-model .check { width: 17px; height: 17px; color: var(--text); opacity: 0; }
.pop-model[aria-checked="true"] .check { opacity: 1; }

.profile-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.profile-meta { display: flex; flex-direction: column; min-width: 0; }
.profile-meta strong { font-size: 14px; }
.profile-meta em { font-style: normal; font-size: 12.5px; color: var(--text-3); }

/* ---------- modals ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--overlay);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 11vh 16px 16px;
  opacity: 0;
  transition: opacity 200ms var(--ease-out);
}
.overlay.center { align-items: center; padding: 16px; }
.overlay.open { opacity: 1; }

.sheet {
  width: 100%;
  background: var(--pop);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

/* Search opens with zero animation. It is keyboard initiated and used
   constantly, so instant is the correct feel. */
#searchModal { transition: none; opacity: 1; }
#searchModal .search-sheet { transform: none; transition: none; }
.search-sheet { max-width: 620px; }

/* A centered sheet is a flex item, and flex items refuse to shrink below
   their content by default. One wide child (a 100% width select, say)
   could push the whole sheet past the phone viewport, cut on both sides.
   Shrink is now allowed, and rows keep their wide children in check. */
.overlay.center > .sheet { min-width: 0; }
.setting-row select.text-input { width: auto; flex: 0 1 170px; min-width: 110px; }

/* Settings is rare, so it gets the standard modal entrance. */
.settings-sheet {
  max-width: min(520px, 100%);
  max-height: min(84dvh, 720px);
  display: flex;
  flex-direction: column;
  transform: scale(0.96);
  opacity: 0;
  transform-origin: center;
  transition: opacity 220ms var(--ease-out), transform 250ms var(--ease-out);
}
.overlay.open .settings-sheet { transform: scale(1); opacity: 1; }

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.search-bar .lucide, .search-bar i[data-lucide] { width: 18px; height: 18px; color: var(--text-3); }
.search-bar input { flex: 1; background: none; border: none; font-size: 15px; min-width: 0; }
.search-bar input::placeholder { color: var(--text-3); }
.search-bar kbd {
  font-family: inherit;
  font-size: 11.5px;
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
}

.search-results { max-height: 50dvh; overflow-y: auto; padding: 6px; }
.search-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  text-align: left;
  transition: background-color 120ms ease;
}
@media (hover: hover) { .search-row:hover, .search-row.hot { background: var(--hover); } }
.search-row .lucide, .search-row i[data-lucide] { width: 17px; height: 17px; color: var(--text-3); flex: none; }
.search-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.search-row-text strong { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-row-text em { font-style: normal; font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-empty { padding: 22px; text-align: center; color: var(--text-3); font-size: 14px; margin: 0; }

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 14px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.settings-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.settings-body { padding: 6px 20px 18px; overflow-y: auto; }
.settings-section { padding: 14px 0 4px; border-bottom: 1px solid var(--border-soft); }
.settings-section:last-of-type { border-bottom: none; }
.settings-section h3 { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--text-2); }

.seg {
  display: flex;
  gap: 4px;
  background: var(--hover);
  border: 1px solid var(--border-soft);
  border-radius: 13px;
  padding: 4px;
  margin-bottom: 12px;
}
.seg button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 4px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease, transform 160ms var(--ease-out);
}
@media (hover: hover) { .seg button:hover { color: var(--text); } }
.seg button:active { transform: scale(0.97); }
.seg button[aria-pressed="true"] { background: var(--seg-active); border-color: var(--border-soft); color: var(--text); }
.seg .lucide, .seg i[data-lucide] { width: 16px; height: 16px; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
}
.setting-text { display: flex; flex-direction: column; min-width: 0; }
.setting-text strong { font-size: 14px; font-weight: 500; }
.setting-text span { font-size: 12.5px; color: var(--text-3); }

.toggle {
  width: 45px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--hover);
  position: relative;
  flex: none;
  transition: background-color 180ms ease, border-color 180ms ease, transform 160ms var(--ease-out);
}
.toggle:active { transform: scale(0.95); }
.toggle .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform 180ms var(--ease-out), background-color 180ms ease;
}
.toggle[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.toggle[aria-checked="true"] .knob { transform: translateX(19px); background: var(--accent-fg); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 500;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  flex: none;
  transition: transform 160ms var(--ease-out), background-color 140ms ease;
}
@media (hover: hover) { .btn:hover { background: var(--hover); } }
.btn:active { transform: scale(0.96); }
.btn .lucide, .btn i[data-lucide] { width: 15px; height: 15px; }
.btn.danger { color: var(--danger); border-color: var(--danger); }

/* Hold to confirm: slow linear fill on press, snappy release. */
.hold { position: relative; overflow: hidden; }
.hold .fill {
  position: absolute;
  inset: 0;
  background: var(--danger-soft);
  clip-path: inset(0 100% 0 0);
  transition: clip-path 200ms var(--ease-out);
  pointer-events: none;
}
.hold.armed .fill { clip-path: inset(0 0 0 0); transition: clip-path 1.4s linear; }
.hold .lucide, .hold i[data-lucide], .hold span:not(.fill) { position: relative; z-index: 1; }

.version { font-size: 12.5px; color: var(--text-3); margin: 14px 0 4px; }

/* ---------- toasts ---------- */

#toasts {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--pop);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px 10px 14px;
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 220ms var(--ease-out), transform 240ms var(--ease-out);
  max-width: 100%;
}
.toast.in { opacity: 1; transform: translateY(0); }
.toast-msg { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-act {
  color: var(--link);
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 7px;
  flex: none;
  transition: background-color 140ms ease, transform 160ms var(--ease-out);
}
@media (hover: hover) { .toast-act:hover { background: var(--hover); } }
.toast-act:active { transform: scale(0.95); }

/* ---------- backdrop (mobile nav) ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms var(--ease-out);
}
@media (max-width: 768px) {
  body.nav-open .backdrop { opacity: 1; pointer-events: auto; }
}
@media (min-width: 769px) {
  .backdrop { display: none; }
  #openSidebarBtn { display: none; }
  body:not(.nav-open) #openSidebarBtn { display: inline-flex; }
}

/* ---------- responsive ---------- */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    z-index: 60;
    border-right: 1px solid var(--border);
    transform: translateX(-105%);
    clip-path: none;
    touch-action: pan-y;
    transition: transform 260ms var(--ease-drawer);
  }
  body.nav-open .sidebar { transform: none; }
  body:not(.nav-open) .sidebar { width: min(300px, 85vw); border-right-color: var(--border); clip-path: none; visibility: hidden; transition: transform 260ms var(--ease-drawer), visibility 0s linear 260ms; }
  .sidebar-inner { width: 100%; }
  body:not(.nav-open) .sidebar-inner { opacity: 1; transform: none; }

  .share-btn span { display: none; }
  .share-btn { padding: 8px; }
  .settings-tabs { overflow-x: auto; scrollbar-width: none; }
  .settings-tabs::-webkit-scrollbar { display: none; }
  .settings-tabs button { flex: none; }
  .settings-body { padding: 6px 14px 16px; }
  .bubble { max-width: 88%; }
  .overlay { padding: 8vh 12px 12px; }
  .overlay.center { padding: 12px; }

  /* Topbar on phones: the model label yields, the buttons keep their feet
     AND their spacing -- four icons jammed edge to edge read as one blob. */
  html, body { overflow-x: hidden; }
  .topbar { padding: 0 8px; gap: 8px; }
  .top-left { flex: 1 1 auto; min-width: 0; }
  .top-right { flex: none; gap: 6px; }
  .model-btn { min-width: 0; max-width: 100%; padding: 8px 6px 8px 8px; font-size: 16px; }
  /* Two classes beat the plain #modelName rule further down the file. */
  .model-btn #modelName { max-width: none; flex: 0 1 auto; min-width: 0; }
  .model-btn .health-dot, .model-btn .chev { flex: none; }
  .top-right .icon-btn { flex: none; }
}

/* ---------- scrollbars ---------- */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 999px; }
* { scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; }

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
  .chip { opacity: 1; transform: none; }
}
html.reduce-motion .chip { opacity: 1; transform: none; animation: none; }
html.reduce-motion .cursor { animation: none; }
html.reduce-motion .dots span { animation: none; opacity: 0.7; }

/* ---------- settings tabs ---------- */

.settings-tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-soft);
  flex: none;
}
.settings-tabs button {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  padding: 11px 10px 9px;
  margin-right: 8px;
  border-bottom: 2px solid transparent;
  transition: color 140ms ease, border-color 140ms ease;
}
@media (hover: hover) { .settings-tabs button:hover { color: var(--text); } }
.settings-tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }

.pane-note { font-size: 13px; line-height: 1.55; color: var(--text-2); margin: 12px 0 4px; }

/* ---------- provider list ---------- */

#providerList { padding-top: 14px; }

.provider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 11px 10px 11px 13px;
  margin-bottom: 8px;
  transition: border-color 140ms ease, background-color 140ms ease;
}
@media (hover: hover) { .provider-row:hover { border-color: var(--border); } }
.provider-row.is-active { border-color: var(--border); background: var(--hover); }

.icon-box {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--hover);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.icon-box .lucide, .icon-box i[data-lucide] { width: 18px; height: 18px; color: var(--text-2); }

.provider-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.provider-text strong { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.provider-text em { font-style: normal; font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.active-tag { font-size: 12.5px; font-weight: 600; color: var(--text); padding: 0 4px; flex: none; }

.pill-btn {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 15px;
  border: 1px solid var(--border);
  border-radius: 999px;
  flex: none;
  transition: transform 160ms var(--ease-out), background-color 140ms ease;
}
@media (hover: hover) { .pill-btn:hover { background: var(--hover); } }
.pill-btn:active { transform: scale(0.94); }

.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm .lucide, .icon-btn.sm i[data-lucide] { width: 16px; height: 16px; }

.btn.wide { width: 100%; justify-content: center; margin-top: 6px; padding: 10px 14px; }

/* ---------- provider editor ---------- */

.overlay.above { z-index: 100; }
.provider-sheet { max-width: 600px; }
.provider-head h2 { flex: 1; margin-left: 2px; }

.preset-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  transition: background-color 120ms ease, transform 160ms var(--ease-out);
}
@media (hover: hover) { .preset-row:hover { background: var(--hover); } }
.preset-row:active { transform: scale(0.99); }
.preset-row strong { display: block; font-size: 14px; font-weight: 600; }
.preset-row em { display: block; font-style: normal; font-size: 12.5px; color: var(--text-3); }

.field { margin-bottom: 14px; }
.flabel { display: block; font-size: 13px; font-weight: 600; margin: 0 0 6px; }
.flabel.gap { margin: 14px 0 8px; }

.text-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  transition: border-color 140ms ease;
}
.text-input::placeholder { color: var(--text-3); }
.text-input:focus { border-color: var(--border); }
.text-input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13.5px; }
textarea.text-input { resize: vertical; min-height: 76px; line-height: 1.55; }

.fhelp { font-size: 12.5px; color: var(--text-3); margin: 6px 0 0; line-height: 1.5; }

.key-wrap { position: relative; }
.key-wrap .text-input { padding-right: 42px; }
.key-toggle {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-3);
  transition: background-color 140ms ease, color 140ms ease;
}
@media (hover: hover) { .key-toggle:hover { background: var(--hover); color: var(--text); } }
.key-toggle .lucide, .key-toggle i[data-lucide] { width: 17px; height: 17px; }

.models-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 4px; }
.models-head .flabel { margin: 0; }

.status-line { font-size: 13px; line-height: 1.5; color: var(--text-2); margin: 8px 0; min-height: 20px; }
.status-line.error { color: var(--danger); }
.status-line .spin { display: inline-flex; vertical-align: -3px; margin-right: 7px; }
.spin .lucide, .spin i[data-lucide] { width: 15px; height: 15px; animation: rot 0.9s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

.slot { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.slot input[type="radio"] { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); cursor: pointer; }
.slot-num { font-size: 12px; color: var(--text-3); width: 12px; flex: none; text-align: center; }
.slot .text-input { flex: 1; min-width: 0; }

.advanced-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 10px 13px;
  margin: 16px 0 4px;
  transition: background-color 140ms ease, border-color 140ms ease;
}
@media (hover: hover) { .advanced-row:hover { background: var(--hover); border-color: var(--border); } }
.advanced-row > .lucide, .advanced-row > i[data-lucide] { width: 18px; height: 18px; color: var(--text-2); }
.advanced-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.advanced-text strong { font-size: 14px; font-weight: 600; }
.advanced-text em { font-style: normal; font-size: 12.5px; color: var(--text-3); }
.adv-chev { transition: transform 180ms var(--ease-out); }
.advanced-row[aria-expanded="true"] .adv-chev { transform: rotate(180deg); }

#pfAuthSeg button { font-size: 12.5px; }

.editor-foot { display: flex; gap: 8px; margin-top: 14px; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
@media (hover: hover) { .btn.primary:hover { background: var(--accent); opacity: 0.88; } }
.btn.grow { flex: 1; justify-content: center; padding: 10px 14px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:disabled:active { transform: none; }

/* ---------- model menu additions ---------- */

.model-group { font-size: 12px; font-weight: 600; color: var(--text-3); padding: 9px 10px 3px; margin: 0; }
#modelName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 44vw; }
#modelMenu { min-width: 250px; max-width: min(340px, calc(100vw - 24px)); }
.pop-model strong, .pop-model em { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- debug panel (edge tab, bottom sheet) ---------- */

.debug-tab {
  position: fixed;
  right: 0;
  top: 64px;
  z-index: 85; /* under the modals (90+); the open panel itself is 120 */
  width: 30px;
  padding: 10px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--pop);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 999px 0 0 999px;
  color: var(--text-3);
  transition: transform 160ms var(--ease-out), background-color 140ms ease, color 140ms ease;
}
@media (hover: hover) { .debug-tab:hover { color: var(--text); } }
.debug-tab:active { transform: scale(0.94); }
.debug-tab .lucide, .debug-tab i[data-lucide] { width: 14px; height: 14px; }
.debug-tab.bad { background: var(--text); border-color: var(--text); color: var(--bg); }
.debug-tab-count { font-size: 10px; font-weight: 700; line-height: 1; }

.debug-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 95;
  height: min(52dvh, 600px);
  background: var(--pop);
  border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  transform: translateY(103%);
  transition: transform 320ms var(--ease-drawer);
}
.debug-panel.open { transform: none; }
.debug-inner { max-width: 880px; margin: 0 auto; height: 100%; display: flex; flex-direction: column; padding: 0 16px; }
.debug-head { display: flex; align-items: center; gap: 8px; padding: 14px 4px 10px; }
.debug-head strong { font-size: 15px; font-weight: 600; }
.debug-count { font-size: 12px; color: var(--text-3); flex: 1; }
.debug-head-btns { display: flex; gap: 2px; }
.debug-seg { padding-bottom: 8px; }
.debug-seg .seg { margin-bottom: 0; }
.debug-list { flex: 1; overflow-y: auto; padding: 2px 2px 16px; }
.debug-empty { text-align: center; color: var(--text-3); font-size: 13px; padding: 26px 0; margin: 0; }
.debug-row { padding: 7px 10px; border-radius: 10px; margin-bottom: 3px; cursor: pointer; transition: background-color 120ms ease; }
@media (hover: hover) { .debug-row:hover { background: var(--hover); } }
.debug-row.bad { background: var(--hover); }
.debug-meta { display: flex; align-items: center; gap: 8px; }
.debug-clock { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10.5px; color: var(--text-3); }
.debug-where { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10.5px; font-weight: 700; color: var(--text-2); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.debug-row.bad .debug-where, .debug-row.warn .debug-where { color: var(--text); }
.debug-pill { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 9.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--text); color: var(--bg); }
.debug-row.warn .debug-pill { background: var(--press); color: var(--text); }
.debug-what { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px; line-height: 1.45; color: var(--text-2); overflow-wrap: break-word; margin-top: 3px; }
.debug-row.bad .debug-what { color: var(--text); font-weight: 600; }

/* ---------- model pick list (tap a row, it probes, it fills) ---------- */
#pickList { display: flex; flex-direction: column; gap: 6px; margin: 2px 0 6px; }
#pickList:empty { display: none; }
.pick-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 12px; background: var(--hover); border: 1px solid var(--border); border-radius: 12px; transition: transform 160ms var(--ease-out), background-color 140ms ease; }
@media (hover: hover) { .pick-row:hover { background: var(--press); } }
.pick-row:active { transform: scale(0.98); }
.pick-row .lucide, .pick-row i[data-lucide] { width: 15px; height: 15px; color: var(--text-3); flex: none; }
.pick-row span { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.pick-row strong { font-size: 12.5px; font-weight: 500; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-row em { font-style: normal; font-size: 11.5px; color: var(--text-3); }
.pick-row em:empty { display: none; }

/* Deep search composer toggle: pressed state. */
.icon-btn[aria-pressed="true"] {
  background: var(--seg-active);
  color: var(--text);
}

/* Input bars take focus without the ring; their border cue stays. */
input:focus-visible,
textarea:focus-visible {
  outline: none;
}

/* Dictation in progress. */
.icon-btn.recording {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- account menu ---------- */

#accountMenu { min-width: 250px; }
.acct-head { display: flex; gap: 10px; align-items: center; padding: 8px 10px 10px; }
.acct-head .avatar { width: 38px; height: 38px; font-size: 16px; flex: none; }
.acct-id { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.acct-name { background: none; border: none; font-weight: 600; font-size: 14.5px; padding: 0; min-width: 0; }
.acct-sub { font-size: 12px; color: var(--text-3); }
.acct-foot { font-size: 11.5px; color: var(--text-3); margin: 8px 10px 6px; }
.pop-item.armed { color: var(--danger); }

/* ---------- banners ---------- */

#banners { flex: none; display: flex; flex-direction: column; gap: 8px; padding: 10px 16px 0; max-width: 768px; margin: 0 auto; width: 100%; }
#banners[hidden] { display: none; }
.banner { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; border: 1px solid var(--border); background: var(--pop); }
.banner.warn { color: var(--text-2); }
.banner.danger { color: var(--danger); border-color: var(--danger); }
.banner .lucide, .banner i[data-lucide] { width: 16px; height: 16px; flex: none; }
.banner .btn { margin-left: auto; }

/* ---------- message states ---------- */

.msg-error { display: flex; gap: 12px; padding: 14px; border: 1px solid var(--danger); border-radius: 14px; color: var(--text-2); }
.msg-error .lucide, .msg-error i[data-lucide] { width: 18px; height: 18px; color: var(--danger); flex: none; margin-top: 2px; }
.msg-error-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg-error-text strong { color: var(--text); font-size: 14px; }
.msg-error-text p { margin: 0; font-size: 13.5px; }
.msg-error-text .btn { align-self: flex-start; margin-top: 6px; }
.btn.small { font-size: 12.5px; padding: 6px 12px; border-radius: 8px; }
.btn.small .lucide, .btn.small i[data-lucide] { width: 13px; height: 13px; }
.pager { display: inline-flex; align-items: center; color: var(--text-3); font-size: 12px; }
.pager > span { min-width: 30px; text-align: center; }
.msg-stats { margin-left: auto; align-self: center; font-size: 11.5px; color: var(--text-3); padding-right: 4px; white-space: nowrap; }

/* user row actions + editor */

.msg.user .msg-actions { justify-content: flex-end; margin: 6px 0 0; }
.edit-box { display: flex; flex-direction: column; gap: 8px; width: min(100%, 560px); }
.edit-box textarea { background: var(--composer); border: 1px solid var(--border); border-radius: 14px; padding: 10px 14px; resize: vertical; min-height: 70px; }
.edit-row { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- sources + citations + followups ---------- */

.sources { margin-top: 2px; }
.msg-actions .sources-head { display: inline-flex; align-items: center; gap: 6px; flex: none; width: auto; height: 32px; padding: 0 8px; border-radius: 8px; font-size: 12px; color: var(--text-2); white-space: nowrap; }
@media (hover: hover) { .msg-actions .sources-head:hover { background: var(--hover); color: var(--text); } }
.sources-head .lucide, .sources-head i[data-lucide] { width: 13px; height: 13px; transition: transform 180ms var(--ease-out); }
.sources-head.open .lucide, .sources-head.open i[data-lucide] { transform: rotate(180deg); }
.src-stack { display: inline-flex; align-items: center; }
.src-stack-img { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--bg); margin-left: -4px; background: var(--code); }
.src-stack-img:first-child { margin-left: 0; }
.sources-grid { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 300ms var(--ease-out), opacity 300ms var(--ease-out); }
.sources-grid.closed { grid-template-rows: 0fr; opacity: 0; }
.sources-clip { overflow: hidden; min-height: 0; }
.sources-list { list-style: none; margin: 6px 0 0; padding: 4px; display: flex; flex-direction: column; gap: 2px; background: var(--code); border: 1px solid var(--border-soft); border-radius: 10px; font-size: 12px; }
.sources-list li { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; transition: background-color 150ms ease; }
@media (hover: hover) { .sources-list li:hover { background: var(--hover); } }
.sources-list li.flash, .trace-row.flash { background: var(--hover); }
.sources-list a { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; color: var(--text-2); text-decoration: none; }
@media (hover: hover) { .sources-list a:hover { color: var(--text); } }
@media (hover: hover) { .sources-list a:hover .src-title { text-decoration: underline; } }
.src-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sources-list .src-fav { width: 16px; height: 16px; margin: 0; vertical-align: 0; flex: none; }
.src-host { margin-left: auto; flex: none; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 10.5px; color: var(--text-3); }
.src-hide { display: inline-flex; padding: 4px; border-radius: 6px; color: var(--text-3); flex: none; }
@media (hover: hover) { .src-hide:hover { background: var(--hover); color: var(--text); } }
.src-hide .lucide, .src-hide i[data-lucide] { width: 13px; height: 13px; }

.followups { display: flex; flex-direction: column; margin-top: 10px; }
.followups-head { font-size: 12px; font-weight: 500; color: var(--text-2); margin: 0 0 2px; }
.followup { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; font-size: 12.5px; color: var(--text); border-bottom: 1px solid var(--border-soft); border-radius: 7px; padding: 7px 6px; animation: fade-up 350ms cubic-bezier(0.23, 1, 0.32, 1) both; animation-delay: var(--d, 0ms); }
@media (hover: hover) { .followup:hover { background: var(--hover); } }
.followup .lucide, .followup i[data-lucide] { width: 11px; height: 11px; color: var(--text-3); flex: none; }

/* ---------- feel: toasts, jump pill, palette ---------- */

.toast .lucide, .toast i[data-lucide] { width: 16px; height: 16px; flex: none; }
.toast.error .lucide, .toast.error i[data-lucide] { color: var(--danger); }
.toast { touch-action: pan-y; }
.jump-pill { position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(8px); opacity: 0; z-index: 40; display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-2); background: var(--pop); border: 1px solid var(--border); border-radius: 999px; padding: 7px 14px; transition: transform 160ms var(--ease-out), opacity 180ms var(--ease-out); }
.jump-pill.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.jump-pill:active { transform: translateX(-50%) scale(0.95); }
.jump-pill .lucide, .jump-pill i[data-lucide] { width: 14px; height: 14px; }
.jump-pill[hidden] { display: none; }
.composer-dock { position: relative; }
#palette { transition: none; opacity: 1; }
#palette .palette-sheet { transform: none; transition: none; max-width: 560px; }
#paletteResults { padding: 6px; }
.palette-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 12px; border-radius: 10px; font-size: 14px; }
.palette-row.hot { background: var(--hover); }
.palette-row .lucide, .palette-row i[data-lucide] { width: 16px; height: 16px; color: var(--text-3); flex: none; }
.palette-row .ph { margin-left: auto; font-size: 12px; color: var(--text-3); flex: none; }
.palette-sec { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); padding: 10px 12px 4px; margin: 0; }

/* reduced motion: fades stay, movement goes */

html.reduce-motion .sidebar,
html.reduce-motion .sidebar-inner,
html.reduce-motion .pop,
html.reduce-motion .overlay,
html.reduce-motion .sheet,
html.reduce-motion .toast,
html.reduce-motion .msg,
html.reduce-motion .msg-actions button,
html.reduce-motion .jump-pill,
html.reduce-motion .followup,
html.reduce-motion .trace-row,
html.reduce-motion .trace-body,
html.reduce-motion .sources-grid,
html.reduce-motion .plan-row,
html.reduce-motion .sources-head .lucide,
html.reduce-motion .chip { transition: none; }

/* ---------- input/output: composer, attachments, thoughts ---------- */

.tok-est { font-size: 11.5px; color: var(--text-3); margin-left: 4px; white-space: nowrap; }
.tok-est.large { color: var(--danger); font-weight: 600; }
.composer.dragover { border-color: var(--link); }
.attach-preview { display: flex; gap: 8px; padding: 0 4px 8px; }
.attach-preview[hidden] { display: none; }
.att-chip { position: relative; flex: none; }
.att-chip img { width: 56px; height: 56px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); display: block; }
.att-x { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%; background: var(--pop); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; }
.att-x .lucide, .att-x i[data-lucide] { width: 13px; height: 13px; }
.bubble-imgs { display: flex; gap: 8px; margin-bottom: 8px; }
.bubble-imgs img { width: 72px; height: 72px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }
.msg-actions button.on { color: var(--link); }
.think { margin: 0 0 10px; border: 1px solid var(--border-soft); border-radius: 12px; }
.think-head { display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; font-size: 13px; font-weight: 600; color: var(--text-3); padding: 8px 12px; border-radius: 12px; }
@media (hover: hover) { .think-head:hover { color: var(--text); } }
.think-head .lucide, .think-head i[data-lucide] { width: 15px; height: 15px; transition: transform 180ms var(--ease-out); }
.think-head.open .lucide, .think-head.open i[data-lucide] { transform: rotate(180deg); }
.think-body { padding: 2px 14px 12px; font-size: 13.5px; color: var(--text-2); }
.think-body[hidden] { display: none; }
html.reduce-motion .think-head .lucide, html.reduce-motion .think-head i[data-lucide] { transition: none; }

/* ---------- organize, presence, install ---------- */

.health-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.health-dot[hidden] { display: none; }
.health-dot.ok { background: var(--ok); }
.health-dot.bad { background: var(--danger); }
.toast.warn .lucide, .toast.warn i[data-lucide] { color: var(--warn); }
.folder { margin: 2px 0 6px; }
.folder-head { display: flex; align-items: center; gap: 2px; }
.folder-toggle { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; font-weight: 600; color: var(--text-2); padding: 6px 8px; border-radius: 8px; text-align: left; }
@media (hover: hover) { .folder-toggle:hover { background: var(--hover); } }
.folder-toggle .lucide, .folder-toggle i[data-lucide] { width: 15px; height: 15px; color: var(--text-3); flex: none; transition: transform 180ms var(--ease-out); }
.folder.closed .folder-toggle .lucide, .folder.closed .folder-toggle i[data-lucide] { transform: rotate(-90deg); }
.folder-toggle span:not(.folder-count) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count { margin-left: auto; font-size: 11.5px; font-weight: 400; color: var(--text-3); flex: none; }
.folder-mini { flex: none; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: 8px; color: var(--text-3); }
@media (hover: hover) { .folder-mini:hover { background: var(--hover); color: var(--text); } }
@media (hover: hover) { .folder-mini.danger:hover { color: var(--danger); } }
.folder-mini .lucide, .folder-mini i[data-lucide] { width: 14px; height: 14px; }
.folder-body { padding-left: 6px; }
.folder.closed .folder-body { display: none; }
.folder .rename-input { flex: 1; min-width: 0; margin: 2px 4px; }
html.reduce-motion .folder-toggle .lucide, html.reduce-motion .folder-toggle i[data-lucide] { transition: none; }

@media (max-width: 768px) {
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .sidebar-inner { padding-bottom: env(safe-area-inset-bottom); }
}

/* sources footer favicons */

.src-fav { width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 7px; }

/* streaming-text primitives */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes act-in { from { opacity: 0; } to { opacity: 1; } }
.cite-chip { display: inline-flex; align-items: center; gap: 4px; vertical-align: -1px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 10.5px; color: var(--text-2); background: var(--code); border: 1px solid var(--border-soft); border-radius: 5px; padding: 1px 4px; margin: 0 1px; }
@media (hover: hover) { .cite-chip:hover { background: var(--hover); color: var(--text); } }
.cite-fav { width: 12px; height: 12px; border-radius: 3px; }
html.reduce-motion .followup, html.reduce-motion .msg-actions.fresh { animation: none; }

.msg-actions .pager { flex: none; }

/* ---------- polish batch: glide, cite cards, credit, regen ---------- */

.chat-groups { position: relative; }

.row-glide {
  position: absolute;
  left: 6px;
  top: 0;
  width: 3px;
  height: 24px;
  border-radius: 2px;
  background: var(--text-2);
  opacity: 0.55;
  pointer-events: none;
}

html.reduce-motion .row-glide { display: none; }

.cite-card {
  position: fixed;
  z-index: 120;
  max-width: 260px;
  background: var(--pop);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

.cite-card strong {
  display: block;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cite-card span {
  display: block;
  margin-top: 2px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cite-card em { display: block; margin-top: 4px; font-style: normal; font-size: 11px; color: var(--text-3); }

.side-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px 2px;
}

.side-credit { font-size: 11.5px; color: var(--text-3); white-space: nowrap; }

#feedbackType { margin: 0 0 14px; }

.msg.regen-out .msg-body,
.msg.regen-out .msg-actions,
.msg.regen-out .sources,
.msg.regen-out .agent-trace {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 160ms ease, transform 160ms var(--ease-out);
}

.greeting { animation: greet-in 380ms var(--ease-out) both; }

@keyframes greet-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

html.reduce-motion .greeting { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .greeting { animation: none; }
  .msg.regen-out .msg-body,
  .msg.regen-out .msg-actions,
  .msg.regen-out .sources,
  .msg.regen-out .agent-trace { transition: none; }
}

/* ---------- agent actions (companion extension) ---------- */

#actionsBtn { position: relative; }

.ext-dot {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  pointer-events: none;
}

.ext-dot.lg { position: static; flex: none; width: 10px; height: 10px; }

.ext-dot.off { background: var(--text-3); }

.ext-status { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

.ext-status-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.ext-status-text span { font-size: 12px; color: var(--text-3); }

.ext-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

.ext-row .text-input { flex: 1; min-width: 0; }

details.snap { margin: 0 0 12px; border: 1px solid var(--border-soft); border-radius: 10px; padding: 8px 10px; }

details.snap summary { cursor: pointer; font-size: 13px; color: var(--text-2); }

details.snap pre { margin: 8px 0 2px; max-height: 180px; overflow: auto; font-size: 12px; white-space: pre-wrap; color: var(--text-2); }

.thread-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  border-radius: 7px;
  padding: 7px 6px;
  margin-bottom: 6px;
  font-size: 12.5px;
}

@media (hover: hover) { .thread-row:hover { background: var(--hover); } }

.thread-row.chosen { background: var(--hover); outline: 1px solid var(--border); }

.thread-row strong { font-weight: 600; }

.thread-row span { color: var(--text-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.action-log { display: flex; flex-direction: column; margin-top: 4px; font-size: 12px; color: var(--text-3); }

.action-log .al { border-top: 1px solid var(--border-soft); padding: 6px 0; color: var(--text-2); }

.action-log .al strong { color: var(--text); font-weight: 600; }

#extSendBtn.armed { background: var(--warn); border-color: transparent; color: #141414; }

#extDraftBtn { margin-bottom: 12px; }

.paste-mode { border-top: 1px solid var(--border-soft); margin-top: 14px; padding-top: 12px; }
.paste-title { font-size: 14px; margin: 0 0 8px; }
#extPasteDraft, #extPasteCopy { margin-bottom: 12px; }


/* ---------- feature kit: meter, slash, library, usage, relay, memory ---------- */

.ctx-meter {
  height: 3px;
  border-radius: 2px;
  background: var(--border-soft);
  margin: 0 16px 6px;
  overflow: hidden;
}
.ctx-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--text-3);
  transition: width var(--dur-2) var(--ease-out);
}
.ctx-meter.warn .ctx-fill { background: var(--warn); }
.ctx-meter.danger .ctx-fill { background: var(--danger); }

.slash-pop {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(100% + 8px);
  max-height: 280px;
  overflow: auto;
}
.composer-block { position: relative; }
.slash-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}
@media (hover: hover) { .slash-row:hover, .slash-row.hot { background: var(--hover); } }
.slash-row strong { display: block; font-size: 13px; font-weight: 600; }
.slash-row em { display: block; font-style: normal; font-size: 12px; color: var(--text-3); }

.mem-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-soft);
}
.mem-row span { flex: 1; font-size: 13px; }
.mem-add { display: flex; gap: 8px; margin-top: 10px; }
.mem-add .text-input { flex: 1; }

.lib-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}
.lib-text { flex: 1; min-width: 0; }
.lib-text strong { display: block; font-size: 13px; }
.lib-text em { display: block; font-style: normal; font-size: 12px; color: var(--text-3); }
.lib-form { display: grid; gap: 8px; margin-top: 12px; }

table.usage {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.usage th, table.usage td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border-soft);
}
table.usage th { color: var(--text-3); font-weight: 500; font-size: 12px; }
table.usage tfoot td { font-weight: 600; border-bottom: 0; }

.relay-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  margin-bottom: 12px;
}
.relay-text { flex: 1; min-width: 0; }
.relay-title { display: block; font-size: 13px; }
.relay-sub { display: block; font-style: normal; font-size: 11px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relay-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.relay-dot.ok { background: var(--ok); }
.relay-dot.bad { background: var(--danger); }
.relay-dot.off { background: var(--text-3); }
.relay-dot.busy { background: var(--warn); }

.pager-model { font-size: 11px; color: var(--text-3); }

.kbd-list { display: grid; gap: 6px; }
.kbd-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 13px;
  padding: 4px 0;
}
.kbd-row kbd {
  font-family: inherit;
  font-size: 11px;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
  margin-left: 4px;
}

.price-row { display: flex; flex-wrap: wrap; gap: 10px; }
.price-row .field { flex: 1 1 150px; }
select.sel { appearance: auto; }


/* Touch: no hover affordances to stick -- :active carries feedback. */
@media (hover: none) {
  .chat-row .row-menu { opacity: 1; }
  .search-row.hot { background: var(--hover); }
}

/* --- code tokens ------------------------------------------------------- */
.codeblock code .tok-kw { color: var(--tok-kw); }
.codeblock code .tok-str { color: var(--tok-str); }
.codeblock code .tok-num { color: var(--tok-num); }
.codeblock code .tok-fn { color: var(--tok-fn); }
.codeblock code .tok-com { color: var(--tok-com); font-style: italic; }

/* --- image gallery ------------------------------------------------------ */
.img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
  margin: 12px 0 6px;
}
.img-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: none;
  border-radius: 12px;
  overflow: hidden;
  background: var(--press);
  cursor: zoom-in;
  /* entry: fade + settle, staggered by inline delay; transform/opacity only */
  animation: img-in 300ms var(--ease-out) backwards;
  transition: transform 160ms var(--ease-out);
}
.img-tile:active { transform: scale(0.97); }
.img-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 220ms ease, transform 220ms var(--ease-out);
}
.img-tile img.loaded { opacity: 1; }
@media (hover: hover) and (pointer: fine) {
  .img-tile:hover img { transform: scale(1.03); }
}
@keyframes img-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
}
html.reduce-motion .img-tile { animation: none; }
html.reduce-motion .img-tile img { transition: opacity 150ms ease; }

/* --- image lightbox (a modal: centered origin is correct here) ---------- */
.imgbox {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 140ms ease; /* exit is faster than enter */
}
.imgbox.open {
  opacity: 1;
  transition: opacity 200ms var(--ease-out);
}
.imgbox-fig {
  margin: 0;
  max-width: min(92vw, 860px);
  transform: scale(0.95);
  transition: transform 140ms ease;
}
.imgbox.open .imgbox-fig {
  transform: scale(1);
  transition: transform 200ms var(--ease-out);
}
.imgbox-fig img {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  background: var(--press);
}
.imgbox-cap {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-2);
}
.imgbox-cap span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imgbox-cap a { color: var(--link); flex: none; }
.imgbox-x {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
}
html.reduce-motion .imgbox-fig { transform: none; transition: none; }
