:root {
  --bg: #121110;
  --panel: #1f1d1a;
  --panel-2: #2a2724;
  --border: #36322d;
  --text: #e8e4dc;
  --muted: #9a938a;
  --accent: #e8875b;
  --accent-text: #1a1917;
  --danger: #e5604f;
  --ok: #7fbf6a;
  --term-bg: #1a1917;
  --radius: 8px;
  --app-height: 100dvh;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 6px;
  padding: 6px 10px;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }

.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  white-space: nowrap;
}
.danger-btn { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.icon-btn { background: transparent; border-color: transparent; font-size: 18px; padding: 4px 8px; line-height: 1; }
.icon-btn.small { font-size: 15px; }
.danger-link { background: transparent; border: 0; color: var(--danger); font-size: 12px; padding: 4px 6px; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0 0; white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 8px 10px; }
.grow { flex: 1; }
.spacer { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.break { overflow-wrap: anywhere; }
[hidden] { display: none !important; }

input, textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- Đăng nhập ---------- */

.login-page {
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  display: grid;
  gap: 14px;
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card label, dialog label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card button { padding: 10px; }
.login-card button[type=submit] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

/* ---------- App ---------- */

#app {
  height: var(--app-height);
  overflow: hidden;
}
.view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.brand { font-size: 16px; padding-left: 6px; }
.project-title { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; flex: none; }

.tabs {
  flex: 1;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  flex: none;
}
.tab.active { border-color: var(--accent); background: var(--panel-2); }
.tab-label { border: 0; background: transparent; padding: 5px 4px 5px 10px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-close { border: 0; background: transparent; color: var(--muted); padding: 5px 8px; }
.tab-close:hover { color: var(--text); }

.body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.sidebar {
  width: 340px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-open .sidebar { display: flex; }
.sidebar-title { display: none; padding: 10px 12px 0; font-weight: 600; }
.panel-tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border); flex: none; }
.panel-tabs button { flex: 1; background: transparent; }
.panel-tabs button.active { background: var(--panel-2); border-color: var(--accent); }
.panel { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; }
.panel-toolbar { display: flex; align-items: center; gap: 4px; padding: 8px; flex-wrap: wrap; }
.panel-toolbar button { padding: 5px 9px; font-size: 13px; }
.session-list, .file-list, .git-list, .project-list { list-style: none; margin: 0; padding: 0 6px; display: grid; gap: 2px; }
.session-item { display: flex; align-items: center; gap: 4px; border-radius: 6px; }
.session-item.active { background: var(--panel-2); }
.session-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: 0;
  background: transparent;
  display: grid;
  padding: 8px 6px;
}
.session-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { color: var(--muted); font-size: 12px; padding: 12px; margin: auto 0 0; }

/* ---------- Danh sách dự án ---------- */

.projects-body { flex: 1; overflow-y: auto; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; display: grid; align-content: start; gap: 12px; }
.projects-head { display: flex; gap: 8px; }
.projects-head input { flex: 1; min-width: 0; }
.project-list { padding: 0; gap: 6px; }
.project-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: inherit;
  text-decoration: none;
}
.project-card:hover { border-color: var(--muted); }
.project-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-meta { grid-column: 1; color: var(--muted); font-size: 12px; }
.dot { grid-column: 2; grid-row: 1 / span 2; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }

/* ---------- File ---------- */

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 0 10px 6px; font-size: 13px; }
.crumb { border: 0; background: transparent; padding: 2px 4px; color: var(--accent); }
.crumbs .sep { color: var(--muted); }
.entry { display: flex; align-items: center; border-radius: 6px; }
.entry:hover { background: var(--panel-2); }
.entry-open {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 8px;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 6px;
}
.entry-icon { grid-row: span 2; font-size: 15px; }
.entry-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta { grid-column: 2; font-size: 11px; color: var(--muted); }
.progress { margin: 6px 8px; padding: 6px 10px; border-radius: 6px; background: var(--panel-2); font-size: 12px; }
.panel.dropping { outline: 2px dashed var(--accent); outline-offset: -6px; }

/* ---------- Git ---------- */

