/* Panel system — ported from test_files/test-panels.html */

.app-shell {
  position: relative;
  height: calc(100vh - 58px);
  min-height: 0;
  overflow: hidden;
  /* Reserve space for fixed side panels so the editor stage squeezes instead of sitting underneath. */
  --stage-inset-left: var(--sidebar-open-default-width);
  --stage-inset-right:0; /* var(--panel-handle-width); */
   
}

.app-shell:has(.panel--left.is-collapsed) {
  --stage-inset-left: var(--sidebar-closed-width);
}

.app-shell:has(.panel--left.is-closed) {
  --stage-inset-left: var(--panel-handle-width);
}

.app-shell:has(.panel--left.is-hidden) {
  --stage-inset-left: 0;
}

.app-shell:has(.panel--right:not(.is-closed):not(.is-hidden):not(.panel--wide)) {
  --stage-inset-right: var(--panel-width-details-effective, var(--panel-width));
}

.app-shell:has(.panel--right.is-hidden) {
  --stage-inset-right: 0;
}

.app-shell[hidden] {
  display: none !important;
}

.app-stage {
  position: relative;
  z-index: 1;
  height: calc(100vh - var(--header-height));
  overflow-y: scroll;
  min-height: 0;
  min-width: 0;
  margin-left: var(--stage-inset-left);
  margin-right: var(--stage-inset-right);
  transition:
    margin-left var(--panel-duration) var(--panel-ease),
    margin-right var(--panel-duration) var(--panel-ease);
}

/* Notes panel is fixed over the stage; shrink the manuscript column when it is open. */
.editor-panel:has(.panel--notes:not(.is-closed):not(.is-hidden)) .editor-section--manuscript {
  margin-left: var(--panel-width-notes-effective, var(--panel-width));
}

/* Base panel (test .panel) */
.panel {
  position: fixed;
  top: 58px;
  height: calc(100vh - 58px);
  background: var(--panel-bg);
  color: var(--text);
  z-index: 9;
  overflow: visible;
  transition:
    width var(--panel-duration) var(--panel-ease),
    transform var(--panel-duration) var(--panel-ease),
    background 0.3s ease;
}

.panel.is-hidden {
  display: none !important;
}

.panel__body {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.panel__body:has(.panel-content) {
  overflow: visible;
  display: flex;
  flex-direction: column;
}

.panel__body.has-layer {
  overflow: hidden;
}

.panel.is-resizing {
  transition: none;
}

.panel.is-resizing .editor-section--manuscript,
.app-shell:has(.panel.is-resizing) .app-stage,
.app-shell:has(.panel.is-resizing) .editor-section--manuscript {
  transition: none;
}

/* ── Resize handle (pill on the seam, vertically centred) ───────────────── */

.panel-resize-handle {
  position: absolute;
  top: 50%;
  width: 6px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 8%, var(--panel-bg));
  cursor: col-resize;
  z-index: 11;
  transform: translateY(-50%);
  touch-action: none;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.panel-resize-handle:hover,
.panel-resize-handle:focus-visible {
  background: var(--header-bg);
  border-color: var(--hairline-strong, var(--hairline));
  outline: none;
}

.panel-resize-handle[hidden] {
  display: none !important;
}

.panel--right .panel-resize-handle--left,
.panel-resize-handle--left {
  left: calc(-1 * var(--panel-handle-width) / 2 - 2px);
}

.panel--notes .panel-resize-handle--right,
.panel-resize-handle--right {
  right: calc(-1 * var(--panel-handle-width) / 2 - 2px);
}

/* ── Panel chrome (single visual spec) ─────────────────────────────────── */

.panel-header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 14px 12px;
  background: var(--panel-bg);
  /* border-bottom: 1px solid var(--hairline); */
}

.panel-header__text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.panel-header__title,
.panel-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--text);
  text-transform: none;
}

.panel-header__title-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: none;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--text);
}

.panel-header__title-input:focus {
  outline: none;
  border-bottom-color: var(--accent);
}

.panel-header__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-dim);
}

.panel-header__meta:empty {
  display: none;
}

.panel-header__meta-text {
  white-space: nowrap;
}

.panel-header button {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  border-radius: var(--radius-xs);
  padding: 15px 7px;
  font-size: 13px;
  transition: background 0.15s ease, color 0.15s ease;
}

