*{box-sizing:border-box}
html,body{max-width:100%;overflow-x:hidden}

/* ==========================================================
   Stage 1 — Fixed Layout Contract
   The left rail and bottom sheet remain viewport-fixed.
   The top workspace header is horizontally anchored, not viewport-fixed:
   it stays in normal vertical document flow and follows browser scrolling.
   ========================================================== */
:root{
  --psm-layout-side-width:168px;
  --psm-layout-bottom-height:114px;
  --psm-layout-content-max-width:1200px;
  --psm-layout-content-padding:24px;

  /* Stage 10.5A — Dual Width Layout Contract.
     Header and Final Prompt remain in the centered content frame.
     The Master Workspace owns the full browser width to the right of the
     persistent side rail, while each Prompt Sheet keeps the Stage 10 width. */
  --psm-layout-canvas-left:var(--psm-layout-side-width);
  --psm-layout-canvas-right:0px;
  --psm-layout-canvas-width:calc(
    100vw - var(--psm-layout-canvas-left) - var(--psm-layout-canvas-right)
  );
  --psm-layout-canvas-edge-inset:10px;
  --psm-layout-stage10-sheet-width:min(
    calc(
      100vw - var(--psm-layout-side-width) -
      var(--psm-layout-content-padding) - var(--psm-layout-content-padding)
    ),
    calc(
      var(--psm-layout-content-max-width) -
      var(--psm-layout-content-padding) - var(--psm-layout-content-padding)
    )
  );

  /* Stage 10.5B/10.5C — Prompt Sheet width modes.
     Single keeps the Stage 10 sheet width. Compare uses one stable responsive
     width calculated by the Wrapper from the current Canvas viewport; it is
     independent of whether 2 or 20 Prompt Sheets exist. */
  /* Compare width is calculated from the live Canvas viewport.
     Exactly two Prompt columns fill the visible workspace at every width. */
  --psm-layout-active-compare-sheet-width:720px;

  --psm-layout-horizontal-anchor-left:0px;
  --psm-layout-header-z-index:700;
  --psm-layout-final-dock-z-index:690;
  --psm-layout-header-gap:24px;

  /* Shared workspace width and Master Canvas column contract. */
  --psm-layout-workspace-width:100%;
  --psm-layout-column-gap:14px;

  /* Viewport-fixed bottom Prompt scroll controller. */
  --psm-layout-fixed-scrollbar-height:30px;
  --psm-prompt-scrollbar-thumb-min-width:34px;

  /* Backward-compatible aliases used by the existing fixed regions. */
  --psm-fixed-side-width:var(--psm-layout-side-width);
  --psm-fixed-bottom-height:57px; /* left login/rail unchanged; only Conflict panel doubles */
  --psm-fixed-region-bg:#0b1220;
}

body{
  margin:0;
  padding-left:var(--psm-layout-side-width);
  padding-bottom:calc(
    var(--psm-layout-bottom-height) +
    var(--psm-layout-fixed-scrollbar-height)
  );
  font-family:Arial,sans-serif;
  background:#111827;
  color:#e5e7eb;
}
.app{
  width:var(--psm-layout-workspace-width);
  max-width:var(--psm-layout-content-max-width);
  margin:0 auto;
  padding:var(--psm-layout-content-padding) var(--psm-layout-content-padding) 0;
}

/* Persistent fixed workspace regions.
   Display-only empty areas. No labels, icons, controls, or behavior. */
body > .psm-persistent-rail,
body > .psm-persistent-login,
body > .psm-persistent-sheet-bar{
  position:fixed !important;
  display:block !important;
  visibility:visible !important;
  opacity:1 !important;
  margin:0 !important;
  padding:0 !important;
  border:0 !important;
  background:var(--psm-fixed-region-bg) !important;
  pointer-events:none;
  overflow:hidden;
  z-index:900;
}
body > .psm-persistent-rail{
  top:0;
  bottom:var(--psm-fixed-bottom-height);
  left:0;
  width:var(--psm-fixed-side-width);
  height:auto;
}
body > .psm-persistent-login{
  left:0;
  bottom:0;
  width:var(--psm-fixed-side-width);
  height:var(--psm-fixed-bottom-height);
}
body > .psm-persistent-sheet-bar{
  left:var(--psm-fixed-side-width);
  right:0;
  bottom:0;
  width:auto;
  height:var(--psm-layout-bottom-height);
}

