/* ── Custom properties (dark theme) ─────────────────────────────── */
:root {
  --bg-base:    #0d1117;
  --bg-surface: #161b22;
  --bg-raised:  #21262d;
  --bg-hover:   #30363d;
  --border:     #30363d;
  --border-muted: #21262d;

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #6e7681;

  --accent-blue:   #58a6ff;
  --accent-purple: #bc8cff;
  --accent-green:  #3fb950;
  --accent-yellow: #d29922;
  --accent-red:    #f85149;
  --accent-orange: #e3b341;

  /* Status colours */
  --status-clean:    #3fb950;
  --status-dirty:    #d29922;
  --status-behind:   #58a6ff;
  --status-ahead:    #58a6ff;
  --status-diverged: #f85149;
  --status-conflict: #f85149;
  --status-local:    #6e7681;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow:    0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);

  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-ui:   -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Reset / base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  font-family: var(--font-ui);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  font: inherit;
  border: none;
  background: none;
  color: inherit;
}

/* ── Auth overlay ────────────────────────────────────────────────── */
#auth-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

#auth-overlay.hidden { display: none; }

.auth-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 360px;
  box-shadow: var(--shadow-lg);
}

.auth-box h2 { margin-bottom: 0.25rem; font-size: 1.25rem; }
.auth-box p  { color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 0.875rem; }

.auth-box input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

.auth-box input:focus { outline: none; border-color: var(--accent-blue); }

/* ── Layout ──────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }
#app.hidden { display: none; }

/* ── Top bar ─────────────────────────────────────────────────────── */
.topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-logo {
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  color: var(--text-primary);
}

.topbar-logo .logo-icon { color: var(--accent-orange); }

.topbar-spacer { flex: 1; }

.ws-indicator {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--status-local);
  transition: background 0.3s;
}
.ws-indicator.connected  { background: var(--status-clean); }
.ws-indicator.connecting { background: var(--accent-yellow); }

/* ── Summary bar ─────────────────────────────────────────────────── */
.summary-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.summary-stat {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.summary-stat .count {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.summary-stat.dirty  .count { color: var(--status-dirty); }
.summary-stat.behind .count { color: var(--status-behind); }
.summary-stat.clean  .count { color: var(--status-clean); }

.summary-sep { color: var(--border); }

.bulk-actions { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; }

/* ── Toolbar (search + group) ────────────────────────────────────── */
.toolbar {
  padding: 0.75rem 1.5rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 400px;
}

.search-wrap .search-icon {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  padding: 0.45rem 0.75rem 0.45rem 2rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.8125rem;
}

.search-wrap input:focus { outline: none; border-color: var(--accent-blue); }
.search-wrap input::placeholder { color: var(--text-muted); }

.group-tabs {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}

.group-tab {
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.group-tab.active {
  background: var(--bg-raised);
  color: var(--text-primary);
  font-weight: 500;
}

.group-tab:hover:not(.active) { color: var(--text-primary); }

/* ── Main content area ───────────────────────────────────────────── */
.main {
  display: flex;
  flex: 1;
  gap: 0;
}

.repos-area {
  flex: 1;
  padding: 1rem 1.5rem;
  min-width: 0;
}

/* ── Group sections ──────────────────────────────────────────────── */
.group-section { margin-bottom: 1.5rem; }

.group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
  user-select: none;
}

.group-chevron {
  color: var(--text-muted);
  transition: transform 0.2s;
  font-size: 0.75rem;
}
.group-chevron.open { transform: rotate(90deg); }

.group-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.group-name {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.group-badge {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.6875rem;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  font-weight: 600;
}

.group-line {
  flex: 1;
  height: 1px;
  background: var(--border-muted);
}

.group-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.75rem;
}

.group-cards.collapsed { display: none; }

/* ── Repo card ───────────────────────────────────────────────────── */
.repo-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}

.repo-card:hover { border-color: var(--bg-hover); box-shadow: var(--shadow); }

.repo-card.status-clean    { border-left: 3px solid var(--status-clean); }
.repo-card.status-dirty    { border-left: 3px solid var(--status-dirty); }
.repo-card.status-behind   { border-left: 3px solid var(--status-behind); }
.repo-card.status-ahead    { border-left: 3px solid var(--status-ahead); }
.repo-card.status-diverged { border-left: 3px solid var(--status-diverged); }
.repo-card.status-conflict { border-left: 3px solid var(--status-conflict); }
.repo-card.status-local    { border-left: 3px solid var(--status-local); }

.card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem 0.4rem;
  cursor: pointer;
  min-width: 0;
}

