:root {
  --bg: #0b1020;
  --panel: #111a30;
  --panel2: #0f172a;
  --text: #eef3ff;
  --muted: #9eacd0;
  --line: rgba(255,255,255,.10);
  --lineStrong: rgba(255,255,255,.17);
  --accent: #76a9ff;
  --accentSoft: rgba(118,169,255,.16);
  --green: #7ce6bf;
  --greenSoft: rgba(124,230,191,.13);
  --danger: #ff8080;
  --dangerSoft: rgba(255,128,128,.10);
  --shadow: 0 14px 36px rgba(0,0,0,.28);
  --radius: 16px;
  --radiusSmall: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(1000px 600px at 10% -10%, rgba(72,126,255,.20), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(81,219,176,.11), transparent 60%),
    var(--bg);
  color: var(--text);
}

button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.appShell { min-height: 100vh; }

.topbar {
  width: 100%;
  min-height: 76px;
  padding: 12px 20px;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto minmax(160px, 1fr);
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(8,13,26,.82);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brandBlock { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brandMark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--green));
  color: #06101d;
  font-weight: 950;
  box-shadow: var(--shadow);
}
.brandTitle { font-size: 18px; font-weight: 850; letter-spacing: .1px; }
.brandSub { margin-top: 2px; font-size: 12px; color: var(--muted); }

.topnav { display: flex; gap: 6px; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.025); }
.navLink { text-decoration: none; padding: 8px 14px; border-radius: 999px; color: var(--muted); font-size: 13px; font-weight: 750; }
.navLink:hover, .navLink.active { color: var(--text); background: var(--accentSoft); }

.status { justify-self: end; color: var(--muted); font-size: 13px; font-weight: 750; text-align: right; }
.status[data-kind="success"] { color: var(--green); }
.status[data-kind="error"] { color: var(--danger); }

.page { width: 100%; max-width: none; padding: 16px 20px 28px; }
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.022));
  box-shadow: var(--shadow);
}

.toolbar {
  width: 100%;
  min-height: 66px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.modeGroup { display: flex; align-items: center; gap: 8px; }
.toolbarLabel, .fileLabel { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.modeBtn, .btn {
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid var(--lineStrong);
  border-radius: 11px;
  background: rgba(255,255,255,.04);
  cursor: pointer;
  font-weight: 800;
}
.modeBtn.on { border-color: rgba(118,169,255,.55); background: var(--accentSoft); }
.btn.primary { border-color: rgba(118,169,255,.52); background: rgba(118,169,255,.20); }
.btn.secondary { color: var(--muted); }
.btn:hover, .modeBtn:hover { border-color: rgba(255,255,255,.28); }
.btn:disabled { opacity: .55; cursor: progress; }

.pdfPicker { display: none; align-items: center; gap: 8px; margin-left: 6px; }
.pdfPicker.on { display: flex; }
.pdfPicker input { max-width: 320px; color: var(--muted); }
.toolbarSpacer { flex: 1; }

.errorBanner {
  display: none;
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid rgba(255,128,128,.32);
  border-radius: 12px;
  color: #ffc1c1;
  background: var(--dangerSoft);
  font-weight: 750;
  white-space: pre-wrap;
}
.errorBanner.on { display: block; }

.workspace { width: 100%; display: block; }
.workspace.pdfMode {
  display: grid;
  grid-template-columns: minmax(460px, 43%) minmax(660px, 57%);
  align-items: start;
  gap: 14px;
}

.pdfPanel { display: none; overflow: hidden; position: sticky; top: 92px; }
.pdfPanel.on { display: block; }
.pdfPanel .sectionHeader { padding: 13px 15px; border-bottom: 1px solid var(--line); }
.pdfPreviewBody { height: calc(100vh - 196px); min-height: 650px; background: rgba(0,0,0,.22); }
.pdfPreviewBody iframe { width: 100%; height: 100%; border: 0; display: none; background: #242424; }
.pdfPreviewBody iframe.on { display: block; }
.pdfEmpty { height: 100%; display: grid; place-items: center; padding: 30px; text-align: center; color: var(--muted); line-height: 1.5; }
.pdfEmpty.hidden { display: none; }

.classification { min-width: 0; display: grid; gap: 14px; }
.topGrid, .middleGrid, .selectionGrid { display: grid; gap: 14px; }
.topGrid { grid-template-columns: minmax(360px, .92fr) minmax(440px, 1.4fr); }
.middleGrid { grid-template-columns: minmax(420px, 1.35fr) minmax(300px, .65fr); }
.selectionGrid { grid-template-columns: minmax(420px, .8fr) minmax(560px, 1.2fr); }
.workspace.pdfMode .topGrid,
.workspace.pdfMode .middleGrid,
.workspace.pdfMode .selectionGrid { grid-template-columns: 1fr; }

.fieldCard { padding: 14px; min-width: 0; }
.fieldHeading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 10px; }
.fieldHeading.compact { align-items: center; }
.stepKicker { color: var(--accent); font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 3px; }
.fieldTitle, .sectionTitle { display: block; font-size: 16px; font-weight: 850; }
.sectionSub { margin-top: 3px; color: var(--muted); font-size: 12px; word-break: break-word; }

.input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--lineStrong);
  border-radius: 11px;
  background: rgba(4,9,20,.45);
  color: var(--text);
  outline: none;
}
.input:focus { border-color: rgba(118,169,255,.62); box-shadow: 0 0 0 3px rgba(118,169,255,.10); }

