/* Armature Discoverability — design system.
   Derived from the main app's tokens: warm bone surfaces, hard ink, brick
   accent, zero border-radius everywhere except true pills. */

@font-face {
  font-family: 'Stack Sans Notch';
  src: url('/frontend/assets/fonts/StackSansNotch-VariableFont_wght.ttf') format('truetype');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #fbf9f7;
  --surface: #ffffff;
  --surface-2: #f6f2ef;
  --surface-3: #ede7e2;
  --hover: #f0ebe6;
  --paper: #ffffff;

  --ink: #090808;
  --on-ink: #f6f2ef;
  --border: rgba(9, 8, 8, 0.14);
  --border-strong: rgba(9, 8, 8, 0.32);
  --border-soft: rgba(9, 8, 8, 0.07);

  --text: #090808;
  --text-2: #4a4644;
  --text-3: #807a76;
  --text-4: #b1aba5;

  --brand: #c8410d;
  --brand-2: #b3380a;
  --brand-soft: #fbe6dd;
  --brand-soft-border: #f3c8b4;

  --green: #1d7a4a; --green-soft: #e6f3eb; --green-soft-border: #c8e3d2;
  --red: #b3261e;   --red-soft: #fbe9e7;   --red-soft-border: #f3c9c5;
  --amber: #a86207; --amber-soft: #fbf0db; --amber-soft-border: #f0dcb0;
  --blue: #1f5da6;  --blue-soft: #e7eff9;  --blue-soft-border: #c9d8ef;
  --violet: #6c4ab3; --violet-soft: #efeaf8;
  --teal: #0f766e;  --teal-soft: #e3f2f0;  --teal-soft-border: #bfdedb;

  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Stack Sans Notch', 'DM Sans', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', ui-monospace, Menlo, monospace;

  --shadow-sm: 0 1px 2px rgba(20, 16, 8, 0.04), 0 0 0 1px rgba(20, 16, 8, 0.04);
  --shadow-md: 0 2px 6px rgba(20, 16, 8, 0.06), 0 0 0 1px rgba(20, 16, 8, 0.05);
  --shadow-lg: 0 8px 24px rgba(20, 16, 8, 0.08), 0 0 0 1px rgba(20, 16, 8, 0.05);
  --shadow-pop: 0 12px 36px rgba(20, 16, 8, 0.14), 0 0 0 1px rgba(20, 16, 8, 0.06);
  --ring: 0 0 0 3px rgba(200, 65, 13, 0.22);

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-1: 90ms; --dur-2: 160ms; --dur-3: 220ms;

  --sidebar-w: 224px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--brand-soft); }
a { color: inherit; }
button { font-family: var(--font-sans); }

.mono { font-family: var(--font-mono); }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 8px; }
.clickable { cursor: pointer; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 20;
}
.sb-brand { padding: 18px 16px 14px; border-bottom: 1px solid var(--border-soft); }
.sb-wordmark { font-weight: 700; font-size: 15.5px; letter-spacing: -0.01em; }
.sb-module { font-family: var(--font-mono); font-size: 11px; color: var(--brand); margin-top: 1px; }
.sb-org { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-3); margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sb-group {
  margin: 14px 19px 4px;
  font-family: var(--font-display);
  font-size: 10.5px; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-4);
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  margin: 0 8px; padding: 8px 11px;
  font-size: 13.5px; color: var(--text-2);
  cursor: pointer; user-select: none;
  border-left: 2px solid transparent;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
  text-decoration: none;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--paper); color: var(--text); border-left-color: var(--brand); font-weight: 500; }
.nav-item svg { flex: none; }
.nav-item .ext { margin-left: auto; color: var(--text-4); }
.nav-item.disabled { color: var(--text-4); cursor: default; }
.nav-item.disabled:hover { background: transparent; }

