/* Hallmark · v2.0.0 · theme: workbench (custom, by request: похож на opencode) · genre: modern-minimal
   critique: editor-like dark workspace; amber signal, mono accents, square-ish surfaces, no gradients, no emoji.
   waive: 47b — session status is a functional signal, rendered as a small CSS dot with a text label.
   waive: 24b — editor-density spacing deliberately uses 1px increments in code and tool chrome.
   waive: 3 — the accent side stripe marks actionable permission and toast alerts, not decoration.
*/
/* Hallmark · waive 24b · opencode editor-density uses 1px increments for tool chrome · compact code readability at 15px body size */
/* Hallmark · waive 39b · opencode app controls keep 36 to 44px; the flagged 22px is a native radio inside a 32px option row · the label is the hit target */
/* Hallmark · waive 72 · session rows and tabs clip long titles with ellipsis · opencode session rows use 8px padding and verified browser renders */
/* Hallmark · dismissed 3 · permission and toast side stripes carry alert state alongside readable text · checked in desktop and mobile renders */
/* Hallmark · dismissed F24 · command menu floats over the composer and needs elevation · border plus shadow defines the popover edge */

:root {
  --font-sans: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", "Cascadia Code", Consolas, "Liberation Mono", monospace;

  --bg: #0b0d0c;
  --bg-elev: #111513;
  --bg-panel: #151a18;
  --bg-hover: #1b211e;
  --bg-active: #202822;
  --border: #26302b;
  --border-strong: #3a463f;
  --field-border: #617066;
  --text: #e7eee9;
  --text-dim: #9aa79f;
  --text-faint: #829087;
  --accent: #e8b45f;
  --accent-strong: #f4cb82;
  --accent-ink: #1b1305;
  --accent-soft: rgba(232, 180, 95, 0.13);
  --ok: #73cf9a;
  --ok-soft: rgba(115, 207, 154, 0.14);
  --warn: #e6c35f;
  --warn-soft: rgba(230, 195, 95, 0.14);
  --danger: #e78383;
  --danger-soft: rgba(231, 131, 131, 0.13);
  --info: #83b6e8;
  --info-soft: rgba(131, 182, 232, 0.13);
  --user-bg: #18211c;
  --qr-bg: #f8f6f1;
  --instance-1: #e8b45f;
  --instance-2: #79c9b2;
  --instance-3: #83b6e8;
  --instance-4: #b9a7ea;
  --instance-5: #e79ab8;
  --instance-6: #a6d18a;
  --instance-7: #e8a06a;
  --instance-8: #79cfd8;
  --instance-9: #c9c27a;
  --instance-10: #d29ae0;
  --instance-11: #9fb8f0;
  --instance-12: #8fd6c2;
  --instance-13: #efb08a;
  --instance-14: #c3b2f0;
  --instance-15: #8fd0e0;
  --instance-16: #e8a6c4;
  --code-bg: #090b0a;
  --code-border: #26302a;
  --backdrop: rgba(3, 5, 4, 0.72);
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.03);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.34);
  --shadow-lg: 0 24px 80px rgba(0, 0, 0, 0.5);
  --scroll-thumb: #344039;
  --scroll-thumb-hover: #46554c;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --topbar-h: 54px;
  --tabbar-h: 46px;
  --sidebar-w: 308px;
  --measure: 920px;
  --gap: 20px;
}

