/* =====================================================================
   SHELL — Sidebar + Topbar + Main layout (Modern Minimal style)
   ===================================================================== */

/* ============ APP LAYOUT ============ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  background: var(--bg-app);
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
}

/* ============ SIDEBAR ============ */
.sidebar {
  background: var(--bg-light);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
}
@media (max-width: 900px) {
  .sidebar { position: fixed; transform: translateX(-100%); z-index: 100; width: 240px; box-shadow: var(--shadow-modal); transition: transform .25s; }
  .sidebar.show { transform: translateX(0); }
}

.sb-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 18px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.sb-brand .logo {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--grad-logo);
  display: grid; place-items: center;
  font-size: 15px; color: #fff; font-weight: 800;
  flex-shrink: 0;
}
.sb-brand .name {
  font-size: 15px; font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb-brand .ver { font-size: 9px; color: var(--text-faint); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; margin-top: 1px; }

.sb-section { padding: 14px 0 4px; }
.sb-section:first-of-type { padding-top: 4px; }
.sb-title {
  padding: 6px 10px;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-faint);
  display: flex; justify-content: space-between; align-items: center;
}
.sb-title .add { color: var(--text-mute); cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.sb-title .add:hover { background: var(--bg-board); color: var(--text); }

.sb-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--text-mute);
  font-size: 13.5px; font-weight: 500;
  cursor: pointer; position: relative;
  transition: all .12s;
  text-decoration: none;
}
.sb-link:hover { background: var(--bg-board); color: var(--text); }
.sb-link.active {
  background: var(--text);
  color: var(--text-inv);
  font-weight: 600;
}
.sb-link.active .badge { background: rgba(255,255,255,.18); color: #fff; }
.sb-link .icon { width: 18px; text-align: center; flex-shrink: 0; font-size: 15px; }
.sb-link .badge {
  margin-left: auto;
  background: var(--bg-board);
  color: var(--text-mute);
  padding: 1px 8px;
  border-radius: var(--r-pill);
  font-size: 11px; font-weight: 700;
  min-width: 22px; text-align: center;
}

.sb-foot {
  margin-top: auto;
  padding: 12px 10px 0;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--text-faint);
}
.sb-foot .theme-toggle, .sb-foot .foot-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: grid; place-items: center;
  color: var(--text-mute);
  cursor: pointer;
  transition: all .12s;
}
.sb-foot .theme-toggle:hover, .sb-foot .foot-btn:hover {
  background: var(--bg-board); color: var(--text);
}
.sb-foot .ver-label { flex: 1; font-weight: 600; letter-spacing: 0.04em; }

/* ============ MAIN ============ */
.main {
  background: var(--bg-app);
  min-width: 0;
  display: flex; flex-direction: column;
  position: relative;
}
.main::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at 1px 1px, rgba(0,0,0,.025) 1px, transparent 0);
  background-size: 28px 28px;
  pointer-events: none;
  z-index: 0;
}
[data-theme="dark"] .main::before {
  background-image: radial-gradient(circle at 1px 1px, rgba(255,255,255,.025) 1px, transparent 0);
}
.main > * { position: relative; z-index: 1; }

/* ============ TOPBAR ============ */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 12px;
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  flex-shrink: 0;
}
.sb-toggle {
  display: none;
  width: 36px; height: 36px;
  border-radius: 8px;
  align-items: center; justify-content: center;
  font-size: 18px;
  color: var(--text-mute);
  background: var(--bg-board);
}
.sb-toggle:hover { background: var(--border); color: var(--text); }
@media (max-width: 900px) { .sb-toggle { display: inline-flex; } }

