/* ============================================================================
   newsARTEX workbench — ported from the ARTEX reference UI framework.
   Design tokens mirror ARTEX's shadcn-style theme (grayscale primary, muted
   surfaces, 0.75rem radius, soft shadows) with light/dark modes. Layout is the
   ARTEX shell: sidebar + content inset + sticky topbar + cards.
   All legacy .wb-* selectors used by workbench.js are aliased to these tokens.
   ========================================================================== */

:root {
  --topbar-height: 52px;
  --radius: 0.75rem;
  --background: #f4f5f7;
  --foreground: #18181b;
  --card: #ffffff;
  --card-foreground: #18181b;
  --muted: #f4f4f5;
  --muted-foreground: #71717a;
  --secondary: #f4f4f5;
  --secondary-foreground: #27272a;
  --primary: #18181b;
  --primary-foreground: #fafafa;
  --accent: #f4f4f5;
  --accent-foreground: #18181b;
  --border: #e4e4e7;
  --input: #e4e4e7;
  --ring: #a1a1aa;
  --sidebar: #fbfbfb;
  --sidebar-foreground: #3f3f46;
  --sidebar-accent: #ececee;
  --sidebar-border: #ececee;
  --destructive: #dc2626;
  --success: #16a34a;
  --warning: #b45309;
  --info: #2563eb;
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, .06);
  --shadow: 0 1px 3px rgba(24, 24, 27, .08), 0 1px 2px rgba(24, 24, 27, .04);
  --shadow-lg: 0 20px 50px rgba(9, 9, 11, .18);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --background: #111113;
  --foreground: #fafafa;
  --card: #17171a;
  --card-foreground: #fafafa;
  --muted: #26262a;
  --muted-foreground: #a1a1aa;
  --secondary: #26262a;
  --secondary-foreground: #fafafa;
  --primary: #fafafa;
  --primary-foreground: #18181b;
  --accent: #26262a;
  --accent-foreground: #fafafa;
  --border: #2a2a2f;
  --input: #2a2a2f;
  --ring: #52525b;
  --sidebar: #141416;
  --sidebar-foreground: #d4d4d8;
  --sidebar-accent: #26262a;
  --sidebar-border: #26262a;
  --destructive: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --info: #60a5fa;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 3px rgba(0, 0, 0, .5);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: no-preference) {
  html, .inset { scroll-behavior: smooth; }
}

body.app {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--foreground);
  background: var(--background);
  display: flex;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.skip-link { position: absolute; left: -9999px; top: 0; }
.skip-link:focus { left: 12px; top: 12px; z-index: 100; background: var(--card); padding: 8px 12px; border: 1px solid var(--ring); border-radius: 8px; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 264px;
  flex: 0 0 264px;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
}
body.sidebar-collapsed .sidebar { display: none; }

.sidebar-head { padding: 12px 12px 4px; }
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 10px; text-decoration: none; color: inherit;
}
.brand:hover { background: var(--sidebar-accent); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 34px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #18181b, #3f3f46);
}
html[data-theme="dark"] .brand-mark { background: linear-gradient(135deg, #fafafa, #a1a1aa); color: #18181b; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .01em; }

.sidebar-body { padding: 6px 10px 12px; }
.nav-group { margin: 10px 0; }
.nav-label {
  font-size: 11px; color: var(--muted-foreground);
  padding: 6px 10px 4px; letter-spacing: .02em;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; min-height: 34px; padding: 0 10px; border-radius: 8px;
  border: 0; background: transparent; cursor: pointer; text-align: left;
  color: var(--sidebar-foreground); text-decoration: none;
  font: inherit; font-size: 13.5px; line-height: 1.3;
}
.nav-item svg { width: 16px; height: 16px; flex: 0 0 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
.nav-item:hover { background: var(--sidebar-accent); color: var(--foreground); }
.nav-item[aria-current="location"] { background: var(--sidebar-accent); color: var(--foreground); font-weight: 600; }

.queue-actions { padding: 2px 4px 6px; }
.btn-block { width: 100%; justify-content: center; }
.queue-search { padding: 2px 4px 6px; }
.queue-search input {
  width: 100%; height: 32px; padding: 0 10px; font: inherit; font-size: 12.5px;
  color: var(--foreground); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px;
}
.queue-search input:focus { outline: 2px solid var(--ring); outline-offset: -1px; }
.queue-list { list-style: none; margin: 2px 0 0; padding: 0; display: grid; gap: 2px; }
.wb-queue-item {
  width: 100%; text-align: left; cursor: pointer;
  border: 1px solid transparent; background: transparent;
  border-radius: 8px; padding: 7px 10px;
  font: inherit; font-size: 13px; line-height: 1.35; color: var(--sidebar-foreground);
}
.wb-queue-item:hover { background: var(--sidebar-accent); }
.wb-queue-item[aria-current="true"] { background: var(--sidebar-accent); color: var(--foreground); font-weight: 600; }
.wb-queue-item small { display: block; margin-top: 2px; font-size: 11px; font-weight: 400; color: var(--muted-foreground); }

.sidebar-foot {
  border-top: 1px solid var(--sidebar-border);
  padding: 10px 12px; display: grid; gap: 8px;
}
.actor-field { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted-foreground); }
.actor-field input {
  flex: 1; min-width: 0; height: 30px; padding: 0 9px; font: inherit; font-size: 12.5px;
  color: var(--foreground); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px;
}
.foot-row { display: flex; align-items: center; gap: 8px; }
.foot-row .icon-btn { flex: none; }
.foot-row .chip { line-height: 1.35; }

/* ---------- inset + topbar + main ---------- */
.inset { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-height); flex: 0 0 var(--topbar-height);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 18px; border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--background) 82%, var(--card));
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(8px);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-title { font-size: 13.5px; font-weight: 600; }

