/* ============================================================================
 * code-stats — shared styles
 *
 * Tokens follow the design audit + golden screens:
 *  - Geist (sans + mono) loaded via <link> from each HTML page.
 *  - Two modes: light (default :root) + dark (html.dark).
 *  - WCAG 2.2 AA palette; body text targets 7:1 contrast in both modes.
 *  - Curated 8-color data palette for charts and badges.
 *
 * Existing class names (.btn, .card, .topbar, .field, .stat, etc.) and
 * variable names (--bg, --surface, --text, --accent, ...) are preserved
 * so this file is a drop-in visual upgrade — HTML pages don't need to
 * change shape.
 * ========================================================================== */

:root {
  /* Light mode — default */
  --bg: #ffffff;
  --surface: #fafafa;
  --surface-2: #f5f5f5;
  --surface-hover: #ededed;
  --border: #d4d4d4;
  --border-strong: #a3a3a3;

  --text: #0a0a0a;             /* 20:1 on bg */
  --text-soft: #424242;         /* 10:1 */
  --muted: #525252;             /* 7.5:1 — body-grade muted */
  --muted-soft: #737373;        /* 5:1 — non-text only */

  --accent: #006634;            /* 7.2:1 on white, AAA */
  --accent-soft: #e6f4ec;
  --accent-text: #006634;
  --accent-fg: #ffffff;         /* foreground on accent */

  --secondary: #1e3a8a;         /* 11.6:1 */
  --secondary-soft: #e0e7ff;

  --warn: #855405;              /* 7:1 amber */
  --error: #8a0e0e;             /* 8.2:1 */
  --error-soft: #fbeaea;

  --github: #1f242e;
  --bitbucket: #2684ff;

  /* Data viz — 8 hand-picked hues, ordered by usage prominence */
  --data-1: #1e3a8a;
  --data-2: #006634;
  --data-3: #855405;
  --data-4: #6b21a8;
  --data-5: #9d174d;
  --data-6: #155e75;
  --data-7: #7c2d12;
  --data-8: #404040;
  --data-other: #a3a3a3;

  --shadow: 0 1px 0 rgba(0, 0, 0, 0.04) inset, 0 6px 24px rgba(0, 0, 0, 0.08);
}

html.dark {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1c1c1c;
  --surface-hover: #262626;
  --border: #303030;
  --border-strong: #525252;

  --text: #fafafa;              /* 19.6:1 */
  --text-soft: #d4d4d4;          /* 14.4:1 */
  --muted: #a3a3a3;              /* 8.8:1 */
  --muted-soft: #6b6b6b;

  --accent: #4ade80;             /* 10.4:1 */
  --accent-soft: rgba(74, 222, 128, 0.12);
  --accent-text: #4ade80;
  --accent-fg: #0a0a0a;

  --secondary: #93c5fd;
  --secondary-soft: rgba(147, 197, 250, 0.12);

  --warn: #fbbf24;
  --error: #f87171;
  --error-soft: #2a0808;

  --github: #f0f6fc;
  --bitbucket: #2684ff;

  --data-1: #93c5fd;
  --data-2: #4ade80;
  --data-3: #fbbf24;
  --data-4: #c4b5fd;
  --data-5: #f9a8d4;
  --data-6: #5eead4;
  --data-7: #fca5a5;
  --data-8: #d4d4d4;
  --data-other: #525252;

  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 6px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-feature-settings: 'cv11', 'ss01', 'tnum';
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 180ms ease, color 180ms ease;
}

code, pre, .mono { font-family: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
  text-decoration: none;
}

button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* App shell */