html[data-theme="light"] {
  --bg: #f3f0e8;
  --bg-elev: #faf8f2;
  --bg-panel: #fffdf8;
  --bg-hover: #ece8dd;
  --bg-active: #e5e0d3;
  --border: #d8d3c6;
  --border-strong: #bdb6a6;
  --field-border: #8b8374;
  --text: #1d221e;
  --text-dim: #59645c;
  --text-faint: #59655e;
  --accent: #9a5f0a;
  --accent-strong: #7c4a06;
  --accent-ink: #fff9ee;
  --accent-soft: rgba(154, 95, 10, 0.1);
  --ok: #1f7a4d;
  --ok-soft: rgba(31, 122, 77, 0.1);
  --warn: #866300;
  --warn-soft: rgba(134, 99, 0, 0.1);
  --danger: #a83232;
  --danger-soft: rgba(168, 50, 50, 0.09);
  --info: #1f5f9a;
  --info-soft: rgba(31, 95, 154, 0.09);
  --user-bg: #ece7da;
  --code-bg: #f1ede3;
  --code-border: #ddd7c9;
  --backdrop: rgba(35, 31, 24, 0.45);
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.65);
  --shadow-md: 0 10px 26px rgba(70, 60, 38, 0.12);
  --shadow-lg: 0 24px 70px rgba(70, 60, 38, 0.2);
  --scroll-thumb: #c7c0af;
  --scroll-thumb-hover: #ada592;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow-x: clip;
  background: var(--bg);
}

body {
  height: 100%;
  overflow-x: clip;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] {
  display: none !important;
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

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

button {
  cursor: pointer;
}

a {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.focus-ring {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border: 3px solid transparent;
  border-radius: 10px;
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
  background-clip: content-box;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

[data-icon] {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  flex: none;
}

[data-icon] svg {
  width: 18px;
  height: 18px;
  display: block;
}

.icon-svg {
  width: 18px;
  height: 18px;
  display: block;
  flex: none;
}

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

/* ---- shared controls ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:active:not(:disabled),
.icon-btn:active,
.chip:active,
.session-item:active,
.tab:active,
.option:active,
.modal-row:active,
.dir-row:active,
.command-item:active,
.send-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-dim);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.icon-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 280px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
}

.chip:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.chip span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip .chip-model {
  color: var(--text);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}

.status-busy {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 1.4s ease-in-out infinite;
}

.status-retry {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 1.4s ease-in-out infinite;
}

.status-question {
  background: var(--info);
  box-shadow: 0 0 0 3px var(--info-soft);
}

.status-permission {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.status-idle {
  background: var(--ok);
}

.status-dot.is-unread {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 85%, transparent);
}

.status-offline {
  background: var(--text-faint);
}

.status-error {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---- login ---- */

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 12%, var(--accent-soft), transparent 42%),
    radial-gradient(circle at 86% 88%, var(--info-soft), transparent 40%),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand-lg {
  font-size: 19px;
  margin-bottom: 28px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -0.04em;
  transform: translateY(4px);
}

.brand-sub {
  color: var(--text-faint);
  font-weight: 400;
}

.login-card h1 {
  margin: 0 0 10px;
  font-size: 25px;
  line-height: 1.2;
  letter-spacing: -0.03em;
  font-weight: 650;
  text-wrap: balance;
}

.login-copy {
  margin: 0 0 24px;
  color: var(--text-dim);
  font-size: 14px;
}

.login-copy code {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
}

.login-form input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  outline: none;
}

.login-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.login-form .btn {
  margin-top: 4px;
  min-height: 44px;
}

.form-error {
  margin: 2px 0 0;
  padding: 9px 11px;
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

.login-foot {
  margin: 22px 0 0;
  color: var(--text-faint);
  font-size: 12px;
}

/* ---- app shell ---- */

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  min-width: 0;
  z-index: 20;
}

.topbar-menu {
  display: none;
}

.topbar .brand {
  margin-right: 4px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.menu-anchor {
  position: relative;
}

.menu-caret {
  width: 12px !important;
  height: 12px !important;
  opacity: 0.8;
  margin-left: 2px;
}

.menu-caret svg {
  width: 12px;
  height: 12px;
}

.topbar-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  padding: 5px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  box-shadow: var(--shadow-lg);
  z-index: 40;
}

.topbar-popover button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  text-align: left;
  font-size: 13px;
}

.topbar-popover button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.topbar-popover button [data-icon] {
  color: var(--text-faint);
}

.tabs-popover {
  width: 420px;
  max-width: 100%;
  max-height: min(62vh, 500px);
  overflow-y: auto;
}

.tabs-menu-head {
  padding: 6px 10px 8px;
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
}