.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.clean    { background: var(--status-clean); }
.status-dot.dirty    { background: var(--status-dirty); box-shadow: 0 0 4px var(--status-dirty); }
.status-dot.behind   { background: var(--status-behind); }
.status-dot.ahead    { background: var(--status-ahead); }
.status-dot.diverged { background: var(--status-diverged); box-shadow: 0 0 4px var(--status-diverged); }
.status-dot.conflict { background: var(--status-conflict); box-shadow: 0 0 6px var(--status-conflict); animation: pulse 1s infinite; }
.status-dot.local    { background: var(--status-local); border: 1px solid var(--border); background: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.repo-name {
  font-weight: 600;
  font-size: 0.9rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.branch-badge {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
}

.branch-badge.main   { background: rgba(88,166,255,0.15); color: var(--accent-blue); }
.branch-badge.master { background: rgba(88,166,255,0.15); color: var(--accent-blue); }
.branch-badge.feature { background: rgba(188,140,255,0.15); color: var(--accent-purple); }
.branch-badge.other   { background: var(--bg-raised); color: var(--text-secondary); }

.card-toggle {
  color: var(--text-muted);
  font-size: 0.7rem;
  transition: transform 0.2s;
  flex-shrink: 0;
  padding: 0.2rem;
}
.card-toggle.open { transform: rotate(180deg); }

.card-meta {
  padding: 0 0.75rem 0.5rem;
  font-size: 0.78rem;
}

.card-description {
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-commit {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.card-commit .commit-msg {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

.card-commit .commit-time { flex-shrink: 0; }

.card-counters {
  display: flex;
  gap: 0.6rem;
  padding: 0.3rem 0.75rem 0.55rem;
  flex-wrap: wrap;
}

.counter-chip {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.counter-chip .val { font-weight: 600; color: var(--text-secondary); }
.counter-chip.has-value .val { color: var(--accent-yellow); }
.counter-chip.ahead-chip .val { color: var(--accent-blue); }
.counter-chip.behind-chip .val { color: var(--accent-orange); }

/* ── Expanded card body ──────────────────────────────────────────── */
.card-body { display: none; border-top: 1px solid var(--border-muted); }
.card-body.open { display: block; }

.card-section {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-muted);
}

.card-section:last-child { border-bottom: none; }

.section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.4rem;
}

/* ── Branch list ─────────────────────────────────────────────────── */
.branch-list { display: flex; flex-direction: column; gap: 0.3rem; }

.branch-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  padding: 0.2rem 0.3rem;
  border-radius: var(--radius-sm);
}

.branch-item.current { background: var(--bg-raised); }

.branch-item .b-name {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.branch-item.current .b-name { color: var(--accent-blue); font-weight: 600; }

.branch-item .b-upstream { color: var(--text-muted); font-size: 0.68rem; font-family: var(--font-mono); }

.branch-item .b-track {
  display: flex;
  gap: 0.25rem;
  font-size: 0.7rem;
}

.b-ahead  { color: var(--accent-blue); }
.b-behind { color: var(--accent-orange); }
.b-gone   { color: var(--accent-red); font-size: 0.65rem; }

/* ── Action buttons ──────────────────────────────────────────────── */
.action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all 0.15s;
  white-space: nowrap;
}

.action-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent-blue);
}

.action-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.action-btn.running { color: var(--accent-yellow); border-color: var(--accent-yellow); }
.action-btn.success { color: var(--accent-green); border-color: var(--accent-green); }
.action-btn.error   { color: var(--accent-red);   border-color: var(--accent-red); }

.action-btn.link-btn {
  color: var(--accent-blue);
  border-color: rgba(88,166,255,0.3);
}

/* ── Output panel ────────────────────────────────────────────────── */
.output-panel {
  background: var(--bg-base);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.6;
}
.output-panel:empty { display: none; }

/* ── Timeline sidebar ────────────────────────────────────────────── */
.timeline-sidebar {
  width: 280px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.timeline-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-muted);
}

.timeline-entry {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.75rem;
}

.tl-repo {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--accent-blue);
  font-weight: 600;
}

.tl-msg {
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl-meta {
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.tl-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border);
  margin-top: 0.35rem;
  flex-shrink: 0;
}

.tl-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
}
.btn-primary:hover { background: #79b8ff; }

.btn-ghost {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--bg-hover); }

.btn-danger { background: var(--accent-red); color: #fff; }

/* ── Refresh indicator ───────────────────────────────────────────── */
.refresh-badge {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.refresh-badge.spinning { color: var(--accent-yellow); }

/* ── Empty state ─────────────────────────────────────────────────── */
.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .timeline-sidebar { display: none; }
  .group-cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

@media (max-width: 600px) {
  .topbar { padding: 0 1rem; }
  .repos-area { padding: 0.75rem 1rem; }
  .summary-bar { padding: 0.5rem 1rem; gap: 0.75rem; }
  .toolbar { padding: 0.5rem 1rem; }
  .group-cards { grid-template-columns: 1fr; }
  .bulk-actions { display: none; }
}

/* ── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
