/* ─── Design System — Code Historian ─────────────────────────────────────── */

:root {
  /* Core brand */
  --j:  #252525;   /* Dark primary text */
  --s:  #141414;   /* Darkest */
  --rm: #E7343E;   /* Trackting brand red */
  --ok: #079455;   /* Success green */
  --wa: #DC6803;   /* Warning orange */
  --er: #F04438;   /* Error red */
  --nb: #167CCF;   /* Info blue */

  /* Neutrals */
  --bp: #424242;
  --ca: #525252;
  --ir: #737373;
  --ds: #A3A3A3;
  --sm: #D6D6D6;
  --sh: #D2D6DB;
  --co: #ECECEC;
  --ws: #F5F5F5;
  --pr: #FDEBEC;   /* Problem red bg */
  --wh: #FFFFFF;

  /* Typography */
  --ff: 'Outfit', system-ui, -apple-system, sans-serif;
  --mf: 'SF Mono', 'Fira Code', 'Fira Mono', ui-monospace, monospace;

  /* Radius */
  --rxs: 4px;
  --rsm: 6px;
  --rmd: 8px;
  --rlg: 10px;
  --rp:  100px;

  /* Shadow */
  --sc: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
  --sm-shadow: 0 1px 2px rgba(16,24,40,.05);

  /* Sidebar */
  --sb-w: 214px;
  --sb-collapsed: 48px;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--ff);
  font-size: 12px;
  color: var(--j);
  background: var(--ws);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ─── Animations ─────────────────────────────────────────────────────────── */
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes dot {
  0%, 80%, 100% { transform: scale(0); opacity: .4; }
  40%            { transform: scale(1); opacity: 1; }
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sb-w);
  min-width: var(--sb-w);
  background: var(--j);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .2s ease, min-width .2s ease;
  flex-shrink: 0;
}
.sidebar.collapsed {
  width: var(--sb-collapsed);
  min-width: var(--sb-collapsed);
}

/* Logo */
.sb-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sb-logo-icon {
  width: 24px;
  height: 24px;
  background: var(--rm);
  border-radius: var(--rsm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  font-size: 14px;
}
.sb-logo-text {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
}
.sb-logo-sub {
  font-size: 9px;
  color: rgba(255,255,255,.4);
  white-space: nowrap;
}

/* Nav */
.sb-nav {
  flex: 1;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
}
.sb-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--rsm);
  cursor: pointer;
  transition: background .15s;
  text-decoration: none;
  color: rgba(255,255,255,.6);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
}
.sb-nav-item:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.9); }
.sb-nav-item.active {
  background: rgba(231,52,62,.15);
  color: var(--rm);
}
.sb-nav-item .material-symbols-outlined {
  font-size: 16px;
  flex-shrink: 0;
}
.sb-nav-label { white-space: nowrap; overflow: hidden; }

/* Sidebar toggle button */
.sb-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  cursor: pointer;
  color: rgba(255,255,255,.4);
  transition: color .15s;
  flex-shrink: 0;
}
.sb-toggle:hover { color: rgba(255,255,255,.8); }
.sb-toggle .material-symbols-outlined { font-size: 16px; }

/* User section */
.sb-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sb-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.sb-user-name {
  font-size: 11px;
  color: rgba(255,255,255,.8);
  white-space: nowrap;
  overflow: hidden;
}

/* Label fade on collapse */
.sb-label { transition: opacity .15s; }
.sidebar.collapsed .sb-label { opacity: 0; width: 0; overflow: hidden; }