.main {
  width: 100%; max-width: 1440px; margin: 0 auto;
  padding: 20px; display: flex; flex-direction: column; gap: 14px;
}
.main, .card-head h3[id] { scroll-margin-top: calc(var(--topbar-height) + 24px); }

/* ---------- page head ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-title { min-width: 0; }
.page-head h1 { margin: 0 0 4px; font-size: 22px; font-weight: 650; letter-spacing: -.01em; line-height: 1.3; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.muted { color: var(--muted-foreground); font-size: 12.5px; margin: 0; line-height: 1.6; }
.status { font-size: 12.5px; color: var(--muted-foreground); min-height: 16px; margin: 0; }
.status[data-tone="warn"] { color: var(--warning); }
.status[data-tone="error"] { color: var(--destructive); }
.main > .status:empty { display: none; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: 13px; height: 34px; padding: 0 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--card); color: var(--foreground); cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease, opacity .12s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover:not(:disabled) { background: var(--primary); opacity: .9; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--muted); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn-danger { background: var(--destructive); border-color: var(--destructive); color: #fff; }
.icon-btn {
  width: 32px; height: 32px; padding: 0; display: grid; place-items: center;
  border-radius: 8px; border: 1px solid transparent; background: transparent;
  color: var(--muted-foreground); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: var(--muted); color: var(--foreground); }
.wb-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.card-body { padding: 14px 16px; }

/* ---------- research progress ---------- */
#wbResearchDeferred[hidden] { display: none; }
.run-progress { display: grid; gap: 10px; }
.run-status { margin: 0; font-size: 17px; font-weight: 650; line-height: 1.45; }
.run-status[data-tone="warn"] { color: var(--warning); }
.run-status[data-tone="error"] { color: var(--destructive); }
.run-work:not([hidden]) {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 8px;
}
.run-workitem {
  position: relative; display: flex; flex-direction: column; gap: 3px; min-width: 0;
  padding: 9px 30px 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--foreground); text-decoration: none; line-height: 1.5;
}
.run-workitem strong { font-size: 13.5px; font-weight: 600; }
.run-workitem-meta { color: var(--muted-foreground); font-size: 12.5px; }
.run-workitem-warning { color: var(--warning); font-size: 12.5px; }
.run-workitem::after {
  content: ''; position: absolute; top: 17px; right: 12px; width: 6px; height: 6px;
  border-top: 1.5px solid currentColor; border-right: 1.5px solid currentColor; transform: rotate(45deg);
}
.run-workitem[data-priority="primary"] { background: var(--muted); }
.run-workitem:hover, .run-workitem:focus-visible { border-color: var(--ring); }
.run-workitem[data-priority="blocking"] {
  background: color-mix(in oklab, var(--warning) 8%, var(--card));
  border-color: color-mix(in oklab, var(--warning) 50%, var(--border));
}
.run-workitem[data-priority="blocking"]::after { color: var(--warning); }
.run-workitem[data-priority="blocking"]:is(:hover, :focus-visible) { border-color: var(--warning); }
.run-details { border-top: 1px solid var(--border); padding-top: 10px; }
.run-details summary { cursor: pointer; color: var(--muted-foreground); font-size: 12.5px; }
.run-details > :not(summary):not(:empty) { margin-top: 7px; }
.run-details > :empty { display: none; }
.run-metrics { display: flex; flex-wrap: wrap; gap: 4px 14px; }

