:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #1a2232;
  --border: #232c3d;
  --text: #e7ecf5;
  --muted: #8b97ab;
  --accent: #3b82f6;
  --accent-press: #2563eb;
  --accent-soft: rgba(59, 130, 246, .16);
  --accent-text: #7fb0ff;
  --danger: #f87171;
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  display: flex; flex-direction: column; overflow: hidden;
  height: var(--tg-viewport-height, 100dvh);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }

.btn-primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 600; }
.btn-primary:active { background: var(--accent-press); }
.btn-secondary { background: transparent; color: var(--accent-text); border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; font-weight: 600; }
.icon-btn { background: none; border: 0; color: var(--muted); padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.icon-btn:hover { color: var(--text); background: var(--surface); }
.icon-btn.on { color: var(--accent-text); background: var(--accent-soft); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); }

/* top tabs */
.topbar { flex: none; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; background: var(--surface); border-radius: 10px; padding: 3px; max-width: 420px; margin: 0 auto; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 7px 0; border-radius: 8px; font-weight: 600; }
.tab.active { background: var(--accent-soft); color: var(--accent-text); }

/* chats layout: list → chat on phones, side by side on wide screens */
.layout { flex: 1; display: flex; min-height: 0; position: relative; }
#sidebar { width: 100%; display: flex; flex-direction: column; min-height: 0; }
#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.empty { flex: 1; display: none; place-items: center; color: var(--muted); }
body:not(.in-chat) #chat { display: none; }
body.in-chat #sidebar { display: none; }
@media (min-width: 760px) {
  #sidebar { width: 300px; flex: none; border-right: 1px solid var(--border); }
  body.in-chat #sidebar { display: flex; }
  body:not(.in-chat) .empty { display: grid; }
}