.git-info { padding: 0 10px 8px; display: grid; gap: 2px; }
.branch { font-weight: 600; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 10px 10px 4px; }
.change, .commit {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 5px 6px;
  border-radius: 6px;
}
.change { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.change:hover, .commit:hover { background: var(--panel-2); }
.commit { display: grid; gap: 1px; }
.commit-subject { font-size: 13px; }
.badge { flex: none; font-size: 10px; padding: 1px 5px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--border); min-width: 46px; text-align: center; }
.badge.s-A, .badge.s-\? { color: var(--ok); border-color: currentColor; }
.badge.s-D { color: var(--danger); border-color: currentColor; }
.badge.s-M, .badge.s-R { color: #d9b45b; border-color: currentColor; }
.badge.s-U { color: #fff; background: var(--danger); }
.commit-form { display: grid; gap: 6px; padding: 8px; }
.commit-form textarea { resize: vertical; }
.job {
  margin: 0 8px 8px;
  padding: 8px;
  max-height: 200px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: 12px/1.4 Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
dialog .job { margin: 0; }
.branch-btn { display: flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%; font-weight: 600; }
.branch-btn .ellipsis { min-width: 0; }
.git-ops { padding-top: 0; }
.autosync { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text); cursor: pointer; }
.autosync input { width: auto; margin: 0; }
.git-tabs { display: flex; gap: 4px; padding: 4px 8px; border-top: 1px solid var(--border); }
.git-tabs button { flex: 1; background: transparent; font-size: 13px; padding: 5px; }
.git-tabs button.active { background: var(--panel-2); border-color: var(--accent); }
.change-row { display: flex; align-items: center; gap: 2px; }
.change-row .change { flex: 1; min-width: 0; }
.commit-meta { white-space: pre-wrap; overflow-wrap: anywhere; }
.branch-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 50vh; overflow: auto; }
.branch-list button { width: 100%; text-align: left; display: flex; gap: 6px; align-items: center; border-color: transparent; }
.branch-list button.current { border-color: var(--accent); }
.branch-list .group { font-size: 12px; color: var(--muted); padding: 6px 2px 2px; }
.branch-new { display: flex; gap: 6px; }
.branch-new input { flex: 1; min-width: 0; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--term-bg);
}
.stage { flex: 1; min-height: 0; display: flex; position: relative; }
.stage > .terminals { flex: 1; min-width: 0; }
.terminals { flex: 1; min-height: 0; position: relative; }
.term { position: absolute; inset: 0; padding: 4px 0 0 6px; display: none; }
.term.visible { display: block; }
.term { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.term-selbar { position: absolute; top: 8px; right: 8px; z-index: 5; display: flex; gap: 6px; padding: 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); box-shadow: 0 4px 14px rgba(0, 0, 0, .4); }
.term-selbar[hidden] { display: none; }
.term-selbar button { min-width: 44px; min-height: 36px; padding: 0 12px; }
.term-selbar button:first-child { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.empty { position: absolute; inset: 0 0 auto; padding: 48px 16px; text-align: center; color: var(--muted); pointer-events: none; }
.empty[hidden] { display: none; }

.status {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  z-index: 5;
}

.mobile-bar {
  flex: none;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 6px;
  display: grid;
  gap: 6px;
  position: relative;
}
.keys { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
/* Gợi ý lệnh "/" (slash.js), nổi phía trên ô prompt */
.slash-menu { position: absolute; left: 6px; right: 6px; bottom: calc(100% - 1px); z-index: 20; list-style: none; margin: 0; padding: 4px;
  max-height: min(40vh, 360px); overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 -6px 20px rgba(0, 0, 0, .35); }
.slash-menu li { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: grid; gap: 2px; }
.slash-menu li.active, .slash-menu li:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.slash-name { display: flex; align-items: baseline; gap: 4px; min-width: 0; }
.slash-name b { font-weight: 600; font-family: Menlo, Monaco, Consolas, monospace; font-size: 13px; }
.slash-src { margin-left: auto; flex: none; }
.keys::-webkit-scrollbar { display: none; }
.keys button { flex: none; min-width: 40px; padding: 6px 8px; font-size: 13px; }
.keybar-edit, .history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 60vh; overflow-y: auto; }
.keybar-edit li { display: flex; align-items: center; gap: 6px; }
.keybar-edit label.inline { flex: 1; }
.keybar-edit .key-label { display: inline-block; min-width: 40px; text-align: center; }
.text-view { margin: 0; max-height: 70vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.4 Menlo, Monaco, Consolas, monospace; -webkit-user-select: text; user-select: text; }
/* Nội dung phiên: giống terminal (nền, font, đúng từng dòng, cuộn ngang nếu dòng dài hơn khung) */
.term-view { white-space: pre; overflow-wrap: normal; background: var(--term-bg); color: var(--text); padding: 8px; border-radius: 6px;
  font-family: Menlo, Monaco, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace; line-height: 1.2; tab-size: 8; }
.dlg-text { height: min(900px, calc(var(--app-height) - 16px)); max-height: none; }
.dlg-text form { display: flex; flex-direction: column; gap: 8px; height: 100%; }
.dlg-text p { margin: 0; }
.dlg-text .text-view { flex: 1; min-height: 0; max-height: none; }
.queue-item { display: flex; align-items: flex-start; gap: 4px; }
.queue-item .queue-text { flex: 1; min-width: 0; }
.keys button.armed { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tab-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: middle; background: var(--muted); }
.tab-dot.busy, .tab-dot.sent { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.tab-dot.idle { background: var(--ok); }
.tab-dot.waiting { background: #e5c04f; }
.tab-dot.ended { background: transparent; border: 1px solid var(--muted); }
.tab-queued { margin-left: 4px; font-size: 11px; color: var(--muted); }
@keyframes pulse { 50% { opacity: .35; } }

/* Khóa dự án khi tự đồng bộ đang pull / Claude đang xử lý xung đột: lớp phủ chặn thao tác, hoặc thanh báo nhỏ ở trên. */
.project-lock { position: absolute; top: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: center; padding: 8px; pointer-events: none; }
.project-lock[hidden] { display: none; }
.project-lock.full { bottom: 0; align-items: center; padding: 16px; background: rgba(0, 0, 0, .55); pointer-events: auto; }
.lock-box { pointer-events: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; max-width: 520px; padding: 8px 12px; border: 1px solid #e5c04f; border-radius: 10px; background: var(--panel-2); box-shadow: 0 4px 14px rgba(0, 0, 0, .4); font-size: 13px; }
.project-lock.full .lock-box { padding: 16px; font-size: 14px; }
.lock-box #lock-text { flex: 1 1 220px; }
.lock-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.lock-actions button[hidden] { display: none; }
.spinner { width: 16px; height: 16px; flex: none; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.history-list .prompt-text { width: 100%; text-align: left; padding: 8px 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.prompt-form { display: flex; gap: 6px; align-items: flex-end; }
.prompt-form textarea { resize: none; min-height: 38px; max-height: 160px; }
.prompt-form button { height: 38px; }
.prompt-tools { display: contents; }
.prompt-tools > #prompt-queue { order: 1; } /* màn rộng: ⏳ nằm sau ô prompt như cũ */
.prompt-form > textarea { order: 0; }
.prompt-form > [type=submit] { order: 2; }
.prompt-more, .pt-label { display: none; }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
/* Đang mở dialog: trang phía sau đứng yên, cuộn tới cuối dialog cũng không kéo trang theo (common.js gắn class) */
html.modal-open, html.modal-open body { overflow: hidden; overscroll-behavior: none; }
dialog, dialog pre, dialog ul, dialog .diff, dialog .fv-image, dialog textarea { overscroll-behavior: contain; }
dialog form { display: grid; gap: 12px; }
dialog h2 { margin: 0; font-size: 16px; }
dialog fieldset { border: 1px solid var(--border); border-radius: 6px; display: flex; gap: 16px; }
dialog legend { color: var(--muted); font-size: 13px; padding: 0 4px; }
dialog label.inline { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
dialog label.inline input { width: auto; }
.sheet-close { display: none; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dlg-head .small-btn { padding: 6px 10px; font-size: 13px; }
.new-advanced { display: grid; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.new-advanced.danger { border-color: var(--danger); }
.new-advanced p { margin: 0; }
.new-advanced button { width: 100%; padding: 12px; }
.danger-text { color: var(--danger); }
.new-advanced .switch input { appearance: none; -webkit-appearance: none; width: 36px; height: 20px; border-radius: 10px; background: var(--border); position: relative; flex: none; cursor: pointer; margin: 0; padding: 0; border: 0; }
.new-advanced .switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); transition: left .15s; }
.new-advanced .switch input:checked { background: var(--danger); }
.new-advanced .switch input:checked::after { left: 18px; }
.entry-actions { display: grid; gap: 6px; }
.entry-actions button { padding: 10px; }
.ssh { display: grid; gap: 6px; border-top: 1px solid var(--border); padding-top: 12px; }
.ssh p { margin: 0; }
.acct-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.acct { display: grid; gap: 4px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; min-width: 0; }
.acct-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.acct-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.acct-actions button { padding: 4px 10px; font-size: 13px; }
.acct-key { display: grid; gap: 6px; }
.acct-key textarea { font: 11px/1.4 Menlo, Monaco, Consolas, monospace; resize: none; overflow-wrap: anywhere; }
.acct-add { display: flex; flex-wrap: wrap; gap: 6px; }
.acct-add input { flex: 2 1 180px; min-width: 0; }
.acct-add #acct-host { flex: 1 1 100px; }
.acct-add #acct-label { flex: 1 1 100%; }
.acct-head .ellipsis { min-width: 0; }
.acct-edit label { font-size: 13px; }
.acct-edit-row { display: flex; flex-wrap: wrap; gap: 8px; }
.acct-edit-row label { flex: 1 1 140px; min-width: 0; }
.acct-edit .error:empty { display: none; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg label { flex: 1; display: block; text-align: center; padding: 8px 4px; font-size: 13px; color: var(--text); cursor: pointer; }
.seg label + label { border-left: 1px solid var(--border); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-text, #fff); }
.pm { display: grid; gap: 10px; }
.git-remote { display: flex; align-items: center; gap: 4px; min-width: 0; }
.git-remote .icon-btn { flex: none; padding: 0 6px; }
.dlg-wide { width: min(1000px, calc(100vw - 16px)); padding: 12px; }
.view-head { display: flex; align-items: center; gap: 8px; }
.view-head h2 { flex: 1; }
.diff {
  margin: 0;
  max-height: calc(var(--app-height) - 120px);
  overflow: auto;
  background: var(--term-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font: 12px/1.45 Menlo, Monaco, Consolas, monospace;
}
.diff.plain { white-space: pre; tab-size: 4; }
.dlg-file { display: none; flex-direction: column; gap: 8px; height: min(900px, calc(var(--app-height) - 16px)); max-height: none; }
.dlg-file[open] { display: flex; }
.dlg-file .diff { flex: 1; min-height: 0; max-height: none; }
.fv-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.fv-bar button { padding: 5px 10px; font-size: 13px; }
.seg { display: flex; }
.seg[hidden] { display: none; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.seg button.active { background: var(--panel-2); border-color: var(--accent); position: relative; }
.fv-image { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 6px;
  background: repeating-conic-gradient(#2a2724 0 25%, #1f1d1a 0 50%) 0 0 / 16px 16px; }
.fv-image[hidden] { display: none; }
.fv-image img { max-width: 100%; max-height: 100%; object-fit: contain; }
.fv-editor { flex: 1; min-height: 0; resize: none; font: 12px/1.45 Menlo, Monaco, Consolas, monospace; white-space: pre; tab-size: 4; background: var(--term-bg); }
.fv-editor[hidden] { display: none; }
.dlg-browser { display: none; flex-direction: column; gap: 8px; height: min(1000px, calc(var(--app-height) - 16px)); max-height: none; }
.dlg-browser[open] { display: flex; }
.bv-bar, .bv-type { display: flex; align-items: center; gap: 6px; }
.bv-bar button, .view-head #bv-stop { padding: 5px 10px; font-size: 13px; }
.bv-bar { flex-wrap: wrap; }
.bv-bar form { display: flex; min-width: 0; flex: 1 1 220px; }
.bv-bar input { flex: 1; min-width: 0; }
.bv-bar select { max-width: 30%; }
.bv-type input { flex: 1; min-width: 0; }
@media (max-width: 600px) {
  .bv-bar form { order: 1; flex-basis: 100%; }
  .bv-bar select { flex: 1; max-width: none; min-width: 0; }
}
.bv-screen { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--term-bg); border: 1px solid var(--border); border-radius: 6px; outline: none; }
.bv-screen:focus-visible { border-color: var(--accent); }
.bv-screen img { max-width: 100%; max-height: 100%; touch-action: none; cursor: default; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.bv-screen p { margin: 0; padding: 16px; text-align: center; }
.bv-screen p:empty { display: none; }
.entry-open, .entry { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.diff .add { color: #8fd17a; }
.diff .del { color: #f08070; }
.diff .hunk { color: #6fb3d9; }
.diff .meta { color: var(--muted); font-weight: 600; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  z-index: 100;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  white-space: pre-wrap;
}
.toast.error { border-color: var(--danger); }

@media (max-width: 760px) {
  #btn-new { padding: 6px 12px; }
  .prompt-form { position: relative; }
  .prompt-more { display: block; flex: none; width: 38px; padding: 0; border: 1px solid var(--border); border-radius: 50%; font-size: 20px; }
  .prompt-more[aria-expanded="true"] { background: color-mix(in srgb, var(--accent) 18%, transparent); }
  .prompt-tools { display: none; position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 20; flex-direction: column; min-width: 220px; padding: 4px;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 -6px 20px rgba(0, 0, 0, .35); }
  .prompt-tools.open { display: flex; }
  .prompt-tools > button, .prompt-tools > #prompt-queue { order: 0; display: flex; align-items: center; gap: 10px; height: 44px; width: 100%; padding: 0 10px;
    background: transparent; border: 0; text-align: left; font-size: 18px; }
  .prompt-tools .pt-label { display: inline; font-size: 15px; color: var(--text); }
  .hide-narrow, .project-title { display: none; }
  .sidebar-title { display: block; }
  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(320px, 88vw);
    z-index: 10;
    box-shadow: 8px 0 24px rgba(0, 0, 0, .5);
  }
  .term { padding-left: 2px; }
}

/* Icon vẽ bằng SVG (mask theo màu chữ): ký tự như ⏻ ⎇ không có font trên Android nên hiện ô vuông. */
.ico { display: inline-block; width: 1em; height: 1em; vertical-align: -0.15em; background: currentColor; -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat; }
.project-meta .ico, .branch .ico { margin-right: 0.3em; }
.ico-power { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M12 3v9'/%3E%3Cpath d='M6.3 6.3a8 8 0 1 0 11.4 0'/%3E%3C/svg%3E"); }
.ico-branch { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='6' cy='5' r='2.2'/%3E%3Ccircle cx='6' cy='19' r='2.2'/%3E%3Ccircle cx='18' cy='7' r='2.2'/%3E%3Cpath d='M6 7.2v9.6'/%3E%3Cpath d='M18 9.2c0 5-12 3-12 7.6'/%3E%3C/svg%3E"); }

/* Mở thư mục bất kỳ làm dự án */
.project-path { grid-column: 1; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.browse-path { display: flex; gap: 6px; }
.browse-path input { flex: 1; min-width: 0; }
.browse-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.browse-tools button { padding: 5px 9px; font-size: 13px; }
.browse-list { max-height: 50vh; }
.browse-item { width: 100%; text-align: left; display: flex; align-items: center; gap: 8px; padding: 8px 10px; overflow-wrap: anywhere; }
.browse-item .ico, .browse-ico { flex: none; width: 1em; text-align: center; }
.browse-row { display: flex; align-items: center; gap: 4px; }
.browse-row .browse-item { flex: 1; min-width: 0; }
.browse-recent-text { display: grid; gap: 2px; min-width: 0; }
#browse-recent.active { border-color: var(--accent); }
.pre-line { white-space: pre-line; overflow-wrap: anywhere; }
.dlg-actions .push-left { margin-right: auto; }

/* Khung Preview cạnh terminal (preview.js) */
.preview { --pv-width: 45%; position: relative; flex: 0 0 var(--pv-width); max-width: calc(100% - 240px); min-width: 280px; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--border); }
.preview[hidden] { display: none; }
.pv-resize { position: absolute; left: -4px; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 2; touch-action: none; }
.pv-dragging .pv-stage { pointer-events: none; }
.pv-bar { display: flex; align-items: center; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--border); overflow-x: auto; flex: none; }
.pv-bar select { flex: 1 1 120px; min-width: 90px; padding: 4px 6px; font-size: 13px; }
.pv-bar select[hidden] { display: none; }
.pv-bar button { flex: none; }
.pv-bar #pv-pdf { padding: 4px 8px; font-size: 12px; }
.pv-bar button.active { background: var(--panel-2); border-color: var(--accent); }
.pv-stage { flex: 1; min-height: 0; display: flex; justify-content: center; background: var(--bg); overflow: auto; }
.pv-stage iframe { flex: 1; width: 100%; height: 100%; border: 0; background: #fff; }
.pv-stage iframe[hidden] { display: none; }
.pv-phone .pv-stage { padding: 12px; }
.pv-phone .pv-stage iframe { flex: none; width: 390px; max-width: 100%; height: min(844px, 100%); border-radius: 18px; box-shadow: 0 0 0 6px #333; }
.pv-inspecting .pv-stage { box-shadow: inset 0 0 0 2px var(--accent); }
.pv-msg { margin: auto; padding: 24px; max-width: 420px; text-align: center; }
.pv-msg[hidden] { display: none; }
.preview.pv-max { position: fixed; inset: 0; z-index: 50; max-width: none; border: 0; }
.preview.pv-max .pv-resize { display: none; }
@media (max-width: 760px) {
  .preview { flex: 1; max-width: none; min-width: 0; border-left: 0; }
  .pv-resize { display: none; }
  body.preview-open .stage > .terminals { display: none; }
}
body.preview-open .stage > .empty { display: none; }
.fb-text { padding: 6px 8px; border-left: 3px solid var(--accent); background: var(--bg); max-height: 6em; overflow: auto; }
#dlg-feedback textarea { width: 100%; }

/* Vẽ phác (sketch.js) */
.dlg-sketch { display: none; flex-direction: column; gap: 8px; height: min(900px, calc(var(--app-height) - 16px)); max-height: none; }
.dlg-sketch[open] { display: flex; }
.sk-tools { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.sk-tools button { min-width: 34px; height: 32px; padding: 0 8px; }
.sk-tools button.active { border-color: var(--accent); background: var(--panel-2); }
.sk-color { background: var(--c) !important; }
.sk-color.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.sk-sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.sk-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--bg); border-radius: 6px; }
.sk-wrap canvas { touch-action: none; cursor: crosshair; background: #fff; }
.sk-foot { display: flex; gap: 6px; }
.sk-foot input { flex: 1; min-width: 0; }

/* Điện thoại: mọi dialog thành bottom sheet trượt lên từ đáy, cuộn bên trong sheet */
@media (max-width: 760px) {
  dialog:modal {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
    max-height: calc(var(--app-height) - 24px);
    overflow-y: auto;
    padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
    animation: sheet-up .22s ease-out;
  }
  /* Vạch kéo ở đầu sheet cho dễ nhận ra là bottom sheet */
  dialog:modal::before { content: ''; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--border); }
  /* Nút ✕ của sheet: dải trên cùng (cạnh vạch kéo), dính ở đầu khi cuộn; cao 0 nên không đẩy nội dung.
     top âm vì sticky tính từ mép trong padding của sheet */
  dialog.has-sheet-close:modal { padding-top: 46px; }
  dialog:modal > .sheet-close { display: flex; justify-content: flex-end; position: sticky; top: -42px; height: 0; margin: -42px -10px 42px 0; z-index: 2; }
  .sheet-x { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex: none; border: 1px solid var(--border); border-radius: 50%; background: var(--panel-2); color: var(--text); font-size: 16px; cursor: pointer; user-select: none; }
  /* Sheet chiếm gần hết màn: xem file, trình duyệt, vẽ phác, nội dung phiên */
  dialog.dlg-wide:modal { height: calc(var(--app-height) - 24px); padding: 18px 8px calc(8px + env(safe-area-inset-bottom)); }
  dialog.dlg-wide:modal:not(.dlg-file):not(.dlg-browser):not(.dlg-sketch):not(.dlg-text) { height: auto; }
  /* Nội dung phiên: khung chữ rộng sát mép như terminal, để dòng vừa khít không phải cuộn ngang */
  dialog.dlg-text:modal { padding-left: 0; padding-right: 0; }
  .dlg-text .view-head, .dlg-text p { padding: 0 12px; }
  .dlg-text .term-view { border-radius: 0; padding: 4px 0 4px 6px; }
  /* Danh sách bên trong không tự cuộn riêng: cả sheet cuộn một lần cho khỏi kẹt ngón tay */
  dialog .keybar-edit, dialog .history-list, dialog .branch-list, dialog .browse-list { max-height: none; overflow: visible; }
  dialog .dlg-actions { flex-wrap: wrap; }
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { dialog:modal { animation: none; } }