.panel-header button:hover {
  background: color-mix(in srgb, var(--text) 7%, transparent);
  color: var(--text);
}

.panel-header [data-panel-header-slot] {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

.panel__body.has-panel-close > .panel-header,
.panel-layer .panel-header {
  padding-right: 48px;
}

.panel-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 6;
}

.panel-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--panel-bg);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.panel-layer.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.panel-layer.is-closing {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
}

.panel-layer[hidden] {
  display: none !important;
}

.panel-nav {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  height: var(--panel-nav-height, 34px);
  min-height: var(--panel-nav-height, 34px);
  padding: 0 14px;
  box-sizing: border-box;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--hairline);
}

.panel-nav:empty,
.panel-nav[hidden] {
  display: none;
}

.panel-nav:has(.panel-nav__links) {
  height: auto;
  min-height: var(--panel-nav-height, 34px);
  padding: 8px 14px;
  align-items: flex-start;
}

.panel-nav__links {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.panel-nav__link,
.panel-nav a,
.panel-nav button.panel-nav__link {
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  color: var(--accent);
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.panel-nav__link:hover,
.panel-nav a:hover,
.panel-nav button.panel-nav__link:hover {
  text-decoration: underline;
}

.panel-actions {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-bottom: 1px solid var(--hairline);
  background: var(--panel-bg);
  overflow: visible;
  position: relative;
  z-index: 4;
}

.panel-actions[hidden],
.panel-footer[hidden] {
  display: none !important;
}

.panel-actions .action-button-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.panel-actions .action-button-group button {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--text) 4%, transparent);
  color: var(--text);
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.panel-actions .action-button-group button.is-active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--hairline));
  color: var(--accent);
}

.panel-actions .action-button-group button[id$="-save"] {
  background: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 80%, var(--hairline));
  color: var(--heading, #fff);
}

.panel-actions .action-button-group button[id$="-save"]:hover {
  background: color-mix(in srgb, var(--accent) 88%, var(--text));
}

.panel-actions #add-note-button {
  min-width: 28px;
  padding: 4px 8px;
  font-size: 17px;
  font-weight: 500;
  line-height: 1;
}

.panel-actions .action-button-group > .panel-actions__stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  flex: 1 1 100%;
}

.panel-actions .notes-panel-colour-mixer {
  flex-shrink: 0;
}

.panel-actions .notes-panel-colour-mixer button.colour-mixer__trigger,
.panel-actions .notes-panel-colour-mixer button.colour-mixer__swatch {
  padding: 0;
  min-width: 0;
  line-height: 0;
  font-weight: inherit;
  border-radius: var(--colour-mixer-radius);
}

.panel-actions .notes-panel-colour-mixer button.colour-mixer__swatch:not(.colour-mixer__swatch--custom) {
  background: none;
}

.panel-actions .notes-panel-colour-mixer .colour-mixer__swatch--custom,
.panel-actions .notes-panel-colour-mixer .colour-mixer__swatch--custom:hover {
  background: var(--input-bg);
}

.panel-actions .notes-panel-colour-mixer .colour-mixer__popout {
  z-index: 50;
}

.panel-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px 14px;
}

.panel-footer {
  flex: 0 0 auto;
  padding: 10px 14px 12px;
  background: var(--panel-bg);
  border-top: 1px solid var(--hairline);
}