.sidebar-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 12px 6px; }
#new-chat { flex: 1; }
#archive-toggle { flex: 1 0 100%; padding-block: 4px; } /* its own slim row under the two buttons */
#chat-list { list-style: none; margin: 0; padding: 4px 8px 12px; overflow-y: auto; flex: 1; }
.chat-item { position: relative; padding: 9px 36px 9px 12px; border-radius: 10px; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.chat-more { position: absolute; top: 50%; right: 3px; transform: translateY(-50%); width: 28px; height: 28px; }
#voice-btn[aria-pressed="true"] { color: #fa7474; animation: pulse 1.4s infinite; }
.chat-item:hover { background: var(--surface); }
.chat-item.active { background: var(--accent-soft); }
.chat-item .t, .chat-item .m { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .t { font-weight: 600; }
.chat-item.active .t { color: var(--accent-text); }
.chat-item .m { font-size: 12.5px; color: var(--muted); margin-top: 1px; display: flex; align-items: center; gap: 6px; }
.chat-item .m span:last-child { overflow: hidden; text-overflow: ellipsis; }
.badge { flex: none; font-size: 11.5px; font-weight: 600; padding: 0 7px; border-radius: 999px; line-height: 18px; }
.badge.run { color: var(--accent-text); background: var(--accent-soft); }
.badge.run::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 5px; vertical-align: 1px; animation: pulse 1.4s infinite; }
.badge.wait { color: #fbbf24; background: rgba(245, 158, 11, .14); }
.list-empty { color: var(--muted); padding: 16px 12px; text-align: center; }

.chat-head { flex: none; display: flex; align-items: center; gap: 8px; padding: 7px 8px 7px 16px; border-bottom: 1px solid var(--border); }
.chat-head-text { flex: 1; min-width: 0; }
.chat-head h2 { margin: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: text; }
.title-input {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); outline: none;
  border: 1px solid var(--accent); border-radius: 6px; padding: 2px 6px;
}
.turn-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.turn-status .elapsed { font-variant-numeric: tabular-nums; opacity: .8; }
.chat-status { font-size: 12px; margin-top: 1px; }
.chat-status.run { color: var(--accent-text); }
.chat-status.wait { color: #fbbf24; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* messages: user bubbles on the right, the agent's turn as a full-width feed */
#messages { flex: 1; overflow-y: auto; padding: 14px 14px 18px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }
.hint { margin: auto; color: var(--muted); text-align: center; max-width: 320px; }
.history-notice {
  align-self: center; display: flex; align-items: center; gap: 8px; max-width: 100%;
  color: var(--muted); font-size: 12.5px; line-height: 1.4; text-align: center;
}
.history-notice::before, .history-notice::after {
  content: ''; flex: 0 1 24px; width: 24px; border-top: 1px solid var(--border);
}
.history-notice:has(.delegation-result) { display: grid; gap: 4px; width: min(100%, 580px); }
.history-notice:has(.delegation-result)::before, .history-notice:has(.delegation-result)::after { display: none; }
.delegation-status { flex: none; overflow-y: auto; max-height: 28vh; border-top: 1px solid var(--border); padding: 6px 14px; }
.delegation-card { color: var(--muted); font-size: 12.5px; line-height: 1.45; overflow-wrap: anywhere; }
.delegation-card + .delegation-card { margin-top: 6px; }
.delegation-line { display: flex; align-items: center; gap: 7px; }
.delegation-line .pulse { flex: none; }
.delegation-result { color: var(--text); overflow-wrap: anywhere; }
.history-notice .delegation-result { text-align: left; }
.msg.user {
  position: relative; align-self: flex-end; max-width: min(86%, 680px); padding: 9px 13px; border-radius: 18px; border-bottom-right-radius: 5px;
  background: var(--accent-press); color: #fff; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.user.failed { background: transparent; color: var(--text); border: 1px solid rgba(248, 113, 113, .55); }
.turn-error {
  align-self: stretch; max-width: 780px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(248, 113, 113, .4); background: rgba(248, 113, 113, .07);
}
.turn-error-title { font-weight: 600; color: var(--danger); }
.turn-error-text { font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user.queued { background: transparent; color: var(--text); border: 1px dashed rgba(59, 130, 246, .55); }
.queued-meta { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 4px; font-size: 11.5px; color: var(--accent-text); }
.queued-cancel { background: none; border: 0; color: var(--muted); padding: 0 2px; font-size: 13px; line-height: 1; }
.queued-cancel:hover { color: var(--danger); }
.turn { align-self: stretch; max-width: 780px; display: flex; flex-direction: column; gap: 6px; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: .55em 0; }
.md ul, .md ol { padding-left: 1.3em; }
.md h1, .md h2, .md h3 { font-size: 1.05em; margin: .9em 0 .4em; }
.md a { color: var(--accent-text); }
.md a.file-link { text-decoration: underline dotted; text-underline-offset: 3px; cursor: pointer; }
.md a.file-link code { color: var(--accent-text); }
.md code, .tool-label { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86em; }
.md code { background: rgba(255, 255, 255, .07); padding: 1px 4px; border-radius: 4px; }
.md pre, .tool-body pre { background: #0a0d14; border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; }
.md blockquote { margin: .5em 0; padding-left: 10px; border-left: 3px solid var(--border); color: var(--muted); }
.note { font-size: 12.5px; color: var(--muted); }

/* collapsible rows: thinking and tool calls */
.block-think > summary, .block-tool > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 7px; min-width: 0;
  color: var(--muted); font-size: 13px; padding: 4px 6px; margin: 0 -6px; border-radius: 7px;
}
.block-think > summary::-webkit-details-marker, .block-tool > summary::-webkit-details-marker { display: none; }
.block-think > summary:hover, .block-tool > summary:hover { background: var(--surface); }
.block-think > summary::after, .block-tool > summary::after { content: "›"; margin-left: auto; padding-left: 6px; transition: transform .15s; }
details[open] > summary::after { transform: rotate(90deg); }
.block-think > summary::before { content: "✦"; color: var(--accent-text); font-size: 11px; }
.think-body { color: var(--muted); font-size: 13.5px; border-left: 2px solid var(--border); padding: 2px 0 2px 11px; margin: 4px 0 6px 4px; }
.tool-name { flex: none; color: var(--text); font-weight: 500; }
.tool-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.tool-icon { flex: none; width: 14px; height: 14px; display: grid; place-items: center; font-size: 11px; }
.tool-icon.running { border: 2px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.tool-icon.ok::before { content: "✓"; color: #4ade80; }
.tool-icon.fail::before { content: "✕"; color: var(--danger); }
.tool-icon.done::before { content: "•"; color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }
.tool-body { margin: 4px 0 6px 4px; padding-left: 11px; border-left: 2px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.tool-body pre { margin: 0; max-height: 320px; overflow: auto; white-space: pre-wrap; font-size: 12px; }
.tool-args { color: var(--accent-text); }
.turn-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 2px 0; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s infinite; }

.approval { padding: 10px; border-radius: 10px; border: 1px solid rgba(245, 158, 11, .4); background: rgba(245, 158, 11, .07); }
.approval.settled { padding: 6px 10px; border-color: var(--border); background: transparent; }
.approval-title { font-weight: 600; margin-bottom: 4px; }
.approval pre { white-space: pre-wrap; margin: 6px 0; }
.approval-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* composer */
#composer { position: relative; flex: none; padding: 8px 10px calc(8px + var(--safe-bottom)); border-top: 1px solid var(--border); background: var(--bg); }
.slash-menu {
  position: absolute; left: 10px; right: 10px; bottom: calc(100% + 6px); z-index: 5; max-height: 50dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.slash-item {
  display: grid; grid-template-columns: auto 1fr; column-gap: 8px; width: 100%; text-align: left;
  background: none; border: 0; color: var(--text); padding: 7px 9px; border-radius: 8px;
}
.slash-item.active, .slash-item:hover { background: var(--accent-soft); }
.slash-name { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--accent-text); font-weight: 600; }
.slash-args { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--muted); }
.slash-desc { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.sys-note { align-self: stretch; max-width: 780px; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; font-size: 13px; background: var(--surface); }
.sys-title { font-weight: 600; margin-bottom: 6px; }
.sys-note.continued { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.sys-row { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 10px; padding: 3px 0; color: var(--muted); }
.sys-row code { color: var(--accent-text); font-size: 12.5px; }

/* /btw side chat */
dialog.sheet { width: min(96vw, 680px); height: min(88dvh, 760px); }
.btw { display: flex; flex-direction: column; height: 100%; box-sizing: border-box; padding: 12px 12px calc(10px + var(--safe-bottom)); gap: 8px; }
.btw-head { display: flex; align-items: flex-start; gap: 8px; }
.btw-head-text { flex: 1; min-width: 0; }
.btw-head h3 { margin: 0; font-size: 15px; }
.btw-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 6px 2px; border-top: 1px solid var(--border); }
#btw-input { flex: 1; resize: none; max-height: 120px; outline: none; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 19px; padding: 9px 14px; font: inherit; }
#btw-input:focus { border-color: var(--accent); }
.composer-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.composer-tools #model { max-width: min(40%, 240px); text-overflow: ellipsis; }
.composer-tools #mode { max-width: min(36%, 190px); text-overflow: ellipsis; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; max-width: 34%; min-width: 0;
  background: var(--surface); color: var(--muted); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px; font-size: 12.5px; font-weight: 600; line-height: 1.4;
}
.pill svg { flex: none; }
.pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill.set { color: var(--accent-text); }

/* dialogs (native <dialog>) */
dialog { padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); width: min(92vw, 480px); max-height: 86dvh; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dlg { padding: 16px; display: flex; flex-direction: column; gap: 10px; max-height: 86dvh; box-sizing: border-box; }
.dlg h3 { margin: 0; font-size: 16px; }
.dlg p { margin: 0; }
.dlg-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dlg-actions .spacer { flex: 1; }
.dlg-actions #cwd-pick { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs { display: flex; flex-wrap: wrap; gap: 2px; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.crumb { background: none; border: 0; color: var(--accent-text); padding: 2px 4px; border-radius: 4px; }
.crumb:hover { background: var(--accent-soft); }
.crumb + .crumb::before { content: "/"; color: var(--muted); margin-right: 4px; }
.crumb:first-child + .crumb::before { content: ""; margin: 0; }
.dir-list { list-style: none; margin: 0; padding: 4px; overflow-y: auto; max-height: 38dvh; min-height: 80px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.dir-list li.muted { padding: 8px; }
.dir { width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 7px 8px; border-radius: 6px; font-size: 14px; }
.dir::before { content: "📁 "; }
.dir:hover { background: var(--surface-2); }
.cwd-manual { display: flex; gap: 6px; }
.cwd-manual input { flex: 1; min-width: 0; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; font: 13px ui-monospace, Menlo, monospace; outline: none; }
.cwd-manual input:focus { border-color: var(--accent); }
.recent { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 3px 9px; font: 12px ui-monospace, Menlo, monospace; }
#model, #mode {
  appearance: none; -webkit-appearance: none; max-width: 100%;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237fb0ff' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--accent-text); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 28px 4px 11px; font-family: inherit; font-size: 12.5px; font-weight: 600; line-height: 1.4;
}
.input-row { display: flex; gap: 6px; align-items: flex-end; margin-top: 7px; }
.attach-btn { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; }
.attach-btn:hover { color: var(--accent-text); background: var(--surface); }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.att {
  display: inline-flex; align-items: center; gap: 6px; max-width: 240px; min-width: 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px 6px; font-size: 12px;
}
.att img { width: 28px; height: 28px; object-fit: cover; border-radius: 5px; flex: none; }
.att-icon { flex: none; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { flex: none; color: var(--muted); }
.att-x { flex: none; background: none; border: 0; color: var(--muted); padding: 0 2px; font-size: 12px; }
.att-x:hover { color: var(--danger); }
.att-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; white-space: normal; }
.msg.user .att { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .18); color: #fff; }
.msg.user .att-size { color: rgba(255, 255, 255, .7); }
#input {
  flex: 1; resize: none; max-height: 160px; outline: none; overflow-y: hidden;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 19px;
  padding: 9px 14px; font: inherit;
}
#input:focus { border-color: var(--accent); }
.send { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; }
.send:active { background: var(--accent-press); }
.send.stop { background: var(--surface-2); color: var(--text); }

/* settings */
#settings-view, #providers-view { flex: 1; overflow-y: auto; padding: 14px 12px calc(14px + var(--safe-bottom)); }
#settings-view > *, #providers-view > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.card h4 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.provider-name { font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.stat .v { font-size: 19px; font-weight: 600; }
.stat .k { font-size: 12px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.card th { color: var(--muted); font-weight: 500; text-align: right; padding: 4px 0 4px 10px; }
.card td { text-align: right; padding: 5px 0 5px 10px; border-top: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
.card th:first-child, .card td:first-child { text-align: left; padding-left: 0; white-space: normal; }

/* usage: month nav, hero figure, chart, tables */
.month-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.month-nav h3 { flex: 1; margin: 0; text-align: center; }
.month-nav .icon-btn { width: 34px; height: 34px; font-size: 22px; line-height: 1; color: var(--accent-text); }
.icon-btn:disabled { opacity: .25; }
.hero { margin: 8px 0 12px; }
.hero .k { font-size: 12.5px; color: var(--muted); }
.hero .v { font-size: 48px; font-weight: 600; line-height: 1.05; letter-spacing: -.01em; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 2px 0 8px; font-size: 12.5px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.usage-refresh { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.usage-refresh progress { flex: none; width: 64px; }
.sw { flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.chart { position: relative; min-height: 180px; }
.chart svg { display: block; }
.chart .grid { stroke: #1c2433; stroke-width: 1; }
.chart .axis { stroke: #2b3446; stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: pointer; outline: none; }
.chart .hit:hover, .chart .hit:focus-visible { fill: rgba(255, 255, 255, .05); }
.tip {
  position: absolute; top: 0; z-index: 2; pointer-events: none; min-width: 150px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.tip-date { color: var(--muted); margin-bottom: 3px; }
.tip-total { margin-bottom: 4px; }
.tip-total strong { font-size: 15px; }
.tip-row { display: flex; align-items: center; gap: 6px; line-height: 1.6; }
.tip-row strong { font-variant-numeric: tabular-nums; }
.tip-key { flex: none; width: 10px; height: 2px; border-radius: 1px; }
.usage-table .model-row td { font-weight: 600; padding-top: 9px; }
.usage-table .model-row td:first-child { display: flex; align-items: center; gap: 7px; }
.usage-table .who-row td { border-top: 0; color: var(--muted); padding-top: 2px; padding-bottom: 2px; }
.usage-table .who-row td:first-child { padding-left: 17px; }
.day-table > summary { cursor: pointer; color: var(--accent-text); font-size: 13px; margin-top: 14px; }
.day-table table { margin-top: 6px; }

/* search */
.search-box { padding: 2px 12px 6px; }
#search { width: 100%; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; font: inherit; font-size: 14px; outline: none; }
#search:focus { border-color: var(--accent); }
.snip { font-size: 12.5px; color: var(--muted); margin-top: 3px; padding: 1px 4px; margin-left: -4px; border-radius: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.snip:hover { color: var(--text); background: var(--surface-2); }
.snip mark { background: var(--accent-soft); color: var(--accent-text); border-radius: 3px; padding: 0 2px; }
.flash { animation: flash 2.4s ease-out; }
@keyframes flash { 0%, 35% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 3px transparent; } }

/* context fill (chat head) and subscription limits (composer): green-blue / amber / red, always with the number */
.ctx-btn {
  flex: none; display: inline-flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 9px; color: var(--accent-text); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.ctx-bar { width: 22px; height: 4px; border-radius: 2px; background: var(--surface-2) linear-gradient(currentColor, currentColor) no-repeat; background-size: var(--p) 100%; }
.limits {
  background: var(--surface); color: var(--accent-text); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px;
  font-size: 12.5px; font-weight: 600; line-height: 1.4; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.ctx-btn.mid, .limits.mid { color: #fbbf24; }
.ctx-btn.high, .limits.high { color: var(--danger); }
.info-body { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.info-body p { margin: 0; }
.big-num { font-size: 40px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter.mid i { background: #f59e0b; }
.meter.high i { background: var(--danger); }
.limit-row { display: flex; flex-direction: column; gap: 5px; }
.limit-head { display: flex; justify-content: space-between; gap: 8px; }
.limit-head strong { font-variant-numeric: tabular-nums; }

/* edit a message into a new branch */
.msg-edit {
  position: absolute; left: -32px; bottom: 2px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: transparent; color: var(--muted); opacity: 0; transition: opacity .15s;
}
.msg.user:hover .msg-edit, .msg-edit:focus-visible { opacity: 1; }
.msg-edit:hover { color: var(--accent-text); background: var(--surface); }
@media (hover: none) { .msg-edit { opacity: .6; } }
.msg.user.editing { width: min(86%, 680px); background: var(--surface); color: var(--text); border: 1px solid var(--accent); white-space: normal; display: flex; flex-direction: column; gap: 8px; }
.edit-input { width: 100%; resize: vertical; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font: inherit; outline: none; }
.edit-input:focus { border-color: var(--accent); }
.edit-hint { font-size: 12px; color: var(--muted); }
.edit-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* files of the working directory: an overlay over the chat, a third column on wide screens */
.files-panel {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 6; width: min(100%, 440px); display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--border); box-shadow: -12px 0 32px rgba(0, 0, 0, .45);
}
@media (min-width: 1100px) { .files-panel { position: static; width: 380px; flex: none; box-shadow: none; } }
.files-head { flex: none; display: flex; align-items: center; gap: 2px; padding: 7px 6px; border-bottom: 1px solid var(--border); }
.files-head .icon-btn { width: 32px; height: 32px; font-size: 16px; }
.files-crumbs { flex: 1; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; white-space: nowrap; }
.files-list { list-style: none; margin: 0; padding: 4px 6px calc(10px + var(--safe-bottom)); overflow-y: auto; flex: 1; }
.file-item { width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; background: none; border: 0; color: var(--text); padding: 7px 8px; border-radius: 8px; font-size: 14px; }
.file-item:hover { background: var(--surface); }
.file-icon { flex: none; width: 18px; text-align: center; }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pad { padding: 10px 8px; }
.file-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.file-view-head { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid var(--border); }
.file-view-head .icon-btn { width: 32px; height: 32px; font-size: 20px; }
.file-view-name { flex: 1; min-width: 0; }
#file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-body { flex: 1; overflow: auto; padding: 10px 12px calc(12px + var(--safe-bottom)); }
.file-text { margin: 0; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.file-img { max-width: 100%; height: auto; border-radius: 8px; background: repeating-conic-gradient(#1a2232 0 25%, #121826 0 50%) 0 0 / 16px 16px; }

/* providers */
.provider { padding: 12px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 7px; }
.provider-head { display: flex; align-items: center; gap: 8px; }
.badge.ok { color: #4ade80; background: rgba(74, 222, 128, .12); }
.badge.off { color: var(--muted); background: var(--surface-2); }
.cred { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 8px; padding: 1px 2px 1px 10px; }
.cred span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.provider-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.key-form > summary { cursor: pointer; color: var(--accent-text); font-size: 13px; width: max-content; }
.key-row { display: flex; gap: 6px; margin-top: 6px; }
.key-row input { flex: 1; min-width: 0; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; font: 13px ui-monospace, Menlo, monospace; outline: none; }
.key-row input:focus { border-color: var(--accent); }
.login-box { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.login-box .key-row { align-self: stretch; margin: 0; }
.login-code { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; background: var(--surface-2); border: 1px dashed var(--accent); border-radius: 8px; padding: 8px 12px; color: var(--text); text-align: left; }
.login-code strong { font: 600 20px ui-monospace, Menlo, monospace; letter-spacing: .08em; color: var(--accent-text); }

#gate { margin: auto; padding: 24px; text-align: center; color: var(--muted); }

/* projects: folders in the sidebar; chats are dragged onto them */
.project { list-style: none; border-radius: 10px; margin-bottom: 2px; transition: background .12s; }
.project.drop-target { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.project-head { display: flex; align-items: center; gap: 2px; }
.project-toggle {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; background: none; border: 0; color: var(--text);
  padding: 8px 10px; border-radius: 8px; font-weight: 600; text-align: left;
}
.project-toggle:hover { background: var(--surface); }
.project-caret { flex: none; width: 12px; color: var(--muted); }
.project-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-name::before { content: "📁"; margin-right: 6px; }
.project-toggle .pulse { flex: none; }
.project-handle { cursor: grab; touch-action: none; }
.workspace-field { display: grid; gap: 4px; margin-block: 8px; }
.workspace-field :is(input, select, textarea) { width: 100%; box-sizing: border-box; }
.inline-agent-image { display: block; max-width: min(100%, 640px); max-height: 60vh; object-fit: contain; margin-block: 6px; border-radius: 8px; }
.project-count { flex: none; margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.project-more { flex: none; width: 30px; height: 30px; font-size: 16px; }
.project-chats { list-style: none; margin: 0; padding: 0 0 4px; }
.project:not(.loose) .project-chats { margin-left: 15px; padding-left: 4px; border-left: 1px solid var(--border); }
.project-empty { color: var(--muted); font-size: 12.5px; padding: 6px 12px; }
.loose-head { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .03em; padding: 10px 12px 4px; }
.chat-item.lifted { background: var(--surface-2); box-shadow: 0 6px 18px rgba(0, 0, 0, .45); }
.chat-item.dragging { opacity: .4; }
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; max-width: 240px; padding: 6px 10px;
  border-radius: 8px; background: var(--surface-2); border: 1px solid var(--accent); color: var(--text);
  font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
body.dragging-chat, body.dragging-chat * { cursor: grabbing !important; }
.sheet-option {
  display: block; width: 100%; text-align: left; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sheet-option:hover { border-color: var(--accent); }
.sheet-option.current { border-color: var(--accent); color: var(--accent-text); }
.sheet-option.current::after { content: " ✓"; }
.sheet-option.danger { color: var(--danger); }
.backup-status { margin: 10px 0 4px; display: flex; flex-direction: column; gap: 4px; }
.backup-status .pulse { display: inline-block; margin-right: 8px; vertical-align: 1px; }
.backup-path a.file-link, .backup-row a.file-link { color: var(--accent-text); text-decoration: underline dotted; text-underline-offset: 3px; overflow-wrap: anywhere; }
.backup-list { display: flex; flex-direction: column; margin-top: 8px; }
.backup-row { padding: 10px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.backup-when { font-weight: 600; }
.backup-row a.file-link { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-size: 13px; text-decoration: none; }
.backup-row a.file-link code { font-size: 12px; text-decoration: underline dotted; text-underline-offset: 3px; overflow-wrap: anywhere; }
.backup-kind { color: var(--text); }
.name-input { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; font: inherit; outline: none; }
.name-input:focus { border-color: var(--accent); }