.topbar .crumb {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.topbar .crumb .sep { color: var(--text-faint); font-weight: 400; }
.topbar .crumb .sub { color: var(--text-mute); font-weight: 500; font-size: 12.5px; }

.topbar .spacer { flex: 1; min-width: 12px; }

.topbar .updated {
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.topbar .updated .live-dot {
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ok);
  margin-right: 4px;
  vertical-align: middle;
  animation: ping 2s infinite;
}

.topbar .btn {
  padding: 7px 12px;
  border-radius: var(--r-sm);
  color: var(--text-mute);
  font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .12s;
  text-decoration: none;
  border: 1px solid transparent;
  white-space: nowrap;
}
.topbar .btn:hover { background: var(--bg-board); color: var(--text); border-color: var(--border); }
.topbar .btn.primary { background: var(--text); color: var(--text-inv); }
.topbar .btn.primary:hover { background: var(--primary-hover); border-color: transparent; }
.topbar .btn.ghost { background: transparent; }

/* Search box */
.search-box {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  background: var(--bg-board);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  min-width: 220px;
  color: var(--text-mute);
  transition: all .15s;
}
.search-box:focus-within {
  border-color: var(--accent);
  background: var(--bg-light);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.search-box input {
  background: transparent; border: none; outline: none;
  flex: 1; font-size: 13px; color: var(--text);
  min-width: 0;
}
.search-box input::placeholder { color: var(--text-faint); }
.search-box .kbd {
  font-family: var(--font-mono);
  font-size: 10px; padding: 2px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text-faint);
  background: var(--bg-light);
}

/* ============ PAGE CONTENT ============ */
.page {
  flex: 1;
  padding: 24px 32px 80px;
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  animation: fadeIn .3s ease;
}
@media (max-width: 768px) {
  .page { padding: 16px 14px 80px; }
}

.page-head {
  margin-bottom: 20px;
}
.page-head h1 {
  font-size: 24px; font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}
.page-head .sub {
  color: var(--text-mute);
  font-size: 13px;
  margin-top: 4px;
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ============ CMD+K PALETTE ============ */
.cmdk-bg {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: none; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  animation: fadeIn .15s;
}
.cmdk-bg.show { display: flex; }
.cmdk {
  width: 100%; max-width: 640px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: slideUp .2s ease;
}
.cmdk-search {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.cmdk-search .icon { color: var(--text-faint); font-size: 18px; }
.cmdk-search input {
  flex: 1; border: none; outline: none;
  font-size: 15px; background: transparent; color: var(--text);
}
.cmdk-search input::placeholder { color: var(--text-faint); }
.cmdk-search .kbd {
  font-family: var(--font-mono); font-size: 10px;
  padding: 2px 6px; border: 1px solid var(--border-strong);
  border-radius: 4px; color: var(--text-faint);
}
.cmdk-results {
  max-height: 60vh; overflow-y: auto;
  padding: 6px;
}
.cmdk-hint, .cmdk-empty {
  padding: 20px; text-align: center;
  color: var(--text-faint); font-size: 13px;
}
.cmdk-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background .1s;
}
.cmdk-item:hover, .cmdk-item.active { background: var(--bg-board); }
.cmdk-item .icon { font-size: 18px; width: 24px; text-align: center; }
.cmdk-item .text { flex: 1; min-width: 0; }
.cmdk-item .title {
  font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cmdk-item .sub {
  font-size: 12px; color: var(--text-mute);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cmdk-item .kind {
  font-size: 10px; font-weight: 700;
  padding: 2px 8px; border-radius: var(--r-pill);
  background: var(--bg-board); color: var(--text-mute);
  text-transform: uppercase; letter-spacing: 0.06em;
}

/* ============ TOAST ============ */
.toast {
  background: var(--text);
  color: var(--text-inv);
  padding: 10px 16px;
  border-radius: var(--r);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-card-hover);
  animation: slideUp .2s ease;
  transition: opacity .3s;
  max-width: 360px;
}
.toast-info { background: var(--text); color: var(--text-inv); }
.toast-ok { background: var(--ok); color: #fff; }
.toast-warn { background: var(--warn); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

/* ============ SKELETON ============ */
.skeleton {
  background: linear-gradient(90deg, var(--bg-board) 0%, var(--border) 50%, var(--bg-board) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r);
}
.skeleton-card { height: 80px; margin-bottom: 8px; }
.skeleton-text { height: 12px; margin-bottom: 6px; }
.skeleton-stat { height: 60px; }

/* ============ QUICK ADD MODAL ============ */
.quickadd { max-width: 560px; }
.quickadd-body {
  display: flex; flex-direction: column; gap: 10px;
  padding: 22px 26px;
}
.quickadd-body label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11.5px; font-weight: 600; color: var(--text-mute);
  letter-spacing: 0.02em;
}
.quickadd-body label.row { flex: 1; }
.quickadd-body .row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.quickadd-body input,
.quickadd-body select,
.quickadd-body textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--bg-app); font-size: 13px; color: var(--text);
  font-family: inherit; font-weight: 400;
  outline: none; transition: border-color .12s, box-shadow .12s;
}
.quickadd-body input:focus,
.quickadd-body select:focus,
.quickadd-body textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.1); background: var(--bg-light);
}
.quickadd-body textarea { resize: vertical; min-height: 50px; font-family: var(--font-mono); font-size: 12px; }
.qa-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* CmdK filter tags */
.cmdk-filter { display: inline-block; padding: 1px 8px; border-radius: var(--r-pill); background: var(--bg-board); color: var(--text-mute); font-size: 11px; margin: 0 4px 0 0; }
.cmdk-filter b { color: var(--text); font-weight: 700; }

