/* ═══════════════════════════════════════════════
   Ragman Web – Styles
   ═══════════════════════════════════════════════ */

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #23273a;
  --border: #2d3148;
  --text: #e4e6f0;
  --text-muted: #8b8fa8;
  --accent: #5b8def;
  --accent-dim: #3a5faa;
  --accent-bg: rgba(91, 141, 239, 0.08);
  --green: #4ec9a0;
  --orange: #e0a458;
  --red: #e05858;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,.35);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

#app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 2rem;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1rem;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
}
header h1 {
  display: inline-flex; align-items: center; gap: .6rem;
  font-size: 1.35rem; font-weight: 600; color: var(--accent);
}
.logout-btn {
  font-size: .82rem; color: var(--text-muted);
  padding: .3rem .8rem; border: 1px solid var(--border);
  border-radius: 6px; text-decoration: none;
  transition: color .15s, background .15s;
}
.logout-btn:hover { color: var(--text); background: var(--surface-hover); }

/* ── Main navigation ── */
#main-nav {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}
.nav-item {
  padding: .65rem 1.6rem;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-muted); cursor: pointer; font-size: .95rem;
  font-family: var(--font); font-weight: 500;
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
}
.nav-item:hover { color: var(--text); }
.nav-item.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Sub-navigation ── */
#sub-nav {
  display: flex; align-items: center; gap: .45rem; flex-wrap: wrap;
  padding: .55rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  min-height: 46px;
}
.subnav-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); padding: .3rem .9rem; border-radius: 6px;
  cursor: pointer; font-size: .82rem; font-family: var(--font);
  transition: background .15s, color .15s;
}
.subnav-btn:hover { background: var(--surface-hover); color: var(--text); }
.subnav-btn.primary {
  background: var(--accent-dim); color: #fff; border-color: var(--accent-dim);
}
.subnav-btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.subnav-btn.danger { color: var(--red); border-color: rgba(224,88,88,.3); }
.subnav-btn.danger:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Content area ── */
#content { min-height: 240px; }

/* ── Section title ── */
.section-title {
  font-size: .78rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 1rem;
}

/* ── Item grid (checklist set folders) ── */
.item-grid {
  display: flex; flex-wrap: wrap; gap: .9rem; padding: .25rem 0;
}
.folder-card {
  display: flex; flex-direction: column; align-items: center; gap: .4rem;
  padding: .85rem .7rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; width: 120px;
  transition: background .15s, border-color .15s; user-select: none;
}
.folder-card:hover { background: var(--surface-hover); border-color: var(--accent-dim); }
.folder-card.selected {
  background: var(--accent-bg); border-color: var(--accent);
  outline: 1px solid rgba(91,141,239,.3);
}
.folder-icon { font-size: 2rem; line-height: 1; }
.folder-name {
  font-size: .78rem; color: var(--text); text-align: center;
  word-break: break-word; max-width: 108px; line-height: 1.3;
}

/* ── File list (checklist files inside a CHS) ── */
.file-list { display: flex; flex-direction: column; gap: .2rem; max-width: 680px; }
.file-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .4rem .7rem; border-radius: 6px; cursor: pointer;
  font-size: .9rem; transition: background .12s; user-select: none;
}
.file-item:hover { background: var(--surface-hover); }
.file-item.selected {
  background: rgba(91, 141, 239, .1);
  outline: 1px solid rgba(91,141,239,.3);
}
.file-icon { color: var(--text-muted); font-size: .95rem; flex-shrink: 0; }
.file-name { color: var(--text); }
.file-action-btn {
  margin-left: auto; padding: .2rem .65rem; border-radius: 5px;
  font-size: .75rem; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); flex-shrink: 0;
  transition: background .15s, color .15s, border-color .15s;
}
.file-action-btn:hover { background: var(--surface-hover); color: var(--text); }
.file-action-btn.danger { color: var(--red); border-color: rgba(224,88,88,.3); }
.file-action-btn.danger:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Empty state ── */
.empty-state {
  padding: 2.5rem 1rem; text-align: center;
  color: var(--text-muted); font-size: .9rem;
}
.empty-state p + p { margin-top: .4rem; font-size: .82rem; }

