:root {
  --bg: #0b0d12;
  --bg-elevated: #12151d;
  --bg-card: #161a24;
  --border: #242938;
  --border-soft: #1c202c;
  --text: #e7e9f1;
  --text-dim: #9298ab;
  --text-faint: #5c6274;
  --accent: #7c6cf6;
  --accent-2: #22d3ee;
  --accent-soft: rgba(124, 108, 246, 0.14);
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "Apple SD Gothic Neo",
    Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(1200px 800px at 15% -10%, #17132b 0%, transparent 55%),
    radial-gradient(1000px 700px at 100% 0%, #0b1f2a 0%, transparent 50%), var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

button {
  font-family: inherit;
}

/* ---------- Auth gate ---------- */

.auth-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.auth-card {
  width: 340px;
  padding: 32px 28px;
  background: linear-gradient(180deg, var(--bg-card), var(--bg-elevated));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 22px;
  color: #0b0d12;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 19px;
}

.auth-card p {
  margin: 0 0 18px;
  color: var(--text-dim);
  font-size: 13px;
}

.auth-card input {
  width: 100%;
  margin-bottom: 12px;
}

.error-text {
  color: var(--red);
  font-size: 12.5px;
  min-height: 16px;
}

/* ---------- Layout ---------- */

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border-soft);
  background: rgba(18, 21, 29, 0.6);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0d12;
  font-size: 13px;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  transform: rotate(45deg);
}

.tree-search {
  padding: 0 14px 10px;
}

.tree-search input,
.branch-create input,
.auth-card input {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tree-search input:focus,
.branch-create input:focus,
.auth-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 2px 8px 12px;
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.home-label {
  color: var(--text-faint);
  font-size: 11.5px;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#logout-btn {
  flex: 0 0 auto;
  font-size: 14px;
}

#logout-btn:hover {
  color: var(--red);
  border-color: var(--red);
  transform: none;
}

/* ---------- Repo list ---------- */

.repo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-dim);
  transition: background 0.12s ease, color 0.12s ease;
  user-select: none;
}

.repo-item:hover {
  background: var(--bg-card);
  color: var(--text);
}

.repo-item.selected {
  background: var(--accent-soft);
  color: var(--text);
}

.tree-dot {
  flex: 0 0 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
}

.tree-dot.repo {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 6px rgba(124, 108, 246, 0.6);
}

.repo-item-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.repo-item-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.repo-item-path {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.repo-item.selected .repo-item-path {
  color: var(--accent-2);
}

.tree-loading,
.tree-empty {
  padding: 8px 10px;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.5;
}

/* ---------- Main ---------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-soft);
}

.breadcrumb {
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breadcrumb-placeholder {
  color: var(--text-faint);
  font-family: var(--font-sans);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
}

.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-1px);
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #5b4bdb);
  border-color: transparent;
  color: #fff;
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent-2), #0891b2);
  border-color: transparent;
  color: #06262c;
}

.btn.loading {
  opacity: 0.7;
  pointer-events: none;
}

/* ---------- Repo panel ---------- */

.repo-panel {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.empty-state {
  height: 100%;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
}

.empty-glyph {
  font-size: 32px;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.empty-state p {
  max-width: 360px;
  line-height: 1.6;
  font-size: 13.5px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.status-card {
  background: linear-gradient(180deg, var(--bg-card), var(--bg-elevated));
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.status-value {
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-value-sm {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
}

.status-value.ok { color: var(--green); }
.status-value.warn { color: var(--amber); }
.status-value.bad { color: var(--red); }

.panel-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 16px;
}

.tab-btn {
  position: relative;
  padding: 9px 14px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-2);
  margin-left: 6px;
  vertical-align: middle;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.tab-dot.show {
  opacity: 1;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ---------- Commit list ---------- */

.commit-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
}

.commit-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}

.commit-list li:last-child {
  border-bottom: none;
}

.commit-hash {
  font-family: var(--font-mono);
  color: var(--accent-2);
  flex: 0 0 auto;
}

.commit-subject {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.commit-meta {
  flex: 0 0 auto;
  color: var(--text-faint);
  font-size: 12px;
  white-space: nowrap;
}

/* ---------- Branches ---------- */

.branch-create {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.branch-create input {
  flex: 1;
}

.branch-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.branch-columns h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 0 0 8px;
}

.branch-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
}

.branch-list li {
  padding: 9px 12px;
  font-size: 13px;
  font-family: var(--font-mono);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.branch-list li:last-child {
  border-bottom: none;
}

.branch-list li.local-branch {
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.branch-list li.local-branch:hover {
  background: var(--bg-card);
  color: var(--text);
}

.branch-list li.current {
  color: var(--accent-2);
  font-weight: 600;
}

.branch-current-badge {
  font-size: 10px;
  font-family: var(--font-sans);
  background: var(--accent-soft);
  color: var(--accent-2);
  padding: 2px 6px;
  border-radius: 999px;
}

/* ---------- Diff / console ---------- */

.diff-view,
.console-view {
  margin: 0;
  padding: 16px;
  background: #090a0f;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 480px;
  overflow-y: auto;
}

.console-line-cmd {
  color: var(--accent-2);
}

.console-line-err {
  color: var(--red);
}

.console-line-ok {
  color: var(--green);
}

/* ---------- Toasts ---------- */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow);
  font-size: 13px;
  min-width: 240px;
  max-width: 360px;
  animation: toast-in 0.2s ease;
}

.toast.success {
  border-left-color: var(--green);
}

.toast.error {
  border-left-color: var(--red);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Scrollbars ---------- */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    max-height: 40vh;
  }
  .status-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .branch-columns {
    grid-template-columns: 1fr;
  }
}
