:root {
  --bg: #0f1117;
  --panel: #161a23;
  --panel-2: #1d2230;
  --border: #2a3142;
  --text: #e8ecf4;
  --muted: #93a0b8;
  --accent: #4f8cff;
  --danger: #e55353;
  --warn: #e3b341;
  --claude: #d97757;
  --agy: #58a6ff;
  --codex: #3fb950;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.xs-text { font-size: 12px; }
.error-text { color: #ff7b7b; font-size: 13px; margin-top: 4px; }
.ok-text { color: var(--codex); font-size: 13px; margin-top: 4px; }
.model-select { max-width: 240px; }
.advanced-box { border: 1px dashed var(--border); border-radius: 8px; padding: 8px 10px; }
.settings-section { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.pair-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pair-code { font-size: 20px; font-weight: 700; letter-spacing: 0.12em; color: var(--agy); background: #0b0d12; padding: 4px 12px; border-radius: 8px; border: 1px solid var(--border); }

.login-screen { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.login-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; font-size: 22px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, textarea, select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
}
input:focus, textarea:focus, select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.full { width: 100%; }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.xs { padding: 3px 8px; font-size: 12px; }
.btn.icon-only { padding: 6px 10px; }
.small-select { padding: 5px 8px; font-size: 13px; }

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  width: 100%;
  max-width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand { font-weight: 700; font-size: 15px; }
.sidebar-actions { display: flex; gap: 6px; }

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.workers-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: #121620;
  font-size: 11.5px;
}
.worker-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.worker-pill:hover:not(:disabled) { border-color: var(--accent); }
.worker-pill.offline { opacity: 0.55; color: var(--muted); cursor: default; }
.w-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.w-dot.online { background: var(--codex); box-shadow: 0 0 5px var(--codex); }
.w-dot.busy { background: var(--accent); animation: pulse 1.1s infinite; }
.w-dot.offline { background: var(--danger); }

.active-runs-section {
  background: rgba(79, 140, 255, 0.08);
  border: 1px solid rgba(79, 140, 255, 0.28);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.active-runs-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--agy);
  text-transform: uppercase;
  padding: 2px 6px;
}

/* Terminal Output Cards */
.term-drawer {
  margin-bottom: 10px;
  background: #0a0d13;
  border: 1px solid #263147;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
}
.term-drawer summary { cursor: pointer; user-select: none; font-weight: 600; color: #9ec0ff; }
.term-list { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.term-card {
  background: #06080c;
  border: 1px solid #1e2738;
  border-radius: 7px;
  overflow: hidden;
}
.term-cmd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px;
  background: #101521;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: #e6edf3;
}
.term-cmd-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-exit { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 999px; flex-shrink: 0; }
.term-exit.ok { background: rgba(63, 185, 80, 0.2); color: var(--codex); }
.term-exit.err { background: rgba(229, 83, 83, 0.22); color: #ff7b7b; }
.term-out {
  margin: 0;
  padding: 8px 10px;
  max-height: 200px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.45;
  color: #b7c3d6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Project File Viewer Modal */
.dialog.file-dialog {
  width: min(920px, calc(100vw - 20px));
  height: min(680px, 86dvh);
  max-height: 86dvh;
}
.file-dialog-body { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.file-viewer-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 10px;
}
.file-tree-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0c0e14;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.file-row {
  padding: 7px 10px;
  border-bottom: 1px solid #1a2030;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-row:hover { background: var(--panel-2); }
.file-row.active { background: #1e273a; color: #fff; font-weight: 600; }
.file-code-pane {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0b0d12;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.file-code-head {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: #121621;
  flex-shrink: 0;
}
.file-code-body {
  flex: 1;
  margin: 0;
  padding: 10px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #dbe4f3;
}
.file-viewer-grid.tree-hidden { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.file-viewer-grid.tree-hidden .file-tree-list { display: none; }
.file-code-body .vs-spacer { position: relative; }
.file-code-body .vs-win {
  position: absolute;
  top: 0;
  left: 0;
  white-space: pre;
  line-height: 18px;
  will-change: transform;
}
@media (max-width: 720px) {
  .file-viewer-grid { grid-template-columns: 1fr; grid-template-rows: 180px 1fr; }
  .file-viewer-grid.tree-hidden { grid-template-rows: 1fr; }
}

.project-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tree-group { display: flex; flex-direction: column; gap: 2px; }
.tree-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.tree-group.has-active .tree-group-head { color: var(--text); }
.tree-group-title {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex: 1;
  cursor: pointer;
}
.tree-group-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-group-actions { display: flex; gap: 2px; flex-shrink: 0; opacity: 0.75; }
.tree-group-head:hover .tree-group-actions { opacity: 1; }
.tree-icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 13px;
  line-height: 1.2;
}
.tree-icon-btn:hover { background: var(--panel-2); color: var(--text); }

.tree-sessions { display: flex; flex-direction: column; gap: 2px; padding-left: 14px; }
.tree-session {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: #c7d0e0;
  font-size: 13.5px;
  transition: background 0.12s ease;
}
.tree-session:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.tree-session.active {
  background: #232a3b;
  color: #fff;
  font-weight: 500;
}
.tree-session-main { display: flex; align-items: center; gap: 7px; min-width: 0; flex: 1; }
.tree-session-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-session-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; font-size: 11.5px; color: var(--muted); }
.agent-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.agent-dot.claude { background: var(--claude); }
.agent-dot.agy { background: var(--agy); }
.agent-dot.codex { background: var(--codex); }
.active-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); flex-shrink: 0; }
.active-dot.running { animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.45; transform: scale(0.8); } }

.usage-drawer {
  border-top: 1px solid var(--border);
  padding: 6px 10px;
  background: #131720;
}
.usage-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}
.usage-summary::-webkit-details-marker { display: none; }
.usage-summary-text { min-width: 0; flex: 1; line-height: 1.35; }
.usage-summary-sub { padding-left: 11px; color: var(--muted); opacity: 0.9; }
.usage-drawer[open] .usage-cards { margin-top: 8px; }
.usage-cards { display: flex; flex-direction: column; gap: 6px; }
.usage-row {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
}
.usage-row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.usage-subhead { font-size: 11px; margin: 4px 0 2px; }
.usage-bars { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bar-wrap { display: flex; flex-direction: column; gap: 2px; }
.bar-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.bar-track { height: 5px; background: #0b0d12; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; }
.bar-fill.high { background: var(--warn); }
.bar-fill.crit { background: var(--danger); }

.project-bar { display: flex; gap: 6px; }
.sidebar-footer {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.crumb-proj {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--agy);
  background: rgba(88, 166, 255, 0.14);
  padding: 1px 7px;
  border-radius: 6px;
  margin-right: 6px;
  vertical-align: middle;
}

.session-item {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.session-item:hover { background: var(--panel-2); }
.session-item.active { background: var(--panel-2); border-color: var(--accent); }
.session-item-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.session-title { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.badge.claude { background: rgba(217, 119, 87, 0.22); color: var(--claude); }
.badge.agy { background: rgba(88, 166, 255, 0.22); color: var(--agy); }
.badge.codex { background: rgba(63, 185, 80, 0.22); color: var(--codex); }
.badge.running { background: rgba(79, 140, 255, 0.28); color: #9ec0ff; }
.badge.handoff { background: rgba(227, 179, 65, 0.2); color: var(--warn); }

.main-area { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; width: 100%; max-width: 100%; overflow: hidden; }
.topbar {
  position: relative;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 100%;
  overflow: visible;
}
.topbar-meta { flex: 1; min-width: 0; overflow: hidden; }
.active-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.active-sub { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-controls { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.menu-wrap { position: relative; flex-shrink: 0; }
.session-menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0; z-index: 40; min-width: 220px;
  flex-direction: column; gap: 4px; padding: 8px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--panel); box-shadow: 0 10px 28px #000a;
}
.session-menu.open { display: flex; }
.session-menu .btn, .session-menu .select { width: 100%; justify-content: flex-start; text-align: left; }
.session-menu .btn.danger-item { color: var(--danger); }
.session-menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }
.back-btn { gap: 4px; align-items: center; font-weight: 600; }
.back-btn .back-label { font-size: 13px; }

.chat-pane { position: relative; display: flex; flex: 1; min-height: 0; }
.messages {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#btn-latest-message {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  white-space: nowrap;
  min-height: 40px;
  border-radius: 999px;
  background: var(--panel-2);
}
.empty-state { margin: auto; text-align: center; max-width: 440px; }

.msg {
  max-width: 860px;
  width: fit-content;
  border-radius: 12px;
  padding: 11px 14px;
  line-height: 1.6;
  word-break: break-word;
}
.msg.user { align-self: flex-end; background: #22355c; border: 1px solid #314b82; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); width: 100%; }
.msg-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }

.tools-drawer {
  margin-bottom: 10px;
  background: #11151e;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
}
.tools-drawer summary { cursor: pointer; user-select: none; font-weight: 500; }
.tools-list {
  margin-top: 8px;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--border);
  padding-top: 6px;
}
.tool-line { display: flex; gap: 8px; align-items: baseline; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px; }
.tool-name { color: var(--agy); font-weight: 600; flex-shrink: 0; }
.tool-sum { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.md-p { margin: 0 0 10px; }
.md-p:last-child { margin-bottom: 0; }
.md-h { margin: 12px 0 6px; font-weight: 600; color: #fff; }
.md-list { margin: 6px 0 10px; padding-left: 20px; }
.md-list li { margin: 4px 0; }
.inline-code {
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12.5px;
  color: #b7d5ff;
}
.md-file-ref { color: var(--agy); text-decoration: underline dotted; }
.md-file-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 6px;
  border: 1px solid rgba(88, 166, 255, 0.35);
  background: rgba(88, 166, 255, 0.12);
  color: #93c5fd;
  font: inherit;
  font-size: 0.92em;
  cursor: pointer;
  vertical-align: baseline;
  text-decoration: none;
}
.md-file-link:hover { background: rgba(88, 166, 255, 0.22); color: #fff; }
.md-img-wrap {
  margin: 10px 0;
  display: inline-flex;
  flex-direction: column;
  gap: 5px;
  max-width: 100%;
}
.md-img {
  max-width: min(100%, 560px);
  max-height: 420px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b0d12;
  object-fit: contain;
  cursor: zoom-in;
}
.md-img-caption { font-size: 12px; color: var(--muted); }
.att-img-btn {
  padding: 0;
  border: none;
  background: transparent;
  cursor: zoom-in;
  border-radius: 8px;
  line-height: 0;
}
.demo-embed-card {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #0d111a;
}
.demo-embed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 7px 10px;
  background: #141926;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.demo-embed-title {
  font-weight: 600;
  color: #dbeafe;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}
.demo-embed-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.demo-embed-frame {
  display: block;
  width: 100%;
  height: 440px;
  border: none;
  background: #ffffff;
}
.lightbox-dialog {
  margin: auto;
  width: min(94vw, 1080px);
  max-height: 92dvh;
  background: #0b0e14;
}
.lightbox-body { height: 100%; max-height: 92dvh; padding: 12px; }
.lightbox-title {
  margin: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.lightbox-img-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  max-height: 80dvh;
  background: #07090e;
  border-radius: 8px;
  padding: 6px;
}
.lightbox-img {
  max-width: 100%;
  max-height: 76dvh;
  object-fit: contain;
  border-radius: 6px;
}
.demo-dialog {
  margin: auto;
  width: min(96vw, 1180px);
  height: min(90dvh, 860px);
  max-height: 92dvh;
}
.demo-dialog-body {
  height: 100%;
  padding: 12px;
  display: flex;
  flex-direction: column;
}
.demo-dialog-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}
@media (max-width: 820px) {
  .demo-embed-frame { height: 360px; }
}
.msg a { color: var(--agy); }
.code-wrap { margin: 10px 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #0b0d12; }
.code-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 8px 2px 12px; border-bottom: 1px solid var(--border); background: #121621; }
.code-lang { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.code-header .btn { min-height: 32px; flex-shrink: 0; }
.md-table-wrap { overflow-x: auto; margin: 10px 0; border: 1px solid var(--border); border-radius: 8px; }
.md-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.md-table th, .md-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md-table th { background: #1c2231; font-weight: 600; color: #fff; }
.md-table tr:last-child td { border-bottom: none; }

.tool-pill {
  font-size: 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  color: var(--muted);
}
.msg-footer { margin-top: 8px; font-size: 11px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.msg pre { background: #0b0d12; border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-x: auto; margin: 8px 0; }
.msg code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

.composer {
  padding: 6px 14px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(15, 17, 23, 0) 0%, var(--bg) 28%);
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
}
.composer > .queue-bar,
.composer > .autocomplete-popup,
.composer > .composer-card {
  width: 100%;
  max-width: 860px;
}
.composer-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 10px 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32), 0 1px 2px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, border-radius 0.18s ease;
}
.composer-card:focus-within {
  border-color: rgba(125, 168, 255, 0.45);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.42), 0 0 0 1px rgba(79, 140, 255, 0.16);
}
.composer-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "input input input"
    "attach model actions";
  gap: 8px 8px;
  align-items: center;
}
.composer-grid textarea {
  grid-area: input;
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  resize: none;
  field-sizing: content;
  min-height: 28px;
  max-height: 160px;
  line-height: 1.5;
  padding: 4px 8px;
  font-size: 15px;
  outline: none;
  box-shadow: none;
}
.composer-grid textarea::placeholder { color: var(--muted); opacity: 0.85; }
#btn-attach { grid-area: attach; }
.composer-meta-bar {
  grid-area: model;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}
.model-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  height: 36px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.model-trigger:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.16); }
.picker-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 58vw; }
.picker-caret { color: var(--muted); font-size: 11px; flex-shrink: 0; }
.handoff-hint { font-size: 11.5px; color: var(--warn); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 1; }
.composer-buttons { grid-area: actions; display: flex; align-items: center; gap: 6px; }
.composer-circle-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
}
.composer-circle-btn:hover { background: rgba(255, 255, 255, 0.13); }
.composer-circle-btn:active { transform: scale(0.94); }
.composer-circle-btn:disabled { opacity: 0.45; cursor: default; }
.composer-circle-btn.recording {
  background: rgba(229, 83, 83, 0.28);
  border-color: var(--danger);
  color: #ff8c8c;
  animation: pulse 1s infinite;
}
.composer-circle-btn.stop-btn {
  background: rgba(229, 83, 83, 0.22);
  border-color: rgba(229, 83, 83, 0.45);
  color: #ff8c8c;
}
.composer-circle-btn.stop-btn:hover { background: rgba(229, 83, 83, 0.35); }
.composer-circle-btn.send-btn {
  background: rgba(217, 119, 87, 0.26);
  color: rgba(255, 255, 255, 0.55);
}
.composer.has-content .composer-circle-btn.send-btn {
  background: var(--claude);
  color: #ffffff;
  box-shadow: 0 3px 12px rgba(217, 119, 87, 0.35);
}
.composer.has-content .composer-circle-btn.send-btn:hover {
  filter: brightness(1.08);
}
.composer-circle-btn.send-btn.is-queue {
  background: rgba(79, 140, 255, 0.28);
  color: #cfe0ff;
}
.composer.has-content .composer-circle-btn.send-btn.is-queue {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 3px 12px rgba(79, 140, 255, 0.35);
}
.diff-status {
  background: #0d1017;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 120px;
  overflow-y: auto;
}
.diff-view {
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin: 0;
  max-height: 55vh;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}
.diff-add { color: #56d364; background: rgba(63, 185, 80, 0.12); display: block; }
.diff-del { color: #ff7b72; background: rgba(248, 81, 73, 0.12); display: block; }
.diff-hunk { color: #79c0ff; font-weight: 600; display: block; margin-top: 6px; }
.err-more summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 4px; }
.attach-preview { display: flex; gap: 8px; flex-wrap: wrap; padding: 2px 0; }
.attach-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  max-width: 220px;
}
.attach-chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; }
.attach-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-rm {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 3px;
  font-size: 13px;
}
.attach-rm:hover { color: #ff7b7b; }
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg-att-img { max-width: 220px; max-height: 180px; border-radius: 8px; border: 1px solid var(--border); object-fit: cover; }

/* Fixed-size Centered Agent/Model Picker Popup */
.sheet-dialog {
  margin: auto;
  width: min(440px, calc(100vw - 24px));
  height: min(560px, 82dvh);
  max-height: 82dvh;
  border-radius: 16px;
  overflow: hidden;
}
.sheet-body {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
.sheet-seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: #0d1017;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}
.seg-btn:active { transform: scale(0.97); }
.seg-btn.active { background: #232c42; color: #fff; border-color: #3a4a6b; }

.sheet-effort-wrap {
  min-height: 58px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.effort-note {
  font-size: 12.5px;
  color: var(--muted);
  padding: 6px 10px;
  background: #0d1017;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.effort-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.chip-btn.active { background: rgba(79, 140, 255, 0.22); color: #fff; border-color: var(--accent); }

.sheet-model-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0d1017;
  padding: 5px;
}
.sheet-model-list.tab-fade { animation: sheetFade 0.18s ease-out; }
@keyframes sheetFade {
  from { opacity: 0.25; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.model-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.14s ease;
}
.model-option:hover { background: rgba(255, 255, 255, 0.05); }
.model-option.active { background: #1e273a; color: #fff; font-weight: 600; }
.model-check { color: var(--accent); font-weight: 700; flex-shrink: 0; }

.dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  width: min(500px, calc(100vw - 20px));
}
.dialog.wide { width: min(620px, calc(100vw - 20px)); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.68); }
.dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.dialog-body h3 { margin: 0; font-size: 17px; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.drive-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.folder-nav { display: flex; align-items: center; gap: 8px; }
.folder-path { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.folder-list {
  max-height: 42vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0c0e14;
  display: flex;
  flex-direction: column;
}
.folder-row {
  padding: 10px 12px;
  border-bottom: 1px solid #1d2230;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.folder-row:last-child { border-bottom: none; }
.folder-row:hover { background: var(--panel-2); }
.folder-name { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.doc-editor {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  resize: vertical;
}

.discover-list { max-height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.discover-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.discover-info { min-width: 0; flex: 1; }
.discover-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.discover-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mobile-only, .sidebar-backdrop { display: none; }

@media (max-width: 820px), (pointer: coarse) and (max-height: 550px) {
  html, body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }
  .app-shell {
    grid-template-columns: 1fr;
    position: fixed;
    inset: var(--app-viewport-top, 0px) 0 auto;
    width: 100%;
    height: var(--app-viewport-height, 100dvh);
    overflow: hidden;
  }
  .login-screen {
    position: fixed;
    inset: var(--app-viewport-top, 0px) 0 auto;
    height: var(--app-viewport-height, 100dvh);
    min-height: 0;
    overflow: auto;
    align-items: safe center;
  }
  .mobile-only { display: inline-flex; flex-shrink: 0; }
  .topbar {
    position: relative;
    z-index: 5;
    padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) 4px max(6px, env(safe-area-inset-left));
    gap: 6px;
    flex-wrap: nowrap;
    overflow: visible;
  }
  .topbar-meta {
    flex: 1;
    min-width: 0;
  }
  .topbar .crumb-proj { display: none; }
  .topbar > .icon-only { width: 44px; height: 44px; padding: 0; align-items: center; justify-content: center; }
  #btn-mobile-model { max-width: 36%; height: 44px; min-width: 0; padding-inline: 9px; }
  #btn-mobile-model .picker-label { min-width: 0; }
  .menu-wrap { position: static; }
  .topbar-controls { display: none; }
  .session-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: max(8px, env(safe-area-inset-right));
    width: min(300px, calc(100vw - 16px));
    max-height: calc(var(--app-viewport-height, 100dvh) - 76px);
    overflow: auto;
  }
  .session-menu.open { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .session-menu hr { grid-column: 1 / -1; margin: 2px 0; }
  .session-menu :is(.btn.small, .small-select) { min-height: 44px; max-width: 100%; }
  .session-menu .select { min-width: 0; }
  .back-btn { width: auto !important; padding: 0 10px !important; min-width: 44px; }
  .active-sub { display: none; }
  .messages {
    padding: 10px;
    gap: 10px;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .msg, .msg-body { max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
  .msg-body pre, .term-out { max-width: 100%; overflow-x: auto; }
  .composer {
    padding: 4px max(10px, env(safe-area-inset-right))
      calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    max-width: 100%;
    overflow: visible;
  }
  .composer:not(.expanded) .composer-card {
    border-radius: 999px;
    padding: 6px 8px;
  }
  .composer:not(.expanded) .composer-grid {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "attach input actions";
    gap: 6px;
  }
  .composer .composer-meta-bar { display: flex; min-width: 0; }
  .composer .picker-label { max-width: 46vw; }
  #btn-mobile-model { display: none !important; }
  .composer:not(.expanded) .composer-grid textarea {
    min-height: 36px;
    max-height: 40px;
    padding: 6px 4px;
    overflow: hidden;
    white-space: nowrap;
  }
  .composer.expanded .composer-card {
    border-radius: 24px;
    padding: 10px 10px 8px;
  }
  .composer.expanded .composer-grid {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "input input input"
      "attach model actions";
    gap: 8px 6px;
  }
  .composer-grid textarea {
    min-height: 36px;
    max-height: min(8.5rem, calc(var(--app-viewport-height, 100dvh) * .32));
    overflow-wrap: anywhere;
    overscroll-behavior: contain;
  }
  .composer .composer-circle-btn { width: 44px; height: 44px; }
  .perm-bar { max-height: 32vh; overflow-y: auto; }
  .composer > :is(.queue-bar, .autocomplete-popup) {
    max-height: min(6rem, calc(var(--app-viewport-height, 100dvh) * .2));
    overflow-y: auto;
  }
  .composer-card .attach-preview {
    max-height: 5.5rem;
    overflow-y: auto;
    padding: 0 4px 2px;
  }
  #prompt-input, #sidebar-search.sidebar-search { font-size: 16px; }
  .sheet-dialog {
    position: fixed;
    inset: auto 0 max(0px, calc(100dvh - var(--app-viewport-height, 100dvh) - var(--app-viewport-top, 0px)));
    margin: 0 auto;
    width: min(100%, 540px);
    max-width: 100%;
    height: min(540px, calc(var(--app-viewport-height, 100dvh) - 12px));
    max-height: none;
    border-radius: 20px 20px 0 0;
  }
  .sheet-body { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .sheet-dialog .model-option { min-height: 44px; }
  .sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 30;
    overscroll-behavior: contain;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.15s ease, visibility 0s linear 0.15s;
  }
  .sidebar.open { visibility: visible; opacity: 1; transition: opacity 0.15s ease; }
  .sidebar-backdrop, #btn-close-sidebar { display: none !important; }
  .sidebar-header { flex-wrap: wrap; }
  .sidebar-actions { flex-wrap: wrap; }
  .sidebar-actions .btn, .sidebar-footer .btn, #btn-refresh-usage { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .sidebar-actions .btn { min-width: 40px; }
  .tree-icon-btn { min-width: 36px; min-height: 36px; display: inline-flex; align-items: center; justify-content: center; }
  .project-tree { flex: 1 0 min(8rem, 24dvh); }
}


/* Sidebar Search, Message Queue, Autocomplete, Syntax Highlight, Diff Cards & Interactive Shell */
.sidebar-search-wrap { padding: 4px 10px 6px; }
.sidebar-search { width: 100%; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 12px; }
.queue-bar { display: flex; flex-direction: column; gap: 4px; padding: 6px 10px; margin-bottom: 6px; border-radius: 10px; background: rgba(99, 102, 241, 0.12); border: 1px solid rgba(99, 102, 241, 0.35); font-size: 12px; }
.attention-badge { font-size: 12px; }
#btn-menu.has-attention { position: relative; }
#btn-menu.has-attention::after { content: ''; position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: #f59e0b; }
.load-older { align-self: center; flex-shrink: 0; }
.upload-status { padding: 4px 10px; font-size: 12px; }
.diff-file-patch [data-line] { cursor: pointer; }
.diff-file-patch [data-line].noted { outline: 1px solid #f59e0b; }
.perm-detail.expanded { max-height: 40dvh; }
.conn-banner { padding: 6px 12px; font-size: 12px; text-align: center; background: rgba(245, 158, 11, 0.16); border-bottom: 1px solid rgba(245, 158, 11, 0.4); }
.queue-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.queue-item-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.autocomplete-popup { max-height: 210px; overflow-y: auto; margin-bottom: 6px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); }
.ac-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; font-size: 12.5px; cursor: pointer; border-bottom: 1px solid rgba(255, 255, 255, 0.04); }
.ac-item:hover, .ac-item.active { background: rgba(99, 102, 241, 0.2); }
.ac-sub { font-size: 11px; color: var(--muted); }
.file-search-input { width: 180px; max-width: 40%; padding: 5px 8px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 12px; }
.file-search-results { max-height: 150px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 4px; margin-bottom: 6px; font-size: 12px; }
.search-hit { display: flex; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.search-hit:hover { background: rgba(255, 255, 255, 0.07); }
.search-hit-file { color: #93c5fd; font-family: ui-monospace, monospace; white-space: nowrap; }
.search-hit-text { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-code-head-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--border); padding-right: 8px; }
.file-code-actions { display: flex; gap: 4px; }
.file-code-editor { flex: 1; width: 100%; min-height: 320px; border: none; padding: 10px; background: #0b0e14; color: #e5e7eb; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; line-height: 1.5; resize: none; }
.syn-kw { color: #c084fc; }
.syn-str { color: #86efac; }
.syn-com { color: #64748b; font-style: italic; }
.syn-num { color: #fbbf24; }
.diff-files { display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; }
.diff-file-card { border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--bg); }
.diff-file-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; background: rgba(255, 255, 255, 0.04); font-size: 12.5px; cursor: pointer; }
.diff-file-stats { display: flex; align-items: center; gap: 6px; font-family: ui-monospace, monospace; font-size: 11px; }
.diff-stat-add { color: #4ade80; }
.diff-stat-del { color: #f87171; }
.diff-file-patch { margin: 0; padding: 8px 10px; overflow-x: auto; font-size: 11.5px; line-height: 1.45; font-family: ui-monospace, monospace; }
.shell-chips { display: flex; flex-wrap: wrap; gap: 6px; }
#shell-form { flex-wrap: nowrap; }
#shell-input { flex: 1; min-width: 0; width: auto; }
.shell-out { margin: 0; padding: 10px; min-height: 220px; max-height: 45vh; overflow: auto; border-radius: 9px; border: 1px solid var(--border); background: #090c12; color: #d1fae5; font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }

/* Artifact / Markdown Viewer Modal */
.dialog.artifact-dialog {
  width: min(860px, calc(100vw - 20px));
  height: min(760px, 88dvh);
  max-height: 88dvh;
}
.artifact-dialog-body {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.artifact-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0d1017;
  line-height: 1.65;
  word-break: break-word;
}
.artifact-content pre {
  background: #07090e;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
  margin: 8px 0;
}
.artifact-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}
.msg .code-wrap pre, .artifact-content .code-wrap pre { border: 0; border-radius: 0; margin: 0; padding: 10px 12px; }
.artifact-content a { color: var(--agy); }


/* Drag-and-drop & Mobile Long-Press Reorder */
body.tree-dragging, body.tree-dragging * { user-select: none !important; -webkit-user-select: none !important; }
.tree-group-head, .tree-session { -webkit-touch-callout: none; }
.drag-handle { cursor: grab; touch-action: none; font-weight: 700; letter-spacing: -1px; }
.drag-handle:active { cursor: grabbing; }
.is-dragging { opacity: 0.45; background: rgba(79, 140, 255, 0.16) !important; }
.drop-before { box-shadow: inset 0 2px 0 0 var(--accent); }
.drop-after { box-shadow: inset 0 -2px 0 0 var(--accent); }
.drag-ghost {
  position: fixed;
  left: 16px;
  right: auto;
  max-width: 260px;
  padding: 7px 12px;
  border-radius: 10px;
  background: rgba(79, 140, 255, 0.92);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* Phê duyệt quyền theo từng lệnh */
.perm-bar { display: flex; flex-direction: column; gap: 8px; padding: 8px 12px; }
.perm-bar.hidden { display: none; }
.perm-card { border: 1px solid var(--border, #444); border-radius: 12px; padding: 10px 12px; background: rgba(255, 170, 0, 0.08); }
.perm-title { font-size: 14px; margin-bottom: 6px; }
.perm-detail { margin: 0 0 8px; padding: 8px; max-height: 140px; overflow: auto; white-space: pre-wrap; word-break: break-all; font-size: 12px; border-radius: 8px; background: rgba(0, 0, 0, 0.25); }
.perm-actions { display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; padding: 4px 0; background: var(--panel); }
.perm-card { flex-shrink: 0; }
.perm-bar:has(.perm-detail.expanded) { max-height: 65dvh; overflow-y: auto; }

.device-list { display: flex; flex-direction: column; gap: 8px; }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid var(--border, #444); border-radius: 10px; }

/* ===== Project collapse / overflow menu ===== */
.tree-group-title {
  background: transparent; border: 0; padding: 0; margin: 0; font: inherit; color: inherit; text-align: left;
}
.tree-group-title:focus-visible, .tree-icon-btn:focus-visible, .usage-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tree-chevron { width: 12px; flex-shrink: 0; color: var(--muted); font-size: 11px; }
.tree-group-count {
  flex-shrink: 0; min-width: 18px; padding: 0 6px; border-radius: 99px; text-align: center;
  background: var(--panel-2); color: var(--muted); font-size: 11px; font-weight: 500; line-height: 18px;
}
.tree-group.collapsed .tree-group-head { opacity: 0.9; }
.tree-group-menu { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 8px 6px 26px; }
.tree-group-menu .btn { min-height: 32px; }
.sidebar-search-wrap { display: flex; gap: 6px; align-items: center; }
.sidebar-search-wrap .sidebar-search { flex: 1; min-width: 0; }
#btn-collapse-all { flex-shrink: 0; }

/* ===== Compact usage meter ===== */
.usage-drawer { display: flex; align-items: stretch; gap: 6px; padding: 6px 8px; }
.usage-open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 4px 6px; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: 8px; color: var(--muted); text-align: left; font: inherit; font-size: 11px;
}
.usage-open:hover { background: var(--panel-2); border-color: var(--border); }
.usage-open .usage-summary-text { display: flex; flex-direction: column; gap: 3px; }
.usage-open-hint { color: var(--muted); font-size: 13px; }
.um-head { display: flex; justify-content: space-between; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.8; }
.um-row { display: grid; grid-template-columns: 14px 1fr 1fr 34px; gap: 5px; align-items: center; }
.um-name { font-weight: 700; font-size: 11px; }
.um-name.claude { color: var(--claude); } .um-name.codex { color: var(--codex); } .um-name.agy { color: var(--agy); }
.um-bar { height: 6px; background: #0b0d12; border-radius: 99px; overflow: hidden; }
.um-bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.um-bar i.high { background: var(--warn); } .um-bar i.crit { background: var(--danger); }
.um-pct { text-align: right; font-variant-numeric: tabular-nums; }
.um-pct.high { color: var(--warn); } .um-pct.crit { color: var(--danger); }
#usage-dialog .usage-cards { max-height: 60dvh; overflow-y: auto; }
#usage-dialog .usage-bars { grid-template-columns: 1fr 1fr; }
#btn-refresh-usage { align-self: center; }

/* ===== Schedule dialog ===== */
.schedule-list { display: flex; flex-direction: column; gap: 8px; max-height: 34dvh; overflow-y: auto; }
.schedule-item { display: flex; gap: 8px; justify-content: space-between; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); }
.schedule-item.off { opacity: 0.6; }
.schedule-item-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.schedule-item-name { font-weight: 600; font-size: 13.5px; overflow-wrap: anywhere; }
.schedule-item-actions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; max-width: 45%; }
.schedule-empty { padding: 10px 2px; }
.schedule-form { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.schedule-form h4 { margin: 0; font-size: 14px; }
.schedule-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.schedule-form input[type=text], .schedule-form input[type=time], .schedule-form input[type=number], .schedule-form input[type=datetime-local], .schedule-form textarea {
  width: 100%; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; font-size: 14px;
}
.schedule-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.sch-days { display: flex; flex-wrap: wrap; gap: 6px; }
.schedule-form .sch-day { flex-direction: row; align-items: center; gap: 4px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 99px; color: var(--text); cursor: pointer; }
.sch-day:has(input:checked) { background: rgba(99, 102, 241, 0.25); border-color: var(--accent); }

/* ===== Mobile sidebar polish ===== */
@media (max-width: 820px), (pointer: coarse) and (max-height: 550px) {
  .sidebar-header { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px 12px 8px; }
  .sidebar-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 48px 48px; gap: 6px; }
  .sidebar-actions .btn { min-width: 0; padding-inline: 4px; }
  #btn-close-sidebar { display: inline-flex; min-width: 44px; min-height: 44px; align-items: center; justify-content: center; }
  .sidebar-search-wrap { padding: 8px 10px; }
  #btn-collapse-all, #btn-refresh-usage-dialog { min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .tree-group-head { padding: 4px 6px; min-height: 44px; }
  .tree-group-title { min-height: 44px; }
  .tree-session { min-height: 44px; }
  .tree-group-menu { padding-left: 14px; }
  .tree-group-menu .btn { min-height: 44px; flex: 1 1 40%; justify-content: center; }
  .project-tree { gap: 6px; }
  .usage-drawer { padding-bottom: 6px; }
  .usage-open { min-height: 52px; }
  #btn-refresh-usage { min-width: 44px; }
  .schedule-item { flex-direction: column; }
  .schedule-item-actions { max-width: none; justify-content: flex-start; }
  .schedule-item-actions .btn { min-height: 40px; min-width: 40px; }
  #schedule-dialog, #usage-dialog { max-height: calc(var(--app-viewport-height, 100dvh) - 12px); }
  .schedule-form input, .schedule-form textarea, .schedule-form select { font-size: 16px; }
}

/* ===== Sidebar "Xem thêm" + drag ===== */
.sidebar-more { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: #121620; }
.sidebar-more .more-item { display: flex; align-items: center; gap: 8px; justify-content: flex-start; text-align: left; min-height: 38px; }
.sidebar-more .workers-bar { padding: 0; border: 0; background: transparent; }
.more-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.more-label:has(+ .hidden) { display: none; }
.tree-group-head, .tree-session { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
@media (max-width: 820px), (pointer: coarse) and (max-height: 550px) {
  .sidebar-more .more-item { min-height: 44px; }
  .sidebar-actions .btn { min-height: 44px; }
}

/* ===== Phiên ghim: dải tab nóng, bảng nhanh, mục ghim ===== */
.pin-strip { flex: none; display: flex; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--border); background: #121620; overflow-x: auto; scrollbar-width: none; }
.pin-strip::-webkit-scrollbar { display: none; }
.pin-chip {
  flex: 1 1 0; min-width: 96px; max-width: 260px; display: flex; flex-direction: column; gap: 1px; text-align: left;
  padding: 6px 9px; border-radius: 11px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font: inherit; cursor: pointer;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
}
.pin-chip.on { border-color: var(--accent); background: #1b2a47; }
.pin-chip.alert { border-color: var(--warn); }
.pin-row { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12.5px; font-weight: 600; }
.pin-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pin-sub { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: #4a5368; display: inline-block; }
.pin-dot.run { background: var(--accent); box-shadow: 0 0 7px var(--accent); animation: pulse 1.1s infinite; }
.pin-dot.wait { background: var(--warn); box-shadow: 0 0 7px var(--warn); }
.pin-dot.done { background: var(--codex); }
.pin-dot.err { background: var(--danger); }
.pin-add, .pin-panel-btn { flex: none; min-width: 44px; padding: 0 10px; border-radius: 11px; border: 1px dashed var(--border); background: transparent; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; }
.pin-panel-btn { border-style: solid; background: var(--panel-2); font-size: 16px; }
.pin-chip:focus-visible, .pin-add:focus-visible, .pin-panel-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pin-toggle { color: var(--muted); }
.pin-toggle.pinned { color: var(--warn); }
.pin-side { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pinned-section .tree-session-title { max-width: 100%; }
.pin-panel-body { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; max-height: 70dvh; }
.pin-card { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 14px; border: 1px solid var(--border); background: var(--panel-2); }
.pin-card.alert { border-color: var(--warn); }
.pin-card-h { display: flex; align-items: center; gap: 8px; }
.pin-card-h b { flex: 1; min-width: 0; font-size: 14.5px; }
.pin-prev { margin: 0; padding: 8px 10px; max-height: 96px; overflow: auto; border-radius: 10px; background: #0d1017; color: #b9c3d6; font: 12px/1.45 ui-monospace, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.pin-acts { display: flex; gap: 6px; }
.pin-acts .btn { flex: 1; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
.pin-acts .btn.ok { background: var(--codex); border-color: var(--codex); color: #06210d; font-weight: 600; }
.pin-acts .btn.danger-text { color: var(--danger); }
.pin-replace-list { display: flex; flex-direction: column; gap: 8px; }
.pin-replace-item { display: flex; align-items: center; gap: 8px; justify-content: flex-start; min-height: 46px; text-align: left; }
@media (max-width: 820px), (pointer: coarse) and (max-height: 550px) {
  .pin-chip { min-width: 0; padding: 6px 7px; }
  .pin-add, .pin-panel-btn { min-height: 44px; }
  .pin-toggle { min-width: 36px; }
}

/* ===== Footer 4 tab (điện thoại) ===== */
.sidebar-tabs, .sidebar-schedules, .sidebar-usage { display: none; }
.stab-badge { position: absolute; top: 6px; left: calc(50% + 8px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px; background: var(--warn); color: #000; font: 700 10px/16px sans-serif; text-align: center; font-style: normal; }
.sidebar-schedules .sv-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-schedules h2, .sidebar-usage h2 { margin: 0; font-size: 17px; }
.sidebar-usage .sv-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sec-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 6px 2px 0; }
.sch-project-wrap { display: flex; flex-direction: column; gap: 3px; }
.pin-quick { display: inline-flex; gap: 4px; margin-left: 4px; }
.pin-quick button { min-width: 32px; min-height: 28px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); cursor: pointer; font-size: 14px; }
.pin-quick .pin-allow { background: var(--codex); border-color: var(--codex); color: #06210d; font-weight: 700; }
.pin-quick .pin-deny { color: var(--danger); }
@media (max-width: 820px), (pointer: coarse) and (max-height: 550px) {
  .sidebar { width: 100vw; max-width: none; }
  .sidebar-tabs { display: grid; grid-template-columns: repeat(5, 1fr); flex: none; height: calc(60px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--border); background: #121620; }
  .stab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: transparent; border: 0; color: var(--muted); font: inherit; font-size: 11px; cursor: pointer; min-height: 56px; }
  .stab b { font-size: 20px; font-weight: 400; line-height: 1; }
  .stab.on { color: var(--accent); }
  .stab.on::before { content: ''; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
  .stab:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
  .sidebar { padding-bottom: 0; }
  #btn-sidebar-more, .desktop-only-item { display: none !important; }
  .sidebar-more { display: none !important; }
  .sidebar[data-view='more'] .sidebar-more, .sidebar[data-view='more'] .sidebar-more.hidden { display: flex !important; flex: 1; overflow-y: auto; border-bottom: 0; }
  .sidebar[data-view='more'] .sidebar-more .more-item { min-height: 52px; }
  .sidebar[data-view='schedules'] .sidebar-schedules { display: flex; flex-direction: column; flex: 1; overflow-y: auto; gap: 8px; padding: 12px; }
  .sidebar[data-view='usage'] .sidebar-usage { display: flex; flex-direction: column; flex: 1; overflow-y: auto; gap: 10px; padding: 12px; }
  .sidebar .usage-drawer { display: none; }
  .sidebar[data-view='usage'] .sidebar-search-wrap, .sidebar[data-view='usage'] .project-tree, .sidebar[data-view='usage'] .sidebar-footer { display: none; }
  .sidebar-usage .usage-cards { max-height: none; }
  .sidebar[data-view='more'] .sidebar-search-wrap, .sidebar[data-view='more'] .project-tree, .sidebar[data-view='more'] .usage-drawer, .sidebar[data-view='more'] .sidebar-footer,
  .sidebar[data-view='schedules'] .sidebar-search-wrap, .sidebar[data-view='schedules'] .project-tree, .sidebar[data-view='schedules'] .usage-drawer, .sidebar[data-view='schedules'] .sidebar-footer { display: none; }
  .sidebar-footer { justify-content: stretch; }
  .sidebar-footer .btn { flex: 1; }
  .pin-quick button { min-width: 40px; min-height: 40px; }
}

/* ===== Tự phục hồi ===== */
.set-auto { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px 10px; display: flex; flex-direction: column; gap: 8px; }
.set-auto legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.set-check { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; }
.set-check input { width: 18px; height: 18px; flex: none; }
.set-inline { display: flex !important; flex-direction: row !important; align-items: center; justify-content: space-between; gap: 8px; }
.set-inline input { width: 72px; }
.auto-item { color: var(--warn); }

/* ===== Thông tin phiên ===== */
.si-findings { display: flex; flex-direction: column; gap: 6px; }
.si-finding { padding: 8px 10px; border-radius: 10px; font-size: 13px; line-height: 1.4; background: var(--panel-2); border: 1px solid var(--border); }
.si-finding.error { border-color: var(--danger); background: rgba(229, 83, 83, 0.12); }
.si-finding.warn { border-color: var(--warn); background: rgba(227, 179, 65, 0.1); }
.si-finding.ok { border-color: var(--codex); background: rgba(63, 185, 80, 0.1); }
.si-rows { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: 12.5px; }
.si-rows dt { color: var(--muted); }
.si-rows dd { margin: 0; overflow-wrap: anywhere; user-select: all; font-family: ui-monospace, Consolas, monospace; white-space: pre-wrap; }
.si-actions { flex-wrap: wrap; justify-content: stretch; }
.si-actions .btn { flex: 1; min-height: 44px; }

/* ===== Phân tầng giao diện: máy tính dùng dải chip; điện thoại dùng mục Ghim ở trang chủ ===== */
.pinned-section { display: none; }
body[data-screen='home'] .pinned-section { display: block; }
.topbar .active-sub { max-width: 100%; }