/* ── Inline loading ── */
.content-loading {
  display: flex; flex-direction: column; align-items: center;
  gap: .6rem; padding: 3rem 1rem; color: var(--text-muted); font-size: .9rem;
}
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Inline error ── */
.content-error {
  background: rgba(224, 88, 88, .1); border: 1px solid var(--red);
  color: var(--red); border-radius: var(--radius);
  padding: .9rem 1.2rem; font-size: .9rem; max-width: 600px;
}

/* ── Modal overlay ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, .6); display: flex;
  align-items: center; justify-content: center; backdrop-filter: blur(3px);
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,.5);
  width: min(560px, 92vw); max-height: 85vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1.2rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; color: var(--accent); }
.modal-close-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.3rem; cursor: pointer; line-height: 1; padding: 0 .2rem;
  transition: color .15s;
}
.modal-close-btn:hover { color: var(--red); }
#modal-body { overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: .5rem;
  padding: .8rem 1.2rem; border-top: 1px solid var(--border);
}
#modal-footer-extra { display: contents; }
.modal-btn {
  padding: .4rem 1.1rem; border-radius: 6px; font-size: .85rem;
  font-family: var(--font); cursor: pointer; border: 1px solid var(--border);
  transition: background .15s, color .15s;
}
.modal-btn-cancel { background: var(--surface); color: var(--text-muted); }
.modal-btn-cancel:hover { background: var(--surface-hover); color: var(--text); }
.modal-btn-save { background: var(--accent-dim); color: #fff; border-color: var(--accent-dim); }
.modal-btn-save:hover { background: var(--accent); border-color: var(--accent); }
.modal-btn-danger { background: rgba(224,88,88,.15); color: var(--red); border-color: rgba(224,88,88,.4); }
.modal-btn-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Modal form fields ── */
.modal-form { padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: .9rem; }
.modal-field { display: flex; flex-direction: column; gap: .3rem; }
.modal-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; }
.modal-input {
  padding: .5rem .8rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: .9rem;
  font-family: var(--font); outline: none; transition: border-color .2s;
  width: 100%;
}
.modal-input:focus { border-color: var(--accent); }
.modal-file-input { color: var(--text); font-size: .88rem; }
.modal-msg {
  padding: .9rem 1.2rem; font-size: .9rem; color: var(--text); line-height: 1.5;
}
.modal-msg strong { color: var(--accent); }

/* ── Toast notifications ── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 2000;
  padding: .6rem 1.2rem; border-radius: 8px; font-size: .88rem;
  box-shadow: var(--shadow); max-width: 380px;
  animation: toast-in .18s ease;
}
.toast.success {
  background: rgba(78,201,160,.14); border: 1px solid var(--green); color: var(--green);
}
.toast.error {
  background: rgba(224,88,88,.12); border: 1px solid var(--red); color: var(--red);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Login ── */
.login-wrapper {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2.2rem 2rem;
  width: 100%; max-width: 380px; box-shadow: var(--shadow);
}
.login-header {
  display: flex; align-items: center; gap: .7rem;
  justify-content: center; margin-bottom: .6rem; color: var(--accent);
}
.login-header h1 { font-size: 1.4rem; font-weight: 700; }
.login-subtitle {
  text-align: center; color: var(--text-muted); font-size: .88rem; margin-bottom: 1.4rem;
}
.login-error {
  background: rgba(224,88,88,.12); border: 1px solid var(--red);
  color: var(--red); border-radius: 6px; padding: .5rem .9rem;
  font-size: .85rem; margin-bottom: 1rem;
}
.login-form { display: flex; flex-direction: column; gap: .7rem; }
.login-input {
  padding: .6rem .9rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: 7px; color: var(--text); font-size: .95rem;
  font-family: var(--font); outline: none; transition: border-color .2s; width: 100%;
}
.login-input:focus { border-color: var(--accent); }
.login-btn {
  padding: .6rem; background: var(--accent-dim); color: #fff;
  border: none; border-radius: 7px; font-size: .95rem; font-family: var(--font);
  cursor: pointer; font-weight: 600; transition: background .15s;
}
.login-btn:hover { background: var(--accent); }