/* ---------- chips / badges ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.wb-badge, .chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; line-height: 1; padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--muted); color: var(--muted-foreground);
}
.wb-badge { margin-right: 6px; }
.chip-row .wb-badge { margin-right: 0; }
.wb-badge[data-ok="true"] { border-color: color-mix(in oklab, var(--success) 40%, white); background: color-mix(in oklab, var(--success) 12%, white); color: var(--success); }
.wb-badge[data-tone="warn"] { border-color: color-mix(in oklab, var(--warning) 40%, white); background: color-mix(in oklab, var(--warning) 12%, white); color: var(--warning); }
.chip[data-tone="warn"] { border-color: color-mix(in oklab, var(--warning) 45%, white); background: color-mix(in oklab, var(--warning) 14%, white); color: var(--warning); }
.chip[data-tone="error"] { border-color: color-mix(in oklab, var(--destructive) 45%, white); background: color-mix(in oklab, var(--destructive) 12%, white); color: var(--destructive); }
html[data-theme="dark"] .wb-badge[data-ok="true"],
html[data-theme="dark"] .wb-badge[data-tone="warn"],
html[data-theme="dark"] .chip[data-tone="warn"],
html[data-theme="dark"] .chip[data-tone="error"] { background: var(--muted); }

/* ---------- claims / evidence ---------- */
.claims { display: grid; gap: 12px; }
.wb-claim { min-width: 0; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--card); }
.wb-claim[data-kind="nonfactual"] { background: color-mix(in oklab, var(--muted) 60%, var(--card)); }
.wb-claim h4 { margin: 0 0 8px; font-size: 14px; font-weight: 650; line-height: 1.5; overflow-wrap: anywhere; }
.wb-chip-row { display: flex; flex-wrap: wrap; gap: 5px; margin: 0 0 8px; }
.wb-chip-row .wb-badge { margin-right: 0; }
.wb-judgment, .wb-editorial-preview { margin: 8px 0; padding: 9px 11px; background: var(--muted); border-radius: 8px; font-size: 13px; line-height: 1.65; }
.wb-judgment p, .wb-editorial-preview p { margin: 0; }
.wb-judgment p + p, .wb-editorial-preview p + p { margin-top: 4px; }
.wb-judgment strong, .wb-editorial-preview strong { font-weight: 600; }
.wb-claim > .wb-toolbar-actions, .wb-gap > .wb-toolbar-actions { margin: 8px 0 0; }
.wb-details { border-top: 1px solid var(--border); padding: 8px 0; }
.wb-details summary { cursor: pointer; color: var(--sidebar-foreground); font-size: 12.5px; line-height: 1.5; }
.wb-details summary:hover { color: var(--info); }
.wb-detail-body { padding: 7px 2px 0; font-size: 12.5px; line-height: 1.7; overflow-wrap: anywhere; }
.wb-detail-body p { margin: 0 0 6px; }
.wb-detail-body p, .wb-detail-body li, .wb-evidence blockquote { max-inline-size: 110ch; }
.wb-detail-body h5 { font-size: 12.5px; margin: 8px 0 4px; }
.wb-detail-body ul { padding-left: 18px; margin: 4px 0 8px; }
.wb-detail-body .wb-lines, .wb-detail-entry p { white-space: pre-line; }
.wb-detail-entry + .wb-detail-entry, .wb-challenge + .wb-challenge, .wb-evidence + .wb-evidence {
  border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px;
}
.wb-evidence blockquote { margin: 8px 0; padding: 2px 0 2px 10px; border-left: 2px solid var(--border); }
.wb-evidence a, .wb-graph-table a { color: var(--info); overflow-wrap: anywhere; }
.wb-evidence .wb-meta { color: var(--muted-foreground); margin-top: 4px; }

/* ---------- gaps ---------- */
.gaps { display: grid; gap: 10px; max-height: 46vh; overflow: auto; }
.wb-gap { border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; font-size: 13px; background: var(--card); }
.wb-gap[data-status="open"] { border-left: 3px solid var(--warning); }
.wb-gap[data-status="resolved"], .wb-gap[data-status="accepted_limitation"] { opacity: .82; }
.wb-gap p { margin: 0 0 6px; line-height: 1.6; }
.wb-gap-question { font-weight: 600; }