.tabs-menu-item .tabs-menu-host {
  flex: none;
  padding: 1px 5px;
  border: 1px solid color-mix(in srgb, var(--instance-color, var(--border)) 55%, var(--border));
  border-radius: 4px;
  color: var(--instance-color, var(--text-dim));
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
}

.tabs-menu-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.tabs-menu-row .tabs-menu-item {
  flex: 1;
  min-width: 0;
}

.topbar-popover .tabs-menu-edit {
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius-sm);
  color: var(--text-faint);
}

.topbar-popover .tabs-menu-edit:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.tabs-menu-item .tabs-menu-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs-menu-item.is-active {
  background: var(--bg-active);
  color: var(--text);
}

.tabs-menu-empty {
  padding: 10px;
  color: var(--text-faint);
  font-size: 12px;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 0;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11.5px;
  white-space: nowrap;
}

.connection #connection-text {
  display: none;
}

.connection-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}

.connection.is-online {
  color: var(--ok);
  border-color: var(--ok);
}

.connection.is-online .connection-dot {
  background: var(--ok);
}

.connection.is-reconnecting {
  color: var(--warn);
  border-color: var(--warn);
}

.connection.is-reconnecting .connection-dot {
  background: var(--warn);
  animation: pulse 1.2s ease-in-out infinite;
}

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

.sidebar {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-close {
  display: none;
}

.sidebar-collapse {
  display: inline-flex;
}

.sidebar-rail {
  display: none;
}

.app.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.app.sidebar-collapsed .sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  max-width: 90vw;
  transform: translateX(-100%);
  transition: transform 0.18s ease;
  z-index: 35;
  box-shadow: var(--shadow-lg);
}

.app.sidebar-collapsed .sidebar.peek,
.app.sidebar-collapsed .sidebar.sidebar-peek {
  transform: translateX(0);
}

.app.sidebar-collapsed .sidebar-rail {
  position: fixed;
  top: calc(50% - 32px);
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 64px;
  padding: 0;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  background: var(--bg-elev);
  color: var(--text-faint);
  z-index: 36;
  cursor: pointer;
}

.app.sidebar-collapsed .sidebar-rail::before {
  content: "";
  position: fixed;
  left: 0;
  top: var(--topbar-h);
  bottom: 0;
  width: 8px;
}

.app.sidebar-collapsed .sidebar-rail:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.app.sidebar-collapsed .sidebar-rail [data-icon] {
  width: 12px;
  height: 12px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  color: var(--text-dim);
}

.search:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 13px;
}

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 10px 20px;
}

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.instance-group {
  margin-bottom: 16px;
}

.instance-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12px;
}

.instance-head:hover {
  background: var(--bg-hover);
}

.instance-head .status-dot {
  margin-top: 5px;
}

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

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

.instance-dir {
  display: block;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.instance-count {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  padding-top: 2px;
}

.host-group {
  margin-bottom: 2px;
}

.host-head,
.dir-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-dim);
  text-align: left;
}

.host-head:hover,
.dir-head:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.host-head {
  margin-top: 2px;
}

.tree-chevron {
  display: inline-flex;
  width: 14px;
  height: 14px;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  flex: none;
  transition: transform 0.15s ease;
}

.tree-chevron svg {
  width: 12px;
  height: 12px;
}

.host-head.is-open .tree-chevron,
.dir-head.is-open .tree-chevron {
  transform: rotate(90deg);
}

.host-main,
.dir-main {
  min-width: 0;
  flex: 1;
}