/* ── Progress overlay ── */
.progress-overlay {
  position: fixed; inset: 0; z-index: 1500;
  background: rgba(0, 0, 0, .65); display: flex;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 1.2rem; backdrop-filter: blur(4px);
  animation: toast-in .15s ease;
}
.progress-spinner {
  width: 52px; height: 52px; border: 4px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .75s linear infinite;
}
.progress-label {
  font-size: .95rem; color: var(--text-muted); max-width: 320px;
  text-align: center; line-height: 1.5;
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Batch module ── */
.batch-list {
  display: flex; flex-direction: column; gap: .5rem;
}
.batch-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem 1rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
}
.batch-info {
  display: flex; align-items: center; gap: .45rem;
  flex-wrap: wrap; min-width: 0;
}
.batch-op     { font-weight: 600; font-size: .9rem; }
.batch-sep    { color: var(--text-muted); font-size: .85rem; }
.batch-target { color: var(--text-muted); font-size: .88rem; }
.batch-meta   { display: flex; align-items: center; gap: .6rem; flex-shrink: 0; }
.batch-ts     { font-size: .85rem; color: var(--text); font-weight: 600; }
.batch-badge  {
  font-size: .72rem; font-weight: 600; padding: .2rem .5rem;
  border-radius: 99px; white-space: nowrap;
}
.action-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); padding: .2rem .7rem; border-radius: 6px;
  cursor: pointer; font-size: .78rem; font-family: var(--font);
  transition: background .15s, color .15s; white-space: nowrap;
}
.action-btn:hover { background: var(--surface-hover); color: var(--text); }
.action-btn-danger  { color: var(--red);    border-color: rgba(224,88,88,.3); }
.action-btn-danger:hover  { background: var(--red);    color: #fff; border-color: var(--red); }
.action-btn-warning { color: var(--orange); border-color: rgba(224,164,88,.3); }
.action-btn-warning:hover { background: var(--orange); color: #fff; border-color: var(--orange); }
.action-btn-success { color: var(--green);  border-color: rgba(78,201,160,.3); }
.action-btn-success:hover { background: var(--green);  color: #fff; border-color: var(--green); }
.badge-completed  { background: rgba(78,201,160,.12); color: var(--green); }
.badge-inprogress   { background: rgba(224,164,88,.12);  color: var(--orange); }
.badge-interrupted  { background: rgba(239,68,68,.12);   color: #f87171; }
.badge-processed    { background: rgba(34,197,94,.12);   color: #4ade80; font-size: .68rem; padding: .15rem .45rem; border-radius: .25rem; }
.badge-inferred     { display: inline-block; text-align: center; line-height: 1.25; background: rgba(34,197,94,.12);  color: #4ade80; font-size: .65rem; padding: .15rem .5rem; border-radius: .25rem; }
.badge-corrected    { display: inline-block; text-align: center; line-height: 1.25; background: rgba(56,189,248,.12); color: #38bdf8; font-size: .65rem; padding: .15rem .5rem; border-radius: .25rem; }
.badge-indexed      { display: inline-block; text-align: center; line-height: 1.25; background: rgba(168,85,247,.15); color: #c084fc; font-size: .65rem; padding: .15rem .5rem; border-radius: .25rem; }

/* ── Integrity report modal ── */
.modal-wide         { width: min(860px, 96vw) !important; }
.integrity-summary  { padding: .8rem 1.2rem; border-bottom: 1px solid var(--border); }
.integrity-sum-grid { display: flex; gap: .8rem; flex-wrap: wrap; }
.isum-cell          { display: flex; flex-direction: column; align-items: center; background: var(--surface-hover); border-radius: 6px; padding: .4rem .8rem; min-width: 82px; }
.isum-label         { font-size: .65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.isum-val           { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.isum-val.ok        { color: var(--green); }
.isum-val.pct-warn  { color: var(--orange); }
.isum-val.pct-bad   { color: var(--red); }
.integrity-docs     { padding: .6rem 1.2rem 1rem; overflow-y: auto; max-height: 52vh; }
.integrity-doc      { margin-bottom: .6rem; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.integrity-doc summary { cursor: pointer; padding: .45rem .8rem; background: var(--surface-hover); display: flex; align-items: center; justify-content: space-between; font-size: .83rem; font-weight: 600; list-style: none; }
.integrity-doc summary::-webkit-details-marker { display: none; }
.idoc-stats         { font-size: .76rem; color: var(--text-muted); font-weight: 400; }
.integrity-table    { width: 100%; border-collapse: collapse; font-size: .76rem; }
.integrity-table th { text-align: center; color: var(--text-muted); font-weight: 600; padding: .28rem .35rem; border-bottom: 1px solid var(--border); background: var(--bg); white-space: nowrap; }
.integrity-table th:first-child { text-align: left; padding-left: .6rem; }
.integrity-table td { text-align: center; padding: .22rem .35rem; border-bottom: 1px solid var(--border); }
.integrity-table td:first-child { text-align: left; font-family: monospace; font-size: .73rem; padding-left: .6rem; }
.ifield-ok          { color: var(--green); }
.ifield-fail        { color: var(--red); }
.ibadge-complete    { color: var(--green); font-weight: 700; }
.ibadge-incomplete  { color: var(--red); font-weight: 700; }

/* ── Batch log modal ── */
.batch-log-wrap {
  overflow: hidden; display: flex; flex-direction: column;
}
.batch-log-pre {
  font-family: "Consolas", "Courier New", monospace;
  font-size: .78rem; line-height: 1.55;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .8rem 1rem;
  margin: 0; white-space: pre-wrap; word-break: break-all;
  overflow-y: auto; max-height: 440px;
  color: var(--text);
}

/* Resizable modal variant — pulled out of flex flow so resize:both works */
.modal-resizable {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(760px, 94vw);
  max-width: 98vw;
  max-height: 92vh;
  min-width: 360px;
  min-height: 260px;
  resize: both;
  overflow: hidden;    /* required by CSS resize */
}
.modal-resizable .batch-log-pre {
  max-height: none;
  flex: 1 1 0;
  min-height: 0;
}
.modal-resizable #modal-body {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.modal-resizable .batch-log-wrap {
  flex: 1 1 0;
  min-height: 0;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  #app { padding: 1rem .8rem 1.5rem; }
  .folder-card { width: 100px; }
  .nav-item { padding: .6rem 1rem; font-size: .88rem; }
}

/* ── Assessments Module (00600) ─────────────────────────────────────────── */

.assessments-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  padding: 1.25rem;
  height: 100%;
  overflow: auto;
}

.assessments-panel {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

@media (max-width: 700px) {
  .assessments-layout { grid-template-columns: 1fr; }
}

/* ── Hierarchy Correction (00530) ───────────────────────────────────────── */

.hc-layout {
  display: grid;
  gap: 1rem;
  height: calc(100vh - 10rem);
  overflow: hidden;
  grid-template-columns: 260px 1fr;   /* sidebar open */
}
.hc-layout.hc-sidebar-closed {
  grid-template-columns: 36px 1fr;    /* sidebar collapsed to icon strip */
}

/* ── Sidebar ── */
.hc-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
  padding: .5rem 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: none;
}
/* Collapsed: hide everything except the open button */
.hc-sidebar.hc-sidebar-collapsed {
  overflow: hidden;
  padding: .35rem 0;
  align-items: center;
}
.hc-sidebar.hc-sidebar-collapsed > *:not(.hc-sidebar-open-btn) {
  display: none;
}
.hc-sidebar-open-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.05rem;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color .12s, border-color .12s;
}
.hc-sidebar.hc-sidebar-collapsed .hc-sidebar-open-btn {
  display: flex;
}
.hc-sidebar-open-btn:hover { color: var(--accent); border-color: var(--accent); }
/* Collapse button inside the expanded sidebar header */
.hc-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .3rem .7rem .3rem 1rem;
  flex-shrink: 0;
}
.hc-sidebar-header-title {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.hc-sidebar-collapse-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .75rem;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}
.hc-sidebar-collapse-btn:hover { color: var(--text); border-color: var(--text-muted); }
.hc-section-title {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: .6rem 1rem .3rem;
  margin-top: .25rem;
}
.hc-empty {
  font-size: .8rem;
  color: var(--text-muted);
  padding: .3rem 1rem .5rem;
}
.hc-file-item {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .32rem 1rem;
  cursor: pointer;
  font-size: .83rem;
  transition: background .12s;
  flex-wrap: wrap;
}
.hc-file-item:hover  { background: var(--surface-hover); }
.hc-file-item.active { background: rgba(91,141,239,.13); color: var(--accent); }
.hc-file-icon { flex-shrink: 0; font-size: .82rem; }
.hc-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.hc-file-date {
  font-size: .7rem;
  color: var(--text-muted);
  width: 100%;
  padding-left: 1.6rem;
  margin-top: -.1rem;
}
.hc-has-tmp       { flex-shrink: 0; font-size: .8rem; }
.hc-badge-confirmed { flex-shrink: 0; font-size: .8rem; font-weight: 700; color: var(--green, #4caf50); }
.hc-tmp-actions { display: flex; gap: 2px; margin-left: auto; flex-shrink: 0; }
.hc-tmp-btn {
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 3px;
  cursor: pointer;
  font-size: .68rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.hc-tmp-btn.hc-tmp-load:hover { background: var(--accent);      color: #fff; border-color: var(--accent); }
.hc-tmp-btn.hc-tmp-del:hover  { background: var(--danger, #e05);  color: #fff; border-color: var(--danger, #e05); }

/* ── Editor area ── */
.hc-editor {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.hc-editor-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: .9rem;
  text-align: center;
  padding: 2rem;
}
.hc-editor-header { margin-bottom: .5rem; flex-shrink: 0; }
.hc-editor-header h2 { font-size: 1rem; font-weight: 600; margin-bottom: .25rem; }
.hc-stats {
  font-size: .78rem;
  color: var(--text-muted);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ── Dual panel ── */
.hc-dual-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.hc-dual-panel.source-expanded { grid-template-columns: 1fr 1fr; }
.hc-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.hc-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
  flex-wrap: wrap;
  gap: .4rem;
  flex-shrink: 0;
}
.hc-panel-header h3 { font-size: .9rem; font-weight: 600; margin: 0; }
.hc-panel-actions { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.hc-inline-save-btn {
  background: none; border: none; cursor: pointer; font-size: 1rem;
  padding: 0 .2rem; line-height: 1; opacity: .75; transition: opacity .15s;
}
.hc-inline-save-btn:hover { opacity: 1; }
.hc-inline-save-btn.hidden { display: none; }
.hc-inline-pdf-btn {
  display: inline-flex; align-items: center; gap: .25rem;
  background: none; border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-muted); text-decoration: none;
  font-size: .72rem; padding: .15rem .45rem; line-height: 1;
  opacity: .8; transition: opacity .15s, background .15s;
}
.hc-inline-pdf-btn:hover { opacity: 1; background: var(--surface-alt, rgba(255,255,255,.07)); }
.hc-search-input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: .22rem .6rem;
  font-size: .78rem;
  outline: none;
  width: 120px;
}
.hc-search-input:focus { border-color: var(--accent); }

/* Source panel collapsed state */
.hc-panel-source.hc-source-collapsed { min-width: 0; width: auto; }
.hc-panel-source.hc-source-collapsed .hc-origin-header { display: none; }
.hc-panel-source.hc-source-collapsed .hc-tree-container { display: none; }

.origin-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 700;
  padding: .18rem .42rem;
  align-self: flex-start;
  flex-shrink: 0;
  transition: color .12s, border-color .12s;
  margin-bottom: .35rem;
}
.origin-toggle-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ── Selection toolbar ── */
.hc-sel-toolbar {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  padding: .35rem .7rem;
  margin-bottom: .4rem;
  background: rgba(91,141,239,.07);
  border: 1px solid rgba(91,141,239,.2);
  border-radius: 6px;
  flex-shrink: 0;
}
.hc-sel-count { font-size: .8rem; font-weight: 600; color: var(--accent); margin-right: .2rem; }
.sel-btn {
  padding: .2rem .55rem;
  font-size: .78rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.sel-btn:hover        { background: var(--surface-hover); }
.sel-btn.sel-btn-muted { color: var(--text-muted); }
.sel-btn.sel-btn-danger:hover { background: var(--danger, #e05); color: #fff; border-color: var(--danger, #e05); }

/* ── Tree containers ── */
.hc-tree-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.hc-tree-container ul { list-style: none; padding-left: 1.3rem; margin: 0; }
.hc-tree-container > ul { padding-left: 0; }
.hc-tree-container li { position: relative; margin: .1rem 0; }
.hc-tree-container ul ul { border-left: 1px solid var(--border); margin-left: .5rem; }
.hc-tree-container .tree-node {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .18rem .45rem;
  border-radius: 5px;
  cursor: default;
  transition: background .12s;
  max-width: 100%;
  box-sizing: border-box;
}
.hc-tree-container .tree-node:hover  { background: var(--surface-hover); }
.hc-tree-container .tree-node.selected { background: rgba(91,141,239,.12); }
.hc-tree-container .hidden { display: none; }
.hc-empty-tree {
  color: var(--text-muted);
  font-size: .85rem;
  text-align: center;
  padding: 1.5rem 1rem;
  margin: 0;
}
.search-match { background: rgba(255,200,0,.15); border-radius: 3px; }

/* ── Tree node parts ── */
.toggle {
  flex-shrink: 0;
  cursor: pointer;
  font-size: .7rem;
  color: var(--text-muted);
  width: 14px;
  text-align: center;
  transition: color .12s;
}
.toggle:hover { color: var(--text); }
.toggle.collapsed { transform: rotate(-90deg); display: inline-block; }
.node-checkbox { flex-shrink: 0; cursor: pointer; width: 14px; height: 14px; }
.drag-handle {
  flex-shrink: 0;
  cursor: grab;
  color: var(--text-muted);
  font-size: .9rem;
  padding: 0 .1rem;
  line-height: 1;
}
.drag-handle:active { cursor: grabbing; }
.dragging { opacity: .45; }
.drop-above { border-top: 2px solid var(--accent); }
.drop-below { border-bottom: 2px solid var(--accent); }
.level-indicator {
  flex-shrink: 0;
  font-size: .65rem;
  font-weight: 700;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 .28rem;
  color: var(--text-muted);
  letter-spacing: -.02em;
}
.icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  font-size: .68rem;
  font-weight: 700;
}
.icon-title   { background: rgba(255,160,0,.18);  color: #b36b00; }
.icon-section { background: rgba(91,141,239,.18); color: var(--accent); }
.icon-para    { background: rgba(120,120,120,.12); color: var(--text-muted); }
.label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .83rem;
  cursor: default;
}
.label.role-title          { font-weight: 700; color: var(--text); }
.label.role-sectionHeading { font-weight: 600; }
.label.role-paragraph      { color: var(--text-muted); font-size: .78rem; }

/* ── Node action buttons ── */
.hierarchy-btns {
  display: none;
  align-items: center;
  gap: 2px;
  margin-left: .3rem;
  flex-shrink: 0;
}
.tree-node:hover .hierarchy-btns { display: inline-flex; }
.btn-promote, .btn-demote, .btn-edit, .btn-remove, .btn-add-to-corrected {
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 3px;
  cursor: pointer;
  font-size: .72rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .1s, color .1s;
  flex-shrink: 0;
}
.btn-promote:hover, .btn-demote:hover, .btn-edit:hover { background: var(--surface-hover); color: var(--text); }
.btn-promote:disabled, .btn-demote:disabled { opacity: .3; cursor: default; }
.btn-remove:hover          { background: var(--danger, #e05); color: #fff; border-color: var(--danger, #e05); }
.btn-add-to-corrected:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-add-to-corrected:disabled { opacity: .3; cursor: default; }

/* ── Edit dropdown ── */
.edit-dropdown-wrap { position: relative; display: inline-flex; }
.edit-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 3px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  z-index: 200;
  min-width: 180px;
  padding: .3rem 0;
}
.edit-dropdown.open { display: block; }
.edit-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: .35rem .9rem;
  background: none;
  border: none;
  color: var(--text);
  font-size: .83rem;
  cursor: pointer;
  white-space: nowrap;
}
.edit-dropdown button:hover { background: var(--surface-hover); }
