/* packages/web/styles.css */

:root {
  /* dark (default) */
  --bg: oklch(0.165 0.006 271);
  --surface: oklch(0.205 0.007 271);
  --surface-2: oklch(0.235 0.008 271);
  --border: oklch(0.30 0.010 271);
  --border-strong: oklch(0.40 0.012 271);
  --ink: oklch(0.93 0.004 271);
  --muted: oklch(0.70 0.006 271);
  --accent: oklch(0.67 0.145 291);
  --accent-ink: oklch(0.985 0 0);
  --err: oklch(0.70 0.185 25);
  --warn: oklch(0.82 0.135 78);
  --ok: oklch(0.78 0.14 158);
  --add-bg: oklch(0.30 0.05 158);
  --del-bg: oklch(0.32 0.07 20);
  --hi: oklch(0.42 0.09 291);
  --minor: oklch(0.72 0.10 80);

  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;

  --r: 6px;
  --r-sm: 4px;
  --z-sticky: 10;
  --z-toast: 40;
  --z-tooltip: 50;

  --transition: 150ms ease;
}

:root[data-theme="light"] {
  color-scheme: light;
  --minor: oklch(0.55 0.10 80);
  --bg: oklch(0.995 0.001 271);
  --surface: oklch(0.975 0.003 271);
  --surface-2: oklch(0.955 0.004 271);
  --border: oklch(0.90 0.006 271);
  --border-strong: oklch(0.82 0.008 271);
  --ink: oklch(0.26 0.010 271);
  --muted: oklch(0.47 0.012 271);
  --accent: oklch(0.52 0.16 291);
  --accent-ink: oklch(0.99 0 0);
  --err: oklch(0.53 0.20 27);
  --warn: oklch(0.62 0.13 70);
  --ok: oklch(0.52 0.14 158);
  --add-bg: oklch(0.93 0.05 158);
  --del-bg: oklch(0.93 0.05 22);
  --hi: oklch(0.90 0.06 291);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --minor: oklch(0.55 0.10 80);
    --bg: oklch(0.995 0.001 271);
    --surface: oklch(0.975 0.003 271);
    --surface-2: oklch(0.955 0.004 271);
    --border: oklch(0.90 0.006 271);
    --border-strong: oklch(0.82 0.008 271);
    --ink: oklch(0.26 0.010 271);
    --muted: oklch(0.47 0.012 271);
    --accent: oklch(0.52 0.16 291);
    --accent-ink: oklch(0.99 0 0);
    --err: oklch(0.53 0.20 27);
    --warn: oklch(0.62 0.13 70);
    --ok: oklch(0.52 0.14 158);
    --add-bg: oklch(0.93 0.05 158);
    --del-bg: oklch(0.93 0.05 22);
    --hi: oklch(0.90 0.06 291);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 13px/1.5 var(--sans);
  background: var(--bg);
  color: var(--ink);
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 48px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.logo { font: 600 18px/1 var(--mono); text-wrap: balance; }
.tagline { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-glyph { flex: none; align-self: center; }
.brand-glyph .bar { fill: var(--ink); }
.brand-glyph .bar.accent { fill: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex: none; }
.file-count { color: var(--muted); font-size: 12px; }

/* ---------- Icon / ghost / buttons ---------- */

button { font: inherit; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--r);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

.icon-btn.ghost {
  background: transparent;
  border-color: transparent;
}
.icon-btn.ghost:hover { color: var(--err); border-color: var(--border); background: var(--surface-2); }

button:disabled,
.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary,
.btn-secondary {
  height: 30px;
  padding: 0 12px;
  border-radius: var(--r);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--border-strong); }

input[type="checkbox"] { accent-color: var(--accent); }

input[type="text"],
textarea {
  padding: 4px 8px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font: inherit;
  transition: border-color var(--transition);
}
input[type="text"] { height: 28px; }
input[type="text"]:hover,
textarea:hover { border-color: var(--border-strong); }

/* ---------- App shell ---------- */

#app {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Dropzone ---------- */

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--muted);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.dropzone:hover,
.dropzone.over {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--surface-2);
}
.file-input { display: none; }

.empty-hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

/* ---------- Main grid ---------- */

.grid {
  display: grid;
  grid-template-columns: minmax(300px, 340px) 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 820px) {
  .grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px;
  min-width: 0;
}

