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

:root {
  --bg:        #f8f7f4;
  --surface:   #ffffff;
  --border:    #e2e0d8;
  --text:      #1a1917;
  --muted:     #6b6861;
  --accent:    #2f54eb;
  --accent-bg: #eef1fd;
  --red:       #c0392b;
  --red-bg:    #fef3f2;
  --green:     #1a7f47;
  --green-bg:  #f0faf4;
  --amber:     #92600a;
  --amber-bg:  #fffbeb;
  --blue:      #1a4fbd;
  --blue-bg:   #eff4ff;
  --purple:    #6941c6;
  --purple-bg: #f4f0ff;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 28px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.3px;
  margin-bottom: 28px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-logo svg { opacity: .7; }

.nav-group-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 8px;
  margin: 20px 0 6px;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
}

.sidebar nav a:hover { background: var(--bg); color: var(--text); }
.sidebar nav a.active { background: var(--accent-bg); color: var(--accent); font-weight: 500; }

.main { flex: 1; padding: 36px 40px; max-width: 1000px; }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 22px; font-weight: 600; letter-spacing: -.4px; }
.page-header p  { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 16px; }

.card-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ── Form elements ────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; align-items: end; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 5px;
}

.field input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
}

.field input:focus { border-color: var(--accent); background: var(--surface); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover { background: #1e3fcc; }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

/* ── Alert banners ────────────────────────────────────────────────────────── */
.alert {
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.alert-danger  { background: var(--red-bg);    border: 1px solid #fecdca; color: var(--red);    }
.alert-success { background: var(--green-bg);  border: 1px solid #a9efca; color: var(--green);  }
.alert-ai      { background: var(--accent-bg); border: 1px solid #c7d7fd; color: var(--blue);   }
.alert-warning { background: var(--amber-bg);  border: 1px solid #fde68a; color: var(--amber);  }

.alert-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

.alert strong { display: block; font-weight: 600; margin-bottom: 3px; }
.alert p { margin: 0; color: inherit; opacity: .85; }

/* ── Stat row ─────────────────────────────────────────────────────────────── */
.stat-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  min-width: 110px;
  box-shadow: var(--shadow);
}

.stat-val { font-size: 24px; font-weight: 600; line-height: 1; }
.stat-lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* Row coloring by change kind */
tr.added            td:first-child { border-left: 3px solid var(--green);  }
tr.removed          td:first-child { border-left: 3px solid var(--red);    }
tr.signaturechanged td:first-child { border-left: 3px solid var(--amber);  }
tr.bodymodified     td:first-child { border-left: 3px solid #0891b2;       }
tr.renamed          td:first-child { border-left: 3px solid var(--blue);   }
tr.moved            td:first-child { border-left: 3px solid var(--purple); }
tr.typechanged      td:first-child { border-left: 3px solid var(--red);    }
tr.initializerchanged td:first-child { border-left: 3px solid var(--amber); }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-red    { background: var(--red-bg);    color: var(--red);    }
.badge-green  { background: var(--green-bg);  color: var(--green);  }
.badge-amber  { background: var(--amber-bg);  color: var(--amber);  }
.badge-blue   { background: var(--blue-bg);   color: var(--blue);   }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-teal   { background: #f0fdfa;          color: #0f766e;       }
.badge-gray   { background: #f3f4f6;          color: #4b5563;       }

/* ── Code / signature display ─────────────────────────────────────────────── */
.sig {
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

.sig .kw   { color: #7c3aed; }   /* keyword */
.sig .type { color: #0369a1; }   /* type    */
.sig .name { color: var(--text); font-weight: 500; }
.sig .param-changed { background: #fef9c3; border-radius: 3px; padding: 0 2px; color: #713f12; }
.sig .param-added   { background: var(--green-bg); border-radius: 3px; padding: 0 2px; color: var(--green); }
.sig .param-removed { background: var(--red-bg);   border-radius: 3px; padding: 0 2px; color: var(--red); text-decoration: line-through; }

/* ── Semantic diff highlight block ────────────────────────────────────────── */
.diff-block {
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 12.5px;
  background: #1e1e2e;
  color: #cdd6f4;
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.7;
}

.diff-block .removed-line { color: #f38ba8; }
.diff-block .added-line   { color: #a6e3a1; }
.diff-block .hl-token     { background: rgba(249,226,175,.25); color: #f9e2af; border-radius: 3px; padding: 0 3px; }
.diff-block .hl-added     { background: rgba(166,227,161,.2);  color: #a6e3a1; border-radius: 3px; padding: 0 3px; }
.diff-block .hl-removed   { background: rgba(243,139,168,.2);  color: #f38ba8; border-radius: 3px; padding: 0 3px; text-decoration: line-through; }

/* ── Section heading ──────────────────────────────────────────────────────── */
.section-heading {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 28px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ── Param diff list ──────────────────────────────────────────────────────── */
.param-diffs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 0;
  font-size: 14px;
}

/* ── History card ─────────────────────────────────────────────────────────── */
.run-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}

.run-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.run-card-meta { font-size: 13px; color: var(--muted); }
.run-card-meta strong { color: var(--text); font-weight: 600; }
.run-card-body { padding: 16px 20px; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
  .sidebar { width: 60px; padding: 16px 8px; }
  .sidebar-logo span, .nav-group-label, .sidebar nav a span { display: none; }
  .main { padding: 24px 16px; }
}

/* ── Login gate ───────────────────────────────────────────────────────────── */
.login-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 48px 40px;
  text-align: center;
  max-width: 400px;
  width: 100%;
}

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px; height: 56px;
  background: var(--accent-bg);
  border-radius: 14px;
  color: var(--accent);
  margin-bottom: 20px;
}

.login-title { font-size: 22px; font-weight: 600; letter-spacing: -.4px; margin-bottom: 8px; }
.login-sub   { font-size: 14px; color: var(--muted); margin-bottom: 28px; line-height: 1.5; }
.login-note  { font-size: 12px; color: var(--muted); margin-top: 14px; }

.btn-lg { height: 44px; font-size: 15px; padding: 0 24px; border-radius: 8px; width: 100%; justify-content: center; }

/* ── Sidebar user ─────────────────────────────────────────────────────────── */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  margin-top: auto;
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name  { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-login { font-size: 11px; color: var(--muted); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: none;
  background: none;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ── Repo list ────────────────────────────────────────────────────────────── */
.repo-search-wrap { margin-bottom: 10px; }
.repo-search {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.repo-search:focus { border-color: var(--accent); }

.repo-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.repo-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.repo-item:last-child { border-bottom: none; }
.repo-item:hover { background: var(--surface); }
.repo-item-selected { background: var(--accent-bg) !important; }

.repo-item-name { font-size: 13px; font-weight: 500; display: flex; align-items: center; }
.repo-item-desc { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.repo-item-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

/* ── Commit list ──────────────────────────────────────────────────────────── */
.commit-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 0;
}

.commit-item {
  display: grid;
  grid-template-columns: 52px 1fr;
  grid-template-rows: auto auto;
  gap: 1px 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.commit-item:last-child { border-bottom: none; }
.commit-item:hover { background: var(--surface); }
.commit-selected { background: var(--accent-bg) !important; }

.commit-sha  { font-family: monospace; font-size: 11px; color: var(--accent); grid-row: 1; grid-column: 1; }
.commit-msg  { font-size: 12px; font-weight: 500; grid-row: 1; grid-column: 2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.commit-meta { font-size: 11px; color: var(--muted); grid-row: 2; grid-column: 2; }

/* ── Select input ─────────────────────────────────────────────────────────── */
.select-input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  cursor: pointer;
}
.select-input:focus { border-color: var(--accent); }

/* ── Field hint ───────────────────────────────────────────────────────────── */
.field-hint { font-size: 11px; color: var(--muted); font-weight: 400; margin-left: 4px; }

/* ── Dark spinner (for light backgrounds) ─────────────────────────────────── */
.spinner-dark {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* ── Run card (history) ───────────────────────────────────────────────────── */
.run-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}
.run-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.run-card-meta  { font-size: 13px; color: var(--muted); }
.run-card-meta strong { color: var(--text); font-weight: 600; }
.run-card-body  { padding: 16px 20px; }
