/* =============================================================================
   CODEVIEW component — default theme
   ============================================================================= */

/* As wide as the site lets the page be (site.fson screen_width): a file tree
   beside a code pane, and above all two files side by side, want the room.
   <page>.fson width: "restricted" keeps a centred column on a full-width site. */
.page-codeview {
  padding: 0 24px;
  box-sizing: border-box;
}
.page-codeview.cv-restricted {
  max-width: 1200px;
  margin: 0 auto;
}

.cv-empty,
.cv-notfound,
.cv-indexing,
.cv-search-indexing {
  display: block;
  padding: 24px 0;
  color: #777;
  font-style: italic;
}

/* ── breadcrumbs ── */
.cv-breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px;
  margin: 4px 0 18px;
  font-size: 0.95em;
}

.cv-crumb {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: #1b52a8;
  text-decoration: none;
}
.cv-crumb:hover { text-decoration: underline; }

.cv-crumb-current {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: #444;
  font-weight: 600;
}

.cv-crumb-sep {
  color: #aaa;
  padding: 0 2px;
}

/* ── git metadata panel ── */
.cv-git {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  align-items: baseline;
  padding: 10px 14px;
  margin-bottom: 16px;
  background: #f7f7f7;
  border-radius: 6px;
  font-size: 0.9em;
}

.cv-git-row {
  display: flex;
  min-width: 0;
  gap: 6px;
}

.cv-git-label {
  color: #888;
}

.cv-git-value {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: #333;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.cv-git-message {
  flex-basis: 100%;
  color: #555;
  font-style: italic;
}

/* ── search box ── */
.cv-search {
  margin-bottom: 16px;
}

.cv-search-input {
  width: 100%;
  max-width: 420px;
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-sizing: border-box;
  font-size: 0.95em;
}

.cv-search-results {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cv-search-hit {
  color: #1b52a8;
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}
.cv-search-hit:hover { text-decoration: underline; }

/* ── repo-list landing view ──
   minmax(260px, 320px) (not 1fr) so a handful of cards on a wide screen
   keep a sane width instead of stretching edge to edge — the grid packs
   from the start instead of spreading remaining columns out. */
.cv-repo-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 320px));
  justify-content: start;
  gap: 16px;
}

.cv-repo-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-left: 3px solid #888;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.cv-repo-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.09);
}

.cv-repo-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.cv-repo-icon {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 1px;
}

