.git-view {
  height: 100%;
  padding: 10px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  position: relative;
}

/* Mobile-only: triggers and backdrop that hide chrome behind popovers.
   Default state hides them; the mobile media query reveals them. */
.git-view__menu-trigger,
.git-view__tabs-trigger,
.git-view__menu-backdrop {
  display: none;
}

.git-view__panel {
  min-height: 0;
  overflow: hidden;
}

.git-view__toolbar,
.git-view__summary,
.git-view__actions,
.git-log__meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Push the action button cluster to the right edge of the toolbar so the
   summary chips stay left and the buttons don't float in the middle. */
.git-view__actions {
  margin-left: auto;
}

.git-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  padding: 0 2px;
}

.git-tabs__item {
  padding: 6px 14px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.git-tabs__item:hover {
  color: var(--text);
}

.git-tabs__item--active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.git-tabs__badge {
  display: inline-block;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--panel);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  line-height: 16px;
  vertical-align: middle;
}

.git-section {
  min-height: 0;
  display: grid;
  gap: 12px;
  align-content: start;
  overflow-y: auto;
  padding-bottom: 12px;
}

.git-section--changes {
  grid-template-columns: minmax(240px, 1fr) minmax(300px, 1.5fr);
  align-content: stretch;
  overflow: hidden;
}

.git-section--history {
  grid-template-columns: 1fr;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: stretch;
  overflow: hidden;
}

.git-history__header {
  min-height: 0;
}

.git-history__panels {
  display: grid;
  grid-template-columns: minmax(250px, 1fr) minmax(300px, 1.5fr);
  gap: 8px;
  min-height: 0;
}

.git-history__log,
.git-history__detail {
  overflow-y: auto;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(var(--tint), 0.03);
}

.git-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}

.git-log-table th {
  position: sticky;
  top: 0;
  padding: 5px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--muted);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.git-log-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.git-log-table tbody tr {
  cursor: pointer;
}

.git-log-table tbody tr:hover {
  background: color-mix(in srgb, var(--panel-elevated), var(--accent) 8%);
}

.git-log-table--active,
.git-log-table--active:hover {
  background: color-mix(in srgb, var(--panel-elevated), var(--accent) 14%);
  box-shadow: inset 2px 0 0 var(--accent);
}

.git-log-table__hash {
  width: 64px;
  font-weight: 700;
  font-family: monospace;
  color: var(--accent);
}

.git-log-table__msg {
  width: auto;
}

.git-log-table__date {
  width: 100px;
  color: var(--muted);
  font-size: 11px;
}

.git-log-table__author {
  width: 110px;
  color: var(--muted);
  font-size: 11px;
}

.git-history__detail {
  padding: 10px;
}

.git-history__detail .git-output {
  max-height: none;
  border: none;
  background: none;
  padding: 0;
}

.git-section__files,
.git-section__preview {
  display: grid;
  gap: 8px;
  align-content: start;
  min-height: 0;
  overflow-y: auto;
}

.git-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(240px, 1fr);
  gap: 8px;
  align-content: start;
  overflow-y: auto;
}

.git-card {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  background: rgba(var(--tint), 0.03);
  display: grid;
  gap: 10px;
}

.git-card--wide {
  grid-column: 1 / -1;
}

.git-detail-list,
.git-changes-grid,
.git-change-section,
.git-operation-actions,
.git-sibling__badges {
  display: grid;
  gap: 8px;
}

.git-detail-list {
  font-size: 12px;
  color: var(--muted);
}

.git-stat-row,
.git-operation-actions,
.git-sibling__badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.git-changes-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.git-file-list,
.git-sibling-list,
.git-inline-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 1px;
}

.git-file,
.git-sibling-list li {
  width: 100%;
}

.git-file {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border: none;
  border-radius: 3px;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
}

.git-file:hover,
.git-file--active {
  background: color-mix(in srgb, var(--panel-elevated), var(--accent) 10%);
}

.git-file-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.git-file-row .git-file {
  flex: 1;
  min-width: 0;
}

.git-file__edit-btn {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  transition:
    opacity 0.1s,
    background 0.1s,
    color 0.1s;
}

.git-file-row:hover .git-file__edit-btn {
  opacity: 1;
}

.git-file__edit-btn:hover {
  background: var(--accent);
  color: #000;
}

.git-file__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.git-file__dir {
  color: var(--muted);
}

.git-sibling-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 8px;
}