/* ─── Main content ───────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--wh);
  border-bottom: 1px solid var(--sh);
  flex-shrink: 0;
}
.main-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--j);
}
.main-sub {
  font-size: 10px;
  color: var(--ir);
  margin-top: 1px;
}
.main-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--wh);
  border: 1px solid var(--sh);
  border-radius: var(--rlg);
  box-shadow: var(--sc);
}
.card-body { padding: 16px 18px; }

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--wh);
  border: 1px solid var(--sh);
  border-radius: var(--rlg);
  padding: 14px 16px;
  box-shadow: var(--sc);
}
.kpi-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--rsm);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  font-size: 15px;
}
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--j);
  line-height: 1;
}
.kpi-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--ir);
  margin-top: 4px;
}
.kpi-sub {
  font-size: 9px;
  color: var(--ds);
  margin-top: 4px;
}

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--wh);
  border: 1px solid var(--sh);
  border-radius: var(--rlg);
  box-shadow: var(--sc);
  overflow: hidden;
}
.table-header-row {
  display: grid;
  padding: 8px 16px;
  background: var(--ws);
  border-bottom: 1px solid var(--sh);
}
.table-header-cell {
  font-size: 9px;
  font-weight: 600;
  color: var(--ds);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.table-row {
  display: grid;
  padding: 10px 16px;
  border-bottom: 1px solid var(--co);
  align-items: center;
  cursor: pointer;
  transition: background .1s;
}
.table-row:last-child { border-bottom: none; }
.table-row:hover { background: rgba(0,0,0,.02); }
.table-row.error-row { background: rgba(253,235,236,.4); }
.table-cell { font-size: 11px; color: var(--j); overflow: hidden; }

/* ─── Status badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: var(--rp);
  font-size: 9px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
}
.badge .material-symbols-outlined { font-size: 10px; }

.badge-done     { background: rgba(7,148,85,.10);   color: var(--ok); }
.badge-running  { background: rgba(22,124,207,.10); color: var(--nb); }
.badge-running .material-symbols-outlined { animation: spin 2s linear infinite; }
.badge-queued   { background: rgba(163,163,163,.15); color: var(--ds); }
.badge-error    { background: var(--pr);             color: var(--er); }
.badge-warning  { background: rgba(220,104,3,.10);   color: var(--wa); }

/* Issue severity badges */
.badge-critical { background: var(--pr); color: var(--er); }
.badge-high     { background: rgba(220,104,3,.10); color: var(--wa); }
.badge-medium   { background: rgba(163,163,163,.10); color: var(--ca); }
.badge-info     { background: var(--ws); color: var(--ds); }

/* ─── Branch & type chips ────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: var(--rxs);
  font-size: 9px;
  font-weight: 500;
  border: 1px solid transparent;
}
.chip-branch {
  background: rgba(22,124,207,.08);
  color: var(--nb);
  border-color: rgba(22,124,207,.2);
}
.chip-push    { background: rgba(7,148,85,.08);  color: var(--ok); border-color: rgba(7,148,85,.2); }
.chip-pr      { background: rgba(22,124,207,.08); color: var(--nb); border-color: rgba(22,124,207,.2); }

/* ─── Avatar ─────────────────────────────────────────────────────────────── */
.avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--co);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7px;
  font-weight: 700;
  color: var(--ca);
  flex-shrink: 0;
}
.avatar-sm { width: 16px; height: 16px; font-size: 6px; }

/* ─── SHA code ───────────────────────────────────────────────────────────── */
.sha {
  font-family: var(--mf);
  font-size: 10px;
  font-weight: 500;
  color: var(--j);
  background: rgba(0,0,0,.04);
  padding: 1px 5px;
  border-radius: var(--rxs);
}

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--ds);
  border-radius: var(--rmd);
  font-family: var(--ff);
  font-size: 12px;
  color: var(--j);
  background: var(--wh);
  outline: none;
  transition: border-color .15s;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--j) !important;
}
.form-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--ca);
  margin-bottom: 4px;
}
.form-help { font-size: 10px; color: var(--ds); margin-top: 3px; }
.form-error { font-size: 10px; color: var(--er); margin-top: 3px; }
.form-group { margin-bottom: 14px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: var(--rmd);
  font-family: var(--ff);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s;
  border: 1px solid transparent;
}
.btn:hover { opacity: .85; }
.btn .material-symbols-outlined { font-size: 14px; }

