/* ===========================================================================
   Design tokens
   One place for colour, spacing, radius, elevation and motion, so a change
   here moves every page together instead of one page drifting from the rest.
   =========================================================================== */
:root {
  --bg: #f4f6fa; --panel: #ffffff; --ink: #16202e; --muted: #64748b;
  --accent: #2563eb; --accent-ink: #1e40af; --accent-soft: #eff4ff;
  --line: #e3e8f0; --line-strong: #cbd5e1;
  --c-person: #2563eb; --c-organization: #7c3aed; --c-place: #059669;
  --c-event: #d97706; --c-action: #dc2626; --c-task: #0891b2;
  --c-milestone: #be185d; --c-date: #4b5563; --c-other: #64748b;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-pill: 999px;
  --sp-1: 0.35rem; --sp-2: 0.6rem; --sp-3: 1rem; --sp-4: 1.5rem; --sp-5: 2.2rem;
  --shadow-1: 0 1px 2px rgba(16, 32, 60, 0.05);
  --shadow-2: 0 4px 14px rgba(16, 32, 60, 0.08);
  --shadow-3: 0 10px 28px rgba(16, 32, 60, 0.12);
  --ease: 0.16s cubic-bezier(0.3, 0.7, 0.4, 1);
  --topbar-h: 56px;
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.6 "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; transition: color var(--ease); }
a:hover { text-decoration: underline; }
code { background: #eef1f6; padding: 1px 5px; border-radius: 5px; font-size: 0.9em;
  font-family: Consolas, "SF Mono", monospace; }

/* One visible focus treatment for everything keyboard-reachable. */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Respect a reduced-motion preference: keep the states, drop the movement. */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .wscard:hover, .hero-cta:hover { transform: none !important; }
}

/* Keyboard users get to the content without walking the whole nav.
   Hidden by clipping rather than by `left: -9999px`: in a right-to-left
   document that offset is *inside* the scrollable area, so it added ten
   thousand pixels of sideways scroll to every page in Arabic — the shipped
   default language. Clipping takes the element out of layout in both
   directions. */
.skiplink { position: absolute; top: 0; inset-inline-start: 0; z-index: 50;
  width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
  white-space: nowrap;
  background: var(--accent); color: #fff; padding: 0.6rem 1rem;
  border-radius: 0 0 var(--r-sm) 0; }
.skiplink:focus { width: auto; height: auto; overflow: visible;
  clip-path: none; text-decoration: none; }
.flashes { margin-bottom: var(--sp-3); }

/* ---- Chrome: top bar ---- */
.topbar { display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-4); height: var(--topbar-h);
  background: rgba(255, 255, 255, 0.86); backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 0.45rem; font-weight: 700;
  font-size: 1.02rem; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; color: var(--accent); }
.topbar nav { display: flex; gap: 0.15rem; align-items: center; }
.topbar nav a { padding: 0.4rem 0.7rem; border-radius: var(--r-sm);
  color: var(--muted); font-size: 0.92rem; white-space: nowrap; }
.topbar nav a:hover { background: var(--accent-soft); color: var(--accent-ink);
  text-decoration: none; }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent-ink);
  font-weight: 600; }
.searchbox { margin-inline-start: auto; margin-block: 0; }
.searchbox input { padding: 0.42rem 0.9rem; border: 1px solid var(--line);
  border-radius: var(--r-pill); width: 240px; background: var(--panel);
  font: inherit; transition: border-color var(--ease), box-shadow var(--ease); }
.searchbox input:focus { border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14); }
.langswitch { margin-inline-start: var(--sp-1); margin-block: 0; }
.langswitch button { background: transparent; color: var(--muted);
  border: 1px solid var(--line); padding: 0.34rem 0.7rem; font-size: 0.85rem;
  border-radius: var(--r-pill); white-space: nowrap; }
.langswitch button:hover { border-color: var(--accent); color: var(--accent-ink);
  filter: none; }
.topbar:not(:has(.searchbox)) .langswitch { margin-inline-start: auto; }

/* Who is signed in, and the way out. */
.accountchip { display: flex; align-items: center; gap: 0.5rem; padding-inline-start: 0.6rem;
  border-inline-start: 1px solid var(--line); }
.accountchip form { margin: 0; }
.accountchip-who { display: flex; flex-direction: column; line-height: 1.15;
  font-size: 0.78rem; max-width: 15rem; }
.accountchip-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.accountchip-org { color: var(--muted); font-size: 0.72rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.accountchip-out { background: transparent; color: var(--muted);
  border: 1px solid var(--line); padding: 0.3rem 0.7rem; font-size: 0.8rem;
  font-weight: 500; border-radius: var(--r-pill); white-space: nowrap; }
.accountchip-out:hover { border-color: #dc2626; color: #b91c1c; filter: none;
  box-shadow: none; }

/* ---- Chrome: layout and sidebar ----
   The rail shares the page's scroll rather than keeping its own. It used to be
   `position: sticky` with `overflow-y: auto`, which put a second scrollbar and
   a second scroll position on every workspace page: the wheel did different
   things depending on which side of the border the pointer happened to be, and
   the rail kept a stale scroll offset when you navigated. Being a plain flex
   child costs the nav pinning on long pages and buys one predictable scroll. */
.layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }
/* `border-inline-end`, not `border-right`: the border then follows the writing
   direction on its own and the Arabic interface needs no override. */
.sidebar { width: 232px; flex: none;
  padding: var(--sp-3) var(--sp-2) var(--sp-5);
  border-inline-end: 1px solid var(--line); background: var(--panel); }

.sidebar h3 { margin: var(--sp-4) var(--sp-2) var(--sp-1); font-size: 0.66rem;
  text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700;
  color: var(--muted); }
.sidebar h3:first-child { margin-top: var(--sp-1); }
.sidebar ul { list-style: none; padding: 0; margin: 0; }
.sidebar li { margin: 2px 0; }

/* Full-width hit target with a rounded pill, so hover and the active state
   read as one shape instead of a coloured rectangle butted against the edge. */
.sidebar li a { position: relative; display: flex; align-items: center;
  gap: 0.6rem; padding: 0.5rem 0.7rem; border-radius: var(--r-md);
  color: var(--ink); font-size: 0.92rem; font-weight: 500;
  transition: background var(--ease), color var(--ease); }
.sidebar li a:hover { background: var(--accent-soft); color: var(--accent-ink);
  text-decoration: none; }
.sidebar li a.active { background: var(--accent-soft); color: var(--accent-ink);
  font-weight: 650; }

/* The active marker is a rounded bar rather than `inset box-shadow`, which
   squared off the pill's corner. `inset-inline-start` keeps it on the correct
   edge when the interface flips to Arabic. */
