/* ═══════════════════════════════════════════════════════════════════════════
   COMPOSE — Sidebar v6
   Cohesive design system across all panels.
   Consistent 16px edge padding. CSS variables throughout. No shadows.
   Material 3 + Tolstoy website design language.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design constants ────────────────────────────────────────────────── */
:root {
  --sp-pad: 16px;
  --sp-item-h: 36px;
  --sp-control-h: 44px;
  --sp-segment-btn-h: 44px;
  --sp-item-r: 10px;
  --sp-segment-track-pad: 2px;
  --sp-segment-track-radius: 10px;
  --sp-segment-active-radius: calc(var(--sp-segment-track-radius) - var(--sp-segment-track-pad));
  --sp-section-gap: 16px;
  --sp-section-gap-tight: 12px;
  --sp-card-pad: 16px;
  --sp-card-radius: 14px;
  --sp-header-row-h: var(--topbar-h);
  --sp-header-tabs-h: var(--toolbar-h);
  --sp-card-bg: color-mix(in srgb, var(--bg-card) 78%, var(--sidebar-bg));
  --sp-card-border: color-mix(in srgb, var(--border) 84%, var(--border-strong));
  --sp-embed-bg: color-mix(in srgb, var(--fill-muted) 78%, var(--bg-card));
  --sp-segment-bg: color-mix(in srgb, var(--fill-muted) 88%, var(--bg-card));
  --sp-segment-active-bg: var(--bg-card);
  --sp-segment-active-border: color-mix(in srgb, var(--border) 62%, var(--border-strong));
  --sp-header-focus-ring: color-mix(in srgb, var(--accent) 42%, transparent);
  --sp-tab-fg: color-mix(in srgb, var(--text-sec) 88%, var(--text-muted));
  --sp-tab-fg-active: var(--text);
  --sp-tab-fg-selected: var(--accent);
  --sp-tab-hover-bg: color-mix(in srgb, var(--fill-muted) 72%, transparent);
  --sp-tab-active-indicator: var(--accent);
  --sp-context-fg: color-mix(in srgb, var(--text-sec) 82%, var(--text-muted));
  --sp-card-bg-elevated: color-mix(in srgb, var(--sp-card-bg) 92%, var(--bg-card));
  --sp-book-tab-h: 36px;
  --sp-book-tab-radius: 9px;
  --sp-book-tab-gap: 2px;
  --sp-book-tab-border: color-mix(in srgb, var(--border) 62%, transparent);
  --sp-tab-active-bg: var(--chrome-active-bg);
  --sp-tab-active-border: var(--chrome-active-border);
  --sp-tab-indicator-h: 3px;
}


[data-theme="dark"] {
  --sp-card-bg: color-mix(in srgb, var(--bg-card) 86%, var(--sidebar-bg));
  --sp-card-border: color-mix(in srgb, var(--border) 76%, var(--border-strong));
  --sp-tab-fg: color-mix(in srgb, var(--text-sec) 86%, var(--text-muted));
  --sp-tab-fg-active: var(--text);
  --sp-tab-fg-selected: var(--accent);
  --sp-tab-hover-bg: color-mix(in srgb, var(--fill-muted) 86%, transparent);
  --sp-context-fg: color-mix(in srgb, var(--text-sec) 92%, var(--text));
  --sp-header-focus-ring: color-mix(in srgb, var(--accent) 56%, transparent);
  --sp-book-tab-border: color-mix(in srgb, var(--border-strong) 72%, transparent);
  --sp-tab-active-bg: var(--chrome-active-bg);
  --sp-tab-active-border: var(--chrome-active-border);
}

/* ── Sidebar shell ───────────────────────────────────────────────────── */
#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  position: relative;
  overflow: hidden;
}

/* ── Panel stack ─────────────────────────────────────────────────────── */
.sp {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  opacity: 0;
  pointer-events: none;
  transform: translateX(8px);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
}
.sp.is-active {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

/* ── Panel header ────────────────────────────────────────────────────── */
.sp-panel-shell {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.sp-panel-shell.files-subviews,
.sp-panel-shell.navigate-subviews,
.sp-panel-shell.export-subviews,
.sp-panel-shell.settings-subviews,
.sp-panel-shell.workspace-subviews {
  gap: 0;
}

.sp-header {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  min-height: var(--app-header-h);
  height: var(--app-header-h);
  box-sizing: border-box;
  background: var(--topbar-bg);
  border-bottom: 0;
}

.sp-header::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--topbar-border);
  pointer-events: none;
}

