/* App shell. Control register of DESIGN.md: dense, calm, hairline structure, logical properties for RTL. */
*, *::before, *::after { box-sizing: border-box; }
:root { --dir: 1; --topbar-h: 52px; }
:root[dir="rtl"] { --dir: -1; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--canvas); color: var(--text);
  font: 430 14px/1.5 var(--font-body); -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); }
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; inset-inline-start: 12px; inset-block-start: -60px; z-index: 100; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm); }
.skip:focus { inset-block-start: 8px; }
.muted { color: var(--text-muted); }
.soft { color: var(--text-soft); }
.small { font-size: 12.5px; }
.mono { font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.icon { flex: none; }
[dir="rtl"] .icon-flip { transform: scaleX(-1); }

/* Type */
.h-xl { font: 600 clamp(28px, 4vw, 40px)/1.08 var(--font-display); letter-spacing: -0.03em; }
.h-lg { font: 600 clamp(24px, 3vw, 32px)/1.15 var(--font-display); letter-spacing: -0.024em; }
.h-sm { font: 620 18px/1.3 var(--font-display); letter-spacing: -0.01em; }
.label { display: block; font: 620 13px/1.25 var(--font-body); letter-spacing: 0.01em; color: var(--text-soft); }
.label-sm { font: 500 11px/1.3 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.lead { font: 420 16px/1.55 var(--font-body); color: var(--text-soft); max-width: 62ch; margin-block-start: 12px; }
[dir="rtl"] :is(.h-xl, .h-lg, .h-sm, .label, .label-sm, .brand-name, .btn) { letter-spacing: 0; text-transform: none; }

/* Layout */
.app { display: grid; grid-template-rows: var(--topbar-h) minmax(0, 1fr); height: 100dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-inline: 16px; border-bottom: 1px solid var(--border); background: var(--canvas); }
.topbar-start, .topbar-end { display: flex; align-items: center; gap: 8px; min-width: 0; }
.shell { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 0; }
@media (min-width: 1024px) { .shell { grid-template-columns: 240px minmax(0, 1fr); } }
@media (min-width: 1280px) { .shell.has-chat { grid-template-columns: 240px minmax(0, 1fr) 400px; } }
.sidebar { background: var(--sidebar-bg); border-inline-end: 1px solid var(--border); overflow-y: auto; min-height: 0; }
.main { overflow-y: auto; min-height: 0; min-width: 0; }
.main:focus { outline: none; }
.chat-dock { border-inline-start: 1px solid var(--border); background: var(--surface); min-height: 0; display: flex; }
.only-narrow { display: inline-flex; }
@media (min-width: 1024px) { .only-narrow { display: none !important; } }
@media (max-width: 767px) { .hide-narrow { display: none !important; } }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; border-radius: var(--r-xs); }
.brand-mark { display: grid; place-items: center; width: 26px; height: 26px; border-radius: var(--r-xs); background: var(--brand); color: var(--on-brand); }
.brand-name { font: 620 18px/1 var(--font-display); letter-spacing: -0.02em; }

@media (max-width: 479px) {
  .topbar { padding-inline: 8px; gap: 4px; }
  .topbar-start, .topbar-end { gap: 4px; }
  .brand-name { display: none; }
  .seg { min-width: 34px; padding: 0 8px; }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px;
  border-radius: var(--r-sm); border: 1px solid var(--border-strong); background: transparent; color: var(--text);
  font: 620 13px/1.25 var(--font-body); letter-spacing: 0.01em; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease);
}
.btn:hover { background: var(--surface-subtle); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn[aria-pressed="true"] { background: var(--surface-subtle); border-color: var(--text-muted); }
.btn-primary { background: var(--action); border-color: transparent; color: var(--on-action); }
.btn-primary:hover { background: var(--action-hover); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-compact { min-height: 36px; padding: 0 12px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 0 4px; color: var(--link); font: 620 13px var(--font-body); cursor: pointer; text-decoration: underline; border-radius: 4px; }
@media (pointer: coarse) { .btn, .icon-btn, .control { min-height: 44px; } .icon-btn { min-width: 44px; } }

.icon-btn { display: inline-grid; place-items: center; min-width: 40px; min-height: 40px; padding: 0; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-soft); cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: var(--surface-subtle); color: var(--text); }
/* Tooltips (CSS only; used on icon-only controls in the top bar and chat header) */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; inset-block-start: calc(100% + 6px); inset-inline-end: 0; z-index: 70;
  padding: 6px 8px; border-radius: var(--r-sm); background: var(--tooltip-bg); color: var(--tooltip-text);
  font: 450 12px/1.3 var(--font-mono); white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity 140ms var(--ease);
}
[data-tip]:focus-visible::after { opacity: 1; }
@media (hover: hover) { [data-tip]:hover::after { opacity: 1; transition-delay: 300ms; } }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.hint { font-size: 12px; color: var(--text-muted); }
.control {
  width: 100%; min-height: 40px; padding: 8px 12px; background: var(--surface-subtle); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); line-height: 1.4;
}
.control::placeholder { color: var(--text-muted); }
.control:hover { border-color: var(--text-muted); }
.control:focus-visible { border-color: var(--focus); }
.control-sm { min-height: 36px; padding: 6px 10px; }
textarea.control { resize: vertical; min-height: 64px; }
select.control { appearance: none; padding-inline-end: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23989898' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-size: 16px; background-position: right 10px center; }
[dir="rtl"] select.control { background-position: left 10px center; }
.input-group { display: flex; align-items: center; gap: 4px; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.code-area { font: 450 13px/1.55 var(--font-mono); min-height: 320px; tab-size: 2; white-space: pre; overflow: auto; }

/* Sidebar */
.sidebar-inner { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.nav-label { display: flex; align-items: center; justify-content: space-between; margin-block-start: 8px; font: 500 11px/1.3 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
[dir="rtl"] .nav-label { letter-spacing: 0; text-transform: none; font-size: 12px; }
.mono-count { font-family: var(--font-mono); }
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 10px; border-radius: var(--r-xs);
  color: var(--text-soft); text-decoration: none; font-weight: 500;
}
.nav-item:hover { background: var(--surface-subtle); color: var(--text); }
:root:not([data-theme="light"]) .nav-item:hover { background: var(--surface-subtle); }
.nav-item.is-active { background: var(--surface-subtle); color: var(--text); font-weight: 620; box-shadow: inset 0 0 0 1px var(--border); }
.nav-item.is-active::before { content: ""; position: absolute; inset-inline-start: 0; inset-block: 8px; width: 3px; border-radius: 2px; background: var(--action); }
.nav-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (pointer: coarse) { .nav-item { min-height: 44px; } }

/* Overlays: drawers (start/end) and dialogs (center) */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; }
.scrim { position: absolute; inset: 0; background: var(--scrim); animation: fade 160ms var(--ease); }
.panel { position: relative; background: var(--surface); color: var(--text); outline: none; overflow: auto; }
.overlay-start { justify-content: flex-start; }
.overlay-end { justify-content: flex-end; }
.overlay-start .panel, .overlay-end .panel { width: min(340px, 88vw); height: 100%; box-shadow: var(--shadow-pop); display: flex; flex-direction: column; animation: slide-in 220ms var(--ease-in); }
.overlay-start .panel { background: var(--sidebar-bg); border-inline-end: 1px solid var(--border); --from: calc(var(--dir) * -24px); }
.overlay-end .panel { width: min(440px, 100vw); border-inline-start: 1px solid var(--border); --from: calc(var(--dir) * 24px); overflow: hidden; }
.overlay-center { align-items: center; justify-content: center; padding: 16px; }
.overlay-center .panel { width: min(560px, 100%); max-height: calc(100dvh - 32px); border-radius: var(--r-lg); border: 1px solid var(--border); box-shadow: var(--shadow-modal); animation: rise 240ms var(--ease-in); }
@media (max-width: 639px) {
  .overlay-center { align-items: flex-end; padding: 0; }
  .overlay-center .panel { width: 100%; max-height: 100dvh; border-radius: var(--r-lg) var(--r-lg) 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .overlay-end .panel { width: 100vw; border-inline-start: 0; }
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 8px 16px; min-height: var(--topbar-h); border-bottom: 1px solid var(--border); }
.drawer-body { overflow-y: auto; flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-in { from { opacity: 0; transform: translateX(var(--from)); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.dialog { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-title { font: 600 24px/1.25 var(--font-display); letter-spacing: -0.018em; }
[dir="rtl"] .dialog-title { letter-spacing: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.dialog-wide { gap: 24px; }
.form-section { display: flex; flex-direction: column; gap: 14px; padding-block-start: 20px; border-top: 1px solid var(--border); }
.form-section:first-of-type { border-top: 0; padding-block-start: 0; }
.danger-zone { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-block-start: 8px; }

/* Banners */
.banner { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: var(--r-xs); border-inline-start: 3px solid var(--info); background: var(--info-bg); }
.banner-danger { border-color: var(--danger); background: var(--danger-bg); }
.banner-success { border-color: var(--success); background: var(--success-bg); }
.banner-body { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.banner-body pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Pages */
.page { max-width: 1040px; margin-inline: auto; padding: 24px 16px 72px; display: flex; flex-direction: column; gap: 32px; }
@media (min-width: 768px) { .page { padding-inline: 24px; } }
@media (min-width: 1280px) { .page { padding-inline: 32px; } }
.block { display: flex; flex-direction: column; gap: 12px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.empty { padding: 24px; border: 1px dashed var(--border-strong); border-radius: var(--r-sm); color: var(--text-soft); }

.try-list { border-top: 1px solid var(--border); }
.try { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 8px 4px; text-align: start; background: none; border: 0; border-bottom: 1px solid var(--border); color: var(--text); cursor: pointer; border-radius: 0; }
.try:hover { background: var(--surface-subtle); }
.try > svg:last-child:not(:first-child) { margin-inline-start: auto; color: var(--text-muted); }
.try > svg:first-child { color: var(--text-muted); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-sm); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0 12px; height: 44px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; font-weight: 430; }
.table tbody tr:last-child > * { border-bottom: 0; }
.table thead th { height: 36px; background: var(--surface-subtle); color: var(--text-muted); font: 500 11px/1.3 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
[dir="rtl"] .table thead th { letter-spacing: 0; text-transform: none; font-size: 12px; }
.table tbody tr:hover > * { background: var(--surface-subtle); }
.table tbody th { position: sticky; inset-inline-start: 0; background: var(--canvas); font-weight: 620; white-space: nowrap; }
.row-link { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.row-link:hover span { text-decoration: underline; }
.table td.soft { min-width: 220px; }
.table td.mono, .table td.nowrap { white-space: nowrap; }

.tool-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 0; }
.tool-title { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }
.tool-title > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tool-icon { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-subtle); }
.tool-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.page-tool { gap: 20px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-block-start: -4px; }
.tab { position: relative; display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; color: var(--text-muted); text-decoration: none; font-weight: 620; border-radius: var(--r-xs) var(--r-xs) 0 0; }
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { color: var(--text); }
.tab[aria-current="page"]::after { content: ""; position: absolute; inset-inline: 8px; inset-block-end: -1px; height: 2px; background: var(--action); }
.stage { display: flex; flex-direction: column; gap: 12px; }
.frame-wrap { position: relative; max-width: 880px; min-height: 120px; }
.frame { display: block; width: calc(100% + 8px); margin: -4px; border: 0; background: transparent; color-scheme: normal; }
.frame-loading { position: absolute; inset: 0; display: flex; align-items: flex-start; gap: 10px; padding-block-start: 8px; }
.source { display: flex; flex-direction: column; gap: 16px; max-width: 880px; }
.versions { border-top: 1px solid var(--border); }
.versions li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.versions li .btn { margin-inline-start: auto; }
.versions-h { margin-block-start: 8px; }

/* Chat */
.chat { display: flex; flex-direction: column; min-height: 0; width: 100%; flex: 1; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 16px; min-height: 52px; border-bottom: 1px solid var(--border); }
.chat-head-actions { display: flex; align-items: center; }
.context-chip { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 16px; background: var(--surface-subtle); border-bottom: 1px solid var(--border); color: var(--text-soft); font-size: 12.5px; }
.context-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-x { display: inline-grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: var(--r-xs); background: transparent; color: var(--text-muted); cursor: pointer; }
.chip-x:hover { background: var(--border); color: var(--text); }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 22px; overscroll-behavior: contain; }
.chat-empty { display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; flex-direction: column; gap: 6px; }
.msg-label { font: 500 11px/1.3 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
[dir="rtl"] .msg-label { letter-spacing: 0; text-transform: none; font-size: 12px; }
.msg-body { display: flex; flex-direction: column; gap: 10px; min-width: 0; overflow-wrap: anywhere; }
.msg-user .msg-body { padding-inline-start: 12px; border-inline-start: 2px solid var(--border-strong); white-space: pre-wrap; }
.md > * + * { margin-block-start: 8px; }
.md ul, .md ol { padding-inline-start: 20px; list-style: revert; }
.md code { font: 450 12.5px var(--font-mono); background: var(--surface-subtle); padding: 1px 5px; border-radius: 6px; }
.md pre { margin: 0; padding: 14px; overflow-x: auto; border-radius: var(--r-md); background: var(--code-bg); color: var(--code-text); }
.md pre code { background: none; padding: 0; color: inherit; }
.progress-line { display: flex; align-items: center; gap: 10px; }

/* Toasts */
.toaster { position: fixed; inset-block-end: calc(16px + env(safe-area-inset-bottom)); inset-inline-end: 16px; z-index: 90; display: flex; flex-direction: column; gap: 8px; width: min(400px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 14px; background: var(--surface-subtle); color: var(--text); border: 1px solid var(--border-strong); border-inline-start: 3px solid var(--info); border-radius: var(--r-sm); box-shadow: var(--shadow-pop); animation: rise 200ms var(--ease-in); }
.toast-success { border-inline-start-color: var(--success); }
.toast-danger { border-inline-start-color: var(--danger); }
.toast-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-x { display: inline-grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: var(--r-xs); background: transparent; color: var(--text-muted); cursor: pointer; }
.toast-x:hover { color: var(--text); background: var(--border); }

.spinner { display: inline-block; flex: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--action); animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition: none !important; scroll-behavior: auto !important; }
  .spinner { animation: none; border-top-color: var(--border-strong); border-inline-end-color: var(--action); }
}
@media (prefers-contrast: more) {
  :root { --border: var(--border-strong); }
}
@media (forced-colors: active) {
  .btn, .control, .nav-item.is-active { border: 1px solid CanvasText; }
}
@media (max-width: 479px) { .drawer-head .brand-name { display: inline; } }

/* Account */
.avatar { display: inline-block; flex: none; border-radius: 50%; object-fit: cover; background: var(--surface-subtle); border: 1px solid var(--border); }
.avatar-fallback { display: inline-grid; place-items: center; font-weight: 700; color: var(--on-action); background: var(--action); border: 0; }
.avatar-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; }
.avatar-btn:hover .avatar { border-color: var(--text-muted); }
.menu-root { position: relative; }
.popover { position: absolute; inset-block-start: calc(100% + 6px); inset-inline-end: 0; z-index: 60; width: min(280px, calc(100vw - 24px)); padding: 6px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--shadow-pop); animation: rise 160ms var(--ease-in); }
.popover-head { display: flex; align-items: center; gap: 12px; padding: 10px; }
.popover-id { display: flex; flex-direction: column; min-width: 0; }
.popover-id > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover-status { padding: 0 10px 8px; border-bottom: 1px solid var(--border); margin-block-end: 6px; }
.popover-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 10px; border: 0; border-radius: var(--r-xs); background: none; color: var(--text); text-decoration: none; font-weight: 500; text-align: start; cursor: pointer; }
.popover-item:hover { background: var(--surface-subtle); }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.sync-error { color: var(--danger); }
.gbtn { display: flex; justify-content: center; min-height: 44px; }
.dev-login { display: flex; flex-direction: column; gap: 12px; padding-block-start: 16px; border-top: 1px dashed var(--border-strong); }
.account-head { display: flex; align-items: center; gap: 16px; margin: 0; }
.account-head > div { min-width: 0; }
.page-account { max-width: 720px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.grow { flex: 1 1 220px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 0; }
.facts > div { padding-block-start: 10px; border-top: 1px solid var(--border); }
.facts dt { font: 500 11px/1.3 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
[dir="rtl"] .facts dt { letter-spacing: 0; text-transform: none; font-size: 12px; }
.facts dd { margin: 4px 0 0; }
.plain-list { display: flex; flex-direction: column; gap: 8px; }
.plain-list li { display: flex; align-items: flex-start; gap: 10px; color: var(--text-soft); }
.plain-list li > svg { margin-block-start: 3px; color: var(--text-muted); }
.wait { display: flex; flex-direction: column; gap: 6px; }

/* Icon buttons that look like buttons, option groups, menus */
.btn-icon { min-width: 40px; padding: 0; }
.btn-icon.btn-compact { min-width: 36px; }
.opt-group { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface-subtle); align-self: flex-start; }
.opt { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 14px; border: 0; border-radius: 10px; background: transparent; color: var(--text-soft); font: 620 13px var(--font-body); cursor: pointer; }
.opt:hover { color: var(--text); }
.opt[aria-checked="true"] { background: var(--action); color: var(--on-action); }
@media (pointer: coarse) { .opt { min-height: 44px; } }
.popover-rule { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.popover-item.is-danger { color: var(--danger); }
.popover-item:focus-visible { outline-offset: -2px; }
.menu-root .popover { min-width: 220px; }

/* Composer: one rounded box, hint on the start side, send on the end side */
.composer { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.composer.gate { align-items: flex-start; padding: 16px; gap: 10px; }
.composer-box { display: flex; flex-direction: column; background: var(--surface-subtle); border: 1px solid var(--border-strong); border-radius: var(--r-md); transition: border-color 120ms var(--ease); }
.composer-box:focus-within { border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
.composer-box textarea { width: 100%; min-height: 48px; max-height: 180px; padding: 12px 14px 4px; border: 0; outline: none; background: transparent; color: var(--text); resize: none; line-height: 1.5; }
.composer-box textarea::placeholder { color: var(--text-muted); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 8px 8px 14px; }
.composer-hint { font-size: 12px; color: var(--text-muted); }
@media (pointer: coarse) { .composer-hint { display: none; } }
.send-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; margin-inline-start: auto; border: 0; border-radius: 50%; background: var(--action); color: var(--on-action); cursor: pointer; transition: background-color 120ms var(--ease); }
.send-btn:hover:not(:disabled) { background: var(--action-hover); }
.send-btn:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }
.send-btn.is-stop { background: transparent; border: 1px solid var(--border-strong); color: var(--text); }
.send-btn.is-stop:hover { background: var(--surface); }
@media (pointer: coarse) { .send-btn { width: 44px; height: 44px; } }
.composer .context-chip { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 4px 4px 4px 10px; }

/* What the builder did to a tool: the card opens it; Undo sits apart so a stray tap cannot cost work */
.action-wrap { display: flex; flex-direction: column; gap: 4px; }
.action { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-subtle); overflow: hidden; }
.action.is-undone { background: transparent; border-style: dashed; }
.action-main { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; padding: 10px 12px; border: 0; background: none; color: var(--text); text-align: start; cursor: pointer; }
.action-main:disabled { cursor: default; color: var(--text-muted); }
.action-main:not(:disabled):hover { background: var(--surface); }
.action-icon { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: var(--r-xs); background: var(--surface); border: 1px solid var(--border); color: var(--text-soft); }
.action-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.action-name { font-weight: 620; overflow-wrap: anywhere; }
.action-undo { display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none; min-width: 84px; padding: 0 14px; border: 0; border-inline-start: 1px solid var(--border); background: none; color: var(--text-soft); font: 620 12.5px var(--font-body); cursor: pointer; }
.action-undo:hover { background: var(--surface); color: var(--text); }
@media (pointer: coarse) { .action-undo { min-width: 96px; min-height: 52px; } }
.action-fail { border-color: var(--danger); background: var(--danger-bg); padding: 10px 12px; gap: 12px; align-items: flex-start; }
.action-fail .action-icon { color: var(--danger); }
.action-hint { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 0; }

/* Chat header, history */
.chat-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history { display: flex; flex-direction: column; gap: 12px; padding: 12px; overflow-y: auto; flex: 1; min-height: 0; }
.history-list { display: flex; flex-direction: column; border-top: 1px solid var(--border); }
.history-item { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); }
.history-item.is-active { background: var(--surface-subtle); box-shadow: inset 3px 0 0 var(--action); }
[dir="rtl"] .history-item.is-active { box-shadow: inset -3px 0 0 var(--action); }
.history-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; padding: 10px 12px; border: 0; background: none; color: var(--text); text-align: start; cursor: pointer; }
.history-main:hover { background: var(--surface-subtle); }
.history-title { font-weight: 620; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-del { display: inline-grid; place-items: center; flex: none; width: 44px; border: 0; background: none; color: var(--text-muted); cursor: pointer; }
.history-del:hover { color: var(--danger); background: var(--surface-subtle); }

/* Tool page extras */
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0; }
.badge-official { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: var(--r-full); background: var(--info-bg); color: var(--text); border: 1px solid var(--border); font: 500 11px/1.7 var(--font-mono); }
.badge-official svg { color: var(--info); }
.nav-trash { margin-block-start: 8px; border-top: 1px solid var(--border); border-radius: 0 0 var(--r-xs) var(--r-xs); padding-block-start: 10px; }
.nav-trash .mono-count { margin-inline-start: auto; font-size: 12px; color: var(--text-muted); }
.trash-list { display: flex; flex-direction: column; border-top: 1px solid var(--border); }
.trash-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.trash-text { display: flex; flex-direction: column; flex: 1 1 160px; min-width: 0; }
