/* CXP Archive — UI. Palette, typography and radii come from CONEK's design
 * system via conek-tokens.css (vendored from @a-safe-digital/conek-ui). */
:root {
  --ink: hsl(var(--foreground));
  --ink-2: hsl(var(--foreground-medium));
  --muted: hsl(var(--foreground-light));
  --line: hsl(var(--border));
  --line-2: hsl(var(--card-secondary));
  --bg: hsl(var(--background));
  --panel: hsl(var(--card));
  --accent: hsl(var(--primary));
  --accent-strong: hsl(var(--primary-700));
  --accent-soft: hsl(var(--primary-50));
  --link: hsl(var(--primary-700));
  --shadow: 0 1px 2px hsl(var(--foreground) / .05);
  --shadow-lg: 0 8px 24px hsl(var(--foreground) / .08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.55 "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 26px; height: 26px; }
.brand-mark path { stroke: hsl(var(--primary)); stroke-width: 2; fill: none; }
.brand-mark.big { width: 42px; height: 42px; margin-bottom: 8px; }
.brand-text strong { display: block; font-size: 15.5px; letter-spacing: -.01em; }
.brand-text span { display: block; font-size: 12px; color: var(--muted); margin-top: -2px; }
.user-box { display: flex; gap: 12px; align-items: center; }
.avatar { color: var(--ink-2); font-size: 13.5px; }

/* ---------------- layout ---------------- */
main { max-width: 1560px; margin: 0 auto; padding: 18px 22px 70px; }

/* ---------------- toolbar ---------------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.search-wrap { position: relative; flex: 1; max-width: 640px; }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2;
}
.toolbar input[type="search"] {
  width: 100%; padding: 10px 14px 10px 36px; font-size: 14.5px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  box-shadow: var(--shadow); outline: none;
}
.toolbar input[type="search"]:focus { border-color: hsl(var(--focus)); box-shadow: 0 0 0 3px hsl(var(--primary-100)); }
.toolbar select {
  padding: 9px 12px; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow);
}
.chk { display: flex; gap: 7px; align-items: center; color: var(--ink-2); white-space: nowrap; cursor: pointer; user-select: none; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; }

.results-meta { margin: 2px 2px 10px; color: var(--muted); font-size: 13px; }

/* ---------------- results table ---------------- */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table.results { width: 100%; border-collapse: collapse; }
table.results th, table.results td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--line-2); }
table.results th {
  position: sticky; top: 0;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); background: hsl(var(--card-secondary)); border-bottom: 1px solid var(--line);
}
table.results tbody tr { cursor: pointer; transition: background .1s; }
table.results tbody tr:hover { background: hsl(var(--primary-50)); }
table.results tbody tr:last-child td { border-bottom: none; }
.client-cell { font-weight: 600; }
.sub-chip {
  display: inline-block; padding: 1px 9px; font-size: 11.5px; border-radius: 999px;
  background: hsl(var(--accent)); color: var(--ink-2); white-space: nowrap;
}
.row-arrow { color: var(--line); float: right; font-weight: 600; }
table.results tbody tr:hover .row-arrow { color: var(--accent); }
.empty { padding: 46px 20px; text-align: center; }