.sp-header-top {
  display: flex;
  flex: 0 0 var(--sp-header-row-h);
  align-items: center;
  gap: 12px;
  min-height: var(--sp-header-row-h);
  height: var(--sp-header-row-h);
  padding: 4px var(--header-inline-pad) 5px;
  background: var(--topbar-bg);
}

.sp-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.sp-title-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: var(--text-sec);
  flex: 0 0 auto;
}

.sp-title-icon svg {
  width: 18px;
  height: 18px;
}

.sp-title {
  margin: 0;
  min-width: 0;
  flex: 1 1 auto;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  letter-spacing: -0.02em;
}

.sp-header-context {
  display: none;
}

.sp-context-line {
  margin: 0;
  min-width: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--sp-context-fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sp-header-bottom {
  display: flex;
  flex: 0 0 var(--sp-header-tabs-h);
  align-items: stretch;
  min-height: var(--sp-header-tabs-h);
  height: var(--sp-header-tabs-h);
  padding: 4px var(--header-inline-pad) 6px;
  box-sizing: border-box;
  background: var(--toolbar-bg);
}

.sp-header-bottom .sp-subnav {
  width: 100%;
}

.sp-close,
.sp-close.header-action-btn,
.sp-close.topbar-btn {
  position: static;
  flex: 0 0 auto;
  margin-inline-start: auto;
  inline-size: var(--header-action-size);
  block-size: var(--header-action-size);
  border-radius: 8px;
  z-index: 1;
}
.sp-close svg { width: 17px; height: 17px; }
.sp-close:focus-visible {
  outline: 2px solid var(--sp-header-focus-ring);
  outline-offset: -2px;
}
.sp-close:hover {
  background: var(--sp-tab-hover-bg);
}

/* ── Panel body ──────────────────────────────────────────────────────── */
.sp-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 16px var(--sp-pad) 20px;
}
.sp-body::-webkit-scrollbar-thumb:hover { background: var(--text-disabled); }

.sp-panel-shell:is(.files-subviews, .navigate-subviews, .settings-subviews, .workspace-subviews) > .sp-body {
  padding-top: 14px;
}

[data-subviews-body] {
  gap: var(--sp-section-gap);
}

.navigate-sticky-rail {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 14px;
  background: linear-gradient(to bottom, var(--sidebar-bg) 0%, var(--sidebar-bg) calc(100% - 18px), color-mix(in srgb, var(--sidebar-bg) 0%, transparent) 100%);
}


.navigate-sticky-group {
  box-shadow: 0 1px 0 color-mix(in srgb, var(--sidebar-border) 72%, transparent);
}

/* ── Section and block primitives ───────────────────────────────────── */
.sp-block,
.sp-list {
  min-width: 0;
}

.sp-list {
  display: flex;
  flex-direction: column;
}

.sp-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sp-body > :is(.sp-block, .sp-list, .sp-section, .sp-card) + :is(.sp-block, .sp-list, .sp-section, .sp-card),
.sp-body > .sp-divider + :is(.sp-block, .sp-list, .sp-section, .sp-card),
.sp-body > :is(.sp-block, .sp-list, .sp-section, .sp-card) + .sp-divider {
  margin-top: var(--sp-section-gap);
}

.sp-section--bleed {
  margin-inline: calc(var(--sp-pad) * -1);
}

.sp-section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--text-sec);
  line-height: 1.4;
}

.sp-setting-field {
  gap: 6px;
}

.sp-select {
  height: var(--sp-control-h);
  border-radius: var(--sp-item-r);
  display: block;
  font-weight: 500;
}

.ui-choice-group.sp-choice-group {
  padding: var(--sp-segment-track-pad);
  gap: 2px;
  border-radius: var(--sp-segment-track-radius);
  border: 1px solid color-mix(in srgb, var(--sp-card-border) 72%, transparent);
  background: var(--sp-segment-bg);
}

.sp-choice-group .ui-choice-btn {
  position: relative;
  height: var(--sp-segment-btn-h);
  min-height: var(--sp-segment-btn-h);
  padding-inline: 12px;
  font-size: 12.5px;
  line-height: 1;
  border-radius: var(--sp-segment-active-radius);
}