/* ---------- Files table ---------- */

table.files {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
table.files th {
  text-align: left;
  color: var(--muted);
  font-weight: normal;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
}
table.files th.fx,
table.files td.fx,
table.files th.del,
table.files td.del {
  width: 1px;
  white-space: nowrap;
  text-align: center;
  padding: 6px 8px;
}
/* State shrinks to its pill so the name column gets the space. */
table.files th.state,
table.files td.state {
  width: 1px;
  white-space: nowrap;
  text-align: right;
  padding: 6px 8px;
}
/* Name takes all remaining width and ellipsizes only when truly too long. */
table.files td.name {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
table.files td {
  padding: 6px 8px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
tr.file-row { cursor: default; transition: background var(--transition); }
tr.file-row:hover { background: var(--surface-2); }
tr.file-row.selected { background: var(--surface-2); }
tr.file-row.selected td.fx {
  box-shadow: inset 2px 0 0 var(--accent);
}
td.name {
  font-family: var(--mono);
  cursor: pointer;
  max-width: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td.name:hover { text-decoration: underline; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  border-radius: var(--r-sm);
  padding: 1px 6px;
}
.pill-clean { color: var(--ok); }
.pill-warnings { color: var(--warn); }
.pill-errors { color: var(--err); }

/* ---------- Batch action row ---------- */

.batch-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
}
.batch-count { color: var(--muted); font-size: 12px; margin-left: auto; }

/* ---------- Detail toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.options-pane {
  display: inline-flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-left: auto; padding: 5px 12px;
  border: 1px solid var(--border); border-radius: var(--r); background: var(--surface);
}
.options-pane label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; white-space: nowrap; cursor: pointer; }
.opt-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--surface); color: var(--muted); padding: 4px 10px; font-size: 12.5px; cursor: pointer; transition: background var(--transition), color var(--transition); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:focus-visible { outline-offset: -2px; } /* .seg clips overflow; keep the ring inside */
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.seg button:not(.active):hover { background: var(--surface-2); color: var(--ink); }

/* ---------- Workbench: findings + source ---------- */

.workbench {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}

table.findings {
  min-width: 0;
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
table.findings th {
  text-align: left;
  color: var(--muted);
  font-weight: normal;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
}
table.findings th.fx,
table.findings td.fx { width: 1px; white-space: nowrap; text-align: center; padding: 6px 8px; }
table.findings td { padding: 6px 8px; vertical-align: top; border-bottom: 1px solid var(--border); }
table.findings tbody tr:hover { background: var(--surface-2); }
table.findings tr.diag-error .diag-meta { color: var(--err); }
table.findings tr.diag-warning .diag-meta { color: var(--warn); }
table.findings tr.diag-info .diag-meta { color: var(--muted); }
.diag-text {
  cursor: pointer;
  color: var(--ink);
  font-family: var(--sans);
}
.diag-meta { font-family: var(--mono); font-weight: 600; white-space: nowrap; margin-right: 6px; }
.diag-msg { color: var(--ink); }
.diag-text:hover .diag-msg { text-decoration: underline; }
.diff-empty { color: var(--muted); padding: 8px; }

/* ---------- Source view ---------- */

.source-view {
  min-width: 0;
  max-height: 440px;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.45;
}
.src-line { display: flex; white-space: pre; }
.src-line .ln {
  color: var(--muted);
  text-align: right;
  min-width: 3ch;
  padding: 0 8px;
  user-select: none;
  border-right: 1px solid var(--border);
}
.src-line .lc { padding: 0 8px; white-space: pre-wrap; word-break: break-all; }
.src-line.highlight { background: var(--hi); }
.src-line.highlight .ln { box-shadow: inset 2px 0 0 var(--accent); }

/* ---------- Record diff ---------- */

table.record-diff {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-top: 16px;
  font-family: var(--mono);
  font-size: 12.5px;
}
table.record-diff td {
  width: 50%;
  vertical-align: top;
  white-space: pre-wrap;
  word-break: break-all;
  padding: 2px 8px;
  border-left: 1px solid var(--border);
}
table.record-diff td:first-child { border-left: none; }
.record-diff .diff-block-header td {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 8px 2px;
  border-left: none;
  border-top: 1px solid var(--border);
}
.record-diff tr.rec-modified .left,
.record-diff tr.rec-removed .left { background: var(--del-bg); }
.record-diff tr.rec-modified .right,
.record-diff tr.rec-added .right { background: var(--add-bg); }
.record-diff tr.rec-unchanged td { color: var(--muted); }

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Validate view */
.top-nav { display: flex; align-items: center; }
.validate-panel { display: flex; flex-direction: column; gap: 12px; }
.list-editor-head { font-weight: 600; margin-bottom: 4px; }
.list-rows { display: flex; flex-direction: column; gap: 6px; }
.list-row { display: flex; gap: 6px; align-items: center; }
.list-input { flex: 1; }
.resolver-note { font-size: 12px; color: var(--muted); margin: 0; }
.validate-banner { padding: 8px 12px; border-radius: var(--r); font-weight: 600; }
.validate-banner.pass { background: color-mix(in oklab, var(--ok) 15%, transparent); color: var(--ok); }
.validate-banner.fail { background: color-mix(in oklab, var(--err) 15%, transparent); color: var(--err); }
.validate-error { color: var(--err); font-family: var(--mono); white-space: pre-wrap; }
.authority-summary { display: flex; flex-direction: column; gap: 2px; font-size: 12px; }
.authority-line.pass { color: var(--ok); }
.authority-line.fail { color: var(--err); }
.ns-by-target { color: var(--muted); font-family: var(--mono); }
.authority-detail { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.validate-records { width: 100%; border-collapse: collapse; }
.validate-records th, .validate-records td { padding: 4px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.validate-records td.verdict { font-weight: 600; }
.validate-records td.expected { font-family: var(--mono); color: var(--muted); }
.v-match { color: var(--ok); }
.v-mismatch, .v-diverged, .v-unexpected { color: var(--err); }
.v-minor { color: var(--minor); } /* muted amber — non-failing cosmetic (trailing-dot) difference */
.v-missing, .v-extra { color: var(--warn); }
.v-ignored { color: var(--muted); }
.scoped-editor { display: flex; flex-direction: column; gap: 6px; }
.scoped-editor-bar { display: flex; align-items: center; gap: 8px; }
.scope-toggle { font-size: 12px; }
.override-badge { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--warn); }
.btn-secondary.reset-override { height: 24px; font-size: 12px; padding: 0 8px; }
.scope-note { font-size: 12px; color: var(--muted); margin: 0; }
.stale-note { color: var(--warn); font-size: 12px; align-self: center; }
.build-panel { display: flex; flex-direction: column; gap: 12px; }
.build-origin-row { display: flex; gap: 8px; }
.build-origin { flex: 1; }
.build-discovery { display: flex; gap: 8px; flex-wrap: wrap; }
.build-custom-wrap { display: flex; flex-direction: column; gap: 6px; }
.build-custom { min-height: 3em; }
.build-key { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.build-status { font-size: 12px; color: var(--muted); margin: 0; }
.build-count { align-self: center; color: var(--muted); font-size: 12px; }

/* ---------- Export split-button ---------- */

.export-menu { position: relative; display: inline-flex; }
.export-menu .split-main { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.export-menu .split-caret {
  border-top-left-radius: 0; border-bottom-left-radius: 0;
  border-left: 1px solid var(--border-strong);
  padding-left: 8px; padding-right: 8px;
}
.export-menu-list {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  display: flex; flex-direction: column; min-width: 200px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
.export-menu-list[hidden] { display: none; }
.export-menu-item {
  border: 0; background: transparent; color: var(--ink);
  text-align: left; padding: 6px 10px; border-radius: var(--r-sm);
  font-size: 12.5px; cursor: pointer; white-space: nowrap;
  transition: background var(--transition);
}
.export-menu-item:hover { background: var(--surface-2); }

/* ---------- Manual edit mode ---------- */

.source-pane { flex: 1 1 360px; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.findings-area { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.pane-header { display: flex; align-items: center; justify-content: space-between; }
.pane-title { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.source-editor { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.edit-area {
  width: 100%; min-height: 320px; resize: vertical; box-sizing: border-box;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border-strong); border-radius: var(--r);
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 12.5px; line-height: 1.45;
}
.edit-actions { display: flex; align-items: center; gap: 8px; }
.edit-status { color: var(--muted); font-size: 12px; margin-left: auto; }
.edit-status.has-errors { color: var(--err); }
.manual-badge {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font-size: 12.5px;
}