.host-name {
  display: block;
  color: var(--instance-color, var(--text));
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.host-sub {
  display: block;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.host-dirs {
  margin-left: 15px;
  padding-left: 6px;
  border-left: 1px solid var(--border);
}

.dir-group {
  margin: 1px 0;
}

.dir-icon {
  display: inline-flex;
  width: 17px;
  height: 17px;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  flex: none;
}

.dir-icon svg {
  width: 15px;
  height: 15px;
}

.dir-name {
  display: block;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dir-path {
  display: block;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dir-count {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  flex: none;
}

.dir-sessions {
  padding-left: 19px;
  padding-bottom: 3px;
}

.session-item {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  width: 100%;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-dim);
  text-align: left;
}

.session-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.session-item.is-active {
  background: var(--bg-active);
  border-color: var(--border-strong);
  color: var(--text);
}

.session-item.is-tab {
  box-shadow: inset 2px 0 0 var(--instance-color, transparent);
}

.session-item .status-dot {
  margin-top: 5px;
}

.session-main {
  min-width: 0;
}

.session-title {
  display: block;
  color: color-mix(in srgb, var(--instance-color, var(--text-dim)) 55%, var(--text));
  font-size: 13px;
  font-weight: 550;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item.is-offline .session-title,
.session-item.is-offline .session-sub {
  opacity: 0.55;
}

.session-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-badge {
  align-self: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: var(--accent-ink);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.session-empty,
.instance-empty {
  padding: 10px;
  color: var(--text-faint);
  font-size: 12.5px;
}

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

.main {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.tabbar {
  display: flex;
  align-items: stretch;
  min-height: var(--tabbar-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  min-width: 0;
}

.tabs {
  display: flex;
  align-items: stretch;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 250px;
  min-width: 120px;
  padding: 0 10px 0 12px;
  border: 0;
  border-right: 1px solid var(--border);
  background-color: transparent;
  background-image: linear-gradient(
    to left,
    color-mix(in srgb, var(--instance-color, transparent) 32%, transparent),
    transparent
  );
  background-size: 57px 100%;
  background-position: right center;
  background-repeat: no-repeat;
  color: var(--text-dim);
  font-size: 12.5px;
  white-space: nowrap;
}

.tab:hover {
  background-color: var(--bg-hover);
  color: var(--text);
}

.tab.is-active {
  background-color: var(--bg);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.tab .status-dot,
.tabs-menu-item .status-dot {
  width: 6px;
  height: 12px;
  border-radius: 2px;
  box-shadow: none;
}

/* Keep the unread ring visible on the narrow cursor-shaped tab indicator. */
.tab .status-dot.is-unread,
.tabs-menu-item .status-dot.is-unread {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 85%, transparent);
}

.tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
  text-align: left;
}

.tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-faint);
  flex: none;
}

.tab-close:hover {
  background: var(--bg-active);
  color: var(--text);
}

.tab-close svg {
  width: 13px;
  height: 13px;
}

.tab-new {
  flex: none;
  align-self: center;
  margin: 0 4px;
}

.tab-attention {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
  flex: none;
}

/* ---- workspace / empty ---- */

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 24px;
  text-align: center;
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.empty h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.15;
  letter-spacing: -0.035em;
  font-weight: 650;
  max-width: 560px;
  text-wrap: balance;
}

.empty p {
  margin: 0;
  max-width: 500px;
  color: var(--text-dim);
  font-size: 14px;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}

/* ---- session ---- */

.session {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.session-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.session-head-main {
  min-width: 0;
  flex: 1;
}

.session-head-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow-wrap: break-word;
  text-wrap: balance;
}

.session-head-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px 12px;
  margin-top: 4px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.session-head-meta span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.session-head-meta .path {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-head-title .session-head-host {
  color: var(--instance-color, var(--text-dim));
  display: inline-flex;
  align-items: center;
  max-width: 180px;
  margin-right: 7px;
  padding: 1px 6px;
  border: 1px solid color-mix(in srgb, var(--instance-color, var(--border)) 55%, var(--border));
  border-radius: 5px;
  background: var(--bg-panel);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.35;
  vertical-align: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-head-meta .session-model {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field input {
  flex: 1;
  padding-right: 38px;
}

.password-reveal {
  position: absolute;
  right: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
}

.password-reveal:hover,
.password-reveal.is-visible {
  background: var(--bg-hover);
  color: var(--text);
}

.password-reveal [data-icon] {
  width: 16px;
  height: 16px;
}

.settings-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 8px;
}

.settings-section h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
}

.settings-form {
  display: grid;
  gap: 8px;
}

.settings-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: 11.5px;
}

.settings-inline input {
  width: 90px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text);
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.session-list {
  display: grid;
  gap: 4px;
}

.session-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 11px;
}

.session-line.is-current {
  background: var(--bg-panel);
  color: var(--text);
}

.settings-details {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.settings-details summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 11.5px;
}

.settings-details .settings-form {
  margin-top: 8px;
}

.totp-setup {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
}

.totp-qr {
  width: 180px;
  height: 180px;
  background: var(--qr-bg);
  border-radius: var(--radius-sm);
}

.totp-secret {
  overflow-wrap: anywhere;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
}

.info-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.info-section-title {
  margin: 6px 0 5px;
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
}

.info-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}

.info-tag {
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 11px;
}

.info-tag.mcp-connected {
  border-color: color-mix(in srgb, var(--ok) 55%, var(--border));
  color: var(--ok);
}

.info-tag.mcp-failed,
.info-tag.mcp-needs_auth {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
  color: var(--danger);
}

.info-tag.mcp-pending,
.info-tag.mcp-disabled {
  border-color: color-mix(in srgb, var(--warn) 55%, var(--border));
  color: var(--warn);
}

.info-tag.is-auto {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  color: var(--accent);
}

.info-empty {
  color: var(--text-faint);
  font-size: 11.5px;
}

.file-path {
  padding: 4px 8px 8px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  text-align: left;
  font-size: 12.5px;
}

.file-row:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.file-icon {
  display: inline-flex;
  width: 18px;
  justify-content: center;
  color: var(--file-color, var(--text-faint));
}

.file-row.is-dir .file-name {
  color: var(--file-color, var(--text-dim));
}

.file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  flex: none;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.file-preview-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.file-preview-image {
  display: block;
  max-width: 100%;
  max-height: 55vh;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.file-preview-text {
  max-height: 45vh;
  margin: 8px 0 0;
  padding: 10px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--code-bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11.5px;
  white-space: pre-wrap;
}

.session-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.message-scroll {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.messages {
  width: min(100%, var(--measure));
  margin: 0 auto;
  padding: 26px clamp(14px, 3vw, 28px) 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.message {
  min-width: 0;
}

.message-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.message-role {
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.message-time {
  color: var(--text-faint);
}

.message-user {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--user-bg);
}

.message-user .message-body {
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-assistant .message-body,
.message-system .message-body {
  min-width: 0;
}

.message-system {
  padding: 9px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-faint);
  font-size: 12.5px;
}

.message-system .message-body {
  color: var(--text-dim);
}

.message-error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

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

.message-pending {
  opacity: 0.65;
}

.message-streaming .message-role::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 12px;
  margin-left: 5px;
  background: var(--accent);
  vertical-align: -1px;
  animation: pulse 1.1s steps(2, start) infinite;
}

.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.message-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.message-action:hover {
  border-color: var(--border);
  background: var(--bg-hover);
  color: var(--text);
}

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

.md {
  overflow-wrap: anywhere;
}

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

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

.md p {
  margin: 0 0 10px;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  margin: 16px 0 8px;
  line-height: 1.25;
  letter-spacing: -0.02em;
  font-weight: 650;
}

.md h1 {
  font-size: 20px;
}

.md h2 {
  font-size: 18px;
}

.md h3 {
  font-size: 16px;
}

.md h4 {
  font-size: 14px;
}

.md ul,
.md ol {
  margin: 0 0 10px;
  padding-left: 22px;
}

.md li {
  margin: 3px 0;
}

.md blockquote {
  margin: 10px 0;
  padding: 6px 12px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-dim);
}

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

.md code {
  padding: 1px 5px;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.md a {
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.md strong {
  color: var(--text);
  font-weight: 650;
}

.md table {
  width: 100%;
  margin: 10px 0;
  border-collapse: collapse;
  font-size: 0.92em;
}

.md th,
.md td {
  padding: 6px 9px;
  border: 1px solid var(--border);
  text-align: left;
}

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

.code-block {
  margin: 12px 0;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-md);
  background: var(--code-bg);
  overflow: hidden;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 8px 5px 12px;
  border-bottom: 1px solid var(--code-border);
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.code-copy:hover {
  border-color: var(--border);
  color: var(--text);
}

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
}

.code-block pre code {
  padding: 0;
  border: 0;
  background: transparent;
}

/* ---- tool / reasoning cards ---- */

.tool,
.reasoning {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  overflow: hidden;
}

.tool[open],
.reasoning[open] {
  background: var(--bg-panel);
}

.tool summary,
.reasoning summary {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 7px 11px;
  cursor: pointer;
  list-style: none;
  color: var(--text-dim);
  font-size: 12.5px;
}

.tool summary::-webkit-details-marker,
.reasoning summary::-webkit-details-marker {
  display: none;
}

.tool summary:hover,
.reasoning summary:hover {
  background: var(--bg-hover);
}

.tool-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  color: var(--text-faint);
  flex: none;
}

.tool-icon svg {
  width: 18px;
  height: 18px;
}

.tool-name {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  flex: none;
}

.tool-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-faint);
  flex: 1;
}