.git-sibling--current {
  border-color: color-mix(in srgb, var(--accent), transparent 42%);
}

.git-sibling__meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.git-sibling__meta small {
  color: var(--muted);
}

.git-sibling__meta {
  flex: 1 1 auto;
}

/* Worktree row actions: right-aligned cluster (1.2 — buttons right). */
.git-sibling__actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  margin-left: auto;
}

.workspace-chip--muted {
  color: var(--muted);
  border-color: color-mix(in srgb, var(--border), transparent 30%);
}

.git-operation-banner {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(var(--tint), 0.03);
}

.git-operation-banner--warning {
  border-color: color-mix(in srgb, var(--accent), transparent 40%);
}

.git-operation-banner--ok {
  border-color: rgba(110, 223, 182, 0.4);
}

.git-operation-banner--error {
  border-color: rgba(255, 111, 141, 0.35);
}

.git-details {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
}

.git-details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
}

.git-details[open] summary {
  margin-bottom: 6px;
}

.git-card__hint--warning {
  color: #ffb86c;
}

.git-commit-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.git-commit-form input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}

.git-commit-form input:focus {
  border-color: var(--accent);
  outline: none;
}

.git-operation-banner--confirm {
  border-color: color-mix(in srgb, var(--accent), transparent 20%);
  background: color-mix(in srgb, var(--panel-elevated), var(--accent) 6%);
}

.git-operation-banner--warn {
  border-color: rgba(255, 184, 108, 0.5);
  background: rgba(255, 184, 108, 0.06);
}

.git-operation-banner--danger {
  border-color: rgba(255, 111, 141, 0.55);
  background: rgba(255, 111, 141, 0.07);
}

.button--danger {
  background: rgba(255, 111, 141, 0.18);
  border-color: rgba(255, 111, 141, 0.4);
  color: #ff6f8d;
}

.button--danger:hover {
  background: rgba(255, 111, 141, 0.28);
}

.git-diverged-banner {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 184, 108, 0.5);
  border-radius: 4px;
  background: rgba(255, 184, 108, 0.06);
  margin-bottom: 4px;
}

.git-diverged-banner__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.git-info-banner {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(var(--tint), 0.03);
  margin-bottom: 4px;
}

.git-info-banner--warn {
  border-color: rgba(255, 184, 108, 0.4);
  background: rgba(255, 184, 108, 0.05);
}

.git-info-banner--error {
  border-color: rgba(255, 111, 141, 0.35);
  background: rgba(255, 111, 141, 0.05);
}

.workspace-chip--muted {
  opacity: 0.65;
}

.workspace-chip--warn {
  background: rgba(255, 184, 108, 0.18);
  color: #ffb86c;
  border-color: rgba(255, 184, 108, 0.35);
}