.panel-footer__links {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.panel-footer__link,
.panel-footer a,
.panel-footer button.panel-footer__link {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.panel-footer__link:hover,
.panel-footer a:hover,
.panel-footer button.panel-footer__link:hover {
  text-decoration: underline;
}

/* LEFT (test .left) */
.panel--left {
  left: 0;
  width: var(--sidebar-open-default-width);
  transform: translateX(0);
  border-right: 1px solid var(--hairline);
}

.panel--left.is-collapsed {
  width: var(--sidebar-closed-width);
}

.panel--left.is-closed {
  transform: translateX(calc(-105% + var(--panel-handle-width)));
}

/* RIGHT (test .right) */
.panel--right:not(.panel--wide) {
  right: 0;
  width: var(--panel-width-details-effective, var(--panel-width));
  transform: translateX(0);
  z-index: 8;
  border-left: 1px solid var(--hairline);
}

.panel--right.is-closed {
  transform: translateX(calc(104% - var(--panel-handle-width)));
}

/* Notes — same is-closed pattern; left tracks menu via :has (no JS) */
.panel--notes {
  left: var(--sidebar-open-default-width);
  width: var(--panel-width-notes-effective, var(--panel-width));
  transform: translateX(0);
  z-index: 7;
  border-right: 1px solid var(--hairline);
  transition:
    left var(--panel-duration) var(--panel-ease),
    width var(--panel-duration) var(--panel-ease),
    transform var(--panel-duration) var(--panel-ease),
    background 0.3s ease;
}

.panel--notes.is-closed {
  transform: translateX(calc(-104% + var(--panel-handle-width)));
}

.app-shell:has(.panel--left.is-collapsed) .panel--notes {
  left: var(--sidebar-closed-width);
}

.app-shell:has(.panel--left.is-closed) .panel--notes {
  left: 0;
}

.sidebar-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  height: 100%;
  min-height: 0;
}

.sidebar-panel > .panel__body {
  min-height: 0;
  overflow: hidden;
}

.menu-content {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* MENU labels (test .label) */
.panel-label,
#sidebar-root .group-btn,
#sidebar-root .entity-btn,
#sidebar-root .entity-subtitle {
  overflow: hidden;
  white-space: nowrap;
  opacity: 1;
  max-width: 10rem;
  transition:
    opacity var(--panel-duration) var(--panel-ease),
    max-width var(--panel-duration) var(--panel-ease);
}

.panel--left.is-collapsed .panel-label,
.panel--left.is-collapsed #sidebar-root .group-btn,
.panel--left.is-collapsed #sidebar-root .entity-btn,
.panel--left.is-collapsed #sidebar-root .entity-subtitle {
  opacity: 0;
  max-width: 0;
}

/* HANDLES (test .handle — always on the seam) */
.panel-handle {
  position: absolute;
  
  width: var(--panel-handle-width);
  height: var(--panel-handle-height);
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-bg);
  border: 1px solid var(--hairline);
  color: var(--text-faint);
  cursor: pointer;
  z-index: 10;
  transform: translateY(-50%);
  transition: color 0.18s ease, background 0.18s ease;
}


.panel--left .panel-handle {
  top: calc(var(--panel-handle-top-offset) + (var(--panel-handle-height) * 0));
}

.panel--notes .panel-handle {
  top: calc(var(--panel-handle-top-offset) + (var(--panel-handle-height) * 1));
}

.panel--right .panel-handle {
  top: calc(var(--panel-handle-top-offset) + (var(--panel-handle-height) * 2));
}


.panel-handle.is-hidden {
  display: none !important;
}

.panel-handle:hover {
  color: var(--accent);
  background: var(--header-bg);
}

.panel-handle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.panel-handle img {
  display: none;
}

.panel-handle .ui-caret--horizontal { color: currentColor; }

.panel--left:not(.is-collapsed):not(.is-closed) .panel-handle--right .ui-caret--horizontal {
  transform: rotate(180deg);
}

.panel--right.is-closed .panel-handle--left .ui-caret--horizontal,
.panel--notes.is-closed .panel-handle--left .ui-caret--horizontal {
  transform: rotate(180deg);
}

.panel--left .panel-handle,
.panel-handle--right {
  right: calc(-1 * var(--panel-handle-width));
  border-left-color: transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.panel--right .panel-handle,
.panel-handle--left {
  left: calc(-1 * var(--panel-handle-width));
  border-right-color: transparent;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.panel-handle[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--text);
  background: var(--header-bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 11;
}

.panel-handle[data-tooltip]:hover::before,
.panel-handle[data-tooltip]:focus-visible::before {
  opacity: 1;
}

.panel-handle--right[data-tooltip]::before {
  left: calc(100% + 8px);
}

.panel-handle--left[data-tooltip]::before {
  right: calc(100% + 8px);
}

.panel--notes .panel__body {
  padding-left: calc(var(--panel-handle-width) + 0px);
}

@media (max-width: 1180px) {
  .panel--right {
    box-shadow: -22px 0 48px -28px rgba(0, 0, 0, 0.55);
  }
}