.tool-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-faint);
  flex: none;
  transition: transform 0.15s ease;
}

.tool[open] .tool-chevron,
.reasoning[open] .tool-chevron {
  transform: rotate(90deg);
}

.tool-body,
.reasoning-body {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
}

.tool-body pre,
.reasoning-body pre {
  margin: 0 0 8px;
  padding: 9px 10px;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 360px;
}

.tool-body pre:last-child,
.reasoning-body pre:last-child {
  margin-bottom: 0;
}

.tool-label {
  display: block;
  margin-bottom: 4px;
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-size: 11px;
}

.tool-running .tool-name {
  color: var(--accent);
}

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

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

.tool-completed .tool-name {
  color: var(--ok);
}

.reasoning {
  border-style: dashed;
}

.reasoning summary {
  color: var(--text-faint);
  font-style: normal;
}

.reasoning-body {
  color: var(--text-dim);
  font-size: 13px;
}

.reasoning-body pre {
  white-space: pre-wrap;
  font-family: var(--font-sans);
  background: transparent;
  border: 0;
  padding: 0;
}

/* ---- attention (permissions / questions) ---- */

.attention {
  padding: 0 clamp(14px, 3vw, 28px) 18px;
  background: transparent;
}

.attention-inner {
  width: min(100%, var(--measure));
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  align-items: start;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.request-card {
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  padding: 11px 13px;
}

.request-card.is-danger {
  border-left-color: var(--danger);
}

.request-head {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: none;
}

.request-title {
  margin-top: 4px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.request-pattern {
  margin: 6px 0 0;
  padding: 6px 8px;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 140px;
  overflow-y: auto;
}

.request-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.question-field {
  margin-top: 9px;
}

.question-label {
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
}

.question-description {
  margin: 2px 0 7px;
  color: var(--text-faint);
  font-size: 12px;
}

.option-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
}

.option:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.option.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.option input {
  accent-color: var(--accent);
}

.question-custom {
  width: 100%;
  min-height: 36px;
  margin-top: 7px;
  padding: 8px 9px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 13px;
}

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

.composer {
  position: relative;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 10px clamp(12px, 3vw, 24px) calc(10px + env(safe-area-inset-bottom));
}

.composer-box {
  width: min(100%, var(--measure));
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  max-height: 190px;
  padding: 9px 12px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  outline: 0;
  resize: none;
  font-size: 14.5px;
  line-height: 1.5;
}

.composer textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-ink);
  flex: none;
}

