:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev2: #1c2128;
  --bg-hover: #21262d;
  --border: #30363d;
  --border-muted: #21262d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-faint: #6e7681;
  --accent: #2f81f7;
  --accent-muted: rgba(56, 139, 253, 0.15);
  --accent-fg: #ffffff;
  --green: #3fb950;
  --green-muted: rgba(46, 160, 67, 0.15);
  --red: #f85149;
  --red-muted: rgba(248, 81, 73, 0.15);
  --yellow: #d29922;
  --yellow-muted: rgba(187, 128, 9, 0.15);
  --purple: #a371f7;
  --purple-muted: rgba(163, 113, 247, 0.15);
  --user-bg: #1f2a3a;
  --code-bg: #0b0f14;
  --shadow: 0 8px 24px rgba(1, 4, 9, 0.6);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Helvetica, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f6f8fa;
  --bg-elev2: #eef1f4;
  --bg-hover: #eaeef2;
  --border: #d0d7de;
  --border-muted: #e5e9ed;
  --text: #1f2328;
  --text-dim: #59636e;
  --text-faint: #818b98;
  --accent: #0969da;
  --accent-muted: rgba(9, 105, 218, 0.1);
  --green: #1a7f37;
  --green-muted: rgba(26, 127, 55, 0.1);
  --red: #cf222e;
  --red-muted: rgba(207, 34, 46, 0.1);
  --yellow: #9a6700;
  --yellow-muted: rgba(154, 103, 0, 0.1);
  --purple: #8250df;
  --purple-muted: rgba(130, 80, 223, 0.1);
  --user-bg: #ddf4ff;
  --code-bg: #f6f8fa;
  --shadow: 0 8px 24px rgba(140, 149, 159, 0.3);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  overflow: hidden;
}

.boot,
.boot-wait {
  margin: auto;
  color: var(--text-dim);
}

a {
  color: var(--accent);
}

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

button {
  cursor: pointer;
}

code,
pre,
kbd,
.mono {
  font-family: var(--mono);
  font-size: 0.88em;
}

.dim {
  color: var(--text-dim);
}
.faint {
  color: var(--text-faint);
}
.grow {
  flex: 1;
  min-width: 0;
}
.row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wrap {
  flex-wrap: wrap;
}
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hidden {
  display: none !important;
}

/* ---------- buttons & inputs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev2);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  user-select: none;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover {
  background: var(--bg-hover);
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
.btn.primary:hover {
  filter: brightness(1.1);
}
.btn.danger {
  color: var(--red);
}
.btn.danger.solid {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.btn.green {
  background: #238636;
  border-color: #238636;
  color: #fff;
}
.btn.small {
  min-height: 28px;
  padding: 3px 10px;
  font-size: 13px;
}
a.btn {
  text-decoration: none;
}
.btn.block {
  width: 100%;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
}
.btn.ghost:hover {
  background: var(--bg-hover);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
}
.icon-btn:hover,
.icon-btn.active {
  background: var(--bg-hover);
  color: var(--text);
}
.icon-btn svg,
.btn svg {
  width: 20px;
  height: 20px;
}
.btn.small svg {
  width: 16px;
  height: 16px;
}

.input,
.textarea,
.select {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-size: 16px; /* prevents iOS zoom */
}
.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}
.textarea {
  resize: vertical;
  min-height: 80px;
}
label.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
}
label.field .input,
label.field .textarea,
label.field .select,
.field .select {
  font-weight: 400;
}
label.field .hint {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 13px;
}
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
}
.check input {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elev2);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 100%;
}
button.chip:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.chip svg {
  width: 14px;
  height: 14px;
  flex: none;
}
.chip.warn {
  color: var(--yellow);
  border-color: var(--yellow);
  background: var(--yellow-muted);
}
.chip.danger {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-muted);
}
.chip.accent {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-muted);
}
.chip.purple {
  color: var(--purple);
  border-color: var(--purple);
  background: var(--purple-muted);
}
.chip.green {
  color: var(--green);
  border-color: var(--green);
  background: var(--green-muted);
}

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.segmented button {
  flex: 1;
  padding: 8px 6px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
}
.segmented button + button {
  border-left: 1px solid var(--border);
}
.segmented button.on {
  background: var(--accent-muted);
  color: var(--accent);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 700;
  background: var(--yellow);
  color: #000;
}

.spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner.small {
  width: 12px;
  height: 12px;
  border-width: 2px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex: none;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

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

.layout {
  display: flex;
  width: 100%;
  height: 100%;
}
.sidebar {
  width: 340px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  min-height: 0;
}
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
@media (max-width: 899px) {
  .layout .sidebar {
    display: none;
    width: 100%;
    border-right: none;
  }
  .layout.home .sidebar {
    display: flex;
  }
  .layout.home .main {
    display: none;
  }
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  padding: calc(6px + var(--safe-top)) 8px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.topbar .title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0 4px;
}
.topbar .title strong {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .title small {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.only-mobile {
  display: none;
}
@media (max-width: 899px) {
  .only-mobile {
    display: inline-flex;
  }
  .only-desktop {
    display: none !important;
  }
}

.scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(24px + var(--safe-bottom));
}
.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 20px 4px 8px;
}
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  overflow: hidden;
}
.card + .card {
  margin-top: 12px;
}
.card-body {
  padding: 14px;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-top: 1px solid var(--border-muted);
  background: transparent;
  text-align: left;
  color: var(--text);
  min-height: 48px;
}
.list-item:first-child {
  border-top: none;
}
button.list-item:hover,
a.list-item:hover {
  background: var(--bg-hover);
}
.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-dim);
}

/* ---------- sessions list ---------- */

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(8px + var(--safe-top)) 8px 8px 14px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  flex: 1;
}
.brand img {
  width: 24px;
  height: 24px;
}
.search {
  padding: 10px 12px 6px;
}
.session-group {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 12px 16px 4px;
}
.session-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  text-align: left;
  color: var(--text);
  border-left: 3px solid transparent;
}
.session-row:hover {
  background: var(--bg-hover);
}
.session-row.active {
  background: var(--accent-muted);
  border-left-color: var(--accent);
}
.session-row .t {
  font-weight: 500;
  font-size: 14.5px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.session-row .m {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
}
.session-row .status {
  width: 18px;
  flex: none;
  display: flex;
  justify-content: center;
  padding-top: 3px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  opacity: 0.5;
}
.dot.live {
  background: var(--accent);
  opacity: 1;
}

/* ---------- conversation ---------- */

.conn-banner {
  flex: none;
  padding: 6px 12px;
  font-size: 13px;
  text-align: center;
  background: var(--yellow-muted);
  color: var(--yellow);
  border-bottom: 1px solid var(--border);
}
.warn-banner {
  flex: none;
  padding: 8px 14px;
  font-size: 13px;
  background: var(--yellow-muted);
  color: var(--yellow);
  border-bottom: 1px solid var(--border);
}
.timeline {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  position: relative;
}
.timeline-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.load-older {
  align-self: center;
  margin: 4px 0 10px;
}

.msg-user {
  align-self: flex-end;
  max-width: 88%;
  background: var(--user-bg);
  border-radius: 14px 14px 4px 14px;
  padding: 8px 13px;
  margin: 10px 0 4px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-user .attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.msg-user.system {
  align-self: center;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  font-size: 13px;
  max-width: 100%;
}
.mode-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--purple);
  margin-right: 6px;
}

.msg-assistant {
  padding: 2px 2px;
  word-break: break-word;
}