.btn-primary { background: var(--j); color: #fff; }
.btn-secondary { background: var(--wh); color: var(--j); border-color: var(--sh); }
.btn-danger { background: var(--pr); color: var(--er); border-color: rgba(240,68,56,.2); }
.btn-sm { padding: 4px 10px; font-size: 10px; }

/* Filter chip buttons */
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--rp);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--sh);
  background: var(--wh);
  color: var(--ir);
  transition: all .15s;
}
.filter-chip.active {
  background: var(--j);
  color: var(--wh);
  border-color: var(--j);
}
.filter-chip .material-symbols-outlined { font-size: 12px; }

/* ─── Toggle switch ──────────────────────────────────────────────────────── */
.toggle {
  width: 32px;
  height: 18px;
  border-radius: var(--rp);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}
.toggle-on { background: var(--ok); }
.toggle-off { background: var(--co); }
.toggle-thumb {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  transition: left .15s;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.toggle-on .toggle-thumb  { left: calc(100% - 14px - 2px); }
.toggle-off .toggle-thumb { left: 2px; }

/* ─── Breadcrumb ─────────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
}
.breadcrumb-item {
  font-size: 10px;
  color: var(--ir);
  cursor: pointer;
}
.breadcrumb-item:hover { color: var(--j); }
.breadcrumb-sep { font-size: 10px; color: var(--sm); }
.breadcrumb-current { color: var(--j); font-weight: 500; cursor: default; }

/* ─── Tabs ───────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--sh);
  background: var(--wh);
}
.tab-item {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--ir);
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
}
.tab-item.active { color: var(--j); border-bottom-color: var(--j); }
.tab-item:hover:not(.active) { color: var(--ca); }

/* ─── Diff viewer ────────────────────────────────────────────────────────── */
.diff-wrap {
  font-family: var(--mf);
  font-size: 11.5px;
  line-height: 1.7;
  border-radius: var(--rmd);
  overflow: hidden;
  border: 1px solid var(--sh);
}
.diff-file-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--ws);
  border-bottom: 1px solid var(--sh);
  font-size: 11px;
  font-weight: 500;
}
.diff-line {
  display: grid;
  grid-template-columns: 40px 40px 14px 1fr;
}
.diff-line-add  { background: rgba(7,148,85,.08); }
.diff-line-del  { background: rgba(240,68,56,.07); }
.diff-line-ctx  { background: var(--wh); }
.diff-line-hunk { background: rgba(22,124,207,.06); }
.diff-ln {
  color: var(--ds);
  padding: 0 8px;
  text-align: right;
  user-select: none;
  border-right: 1px solid var(--co);
  font-size: 10px;
}
.diff-sig {
  padding: 0 4px;
  text-align: center;
  color: var(--ir);
}
.diff-line-add  .diff-sig { color: var(--ok); }
.diff-line-del  .diff-sig { color: var(--er); }
.diff-line-hunk .diff-sig { color: var(--nb); }
.diff-text { padding: 0 8px; white-space: pre; overflow-x: auto; }

/* ─── Markdown content ───────────────────────────────────────────────────── */
.review-body { color: var(--bp); line-height: 1.6; font-size: 12px; }
.review-body h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--j);
  margin: 18px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--co);
}
.review-body h3:first-child { margin-top: 0; }
.review-body p  { margin-bottom: 8px; }
.review-body ul { padding-left: 18px; margin-bottom: 8px; }
.review-body li { margin-bottom: 3px; }
.review-body code {
  font-family: var(--mf);
  font-size: 10px;
  background: rgba(0,0,0,.05);
  color: var(--nb);
  padding: 1px 5px;
  border-radius: var(--rxs);
}
.review-body pre {
  background: var(--ws);
  border: 1px solid var(--sh);
  border-radius: var(--rmd);
  padding: 12px;
  overflow-x: auto;
  margin-bottom: 10px;
}
.review-body pre code {
  background: none;
  color: var(--j);
  padding: 0;
  font-size: 11px;
}
.review-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  font-size: 11px;
}
.review-body th {
  background: var(--ws);
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  border: 1px solid var(--sh);
}
.review-body td { padding: 5px 10px; border: 1px solid var(--sh); }
.review-body tr:nth-child(even) td { background: rgba(0,0,0,.02); }