.send-btn:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.send-btn.stop {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.send-btn.stop:hover {
  background: var(--danger-soft);
}

.composer-meta {
  width: min(100%, var(--measure));
  margin: 7px auto 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 30px;
}

.usage {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
}

.context-meter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
}

.meter {
  width: 54px;
  height: 5px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  background: var(--ok);
  border-radius: inherit;
  transform-origin: left center;
}

.meter-fill.warn {
  background: var(--warn);
}

.meter-fill.danger {
  background: var(--danger);
}

/* ---- command menu ---- */

.command-menu {
  position: absolute;
  left: 50%;
  bottom: calc(100% - 4px);
  transform: translateX(-50%);
  width: min(calc(100% - 32px), var(--measure));
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  box-shadow: var(--shadow-lg);
  padding: 5px;
  z-index: 15;
}

.command-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  text-align: left;
}

.command-item:hover,
.command-item.is-selected {
  background: var(--accent-soft);
  color: var(--text);
}

.command-name {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  flex: none;
}

.command-desc {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-faint);
}

.jump-bottom {
  position: sticky;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 11.5px;
  box-shadow: var(--shadow-md);
  z-index: 5;
}

.jump-bottom:hover {
  color: var(--text);
  background: var(--bg-hover);
}

/* ---- modal ---- */