.git-output {
  margin: 0;
  padding: 10px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.git-output--preview {
  max-height: none;
  flex: 1;
  min-height: 0;
}

.diff-add {
  color: var(--success-fg);
  background: rgba(110, 223, 182, 0.08);
}

.diff-del {
  color: #ff6f8d;
  background: rgba(255, 111, 141, 0.08);
}

.diff-hunk {
  color: #8eaaff;
}

.diff-meta {
  color: var(--muted);
  font-style: italic;
}

/* ── Git Branch Select & PR Form ── */
/* !important is required to beat CustomSelect's scoped `width: 100%` on its root. */
.git-branch-select {
  width: 220px !important;
}
.git-view__actions .git-branch-select {
  width: 180px !important;
}

.git-detail-list__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.git-pr-form {
  display: grid;
  gap: 10px;
}

.git-pr-form__field {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.git-pr-form__label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.git-pr-form__input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}

.git-pr-form__input:focus {
  border-color: var(--accent);
  outline: none;
}

.git-pr-form__input:disabled {
  opacity: 0.6;
}

.git-pr-form__textarea {
  resize: vertical;
  min-height: 60px;
  grid-column: 2 / -1;
}

.button--small {
  padding: 3px 8px;
  font-size: 11px;
}

/* ── Mobile: make the Git pane fit narrow viewports without horizontal
   overflow. Same compound breakpoint as mobile.css — covers portrait
   phones (≤768px wide) and landscape phones (≤500px tall). ── */
@media (max-width: 768px), (max-height: 500px) {
  .git-view {
    padding: 5px;
    gap: 0;
    /* Two rows on mobile: a fixed-height chrome strip (filled by absolute
       triggers) and the data area. Toolbar and tabs both render as popovers
       anchored under the chrome strip when their menus are open. */
    grid-template-rows: 32px minmax(0, 1fr);
  }

  .git-view__panel {
    grid-row: 2;
  }

  .git-view__toolbar,
  .git-view__summary,
  .git-view__actions {
    gap: 5px;
  }

  /* Toolbar collapses behind the "⋮" trigger; only renders when open. */
  .git-view__toolbar {
    display: none;
  }

  .git-view--menu-open .git-view__toolbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    position: absolute;
    top: 36px;
    left: 5px;
    right: 5px;
    z-index: 50;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel-elevated);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    max-height: calc(100% - 50px);
    overflow-y: auto;
  }

  .git-view--menu-open .git-view__summary,
  .git-view--menu-open .git-view__actions {
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
  }

  .git-view--menu-open .git-view__actions .button {
    padding: 6px 10px;
    font-size: 12px;
    flex: 1 1 auto;
  }

  .git-view--menu-open .git-view__actions .git-branch-select,
  .git-view--menu-open .git-view__actions .git-repo-picker__select {
    width: auto !important;
    flex: 1 1 140px;
    min-width: 0;
  }

  .git-view--menu-open .git-repo-picker {
    flex: 1 1 100%;
  }

  /* "⋮ Actions" trigger — pinned to the top-right of the git pane, level
     with the tabs row so the tabs and the trigger share a single chrome row.
     Above the backdrop so the user can tap to close directly. */
  .git-view__menu-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--panel);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    position: absolute;
    top: 5px;
    right: 5px;
    z-index: 50;
  }
  .git-view__menu-trigger:hover {
    background: rgba(var(--tint), 0.08);
  }
  .git-view__menu-trigger__dot {
    font-size: 16px;
    line-height: 1;
  }

  /* Backdrop for click-outside dismissal of the actions popover. */
  .git-view__menu-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 40;
  }

  /* Tabs collapse behind the left "current tab ▼" trigger. Default hidden;
     popover when --tabs-menu-open. */
  .git-tabs {
    display: none;
  }
  .git-view--tabs-menu-open .git-tabs {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    border-bottom: none;
    position: absolute;
    top: 36px;
    left: 5px;
    right: 5px;
    z-index: 50;
    padding: 4px 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel-elevated);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    max-height: calc(100% - 50px);
    overflow-y: auto;
  }
  .git-view--tabs-menu-open .git-tabs__item {
    padding: 10px 12px;
    text-align: left;
    border-bottom: none;
    border-left: 3px solid transparent;
    font-size: 13px;
    width: 100%;
    flex: 0 0 auto;
  }
  .git-view--tabs-menu-open .git-tabs__item--active {
    border-left-color: var(--accent);
    background: rgba(var(--tint), 0.08);
  }

  /* "Current tab ▼" trigger — pinned top-left, level with the actions trigger. */
  .git-view__tabs-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--panel);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    position: absolute;
    top: 5px;
    left: 5px;
    max-width: calc(100% - 110px);
    z-index: 50;
  }
  .git-view__tabs-trigger:hover {
    background: rgba(var(--tint), 0.08);
  }
  .git-view__tabs-trigger__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }
  .git-view__tabs-trigger__caret {
    font-size: 9px;
    opacity: 0.7;
    flex-shrink: 0;
  }

  .git-card {
    padding: 10px;
    gap: 8px;
  }

  /* Inline selects inside cards (Switch Branch, Base branch picker) need
     to flex with the row, not hold a desktop 220px. */
  .git-card .git-branch-select {
    width: auto !important;
    flex: 1 1 140px;
    min-width: 0;
  }

  /* Detail rows wrap so label + select + button can break across lines
     instead of overflowing. */
  .git-detail-list__row {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* PR form: 3-col grid (label / input / action) → stacked. */
  .git-pr-form__field {
    grid-template-columns: minmax(0, 1fr);
  }
  .git-pr-form__textarea {
    grid-column: 1 / -1;
  }

  /* Multi-column card grids collapse to single column. */
  .git-changes-grid,
  .git-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  /* History: drop the 250px+300px two-column track so log/detail stack. */
  .git-history__panels {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Long branch names / paths shouldn't push the card wider than viewport. */
  .git-card h3,
  .git-card__path {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .section-head {
    flex-wrap: wrap;
  }
}