h1{margin:0 0 4px;font-size:32px}
.tagline{color:#9ca3af;margin:0}

/* Semi-fixed top workspace header.
   It is anchored only on the horizontal axis while remaining in normal
   vertical document flow. No top inset, border, shadow, or contrasting panel. */
.psm-horizontal-anchor{
  position:sticky;
  left:var(--psm-layout-horizontal-anchor-left);
}
.psm-top-header{
  z-index:var(--psm-layout-header-z-index);
  display:flex;
  align-items:flex-start;
  flex-wrap:wrap;
  gap:14px var(--psm-layout-header-gap);
  padding:6px 0 16px;
  margin-bottom:16px;
  background:var(--psm-page-bg,#ffffff);
}
.psm-top-header-brand{
  min-width:0;
  flex:1 1 620px;
}
.psm-header-actions{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  justify-content:flex-start;
  gap:8px;
  flex:0 0 auto;
  flex-wrap:nowrap;
  min-width:310px;
}
.psm-header-primary-actions{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:10px;
  flex-wrap:nowrap;
  width:100%;
}
.psm-header-primary-actions button{
  margin:0;
}
.psm-header-apply-row{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:8px;
  width:100%;
  min-height:0;
}
.psm-header-apply-row[hidden]{
  display:none !important;
}
.psm-header-tagline-row{
  display:flex;
  align-items:center;
  gap:14px;
  min-width:0;
  margin-top:2px;
}
.psm-header-toggle-row{
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:10px 18px;
  margin-top:10px;
}
.psm-header-toggle-row .toolbar-toggle{
  margin:0;
  white-space:nowrap;
}
.psm-header-toggle-row .toggle-switch{
  margin-right:0;
}

/* The sole Prompt scroll controller is viewport-fixed directly above the
   existing bottom Prompt Sheet reservation. It controls only the Master
   Workspace Viewport; no top or Category-specific scroll controller exists. */
.psm-fixed-scroll-controller{
  position:fixed;
  left:var(--psm-layout-canvas-left);
  right:var(--psm-layout-canvas-right);
  bottom:var(--psm-layout-bottom-height);
  height:var(--psm-layout-fixed-scrollbar-height);
  z-index:920;
  display:flex;
  align-items:center;
  padding:0 var(--psm-layout-canvas-edge-inset);
  margin:0;
  background:var(--psm-page-bg,#ffffff);
  border-top:1px solid var(--psm-fixed-line,#cbd5e1);
  overflow:hidden;
}
.psm-prompt-scrollbar{
  width:100%;
  min-width:0;
  max-width:none;
  height:100%;
  flex:1 1 auto;
  display:flex;
  align-items:center;
  touch-action:none;
  user-select:none;
}
.psm-prompt-scrollbar-track{
  position:relative;
  width:100%;
  height:6px;
  border-radius:999px;
  background:#e2e8f0;
  cursor:pointer;
}
.psm-prompt-scrollbar-thumb{
  position:absolute;
  top:-3px;
  left:0;
  height:12px;
  min-width:var(--psm-prompt-scrollbar-thumb-min-width);
  border-radius:999px;
  background:#64748b;
  transform:translateX(0);
  cursor:grab;
  will-change:transform,width;
}
.psm-prompt-scrollbar-thumb:active,
.psm-prompt-scrollbar.dragging .psm-prompt-scrollbar-thumb{
  cursor:grabbing;
  background:#475569;
}
.psm-prompt-scrollbar[data-scrollable="false"] .psm-prompt-scrollbar-thumb{
  cursor:default;
  background:#94a3b8;
}
.psm-prompt-scrollbar:focus-visible{
  outline:2px solid #2563eb;
  outline-offset:4px;
  border-radius:4px;
}

.psm-top-header,
.psm-final-dock,
.footer{
  width:var(--psm-layout-workspace-width);
  max-width:100%;
}
/* Stage 10.5A — Dual Width Layout Contract.
   The centered .app remains the Content Frame for Header and Final Prompt.
   Only the Master Workspace breaks out to the browser-width Canvas Frame.
   Its outer bounds share the same left/right contract as the fixed scrollbar. */
.psm-master-workspace-region{
  position:relative;
  left:50%;
  transform:translateX(-50%);
  width:var(--psm-layout-canvas-width);
  max-width:none;
  margin:0;
}

/* Stage 10.5B — two explicit workspace modes only.
   The mode is written by the HTML Wrapper from the number of existing Prompt
   Sheets. No 1/N width division and no Prompt-count-specific selectors. */
.psm-master-workspace-region[data-workspace-mode="single"] .psm-prompt-sheet{
  flex-basis:var(--psm-layout-stage10-sheet-width);
  width:var(--psm-layout-stage10-sheet-width);
  min-width:var(--psm-layout-stage10-sheet-width);
  max-width:var(--psm-layout-stage10-sheet-width);
}
.psm-master-workspace-region[data-workspace-mode="compare"] .psm-prompt-sheet{
  flex-basis:var(--psm-layout-active-compare-sheet-width);
  width:var(--psm-layout-active-compare-sheet-width);
  min-width:var(--psm-layout-active-compare-sheet-width);
  max-width:var(--psm-layout-active-compare-sheet-width);
}
.psm-master-workspace-viewport{
  width:100%;
  max-width:none;
  overflow-x:auto;
  overflow-y:visible;
  overscroll-behavior-inline:contain;
  scrollbar-width:none;
  -ms-overflow-style:none;
  margin:0 0 16px;
  padding-inline:var(--psm-layout-canvas-edge-inset);
}
.psm-master-workspace-viewport::-webkit-scrollbar{display:none}
.psm-master-workspace-track{
  display:flex;
  flex-flow:row nowrap;
  align-items:flex-start;
  gap:var(--psm-layout-column-gap);
  width:max-content;
  min-width:100%;
  margin:0;
  padding:0;
}
.psm-prompt-sheet{
  flex:0 0 var(--psm-layout-stage10-sheet-width);
  width:var(--psm-layout-stage10-sheet-width);
  min-width:var(--psm-layout-stage10-sheet-width);
  max-width:var(--psm-layout-stage10-sheet-width);
  padding:14px;
  border:1px solid var(--psm-border,#cbd5e1);
  border-radius:14px;
  background:var(--psm-surface,#ffffff);
  box-shadow:0 1px 2px rgba(15,23,42,.05);
}
.psm-prompt-sheet:only-child{
  margin-inline:auto;
}
.psm-prompt-sheet.inactive-prompt-sheet{
  border-color:var(--psm-border-strong,#94a3b8);
  border-style:dashed;
}
.psm-prompt-sheet .prompt-card{margin:0 0 14px}
.psm-prompt-sheet-results{width:100%;min-width:0}
.prompt-sheet-category-stack{width:100%;min-width:0}
.prompt-sheet-category:last-child{margin-bottom:0}
.box,.category{background:#1f2937;border:1px solid #374151;border-radius:12px;padding:16px}
label{display:block;font-weight:bold;margin-bottom:8px}
.box-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
.box-header label{margin:0}
.paste-btn{margin:0;padding:5px 11px;font-size:12px;border-radius:6px;background:#4b5563;color:#e5e7eb;cursor:pointer;border:none;font-weight:600;letter-spacing:.02em}
.paste-btn:hover{background:#6b7280}
.final-prompt-reset-button{margin:0;padding:5px 11px;font-size:12px;border-radius:6px;background:#16a34a;color:#fff;cursor:pointer;border:none;font-weight:700;letter-spacing:.02em}
.final-prompt-reset-button:hover:not(:disabled){background:#15803d}
.final-prompt-reset-button:disabled{background:#d1d5db;color:#6b7280;cursor:default;opacity:.72}
.paste-error{color:#ef4444;font-size:12px;margin-top:5px;display:none}
.textarea-container{position:relative;width:100%}
.backdrop{position:absolute;top:0;left:0;right:0;bottom:0;overflow:auto;background:#030712;color:transparent;border:1px solid #374151;border-radius:10px;padding:12px;font-size:14px;line-height:1.5;font-family:inherit;white-space:pre-wrap;overflow-wrap:break-word;word-wrap:break-word;pointer-events:none;z-index:1;box-sizing:border-box;scrollbar-width:none;-ms-overflow-style:none;width:100%}
.backdrop::-webkit-scrollbar{display:none}
textarea{display:block;width:100%;min-height:170px;resize:vertical;background:transparent;color:#e5e7eb;border:1px solid transparent;border-radius:10px;padding:12px;font-size:14px;line-height:1.5;font-family:inherit;white-space:pre-wrap;overflow-wrap:break-word;word-wrap:break-word;position:relative;z-index:2;box-sizing:border-box}
textarea:focus{outline:1px solid #3b82f6}
button{border:0;border-radius:10px;padding:12px 18px;font-weight:bold;cursor:pointer;background:#2563eb;color:white;margin:8px 8px 8px 0}
button:hover{background:#1d4ed8}
button:disabled{background:#374151 !important;color:#9ca3af !important;cursor:not-allowed;opacity:0.8}
.category{margin-bottom:14px}
.category h2{margin:0 0 12px;font-size:20px;color:#93c5fd}
.count{color:#9ca3af;font-size:14px}
.source{background:#030712;border:1px solid #374151;border-radius:10px;padding:12px}
/* STEP03: keep an accessible, usable drop area when no Category text is present. */
.prompt-sheet-category .source{min-height:44px;box-sizing:border-box}
.source-title{font-weight:bold;margin-bottom:8px;color:#facc15}
.tag{display:inline-flex;align-items:center;position:relative;background:#374151;padding:9px 12px;border-radius:8px;margin:6px;font-size:19px;max-width:100%;white-space:normal;overflow-wrap:break-word;word-break:keep-all;vertical-align:top;cursor:pointer;user-select:text;transition:background .2s}
.tag.selected{background:#2563eb;color:#ffffff}
.modal-overlay{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center;z-index:1000}
.modal-content.qa-modal{background:#1f2937;border-radius:8px;width:400px;max-width:90%;display:flex;flex-direction:column}
.modal-header{padding:16px;border-bottom:1px solid #374151;display:flex;justify-content:space-between;align-items:center}
.modal-header h3{margin:0;font-size:18px;color:#facc15}
.modal-close{background:none;border:none;color:#9ca3af;font-size:18px;cursor:pointer}
.modal-close:hover{color:white}
.modal-body{padding:16px;max-height:400px;overflow-y:auto;color:#e5e7eb;font-size:14px}
.modal-footer.qa-note{padding:12px 16px;border-top:1px solid #374151;font-size:12px;color:#9ca3af}
.qa-group{margin-bottom:12px}
.qa-group-title{font-weight:bold;color:#d97706;margin-bottom:4px}
body.tag-adjust-mode .tag{user-select:none}
body.tag-adjust-mode .tag[draggable="true"]{cursor:grab}
body.tag-adjust-mode .tag.dragging{opacity:.45;cursor:grabbing}
body.tag-adjust-mode .tag:hover{opacity:.9}
.source, .category, .source-title, .category h2{cursor:default}
.tag-delete{display:none;flex:0 0 24px;width:24px;min-width:24px;max-width:24px;height:24px;min-height:24px;max-height:24px;aspect-ratio:1/1;align-self:center;border-radius:50%;padding:0;margin:0 0 0 8px;background:#dc2626;color:white;font-size:15px;line-height:1;border:none;cursor:pointer}
.tag-delete:hover{background:#b91c1c}

.tag-restore {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 24px;
  width: 24px;
  min-width: 24px;
  max-width: 24px;
  height: 24px;
  min-height: 24px;
  max-height: 24px;
  aspect-ratio: 1 / 1;
  padding: 0;
  margin: 0 0 0 6px;
  border-radius: 50%;
  background: #4b5563;
  color: #ffffff;
  font-size: 15px;
  line-height: 24px;
  cursor: pointer;
}

.tag-restore:hover {
  background: #6b7280;
}
body.tag-adjust-mode .tag-delete{display:inline-flex;align-items:center;justify-content:center}
.category-status{font-size:14px;color:#9ca3af;font-weight:bold;margin-top:8px}
.toggle-switch{position:relative;display:inline-block;width:36px;height:20px;margin-right:8px}
.toggle-switch input{opacity:0;width:0;height:0}
.toggle-slider{position:absolute;cursor:pointer;top:0;left:0;right:0;bottom:0;background-color:#374151;transition:.2s;border-radius:20px}
.toggle-slider:before{position:absolute;content:"";height:14px;width:14px;left:3px;bottom:3px;background-color:#9ca3af;transition:.2s;border-radius:50%}
input:checked+.toggle-slider{background-color:#2563eb}
input:checked+.toggle-slider:before{transform:translateX(16px);background-color:white}
.toggle-label{font-size:14px;color:#9ca3af;font-weight:bold}
.source.drop-enabled{transition:border-color .15s ease,background .15s ease}
.source.drag-over{border-color:#60a5fa;background:#111827}
.empty{color:#6b7280;font-size:13px}
#finalPrompt{min-height:140px;width:100%}

/* ==========================================================
   Stage 3 — semi-fixed Final Prompt dock.
   Like the top header, this dock is anchored only horizontally.
   It remains in normal vertical document flow and therefore moves
   with browser scrolling. No top/bottom viewport inset is used.
   ========================================================== */
.psm-final-dock{
  z-index:var(--psm-layout-final-dock-z-index);
  margin-top:16px;
  padding:0;
  background:var(--psm-page-bg,#ffffff);
}
.psm-final-dock-actions{
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:8px;
  margin:0 0 10px;
}
.psm-final-dock-actions button{margin:0}
.pse-magic-wand-button{
  width:42px;
  min-width:42px;
  height:42px;
  padding:0;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border:1px solid #3b82f6;
  background:#1d4ed8;
  box-shadow:0 1px 2px rgba(0,0,0,.18);
}
.pse-magic-wand-button:hover{background:#2563eb}
.pse-magic-wand-button:active{transform:translateY(1px)}
.pse-magic-wand-button svg{
  width:22px;
  height:22px;
  display:block;
  fill:none;
  stroke:currentColor;
  stroke-width:1.8;
  stroke-linecap:round;
  stroke-linejoin:round;
  pointer-events:none;
}
.pse-magic-wand-info{
  display:flex;
  flex-direction:column;
  gap:2px;
  margin-left:2px;
  font-size:12px;
  line-height:1.35;
  color:#9ca3af;
}
.pse-magic-wand-error{
  color:#ef4444;
  font-weight:700;
}
.psm-final-dock-output{
  width:100%;
  max-width:100%;
  margin:0;
}
.psm-final-dock .footer{
  margin:12px 0 0;
}
.footer{color:#6b7280;margin-top:24px;font-size:13px}

.toolbar-toggle {
  display:inline-flex;
  align-items:center;
  gap:8px;
}



.prompt-add-button{margin:0;white-space:nowrap}
.prompt-remove-button{margin:0;padding:5px 11px;font-size:12px;border-radius:6px;background:#dc2626;color:#fff;white-space:nowrap}
.prompt-remove-button:hover{background:#b91c1c}
.prompt-card{
  min-width:0;
  width:100%;
  max-width:100%;
}
.prompt-card-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:10px}
.prompt-card-actions button{margin:0}
.prompt-card-status{font-size:12px;font-weight:700;color:#9ca3af}
.prompt-card-status[data-status="applied"]{color:#22c55e}
.prompt-card-status[data-status="modified"]{color:#f59e0b}
.prompt-card-status[data-status="empty"]{color:#9ca3af}
.prompt-card-status[data-status="error"]{color:#ef4444}
.prompt-card-summary{margin-top:7px;font-size:12px;color:#9ca3af;min-height:16px}
.prompt-card .textarea-container{min-height:170px}
.apply-target-control{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.apply-target-control[hidden]{display:none}
.apply-target-label{font-size:12px;color:#93c5fd;font-weight:700;white-space:nowrap}
.apply-target-button{margin:0;background:#374151;white-space:nowrap}
.apply-target-button:hover{background:#4b5563}
/* Stage 8B — the 20-item Apply Target list remains inside the modal's
   own vertical scroll area. Selected options use scroll-margin so opening a
   Prompt 20 target never moves the browser document itself. */
.apply-target-options{display:grid;gap:10px;scrollbar-gutter:stable}
.apply-target-option{width:100%;margin:0;display:flex;align-items:center;justify-content:space-between;background:#374151;text-align:left;scroll-margin-block:10px}
.apply-target-option:hover{background:#4b5563}
.apply-target-option.selected{background:#2563eb}
.apply-target-option-subtext{font-size:12px;color:#cbd5e1;font-weight:400}
.apply-target-help{font-size:12px;line-height:1.45;color:#9ca3af;margin-bottom:12px}
/* ==========================================================
   Stage 9A — dynamic Prompt Sheet row alignment.
   JavaScript assigns only the current natural maximum as min-height for the
   Prompt input row and each matching Category row. No permanent fixed height
   is declared here, so rows can shrink again after edits or deletions.
   ========================================================== */
.psm-prompt-sheet .prompt-card[data-prompt-id],
.prompt-sheet-category[data-prompt-sheet-category]{
  min-height:0;
}
.psm-prompt-sheet-height-synced{
  align-self:stretch;
}

/* ==========================================================
   Stage 7.5B — Prompt-centered Category presentation.
   Category rails no longer exist. Each Category belongs to one Prompt Sheet,
   and the Master Workspace Viewport moves complete sheets horizontally.
   ========================================================== */
.prompt-sheet-category{
  width:100%;
  min-width:0;
  margin-bottom:14px;
}
.prompt-sheet-category .source{
  width:100%;
  min-width:0;
}
.prompt-source{
  min-width:0;
  width:100%;
  max-width:100%;
  transition:opacity .18s ease,border-color .18s ease,filter .18s ease;
}
.prompt-source.active-source{border-color:#3b82f6}
.prompt-source.inactive-source{opacity:.42;filter:grayscale(.35);border-style:dashed}
.prompt-source.inactive-source .tag{cursor:not-allowed}
.tag.inactive-tag{background:#374151;color:#9ca3af}
.source-target-state{display:inline-flex;margin-left:8px;padding:2px 7px;border-radius:999px;font-size:10px;line-height:1.2;vertical-align:middle}
.source-target-state.active{background:#14532d;color:#86efac}
.source-target-state.inactive{background:#374151;color:#9ca3af}
.prompt-card-target-state{font-size:10px;padding:2px 7px;border-radius:999px;background:#14532d;color:#86efac}
.prompt-card-target-state.inactive{background:#374151;color:#9ca3af}
.prompt-card.inactive-prompt-card{border-color:#4b5563}

@media(max-width:800px){
  body{
    padding-left:var(--psm-fixed-side-width);
    padding-bottom:calc(
      var(--psm-layout-bottom-height) +
      var(--psm-layout-fixed-scrollbar-height)
    );
  }
  .prompt-card,.prompt-source,.psm-prompt-sheet{min-width:0}
  .psm-top-header{
    align-items:flex-start;
    gap:12px;
  }
  .psm-top-header-brand{flex:1 1 100%}
  .psm-header-actions{
    flex:1 1 100%;
    min-width:0;
    width:100%;
    align-items:flex-start;
  }
  .psm-header-primary-actions,
  .psm-header-apply-row{
    justify-content:flex-start;
  }
  .psm-header-tagline-row{
    align-items:flex-start;
    flex-wrap:wrap;
  }
  .psm-header-toggle-row{
    gap:8px 14px;
  }
}


/* ==========================================================
   White UI theme + visible fixed-region separator lines
   ========================================================== */
:root{
  --psm-page-bg:#ffffff;
  --psm-surface:#ffffff;
  --psm-surface-soft:#f8fafc;
  --psm-border:#cbd5e1;
  --psm-border-strong:#94a3b8;
  --psm-text:#0f172a;
  --psm-text-muted:#64748b;
  --psm-fixed-region-bg:#f8fafc;
  --psm-fixed-line:#cbd5e1;
}

html{background:var(--psm-page-bg)}
body{background:var(--psm-page-bg);color:var(--psm-text)}

/* Fixed empty regions: keep the regions empty, expose only their boundaries. */
body > .psm-persistent-rail,
body > .psm-persistent-login,
body > .psm-persistent-sheet-bar{
  background:var(--psm-fixed-region-bg) !important;
}
body > .psm-persistent-rail{
  border-right:1px solid var(--psm-fixed-line) !important;
}
body > .psm-persistent-login{
  border-top:1px solid var(--psm-fixed-line) !important;
  border-right:1px solid var(--psm-fixed-line) !important;
}
body > .psm-persistent-sheet-bar{
  border-top:1px solid var(--psm-fixed-line) !important;
}

h1,label{color:var(--psm-text)}
.tagline,
.prompt-card-summary,
.prompt-card-status,
.category-status,
.toggle-label,
.apply-target-help,
.apply-target-option-subtext,
.footer,
.empty,
.count{color:var(--psm-text-muted)}

.box,.category{
  background:var(--psm-surface);
  border-color:var(--psm-border);
  box-shadow:0 1px 2px rgba(15,23,42,.05);
}
.category h2{color:#1d4ed8}

.backdrop,
.source{
  background:var(--psm-surface-soft);
  border-color:var(--psm-border);
}
textarea{
  color:var(--psm-text);
  caret-color:var(--psm-text);
}
textarea:focus{outline:1px solid #2563eb}

.paste-btn,
.apply-target-button,
.apply-target-option,
.tag-restore{
  background:#e2e8f0;
  color:var(--psm-text);
}
.paste-btn:hover,
.apply-target-button:hover,
.apply-target-option:hover,
.tag-restore:hover{
  background:#cbd5e1;
}
.apply-target-option.selected{background:#2563eb;color:#ffffff}

button:disabled{
  background:#e2e8f0 !important;
  color:#94a3b8 !important;
}

.source-title{color:#92400e}
.source.drag-over{border-color:#3b82f6;background:#eff6ff}
.prompt-source.active-source{border-color:#3b82f6}
.prompt-source.inactive-source{border-color:var(--psm-border-strong)}
.prompt-card.inactive-prompt-card{border-color:var(--psm-border-strong)}

.tag{background:#e2e8f0;color:var(--psm-text)}
.tag.selected{background:#2563eb;color:#ffffff}
.tag.inactive-tag{background:#e2e8f0;color:#94a3b8}

.toggle-slider{background-color:#cbd5e1}
.toggle-slider:before{background-color:#ffffff;box-shadow:0 1px 2px rgba(15,23,42,.25)}
input:checked+.toggle-slider{background-color:#2563eb}

.modal-content.qa-modal{background:var(--psm-surface);border:1px solid var(--psm-border)}
.modal-header{border-bottom-color:var(--psm-border)}
.modal-header h3{color:#92400e}
.modal-close{color:var(--psm-text-muted)}
.modal-close:hover{color:var(--psm-text)}
.modal-body{color:var(--psm-text)}
.modal-footer.qa-note{border-top-color:var(--psm-border);color:var(--psm-text-muted)}

.prompt-card-target-state.inactive,
.source-target-state.inactive{background:#e2e8f0;color:#64748b}



/* ==========================================================
   UI-ONLY SHELL
   Analysis / parser / resolver / pattern / dictionary / QA engine /
   final prompt composition are intentionally disconnected.
   ========================================================== */
.ui-shell-note{
  margin:0 0 14px;
  padding:10px 12px;
  border:1px solid #cbd5e1;
  border-radius:8px;
  background:#f8fafc;
  color:#64748b;
  font-size:12px;
  line-height:1.45;
}
.ui-shell-category-placeholder{
  color:#94a3b8;
  font-size:13px;
  padding:6px 2px;
}
.prompt-card-status[data-status="ready"]{color:#16a34a}
.prompt-card-status[data-status="running"]{color:#2563eb}
.prompt-card-status[data-status="error"]{color:#dc2626}
.prompt-card-status[data-status="disconnected"]{color:#f59e0b}

.ui-shell-note[data-backend-status="connected"]{
  border-color:#86efac;
  background:#f0fdf4;
  color:#166534;
}
.ui-shell-note[data-backend-status="checking"]{
  border-color:#bfdbfe;
  background:#eff6ff;
  color:#1d4ed8;
}
.ui-shell-note[data-backend-status="error"]{
  border-color:#fecaca;
  background:#fef2f2;
  color:#991b1b;
}
.model-output-tag{
  cursor:default;
  user-select:text;
}
.model-output-tag.inactive-tag{cursor:pointer}


/* Value Sort Engine STEP 4 - one hard-scope Tag, display-only Value groups. */
.pse-value-scope-mixed{
  background:#f8fafc !important;
  color:#111827 !important;
  padding:3px !important;
  border:1px solid #cbd5e1;
  white-space:pre-wrap;
}
.pse-value-general-text{
  display:inline;
  color:#111827;
  white-space:pre-wrap;
}
.pse-value-ui-group{
  display:inline;
  margin:0;
  padding:3px 6px;
  border-radius:6px;
  background:#2563eb;
  color:#ffffff;
  font-weight:inherit;
  white-space:pre-wrap;
  cursor:pointer;
  box-decoration-break:clone;
  -webkit-box-decoration-break:clone;
}
.pse-value-ui-group:hover{
  box-shadow:0 0 0 2px rgba(37,99,235,.20);
}
.pse-value-scope-whole > .pse-value-ui-group{
  margin:0;
  padding:0;
  border-radius:0;
  background:transparent;
  color:inherit;
  box-shadow:none;
}
.model-output-tag.inactive-tag .pse-value-ui-group{
  background:#94a3b8;
}
.model-output-tag.inactive-tag.pse-value-scope-whole > .pse-value-ui-group{
  background:transparent;
}
.pse-preset-value-tag.pse-value-scope-mixed,
.pse-category-pasted-preset-value.pse-value-scope-mixed{
  margin:3px;
}
.tag-boundary-x{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:20px;
  height:20px;
  padding:0 6px;
  margin-left:7px;
  border-radius:999px;
  background:#7c3aed;
  color:#ffffff;
  font-size:11px;
  font-weight:800;
  line-height:1;
}
.model-output-error{
  color:#dc2626;
  font-size:13px;
  line-height:1.45;
  white-space:pre-wrap;
}
.previous-result-badge{
  display:inline-flex;
  align-items:center;
  margin-left:7px;
  padding:2px 7px;
  border-radius:999px;
  background:#fef3c7;
  color:#92400e;
  font-size:10px;
  font-weight:800;
  line-height:1.2;
  vertical-align:middle;
}
.prompt-card-summary[data-kind="stale"]{color:#b45309}
.prompt-card-summary[data-kind="error"]{color:#dc2626}
.prompt-card-summary[data-kind="ready"]{color:#15803d}

/* ==========================================================
   PSE Boundary L1/L2/L3 Presentation v1.2 — TIGHT FLOW
   - standalone L1 = snug blue outer boundary
   - L2 = snug green max-content boundary, clamped only by available width
   - L1/L2 share leftover row space naturally
   - L3 remains full-width amber
   ========================================================== */
.pse-boundary-flow{
  display:flex;
  flex-wrap:wrap;
  align-items:flex-start;
  align-content:flex-start;
  gap:8px 8px;
  width:100%;
  min-width:0;
}

/* Boundary presentation OFF: keep Boundary Engine data, render plain tags only. */
.pse-boundary-flat-flow{
  display:flex;
  flex-wrap:wrap;
  align-items:flex-start;
  align-content:flex-start;
  gap:0;
  width:100%;
  min-width:0;
}

/* ---------- Category Preset paste ---------- */
.pse-category-pasted-presets{
  display:flex;
  flex-wrap:wrap;
  align-items:flex-start;
  align-content:flex-start;
  gap:8px;
  width:100%;
  min-width:0;
  margin-top:8px;
}
.pse-category-pasted-preset{
  position:relative;
  display:inline-flex;
  flex:0 1 auto;
  width:max-content;
  max-width:100%;
  flex-wrap:wrap;
  align-items:flex-start;
  align-content:flex-start;
  gap:0;
  margin:3px 0;
  padding:8px 28px 5px 5px;
  border:2px solid #111827;
  border-radius:12px;
  background:#ffffff;
  vertical-align:top;
}
.pse-category-pasted-preset-remove{
  position:absolute;
  top:3px;
  right:4px;
  z-index:3;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:20px;
  height:20px;
  padding:0;
  border:0;
  border-radius:6px;
  background:transparent;
  color:#6b7280;
  font-size:18px;
  font-weight:900;
  line-height:1;
  cursor:pointer;
}
.pse-category-pasted-preset-remove:hover{
  background:#fee2e2;
  color:#dc2626;
}
.pse-category-pasted-preset-label{
  position:absolute;
  top:-9px;
  left:8px;
  z-index:2;
  display:inline-flex;
  align-items:center;
  min-height:16px;
  padding:1px 5px;
  border:1px solid #111827;
  border-radius:999px;
  background:#ffffff;
  color:#111827;
  font-size:9px;
  font-weight:900;
  line-height:1;
  letter-spacing:.02em;
  white-space:nowrap;
  user-select:none;
}
.pse-category-pasted-preset-value{
  margin:3px;
  max-width:calc(100% - 6px);
}
.pse-category-pasted-preset-directory{
  display:inline-flex;
  align-items:center;
  max-width:calc(100% - 6px);
  margin:3px;
  padding:7px 9px;
  border:1px solid #9ca3af;
  border-radius:8px;
  background:#f8fafc;
  color:#6b7280;
  font-size:13px;
  font-weight:700;
  line-height:1.25;
  white-space:normal;
  overflow-wrap:anywhere;
}
.pse-category-pasted-preset-directory.has-selected-value{
  border-color:#111827;
  color:#111827;
}

/* ---------- L1 standalone ---------- */
.pse-l1-single{
  position:relative;
  display:inline-flex;
  flex:0 0 auto;
  width:max-content;
  max-width:100%;
  align-items:flex-start;
  padding:4px;
  margin:3px 0;
  border:2px solid #2563eb;
  border-radius:11px;
  background:#eff6ff;
  vertical-align:top;
}
.pse-l1-single .model-output-tag{
  margin:0;
}
.pse-l1-badge{
  position:absolute;
  top:-9px;
  left:8px;
  z-index:2;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:16px;
  padding:1px 5px;
  border:1px solid #60a5fa;
  border-radius:999px;
  background:#ffffff;
  color:#1d4ed8;
  font-size:9px;
  font-weight:900;
  line-height:1;
  user-select:none;
}

/* ---------- L2 grouped ---------- */
.pse-l2-group{
  position:relative;
  display:inline-flex;
  flex:0 1 auto;
  width:max-content;
  max-width:100%;
  flex-wrap:wrap;
  align-items:flex-start;
  align-content:flex-start;
  gap:0;
  padding:7px 4px 4px;
  margin:3px 0;
  border:2px solid #22c55e;
  border-radius:12px;
  background:#f0fdf4;
  vertical-align:top;
}

/* Absolute label does NOT enlarge the green box horizontally. */
.pse-l2-label{
  position:absolute;
  top:-9px;
  left:8px;
  z-index:2;
  display:inline-flex;
  width:auto;
  max-width:calc(100% - 16px);
  align-items:center;
  gap:4px;
  margin:0;
  padding:0 3px;
  background:#f0fdf4;
  color:#15803d;
  font-size:9px;
  font-weight:800;
  line-height:1.2;
  letter-spacing:.015em;
  white-space:nowrap;
  user-select:none;
}
.pse-l2-label-code{
  display:inline-flex;
  align-items:center;
  min-height:15px;
  padding:1px 4px;
  border-radius:999px;
  background:#dcfce7;
  border:1px solid #86efac;
}
.pse-l2-label-type{color:#166534}
.pse-l2-label-inherited{
  color:#92400e;
  background:#fef3c7;
  border:1px solid #fde68a;
  border-radius:999px;
  padding:1px 4px;
}
.pse-l2-group .model-output-tag{
  flex:0 1 auto;
  margin:3px;
}

/* A long natural-language L1 may consume the available width;
   short groups remain only as wide as their actual contents. */
.pse-l2-group .model-output-tag{
  max-width:calc(100% - 6px);
}

.pse-l2-group[data-l2-break="true"]{
  border-style:solid;
}
.pse-control-break-tag{
  font-weight:900;
}



/* ---------- v1.9 HEAD ownership ---------- */
.pse-head-scope-owned{
  border-style:solid;
}
.pse-head-scope-owned > .pse-l2-label{
  background:#f0fdf4;
}
.pse-head-nested-break{
  flex:0 0 100%;
  width:100%;
  margin-top:5px;
  padding-top:4px;
}
.pse-head-correction{
  display:inline-flex;
  align-items:center;
  margin-left:4px;
  padding:0 4px;
  min-height:15px;
  border-radius:999px;
  border:1px solid #60a5fa;
  background:#eff6ff;
  color:#1d4ed8;
  font-size:9px;
  font-weight:900;
  line-height:1;
}

/* ---------- BREAK SCOPE ---------- */
.pse-break-scope{
  display:inline-flex;
  flex:0 1 auto;
  width:max-content;
  max-width:100%;
  flex-wrap:wrap;
  align-items:flex-start;
  align-content:flex-start;
  gap:0;
  margin:4px 0;
  padding:8px 5px 5px;
  border:2px dashed #7c3aed;
  border-radius:13px;
  background:#f5f3ff;
  position:relative;
  vertical-align:top;
}
.pse-break-scope-label{
  position:absolute;
  top:-10px;
  left:8px;
  z-index:3;
  display:inline-flex;
  align-items:center;
  gap:4px;
  max-width:calc(100% - 16px);
  padding:1px 5px;
  border:1px solid #a78bfa;
  border-radius:999px;
  background:#ffffff;
  color:#6d28d9;
  font-size:9px;
  font-weight:900;
  line-height:1.15;
  white-space:nowrap;
  user-select:none;
}
.pse-break-scope-merge{
  border-color:#c026d3;
  background:#fdf4ff;
}
.pse-break-scope-merge .pse-break-scope-label{
  color:#a21caf;
  border-color:#e879f9;
}
.pse-break-scope .model-output-tag{
  margin:3px;
}
.pse-category-correction{
  display:inline-flex;
  align-items:center;
  margin-left:4px;
  padding:0 4px;
  min-height:15px;
  border-radius:999px;
  border:1px solid #e879f9;
  background:#fdf4ff;
  color:#a21caf;
  font-size:9px;
  font-weight:900;
  line-height:1;
}
.pse-control-mark{
  display:inline-flex;
  align-items:center;
  margin-left:4px;
  padding:0 4px;
  min-height:15px;
  border-radius:999px;
  border:1px solid #94a3b8;
  background:#f8fafc;
  color:#475569;
  font-size:9px;
  font-weight:900;
  line-height:1;
}

/* ---------- L3 full-width ---------- */
.pse-l3-group{
  flex:0 0 100%;
  width:100%;
  display:block;
  margin:10px 0 12px;
  padding:8px;
  border:2px solid #f59e0b;
  border-radius:15px;
  background:#fffbeb;
}
.pse-l3-label{
  display:flex;
  align-items:center;
  gap:6px;
  margin:0 2px 7px;
  color:#92400e;
  font-size:10px;
  font-weight:900;
  letter-spacing:.025em;
  user-select:none;
}
.pse-l3-label-code{
  display:inline-flex;
  align-items:center;
  min-height:18px;
  padding:2px 6px;
  border-radius:999px;
  background:#fef3c7;
  border:1px solid #fbbf24;
}
.pse-l3-label-type{color:#92400e}
.pse-l3-content{
  display:flex;
  flex-wrap:wrap;
  align-items:flex-start;
  align-content:flex-start;
  gap:8px 8px;
  width:100%;
}
.pse-l3-content > .pse-l1-single,
.pse-l3-content > .pse-l2-group{
  margin-top:3px;
  margin-bottom:3px;
}