.sp-choice-group .ui-choice-btn svg {
  width: 11px;
  height: 11px;
}

.sp-choice-group .ui-choice-btn.is-active {
  background: var(--chrome-active-bg);
  color: var(--chrome-active-fg);
  border-color: var(--chrome-active-border);
  box-shadow: var(--chrome-active-shadow);
}

/* ── Shared subview navigation ─────────────────────────────────────── */
.sp-subnav {
  display: flex;
  align-items: stretch;
  gap: var(--sp-book-tab-gap);
  width: 100%;
  height: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.sp-header-bottom .sp-subnav-btn {
  position: relative;
  display: inline-flex;
  flex: 1 1 0;
  align-self: stretch;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  height: 100%;
  margin: 0;
  padding: 0 12px;
  border-radius: var(--sp-book-tab-radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--sp-tab-fg);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), transform 60ms var(--ease);
}

.sp-header-bottom .sp-subnav-btn:hover:not(.is-active),
.sp-header-bottom .sp-subnav-btn.is-hovered:not(.is-active) {
  color: var(--sp-tab-fg-active);
  background: color-mix(in srgb, var(--sp-tab-hover-bg) 78%, transparent);
  border-color: color-mix(in srgb, var(--sp-book-tab-border) 28%, transparent);
}

.sp-header-bottom .sp-subnav-btn:focus-visible {
  outline: 2px solid var(--sp-header-focus-ring);
  outline-offset: -2px;
}

.sp-header-bottom .sp-subnav-btn.is-active,
.sp-header-bottom .sp-subnav-btn[aria-selected='true'] {
  z-index: 1;
  color: var(--sp-tab-fg-selected);
  background: var(--sp-tab-active-bg);
  border-color: var(--sp-tab-active-border);
  box-shadow: var(--chrome-active-shadow);
  transform: none;
}


.sp-header-bottom .sp-subnav-btn.is-active:hover,
.sp-header-bottom .sp-subnav-btn[aria-selected='true']:hover {
  color: var(--sp-tab-fg-selected);
  background: color-mix(in srgb, var(--sp-tab-active-bg) 92%, var(--fill-hover));
}


.sp-subview {
  display: flex;
  flex-direction: column;
  gap: var(--sp-section-gap);
  padding-bottom: 2px;
}

.sp-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--fill-muted) 82%, var(--bg-card));
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.sp-entity-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--sp-card-border);
  background: var(--sp-card-bg-elevated);
  color: var(--text);
  text-align: left;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.sp-entity-btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.sp-entity-btn:disabled {
  opacity: 0.72;
  cursor: default;
}

.sp-entity-btn-leading,
.sp-entity-btn-trailing {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sp-entity-btn-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1 1 auto;
}

.sp-entity-btn-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.sp-entity-btn-title {
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}

.sp-entity-btn-meta {
  min-width: 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-sec);
}

.sp-subview[hidden] {
  display: none !important;
}

/* ── Shared action primitives ───────────────────────────────────────── */
.sp-action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sp-action-row--stack {
  flex-direction: column;
}

.sp-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: var(--sp-item-r);
  border: 1px solid transparent;
  background: var(--fill-muted);
  color: var(--text-sec);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.2;
  text-align: left;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.sp-action-btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.sp-action-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.sp-action-btn:hover:not(:disabled),
.sp-entity-btn:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--interactive-selected-border) 62%, var(--sp-card-border));
  background: color-mix(in srgb, var(--sp-card-bg-elevated) 88%, var(--fill-hover));
}

.sp-action-btn--primary {
  background: var(--accent);
  color: var(--text-on-accent);
}

.sp-action-btn--full {
  width: 100%;
}

.sp-action-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sp-action-btn-icon svg {
  width: 14px;
  height: 14px;
}

/* ── Shared interactive list rows ────────────────────────────────────── */
.sp-list-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  width: 100%;
  border-radius: 0;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.sp-list-row.is-active {
  background: var(--interactive-current-bg);
}

.sp-list-row:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: -2px;
}

.sp-list-row-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.sp-list-row-leading,
.sp-list-row-meta,
.sp-list-row-trailing {
  flex-shrink: 0;
}

.sp-list-row-body {
  min-width: 0;
  flex: 1;
}