.markdown > :first-child {
  margin-top: 0;
}
.markdown > :last-child {
  margin-bottom: 0;
}
.markdown p,
.markdown ul,
.markdown ol,
.markdown pre,
.markdown blockquote,
.markdown table {
  margin: 0 0 10px;
}
.markdown ul,
.markdown ol {
  padding-left: 22px;
}
.markdown li + li {
  margin-top: 2px;
}
.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4 {
  margin: 14px 0 8px;
  line-height: 1.3;
}
.markdown h1 {
  font-size: 1.35em;
}
.markdown h2 {
  font-size: 1.2em;
}
.markdown h3 {
  font-size: 1.07em;
}
.markdown code {
  background: var(--bg-elev2);
  padding: 1px 5px;
  border-radius: 5px;
}
.markdown pre {
  background: var(--code-bg);
  border: 1px solid var(--border-muted);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
}
.markdown pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}
.markdown blockquote {
  border-left: 3px solid var(--border);
  padding-left: 12px;
  color: var(--text-dim);
}
.markdown table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  font-size: 14px;
}
.markdown th,
.markdown td {
  border: 1px solid var(--border);
  padding: 5px 10px;
}
.markdown th {
  background: var(--bg-elev);
}
.markdown img {
  max-width: 100%;
}
.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
}

.cursor::after {
  content: "▋";
  margin-left: 2px;
  color: var(--accent);
  animation: pulse 1s infinite;
}

