* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  min-height: 100vh;
  color: #1a1a1a;
  background: #fdfdfd;
}
aside {
  width: 300px;
  flex-shrink: 0;
  background: #f5f6f8;
  border-right: 1px solid #e1e4e8;
  padding: 1.5em 1em;
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
  transition: width 0.2s ease, padding 0.2s ease, border-color 0.2s ease;
}
html.nav-collapsed aside {
  width: 0;
  min-width: 0;
  padding-left: 0;
  padding-right: 0;
  overflow: hidden;
  border-right-color: transparent;
}
/* Nav toggle now lives inside the top bar — no longer floats. */
.nav-toggle {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 5px;
  color: #e2e8f0;
  font-size: 1.05em;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.nav-toggle:hover { background: rgba(255,255,255,0.14); }
.nav-toggle:focus-visible { outline: 2px solid #3498db; outline-offset: 2px; }
/* Brand + version now live in the top bar — see .top-bar-brand below. */
aside .search-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.5em 0.7em;
  background: #fff;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  color: #718096;
  font: inherit;
  font-size: 0.9em;
  cursor: pointer;
  margin-bottom: 1em;
  text-align: left;
}
aside .search-trigger:hover {
  border-color: #a0aec0;
  background: #f7fafc;
}
aside .search-trigger .icon { color: #a0aec0; }
aside .search-trigger .label { flex: 1; }
aside .search-trigger kbd {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.78em;
  background: #edf2f7;
  border: 1px solid #cbd5e0;
  border-radius: 3px;
  padding: 0.05em 0.4em;
  color: #4a5568;
}

.search-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 1em 1em;
}
.search-modal[hidden] { display: none; }
.search-modal .backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}
.search-modal .dialog {
  position: relative;
  width: min(640px, 100%);
  max-height: 70vh;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.search-modal .header {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.85em 1em;
  border-bottom: 1px solid #e2e8f0;
}
.search-modal .header .icon { color: #a0aec0; font-size: 1.05em; }
.search-modal .header input {
  flex: 1;
  border: 0;
  outline: 0;
  font-size: 1.05em;
  background: transparent;
  color: #1a202c;
}
.search-modal .header .close {
  font-size: 0.75em;
  color: #4a5568;
  background: #edf2f7;
  border: 1px solid #cbd5e0;
  border-radius: 3px;
  padding: 0.1em 0.5em;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.search-modal .results {
  overflow-y: auto;
  padding: 0.4em 0;
}
.search-modal .results ul { list-style: none; margin: 0; padding: 0; }
.search-modal .results li {
  padding: 0.55em 1em;
  border-left: 3px solid transparent;
  cursor: pointer;
}
.search-modal .results li.active {
  background: #ebf5ff;
  border-left-color: #3498db;
}
.search-modal .results .title {
  font-weight: 600;
  color: #2c5282;
  font-size: 0.95em;
  margin-bottom: 0.15em;
}
.search-modal .results .snippet {
  font-size: 0.85em;
  color: #4a5568;
  line-height: 1.4;
  margin: 0.15em 0;
}
.search-modal .results .path {
  font-size: 0.78em;
  color: #718096;
  font-family: "DejaVu Sans Mono", "Menlo", monospace;
}
.search-modal .results mark { background: #fef3bd; padding: 0; }
.search-modal .empty,
.search-modal .hint {
  padding: 1em;
  color: #718096;
  font-size: 0.9em;
  margin: 0;
}
.search-modal .footer {
  padding: 0.55em 1em;
  border-top: 1px solid #e2e8f0;
  font-size: 0.75em;
  color: #718096;
  display: flex;
  flex-wrap: wrap;
  gap: 1em;
}
.search-modal .footer kbd {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #edf2f7;
  border: 1px solid #cbd5e0;
  border-radius: 3px;
  padding: 0.05em 0.4em;
  color: #4a5568;
  font-size: 0.92em;
}
body.search-open { overflow: hidden; }
aside nav details { margin: 0.2em 0; }
aside nav summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.35em 0.5em;
  color: #34495e;
  border-radius: 4px;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.4em;
}
aside nav summary::-webkit-details-marker { display: none; }
aside nav summary:hover { background: #e9ecef; }
aside nav ul { list-style: none; padding-left: 0.9em; margin: 0.2em 0; }
aside nav li {
  margin: 0;
  display: flex;
  align-items: center;
}
aside nav li > a {
  display: block;
  padding: 0.25em 0.5em;
  color: #2c5282;
  text-decoration: none;
  border-radius: 3px;
  font-size: 0.92em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
aside nav li > a:hover { background: #e9ecef; }
aside nav li > a.active { background: #3498db; color: white; }
aside nav li > details { flex: 1; min-width: 0; }
aside .nav-root { padding-left: 0; margin-bottom: 0.5em; }
aside .nav-root > li > a { font-weight: 600; }

/* ---- Changed-files panel (shows worktree-vs-main delta) ---- */

aside .changed-files-panel {
  margin: 0.6em 0 0.4em;
  padding: 0.35em 0.5em;
  background: #fff7e0;
  border: 1px solid #f5d57e;
  border-radius: 5px;
  font-size: 0.85em;
}
aside .changed-files-panel > summary {
  cursor: pointer;
  font-weight: 600;
  color: #745700;
  padding: 0.2em 0.3em;
  user-select: none;
}
aside .changed-files-panel > summary:hover { background: rgba(0,0,0,0.04); border-radius: 3px; }
aside .changed-files-list {
  list-style: none;
  padding: 0.2em 0 0;
  margin: 0;
}
aside .changed-files-list li {
  display: flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.15em 0;
}
aside .changed-files-link {
  display: flex;
  align-items: center;
  gap: 0.4em;
  flex: 1;
  min-width: 0;
  color: #4a5568;
  text-decoration: none;
  padding: 0.2em 0.4em;
  border-radius: 3px;
}
aside .changed-files-link:hover { background: rgba(0,0,0,0.05); color: #1a202c; }
aside .changed-files-link-disabled {
  opacity: 0.6;
  cursor: default;
}
aside .changed-files-link-disabled:hover { background: transparent; color: inherit; }
aside .changed-files-path {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
}
aside .changed-files-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  border-radius: 2px;
  font-size: 0.7em;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
aside .changed-files-status[data-status="M"] { background: #d97706; }   /* modified */
aside .changed-files-status[data-status="A"] { background: #2563eb; }   /* added */
aside .changed-files-status[data-status="D"] { background: #dc2626; }   /* deleted */
aside .changed-files-status[data-status="?"] { background: #6b7280; }   /* untracked */
aside .changed-files-status[data-status="R"] { background: #7c3aed; }   /* renamed */
aside .changed-files-edit {
  color: #6a737d;
  text-decoration: none;
  padding: 0 0.35em;
  font-size: 0.95em;
  opacity: 0.6;
}
aside .changed-files-edit:hover { opacity: 1; color: #1f6feb; }

/* ---- Inline action buttons on nav rows (edit / delete / new) ---- */

aside .nav-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 0.25em 0;
}
aside .nav-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.1em;
  opacity: 0.35;
  transition: opacity 0.1s;
  flex-shrink: 0;
}
aside nav li:hover > .nav-actions,
aside nav summary:hover .nav-actions,
aside .nav-actions:hover,
aside .nav-actions:focus-within { opacity: 1; }
aside .nav-action {
  background: transparent;
  border: 1px solid transparent;
  color: #4a5568;
  padding: 0.1em 0.35em;
  font-size: 0.85em;
  line-height: 1.2;
  cursor: pointer;
  border-radius: 3px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
aside .nav-action:hover { background: #e2e8f0; border-color: #cbd5e0; color: #1a202c; }
aside .nav-toolbar .nav-action {
  padding: 0.25em 0.6em;
  background: #fff;
  border-color: #cbd5e0;
  font-size: 0.8em;
}
aside .nav-toolbar .nav-action:hover { background: #f7fafc; }

/* ---- Sidebar helpers row (⏶ Collapse all / ⏷ Expand all / ☑ Show selected) ---- */

aside .nav-helpers {
  display: flex;
  gap: 0.25em;
  padding: 0.3em 0 0.4em;
  align-items: center;
}
aside .nav-helper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2em;
  height: 1.8em;
  padding: 0 0.4em;
  background: #fff;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
  color: #4a5568;
  font-size: 0.95em;
  line-height: 1;
  cursor: pointer;
}
aside .nav-helper:hover { background: #edf2f7; color: #1a202c; }
aside .nav-helper:focus-visible {
  outline: 2px solid #3498db;
  outline-offset: 1px;
}
aside .nav-helper-show-selected.is-active {
  background: #3498db;
  border-color: #2b7cb3;
  color: white;
}

/* ---- Group-assignment checkboxes (admin + active group) ---- */

aside nav .nav-assign-cb {
  flex-shrink: 0;
  margin: 0 0.15em 0 0;
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: #3498db;
}
aside nav .nav-li-hidden-unselected { display: none; }

/* ---- Floating Save pill for group-assignment changes ---- */

.nav-save-pill {
  position: fixed;
  bottom: 1em;
  left: 1em;
  z-index: 900;
  display: none;
  align-items: center;
  gap: 0.5em;
  padding: 0.55em 0.75em;
  background: #1f2937;
  color: #f7fafc;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.25);
  font-size: 0.85em;
  max-width: calc(300px - 2em);
}
.nav-save-pill.visible { display: inline-flex; }
.nav-save-pill-count {
  font-weight: 600;
  margin-right: 0.3em;
  white-space: nowrap;
}
.nav-save-pill button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.25em 0.75em;
  font: inherit;
  cursor: pointer;
}
.nav-save-pill-cancel {
  background: transparent;
  color: #cbd5e0;
}
.nav-save-pill-cancel:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
.nav-save-pill-save {
  background: #3498db;
  color: white;
  font-weight: 600;
}
.nav-save-pill-save:hover:not(:disabled) { background: #2b7cb3; }
.nav-save-pill button:disabled { opacity: 0.6; cursor: default; }
html.nav-collapsed .nav-save-pill { display: none; }

/* "+ New" popup chooser menu — attached to <body> so it can escape aside's clip. */
.nav-new-menu {
  position: absolute;
  z-index: 1000;
  background: #fff;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.14);
  padding: 0.25em 0;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
}
.nav-new-menu button {
  background: none;
  border: none;
  text-align: left;
  padding: 0.45em 0.75em;
  cursor: pointer;
  font: inherit;
  color: #1f2328;
}
.nav-new-menu button:hover { background: #eef4ff; }
@media (prefers-color-scheme: dark) {
  .nav-new-menu {
    background: #1c2230;
    border-color: #2a3142;
  }
  .nav-new-menu button { color: #e6ebf4; }
  .nav-new-menu button:hover { background: #232a3a; }
}
aside .chat-link {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.5em 0.7em;
  background: #fff;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  color: #2c5282;
  font-size: 0.9em;
  text-decoration: none;
  margin-bottom: 1em;
  font-weight: 600;
}
aside .chat-link:hover { background: #f7fafc; border-color: #a0aec0; }
aside .chat-link.active { background: #3498db; color: white; border-color: #3498db; }
aside .chat-link .icon { font-size: 1em; }
aside .chat-link .label { flex: 1; }

aside .pdf-download-link {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-top: 1em;
  padding: 0.6em 0.75em;
  background: #f5f6f8;
  border-top: 1px solid #e1e4e8;
  color: #4a5568;
  font-size: 0.85em;
  text-decoration: none;
  transition: background 0.15s;
}
aside .pdf-download-link:hover { background: #e9ecef; color: #2c3e50; }
aside .pdf-download-link .icon { font-size: 1em; color: #e74c3c; }
aside .pdf-download-link .label { flex: 1; }
aside .pdf-download-link .version { font-size: 0.8em; color: #a0aec0; }

/* ---- Always-visible top bar (logged-in users) ---- */

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0 0.75em;
  background: #1f2933;
  color: #e2e8f0;
  border-bottom: 1px solid #11171f;
  z-index: 150;
  font-size: 0.85em;
}
body.has-top-bar { padding-top: 44px; }
body.has-top-bar aside { top: 44px; height: calc(100vh - 44px); }

.top-bar-brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5em;
  color: #e2e8f0;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95em;
  padding: 0 0.4em 0 0.2em;
  white-space: nowrap;
}
.top-bar-brand:hover { color: #ffffff; }
.top-bar-brand-version {
  font-size: 0.78em;
  font-weight: 500;
  color: #cbd5e0;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  padding: 0.05em 0.4em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.top-bar-status {
  color: #cbd5e0;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.85em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top-bar-spacer { flex: 1; }
.top-bar-user {
  color: #cbd5e0;
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0 0.5em;
  white-space: nowrap;
}
.top-bar-role {
  background: rgba(255,255,255,0.12);
  padding: 0.05em 0.4em;
  border-radius: 3px;
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.top-bar-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.35em 0.75em;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 5px;
  color: #e2e8f0;
  font-size: 0.85em;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
}
.top-bar-btn:hover:not(:disabled) { background: rgba(255,255,255,0.12); }
.top-bar-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.top-bar-btn-primary {
  background: #2b6cb0;
  border-color: #2b6cb0;
}
.top-bar-btn-primary:hover:not(:disabled) { background: #2c5282; border-color: #2c5282; }
.top-bar-btn-danger {
  background: transparent;
  border-color: rgba(245, 101, 101, 0.4);
  color: #fc8181;
}
.top-bar-btn-danger:hover:not(:disabled) {
  background: rgba(245, 101, 101, 0.15);
  border-color: rgba(245, 101, 101, 0.7);
}
.top-bar-logout-form { margin: 0; display: inline; }

.top-bar-viewas {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0 0.5em;
  white-space: nowrap;
}
.top-bar-viewas-label {
  color: #94a3b8;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.top-bar-select {
  background: rgba(255,255,255,0.08);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 0.25em 0.5em;
  font-size: 0.85em;
  font-family: inherit;
  cursor: pointer;
}
.top-bar-select:hover { background: rgba(255,255,255,0.14); }
.top-bar-select option { background: #1f2933; color: #e2e8f0; }


main {
  flex: 1;
  padding: 2.5em 3.5em;
  overflow-x: auto;
  max-width: 100%;
}
main #content { max-width: 60em; }
#content hr {
  border: none;
  border-top: 1px solid #e1e4e8;
  margin: 2.5rem 0 1.5rem;
}
main .page-title {
  font-size: 2.6em;
  font-weight: 700;
  color: #1a202c;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0.2em 0 0.6em 0;
  padding-bottom: 0.35em;
  border-bottom: 3px solid #3498db;
}
main h1 { color: #2c3e50; margin-top: 1.4em; }
main h2 { margin-top: 1.6em; color: #34495e; }
main h3 { color: #34495e; }
main pre {
  background: #f5f6f8;
  padding: 0.8em 1em;
  border-radius: 6px;
  overflow-x: auto;
  font-family: "DejaVu Sans Mono", "Menlo", monospace;
  font-size: 0.88em;
  line-height: 1.45;
}
main code { background: #f1f3f5; padding: 0.1em 0.35em; border-radius: 3px; font-size: 0.9em; }
main pre code { background: transparent; padding: 0; }
main img, main svg { max-width: 100%; height: auto; }
main a { color: #2c5282; }
main blockquote {
  border-left: 4px solid #cbd5e0;
  padding-left: 1em;
  color: #4a5568;
  margin: 1em 0;
}
main table { border-collapse: collapse; margin: 1em 0; }
main th, main td { border: 1px solid #cbd5e0; padding: 0.4em 0.7em; }
main th { background: #f5f6f8; }

/* Shared "empty state" card used by the server-side 404 template and the
   PWA's renderEmptyState (no-index landing, missing page). */
.err-card { background: #fff; border-radius: 10px; padding: 2rem 2rem 1.75rem; box-shadow: 0 1px 6px rgba(0,0,0,0.05); max-width: 720px; margin: 1rem 0; }
.err-eyebrow { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: #6b7280; margin: 0 0 .4rem; }
.err-title { font-size: 1.4rem; margin: 0 0 .75rem; border-bottom: none; padding: 0; }
.err-body { color: #374151; line-height: 1.55; margin: 0 0 1rem; }
.err-path { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #f3f4f6; padding: .15rem .4rem; border-radius: 4px; word-break: break-all; }
.err-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.25rem; }
.err-btn { display: inline-block; padding: .5rem .9rem; border-radius: 6px; text-decoration: none; font-size: .9rem; border: 1px solid #d1d5db; background: #fff; color: #111827; }
.err-btn-primary { background: #111827; color: #fff; border-color: #111827; }
.err-hint { color: #6b7280; font-size: .85rem; margin-top: 1rem; }

@media (max-width: 768px) {
  aside {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100vh;
    width: 280px;
    z-index: 150;
    box-shadow: 4px 0 12px rgba(0,0,0,0.12);
  }
  main { padding: 3.2em 1.25em 1.5em; }
}