.sb-spacer { flex: 1; }
.sb-foot {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 9px;
}
.avatar {
  width: 26px; height: 26px; flex: none;
  background: var(--ink); color: var(--on-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 500;
}
.sb-foot-mail { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-signout { margin-left: auto; color: var(--text-3); cursor: pointer; padding: 4px; }
.sb-signout:hover { color: var(--red); }

.content { min-width: 0; }
.page { max-width: 1180px; margin: 0 auto; padding: 26px 30px 80px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-title { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; margin: 0; display: flex; align-items: center; gap: 10px; }
.page-sub { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-3); margin-top: 4px; }

.filterbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

/* ---------- primitives ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px;
  font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--text); background: transparent; color: var(--text);
  cursor: pointer; border-radius: 0; text-decoration: none;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
  user-select: none;
}
.btn:hover { background: var(--text); color: var(--bg); }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.ink { background: var(--ink); color: var(--on-ink); }
.btn.ink:hover { background: #2a2624; }
.btn.ghost { border-color: var(--border-strong); color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text); border-color: var(--text); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: var(--red); color: #fff; }
.btn.sm { padding: 4px 9px; font-size: 11.5px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500;
  line-height: 1.5; text-transform: uppercase; letter-spacing: 0.04em;
  border: 1px solid currentColor; background: transparent;
  white-space: nowrap; border-radius: 0;
}
.badge.gray { color: var(--text-3); }
.badge.ink { color: var(--ink); }
.badge.green { color: var(--green); }
.badge.red { color: var(--red); }
.badge.amber { color: var(--amber); }
.badge.blue { color: var(--blue); }
.badge.violet { color: var(--violet); }
.badge.teal { color: var(--teal); }
.badge.brand { color: var(--brand); }
.badge.fill-brand { background: var(--brand-soft); border-color: var(--brand-soft-border); color: var(--brand-2); }
.badge .dot { width: 6px; height: 6px; background: currentColor; }
.badge .dot.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  font-family: var(--font-mono); font-size: 11px;
  border: 1px solid var(--border-strong); background: var(--surface);
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: all var(--dur-1) var(--ease);
}
.chip:hover { border-color: var(--text); }
.chip.on { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

.delta { display: inline-flex; align-items: center; gap: 3px; font-family: var(--font-mono); font-size: 11px; font-weight: 500; white-space: nowrap; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--text-4); }

.card { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 0; }
.card.hoverable { transition: box-shadow var(--dur-2) var(--ease); }
.card.hoverable:hover { box-shadow: var(--shadow-md); }
.card-head { padding: 11px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card-title { font-size: 13px; font-weight: 600; margin: 0; }
.card-sub { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }
.card-pad { padding: 14px 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border-strong); padding: 13px 15px; transition: box-shadow var(--dur-2) var(--ease); }
.kpi.clickable:hover { box-shadow: var(--shadow-md); }
.kpi-label { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.kpi-value { font-family: var(--font-mono); font-size: 23px; font-weight: 500; margin-top: 5px; line-height: 1.2; display: flex; align-items: baseline; gap: 8px; }
.kpi-sub { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-4); margin-top: 3px; }

/* ---------- tables ---------- */
.table-wrap { background: var(--paper); border: 1px solid var(--border-strong); overflow-x: auto; }
table.tt { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
table.tt thead th {
  text-align: left; font-family: var(--font-mono); font-weight: 500;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-3); padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0;
}
table.tt td { padding: 8px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.tt tbody tr:last-child td { border-bottom: none; }
table.tt tbody tr.click { cursor: pointer; transition: background var(--dur-1) var(--ease); }
table.tt tbody tr.click:hover { background: var(--hover); }
table.tt td.num, table.tt th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.bar-track { height: 8px; background: var(--surface-3); position: relative; min-width: 60px; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--ink); transition: width var(--dur-3) var(--ease); }
.bar-fill.brand { background: var(--brand); }

.rankcell { display: flex; align-items: center; gap: 9px; min-width: 0; }
.favicon { width: 18px; height: 18px; flex: none; display: flex; align-items: center; justify-content: center; background: var(--surface-3); font-family: var(--font-mono); font-size: 10px; font-weight: 500; color: var(--text-2); overflow: hidden; }
.favicon img { width: 14px; height: 14px; display: block; }
.toolname { font-family: var(--font-mono); font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolname.you { color: var(--brand); }

/* ---------- inputs ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); }
.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 8px 10px; font-size: 13px; font-family: var(--font-sans);
  border-radius: 0; outline: none;
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--text); box-shadow: var(--ring); }
.textarea { font-family: var(--font-mono); font-size: 12px; line-height: 1.6; resize: vertical; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; cursor: pointer; }

.seg { display: inline-flex; border: 1px solid var(--ink); }
.seg > button {
  padding: 6px 12px; font-size: 12px; border: none; background: transparent; color: var(--text-2);
  cursor: pointer; border-radius: 0; transition: all var(--dur-1) var(--ease);
}
.seg > button + button { border-left: 1px solid var(--border); }
.seg > button.on { background: var(--ink); color: var(--on-ink); font-weight: 500; }
.seg > button[disabled] { color: var(--text-4); cursor: not-allowed; }

/* ---------- charts ---------- */
.chart-wrap { position: relative; }
.chart-legend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 2px 0 8px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--text-2); }
.legend-swatch { width: 14px; height: 3px; }
.chart-axis { font-family: var(--font-mono); font-size: 10px; fill: var(--text-4); }
.chart-grid { stroke: var(--border-soft); }

/* ---------- specific components ---------- */
.repo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.repo-card { background: var(--surface); border: 1px solid var(--border-strong); padding: 12px 14px; cursor: pointer; transition: box-shadow var(--dur-2) var(--ease), border-color var(--dur-1) var(--ease); display: flex; flex-direction: column; gap: 8px; }
.repo-card:hover { box-shadow: var(--shadow-md); }
.repo-card.selected { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.repo-name { font-family: var(--font-mono); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.checkbox { width: 13px; height: 13px; border: 1px solid var(--border-strong); background: var(--surface); flex: none; display: flex; align-items: center; justify-content: center; color: var(--on-ink); font-size: 10px; transition: all var(--dur-1) var(--ease); }
.checkbox.on { background: var(--ink); border-color: var(--ink); }

.actionbar {
  position: sticky; bottom: 18px; z-index: 15;
  display: flex; align-items: center; gap: 12px;
  background: var(--ink); color: var(--on-ink);
  padding: 10px 16px; margin-top: 16px;
  box-shadow: var(--shadow-pop);
}
.actionbar .mono { color: var(--on-ink); }

.matrix-cell { width: 12px; height: 12px; display: inline-block; }
.matrix-cell.chosen { background: var(--ink); }
.matrix-cell.chosen.you { background: var(--brand); }
.matrix-cell.mentioned { border: 1px solid var(--border-strong); }

.callout { background: var(--surface); border: 1px solid var(--border-strong); border-left: 3px solid var(--brand); padding: 11px 14px; font-size: 12.5px; line-height: 1.6; }

.quote { border-left: 2px solid var(--border-strong); padding: 2px 0 2px 12px; color: var(--text-2); font-size: 12.5px; font-style: italic; margin: 6px 0 0; }

.diff-pane { font-family: var(--font-mono); font-size: 11.5px; line-height: 1.7; }
.diff-pane .dl { padding: 1px 12px; white-space: pre-wrap; word-break: break-word; }
.diff-pane .dl.add { background: var(--green-soft); color: var(--green); }
.diff-pane .dl.del { background: var(--red-soft); color: var(--red); text-decoration: line-through; }
.diff-pane .dl.ctx { color: var(--text-3); }

.edit-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; border-left: 2px solid transparent; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-2); transition: background var(--dur-1) var(--ease); overflow: hidden; }
.edit-item:hover { background: var(--hover); }
.edit-item.on { background: var(--paper); color: var(--text); border-left-color: var(--brand); }
.edit-item .url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.md-preview { font-size: 13px; line-height: 1.65; }
.md-preview h1 { font-size: 17px; margin: 0 0 10px; }
.md-preview h2 { font-size: 14px; margin: 16px 0 8px; }
.md-preview pre { background: var(--surface-2); border: 1px solid var(--border); padding: 10px 12px; font-family: var(--font-mono); font-size: 11.5px; overflow-x: auto; }
.md-preview code { font-family: var(--font-mono); font-size: 11.5px; background: var(--surface-2); padding: 1px 4px; }
.md-preview pre code { background: none; padding: 0; }

/* ---------- drawer ---------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(9, 8, 8, 0.28); z-index: 40; animation: fadein var(--dur-2) var(--ease); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 92vw);
  background: var(--surface); border-left: 1px solid var(--border-strong);
  z-index: 41; display: flex; flex-direction: column;
  box-shadow: var(--shadow-pop);
  animation: slidein var(--dur-3) var(--ease);
}
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.drawer-x { margin-left: auto; cursor: pointer; color: var(--text-3); padding: 4px; }
.drawer-x:hover { color: var(--text); }

/* ---------- states ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 48px 24px; text-align: center; }
.empty-title { font-size: 14px; font-weight: 600; }
.empty-body { color: var(--text-3); font-size: 12.5px; max-width: 380px; }

.error-box { background: var(--red-soft); border: 1px solid var(--red-soft-border); color: var(--red); padding: 10px 14px; font-size: 12.5px; }

.spin { animation: rotate 0.9s linear infinite; }
@keyframes rotate { to { transform: rotate(360deg); } }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 24px; }
.auth-card { width: 380px; background: var(--surface); border: 1px solid var(--border-strong); padding: 30px 30px 26px; box-shadow: var(--shadow-lg); }
.auth-word { font-weight: 700; font-size: 18px; }
.auth-mod { font-family: var(--font-mono); font-size: 11.5px; color: var(--brand); margin-bottom: 22px; }

/* ---------- misc layout ---------- */
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1080px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .app { grid-template-columns: 60px minmax(0, 1fr); }
  .sidebar .sb-module, .sidebar .sb-org, .sidebar .sb-group, .sidebar .nav-label, .sidebar .sb-foot-info { display: none; }
  .sb-wordmark { font-size: 12px; }
  .page { padding: 18px 16px 60px; }
  .grid-2 { grid-template-columns: 1fr; }
}

.hbar-row { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; }
.hbar-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; }

.src-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.src-row:last-child { border-bottom: none; }
.src-domain { font-family: var(--font-mono); font-size: 12px; font-weight: 500; }
.src-url { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.progressbar { height: 6px; background: var(--surface-3); position: relative; width: 90px; }
.progressbar > i { position: absolute; inset: 0 auto 0 0; background: var(--blue); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border-strong); margin-bottom: 16px; }
.tab { padding: 8px 14px; font-size: 12.5px; font-weight: 500; color: var(--text-3); cursor: pointer; border: 1px solid transparent; border-bottom: none; margin-bottom: -1px; transition: color var(--dur-1) var(--ease); }
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); background: var(--surface); border-color: var(--border-strong); }
