/* ── Design tokens (mirrors TenderRobot workspace) ────────────── */
:root {
  --ws-bg: #f5f6f8;
  --ws-surface: #ffffff;
  --ws-border: #d8dee8;
  --ws-text: #172033;
  --ws-muted: #667085;
  --ws-soft: #8a94a6;
  --ws-primary: #1f6feb;
  --ws-primary-dark: #174ea6;
  --ws-radius: 8px;
  --ws-radius-sm: 6px;
}

body {
  margin: 0;
  background: var(--ws-bg);
  color: var(--ws-text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ── Shell grid ────────────────────────────────────────────────── */
.ws-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  transition: grid-template-columns 0.18s ease;
}

.ws-shell.is-sidebar-collapsed {
  grid-template-columns: 80px minmax(0, 1fr);
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.ws-sidebar {
  box-sizing: border-box;
  min-height: 100vh;
  padding: 1rem;
  background: #111827;
  color: #e5e7eb;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ws-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ws-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.2rem 0.1rem;
  color: #fff;
  font-weight: 800;
  text-decoration: none;
}

.ws-brand:hover { color: #fff; text-decoration: none; }

.ws-sidebar-toggle {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--ws-radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: #d1d5db;
  cursor: pointer;
}

.ws-sidebar-toggle:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

.ws-sidebar-toggle .material-symbols-outlined { font-size: 1.05rem; }

/* ── Nav ───────────────────────────────────────────────────────── */
.ws-nav {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
  flex: 1;
}

.ws-nav-section { min-width: 0; }

.ws-nav-title {
  padding: 0 0.5rem 0.35rem;
  color: #8792a5;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ws-nav-list { display: grid; gap: 0.18rem; }

.ws-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  padding: 0.65rem 0.7rem;
  border-radius: var(--ws-radius-sm);
  color: #d1d5db;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
}

.ws-nav a:hover { background: rgba(255, 255, 255, 0.09); color: #fff; }
.ws-nav a.is-active { background: var(--ws-primary); color: #fff; }
.ws-nav a.bidui-danger-link { color: #f87171; }
.ws-nav a.bidui-danger-link:hover { background: rgba(239, 68, 68, 0.12); color: #fca5a5; }

.ws-nav .material-symbols-outlined { font-size: 1.15rem; flex: 0 0 1.15rem; }

.ws-nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Sidebar footer ────────────────────────────────────────────── */
.ws-sidebar-foot {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.ws-sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--ws-radius-sm);
  color: #d1d5db;
  font-size: 0.85rem;
  overflow: hidden;
}

.ws-sidebar-user .material-symbols-outlined { font-size: 1.15rem; flex: 0 0 1.15rem; color: #8792a5; }

.ws-sidebar-logout {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.7rem;
  border-radius: var(--ws-radius-sm);
  color: #8792a5;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.ws-sidebar-logout .material-symbols-outlined { font-size: 1.15rem; flex: 0 0 1.15rem; }
.ws-sidebar-logout:hover { background: rgba(255, 255, 255, 0.06); color: #e5e7eb; }

.bidui-version {
  padding: 0.2rem 0.7rem;
  font-size: 0.72rem;
  color: #4b5563;
}

/* ── Collapsed rail ────────────────────────────────────────────── */
.ws-shell.is-sidebar-collapsed .ws-sidebar { padding: 1rem 0.5rem; }

.ws-shell.is-sidebar-collapsed .ws-sidebar-head {
  justify-content: center;
  padding-bottom: 0.75rem;
}

.ws-shell.is-sidebar-collapsed .ws-brand { display: none; }
.ws-shell.is-sidebar-collapsed .ws-sidebar-toggle { width: 2.2rem; }

.ws-shell.is-sidebar-collapsed .ws-nav { align-items: stretch; gap: 0.5rem; }
.ws-shell.is-sidebar-collapsed .ws-nav-section { width: 100%; }

.ws-shell.is-sidebar-collapsed .ws-nav-title {
  height: 1px;
  margin: 0.2rem 0.5rem;
  padding: 0;
  overflow: hidden;
  color: transparent;
  background: rgba(255, 255, 255, 0.12);
}

.ws-shell.is-sidebar-collapsed .ws-nav-list { justify-items: stretch; }

.ws-shell.is-sidebar-collapsed .ws-nav a {
  width: 100%;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.2rem;
  padding: 0.55rem 0.25rem;
}

.ws-shell.is-sidebar-collapsed .ws-nav .material-symbols-outlined {
  flex-basis: auto;
  font-size: 1.5rem;
}

.ws-shell.is-sidebar-collapsed .ws-nav-label {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-align: center;
  width: 100%;
  color: #8792a5;
}

.ws-shell.is-sidebar-collapsed .ws-nav a:hover .ws-nav-label,
.ws-shell.is-sidebar-collapsed .ws-nav a.is-active .ws-nav-label { color: #e5e7eb; }

.ws-shell.is-sidebar-collapsed .ws-sidebar-user,
.ws-shell.is-sidebar-collapsed .ws-sidebar-logout {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.5rem 0.25rem;
}

.ws-shell.is-sidebar-collapsed .ws-sidebar-user .material-symbols-outlined,
.ws-shell.is-sidebar-collapsed .ws-sidebar-logout .material-symbols-outlined {
  flex-basis: auto;
  font-size: 1.5rem;
}

.ws-shell.is-sidebar-collapsed .ws-sidebar-foot .ws-nav-label,
.ws-shell.is-sidebar-collapsed .bidui-version { display: none; }

/* ── Main content area ─────────────────────────────────────────── */
.ws-main { min-width: 0; display: flex; flex-direction: column; }

.ws-topbar {
  box-sizing: border-box;
  height: 60px;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ws-surface);
  border-bottom: 1px solid var(--ws-border);
  flex: 0 0 auto;
}

.bidui-page-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  color: var(--ws-text);
}

.ws-content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

/* ── Log panel (unchanged) ─────────────────────────────────────── */
.log-panel {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  background: #0b0f14;
  color: #d8e1ec;
  padding: 1rem;
  border-radius: 0.375rem;
  white-space: pre-wrap;
  max-height: 60vh;
  overflow: auto;
}

/* ── Section editor ────────────────────────────────────────────── */
.bidui-sec-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--ws-bg);
  padding: 0.75rem 0;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--ws-border);
}

/* ── Section rows (aligned column grid) ─────────────────────────────
   One shared column template drives every row so the title / preview /
   compliance / score / workflow / edit cells line up vertically down the list.
   Fixed & minmax tracks only (never content-sized `auto`) so the columns align
   across rows without subgrid. Declared once on the list container; each row
   and the header read it via var(). */
#section-list {
  --bidui-sec-cols:
    minmax(13rem, 19rem)  /* 1 title  */
    minmax(0, 1fr)        /* 2 body preview */
    10rem                 /* 3 compliance */
    3.5rem                /* 4 score ring */
    14rem                 /* 5 workflow */
    4.5rem;               /* 6 edit   */
}
.bidui-sec-row {
  display: grid;
  grid-template-columns: var(--bidui-sec-cols);
  align-items: start;
  column-gap: 1rem;
  row-gap: 0.4rem;
  padding: 0.7rem 0.25rem;
  border-bottom: 1px solid var(--ws-border);
}
.bidui-sec-row:hover { background: rgba(127, 127, 127, 0.06); }
/* Full-span sub-rows: draft banner, error alert, score popover. */
.bidui-sec-full { grid-column: 1 / -1; }
.bidui-score-pop-holder:empty { display: none; }
.bidui-score-pop-holder { margin-top: 0.25rem; }
/* Title cell: heading row + a muted meta line under it. */
.bidui-sec-title { min-width: 0; }
.bidui-sec-title .bidui-focus-link { overflow-wrap: anywhere; }
.bidui-sec-meta { margin-top: 0.15rem; }
.bidui-sec-preview { min-width: 0; }
/* Short cells align to the row top and centre their control. */
.bidui-sec-score { display: flex; justify-content: center; }
.bidui-sec-edit { display: flex; justify-content: flex-end; }
.bidui-sec-workflow { display: flex; flex-direction: column; gap: 0.35rem; }
.bidui-sec-wf-btns { row-gap: 0.35rem; }
/* Column-header row inside the (already sticky) toolbar — same track template. */
.bidui-sec-headrow {
  display: grid;
  grid-template-columns: var(--bidui-sec-cols);
  column-gap: 1rem;
  padding: 0.4rem 0.25rem 0.15rem;
  margin-top: 0.6rem;
  border-top: 1px solid var(--ws-border);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ws-muted);
}
/* Row-context body clamp is 3 lines (the standalone .bidui-clamp is 6). The
   Show-more :checked rule still wins (higher specificity) and expands it. */
.bidui-sec-row .bidui-clamp { -webkit-line-clamp: 3; }

/* Below lg: drop the columns. Title + preview each take a full line, then the
   four controls sit together on one wrapping row; the header row is hidden. */
@media (max-width: 991.98px) {
  .bidui-sec-headrow { display: none; }
  .bidui-sec-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 1rem;
  }
  .bidui-sec-title,
  .bidui-sec-preview,
  .bidui-sec-full { flex: 1 1 100%; }
  .bidui-sec-compliance,
  .bidui-sec-score,
  .bidui-sec-workflow,
  .bidui-sec-edit { flex: 0 0 auto; }
  .bidui-sec-workflow { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .bidui-sec-edit { margin-left: auto; }
}

.bidui-section-body > *:first-child { margin-top: 0; }
.bidui-section-body > *:last-child { margin-bottom: 0; }

/* CSS-only "Show more" clamp — no JS. The hidden checkbox toggles the clamp. */
.bidui-more-toggle { position: absolute; opacity: 0; pointer-events: none; }
.bidui-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bidui-more-toggle:checked ~ .bidui-clamp {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}
.bidui-more-label {
  display: inline-block;
  margin-top: 0.5rem;
  cursor: pointer;
  color: var(--ws-primary);
  font-size: 0.85rem;
  user-select: none;
}
.bidui-more-label::after { content: "Show more"; }
.bidui-more-toggle:checked ~ .bidui-more-label::after { content: "Show less"; }

/* CSS-only Write/Preview tabs — the radios drive pane visibility + tab state. */
.bidui-tab-w, .bidui-tab-p { position: absolute; opacity: 0; pointer-events: none; }
.bidui-preview-pane { display: none; }
.bidui-tab-p:checked ~ .bidui-write-pane { display: none; }
.bidui-tab-p:checked ~ .bidui-preview-pane { display: block; }
.bidui-tab-w:checked ~ .bidui-tabbar label[for^="tabw-"],
.bidui-tab-p:checked ~ .bidui-tabbar label[for^="tabp-"] {
  background-color: var(--ws-primary);
  border-color: var(--ws-primary);
  color: #fff;
}
.bidui-body-textarea { min-height: 14rem; }

/* ── Score ring ────────────────────────────────────────────────── */
.bidui-ring-btn { line-height: 0; }
.bidui-ring { display: inline-flex; vertical-align: middle; line-height: 0; }
.bidui-ring svg { display: block; }
.bidui-ring-track { stroke: var(--ws-border); }
.bidui-ring-fill { stroke: var(--ws-soft); }
.bidui-ring-text { font-size: 11px; font-weight: 700; fill: var(--ws-text); }
/* Fresh rings are color-banded by score. */
.bidui-ring-green .bidui-ring-fill { stroke: #198754; }  /* success */
.bidui-ring-amber .bidui-ring-fill { stroke: #fd7e14; }  /* caution */
.bidui-ring-red   .bidui-ring-fill { stroke: #dc3545; }  /* danger  */
/* Provisional: unverified or stale — mute the band + dash the track so the
   colour is visibly "don't trust me yet". The number still shows. */
.bidui-ring-provisional .bidui-ring-fill { stroke: var(--ws-soft); opacity: 0.7; }
.bidui-ring-provisional .bidui-ring-track { stroke-dasharray: 2 2; }
.bidui-ring-none .bidui-ring-text { fill: var(--ws-muted); }
/* Score breakdown popover table is compact. */
.bidui-score-table td { padding: 0.2rem 0.4rem; }
.bidui-chip .dropdown-toggle::after { margin-left: 0.35rem; }

/* ── Focus mode ────────────────────────────────────────────────── */
/* The card heading links into the full-page focus surface. */
.bidui-focus-link { color: inherit; text-decoration: none; }
.bidui-focus-link:hover { text-decoration: underline; }
/* Deep-work editor is taller than the inline card editor. */
.bidui-focus-textarea { min-height: 24rem; }
.bidui-focus-readonly { background: var(--ws-surface, #fff); }
/* Server-rendered unified diff. */
.bidui-diff { white-space: pre-wrap; word-break: break-word; }
.bidui-diff code { background: none; padding: 0; }
.bidui-diff-add  { display: block; background: rgba(25, 135, 84, 0.12); }
.bidui-diff-del  { display: block; background: rgba(220, 53, 69, 0.12); }
.bidui-diff-hunk { display: block; color: var(--ws-muted); }
.bidui-diff-meta { display: block; color: var(--ws-muted); font-weight: 600; }
.bidui-diff-ctx  { display: block; }
/* Resolved comments dim + collapse; the Reopen toggle expands them. */
.bidui-comment { padding: 0.25rem 0; }
.bidui-comment-resolved { opacity: 0.6; }
.bidui-comment-collapsed { max-height: 3.2rem; overflow: hidden; }
.bidui-reply-toggle { cursor: pointer; }