.sidebar li a.active::before { content: ""; position: absolute;
  inset-inline-start: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 1.15rem; border-radius: var(--r-pill);
  background: var(--accent); }

.sidebar .navicon { width: 1.15em; text-align: center; flex: none;
  font-size: 0.95em; opacity: 0.75; transition: opacity var(--ease); }
.sidebar li a:hover .navicon, .sidebar li a.active .navicon { opacity: 1; }

/* Counts sit in a chip so a three-digit folder does not shove the label. */
.sidebar .navcount { margin-inline-start: auto; font-size: 0.72rem;
  color: var(--muted); font-variant-numeric: tabular-nums;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 0 0.42rem; line-height: 1.5; }
.sidebar li a.active .navcount { background: var(--panel);
  border-color: var(--accent); color: var(--accent-ink); }

.content { flex: 1; min-width: 0; padding: var(--sp-4) var(--sp-5);
  max-width: 1140px; }

/* ---- Typography and page headers ---- */
h1 { margin: 0.1rem 0 var(--sp-2); font-size: 1.7rem; line-height: 1.2;
  letter-spacing: -0.01em; }
h2 { margin-top: var(--sp-5); font-size: 1.22rem; }
h3 { font-size: 1.02rem; }
.muted { color: var(--muted); }
.pagehead-row { display: flex; align-items: flex-start; gap: var(--sp-3);
  flex-wrap: wrap; margin-bottom: var(--sp-2); }
.pagehead-row h1 { margin: 0; flex: 1; min-width: 0; }
.pagehead-actions { display: flex; gap: var(--sp-2); align-items: center;
  flex-wrap: wrap; }
.lede { color: var(--muted); margin: 0 0 var(--sp-3); max-width: 68ch; }

/* Breadcrumb: where am I, and one click back out. */
.crumbs { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;
  font-size: 0.85rem; color: var(--muted); margin-bottom: var(--sp-2); }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { opacity: 0.5; }
.crumbs .here { color: var(--ink); font-weight: 600; }

/* ---- Cards and stats ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: var(--sp-3); margin: var(--sp-3) 0; }
.card { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-1); }
.card.stat { text-align: center; min-width: 0; padding: var(--sp-3) var(--sp-2);
  transition: transform var(--ease), box-shadow var(--ease); }
.card.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.card.stat .num { font-size: 1.9rem; font-weight: 700; color: var(--accent);
  line-height: 1.1; font-variant-numeric: tabular-nums; }
.card.stat > div:last-child { font-size: 0.82rem; color: var(--muted); }
/* A stat that links somewhere should say so on hover. */
a.card.stat { color: inherit; }
a.card.stat:hover { text-decoration: none; border-color: var(--accent); }
.section-empty { text-align: center; padding: var(--sp-5) var(--sp-3);
  color: var(--muted); background: var(--panel); border: 1px dashed var(--line-strong);
  border-radius: var(--r-md); }

/* A link that reads as a secondary button — used in page headers. */
.btnlink { display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.42rem 0.9rem; border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); color: var(--ink); background: var(--panel);
  font-size: 0.9rem; white-space: nowrap;
  transition: border-color var(--ease), color var(--ease), background var(--ease); }
.btnlink:hover { text-decoration: none; border-color: var(--accent);
  color: var(--accent-ink); background: var(--accent-soft); }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 0.78rem;
  background: #e8edf5; color: #33415c; margin: 2px; white-space: nowrap; }