.selectionBadge, .countBadge {
  max-width: 48%;
  padding: 6px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255,255,255,.025);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.selectionBadge.selected { color: var(--green); border-color: rgba(124,230,191,.28); background: var(--greenSoft); }

.chooserList {
  margin-top: 8px;
  max-height: 226px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(2,7,17,.25);
}
.chooserList.short { max-height: 210px; }
.chooserItem {
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  display: block;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.chooserItem:last-child { border-bottom: 0; }
.chooserItem:hover { background: rgba(255,255,255,.04); }
.chooserItem.selected { background: var(--accentSoft); color: #fff; }

.titleCard .input { margin-bottom: 10px; }
.subheading { margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.suggestionRow { display: flex; flex-wrap: wrap; gap: 7px; min-height: 34px; }
.suggestionChip, .groupChip, .selectedChip {
  border: 1px solid var(--lineStrong);
  border-radius: 999px;
  background: rgba(255,255,255,.035);
  cursor: pointer;
}
.suggestionChip { padding: 7px 10px; font-size: 12px; font-weight: 750; }
.suggestionChip:hover { background: var(--accentSoft); border-color: rgba(118,169,255,.38); }
.helper { margin-top: 9px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.textBtn { border: 0; background: transparent; color: var(--accent); font-size: 12px; font-weight: 800; }
.textBtn.disabled { color: var(--muted); opacity: .55; }

.dateCard { display: flex; flex-direction: column; gap: 10px; }
.toggleRow {
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255,255,255,.022);
  cursor: pointer;
}
.toggleRow input { width: 20px; height: 20px; }
.toggleRow span { display: grid; gap: 2px; }
.toggleRow strong { font-size: 13px; }
.toggleRow small { color: var(--muted); font-size: 11px; }

.selectionCard { min-height: 430px; }
.selectedStrip { min-height: 42px; margin: 9px 0; padding: 7px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px dashed var(--lineStrong); border-radius: 11px; }
.selectedEmpty { color: var(--muted); font-size: 12px; }
.selectedChip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; background: var(--greenSoft); border-color: rgba(124,230,191,.28); font-size: 12px; font-weight: 750; }

.checkList { max-height: 300px; overflow: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.checkItem, .categoryItem {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.02);
  cursor: pointer;
}
.checkItem:hover, .categoryItem:hover { background: rgba(255,255,255,.04); }
.checkItem input, .categoryItem input { margin-top: 2px; width: 17px; height: 17px; flex: 0 0 auto; }
.checkItem span { font-size: 12px; line-height: 1.3; }

.categoryGroups { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.groupChip { padding: 6px 9px; color: var(--muted); font-size: 11px; font-weight: 800; }
.groupChip.on { color: var(--text); border-color: rgba(118,169,255,.38); background: var(--accentSoft); }
.categoryResults { max-height: 300px; overflow: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.categoryItem span { min-width: 0; display: grid; gap: 2px; }
.categoryItem strong { font-size: 12px; font-weight: 800; }
.categoryItem small { color: var(--muted); font-size: 10px; line-height: 1.35; overflow-wrap: anywhere; }

.reviewCard { padding: 14px; }
.reviewHeader { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 10px; }
.reviewMode { padding: 6px 9px; border-radius: 999px; background: var(--accentSoft); color: var(--accent); font-size: 11px; font-weight: 850; }
.reviewGrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.reviewItem { padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.02); min-width: 0; }
.reviewItem.wide { grid-column: span 2; }
.reviewItem span { display: block; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.reviewItem strong { display: block; font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }

.reviewActions {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.reviewActions .btn { min-width: 140px; }

.emptyState { padding: 12px; color: var(--muted); font-size: 12px; text-align: center; }
.emptyState.inline { padding: 6px 0; text-align: left; }

@media (max-width: 1500px) {
  .topGrid { grid-template-columns: minmax(320px, .85fr) minmax(420px, 1.15fr); }
  .selectionGrid { grid-template-columns: minmax(360px, .85fr) minmax(500px, 1.15fr); }
  .workspace.pdfMode { grid-template-columns: minmax(430px, 42%) minmax(620px, 58%); }
}

@media (max-width: 1180px) {
  .workspace.pdfMode { grid-template-columns: 1fr; }
  .pdfPanel { position: static; }
  .pdfPreviewBody { height: 640px; min-height: 0; }
  .topGrid, .middleGrid, .selectionGrid { grid-template-columns: 1fr; }
  .reviewGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .topbar { grid-template-columns: 1fr; position: static; }
  .topnav { width: max-content; }
  .status { justify-self: start; }
  .page { padding: 12px; }
  .toolbar { align-items: stretch; flex-wrap: wrap; }
  .toolbarSpacer { display: none; }
  .pdfPicker.on { width: 100%; align-items: flex-start; flex-direction: column; }
  .checkList, .categoryResults { grid-template-columns: 1fr; }
  .reviewGrid { grid-template-columns: 1fr; }
  .reviewItem.wide { grid-column: auto; }
}

/* ---- Contextual title manager ---- */
.suggestionChip.contextual {
  border-color: rgba(124,230,191,.34);
  background: rgba(124,230,191,.09);
}

.textBtn:not(.disabled) { cursor: pointer; }
.textBtn:not(.disabled):hover { color: #a9c8ff; text-decoration: underline; }

body.modalOpen { overflow: hidden; }
.modalBackdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(4px);
}
.modalBackdrop.on { display: flex; }
.titleManagerModal {
  width: min(1500px, 96vw);
  height: min(900px, 92vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--lineStrong);
  border-radius: 16px;
  background: #0b1221;
  box-shadow: 0 28px 80px rgba(0,0,0,.55);
}
.modalHeader {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.018));
}
.modalTitle { font-size: 20px; font-weight: 900; }
.iconBtn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--lineStrong);
  background: rgba(255,255,255,.04);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.iconBtn:hover { background: rgba(255,255,255,.08); }
.titleManagerBody {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(420px, .82fr) minmax(600px, 1.18fr);
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}
.insetCard { box-shadow: none; }
.managerEditor,
.managerLibrary {
  min-height: 0;
  padding: 14px;
  overflow: hidden;
}
.managerEditor { display: flex; flex-direction: column; gap: 10px; }
.managerEditorHeader,
.managerLibraryToolbar,
.managerScopeHeader,
.managerActions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.managerEditorHeader,
.managerLibraryToolbar,
.managerScopeHeader { justify-content: space-between; }
.formLabel {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.managerFlags { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.compactToggle { margin-top: 0; min-height: 62px; }
.managerDocTypes {
  min-height: 0;
  max-height: 300px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 6px;
  padding-right: 2px;
}
.managerDocTypeItem {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255,255,255,.02);
  cursor: pointer;
}
.managerDocTypeItem:hover { background: rgba(255,255,255,.045); }
.managerDocTypeItem input { width: 17px; height: 17px; flex: 0 0 auto; }
.managerDocTypeItem span { min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.managerActions { margin-top: auto; }
.managerMessage { min-height: 20px; color: var(--muted); font-size: 12px; font-weight: 750; }
.managerMessage[data-kind="success"] { color: var(--green); }
.managerMessage[data-kind="error"] { color: var(--danger); white-space: pre-wrap; max-height: 90px; overflow: auto; }
.managerLibrary { display: flex; flex-direction: column; }
.managerLibraryToolbar { margin-bottom: 10px; }
.managerFilters { display: flex; gap: 8px; min-width: min(520px, 55%); }
.selectInput,
.compactInput {
  height: 40px;
  border: 1px solid var(--lineStrong);
  border-radius: 10px;
  background: rgba(4,9,20,.45);
  color: var(--text);
}
.selectInput { padding: 0 10px; min-width: 210px; }
.compactInput { min-width: 180px; }
.managerList {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 6px;
}
.managerRow {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.022);
}
.managerRow.inactive { opacity: .62; }
.managerRowCopy { min-width: 0; display: grid; gap: 3px; }
.managerRowCopy strong { font-size: 13px; overflow-wrap: anywhere; }
.managerRowCopy small { color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.statusPill {
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 850;
  border: 1px solid var(--line);
}
.statusPill.active { color: var(--green); border-color: rgba(124,230,191,.28); background: var(--greenSoft); }
.statusPill.inactive { color: var(--muted); }
.managerRowActions { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.miniBtn {
  min-width: 34px;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--lineStrong);
  border-radius: 8px;
  background: rgba(255,255,255,.035);
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
.miniBtn:hover:not(:disabled) { background: rgba(255,255,255,.08); }
.miniBtn:disabled { opacity: .3; cursor: default; }
.miniBtn.danger { color: #ffb0b0; }
.managerEmpty { border: 1px dashed var(--lineStrong); border-radius: 10px; }

@media (max-width: 1100px) {
  .titleManagerBody { grid-template-columns: 1fr; overflow: auto; }
  .managerEditor, .managerLibrary { overflow: visible; }
  .managerLibrary { min-height: 500px; }
}

@media (max-width: 760px) {
  .modalBackdrop { padding: 8px; }
  .titleManagerModal { width: 100vw; height: 96vh; }
  .managerFlags, .managerDocTypes { grid-template-columns: 1fr; }
  .managerLibraryToolbar { align-items: stretch; flex-direction: column; }
  .managerFilters { min-width: 0; width: 100%; flex-direction: column; }
  .selectInput, .compactInput { width: 100%; }
  .managerRow { grid-template-columns: 1fr; }
  .managerRowActions { justify-content: flex-start; }
}