.tool {
  border-radius: 8px;
  font-size: 14px;
}
.tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 6px;
  border: none;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  color: var(--text);
  min-height: 34px;
}
.tool-head:hover {
  background: var(--bg-hover);
}
.tool-icon {
  width: 18px;
  height: 18px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tool-icon svg {
  width: 16px;
  height: 16px;
}
.tool-icon.done {
  color: var(--green);
}
.tool-icon.failed {
  color: var(--red);
}
.tool-title {
  font-weight: 600;
  white-space: nowrap;
  flex: none;
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-summary {
  flex: 1;
  min-width: 0;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-meta {
  flex: none;
  font-size: 12px;
  color: var(--text-faint);
}
.tool-body {
  margin: 2px 0 8px 26px;
  border-left: 2px solid var(--border);
  padding-left: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tool-sub {
  margin-left: 26px;
  font-size: 12.5px;
  color: var(--text-dim);
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
}
.label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 3px;
}
pre.out {
  margin: 0;
  max-height: 340px;
  overflow: auto;
  background: var(--code-bg);
  border: 1px solid var(--border-muted);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-all;
}
pre.out.nowrap {
  white-space: pre;
  word-break: normal;
}
.diff {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.45;
  background: var(--code-bg);
  border: 1px solid var(--border-muted);
  border-radius: 8px;
  overflow: auto;
  max-height: 480px;
}
.diff.tall {
  max-height: none;
}
.diff div {
  white-space: pre;
  padding: 0 10px;
  min-height: 1.45em;
}
.diff .add {
  background: var(--green-muted);
  color: var(--green);
}
.diff .del {
  background: var(--red-muted);
  color: var(--red);
}
.diff .hunk {
  color: var(--purple);
  background: var(--purple-muted);
}
.diff .meta {
  color: var(--text-faint);
}
.diff .fileh {
  color: var(--text);
  font-weight: 700;
  background: var(--bg-elev2);
}

.reasoning {
  font-size: 13.5px;
  color: var(--text-dim);
}
.reasoning .tool-head {
  color: var(--text-dim);
}
.reasoning-body {
  margin: 0 0 6px 26px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
  font-style: italic;
  white-space: pre-wrap;
}

.info {
  align-self: center;
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
  padding: 2px 10px;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
}
.info.error {
  color: var(--red);
  background: var(--red-muted);
  border-radius: 8px;
  padding: 6px 12px;
  align-self: stretch;
  text-align: left;
}
.info.warning {
  color: var(--yellow);
}
.info.notice {
  align-self: stretch;
  text-align: left;
  border-left: 2px solid var(--border);
  padding-left: 10px;
}

.command-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  overflow: hidden;
  margin: 6px 0;
}
.command-card .h {
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-muted);
}
.command-card .b {
  padding: 10px 12px;
  overflow-x: auto;
}
.command-card .b pre.plain {
  margin: 0;
  white-space: pre-wrap;
  font-size: 13px;
}

.jump {
  position: absolute;
  right: 16px;
  bottom: 12px;
  z-index: 5;
  box-shadow: var(--shadow);
}

/* ---------- bottom area: pending requests, status and composer ---------- */

.bottom {
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  padding-bottom: var(--safe-bottom);
}
.bottom-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pending-wrap {
  max-height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pending {
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pending.question {
  border-color: var(--accent);
}
.pending h4 {
  margin: 0;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pending .intent {
  font-size: 13.5px;
  color: var(--text-dim);
}
.pending .opts {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pending .opts .btn {
  justify-content: flex-start;
  text-align: left;
  white-space: normal;
}
.opt-num {
  display: inline-flex;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: var(--bg-hover);
  font-size: 12px;
  flex: none;
}
.radio-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.radio-list label {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 400;
}
.radio-list label.on {
  border-color: var(--accent);
  background: var(--accent-muted);
}
.radio-list input {
  margin-top: 4px;
  accent-color: var(--accent);
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  min-height: 28px;
  overflow-x: auto;
  scrollbar-width: none;
}
.statusbar::-webkit-scrollbar {
  display: none;
}
.status-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 4px 6px;
  min-width: 0;
  margin-left: auto;
}
/* The context counter and AI credits stay side by side; on narrow phones they move to a line of their own. */
.usage-chips {
  display: flex;
  gap: 6px;
}
.model-name {
  max-width: 150px;
}
@media (max-width: 480px) {
  .hide-narrow {
    display: none;
  }
  .model-name {
    max-width: 105px;
  }
  /* While Copilot works, its status (intent, streamed size, time) gets a line of its own, like the CLI's status line. */
  .statusbar {
    flex-wrap: wrap;
    row-gap: 4px;
  }
  .statusbar > .working {
    flex-basis: 100%;
  }
}
.working {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  min-width: 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  padding: 4px;
}
.composer:focus-within {
  border-color: var(--accent);
}
.composer textarea {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  padding: 8px 6px;
  max-height: 40vh;
  font-size: 16px;
  line-height: 1.4;
}
.composer .icon-btn {
  width: 38px;
  height: 38px;
}
.send-btn {
  background: var(--accent) !important;
  color: #fff !important;
  border-radius: 10px !important;
}
.send-btn:disabled {
  opacity: 0.4;
}
.stop-btn {
  background: var(--red) !important;
  color: #fff !important;
  border-radius: 10px !important;
}
.composer.shell {
  border-color: var(--yellow);
}
.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.attach {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
  max-width: 220px;
  background: var(--bg);
}
.attach img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 5px;
}
.attach button {
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 2px 4px;
}

.palette {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  max-height: 260px;
  overflow-y: auto;
}
.palette button {
  display: flex;
  gap: 10px;
  align-items: baseline;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  text-align: left;
  color: var(--text);
}
.palette button.sel,
.palette button:hover {
  background: var(--accent-muted);
}
.palette .cmd {
  font-family: var(--mono);
  font-size: 13.5px;
  font-weight: 600;
  flex: none;
}
.palette .desc {
  font-size: 12.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- sheets, menus, toasts ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(1, 4, 9, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.15s ease;
}
@media (min-width: 700px) {
  .overlay {
    align-items: center;
  }
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  animation: rise 0.18s ease;
  padding-bottom: var(--safe-bottom);
}
.sheet.wide {
  max-width: 980px;
}
@media (min-width: 700px) {
  .sheet {
    border-radius: 14px;
    padding-bottom: 0;
  }
}
@keyframes rise {
  from {
    transform: translateY(24px);
    opacity: 0.6;
  }
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 18px;
  border-bottom: 1px solid var(--border);
}
.sheet-head h3 {
  flex: 1;
  margin: 0;
  font-size: 16px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sheet-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.menu {
  position: fixed;
  z-index: 60;
  min-width: 220px;
  max-width: calc(100vw - 16px);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
  animation: fade 0.1s ease;
}
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 14px;
}
.menu button:hover {
  background: var(--bg-hover);
}
.menu button.danger {
  color: var(--red);
}
.menu button svg {
  width: 17px;
  height: 17px;
  color: var(--text-dim);
}
.menu button .check-mark {
  margin-left: auto;
  color: var(--accent);
}
.menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}
.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 59;
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: max-content;
  max-width: calc(100vw - 24px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: rise 0.18s ease;
  white-space: pre-wrap;
  word-break: break-word;
}
.toast.error {
  border-color: var(--red);
  color: var(--red);
}
.toast.success {
  border-color: var(--green);
}

/* ---------- model picker ---------- */

.model-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  text-align: left;
  color: var(--text);
}
.model-row.on {
  border-color: var(--accent);
  background: var(--accent-muted);
}
.model-row:disabled {
  opacity: 0.45;
}
.model-row .n {
  font-weight: 600;
  font-size: 14.5px;
}
.model-row .d {
  font-size: 12px;
  color: var(--text-dim);
}
.price {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 1px;
}

/* ---------- git ---------- */

.git-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  border-top: 1px solid var(--border-muted);
  min-height: 44px;
}
.git-file:first-child {
  border-top: none;
}
.git-file .path {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  text-align: left;
  color: var(--text);
  padding: 4px 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;
}
.git-file .path span {
  direction: ltr;
  unicode-bidi: plaintext;
}
.st {
  width: 20px;
  flex: none;
  text-align: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
}
.st.M {
  color: var(--yellow);
}
.st.A,
.st.U\? {
  color: var(--green);
}
.st.D {
  color: var(--red);
}
.st.R,
.st.C {
  color: var(--purple);
}
.st.X {
  color: var(--red);
}
.branch-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.commit {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 12px;
  border-top: 1px solid var(--border-muted);
  font-size: 13.5px;
  width: 100%;
  border-left: none;
  border-right: none;
  border-bottom: none;
  background: none;
  color: var(--text);
  text-align: left;
}
.commit:first-child {
  border-top: none;
}
.commit:hover {
  background: var(--bg-hover);
}
.commit .h {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 12.5px;
  flex: none;
}
.output-log {
  margin: 0;
  max-height: 200px;
  overflow: auto;
  font-size: 12.5px;
  background: var(--code-bg);
  border-radius: 8px;
  padding: 8px 10px;
  white-space: pre-wrap;
}

/* ---------- terminal ---------- */

.term-wrap {
  flex: 1;
  min-height: 0;
  background: #0b0f14;
  padding: 4px 0 0 4px;
  position: relative;
}
.term-wrap .xterm {
  height: 100%;
}
.keybar {
  flex: none;
  display: flex;
  gap: 4px;
  padding: 6px;
  padding-bottom: calc(6px + var(--safe-bottom));
  overflow-x: auto;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  scrollbar-width: none;
}
.keybar::-webkit-scrollbar {
  display: none;
}
.keybar button {
  flex: none;
  min-width: 42px;
  height: 36px;
  padding: 0 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-elev2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}
.keybar button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.term-status {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 3;
}

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

.login {
  margin: auto;
  width: 100%;
  max-width: 380px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login .logo {
  width: 64px;
  height: 64px;
  align-self: center;
}
.login h1 {
  text-align: center;
  margin: 0 0 6px;
  font-size: 22px;
}
.login .err {
  color: var(--red);
  font-size: 14px;
  text-align: center;
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  font-size: 13.5px;
}
.kv dt {
  color: var(--text-dim);
}
.kv dd {
  margin: 0;
  word-break: break-all;
}

.dir-list {
  border: 1px solid var(--border);
  border-radius: 9px;
  max-height: 300px;
  overflow-y: auto;
}
.dir-list button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-top: 1px solid var(--border-muted);
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 14px;
}
.dir-list button:first-child {
  border-top: none;
}
.dir-list button:hover {
  background: var(--bg-hover);
}
.dir-list button.on {
  background: var(--accent-muted);
}
.dir-list svg {
  width: 16px;
  height: 16px;
  color: var(--text-dim);
  flex: none;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-track {
  background: transparent;
}