.badge-person { background: #dbeafe; color: var(--c-person); }
.badge-organization { background: #ede9fe; color: var(--c-organization); }
.badge-place { background: #d1fae5; color: var(--c-place); }
.badge-event { background: #fef3c7; color: var(--c-event); }
.badge-action { background: #fee2e2; color: var(--c-action); }
.badge-task { background: #cffafe; color: var(--c-task); }
.badge-milestone { background: #fce7f3; color: var(--c-milestone); }
.badge-date { background: #e5e7eb; color: var(--c-date); }

.status { font-size: 0.75rem; padding: 1px 8px; border-radius: 6px; background: #eee; }
.status-done { background: #d1fae5; color: #065f46; }
.status-in_progress { background: #fef3c7; color: #92400e; }
.status-blocked { background: #fee2e2; color: #991b1b; }
.status-planned { background: #e0e7ff; color: #3730a3; }

.typegrid { margin: 0.6rem 0; }
.ingest-form label { display: block; margin: 0.6rem 0; font-weight: 600; }
.ingest-form input[type=text] { width: 100%; padding: 0.5rem; border: 1px solid var(--line); border-radius: 8px; font-weight: 400; }
.ingest-form .or { text-align: center; color: var(--muted); margin: 0.4rem 0; }
.ingest-form .checkline { font-weight: 400; }
button { background: var(--accent); color: #fff; border: 0; padding: 0.52rem 1.15rem;
  border-radius: var(--r-sm); font: inherit; font-size: 0.93rem; font-weight: 600;
  cursor: pointer; transition: filter var(--ease), box-shadow var(--ease),
  transform var(--ease); }
button:hover { filter: brightness(1.07); box-shadow: var(--shadow-2); }
button:active { transform: translateY(1px); }
button:disabled, button:disabled:hover { background: var(--line-strong); color: #fff;
  cursor: not-allowed; filter: none; box-shadow: none; transform: none; }
button.secondary { background: transparent; color: var(--ink);
  border: 1px solid var(--line-strong); font-weight: 500; }
button.secondary:hover { background: var(--panel); border-color: var(--accent);
  color: var(--accent-ink); filter: none; }
.inlineform { margin: var(--sp-2) 0; display: flex; gap: var(--sp-2);
  align-items: center; flex-wrap: wrap; }

.flash { display: flex; gap: 0.5rem; padding: 0.7rem 1rem;
  border-radius: var(--r-sm); margin-bottom: var(--sp-2); font-size: 0.93rem;
  border-inline-start: 3px solid currentColor; animation: flashin 0.2s var(--ease); }
@keyframes flashin { from { opacity: 0; transform: translateY(-4px); } }
.flash-ok { background: #ecfdf5; color: #065f46; }
.flash-error { background: #fef2f2; color: #991b1b; }

.joblog { max-height: 260px; overflow-y: auto; background: #10141b; color: #c9d4e3;
  padding: 0.8rem; border-radius: 8px; font-size: 0.82rem; white-space: pre-wrap; }
.progresswrap { display: flex; align-items: center; gap: 0.8rem; margin: 0.6rem 0; }
.progressbar { flex: 1; height: 12px; background: #e3e7ee; border-radius: 999px; overflow: hidden; }
.progressfill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #60a5fa);
  border-radius: 999px; transition: width 0.6s ease; }
.formats-note { display: block; font-weight: 400; font-size: 0.82rem; margin-top: 2px; }
.titleinput { width: 100%; padding: 0.5rem; border: 1px solid var(--line);
  border-radius: 8px; font-weight: 400; }
.editform label { display: block; margin: 0.6rem 0; font-weight: 600; }
.loglist { list-style: none; padding: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-1); overflow: hidden; }
.loglist li { padding: 0.6rem var(--sp-3); border-bottom: 1px solid var(--line);
  transition: background var(--ease); }
.loglist li:last-child { border-bottom: 0; }
.loglist li:hover { background: var(--accent-soft); }
.logtime { font-family: Consolas, monospace; font-size: 0.82rem;
  font-variant-numeric: tabular-nums; }

/* Entity lists read as rows you can scan and click, not a bulleted list. */
.entitylist { list-style: none; padding: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-1); overflow: hidden; }
/* A row is a grid: title and badges on one line, description beneath, so long
   lists stay scannable instead of wrapping into a paragraph. */
.entitylist li { display: grid; grid-template-columns: 1fr auto;
  gap: 0.1rem 0.5rem; align-items: baseline;
  padding: 0.7rem var(--sp-3); border-bottom: 1px solid var(--line);
  transition: background var(--ease); }
.entitylist li:last-child { border-bottom: 0; }
.entitylist li:hover { background: var(--accent-soft); }
.entitylist li > a { font-weight: 600; }
.entitylist li > a:first-child { grid-column: 1; }
.entitylist li > .badge, .entitylist li > .status,
.entitylist li > .muted:not(div) { grid-column: 2; justify-self: end; }
.entitylist li > div { grid-column: 1 / -1; font-size: 0.88rem; margin-top: 0.1rem; }

.timeline { list-style: none; padding-left: 1.1rem; margin-inline-start: 0.3rem;
  border-left: 2px solid var(--line); }
.timeline li { margin: 0.9rem 0; position: relative; padding-left: 0.9rem; }
/* The marker takes the entity type's colour, so a year of the case reads as a
   pattern — red actions, amber events, pink milestones — before any text. */
.timeline li::before { content: ""; position: absolute; left: -1.55rem; top: 0.5rem;
  width: 10px; height: 10px; border-radius: 50%; background: var(--c-other);
  box-shadow: 0 0 0 3px var(--bg); }
.timeline li.tl-event::before { background: var(--c-event); }
.timeline li.tl-action::before { background: var(--c-action); }
.timeline li.tl-milestone::before { background: var(--c-milestone); }
.timeline li.tl-task::before { background: var(--c-task); }
.tl-row { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.tl-title { font-weight: 600; }
.tl-desc { margin: 0.15rem 0 0; font-size: 0.89rem; }
.tlgroup[hidden] { display: none; }

/* The AI-written narrative of the whole timeline. */
.tl-narrative { background: linear-gradient(135deg, #f5f8ff, #eef4ff);
  border: 1px solid #dbe6fb; border-inline-start: 3px solid var(--accent);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-3) 0; }
.tl-narrative-head { margin: 0 0 0.3rem; font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent-ink); }
.tl-narrative p { margin: 0; }
.pillcount { margin-inline-start: 0.35rem; font-size: 0.76rem; opacity: 0.75;
  font-variant-numeric: tabular-nums; }

/* ---- Relationships: the emergent predicate vocabulary as a filter ---- */
.predcloud { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: var(--sp-3) 0; }
.predlink { display: inline-flex; align-items: baseline; gap: 0.1rem;
  padding: 0.24rem 0.7rem; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--panel); color: #33415c;
  font: inherit; font-size: 0.82rem; cursor: pointer;
  transition: background var(--ease), border-color var(--ease), color var(--ease); }
.predlink:hover { border-color: var(--accent); background: var(--accent-soft);
  color: var(--accent-ink); }
.predlink.activepred { background: var(--accent); border-color: var(--accent);
  color: #fff; }

/* ---- Validate / duplicates: issues read as rows with a severity edge ---- */
.issuelist .issue { display: flex; gap: 0.5rem; align-items: baseline;
  border-inline-start: 3px solid transparent; }
.issuelist .issue-error { border-inline-start-color: #dc2626; background: #fef7f7; }
.issuelist .issue-warn { border-inline-start-color: #d97706; background: #fffbf3; }
.issuelist .issue-error:hover { background: #fdeeee; }
.issuelist .issue-warn:hover { background: #fff6e8; }
.tldate { font-family: Consolas, monospace; font-size: 0.85rem; color: var(--muted);
  margin-right: 0.4rem; }
.yearhead { border-bottom: 2px solid var(--line); padding-bottom: 0.2rem;
  position: sticky; top: var(--topbar-h); background: var(--bg); z-index: 2;
  padding-top: 0.3rem; }

.wikipage .pagehead { display: flex; align-items: center; gap: 0.8rem;
  flex-wrap: wrap; }

/* ---- Entity page: body beside its metadata ---- */
.pagegrid { display: grid; grid-template-columns: minmax(0, 1fr) 280px;
  gap: var(--sp-4); align-items: start; }
.pagebody { min-width: 0; }
.pageside { display: flex; flex-direction: column; gap: var(--sp-3);
  position: sticky; top: calc(var(--topbar-h) + var(--sp-3)); }
.sidecard { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--sp-2) var(--sp-3);
  box-shadow: var(--shadow-1); }
.sidecard-head { display: flex; align-items: center; gap: 0.4rem;
  margin: 0 0 0.4rem; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); }
.sidecard-count { margin-inline-start: auto; background: var(--accent-soft);
  color: var(--accent-ink); border-radius: var(--r-pill); padding: 0 0.45rem;
  font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.sidelist { margin: 0; display: grid; gap: 0.4rem; font-size: 0.86rem; }
.sidelist dt { color: var(--muted); font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.05em; }
.sidelist dd { margin: 0.05rem 0 0; overflow-wrap: anywhere; }
.sidelinks { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.35rem;
  font-size: 0.87rem; }
.sidelinks li { display: flex; gap: 0.35rem; align-items: baseline;
  flex-wrap: wrap; }
.sidelinks code { overflow-wrap: anywhere; }
@media (max-width: 980px) {
  .pagegrid { grid-template-columns: 1fr; }
  .pageside { position: static; }
}
.metacard { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--sp-2) var(--sp-3);
  margin: var(--sp-2) 0; font-size: 0.88rem; box-shadow: var(--shadow-1); }
.metarow { display: flex; gap: 0.6rem; padding: 2px 0; }
.metakey { min-width: 118px; color: var(--muted); flex: none; }
.mdbody { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--shadow-1); }
.mdbody h1 { font-size: 1.22rem; border-bottom: 1px solid var(--line);
  padding-bottom: 0.25rem; }

/* Tables: scrollable on narrow screens, sticky headers, readable rows. */
.tablewrap { overflow-x: auto; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--panel);
  box-shadow: var(--shadow-1); }
.tablewrap .reltable { margin: 0; border: 0; }
.mdbody table, .reltable { border-collapse: collapse; width: 100%;
  margin: var(--sp-2) 0; }
.mdbody th, .mdbody td, .reltable th, .reltable td {
  border-bottom: 1px solid var(--line); padding: 0.55rem 0.8rem; text-align: left; }
.mdbody th, .mdbody td { border: 1px solid var(--line); }
.reltable { background: var(--panel); font-size: 0.92rem; }
.reltable th { background: #f1f5fb; color: var(--muted); font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: 0.05em; position: sticky; top: 0;
  z-index: 1; white-space: nowrap; }
.reltable tbody tr { transition: background var(--ease); }
.reltable tbody tr:hover { background: var(--accent-soft); }
.reltable tbody tr:last-child td { border-bottom: 0; }

#graph { width: 100%; height: 72vh; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-1); }

.wschip { background: #e0e7ff; color: #3730a3; padding: 3px 12px; border-radius: 999px;
  font-weight: 600; font-size: 0.9rem; white-space: nowrap; }
.wschip:hover { text-decoration: none; filter: brightness(0.97); }
/* ---- Home: hero ---- */
.hero { display: flex; gap: 2rem; align-items: flex-start; flex-wrap: wrap;
  padding: 2rem 2.2rem; margin-bottom: 1.4rem; border-radius: 14px;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #3b82f6 100%);
  color: #fff; }
.hero-main { flex: 1 1 320px; }
.hero-title { font-size: 2rem; line-height: 1.15; margin: 0 0 0.4rem; color: #fff; }
.hero-lede { margin: 0 0 1.2rem; max-width: 46em; color: #dbe7ff; }
.hero-actions { display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; }
.hero-cta { display: inline-block; background: #fff; color: #1e3a8a;
  padding: 0.6rem 1.4rem; border-radius: 999px; font-weight: 700; }
.hero-cta:hover { text-decoration: none; transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(3, 20, 60, 0.28); }
.hero-link { color: #dbe7ff; font-size: 0.92rem; }
.hero-link:hover { color: #fff; }
.hero-stats { display: grid; grid-template-columns: repeat(4, minmax(70px, auto));
  gap: 0.6rem 1.6rem; margin: 0; }
.hero-stats dt { font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.09em; color: #b9cdf7; }
.hero-stats dd { margin: 0.1rem 0 0; font-size: 1.7rem; font-weight: 700;
  font-variant-numeric: tabular-nums; }
.ws-empty .hero-cta { background: var(--accent); color: #fff; margin-top: 0.6rem; }

/* ---- Home: toolbar ---- */
.ws-toolbar { margin: 0 0 1rem; }
.ws-toolrow { display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; }
.ws-search { flex: 1; min-width: 220px; padding: 0.6rem 0.9rem;
  border: 1px solid var(--line); border-radius: 999px; font: inherit;
  background: var(--panel); }
.ws-search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.ws-sortwrap { display: flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.ws-sortwrap select { padding: 0.35rem 0.5rem; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; }
.ws-filters { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap;
  margin-top: 0.6rem; }
.ws-filter { cursor: pointer; }
.ws-filter.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.ws-count { margin-inline-start: auto; }
.ws-noresults { text-align: center; padding: 2rem 0; }

/* ---- Home: workspace cards ---- */
.wsgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem; margin: 1rem 0; }
.wscard { position: relative; display: flex; flex-direction: column; gap: 0.5rem;
  color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 1.1rem 1.2rem;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
.wscard[hidden] { display: none; }
.wscard:hover { border-color: var(--accent); transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.13); }
.wscard:focus-within { border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18); }
/* An invisible link covering the card makes the whole surface clickable while
   the quick links below stay independently focusable and clickable. */
.wscard-hit { position: absolute; inset: 0; border-radius: 12px; z-index: 1; }
.wscard-head { display: flex; align-items: center; gap: 0.5rem; }
.wscard-icon { font-size: 1.1rem; }
.wsname { font-weight: 700; font-size: 1.08rem; margin: 0; flex: 1; }
.wsdesc { margin: 0; color: var(--muted); font-size: 0.9rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; }
.wsbar { display: flex; height: 6px; border-radius: 999px; overflow: hidden;
  background: #eef1f5; }
.wsbar-seg { background: currentColor; min-width: 3px; }
.wsstats { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.86rem;
  color: #33415c; margin: 0; }
.wsstats strong { font-variant-numeric: tabular-nums; }
.wsmeta { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.wsmeta-chip { font-size: 0.76rem; padding: 2px 9px; border-radius: 999px;
  background: #f1f5f9; color: #475569; max-width: 100%; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.wsmeta-local { background: #dcfce7; color: #166534; }
.wsmeta-cloud { background: #e0e7ff; color: #3730a3; }
.wsjob .progressbar { height: 6px; }
.wsjob-text { display: block; margin-top: 0.25rem; }
.wsquick { display: flex; gap: 0.8rem; flex-wrap: wrap; position: relative;
  z-index: 2; margin-top: auto; padding-top: 0.6rem;
  border-top: 1px solid var(--line); font-size: 0.82rem; }
.wsdemo { border-style: dashed; }
.small { font-size: 0.8rem; }

.card.danger { border-color: #fecaca; }
.dangerbtn { background: #dc2626; }

.editlink { margin-left: auto; font-size: 0.9rem; }
.paneltitle { margin: 0.4rem 0; font-size: 0.95rem; }
.backlinks { list-style: none; padding: 0; margin: 0.2rem 0; }
.backlinks li { padding: 0.15rem 0; }
.editform textarea, .promptcard textarea { width: 100%; font: 0.85rem/1.5 Consolas, monospace;
  padding: 0.8rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.editactions { display: flex; gap: 0.8rem; align-items: center; margin-top: 0.6rem; }
.editactions .cancel { margin-left: auto; }
.srcview { background: #10141b; color: #c9d4e3; padding: 0.9rem; border-radius: 8px;
  font-size: 0.82rem; white-space: pre-wrap; max-height: 420px; overflow-y: auto; }
.promptcard { margin-bottom: 1rem; }
.prompthead { display: flex; gap: 0.8rem; align-items: center; margin-bottom: 0.4rem; }
.promptcard details summary { cursor: pointer; color: var(--accent); margin: 0.3rem 0; }
.defaultview { margin-top: 0.5rem; }
.mergerow { display: flex; align-items: center; gap: 0.8rem; padding: 0.25rem 0; }
.mergerow form { margin: 0; }
.inlineform input[type=text] { padding: 0.45rem 0.7rem; border: 1px solid var(--line);
  border-radius: 8px; min-width: 220px; }

/* ---- filter bars ---- */
.filterbar { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 0.55rem 0.8rem; margin: var(--sp-2) 0;
  position: sticky; top: calc(var(--topbar-h) + 4px); z-index: 6;
  box-shadow: var(--shadow-1); }
.filterbar input[type=search], .filterbar input[type=text] {
  padding: 0.4rem 0.8rem; border: 1px solid var(--line);
  border-radius: var(--r-pill); min-width: 190px; font: inherit;
  font-size: 0.9rem; flex: 1; }
.filterbar input[type=date] { padding: 0.32rem 0.5rem; border: 1px solid var(--line);
  border-radius: var(--r-sm); color: var(--ink); font-size: 0.86rem; }
.filterbar select { padding: 0.4rem 0.5rem; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--panel); font-size: 0.88rem;
  max-width: 230px; }
.filterbar .flabel { color: var(--muted); font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: 0.05em; }
.pill { display: inline-flex; align-items: center; padding: 0.26rem 0.8rem;
  border-radius: var(--r-pill); border: 1px solid var(--line);
  background: var(--panel); color: #33415c; font: inherit; font-size: 0.83rem;
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: background var(--ease), border-color var(--ease), color var(--ease); }
.pill:hover { border-color: var(--accent); color: var(--accent-ink);
  background: var(--accent-soft); }
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill.active:hover { color: #fff; }
.pill.active .pilldot { background: #fff; }
.pilldot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 5px; vertical-align: 1px; }
.fhide { display: none !important; }
[data-filter-reset] { background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 0.85rem; padding: 0.2rem 0.4rem; }
[data-filter-count] { color: var(--muted); font-weight: 400; font-size: 0.95rem; }
.graphbar { position: static; }
.predlink { cursor: pointer; }
.predlink:hover { outline: 1px solid var(--accent); }
.predlink.activepred { background: var(--accent); color: #fff; }

/* ---- AI document data extraction ---- */
.ext-deflist li { padding: 0.7rem 0; }
.ext-defactions { margin-top: 0.35rem; display: flex; gap: 0.9rem; font-size: 0.88rem; }

.ext-statbar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.8rem 0; }
.ext-statchip { padding: 0.25rem 0.7rem; border-radius: 999px; font-size: 0.82rem; }

/* status palette (chips, badges, cell accents) */
.extstatus-high_confidence { background: #d1fae5; color: #065f46; }
.extstatus-needs_review { background: #fef3c7; color: #92400e; }
.extstatus-missing { background: #e5e7eb; color: #4b5563; }
.extstatus-conflict { background: #fee2e2; color: #991b1b; }
.extstatus-verified { background: #dbeafe; color: #1e40af; }

.extkind-extracted { background: #ecfdf5; color: #047857; }
.extkind-derived { background: #eff6ff; color: #1d4ed8; }
.extkind-inferred { background: #fdf2f8; color: #9d174b; }

.ext-results { margin: 0.6rem 0; }
.ext-field { margin: 0.5rem 0; }
.ext-fname { font-weight: 600; font-size: 0.92rem; }
.ext-req { color: #dc2626; }
.ext-obj { border-inline-start: 2px solid var(--line); padding-inline-start: 0.8rem; margin: 0.5rem 0; }
.ext-objname { color: var(--muted); }
.ext-objbody { margin-top: 0.3rem; }

.ext-cell { border: 1px solid var(--line); border-inline-start-width: 4px; border-radius: 8px;
  padding: 0.4rem 0.7rem; margin: 0.25rem 0; background: var(--panel); }
.ext-cell.status-high_confidence { border-inline-start-color: #10b981; }
.ext-cell.status-needs_review { border-inline-start-color: #f59e0b; }
.ext-cell.status-missing { border-inline-start-color: #cbd5e1; }
.ext-cell.status-conflict { border-inline-start-color: #ef4444; }
.ext-cell.status-verified { border-inline-start-color: #3b82f6; }
.ext-cellmain { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.ext-value { font-weight: 600; }
.ext-value.ext-clickable { cursor: pointer; text-decoration: underline dotted; }
.ext-missing { color: var(--muted); font-style: italic; }
.ext-badge { font-size: 0.72rem; padding: 1px 8px; border-radius: 999px; }
.ext-kind { font-size: 0.7rem; padding: 1px 7px; border-radius: 6px; }

.ext-ev { display: none; margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px dashed var(--line); }
.ext-ev.open { display: block; }
.ext-ev-toggle { background: transparent; color: var(--accent); border: 1px solid var(--line);
  padding: 0.1rem 0.45rem; border-radius: 6px; font-size: 0.8rem; }
.ext-ev-label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.ext-evidence { margin: 0.3rem 0; padding: 0.4rem 0.7rem; background: #f8fafc; border-inline-start: 3px solid var(--accent);
  border-radius: 4px; font-size: 0.9rem; white-space: pre-wrap; }
.ext-evidence.small { font-size: 0.82rem; }
.ext-ev-meta { font-size: 0.82rem; margin: 0.2rem 0; }
.ext-cellerr { color: #991b1b; font-size: 0.82rem; margin-top: 0.3rem; }
.ext-conflict { margin-top: 0.4rem; }
.ext-alt { margin: 0.25rem 0; }
.ext-cellactions { display: flex; gap: 0.4rem; margin-top: 0.5rem; flex-wrap: wrap; }
.ext-cellactions .ext-input { flex: 1; min-width: 160px; padding: 0.35rem 0.6rem;
  border: 1px solid var(--line); border-radius: 6px; }
.ext-cellactions button { padding: 0.35rem 0.8rem; font-size: 0.85rem; }
.ext-verify { background: #0891b2; }

.ext-tablewrap { overflow-x: auto; }
.ext-table { border-collapse: collapse; width: 100%; font-size: 0.9rem; background: var(--panel); }
.ext-table th, .ext-table td { border: 1px solid var(--line); padding: 0.35rem 0.5rem; text-align: start; vertical-align: top; }
.ext-table th { background: #eef1f5; }
.ext-table .ext-cell { border: 0; border-inline-start: 3px solid transparent; margin: 0; padding: 0.2rem 0.3rem; }

.ext-valerrors { margin: 0.6rem 0; }
.ext-valerrors summary { cursor: pointer; color: #92400e; }

.ext-testcols { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 1.2rem; align-items: start; }
.ext-testform { position: sticky; top: 70px; }
.ext-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.ext-paste { width: 100%; font: 0.85rem/1.4 Consolas, monospace; padding: 0.6rem;
  border: 1px solid var(--line); border-radius: 8px; }
.ext-sourcepick { max-height: 180px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: 8px; padding: 0.5rem; font-weight: 400; }
.ext-sourcepick label { display: block; margin: 0.15rem 0; }

/* schema builder */
.sb-root { margin: 0.5rem 0; }
.sb-field { border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem; margin: 0.5rem 0; background: var(--panel); }
.sb-head { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.sb-name { flex: 1; min-width: 140px; padding: 0.4rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; font-weight: 600; }
.sb-type { padding: 0.4rem; border: 1px solid var(--line); border-radius: 6px; }
.sb-check { font-size: 0.85rem; color: var(--muted); font-weight: 400; }
.sb-rm { background: #ef4444; padding: 0.3rem 0.6rem; }
.sb-body { margin-top: 0.5rem; }
.sb-row { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.35rem 0; font-weight: 400; }
.sb-row input, .sb-row textarea { width: 100%; padding: 0.35rem 0.6rem; border: 1px solid var(--line);
  border-radius: 6px; margin-top: 0.15rem; font-weight: 400; }
.sb-adv summary { cursor: pointer; color: var(--accent); font-size: 0.85rem; }
.sb-children { border-inline-start: 2px dashed var(--accent); padding-inline-start: 0.8rem; margin-top: 0.5rem; }
.sb-add { background: #64748b; padding: 0.35rem 0.8rem; font-size: 0.85rem; }
.sm-sample { margin: 0.6rem 0; }
.sm-head { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.4rem; }

@media (max-width: 800px) {
  .ext-testcols, .ext-compare { grid-template-columns: 1fr; }
  .ext-testform { position: static; }
}

/* ---- new-workspace wizard ---- */
.wizard-cta { display: inline-block; background: var(--accent); color: #fff; padding: 0.6rem 1.3rem;
  border-radius: 8px; font-weight: 600; }
.wizard-cta:hover { text-decoration: none; filter: brightness(1.08); }
.ws-empty { text-align: center; }
.ws-empty .wizard-cta { margin-top: 0.6rem; }

.wiz-steps { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; padding: 0; margin: 0.8rem 0 1rem; }
.wiz-steps li { display: flex; align-items: center; gap: 0.4rem; color: var(--muted);
  font-size: 0.86rem; padding: 0.3rem 0.7rem; border-radius: 999px; }
.wiz-steps li.active { color: var(--ink); font-weight: 600; background: #eef2ff; }
.wiz-steps li.done { color: var(--c-place); }
.wiz-dot { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border-radius: 50%; background: var(--line); color: #33415c; font-size: 0.78rem; font-weight: 700; }
.wiz-steps li.active .wiz-dot { background: var(--accent); color: #fff; }
.wiz-steps li.done .wiz-dot { background: var(--c-place); color: #fff; }

.wiz-card { max-width: 720px; }
.wiz-step label { display: block; margin: 0.7rem 0; font-weight: 600; }
.wiz-step textarea.titleinput { font-weight: 400; }

.wiz-purposes { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.7rem; }
.wiz-purpose { display: flex; flex-direction: column; align-items: flex-start; gap: 0.2rem;
  text-align: start; background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 0.9rem; cursor: pointer; }
.wiz-purpose:hover { border-color: var(--accent); filter: none; box-shadow: 0 2px 8px rgba(37,99,235,0.1); }
.wiz-purpose.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,0.25); }
.wiz-picon { font-size: 1.6rem; }
.wiz-plabel { font-weight: 700; }

.wiz-langs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.wiz-lang { font-size: 0.9rem; }

.wiz-slug { font-family: Consolas, monospace; margin-top: -0.3rem; }
.wiz-err { color: #991b1b; font-size: 0.86rem; margin: 0.3rem 0; }

.wiz-nav { display: flex; align-items: center; gap: 0.7rem; margin-top: 1.2rem;
  border-top: 1px solid var(--line); padding-top: 1rem; }
.wiz-nav .wiz-next, .wiz-nav .wiz-create { margin-inline-start: auto; }
.wiz-nav .wiz-cancel { color: var(--muted); font-size: 0.9rem; }

@keyframes wizshake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); } }
.wiz-shake { animation: wizshake 0.4s; }

/* ---- API docs ---- */
.api-table code { font-size: 0.82rem; }
.api-method { display: inline-block; min-width: 52px; text-align: center; padding: 1px 8px;
  border-radius: 6px; font-size: 0.74rem; font-weight: 700; color: #fff; }
.api-get { background: #059669; }
.api-post { background: #2563eb; }
.api-put { background: #d97706; }
.api-delete { background: #dc2626; }
.homelinks { margin: 0.4rem 0 1rem; font-size: 0.9rem; }

/* ---- Wizard: model / template picker ---- */
.wiz-templates { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.7rem; margin: 0.8rem 0; }
.wiz-template { display: flex; flex-direction: column; align-items: flex-start; gap: 0.3rem;
  text-align: start; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 0.9rem 1rem;
  font: inherit; cursor: pointer; }
.wiz-template:hover { border-color: var(--accent); filter: none; }
.wiz-template.active { border-color: var(--accent); background: #eef4ff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15); }
.wiz-template .wiz-ptag { font-weight: 400; line-height: 1.45; }
.wiz-engine { border-top: 1px solid var(--line); margin-top: 0.9rem; padding-top: 0.9rem; }
.wiz-engine label { display: block; margin: 0.6rem 0; font-weight: 600; }

/* ---- Source intake panel ----
   Tabs over one card. Without JavaScript every panel is visible in sequence,
   each an independent form, so the markup degrades to a plain stacked page. */
.ing { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
/* The tab strip is tinted so the active tab, which is the same white as the
   panel it opens, reads as continuous with it. */
.ing-tabs { display: flex; gap: 0.2rem; padding: 0.5rem 0.5rem 0;
  background: #eff3f9; border-bottom: 1px solid var(--line);
  border-radius: 10px 10px 0 0; flex-wrap: wrap; }
.ing-tab { display: flex; align-items: center; gap: 0.45rem; background: transparent;
  color: var(--muted); border: 1px solid transparent; border-bottom: 0;
  border-radius: 9px 9px 0 0; padding: 0.55rem 1rem; font: inherit; font-size: 0.92rem;
  cursor: pointer; margin-bottom: -1px; }
.ing-tab:hover { background: #e2e9f4; color: var(--ink); filter: none; }
.ing-tab.active { background: #fff; color: var(--ink); font-weight: 600;
  border-color: var(--line); border-bottom-color: #fff; }
.ing-tab .ing-tabicon { font-size: 1.05rem; }
.ing-panel { padding: 1.2rem 1.4rem; }
.ing-lede { margin: 0 0 0.9rem; color: var(--ink); }
.ing-form { margin: 0; }

.ing-field { display: block; margin: 0.7rem 0; }
.ing-fieldlabel { display: block; font-weight: 600; margin-bottom: 0.25rem; }
.ing-field input[type=text], .ing-field input[type=url], .ing-field textarea {
  width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; }
.ing-field textarea { resize: vertical; line-height: 1.5; }

/* Drop target. The file input is inside the label, so a click anywhere opens
   the picker and drag & drop lands on the same element. */
.ing-drop { display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
  padding: 2rem 1rem; border: 2px dashed var(--line); border-radius: 12px;
  background: #fbfcfe; cursor: pointer; text-align: center; }
.ing-drop:hover, .ing-drop:focus-visible { border-color: var(--accent); background: #f2f6ff; }
.ing-drop.over { border-color: var(--accent); background: #e8f0ff;
  box-shadow: inset 0 0 0 3px rgba(37, 99, 235, 0.1); }
.ing-fileinput { position: absolute; width: 1px; height: 1px; opacity: 0;
  overflow: hidden; }
.ing-dropicon { font-size: 1.7rem; }
.ing-droptitle { font-weight: 600; }
.ing-dropsub { font-size: 0.86rem; }

.ing-filelist { list-style: none; padding: 0; margin: 0.8rem 0 0; }
.ing-fileitem { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.6rem;
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 0.3rem;
  background: #fff; font-size: 0.9rem; }
.ing-fileitem.bad { border-color: #fecaca; background: #fff5f5; }
.ing-filename { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  unicode-bidi: plaintext; }
.ing-filemeta { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ing-fileremove { background: transparent; color: var(--muted); border: 0;
  padding: 0 0.3rem; cursor: pointer; font-size: 0.9rem; border-radius: 6px; }
.ing-fileremove:hover { background: #fee2e2; color: #991b1b; filter: none; }
.ing-filesummary { padding: 0.3rem 0.6rem; color: var(--muted); font-size: 0.85rem; }

.ing-note { padding: 0.55rem 0.8rem; border-radius: 8px; margin-top: 0.7rem;
  font-size: 0.88rem; }
.ing-note-info { background: #eff6ff; color: #1e40af; }
.ing-note-warn { background: #fef3c7; color: #92400e; }

.ing-formats { margin-top: 0.9rem; font-size: 0.88rem; }
.ing-formats summary { cursor: pointer; color: var(--muted); }
.ing-formattable { border-collapse: collapse; margin-top: 0.5rem; }
.ing-formattable td { padding: 0.25rem 0.7rem 0.25rem 0; vertical-align: top; }
.ing-fmticon { font-size: 1.05rem; }

.ing-tip { color: var(--muted); font-size: 0.88rem; margin: 0.6rem 0 0;
  padding-inline-start: 0.1rem; }

.ing-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid var(--line); }
.ing-submit:disabled { background: #cbd5e1; cursor: not-allowed; filter: none; }
.ing-force { display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem;
  cursor: help; }
.ing-hint { display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; background: var(--line);
  color: var(--muted); font-size: 0.7rem; }
.ing-cost { margin-inline-start: auto; }

.ing-pipeline { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;
  padding: 0.7rem 1.4rem; border-top: 1px solid var(--line); background: #fbfcfe;
  border-radius: 0 0 10px 10px; font-size: 0.8rem; color: var(--muted); }
.ing-pipelabel { font-weight: 600; }
.ing-step + .ing-step::before { content: "→"; margin-inline-end: 0.4rem;
  color: var(--line); }
[dir="rtl"] .ing-step + .ing-step::before { content: "←"; }

/* ---- Chat with the workspace ---- */
.chat-layout { display: flex; gap: 1.2rem; align-items: flex-start; margin-top: 0.8rem; }
.chat-convs { width: 210px; flex: none; }
.chat-newbtn { display: block; text-align: center; background: var(--accent); color: #fff;
  padding: 0.5rem; border-radius: 8px; font-weight: 600; font-size: 0.9rem; }
.chat-newbtn:hover { text-decoration: none; filter: brightness(1.08); }
.chat-convlist { list-style: none; padding: 0; margin: 0; }
.chat-convlist li { padding: 0.4rem 0.55rem; border-radius: 8px; margin-bottom: 0.15rem; }
.chat-convlist li.active { background: #e0e7ff; }
.chat-convlist li a { display: block; font-size: 0.9rem; }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.chat-thread { padding: 1rem 1.2rem; max-height: 60vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.9rem; }
.chat-empty { text-align: center; padding: 2rem 1rem; }
.chat-msg { max-width: 100%; }
.chat-who { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 0.2rem; }
.chat-body { padding: 0.6rem 0.9rem; border-radius: 10px; background: #f1f5f9;
  white-space: pre-wrap; }
.chat-user .chat-body { background: #e0e7ff; }
.chat-assistant .chat-body { background: var(--panel); border: 1px solid var(--line);
  white-space: normal; }
.chat-assistant .chat-body > :first-child { margin-top: 0; }
.chat-assistant .chat-body > :last-child { margin-bottom: 0; }
.chat-pending .chat-body { color: var(--muted); font-style: italic; }
.chat-cites { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center;
  margin-top: 0.4rem; }
.chat-citelabel { font-size: 0.75rem; color: var(--muted); }
.chat-cite { font-size: 0.78rem; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: #f8fafc; max-width: 320px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-cite:hover { text-decoration: none; border-color: var(--accent); }
.chat-cite-entity { background: #eef2ff; }
.chat-cite-source { background: #f0fdf4; }
.chat-meta { margin-top: 0.4rem; }
.chat-meta summary { cursor: pointer; list-style: none; }
.chat-meta summary::-webkit-details-marker { display: none; }
.chat-composer { border-top: 1px solid var(--line); padding: 0.8rem 1.2rem; }
.chat-composer textarea { width: 100%; padding: 0.6rem; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; resize: vertical; }
.chat-controls { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.5rem; }
.chat-controls select { padding: 0.25rem; border: 1px solid var(--line); border-radius: 6px; }
.chat-spacer { margin-inline-start: auto; }
.chat-hidden { display: none; }
@media (max-width: 860px) {
  .chat-layout { flex-direction: column; }
  .chat-convs { width: 100%; }
}

/* Bidi: let each element pick its direction from its own text, so Arabic /
   Hebrew titles, facts and table cells render RTL inside the LTR chrome. */
h1, h2, h3, .mdbody p, .mdbody li, .mdbody td, .mdbody th, .mdbody h1,
.entitylist li, .timeline li, .reltable td, .loglist li, .metaval,
.backlinks li, .wsname, .mergerow span, textarea,
.ext-value, .ext-evidence, .ext-fname, .ext-alt, .ext-table td,
.chat-body, .chat-convlist li a {
  unicode-bidi: plaintext;
}

/* ---- Right-to-left interface ----
   The topbar and layout are flex rows, so their item order mirrors from
   dir="rtl" automatically (sidebar moves to the right). These rules fix the
   handful of physical properties that don't follow the inline direction. */
/* The sidebar needs no rule here — it uses `border-inline-end`, which already
   follows the writing direction. */
[dir="rtl"] .reltable th, [dir="rtl"] .reltable td,
[dir="rtl"] .mdbody th, [dir="rtl"] .mdbody td { text-align: right; }
[dir="rtl"] .timeline { border-left: 0; border-right: 3px solid var(--line);
  padding-left: 0; padding-right: 1rem; }
[dir="rtl"] .timeline li { padding-left: 0; padding-right: 0.8rem; }
[dir="rtl"] .timeline li::before { left: auto; right: -1.45rem; }
[dir="rtl"] .metakey { text-align: start; }
[dir="rtl"] .editactions .cancel { margin-left: 0; margin-right: auto; }
[dir="rtl"] .tldate { margin-right: 0; margin-left: 0.4rem; }
[dir="rtl"] .pilldot { margin-right: 0; margin-left: 5px; }
/* Technical blocks stay left-to-right regardless of interface language:
   logs, code, JSON, hashes and monospace data read wrong when mirrored. */
[dir="rtl"] .joblog, [dir="rtl"] .srcview, [dir="rtl"] pre.code,
[dir="rtl"] code, [dir="rtl"] .logtime, [dir="rtl"] .tldate {
  direction: ltr; unicode-bidi: isolate; text-align: left;
}
[dir="rtl"] .metaval code { text-align: left; }

/* ---- Organisation model status: readable at a glance from the page head ---- */
.modelstate { display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.28rem 0.7rem; border-radius: var(--r-pill); font-size: 0.85rem;
  font-weight: 600; border: 1px solid transparent; }
.modelstate code { background: rgba(255, 255, 255, 0.55); font-weight: 500; }
.modelstate.is-on { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.modelstate.is-off { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

/* ---------------------------------------------------------------------------
   Phone layout
   Measured at 390px in both interface languages: every workspace page scrolled
   sideways to ~1232px. The bulk of that was the top bar — one non-wrapping row
   of brand + workspace chip + five nav links + a fixed 240px search field —
   with wide tables and a fixed four-column stat grid behind it.
   --------------------------------------------------------------------------- */
@media (max-width: 760px) {
  /* Rail above the content instead of a 232px column beside it: that column
     left too little room for a table, and there was previously no rule here
     at all — it just squeezed.

     It is one swipeable strip, not a stacked list. Wrapped into rows the three
     sections ran about a thousand pixels tall, so every workspace page opened
     on a full screen of navigation with the content pushed below the fold —
     no sideways scrollbar, and still unusable. Laid out in a row it costs one
     line and the page starts where the page should start. */
  .layout { display: block; }
  .sidebar { width: auto; border-inline-end: 0;
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: var(--sp-2);
    overflow-x: auto; scrollbar-width: none;
    padding: var(--sp-1) var(--sp-3); }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar h3 { margin: 0; flex: none; align-self: center;
    white-space: nowrap; opacity: 0.7; }
  .sidebar ul { display: flex; flex: none; gap: 2px; }
  .sidebar li { margin: 0; }
  .sidebar li a { white-space: nowrap; }
  .sidebar li a.active::before { display: none; }
  .content { padding: var(--sp-3); max-width: none; }

  /* The bar wraps, and stops being sticky — pinned and two rows tall it eats
     a quarter of a phone screen, and every `top: var(--topbar-h)` offset below
     would have to track its new height. */
  .topbar { position: static; height: auto; min-height: var(--topbar-h);
    flex-wrap: wrap; padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); }
  .brand { font-size: 0.95rem; }

  /* Five nav links do not fit on one phone row and look lost over three, so
     the strip swipes sideways inside its own width. */
  .topbar nav { order: 5; width: 100%; overflow-x: auto; gap: 0.2rem;
    scrollbar-width: none; }
  .topbar nav::-webkit-scrollbar { display: none; }

  .searchbox { order: 6; width: 100%; margin-inline-start: 0; }
  .searchbox input { width: 100%; }

  /* Sign-out stays reachable; the email it sits next to does not need a row
     of its own on a phone. */
  .accountchip { margin-inline-start: auto; padding-inline-start: 0;
    border-inline-start: 0; }
  .accountchip-who { display: none; }
  .langswitch { margin-inline-start: 0; }

  /* These pinned themselves below a fixed-height bar that is now static. */
  .yearhead, .pageside, .ext-runbar { top: 0; }
  .pageside { position: static; }

  /* Four fixed columns overflowed a 390px screen by ~18px. */
  .hero-stats { grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    gap: 0.6rem 1rem; }

  h1 { font-size: 1.4rem; }

  /* Rows of labels, badges and buttons laid out with flex and no wrap. On a
     desktop they always fit, so nothing here changes; on a phone each was a
     single line wider than the screen. `.prompthead` was the one the audit
     caught — the rest are the same shape and are fixed pre-emptively rather
     than one bug report at a time. */
  .pagehead-row, .flash, .sidecard-head, .metarow, .ws-sortwrap, .wscard-head,
  .editactions, .prompthead, .mergerow, .ext-defactions, .sm-head, .wiz-nav,
  .ing-tab, .ing-fileitem, .ing-force, .chat-controls { flex-wrap: wrap; }

  /* Give the page title the whole row so the buttons beside it drop below
     instead of squeezing a long workspace name into a three-line column. */
  .pagehead-row > h1 { width: 100%; }

  /* A long unbroken token (a hash, a URL, an Arabic filename) is the other way
     a phone page gets a sideways scrollbar. */
  code, .metaval, .loglist li, .entitylist li { overflow-wrap: anywhere; }
}

/* Wide content scrolls inside its own box rather than widening the document.
   `.tablewrap` (above) already does this for data tables; these are the
   remaining things that can be wider than a phone. */
@media (max-width: 760px) {
  .mdbody { padding: var(--sp-3); }
  .mdbody pre, .mdbody table { display: block; overflow-x: auto;
    max-width: 100%; }
  pre, .codeblock { overflow-x: auto; max-width: 100%; }
}