/* ---------- manuscript / events / editorial / table / diff ---------- */
.manuscript { font-size: 14px; line-height: 1.9; max-height: 62vh; overflow: auto; white-space: pre-wrap; }
.manuscript p { margin: 0 0 10px; }
.manuscript p:last-child { margin-bottom: 0; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 12.5px; color: var(--muted-foreground); }
.events > li:not(.wb-more-events) { display: flex; flex-wrap: wrap; gap: 3px 10px; padding: 7px 10px; background: var(--muted); border-radius: 8px; line-height: 1.5; }
.events > li > strong { font-weight: 600; color: var(--foreground); }
.editorial { font-size: 13px; line-height: 1.7; }
.editorial h4 { margin: 10px 0 4px; font-size: 12px; color: var(--muted-foreground); }
.editorial ul { margin: 0 0 8px; padding-left: 18px; }
.editorial-toolbar { display: flex; align-items: start; flex-wrap: wrap; gap: 12px 20px; margin-bottom: 12px; }
.editorial-toolbar .card-actions { justify-content: flex-start; }
.editorial-toolbar .card-actions[hidden] { display: none; }
.editorial-status { margin: 8px 0; }
.editorial-status:empty { display: none; }
#wbEditorialHint a, .info-dialog a { color: var(--info); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button {
  height: 30px; padding: 0 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--card);
  font: inherit; font-size: 12.5px; color: var(--muted-foreground);
}
.tabs button[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.toolbar-inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.wb-field { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted-foreground); }
.wb-field select, .wb-field input {
  height: 30px; padding: 0 9px; font: inherit; font-size: 12.5px;
  color: var(--foreground); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px;
}
.diff-result { font-size: 12.5px; color: var(--foreground); line-height: 1.7; }
.diff-result ins { background: color-mix(in oklab, var(--success) 18%, transparent); text-decoration: none; }
.diff-result del { background: color-mix(in oklab, var(--destructive) 16%, transparent); text-decoration: line-through; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
.table caption { text-align: left; color: var(--muted-foreground); padding-bottom: 8px; font-size: 11.5px; }
.table th, .table td { border-bottom: 1px solid var(--border); text-align: left; padding: 9px 8px; vertical-align: top; }
.table th { color: var(--muted-foreground); font-weight: 600; font-size: 11.5px; }
.table tbody tr:hover { background: var(--muted); }
.wb-graph-table { max-height: 50vh; overflow: auto; overflow-wrap: anywhere; }
.wb-graph-table th:first-child { min-width: 6em; }

.empty { font-size: 12.5px; color: var(--muted-foreground); padding: 6px 2px; line-height: 1.6; }
.wb-err { color: var(--destructive); font-size: 12px; margin-top: 6px; }

/* ---------- dialog ---------- */
.wb-dialog {
  border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; width: min(580px, 92vw);
  background: var(--card); color: var(--foreground);
  box-shadow: var(--shadow-lg);
}
.wb-dialog::backdrop { background: rgba(9, 9, 11, .45); backdrop-filter: blur(2px); }
.wb-dialog h2 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.wb-dialog label { display: block; font-size: 12px; color: var(--muted-foreground); margin: 10px 0 4px; }
.wb-dialog input, .wb-dialog select, .wb-dialog textarea {
  width: 100%; padding: 8px 10px; font: inherit; font-size: 13px;
  color: var(--foreground); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px;
}
.wb-dialog textarea { min-height: 96px; resize: vertical; }
.wb-dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 18px 0 0; }
.info-dialog { max-height: calc(100dvh - 32px); line-height: 1.65; }
.info-dialog h2 { font-size: 17px; }
.info-dialog ol { padding-left: 1.5em; }
.info-dialog li + li { margin-top: 7px; }
.info-dialog p { margin: 12px 0 0; }

/* ---------- responsive ---------- */
@media (width > 820px) {
  body.app { height: 100dvh; overflow: hidden; }
  .sidebar, .inset { overflow-y: auto; overscroll-behavior-y: contain; }
  .sidebar > * { flex-shrink: 0; }
  .inset { display: block; }
}
@media (max-width: 1080px) {
  .main { padding: 16px; }
}
@media (max-width: 820px) {
  body.app { flex-direction: column; }
  .inset { display: contents; }
  .topbar { order: -1; }
  .sidebar { width: 100%; flex: none; border-right: 0; border-bottom: 1px solid var(--sidebar-border); }
  .page-actions { justify-content: flex-start; }
}