.cv-repo-titlebox {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.cv-repo-name {
  display: block;
  font-weight: 600;
  color: #1b52a8;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cv-repo-name:hover { text-decoration: underline; }

.cv-repo-badge {
  display: inline-block;
  align-self: flex-start;
  padding: 1px 7px;
  color: #666;
  background: #f1f1f1;
  border-radius: 999px;
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.cv-repo-desc {
  display: block;
  color: #555;
  font-size: 0.88em;
  line-height: 1.35;
}

.cv-repo-meta {
  display: block;
  margin-top: auto;
  padding-top: 4px;
  color: #888;
  font-size: 0.85em;
}

/* ── directory tree ── */
.cv-tree {
  display: flex;
  flex-direction: column;
  border: 1px solid #eee;
  border-radius: 6px;
  overflow: hidden;
}

.cv-tree-row {
  padding: 7px 12px;
  border-bottom: 1px solid #f0f0f0;
}
.cv-tree-row:last-child { border-bottom: none; }
.cv-tree-row:hover { background: #f7f7f7; }

.cv-tree-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #222;
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.cv-tree-dir .cv-tree-link { font-weight: 600; }
.cv-tree-link:hover { text-decoration: underline; }

.cv-tree-icon {
  flex: none;
  width: 16px;
  height: 16px;
}

/* ── file view ── */
.cv-file-note {
  display: block;
  margin-bottom: 10px;
  color: #a35c00;
}

.cv-btn {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 6px;
  background: #1b52a8;
  color: #fff;
  text-decoration: none;
  font-size: 0.9em;
}
.cv-btn:hover { opacity: 0.9; }

.cv-file-body {
  display: block;
}
.cv-file-body pre.cv-file {
  margin: 0;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.cv-file-body pre.cv-file code {
  font-size: 0.88em;
  line-height: 1.5;
}

/* ── "tree" view mode: persistent sidebar + content pane ── */
.cv-layout {
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

.cv-sidebar {
  flex: 0 0 260px;
  max-width: 260px;
  position: sticky;
  top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cv-sidebar-backlink {
  display: block;
  color: #1b52a8;
  text-decoration: none;
  font-size: 0.85em;
  margin-bottom: 4px;
}
.cv-sidebar-backlink:hover { text-decoration: underline; }

.cv-sidebar-scroll {
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 6px;
  padding: 6px 0;
}

.cv-sbnode {
  padding: 3px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cv-sbnode-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #333;
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
}
.cv-sbnode--dir .cv-sbnode-link { font-weight: 600; color: #222; }
.cv-sbnode-link:hover { text-decoration: underline; }

.cv-sbnode-icon {
  flex: none;
  width: 14px;
  height: 14px;
}

.cv-sbnode--active {
  background: #eaf1fb;
  border-radius: 4px;
}
.cv-sbnode--active .cv-sbnode-link { color: #1b52a8; font-weight: 600; }

.cv-content {
  flex: 1 1 auto;
  min-width: 0;
}

.cv-readme {
  display: block;
  line-height: 1.6;
}

/* "tree" mode directory landing with no matching landing_files entry —
   centered both ways, never the plain listing (see buildDirContent()). */
.cv-empty-pane {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  color: #999;
  font-style: italic;
  text-align: center;
}

/* Narrow viewports: stack sidebar above content instead of side-by-side. */
@media (max-width: 720px) {
  .cv-layout { flex-direction: column; }
  .cv-sidebar { position: static; max-width: none; width: 100%; }
  .cv-sidebar-scroll { max-height: 40vh; }
  .cv-repo-list { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

/* ── breadcrumb-row trailing controls (theme toggle + render-preview
   toggle) — one shared flush-right wrapper (.cv-breadcrumbs is already
   display:flex; margin-left:auto on THIS wrapper, not on the individual
   controls, so either one can be absent without the other losing its
   flush-right position — same "flush right in a flex row" idiom used
   elsewhere for a group-heading chevron). ── */
.cv-breadcrumb-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.cv-render-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  color: #333;
  font-size: 0.85em;
  cursor: pointer;
}
.cv-render-toggle:hover { background: #f2f2f2; }
.cv-render-toggle-icon { width: 16px; height: 16px; }

.cv-render-preview {
  display: block;
  line-height: 1.6;
}

.cv-render-failed {
  color: #a33;
  font-style: italic;
}

/* ── dark/light highlight-theme toggle — sun shown while the dark theme
   is active (click for light), moon shown once light is active (click
   for dark); see CodeviewPage::buildThemeToggle() for the JS. ── */
.cv-theme-toggle {
  display: inline-flex;
  align-items: center;
  color: #666;
  cursor: pointer;
  padding: 2px;
}
.cv-theme-toggle:hover { color: #333; }
.cv-theme-toggle .cv-theme-icon-moon { display: none; }
.cv-theme-toggle[data-theme="light"] .cv-theme-icon-sun  { display: none; }
.cv-theme-toggle[data-theme="light"] .cv-theme-icon-moon { display: inline; }

/* ── built-in hex-view fallback ── */
.cv-hex {
  display: block;
  overflow-x: auto;
  font-size: 0.82em;
  line-height: 1.5;
  white-space: pre;
}

/* ── image file view: Preview / Hex / Info toggles (reuses
   .cv-render-toggle/.cv-render-toggle-icon for the buttons themselves —
   same look as the generic render-preview toggle, no accent-color
   dependency so one block covers all 3 themes). ── */
.cv-image-preview {
  max-width: 100%;
  height: auto;
  display: block;
}

.cv-image-info {
  border-collapse: collapse;
  font-size: 0.88em;
}
.cv-image-info caption {
  text-align: left;
  font-weight: 600;
  padding: 4px 8px;
  color: #666;
}
.cv-image-info td {
  padding: 4px 8px;
  border-bottom: 1px solid #eee;
}
.cv-image-info td:first-child {
  color: #666;
  white-space: nowrap;
}

/* ── compare view (0.8.0.0) ─────────────────────────────────────────────── */
.cv-compare-offer {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin: -6px 0 16px;
  font-size: 0.92em;
}
.cv-compare-offer-label { color: #777; }
.cv-compare-offer-link {
  padding: 2px 10px;
  border: 1px solid #1b52a8;
  border-radius: 999px;
  color: #1b52a8;
  text-decoration: none;
}
.cv-compare-offer-link:hover { background: #eaf1fb; }

.cv-cmp-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
  margin: 0 0 10px;
  font-size: 1.05em;
}
.cv-cmp-side { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-decoration: none; }
.cv-cmp-side--left  { color: #a3261b; }
.cv-cmp-side--right { color: #1f7a35; }
.cv-cmp-arrow { color: #999; }
.cv-cmp-swap { margin-left: auto; font-size: 0.85em; color: #1b52a8; text-decoration: none; }

.cv-cmp-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  margin: 0 0 14px;
  font-size: 0.9em;
  color: #555;
}
.cv-cmp-count--modified  { color: #9a6700; }
.cv-cmp-count--added     { color: #1f7a35; }
.cv-cmp-count--removed   { color: #a3261b; }
.cv-cmp-toggle { margin-left: auto; }
.cv-cmp-toggle input { margin-right: 6px; }

.cv-cmp-layout {
  display: flex;
  align-items: flex-start;
  gap: 20px;
}
.cv-cmp-files {
  flex: 0 0 280px;
  max-width: 280px;
  max-height: 80vh;
  overflow-y: auto;
  position: sticky;
  top: 12px;
  display: flex;
  flex-direction: column;
  font-size: 0.86em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.cv-cmp-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 4px;
  color: #333;
  text-decoration: none;
  min-width: 0;
}
.cv-cmp-row:hover { background: #eaf1fb; }
.cv-cmp-row--unchanged { display: none; color: #888; }
.cv-cmp-files--all .cv-cmp-row--unchanged,
.cv-cmp-row--unchanged.cv-cmp-row--active { display: flex; }
.cv-cmp-row--active { background: #eaf1fb; font-weight: 600; }
.cv-cmp-icon { width: 16px; height: 16px; flex: 0 0 16px; }
.cv-cmp-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cv-cmp-dirrow {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  color: #666;
}
.cv-cmp-dirrow--unchanged { display: none; }
.cv-cmp-files--all .cv-cmp-dirrow--unchanged { display: flex; }
.cv-cmp-badge {
  flex: 0 0 18px;
  text-align: center;
  font-size: 0.8em;
  font-weight: 700;
  border-radius: 3px;
  color: #fff;
}
.cv-cmp-badge--modified  { background: #bf8700; }
.cv-cmp-badge--added     { background: #2da44e; }
.cv-cmp-badge--removed   { background: #cf222e; }
.cv-cmp-badge--unchanged { background: #bbb; }

.cv-cmp-pane { flex: 1 1 auto; min-width: 0; }
.cv-diff-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-bottom: 10px;
}
.cv-diff-title { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 600; }
.cv-diff-stats { display: flex; gap: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.cv-diff-stat-add { color: #1f7a35; }
.cv-diff-stat-del { color: #a3261b; }
.cv-diff-toggle {
  border: 1px solid #1b52a8;
  cursor: pointer;
  background: #fff;
  color: #1b52a8;
}
.cv-diff-toggle + .cv-diff-toggle { margin-left: 0; }
.cv-diff-stats + .cv-diff-toggle { margin-left: auto; }
.cv-diff-toggle--on { background: #1b52a8; color: #fff; }

.cv-diff-scroll {
  overflow-x: auto;
  border: 1px solid #e3e3e3;
  border-radius: 8px;
}
table.cv-diff {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82em;
  line-height: 1.45;
}
table.cv-diff th {
  text-align: left;
  padding: 6px 10px;
  background: #f6f8fa;
  border-bottom: 1px solid #e3e3e3;
  font-weight: 600;
}
table.cv-diff td { padding: 0 8px; vertical-align: top; }
table.cv-diff col.cv-diff-col-ln { width: 3.4em; }
.cv-diff-ln {
  text-align: right;
  color: #999;
  user-select: none;
  background: #fafbfc;
}
.cv-diff-code { white-space: pre-wrap; word-break: break-all; }
.cv-diff-l { border-right: 1px solid #e3e3e3; }
.cv-diff-del .cv-diff-l,
.cv-diff-chg .cv-diff-l { background: #ffebe9; }
.cv-diff-add .cv-diff-r,
.cv-diff-chg .cv-diff-r { background: #dafbe1; }
.cv-diff-empty { background: #f6f8fa !important; }
.cv-diff-chg .cv-diff-l .cv-diff-mark { background: #ffc1bc; border-radius: 2px; }
.cv-diff-chg .cv-diff-r .cv-diff-mark { background: #aceebb; border-radius: 2px; }
.cv-diff-skip td {
  padding: 3px 10px;
  background: #f1f8ff;
  color: #57606a;
  font-style: italic;
  text-align: center;
}

@media (max-width: 720px) {
  .cv-cmp-layout { flex-direction: column; }
  .cv-cmp-files { position: static; max-width: none; width: 100%; max-height: 40vh; flex-basis: auto; }
}

/* ── git_service kind: branch / tag picker (Topic 139 G4) ───────────────── */
.cv-refs { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; margin: 6px 0 10px; font-size: 0.9em; }
.cv-refs-label { color: #666; margin-left: 6px; }
.cv-refs-label:first-child { margin-left: 0; }
.cv-ref { padding: 1px 8px; border: 1px solid #d8dbe0; border-radius: 999px; text-decoration: none; color: #333; }
.cv-ref:hover { border-color: #1b52a8; }
.cv-ref-current { background: #1b52a8; border-color: #1b52a8; color: #fff; }

/* ── git versions (Topic 142): the commit shown, the history, "Compare with…" ── */
.cv-versions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0 10px; }
.cv-version-pick { max-width: min(34rem, 100%); padding: 5px 8px; border: 1px solid #c9cdd3; border-radius: 4px; background: #fff; font: inherit; font-size: 0.9em; }
.cv-ref-commit { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ── a stored archive looked into (Topic 142 V5) ── */
.cv-archive { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0 10px; }
.cv-archive-warning { color: #8a5a00; font-size: 0.92em; }