dialog.modal {
  width: min(580px, calc(100% - 28px));
  max-height: min(86dvh, 820px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

dialog.modal::backdrop {
  background: var(--backdrop);
}

.modal-form {
  display: flex;
  flex-direction: column;
  max-height: min(86dvh, 820px);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}

.modal-head-main {
  min-width: 0;
  flex: 1;
}

.modal-title {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.modal-sub {
  margin: 3px 0 0;
  color: var(--text-faint);
  font-size: 12px;
}

.modal-body {
  padding: 14px 18px;
  overflow-y: auto;
  min-height: 0;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}

.modal-foot .spacer {
  flex: 1;
}

.modal-error {
  margin: 0 18px 12px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 13px;
}

.field:last-child {
  margin-bottom: 0;
}

.field > label,
.field-label {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-md);
  background: var(--bg);
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-hint {
  color: var(--text-faint);
  font-size: 11.5px;
}

.info-list {
  margin: 0;
  display: grid;
  gap: 8px;
}

.info-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.info-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.info-row dt {
  color: var(--text-faint);
  font-size: 12px;
}

.info-row dd {
  margin: 0;
  min-width: 0;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.modal-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-dim);
  text-align: left;
}

.modal-row:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.modal-row.is-selected {
  border-color: var(--border-strong);
  background: var(--bg-active);
  color: var(--text);
}

.modal-row-main {
  min-width: 0;
  flex: 1;
}

.modal-row-title {
  display: block;
  font-size: 13px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-row-sub {
  display: block;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-empty {
  padding: 22px 10px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

.group-title {
  margin: 12px 0 5px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}

.group-title:first-child {
  margin-top: 0;
}

.model-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 12px;
  margin-top: 3px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.model-meta .price {
  color: var(--info);
}

.launch-path {
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11.5px;
  overflow-wrap: anywhere;
}

.dir-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 300px;
  overflow-y: auto;
}

.dir-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 0 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  text-align: left;
  font-family: var(--font-mono);
  font-size: 12px;
}

.dir-row:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.dir-row .dir-arrow {
  margin-left: auto;
  color: var(--text-faint);
}

.launch-list {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.launch-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.launch-item .dir {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.switch-row:last-child {
  border-bottom: 0;
}

.switch-label {
  min-width: 0;
  flex: 1;
}

.switch-title {
  display: block;
  font-size: 13px;
  font-weight: 550;
}

.switch-sub {
  display: block;
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 11.5px;
}

.switch {
  position: relative;
  width: 40px;
  height: 22px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg);
  flex: none;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.15s ease, background 0.15s ease;
}

.switch.is-on {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.switch.is-on::after {
  transform: translateX(18px);
  background: var(--accent);
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.segmented button {
  min-height: 30px;
  padding: 0 9px;
  border: 0;
  border-right: 1px solid var(--border);
  background-color: transparent;
  background-image: linear-gradient(
    to left,
    color-mix(in srgb, var(--instance-color, transparent) 32%, transparent),
    transparent
  );
  background-size: 57px 100%;
  background-position: right center;
  background-repeat: no-repeat;
  color: var(--text-dim);
  font-size: 11.5px;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.is-selected {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---- toast ---- */

.toast-root {
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 28px));
  pointer-events: none;
}

.toast {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
}

.toast.is-error {
  border-left-color: var(--danger);
}

.toast.is-ok {
  border-left-color: var(--ok);
}

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

@media (max-width: 900px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  }

  .topbar-menu {
    display: inline-flex;
  }

  .connection {
    padding: 0;
  }

  .connection #connection-text {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    display: none;
    width: min(86vw, 340px);
    z-index: 50;
    padding-top: env(safe-area-inset-top);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.is-open {
    display: flex;
  }

  .sidebar-close {
    display: inline-flex;
  }

  .sidebar-collapse,
  .app.sidebar-collapsed .sidebar-rail {
    display: none;
  }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: 45;
    background: var(--backdrop);
  }

  .main {
    grid-column: 1;
    grid-row: 2;
  }

  .session-head {
    padding: 10px 14px;
  }

  .session-head-meta .path {
    max-width: 220px;
  }

  .messages {
    padding-top: 18px;
  }

  .attention {
    padding-left: 12px;
    padding-right: 12px;
  }

  .usage {
    margin-left: 0;
  }
}

@media (max-width: 620px) {
  .app {
    --topbar-h: 50px;
    --tabbar-h: 40px;
  }

  .topbar {
    gap: 8px;
    padding: 0 8px;
  }

  .topbar-actions {
    gap: 4px;
  }

  .topbar-label {
    display: none;
  }

  .topbar .brand {
    font-size: 14px;
  }

  .brand-sub {
    display: none;
  }

  .tab {
    min-width: 96px;
    max-width: 190px;
    padding: 0 7px 0 10px;
  }

  .session-head {
    padding: 7px 10px;
    align-items: center;
    gap: 6px;
  }

  .session-head-title {
    font-size: 14.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-wrap: nowrap;
  }

  .session-head-meta {
    margin-top: 2px;
    flex-wrap: nowrap;
    gap: 8px;
    font-size: 11px;
    overflow: hidden;
    white-space: nowrap;
  }

  .session-head-meta > span {
    flex: none;
  }

  .session-head-meta .session-tokens,
  .session-head-meta .session-cost {
    display: none;
  }

  .session-head-meta .path {
    display: inline-flex;
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
  }

  .session-head-meta .session-model {
    flex: none;
    max-width: 110px;
  }

  .session-head-title .session-head-host {
    max-width: 96px;
  }

  .session-head-meta .session-place {
    max-width: 132px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .session-head-actions {
    margin-left: auto;
  }

  .session-head-actions .icon-btn {
    width: 30px;
    height: 30px;
  }

  .session-head-actions [data-action="new-session-here"] {
    display: none;
  }

  .messages {
    padding: 14px 12px 10px;
    gap: 14px;
  }

  .attention {
    padding: 0 12px 10px;
  }

  .composer {
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }

  .composer textarea {
    min-height: 38px;
    padding: 7px 10px;
    font-size: 14px;
  }

  .send-btn {
    width: 38px;
    height: 38px;
  }

  .composer-meta {
    margin-top: 4px;
    gap: 4px;
    min-height: 28px;
    flex-wrap: nowrap;
  }

  .chip {
    min-height: 26px;
    max-width: 170px;
    padding: 0 8px;
    font-size: 11px;
  }

  .usage {
    display: none;
  }

  .context-meter {
    margin-left: auto;
    font-size: 10.5px;
  }

  .context-meter .ctx-count {
    display: none;
  }

  .meter {
    width: 42px;
  }

  .modal-foot {
    flex-wrap: wrap;
    gap: 6px;
  }

  .modal-foot .spacer {
    display: none;
  }

  .modal-foot .btn {
    flex: 1 1 28%;
    min-width: 0;
    padding: 0 8px;
    font-size: 12.5px;
  }

  .login-card {
    padding: 26px 20px;
  }
}

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