:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #151821;
  --panel-2: #1b1f2a;
  --panel-3: #232836;
  --border: #272c3a;
  --border-strong: #353b4d;
  --text: #e7e9ef;
  --text-2: #b4bacb;
  --muted: #838ba0;
  --accent: #f5a524;
  --accent-hover: #ffb944;
  --accent-ink: #1c1303;
  --accent-soft: rgba(245, 165, 36, 0.13);
  --work: #6aa6ff;
  --idea: #c59bff;
  --discussion: #45d0b4;
  --ok: #4fd08a;
  --danger: #ff6f6f;
  --radius: 10px;
  --radius-sm: 7px;
  --mono: "Cascadia Code", "Cascadia Mono", Consolas, "SF Mono", monospace;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 18px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 18px; font-weight: 650; letter-spacing: -0.01em; }
h3 { font-size: 15px; font-weight: 650; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: content-box; border: 2px solid transparent; }

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

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.grow { flex: 1; }
.icon { display: inline-flex; flex: none; }
.fatal { padding: 40px; color: var(--danger); }

#app { display: flex; height: 100vh; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-weight: 550; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--panel-3); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.success { color: var(--ok); border-color: rgba(79, 208, 138, 0.4); background: rgba(79, 208, 138, 0.08); }
.btn.success:hover { background: rgba(79, 208, 138, 0.16); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #2a0808; }
.btn.danger.ghost { background: transparent; color: var(--danger); border-color: rgba(255, 111, 111, 0.4); }
.btn.danger.ghost:hover { background: rgba(255, 111, 111, 0.1); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 34px; height: 34px;
  background: transparent; border: 0; border-radius: var(--radius-sm); color: var(--muted);
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn.xs { width: 20px; height: 20px; border-radius: 5px; }

/* ---------- badges ---------- */

.vbadge {
  display: inline-flex; align-items: center; flex: none;
  padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font: 600 12px/1.5 var(--mono); font-variant-numeric: tabular-nums;
}
.vbadge.sm { font-size: 11px; padding: 1px 7px; }
.vbadge.manual { background: rgba(106, 166, 255, 0.14); color: var(--work); }

.chip { padding: 2px 8px; border-radius: 5px; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; }
.chip.work { background: rgba(106, 166, 255, 0.14); color: var(--work); }
.chip.idea { background: rgba(197, 155, 255, 0.14); color: var(--idea); }
.chip.discussion { background: rgba(69, 208, 180, 0.13); color: var(--discussion); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.open { color: var(--ok); }
.status.closed { color: var(--muted); }

.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 34px; height: 34px; border-radius: 9px;
  color: #fff; font-size: 12.5px; font-weight: 650; letter-spacing: 0.02em;
}

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }

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

.sidebar {
  display: flex; flex-direction: column; flex: none;
  width: 236px; padding: 14px 12px 12px;
  background: var(--panel); border-right: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 16px; }
.brand-mark {
  display: flex; align-items: center; justify-content: center; flex: none;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
}
.brand-mark.lg { width: 46px; height: 46px; border-radius: 13px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 13.5px; font-weight: 650; }
.brand-text span { font-size: 12px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }

.project-switch {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px;
  padding: 10px 12px; margin-bottom: 14px; text-align: left;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.project-switch:hover, .project-switch.active { border-color: var(--border-strong); background: var(--panel-3); }
.ps-label { grid-column: 1 / -1; font-size: 10.5px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.ps-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 10px; text-align: left;
  background: transparent; border: 0; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 550;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-label { flex: 1; }
.nav-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-item.active .nav-count { color: var(--accent); }
.nav-sep { height: 1px; background: var(--border); margin: 8px 6px; }

.offline-note { display: flex; align-items: center; gap: 8px; padding: 0 8px 10px; font-size: 12px; color: var(--muted); }
.user {
  display: flex; align-items: center; gap: 10px; padding: 8px; text-align: left;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted);
}
.user:hover { background: var(--panel-2); color: var(--text); }
.user .avatar { width: 28px; height: 28px; border-radius: 8px; font-size: 11px; }
.user-name { flex: 1; color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- main layouts ---------- */

.main { flex: 1; min-width: 0; display: flex; }
.main.page { flex-direction: column; padding: 26px 32px; overflow-y: auto; position: relative; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; }
.page-sub { color: var(--muted); margin-top: 4px; }

/* ---------- ticket list ---------- */

.list-pane {
  display: flex; flex-direction: column; flex: none;
  width: 328px; background: var(--bg); border-right: 1px solid var(--border);
}
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 14px 12px 18px; }
.list-label { padding: 14px 18px 2px; font-size: 10.5px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.tabs { display: flex; gap: 4px; padding: 0 14px; border-bottom: 1px solid var(--border); flex: none; }
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 8px; margin-bottom: -1px;
  background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-count { padding: 0 7px; border-radius: 999px; background: var(--panel-3); font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--text-2); }

.list-scroll { flex: 1; overflow-y: auto; padding: 8px; }

.ticket-item {
  display: flex; flex-direction: column; gap: 3px; width: 100%;
  padding: 10px 12px; margin-bottom: 2px; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
}
.ticket-item:hover { background: var(--panel); }
.ticket-item.active { background: var(--panel-2); border-color: var(--border-strong); }
.ticket-item.general { width: auto; margin: 0 8px; }
.ti-top { display: flex; align-items: baseline; gap: 8px; }
.ticket-item.general .ti-top { align-items: center; color: var(--discussion); }
.ticket-item.general .ti-name { color: var(--text); }
.ti-no { font-size: 12px; color: var(--muted); flex: none; }
.ti-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ti-time { font-size: 11.5px; color: var(--muted); flex: none; }
.ti-sub { display: flex; align-items: center; gap: 8px; }
.ti-preview { flex: 1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- ticket detail / chat ---------- */

.detail-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--panel); }
.detail-head { display: flex; align-items: flex-start; gap: 16px; padding: 18px 24px 12px; flex: none; }
.dh-main { flex: 1; min-width: 0; }
.dh-kicker { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }
.dh-main h2 { display: flex; align-items: center; gap: 8px; font-size: 20px; overflow-wrap: anywhere; }
.dh-main h2 .icon { color: var(--discussion); }
.dh-meta { margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.dh-actions { display: flex; gap: 8px; flex: none; }

.detail-desc {
  margin: 0 24px 12px; padding: 10px 14px; max-height: 132px; overflow-y: auto; flex: none;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-2); white-space: pre-wrap; overflow-wrap: anywhere;
}
.detail-desc.muted { color: var(--muted); }
.detail-tabs { padding: 0 24px; }

.messages { flex: 1; overflow-y: auto; padding: 14px 24px 8px; }
.day-sep { display: flex; align-items: center; gap: 12px; margin: 10px 0 12px; color: var(--muted); font-size: 11.5px; font-weight: 600; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.sys-msg { margin: 10px 0; text-align: center; font-size: 12.5px; color: var(--muted); }
.sys-time { margin-left: 8px; font-size: 11px; opacity: 0.8; }

.msg { display: flex; gap: 12px; padding: 5px 0 1px; margin-top: 8px; }
.msg.grouped { margin-top: 0; padding: 1px 0; }
.msg-gutter { width: 34px; flex: none; font-size: 10px; color: transparent; text-align: right; padding-top: 4px; white-space: nowrap; }
.msg.grouped:hover .msg-gutter { color: var(--muted); }
.msg-body { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-author { font-weight: 650; }
.msg-time { font-size: 11.5px; color: var(--muted); }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); max-width: 78ch; }

.attachments { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.att-images { display: flex; flex-wrap: wrap; gap: 6px; }
.att-img { padding: 0; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; line-height: 0; }
.att-img:hover { border-color: var(--border-strong); }
.att-img img { display: block; max-width: 300px; max-height: 210px; object-fit: cover; }
.att-file {
  display: flex; align-items: center; gap: 10px; width: fit-content; max-width: 380px;
  padding: 7px 8px 7px 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--muted);
}
.att-info { display: flex; flex-direction: column; min-width: 0; }
.att-name { color: var(--text); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: 11.5px; }

.composer { padding: 8px 24px 12px; flex: none; }
.composer-row {
  display: flex; align-items: flex-end; gap: 6px; padding: 6px;
  background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: var(--radius);
}
.composer-row:focus-within { border-color: var(--accent); }
.composer-input {
  flex: 1; min-height: 34px; max-height: 168px; padding: 7px 4px; resize: none;
  background: transparent; border: 0; outline: 0; line-height: 1.45;
}
.composer-input::placeholder, input::placeholder, textarea::placeholder { color: var(--muted); }
.btn.send { width: 38px; height: 34px; padding: 0; }
.composer-hint { margin-top: 6px; font-size: 11.5px; color: var(--muted); }
.composer-closed { margin: 8px 24px 16px; padding: 12px; text-align: center; color: var(--muted); background: var(--panel-2); border: 1px dashed var(--border-strong); border-radius: var(--radius); flex: none; }

.pending { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.pending-chip {
  display: inline-flex; align-items: center; gap: 7px; max-width: 240px;
  padding: 4px 5px 4px 8px; background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 12.5px; color: var(--text-2);
}
.pending-chip img { width: 22px; height: 22px; border-radius: 4px; object-fit: cover; }
.pending-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.drop-hint {
  display: none; position: absolute; inset: 10px; z-index: 5;
  align-items: center; justify-content: center; gap: 10px; flex-direction: column;
  background: rgba(15, 17, 21, 0.86); border: 2px dashed var(--accent); border-radius: var(--radius);
  color: var(--accent); font-weight: 650; pointer-events: none;
}
.dragging > .drop-hint { display: flex; }

/* ---------- file lists ---------- */

.file-list { flex: 1; overflow-y: auto; padding: 12px 24px; }
.file-list.flat { flex: none; overflow: visible; padding: 0; margin-top: 16px; }
.file-row { display: flex; align-items: center; gap: 12px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.file-row:last-child { border-bottom: 0; }
.file-thumb {
  display: flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; padding: 0; overflow: hidden;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--muted);
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 12px; color: var(--muted); }

/* ---------- mailbox ---------- */

.notice {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 14px;
  background: var(--accent-soft); border-radius: var(--radius-sm); color: var(--text-2); font-size: 13px;
}
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px; flex: none;
  padding: 26px; background: var(--panel); border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  color: var(--muted);
}
.dropzone strong { color: var(--text); font-weight: 600; margin-top: 4px; }
.dropzone:hover, .dragging .dropzone { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ---------- projects ---------- */

.projects-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.project-card {
  display: flex; flex-direction: column; gap: 10px; padding: 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.project-card.current { border-color: var(--accent); }
.pc-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pc-top h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-desc { color: var(--text-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; min-height: 19px; }
.pc-desc.muted { color: var(--muted); }
.pc-stats { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.pc-stats b { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }
.pc-actions { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.current-tag { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-size: 13px; font-weight: 600; }

.version-panel { padding: 18px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.vp-label { display: flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 650; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.vp-label.history { margin: 20px 0 6px; }
.vp-version { font-size: 38px; font-weight: 650; letter-spacing: -0.02em; color: var(--accent); margin: 6px 0 4px; overflow-wrap: anywhere; line-height: 1.15; }
.vp-note { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.vp-bumps { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.vp-bumps .btn { justify-content: space-between; }
.vp-history { max-height: 340px; overflow-y: auto; }
.vh-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.vh-row:last-child { border-bottom: 0; }
.vh-main { display: flex; flex-direction: column; min-width: 0; }
.vh-reason { font-size: 13px; overflow-wrap: anywhere; }
.vh-meta { font-size: 11.5px; color: var(--muted); }

/* ---------- empty states ---------- */

.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; flex: 1; padding: 40px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 17px; }
.empty p { max-width: 380px; margin-bottom: 6px; }
.empty.small { padding: 28px 16px; font-size: 13px; }

/* ---------- onboarding ---------- */

.onboarding { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; overflow-y: auto; }
.onboard-card {
  display: flex; flex-direction: column; gap: 14px; width: 440px; max-width: 100%;
  padding: 30px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
}
.onboard-card h1 { font-size: 22px; }

/* ---------- forms + modals ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-label em { font-style: normal; font-weight: 400; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); }
.field input, .field textarea {
  width: 100%; padding: 9px 11px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  outline: 0; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 13px; min-height: 0; }
.form-error:empty { display: none; }

.backdrop {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(6, 7, 10, 0.66);
}
.modal {
  display: flex; flex-direction: column; gap: 14px; width: 480px; max-width: 100%; max-height: 100%; overflow-y: auto;
  padding: 24px; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}
.modal h3 { font-size: 17px; }
.modal-intro { color: var(--muted); font-size: 13.5px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

.lightbox { display: flex; flex-direction: column; gap: 12px; max-width: 100%; max-height: 100%; align-items: center; }
.lightbox img { max-width: min(1100px, 92vw); max-height: calc(100vh - 130px); border-radius: var(--radius-sm); object-fit: contain; background: var(--panel); }
.lightbox-bar { display: flex; align-items: center; gap: 10px; }
.lightbox-name { color: var(--text-2); margin-right: 8px; }

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

#toasts { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  max-width: 440px; padding: 10px 14px; overflow-wrap: anywhere;
  background: var(--panel-3); border: 1px solid var(--border-strong); border-left: 3px solid var(--muted); border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); font-size: 13px;
  animation: toast-in 0.18s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1180px) {
  .projects-layout { grid-template-columns: 1fr; }
  .list-pane { width: 290px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- accounts + connection ---------- */

.link-btn { background: none; border: 0; padding: 4px; color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; align-self: center; }
.link-btn:hover { color: var(--text); }
.btn:disabled { opacity: 0.6; cursor: default; }
.offline-note.live .dot, .dot.live { background: var(--ok); }
.user-action { font-size: 12px; color: var(--muted); }
.user:hover .user-action { color: var(--text); }

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

.mobile-top, .back-btn { display: none; }

#app { height: 100dvh; }

@media (max-width: 760px) {
  #app { flex-direction: column; }

  .mobile-top {
    display: flex; align-items: center; gap: 8px; flex: none;
    padding: 8px 10px 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
    background: var(--panel); border-bottom: 1px solid var(--border);
  }
  .mt-project {
    display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; height: 40px; padding: 0 10px; text-align: left;
    background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius);
  }
  .mt-project .ps-name { flex: 1; }
  .mt-user { background: none; border: 0; padding: 3px; display: flex; }

  /* The sidebar becomes a bottom tab bar. */
  .sidebar {
    order: 3; width: 100%; flex-direction: row; padding: 4px 6px; padding-bottom: max(4px, env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border);
  }
  .sidebar .brand, .sidebar .project-switch, .sidebar .offline-note, .sidebar .user, .sidebar .nav-sep, .sidebar > .grow { display: none; }
  .nav { flex-direction: row; flex: 1; gap: 0; }
  .nav-item { flex: 1; flex-direction: column; justify-content: center; gap: 2px; height: 52px; padding: 0 2px; position: relative; }
  .nav-label { flex: none; font-size: 10.5px; white-space: nowrap; }
  .nav-item.active { background: transparent; }
  .nav-count { position: absolute; top: 4px; left: calc(50% + 8px); min-width: 16px; padding: 0 4px; border-radius: 999px; background: var(--panel-3); font-size: 10px; text-align: center; }

  .main { order: 2; min-height: 0; }
  .main.page { padding: 16px; }
  .page-head { flex-wrap: wrap; }
  .page-head h1 { font-size: 20px; }

  /* Tickets: list and open ticket take turns filling the screen. */
  .list-pane { width: 100%; border-right: 0; }
  .split .detail-pane { display: none; }
  .split.show-detail .list-pane { display: none; }
  .split.show-detail .detail-pane { display: flex; }
  .back-btn { display: inline-flex; margin: -4px -6px 0 -8px; }

  .detail-head { padding: 12px 14px 10px; gap: 8px; flex-wrap: wrap; }
  .dh-main { flex-basis: 0; }
  .dh-main h2 { font-size: 17px; }
  .dh-actions { width: 100%; }
  .dh-actions .btn { flex: 1; height: 36px; }
  .detail-desc { margin: 0 14px 10px; max-height: 96px; }
  .detail-tabs { padding: 0 14px; }
  .messages { padding: 10px 14px 6px; }
  .file-list { padding: 8px 14px; }
  .composer { padding: 6px 10px 10px; }
  .composer-hint { display: none; }
  .composer-closed { margin: 6px 10px 10px; }
  .att-img img { max-width: min(300px, 62vw); }
  .att-file { max-width: 100%; }

  .file-row { flex-wrap: wrap; }
  .file-main { flex-basis: 50%; }
  .projects-layout { grid-template-columns: 1fr; }
  .project-grid { grid-template-columns: 1fr; }
  .vp-version { font-size: 32px; }

  .backdrop { padding: 12px; align-items: flex-end; }
  .modal { width: 100%; padding: 20px; }
  .onboarding { padding: 14px; align-items: flex-start; }
  .onboard-card { padding: 22px; }
  #toasts { bottom: 132px; width: calc(100% - 24px); }

  /* 16px inputs stop iOS from zooming the page when a field is focused. */
  .field input, .field textarea, .composer-input { font-size: 16px; }
  .btn { height: 40px; }
  .btn.sm { height: 34px; }
  .tab { height: 40px; }
  .icon-btn { width: 40px; height: 40px; }
  .icon-btn.xs { width: 24px; height: 24px; }
}

/* ---------- AI agent ---------- */
.agent-avatar { background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(245, 165, 36, 0.35); }
.ai-tag { padding: 0 6px; border-radius: 4px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; background: var(--accent-soft); color: var(--accent); }
.agent-busy { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; font-size: 12.5px; color: var(--muted); }
.agent-busy .icon { color: var(--accent); }
.msg-text.job-update { padding-left: 10px; border-left: 3px solid var(--border-strong); }
.msg-text.job-update.working { border-left-color: var(--work); }
.msg-text.job-update.needs_input { border-left-color: var(--accent); }
.msg-text.job-update.done { border-left-color: var(--ok); }
.msg-text.job-update.failed { border-left-color: var(--danger); }

.proposal { margin-top: 8px; max-width: 78ch; padding: 12px 14px; background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: var(--radius); }
.proposal.pending { border-color: rgba(245, 165, 36, 0.55); }
.proposal.cancelled, .proposal.replaced { opacity: 0.6; }
.proposal-label { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.proposal-text { margin-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); }
.proposal-files { margin-top: 6px; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.proposal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.proposal-note { font-size: 12px; color: var(--muted); }
.proposal-state { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.job-pill { padding: 2px 9px; border-radius: 999px; font-weight: 650; background: var(--panel-3); color: var(--text-2); }
.proposal-state.working .job-pill { background: rgba(106, 166, 255, 0.14); color: var(--work); }
.proposal-state.needs_input .job-pill { background: var(--accent-soft); color: var(--accent); }
.proposal-state.done .job-pill { background: rgba(79, 208, 138, 0.12); color: var(--ok); }
.proposal-state.failed .job-pill { background: rgba(255, 111, 111, 0.12); color: var(--danger); }
.msg-text.job-update { margin-top: 5px; }

/* ---------- wiki ---------- */
.wiki-tools { display: flex; flex-direction: column; gap: 8px; padding: 0 14px 10px 18px; border-bottom: 1px solid var(--border); flex: none; }
.wiki-filter {
  width: 100%; height: 34px; padding: 0 10px; font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none;
}
.wiki-filter:focus { border-color: var(--accent); }
.wiki-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.wiki-status-text { flex: 1; min-width: 0; }
.wiki-status.busy { color: var(--accent); }
.wiki-status.error { color: var(--danger); }
.wiki-status .link-btn { flex: none; padding: 0; font-size: 12px; }
.wiki-group { display: flex; align-items: center; gap: 8px; padding: 14px 12px 4px; }
.wiki-count { font-weight: 500; letter-spacing: 0; color: var(--muted); opacity: 0.8; }

.chip.note-live { background: rgba(79, 208, 138, 0.12); color: var(--ok); }
.chip.note-planned { background: rgba(197, 155, 255, 0.14); color: var(--idea); }
.chip.note-unfiled { background: var(--accent-soft); color: var(--accent); }
.chip.note-removed { background: var(--panel-3); color: var(--muted); }
.note-path { font-size: 12px; overflow-wrap: anywhere; }
.note-updated { font-size: 12px; white-space: nowrap; }
.wiki .dh-kicker { flex-wrap: wrap; row-gap: 6px; }
.wiki .dh-meta { font-size: 13.5px; color: var(--text-2); max-width: 78ch; }

.note-scroll { flex: 1; overflow-y: auto; padding: 4px 24px 28px; border-top: 1px solid var(--border); }
.note-body { max-width: 78ch; line-height: 1.6; color: var(--text-2); overflow-wrap: anywhere; }
.note-body > :first-child { margin-top: 16px; }
.note-body h2, .note-body h3 { margin: 26px 0 8px; font-size: 16px; color: var(--text); }
.note-body h4, .note-body h5, .note-body h6 { margin: 20px 0 6px; font-size: 14px; color: var(--text); }
.note-body p { margin: 10px 0; }
.note-body ul, .note-body ol { margin: 10px 0; padding-left: 22px; }
.note-body li { margin: 4px 0; }
.note-body li.nested { margin-left: 20px; }
.note-body strong { color: var(--text); font-weight: 650; }
.note-body code, .note-foot code { padding: 1px 5px; border-radius: 4px; background: var(--panel-3); font-family: var(--mono); font-size: 0.9em; color: var(--text); }
.note-body pre { margin: 12px 0; padding: 12px 14px; overflow-x: auto; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.note-body pre code { padding: 0; background: none; }
.note-body blockquote { margin: 12px 0; padding: 8px 14px; border-left: 3px solid var(--border-strong); background: var(--panel-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--muted); }
.note-body hr { margin: 20px 0; border: 0; border-top: 1px solid var(--border); }
.note-body a, .note-foot a { color: var(--accent); text-decoration: none; }
.note-body a:hover, .note-foot a:hover { text-decoration: underline; text-underline-offset: 3px; }
.md-table { margin: 12px 0; overflow-x: auto; }
.md-table table { border-collapse: collapse; font-size: 13px; }
.md-table th, .md-table td { padding: 6px 12px; border: 1px solid var(--border); text-align: left; vertical-align: top; overflow-wrap: normal; }
.md-table th { background: var(--panel-2); color: var(--text); font-weight: 650; }
.note-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; max-width: 78ch; margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13px; }
.note-foot + .note-foot { margin-top: 12px; }
.note-foot-label { flex-basis: 100%; font-size: 10.5px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

@media (max-width: 760px) {
  .wiki-tools { padding: 0 12px 10px; }
  .wiki-filter { height: 40px; font-size: 16px; }
  .note-scroll { padding: 2px 14px 22px; }
}
