:root {
  --bg: #070b16;
  --bg-2: #0d1326;
  --surface: rgba(13, 19, 38, 0.72);
  --surface-strong: rgba(18, 27, 54, 0.92);
  --surface-soft: rgba(34, 48, 89, 0.42);
  --border: rgba(151, 183, 255, 0.22);
  --text: #ecf2ff;
  --text-muted: #9aacd8;
  --accent: #6ea8ff;
  --accent-strong: #4d8eff;
  --accent-warm: #7ff0d6;
  --success: #2fdf9a;
  --error: #ff6e8e;
  --warning: #ffd26e;
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow-lg: 0 24px 80px rgba(2, 6, 18, 0.58);
  --shadow-md: 0 12px 36px rgba(2, 6, 18, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1000px 420px at 12% -8%, rgba(101, 154, 255, 0.26), transparent 72%),
    radial-gradient(920px 500px at 100% 0%, rgba(97, 255, 226, 0.16), transparent 68%),
    linear-gradient(160deg, var(--bg) 0%, #050912 45%, #0a1124 100%);
  color: var(--text);
  line-height: 1.5;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(151, 183, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(151, 183, 255, 0.045) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
  z-index: -2;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(700px 260px at 50% 100%, rgba(104, 173, 255, 0.12), transparent 70%);
  pointer-events: none;
  z-index: -1;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 2.2rem 1.4rem 4rem;
}

.header {
  position: relative;
  margin-bottom: 1.4rem;
  padding: 1.3rem 1.35rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  background:
    linear-gradient(140deg, rgba(21, 30, 58, 0.9), rgba(10, 16, 34, 0.82)),
    var(--surface-strong);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
}

.header::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(181, 205, 255, 0.08);
  pointer-events: none;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-title-left {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.github-logo {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: linear-gradient(140deg, rgba(118, 180, 255, 0.26), rgba(127, 240, 214, 0.2));
  border: 1px solid rgba(152, 209, 255, 0.45);
  box-shadow: 0 0 22px rgba(97, 156, 255, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f5f9ff;
}

.header h1 {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.subtitle {
  color: var(--text-muted);
  margin: 0.45rem 0 1.05rem 0;
  font-size: 0.92rem;
}

.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.actions-left {
  display: flex;
  gap: 0.58rem;
  flex-wrap: wrap;
}

.auth-area {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 0.44rem;
  font-size: 0.845rem;
  color: var(--text-muted);
}

.auth-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid rgba(169, 200, 255, 0.45);
  box-shadow: 0 5px 16px rgba(6, 10, 25, 0.42);
}

.auth-name {
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.auth-login-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.auth-login-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn {
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #f7fbff;
  border-color: rgba(181, 213, 255, 0.42);
  box-shadow: 0 10px 22px rgba(58, 124, 255, 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgba(58, 124, 255, 0.36);
}

.btn-secondary {
  background: rgba(155, 187, 255, 0.08);
  color: var(--text);
  border-color: rgba(155, 187, 255, 0.28);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(155, 187, 255, 0.18);
  transform: translateY(-1px);
}

.btn-toggle-active,
.filter-btn.filter-btn-active {
  background: linear-gradient(130deg, rgba(110, 168, 255, 0.3), rgba(127, 240, 214, 0.24));
  color: #f7fbff;
  border-color: rgba(166, 229, 255, 0.58);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: rgba(155, 187, 255, 0.22);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(155, 187, 255, 0.12);
}

.btn-danger {
  background: rgba(255, 110, 142, 0.12);
  color: #ffc2d0;
  border-color: rgba(255, 139, 167, 0.44);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(255, 110, 142, 0.22);
}

.btn-sm {
  padding: 0.36rem 0.67rem;
  font-size: 0.82rem;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.72rem 1.16rem;
  border-radius: 999px;
  font-size: 0.86rem;
  z-index: 200;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  max-width: 90vw;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(161, 197, 255, 0.35);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success {
  background: rgba(47, 223, 154, 0.18);
  color: #d4ffe6;
}

.toast.error {
  background: rgba(255, 110, 142, 0.18);
  color: #ffd5de;
}

.toast.info {
  background: rgba(120, 167, 255, 0.16);
  color: #ebf3ff;
}

.add-section,
.list-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.05rem;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px);
}

.add-section {
  margin-bottom: 1rem;
}

.add-section.collapsed {
  display: none;
}

.add-section h2,
.list-section h2 {
  font-size: 1.03rem;
  font-weight: 600;
  margin: 0 0 0.8rem 0;
}

.form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.72rem;
}

.form .form-row {
  margin-bottom: 0;
  min-width: 0;
}

.form label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.32rem;
}

.form input {
  width: 100%;
  padding: 0.56rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  background: rgba(17, 27, 55, 0.65);
  border: 1px solid rgba(148, 185, 255, 0.25);
  border-radius: var(--radius-sm);
  color: var(--text);
  min-width: 0;
}

.form input::placeholder {
  color: rgba(156, 179, 230, 0.72);
}

.form input:focus {
  outline: none;
  border-color: rgba(128, 193, 255, 0.9);
  box-shadow: 0 0 0 2px rgba(89, 140, 255, 0.22);
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.2rem;
  grid-column: 1 / -1;
}

.list-header {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.72rem;
}

.list-header-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.list-header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filter-group {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.24rem;
  border-radius: 999px;
  border: 1px solid rgba(159, 191, 255, 0.26);
  background: rgba(17, 27, 55, 0.66);
}

.search-input {
  padding: 0.48rem 0.86rem;
  border-radius: 999px;
  border: 1px solid rgba(159, 191, 255, 0.38);
  background: rgba(17, 27, 55, 0.72);
  color: var(--text);
  font-size: 0.86rem;
  min-width: 248px;
}

.search-input::placeholder {
  color: rgba(160, 183, 232, 0.72);
}

.search-input:focus {
  outline: none;
  border-color: rgba(128, 193, 255, 0.9);
  box-shadow: 0 0 0 2px rgba(89, 140, 255, 0.2);
}

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  border: 1px solid rgba(156, 188, 255, 0.26);
  border-radius: var(--radius);
  background: rgba(8, 14, 30, 0.62);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 860px;
}

.table thead th {
  position: sticky;
  top: 0;
  background: rgba(18, 27, 54, 0.94);
  z-index: 2;
  backdrop-filter: blur(6px);
}

.table th,
.table td {
  padding: 0.68rem 1rem;
  text-align: left;
  border-bottom: 1px solid rgba(156, 188, 255, 0.16);
  vertical-align: top;
}

.table th {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr.empty td {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
}

.table tbody tr:hover:not(.empty) td {
  background: rgba(126, 176, 255, 0.09);
}

.table .repo-link {
  color: #9ec8ff;
  text-decoration: none;
  font-family: var(--font-mono);
}

.table .repo-link:hover {
  color: #b8d8ff;
  text-decoration: underline;
}

.name-main {
  font-weight: 500;
}

.name-meta {
  margin-top: 0.18rem;
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.commit-time {
  color: #dce7ff;
}

.commit-line {
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}

.commit-line-link {
  color: inherit;
  text-decoration: none;
}

.commit-line-link:hover .commit-line {
  color: #b8d8ff;
  text-decoration: underline;
}

.repo-status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0 0.42rem;
  margin-left: 0.35rem;
  border-radius: 999px;
  font-size: 0.72rem;
  line-height: 1.35;
}

.repo-status-behind {
  background: rgba(255, 110, 142, 0.18);
  color: #ffc2d0;
  border: 1px solid rgba(255, 152, 178, 0.46);
}

code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: rgba(134, 174, 255, 0.12);
  border: 1px solid rgba(155, 187, 255, 0.34);
  border-radius: 8px;
  padding: 0.12rem 0.38rem;
  color: #d7e6ff;
}

.cell-actions {
  display: flex;
  gap: 0.28rem;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  min-height: 32px;
}

.cell-actions .btn {
  white-space: nowrap;
}

/* 分支名单元格：与多行「仓库名 + commit」行高对齐时垂直居中 */
.table th:nth-child(3),
.table td:nth-child(3) {
  vertical-align: middle;
}

.table th:nth-child(4),
.table td:nth-child(4) {
  width: 1%;
  white-space: nowrap;
  position: sticky;
  right: 0;
  box-shadow: -8px 0 16px rgba(2, 6, 18, 0.46);
  vertical-align: middle;
}

.table td:nth-child(4) {
  position: sticky;
  right: 0;
}

.cell-status {
  font-size: 0.76rem;
  position: absolute;
  left: 1rem;
  bottom: 0.08rem;
  white-space: nowrap;
  max-width: calc(100% - 1.5rem);
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-status.ok {
  color: var(--success);
}

.cell-status.fail {
  color: var(--error);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pagination button {
  font-family: var(--font);
  font-size: 0.79rem;
  padding: 0.24rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(155, 187, 255, 0.3);
  background: rgba(17, 27, 55, 0.72);
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease;
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination button:hover:not(:disabled) {
  background: rgba(155, 187, 255, 0.18);
  transform: translateY(-1px);
}

.batch-result {
  margin-top: 0.9rem;
  padding: 0.9rem;
  background: rgba(11, 18, 38, 0.75);
  border: 1px solid rgba(151, 183, 255, 0.22);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  display: none;
}

.batch-result.visible {
  display: block;
}

.batch-result h3 {
  font-size: 0.93rem;
  margin: 0 0 0.45rem 0;
}

.batch-result ul {
  margin: 0;
  padding-left: 1.12rem;
}

.batch-result li {
  margin: 0.2rem 0;
}

.batch-result .ok {
  color: var(--success);
}

.batch-result .fail {
  color: var(--error);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 18, 0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 120;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
  backdrop-filter: blur(4px);
}

.modal-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  width: 100%;
  max-width: 430px;
  background: linear-gradient(145deg, rgba(20, 29, 56, 0.98), rgba(10, 16, 34, 0.98));
  border-radius: 14px;
  border: 1px solid rgba(159, 191, 255, 0.3);
  box-shadow: var(--shadow-lg);
  padding: 1.2rem 1.4rem 1rem;
}

.modal-header h2 {
  margin: 0 0 0.2rem 0;
  font-size: 1.02rem;
  font-weight: 600;
}

.modal-body {
  font-size: 0.89rem;
  color: var(--text-muted);
  margin: 0.44rem 0 1.02rem 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.48rem;
}

.loading-row {
  display: flex;
  align-items: center;
  gap: 0.72rem;
}

.spinner {
  width: 20px;
  height: 20px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  box-sizing: border-box;
  border: 2px solid rgba(152, 191, 255, 0.24);
  border-top-color: var(--accent-warm);
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

.loading-text {
  font-size: 0.89rem;
  color: var(--text-muted);
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1080px) {
  .form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app {
    padding: 1.1rem 0.9rem 3rem;
  }

  .header,
  .add-section,
  .list-section {
    padding: 0.9rem;
  }

  .header h1 {
    font-size: 1.5rem;
  }

  .actions {
    align-items: stretch;
  }

  .actions-left,
  .auth-area {
    width: 100%;
  }

  .auth-area {
    justify-content: flex-end;
  }

  .list-header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .search-input {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  /* 移动端：把 github 头像/用户名/退出按钮放到“一键批量同步”上方 */
  .actions {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 1.15rem;
  }

  .actions-left {
    order: 2;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    align-items: center;
  }

  .form {
    grid-template-columns: 1fr;
  }

  /* 移动端：上游/当前两列改为垂直居中 */
  .table th:nth-child(1),
  .table td:nth-child(1),
  .table th:nth-child(2),
  .table td:nth-child(2) {
    vertical-align: middle;
  }

  .cell-actions {
    /* 移动端允许按钮换行，避免按钮挤出单元格 */
    flex-wrap: wrap;
  }

  /* 移动端：操作列 sticky 需要更高层级与遮挡，避免横向滚动时透出内容 */
  .table th:nth-child(4),
  .table td:nth-child(4) {
    z-index: 6;
    /* 用更不透明的底色，避免 rgba 让底下内容“透出来” */
    background: rgba(18, 27, 54, 1);
    right: -4px;
    /* 避免移动端 sticky 重排时出现闪烁 */
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    box-shadow: -6px 0 14px rgba(2, 6, 18, 0.46);
  }

  /* 避免 hover 规则覆盖上面的背景透明度/颜色，导致滚动时抖动或透出 */
  .table tbody tr:hover:not(.empty) td:nth-child(4) {
    background: rgba(18, 27, 54, 1);
  }

  .actions-left .btn,
  .auth-area .btn {
    width: 100%;
    justify-content: center;
  }

  .auth-area {
    justify-content: center;
    flex-wrap: nowrap;
    order: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.55rem;
  }

  .auth-user {
    justify-content: center;
  }

  .auth-name {
    text-align: center;
  }

  /* 移动端：让退出/登录这类 btn-sm 跟“一键批量同步”保持高度接近 */
  .auth-area .btn.btn-sm {
    padding: 0.5rem 0.95rem;
    font-size: 0.88rem;
  }

  .pagination {
    flex-direction: column;
    align-items: flex-start;
  }
}
