*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary:    #0d1117;
  --bg-secondary:  #161b22;
  --bg-tertiary:   #21262d;
  --bg-hover:      #30363d;
  --border-color:  #30363d;
  --border-muted:  #21262d;

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

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

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-pill: 100px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,.5);
}

html { color-scheme: dark; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
}

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

/* ── Site header ─────────────────────────────────────────── */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}
.header-brand:hover { text-decoration: none; }

.brand-icon {
  width: 28px;
  height: 28px;
  color: var(--accent-green);
  flex-shrink: 0;
}

.brand-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  border-left: 1px solid var(--border-color);
  padding-left: 10px;
  margin-left: 2px;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent-blue);
  color: #0d1117;
  border-color: var(--accent-blue);
}
.btn-primary:hover { background: #79c0ff; border-color: #79c0ff; }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-color);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--text-secondary); }

.btn-danger {
  background: transparent;
  color: var(--accent-red);
  border-color: var(--accent-red);
}
.btn-danger:hover { background: rgba(248,81,73,.1); }

.btn-sm {
  padding: 3px 10px;
  font-size: 12px;
}

.btn-icon {
  padding: 5px 8px;
}

/* ── Main layout ─────────────────────────────────────────── */

.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-header h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Live badge ──────────────────────────────────────────── */

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-green);
  background: rgba(63,185,80,.1);
  border: 1px solid rgba(63,185,80,.3);
  border-radius: var(--radius-pill);
  padding: 2px 8px;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: pulse 2s infinite;
}

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

/* ── Status badges ───────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

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

.badge-queued     { background: rgba(139,148,158,.15); color: var(--text-secondary); }
.badge-queued .badge-dot { background: var(--text-secondary); }

.badge-building   { background: rgba(88,166,255,.15);  color: var(--accent-blue); }
.badge-building .badge-dot { background: var(--accent-blue); animation: pulse 1.2s infinite; }

.badge-decompiling { background: rgba(219,109,40,.15); color: var(--accent-orange); }
.badge-decompiling .badge-dot { background: var(--accent-orange); animation: pulse 1.2s infinite; }

.badge-generating-diff { background: rgba(188,140,255,.15); color: var(--accent-purple); }
.badge-generating-diff .badge-dot { background: var(--accent-purple); animation: pulse 1.2s infinite; }

.badge-completed  { background: rgba(63,185,80,.15);   color: var(--accent-green); }
.badge-completed .badge-dot { background: var(--accent-green); }

.badge-failed     { background: rgba(248,81,73,.15);   color: var(--accent-red); }
.badge-failed .badge-dot { background: var(--accent-red); }

/* ── Data table ──────────────────────────────────────────── */

.table-wrap {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border-muted);
  transition: background 0.1s;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-secondary); }

.data-table td {
  padding: 12px 16px;
  vertical-align: middle;
  color: var(--text-primary);
}

.commits-cell {
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}

.commit-hash {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
}

.commit-arrow {
  color: var(--text-muted);
  margin: 0 5px;
}

.artifacts-cell {
  color: var(--text-secondary);
  font-size: 12px;
}

.date-cell {
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 32px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
}

/* ── Loading spinner ─────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

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

/* ── Toast / flash messages ──────────────────────────────── */

.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid transparent;
}
.flash-error   { background: rgba(248,81,73,.1);   border-color: rgba(248,81,73,.4);   color: var(--accent-red); }
.flash-success { background: rgba(63,185,80,.1);   border-color: rgba(63,185,80,.4);   color: var(--accent-green); }
.flash-info    { background: rgba(88,166,255,.1);  border-color: rgba(88,166,255,.4);  color: var(--accent-blue); }

/* ── Dashboard layout ────────────────────────────────────── */

.dashboard-layout {
  display: flex;
  min-height: calc(100vh - 56px);
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 20px 0;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-section-title {
  padding: 4px 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 20px;
  color: var(--text-secondary);
  font-size: 13px;
  transition: background 0.1s, color 0.1s;
  border-left: 3px solid transparent;
}
.sidebar-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}
.sidebar-link.active {
  color: var(--text-primary);
  border-left-color: var(--accent-blue);
  background: rgba(88,166,255,.08);
  font-weight: 500;
}

.sidebar-link-icon {
  width: 16px;
  height: 16px;
  opacity: 0.8;
  flex-shrink: 0;
}

.dashboard-main {
  flex: 1;
  padding: 32px;
  min-width: 0;
}

.view-section {
  display: none;
}
.view-section.active {
  display: block;
}

/* ── Forms ───────────────────────────────────────────────── */

.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.form-hint {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  padding: 7px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-control:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(88,166,255,.2);
}
.form-control::placeholder { color: var(--text-muted); }

.form-control-mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ── Artifact checklist ──────────────────────────────────── */

.artifact-list {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
}

.artifact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-muted);
  cursor: pointer;
  transition: background 0.1s;
}
.artifact-item:last-child { border-bottom: none; }
.artifact-item:hover { background: var(--bg-hover); }

.artifact-item input[type="checkbox"] {
  accent-color: var(--accent-blue);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.artifact-item-label {
  flex: 1;
  font-size: 12px;
  color: var(--text-primary);
}

.artifact-item-type {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}

/* ── Drag-and-drop upload zone ───────────────────────────── */

.drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--bg-tertiary);
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent-blue);
  background: rgba(88,166,255,.05);
}

.drop-zone-icon {
  font-size: 32px;
  margin-bottom: 10px;
  opacity: 0.5;
}

.drop-zone p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 6px;
}

.drop-zone span {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Card ────────────────────────────────────────────────── */

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

/* ── Split view (Artifacts page) ─────────────────────────── */

.split-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 800px) {
  .split-view { grid-template-columns: 1fr; }
}

/* ── Automation list ─────────────────────────────────────── */

.automation-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.automation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.automation-item-name {
  font-weight: 500;
  font-size: 13px;
}

.automation-item-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  font-family: var(--font-mono);
}

.automation-item-actions {
  display: flex;
  gap: 8px;
}

/* ── Modal ───────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 480px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-md);
  transform: translateY(-10px);
  transition: transform 0.2s;
}
.modal-backdrop.open .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* ── Miscellaneous ───────────────────────────────────────── */

.text-mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.text-muted { color: var(--text-muted); }

.divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 20px 0;
}

.copy-input-wrap {
  display: flex;
  gap: 8px;
}

.copy-input-wrap .form-control {
  font-family: var(--font-mono);
  font-size: 12px;
}