/* ---------------- detail ---------------- */
.detail-top { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.crumb { font-size: 13px; }
.crumb-link { color: var(--link); text-decoration: none; }
.crumb-link:hover { text-decoration: underline; }

.pager { display: flex; align-items: center; gap: 6px; }
.pager .btn:disabled { opacity: .35; cursor: default; }

mark { background: hsl(var(--warning) / .3); border-radius: 3px; padding: 0 1px; }

.canvas-actions { display: flex; gap: 8px; align-items: center; }

/* comments */
.comment { padding: 8px 0; border-bottom: 1px solid var(--line-2); }
.comment:last-child { border-bottom: none; }
.comment-meta { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.comment-meta .ref { margin-left: auto; color: var(--line); }
.comment-text { margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }

.detail-grid {
  display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 16px; align-items: start;
}
@media (max-width: 1100px) { .detail-grid { grid-template-columns: 1fr; } }

.side {
  position: sticky; top: 66px;
  max-height: calc(100vh - 84px);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.side-scroll { max-height: calc(100vh - 104px); overflow-y: auto; padding: 18px 18px 14px; }
.detail-title { margin: 0 0 12px; font-size: 19px; letter-spacing: -.01em; }

dl.meta { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; margin: 0 0 6px; }
dl.meta dt { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
dl.meta dd { margin: 0; font-size: 13.5px; min-width: 0; overflow-wrap: anywhere; }
.note, .warnings { margin: 8px 0 0; }
.warnings { color: hsl(var(--warning)); filter: brightness(.75); }

.tabs { display: flex; gap: 4px; margin: 16px 0 10px; border-bottom: 1px solid var(--line); }
.tab {
  padding: 7px 12px 9px; margin-bottom: -1px;
  font: inherit; font-weight: 500; color: var(--muted);
  background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: hsl(var(--primary)); }
.tab .count {
  display: inline-block; margin-left: 5px; padding: 0 7px; font-size: 11px; border-radius: 999px;
  background: hsl(var(--accent)); color: var(--ink-2);
}

.tabpanel { overflow-x: auto; }

/* parts table */
table.parts { width: 100%; border-collapse: collapse; }
table.parts th, table.parts td { padding: 5px 8px; border-bottom: 1px solid var(--line-2); vertical-align: top; font-size: 13px; }
table.parts th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
table.parts .num { text-align: right; white-space: nowrap; }
table.parts td:first-child, table.parts td:first-child .mono { white-space: nowrap; }
table.parts td:nth-child(4) { white-space: nowrap; }
table.parts.nested { margin: 5px 0 3px 10px; background: hsl(var(--primary-50) / .5); border-left: 2px solid hsl(var(--primary-100)); border-radius: 4px; }
table.parts.nested td { color: var(--ink-2); font-size: 12.5px; }
.kit-tag {
  display: inline-block; margin-left: 6px; padding: 1px 8px; font-size: 11px; font-weight: 500;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.kit-summary { margin: 0 0 8px; }

/* fact files */
details.fact { border-bottom: 1px solid var(--line-2); padding: 6px 0; }
details.fact summary { cursor: pointer; color: var(--ink-2); }
details.fact pre {
  background: var(--line-2); padding: 10px; border-radius: var(--radius);
  overflow: auto; max-height: 320px; margin: 8px 0 2px;
}

/* ---------------- canvas ---------------- */
.canvas-col { min-width: 0; }
.canvas-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; margin-bottom: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.canvas-hint { font-size: 12.5px; }

.viewer-box {
  position: relative;
  background: hsl(var(--card));
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; height: calc(100vh - 170px); min-height: 420px;
}
.viewer-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }

/* ---------------- buttons ---------------- */
.btn {
  padding: 8px 14px; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  cursor: pointer; box-shadow: var(--shadow);
}
.btn:hover { background: hsl(var(--card-secondary)); }
.btn.icon { min-width: 34px; padding: 8px 10px; font-weight: 600; line-height: 1; }
.btn.icon.wide { min-width: 0; font-size: 12.5px; }
.btn.primary { background: hsl(var(--primary)); border-color: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn.primary:hover { background: hsl(var(--primary-600)); }
.btn.ghost { border: none; background: none; box-shadow: none; color: var(--muted); text-decoration: underline; padding: 4px 6px; }

/* ---------------- login ---------------- */
.login-view { display: flex; justify-content: center; align-items: center; min-height: 78vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 40px 52px; text-align: center; box-shadow: var(--shadow-lg);
}
.login-card h2 { margin: 4px 0 8px; letter-spacing: -.01em; }
.login-card .btn { margin-top: 20px; }
.error { color: hsl(var(--danger)); margin-top: 14px; }

/* ---------------- loading ---------------- */
.loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; gap: 14px;
  justify-content: center; align-items: center; background: hsl(var(--background) / .85);
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid hsl(var(--border)); border-top-color: hsl(var(--primary));
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* keep date + numeric cells on one line */
table.results td:nth-child(7) { white-space: nowrap; }