/* Saved views */
.sb-loading { font-size: 11px; color: var(--text-faint); padding: 4px 10px; }
.sb-view {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: var(--r-sm);
  color: var(--text-mute); font-size: 12.5px; font-weight: 500;
  cursor: pointer; text-decoration: none; position: relative;
  transition: all .12s;
}
.sb-view:hover { background: var(--bg-board); color: var(--text); }
.sb-view .ico { font-size: 14px; }
.sb-view .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-view .del {
  opacity: 0; transition: opacity .12s;
  background: none; border: none; cursor: pointer;
  color: var(--text-faint); font-size: 14px; padding: 0 4px;
}
.sb-view:hover .del { opacity: 1; }
.sb-view .del:hover { color: var(--danger); }

/* ============ SHORTCUTS OVERLAY ============ */
.shortcuts-bg {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.shortcuts-bg.show { display: flex; animation: fadeIn .15s; }
.shortcuts-modal {
  width: 100%; max-width: 720px; max-height: 85vh; overflow-y: auto;
  background: var(--bg-light);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-modal);
  animation: slideUp .2s ease;
}
.shortcuts-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-light); z-index: 1;
}
.shortcuts-head h2 {
  font-size: 18px; font-weight: 700; letter-spacing: -0.01em;
}
.shortcuts-body {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0;
}
@media (max-width: 700px) { .shortcuts-body { grid-template-columns: 1fr; } }
.shortcuts-group {
  padding: 16px 22px;
  border-right: 1px solid var(--border);
}
.shortcuts-group:last-child { border-right: none; }
@media (max-width: 700px) {
  .shortcuts-group { border-right: none; border-bottom: 1px solid var(--border); }
  .shortcuts-group:last-child { border-bottom: none; }
}
.shortcuts-group h3 {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 12px;
}
.shortcut-row {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 0;
  font-size: 12.5px;
}
.shortcut-row .keys {
  display: flex; gap: 4px; align-items: center;
  min-width: 110px;
}
.shortcut-row .desc { color: var(--text-mute); }
.kbd {
  font-family: var(--font-mono);
  font-size: 10.5px; font-weight: 600;
  padding: 2px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-app);
  color: var(--text);
  display: inline-block; min-width: 18px; text-align: center;
}
.shortcuts-foot {
  padding: 12px 22px;
  background: var(--bg-board);
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-mute);
  text-align: center;
}
.shortcuts-foot code {
  font-family: var(--font-mono);
  padding: 1px 6px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11.5px;
}

/* ============ 3-LEVEL SIDEBAR (WORKSPACE/CAPABILITY/SYSTEM) ============ */
.sb-section.collapsible .sb-title { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 6px; }
.sb-section.collapsible .sb-title:hover { color: var(--text, #18181b); }
.sb-section.collapsible.collapsed > a { display: none; }
.sb-section.collapsible.collapsed .caret { transform: rotate(-90deg); }
.caret { margin-left: auto; font-size: 10px; opacity: 0.5; transition: transform .15s; }
.sb-title .dot {
  width: 6px; height: 6px; border-radius: 50%; display: inline-block;
}
.dot-workspace { background: #f59e0b; box-shadow: 0 0 6px rgba(245,158,11,.5); }
.dot-capability { background: #3b82f6; box-shadow: 0 0 6px rgba(59,130,246,.5); }
.dot-system { background: #10b981; box-shadow: 0 0 6px rgba(16,185,129,.5); }

/* ============ BRANCH INDICATOR ============ */
.branch-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: var(--bg-app, #f4f4f5);
  border: 1px solid var(--border, #e4e4e7);
  border-radius: 8px;
  font-size: 11.5px; font-weight: 500;
  color: var(--text, #18181b);
  font-family: var(--font-mono, monospace);
  margin-right: 8px;
}
.branch-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px rgba(16,185,129,.5);
  animation: branchPulse 2s ease-in-out infinite;
}
@keyframes branchPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.branch-name { color: var(--text, #18181b); font-weight: 600; }
.branch-count {
  padding: 1px 5px;
  background: var(--bg-light, #fff);
  border: 1px solid var(--border, #e4e4e7);
  border-radius: 4px;
  font-size: 10px;
  color: var(--text-mute, #71717a);
}

/* ============ BREADCRUMB ENHANCEMENT ============ */
.crumb-home { text-decoration: none; color: var(--text-mute, #71717a); font-size: 14px; }
.crumb-home:hover { color: var(--accent, #2563eb); }
.crumb-link { color: var(--text-mute, #71717a); text-decoration: none; }
.crumb-link:hover { color: var(--accent, #2563eb); }
.crumb-active { color: var(--text, #18181b); font-weight: 600; }
.crumb .sep { color: var(--text-faint, #a1a1aa); margin: 0 4px; }