/* ─── Search input ───────────────────────────────────────────────────────── */
.search-wrap { position: relative; }
.search-wrap .material-symbols-outlined {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--ds);
  pointer-events: none;
}
.search-input {
  padding: 6px 10px 6px 28px;
  border: 1px solid var(--sh);
  border-radius: var(--rp);
  font-size: 11px;
  outline: none;
  background: var(--wh);
  color: var(--j);
  width: 200px;
}
.search-input:focus { border-color: var(--j); }

/* ─── Auth pages ─────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ws);
  padding: 20px;
}
.auth-card {
  background: var(--wh);
  border: 1px solid var(--sh);
  border-radius: var(--rlg);
  box-shadow: var(--sc);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}
.auth-logo-icon {
  width: 32px;
  height: 32px;
  background: var(--rm);
  border-radius: var(--rmd);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
}
.auth-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.auth-sub   { font-size: 11px; color: var(--ir); margin-bottom: 24px; }
.auth-footer { margin-top: 16px; text-align: center; font-size: 10px; color: var(--ir); }
.auth-footer a { color: var(--nb); }

/* ─── Alert messages ─────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--rmd);
  font-size: 11px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert-error   { background: var(--pr); color: var(--er); border-color: rgba(240,68,56,.2); }
.alert-success { background: rgba(7,148,85,.08); color: var(--ok); border-color: rgba(7,148,85,.2); }
.alert-info    { background: rgba(22,124,207,.08); color: var(--nb); border-color: rgba(22,124,207,.2); }

/* ─── Verdict bar (review) ───────────────────────────────────────────────── */
.verdict {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--rmd);
  font-size: 11px;
  font-weight: 500;
  margin-top: 16px;
}
.verdict-pass { background: rgba(7,148,85,.08); color: var(--ok); }
.verdict-fail { background: var(--pr); color: var(--er); }
.verdict .material-symbols-outlined { font-size: 16px; }

/* ─── Repo cards (settings) ──────────────────────────────────────────────── */
.repo-card {
  background: var(--wh);
  border: 1px solid var(--sh);
  border-radius: var(--rlg);
  padding: 16px 18px;
  box-shadow: var(--sc);
  margin-bottom: 12px;
}
.repo-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}
.repo-card-name { font-size: 13px; font-weight: 600; color: var(--j); }
.repo-card-url  { font-size: 10px; color: var(--ir); margin-top: 2px; }
.repo-card-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.repo-meta-label { font-size: 9px; color: var(--ds); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 3px; }
.repo-meta-value { font-size: 11px; color: var(--ca); }

/* Add form panel */
.add-form-panel {
  background: var(--wh);
  border: 1px solid rgba(231,52,62,.3);
  border-radius: var(--rlg);
  padding: 18px;
  margin-bottom: 20px;
  box-shadow: 0 0 0 3px rgba(231,52,62,.06);
}
.add-form-title { font-size: 12px; font-weight: 600; color: var(--j); margin-bottom: 14px; }

/* ─── Pygments code highlight override ───────────────────────────────────── */
.codehilite { background: var(--ws) !important; border-radius: var(--rmd); }
.codehilite pre { padding: 12px; font-size: 11px; }

/* ─── Utility ────────────────────────────────────────────────────────────── */
.text-muted  { color: var(--ir); }
.text-small  { font-size: 10px; }
.text-mono   { font-family: var(--mf); }
.flex        { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-2       { gap: 2px; }
.gap-4       { gap: 4px; }
.gap-8       { gap: 8px; }
.gap-12      { gap: 12px; }
.mt-4        { margin-top: 4px; }
.mt-8        { margin-top: 8px; }
.mt-12       { margin-top: 12px; }
.mb-12       { margin-bottom: 12px; }
.mb-16       { margin-bottom: 16px; }
.w-full      { width: 100%; }
.truncate    { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