.sp-list-row-title {
  display: block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Eyebrow label ───────────────────────────────────────────────────── */
.sp-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sp-eyebrow::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Card primitive ──────────────────────────────────────────────────── */
.sp-card {
  padding: var(--sp-card-pad);
  border-radius: var(--sp-card-radius);
  border: 1px solid var(--sp-card-border);
  background: var(--sp-card-bg);
}

.sp-card-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.sp-card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.sp-card-body {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-sec);
}

.sp-settings-group {
  padding: var(--sp-card-pad);
  gap: 0;
  border-radius: var(--sp-card-radius);
}

.sp-settings-group-header {
  gap: 0;
  margin-bottom: 12px;
}

.sp-settings-group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sp-settings-group-heading-trailing {
  margin-inline-start: auto;
  flex-shrink: 0;
}

.sp-settings-group-title {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

.sp-settings-group-description {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-muted);
}

.sp-settings-group-body {
  display: flex;
  flex-direction: column;
}

.sp-settings-group-body > :is(.sp-block, .sp-list, .sp-section, .sp-card) + :is(.sp-block, .sp-list, .sp-section, .sp-card),
.sp-settings-group-body > .sp-divider + :is(.sp-block, .sp-list, .sp-section, .sp-card),
.sp-settings-group-body > :is(.sp-block, .sp-list, .sp-section, .sp-card) + .sp-divider {
  margin-top: var(--sp-section-gap-tight);
}

@media (forced-colors: active) {
  .sp-close,
  .sp-subnav-btn,
  .sp-action-btn,
  .sp-entity-btn,
  .sp-list-row,
  .sp-select {
    forced-color-adjust: auto;
    border: 1px solid ButtonText;
  }

  .sp-header-bottom .sp-subnav-btn.is-active,
  .sp-header-bottom .sp-subnav-btn[aria-selected='true'] {
    background: Highlight;
    color: HighlightText;
    border-color: Highlight;
    box-shadow: none;
    transform: none;
  }

}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE / TOUCH INTEGRATION
   Sidebar-specific touch behavior formerly lived in 11-mobile-polish.css.
   ═══════════════════════════════════════════════════════════════════════════ */

#sidebar,
.ui-panel-header,
.sp-header,
.header-action-btn,
.tb-btn,
.topbar-btn,
.dropdown-item,
.btn,
.hcp-swatch {
  -webkit-touch-callout: none;
}

#sidebar,
.ui-panel-header,
.sp-header,
.header-action-btn,
.tb-btn,
.topbar-btn,
.dropdown-item,
.btn,
.hcp-swatch,
.sp-close,
.sp-item,
.sp-section-label {
  user-select: none;
  -webkit-user-select: none;
}

@media (pointer: coarse) {
  .sp-item:active {
    background: var(--fill-active);
    transition: background 60ms var(--ease);
  }

  .sp-item,
  .ui-chip,
  .ui-option-btn {
    min-height: 44px;
  }

  .sp-choice-group .ui-choice-btn {
    min-height: var(--sp-segment-btn-h);
  }

  .sp-close,
  .sp-subnav-btn,
  .sp-action-btn {
    min-height: 44px;
  }

  #sidebar {
    transition: transform 280ms cubic-bezier(0.34, 1.20, 0.64, 1) !important;
  }

  #sidebar[data-sidebar-open="false"] {
    transition: transform 240ms cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
  }
}

@media (max-width: 767px) {
  .ui-panel-body,
  .sp-body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scrollbar-width: none;
  }
  .ui-panel-body::-webkit-scrollbar,
  .sp-body::-webkit-scrollbar {
    display: none;
  }

  .ui-panel-header,
  .sp-header {
    min-height: var(--app-header-h);
  }

  .sp-header-top,
  .sp-header-bottom {
    padding-inline: var(--sp-pad);
  }

  .sp-title {
    font-size: 18px;
    line-height: 1.2;
    letter-spacing: -0.02em;
  }

  .sp-item {
    min-height: 44px;
    padding: 10px var(--sp-pad);
  }

  #overlay {
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
}

@media (min-width: 768px) and (max-width: 1024px) and (pointer: coarse) {
  .sp-item {
    min-height: 44px;
  }

  .ui-panel-header,
  .sp-header {
    min-height: var(--app-header-h);
  }
}

:root:is([dir="rtl"]) #sidebar {
  right: auto;
  left: 0;
  border-right: none;
  border-left: 1px solid var(--border);
}