.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 56px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; }
.topbar .brand svg { color: var(--accent); }
.topbar .nav { display: flex; gap: 6px; }
.topbar .nav a { color: var(--muted); padding: 6px 12px; border-radius: 6px; font-size: 14px; font-weight: 500; }
.topbar .nav a:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.topbar .nav a.active { color: var(--text); background: var(--surface-2); }
.topbar .user { display: flex; align-items: center; gap: 12px; color: var(--text-soft); font-size: 13px; }
.topbar .user .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--data-2), var(--data-1));
  display: inline-flex; align-items: center; justify-content: center;
  color: #fafafa; font-weight: 600; font-size: 12px;
}
.topbar .user .signout {
  color: var(--muted); font-size: 12px; padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: transparent; font-family: inherit;
}
.topbar .user .signout:hover { background: var(--surface); color: var(--text); border-color: var(--border-strong); }

/* Theme toggle — sits inside .user before the avatar */
.theme-btn {
  width: 28px; height: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.theme-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.theme-btn .icon-sun { display: none; }
html.dark .theme-btn .icon-sun { display: block; }
html.dark .theme-btn .icon-moon { display: none; }

/* Floating theme toggle for pages without a topbar (sign-in landing) */
.theme-btn.floating {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 100;
  width: 32px; height: 32px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

/* Center column for sign-in / connect flows */

.center-pane {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
}
.card.wide { max-width: 720px; }
.card h1 { margin: 0 0 8px; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; color: var(--text); }
.card h2 { margin: 24px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.card p.lede { color: var(--text-soft); margin: 0 0 24px; font-size: 14px; }
.card .helper { color: var(--muted); font-size: 12px; margin-top: 12px; }

/* Brand mark */

.brand-mark { display: inline-flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.brand-mark .icon {
  width: 32px; height: 32px;
  background: var(--text);
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--bg);
}
.brand-mark .name { font-weight: 700; letter-spacing: -0.02em; font-size: 18px; }

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, filter 120ms;
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn:disabled, .btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn:disabled:hover, .btn[disabled]:hover { background: var(--surface); border-color: var(--border); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(0.95); }
.btn.primary:disabled, .btn.primary[disabled] { background: var(--accent); border-color: var(--accent); }
.btn.primary:disabled:hover, .btn.primary[disabled]:hover { background: var(--accent); border-color: var(--accent); }

.btn.large { padding: 14px 22px; font-size: 15px; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface); }
.btn.danger { color: var(--error); border-color: var(--error); background: transparent; }
.btn.danger:hover { background: var(--error-soft); }

.btn.google {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  font-weight: 600;
}
.btn.google:hover { filter: brightness(1.08); }
.btn.github { background: var(--github); color: var(--bg); border-color: var(--github); }
html.dark .btn.github { background: var(--github); color: #0a0a0a; }
.btn.github:hover { filter: brightness(0.95); }
.btn.bitbucket { background: var(--bitbucket); border-color: var(--bitbucket); color: #fff; }
.btn.bitbucket:hover { filter: brightness(1.05); }

/* Form */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.field input[type="text"], .field input[type="date"], .field select, .field textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  transition: border-color 120ms;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Repo-row override — must beat `.field label { text-transform: uppercase }` */
.field label.repo-row {
  text-transform: none;
  letter-spacing: normal;
  font-weight: normal;
  color: var(--text);
  font-size: 13px;
}
.field label.repo-row .meta {
  text-transform: none;
  letter-spacing: normal;
  color: var(--muted);
  font-weight: normal;
}

/* Segmented control */

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.segmented button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}
.segmented button.active {
  background: var(--text);
  color: var(--bg);
}

/* Chips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 500;
}
.chip .remove { color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1; }
.chip.author { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* Connection cards */

.provider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 24px 0; }
@media (max-width: 700px) { .provider-grid { grid-template-columns: 1fr; } }
.provider {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.provider .head { display: flex; align-items: center; gap: 12px; }
.provider .logo {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.provider .logo.github { background: var(--surface-2); color: var(--text); }
html.dark .provider .logo.github { background: #1f242e; color: var(--github); }
.provider .logo.bitbucket { background: rgba(38, 132, 255, 0.15); color: var(--bitbucket); }
.provider .name { font-weight: 600; font-size: 15px; }
.provider .status { font-size: 12px; color: var(--muted); }
.provider .status.connected { color: var(--accent); }

.connection-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.connection {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.connection .who { display: flex; align-items: center; gap: 8px; }
.connection .who .badge {
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
}
.connection .meta { color: var(--muted); font-size: 12px; }

/* Dashboard layout */

.dashboard { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 360px;
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  background: var(--bg);
  position: relative;
  transition: width 180ms ease, padding 180ms ease;
}
.sidebar.collapsed {
  width: 36px;
  padding: 12px 4px;
  overflow: hidden;
}
.sidebar.collapsed > *:not(.sidebar-toggle) { display: none; }
.sidebar-toggle {
  position: absolute;
  top: 10px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 11px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.sidebar-toggle:hover { background: var(--surface-hover); color: var(--text); }
.sidebar.collapsed .sidebar-toggle { right: 6px; }
.sidebar h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 24px 0 10px;
  font-weight: 600;
}
.sidebar h3:first-child { margin-top: 32px; }
.main { flex: 1; padding: 24px 32px; overflow-y: auto; }

.repo-list { display: flex; flex-direction: column; gap: 2px; }
.repo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.repo-item:hover { background: var(--surface); }
.repo-item input[type="checkbox"] { accent-color: var(--accent); }
.repo-item .source-icon {
  width: 16px; height: 16px;
  border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.repo-item .source-icon.github { background: var(--surface-2); color: var(--text); }
html.dark .repo-item .source-icon.github { background: #1f242e; color: var(--github); }
.repo-item .source-icon.bitbucket { background: rgba(38, 132, 255, 0.15); color: var(--bitbucket); }
.repo-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Dashboard content */

.totals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 28px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.stat { min-width: 0; }
.stat .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 500; }
.stat .value {
  font-size: 22px;
  font-weight: 600;
  margin-top: 4px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  font-family: 'Geist Mono', ui-monospace, Menlo, monospace;
  /* Belt + suspenders for unexpectedly large values: never let the
     number overflow its card. The compactNumber helper handles
     formatting in client code; this is the layout safety net. */
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
}
.stat .value.pos { color: var(--accent); }
.stat .value.neg { color: var(--error); }
.stat .delta { font-size: 11px; color: var(--muted); margin-top: 2px; }

.section-h {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 12px;
}
.section { margin-bottom: 32px; }

.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  height: 320px;
  display: flex;
  flex-direction: column;
}
.chart-card .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.chart-card .wrap { flex: 1; position: relative; }
@media (max-width: 1100px) { .charts-row { grid-template-columns: 1fr; } }

/* Tables */

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
table.data td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-family: 'Geist Mono', ui-monospace, Menlo, monospace; }
table.data td.pos { color: var(--accent); }
table.data td.neg { color: var(--error); }
table.data .source-icon {
  width: 14px; height: 14px;
  border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: -2px; margin-right: 6px;
}
table.data .source-icon.github { background: var(--surface-2); color: var(--text); }
html.dark table.data .source-icon.github { background: #1f242e; color: var(--github); }
table.data .source-icon.bitbucket { background: rgba(38, 132, 255, 0.15); color: var(--bitbucket); }
table.data .actor { display: inline-flex; align-items: center; gap: 8px; }
table.data .actor .avatar {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: var(--accent-fg);
}

/* Filter bar */

.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 24px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-soft);
}
.filter-bar .label { color: var(--muted); }

/* Index page */

.index-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
.index-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 120ms, transform 120ms;
}
.index-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.index-card .num { font-size: 11px; color: var(--muted); letter-spacing: 0.1em; font-family: 'Geist Mono', ui-monospace, Menlo, monospace; }
.index-card h3 { margin: 8px 0 4px; font-size: 17px; font-weight: 600; }
.index-card p { margin: 0; color: var(--text-soft); font-size: 13px; }
