/* ============================================================================
 * Shared Workspace Sidebar Component
 * ============================================================================
 * SINGLE SOURCE OF TRUTH for workspace sidebar layout.
 * Used by: Writer, Scholar, Visualizer, Console, Verifier, Hub, Tools
 *
 * Usage: Add class="stx-shell-sidebar" alongside module-specific class:
 *   <aside class="writer-sidebar stx-shell-sidebar" id="writer-sidebar">
 *
 * Module CSS should ONLY define overrides (e.g. background color).
 * ========================================================================== */

/* ===========================================================================
   WORKSPACE LAYOUT CONTAINER
   Standard 3-panel flex layout used by all workspace modules
   =========================================================================== */

.stx-shell-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
  background: var(--workspace-bg-primary, #0d0d0d);
  gap: 0;
}

/* ===========================================================================
   SIDEBAR BASE
   =========================================================================== */

.stx-shell-sidebar {
  width: 250px;
  min-width: var(--ui-collapsed-pane-width, 48px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--workspace-bg-primary, #0d0d0d);
  transition:
    width 0.2s ease,
    min-width 0.2s ease;
  flex-shrink: 0;
  border-right: none; /* Resizer handles visual separation */
  border-bottom: 1px solid var(--workspace-border-default, #3a3a3a);
}

/* ===========================================================================
   SIDEBAR HEADER - 50px standardized
   =========================================================================== */

.stx-shell-sidebar .stx-shell-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 50px;
  min-height: 50px;
  border-bottom: 1px solid var(--workspace-border-default, #3a3a3a);
  background: var(--workspace-bg-secondary, #151515);
  flex-shrink: 0;
  box-sizing: border-box;
  overflow: hidden;
  min-width: 0;
  position: relative;
}

/* Sidebar title: hidden when expanded, vertical text when collapsed */
.stx-shell-sidebar .stx-shell-sidebar__title {
  display: none;
}

.stx-shell-sidebar .stx-shell-sidebar__header h4,
.stx-shell-sidebar .stx-shell-sidebar__header h5 {
  margin: 0;
  padding: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  color: var(--text-primary, #d4e1e8);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.stx-shell-sidebar .stx-shell-sidebar__header h5 i {
  color: var(--workspace-icon-primary, #059669);
}

/* ===========================================================================
   SIDEBAR CONTENT
   =========================================================================== */

.stx-shell-sidebar .stx-shell-sidebar__content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 8px 2px 8px 0;
  background: var(--workspace-bg-monaco, #1e1e1e);
  border-bottom: 1px solid var(--workspace-border-default, #3a3a3a);
}

/* ===========================================================================
   SIDEBAR TOGGLE BUTTON
   =========================================================================== */

.stx-shell-sidebar .stx-shell-sidebar__toggle,
.stx-shell-sidebar .stx-shell-sidebar__toggle-btn {
  background: none;
  border: none;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--text-muted, #6c8ba0);
  border-radius: 4px;
  transition: all 0.15s ease;
}

.stx-shell-sidebar .stx-shell-sidebar__toggle:hover,
.stx-shell-sidebar .stx-shell-sidebar__toggle-btn:hover {
  background: var(--workspace-bg-tertiary, #1a1a1a);
  color: var(--workspace-icon-primary, #059669);
}

/* ===========================================================================
   COLLAPSED STATE
   =========================================================================== */

.stx-shell-sidebar.collapsed {
  width: var(--ui-collapsed-pane-width, 48px) !important;
  min-width: var(--ui-collapsed-pane-width, 48px) !important;
  zoom: 1 !important; /* Neutralize context-aware zoom when collapsed */
  cursor: pointer;
}

.stx-shell-sidebar.collapsed .stx-shell-sidebar__content {
  display: none;
}

.stx-shell-sidebar.collapsed .stx-shell-sidebar__header {
  padding: 8px 0 0;
  justify-content: flex-start;
  align-items: center;
  height: 100%;
  flex-direction: column;
  border-bottom: none;
}

/* Hide everything in header except the toggle button and sidebar title */
.stx-shell-sidebar.collapsed
  .stx-shell-sidebar__header
  > *:not(.stx-shell-sidebar__toggle):not(.stx-shell-sidebar__toggle-btn):not(.panel-toggle-btn):not(
    .stx-shell-sidebar__title
  ) {
  display: none;
}

/* Show sidebar title with icon + label when collapsed, stacked vertically. */
.stx-shell-sidebar.collapsed .stx-shell-sidebar__title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  font-weight: 500;
  color: var(--text-secondary, #8ba7b8);
  margin: 4px 0 0;
  white-space: nowrap;
  line-height: 1;
}

/* Icon visible, top-aligned */
.stx-shell-sidebar.collapsed .stx-shell-sidebar__title i {
  display: block;
  font-size: var(--ui-nav-icon-size, 20px);
  color: var(--text-secondary, #8ba7b8);
}

.stx-shell-sidebar.collapsed .stx-shell-sidebar__toggle,
.stx-shell-sidebar.collapsed .stx-shell-sidebar__toggle-btn,
.stx-shell-sidebar.collapsed .panel-toggle-btn {
  border: none;
  margin: 4px 0;
  padding: 4px;
}

/* Green indicator bar for stx-shell-sidebar is defined in collapsible-panel.css
   (single source of truth for all expanded panel headers) */

/* Subtle green-tinted background + edge glow on hover */
.stx-shell-sidebar.collapsed:hover,
.stx-shell-sidebar.collapsed:hover .stx-shell-sidebar__header {
  background: rgba(5, 150, 105, 0.08) !important;
}
.stx-shell-sidebar.collapsed:hover {
  box-shadow: inset -3px 0 10px -4px var(--workspace-icon-primary);
}
[data-theme="light"] .stx-shell-sidebar.collapsed:hover,
[data-theme="light"] .stx-shell-sidebar.collapsed:hover .stx-shell-sidebar__header {
  background: rgba(5, 150, 105, 0.06) !important;
}

/* ===========================================================================
   WORKSPACE MAIN CONTENT
   =========================================================================== */

.workspace-main {
  flex: 1;
  overflow: hidden;
  min-width: 0;
  background: var(--workspace-bg-primary);
}

/* ===========================================================================
   LIGHT THEME
   =========================================================================== */

[data-theme="light"] .stx-shell-sidebar {
  background: var(--workspace-bg-primary);
}

[data-theme="light"] .stx-shell-sidebar .stx-shell-sidebar__header {
  background: var(--workspace-bg-secondary);
  border-bottom-color: var(--workspace-border-default);
}

/* ===========================================================================
   MODULE ACCENT BORDER
   Continuous accent line across the top of the module content area.
   Framework-controlled via #main-content[data-app-accent].
   Uses ::before pseudo-element with high z-index to prevent app overrides.

   Usage: Add data-app-accent="writer" on the module container.
   =========================================================================== */

/* Accent line: single continuous bar across the top of module content */
#main-content[data-app-accent]::before {
  content: "" !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: 2px !important;
  background: var(--app-accent-color, transparent) !important;
  z-index: 100 !important;
  pointer-events: none !important;
}

/* Module panel headers still get tinted background */
[data-pane-type="module"] {
  background: var(--app-accent-tint, transparent);
}

/* Per-module accent color scoping (cascades to child pane headers) */
[data-app-accent="writer"] {
  --app-accent-color: var(--app-accent-writer);
  --app-accent-tint: var(--app-accent-writer-tint);
}
[data-app-accent="scholar"] {
  --app-accent-color: var(--app-accent-scholar);
  --app-accent-tint: var(--app-accent-scholar-tint);
}
[data-app-accent="visualizer"],
[data-app-accent="vis"] {
  --app-accent-color: var(--app-accent-visualizer);
  --app-accent-tint: var(--app-accent-visualizer-tint);
}
[data-app-accent="console"] {
  --app-accent-color: var(--app-accent-console);
  --app-accent-tint: var(--app-accent-console-tint);
}
[data-app-accent="clew"] {
  --app-accent-color: var(--app-accent-clew);
  --app-accent-tint: var(--app-accent-clew-tint);
}
[data-app-accent="hub"] {
  --app-accent-color: var(--app-accent-hub);
  --app-accent-tint: var(--app-accent-hub-tint);
}
[data-app-accent="example"] {
  --app-accent-color: var(--app-accent-example);
  --app-accent-tint: var(--app-accent-example-tint);
}
[data-app-accent="tools"] {
  --app-accent-color: var(--app-accent-tools);
  --app-accent-tint: var(--app-accent-tools-tint);
}
[data-app-accent="apps"],
[data-app-accent="store"] {
  --app-accent-color: var(--app-accent-store);
  --app-accent-tint: var(--app-accent-store-tint);
}
[data-app-accent="docs"] {
  --app-accent-color: var(--app-accent-docs);
  --app-accent-tint: var(--app-accent-docs-tint);
}
[data-app-accent="home"] {
  --app-accent-color: var(--app-accent-home);
  --app-accent-tint: var(--app-accent-home-tint);
}
[data-app-accent="discovery"] {
  --app-accent-color: var(--app-accent-discovery);
  --app-accent-tint: var(--app-accent-discovery-tint);
}
[data-app-accent="figrecipe"] {
  --app-accent-color: var(--app-accent-figrecipe);
  --app-accent-tint: var(--app-accent-figrecipe-tint);
}

/* No fallback needed — accent is always on #main-content::before */

/* ===========================================================================
   RESPONSIVE
   =========================================================================== */

@media (max-width: 768px) {
  .stx-shell-sidebar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 100;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  }

  .stx-shell-sidebar.collapsed {
    display: none;
  }
}
