/**
 * layout.css - Page Layout, Header, Panels, and Input Areas
 * Codex Platform - CSS Module 3/4
 */

/* =============================================
   APP CONTAINER
   ============================================= */

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* =============================================
   HEADER
   ============================================= */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  height: 53px;
  min-height: 53px;
  padding: 0 18px;
  background-color: var(--dc-paper);
  border-bottom: 1px solid var(--dc-line);
  color: var(--dc-ink);
  flex-shrink: 0;
}

/* The globe and the wordmark are one lockup; the tagline is a rank below it.
   Equal gaps made all three read as peers, so the lockup closes up and the
   tagline steps further out. */
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-header .logo {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.02em;
  overflow: hidden;
}

.header-left h1 {
  display: flex;
  align-items: center;
  /* Close to a word space at 15px so the name and its attribution read as one line
     despite the weight and size change between them. */
  gap: 8px;
  min-width: 0;
  margin: 0;
  line-height: 1.2;
  color: var(--dc-ink);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.powered-by {
  font-weight: 400;
  color: var(--dc-ink-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  letter-spacing: 0;
}

.header-left h1 > .powered-by:first-child {
  color: var(--dc-ink);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header-copilot-icon {
  width: 16px;
  height: 16px;
  vertical-align: middle;
}

.header-globe-icon {
  width: 24px;
  height: 24px;
  vertical-align: middle;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.header-feedback-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-feedback-action {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--dc-line);
  border-radius: 8px;
  background: var(--dc-paper);
  color: var(--dc-ink-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.header-feedback-action[hidden] {
  /* SR freeze: hidden header feedback actions must stay display:none because
     the base inline-flex rule otherwise overrides the hidden attribute. Do not
     change without three explicit SR approvals. */
  display: none;
}

.header-feedback-action:hover {
  background: var(--dc-paper);
  color: var(--dc-ink);
  border-color: var(--dc-line-hover);
}

.header-feedback-action:focus-visible {
  outline: 2px solid var(--dc-accent);
  outline-offset: 2px;
}

.header-learning-action {
  color: var(--dc-ink-2);
}

#guidedTourHeaderBtn > svg,
#guidedTourHeaderBtn > [aria-hidden="true"] {
  color: var(--dc-accent);
}

.first-run-whoami-highlight {
  animation: first-run-whoami-pulse 1s ease-in-out 4;
  border-color: var(--dc-accent);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--dc-accent) 18%, transparent),
    0 0 22px color-mix(in srgb, var(--dc-accent) 28%, transparent);
}

@keyframes first-run-whoami-pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.07);
  }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-shrink: 0;
}

/* Status Indicator */
.codex-status {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 6px var(--spacing-md);
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-round);
  background-color: var(--text-muted);
}

.status-dot.active {
  background-color: var(--accent-success);
}

.status-text {
  color: var(--text-secondary);
}

/* =============================================
   MAIN CONTENT AREA
   ============================================= */

.main-content {
  display: flex;
  flex: 1 1 auto; /* Grow and shrink */
  min-height: 0; /* Critical for flexbox scroll - allows children to scroll */
  overflow: hidden;
  align-items: stretch; /* Children fill height */
}

/* =============================================
   HAMBURGER BUTTON
   ============================================= */

.btn-hamburger {
  padding: var(--spacing-sm);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.btn-hamburger:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-hamburger svg {
  display: block;
}

/* =============================================
   INSIGHTS TOGGLE BUTTON
   ============================================= */

.btn-insights-toggle {
  padding: var(--spacing-sm);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.btn-insights-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-insights-toggle.active {
  color: var(--accent-primary);
  background: rgba(0, 122, 204, 0.1);
}

.btn-insights-toggle svg {
  display: block;
}

/* Header theme toggle: pure-CSS icon swap keyed off the same [data-theme] attribute
   applyTheme() (js/app.js) already sets/removes - no separate JS state. Mirrors the
   existing themeMenuIcon convention: show the icon for the mode you'll switch TO
   (moon while light = switch to dark; sun while dark = switch to light). */
.btn-theme-toggle .theme-toggle-icon {
  display: block;
}

.btn-theme-toggle .theme-toggle-icon-moon {
  display: none;
}

html[data-theme="light"] .btn-theme-toggle .theme-toggle-icon-sun {
  display: none;
}

html[data-theme="light"] .btn-theme-toggle .theme-toggle-icon-moon {
  display: block;
}

/* =============================================
   LEFT NAVIGATION
   ============================================= */

.left-nav-rail {
  width: 74px;
  min-width: 74px;
  height: 100%;
  align-self: stretch;
  background: var(--dc-ground);
  border-right: 1px solid var(--dc-line);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 18px;
  padding: 14px 0;
  overflow: hidden;
  z-index: 1;
}

.left-nav-rail-btn {
  position: relative;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 0 7px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--dc-ink-2);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  line-height: 1.25;
  box-shadow: none;
  transition: color 160ms ease-out, background-color 160ms ease-out;
}

.left-nav-rail-btn:hover,
.left-nav-rail-btn.active {
  color: var(--dc-accent);
  background: var(--dc-paper);
}

.left-nav-rail-btn:focus-visible {
  outline: 2px solid var(--dc-accent);
  outline-offset: -4px;
}

.left-nav-rail-icon {
  width: 19px;
  height: 19px;
  line-height: 0;
}

.left-nav-rail-icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.left-nav-rail-label {
  font-size: 10.5px;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: 0;
  text-transform: none;
}

.left-nav-active-indicator {
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  border-radius: 0 999px 999px 0;
  background: var(--dc-accent);
  opacity: 0;
  transform: scaleY(0.45);
  transition: opacity 160ms ease-out, transform 160ms ease-out;
}

.left-nav-rail-btn.active .left-nav-active-indicator {
  opacity: 1;
  transform: scaleY(1);
}

.sessions-sidebar {
  width: 260px;
  min-width: 260px;
  height: 100%; /* Fill parent height */
  align-self: stretch; /* Fill parent height */
  min-height: 0; /* Critical for flexbox scroll - allows shrinking below content height */
  background-color: var(--dc-sunk, var(--dc-band));
  border-right: 1px solid var(--dc-line);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Contain children */
  transition: margin-left 240ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 180ms ease-out, box-shadow 240ms ease-out;
  box-shadow: 14px 0 34px rgba(15, 23, 42, 0.08);
}

.sessions-sidebar.collapsed {
  margin-left: -260px;
  opacity: 0;
  pointer-events: none;
  box-shadow: none;
}

.left-nav-pane {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.left-nav-pane[hidden] {
  display: none;
}

.left-nav-section-header {
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--border-color);
}

.left-nav-section-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.left-nav-section-header p {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-tertiary);
}

.left-nav-admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: var(--spacing-md);
  overflow-y: auto;
}

.left-nav-admin-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-primary);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}

.left-nav-admin-item:hover {
  background: var(--bg-secondary);
  border-color: rgba(79, 70, 229, 0.28);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}

.left-nav-admin-icon {
  width: 24px;
  flex: 0 0 24px;
  text-align: center;
  line-height: 1.25;
}

.left-nav-admin-item strong {
  display: block;
  font-size: 13px;
  line-height: 1.2;
}

.left-nav-admin-item small {
  display: block;
  margin-top: 3px;
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 1.35;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--dc-line);
  flex-shrink: 0;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--dc-ink);
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-refresh-sessions,
.sidebar-header .btn-new-session,
.btn-new-folder {
  min-width: 30px;
  height: 30px;
  padding: 4px 6px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--dc-ink);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-refresh-sessions:hover,
.sidebar-header .btn-new-session:hover,
.btn-new-folder:hover {
  background: var(--dc-band);
  color: var(--dc-ink);
}

.btn-refresh-sessions.spinning {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.sidebar-search {
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--dc-line);
  flex-shrink: 0;
}

.sidebar-search .sessions-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--dc-line);
  border-radius: var(--radius-md);
  background: var(--dc-paper);
  color: var(--dc-ink);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.sidebar-search .sessions-search-input:focus {
  border-color: var(--dc-accent);
}

.sidebar-search .sessions-search-input::placeholder {
  color: var(--dc-ink-2);
}

.sessions-sidebar-list {
  flex: 1;
  min-height: 0; /* Critical for flexbox scroll - allows shrinking below content height */
  overflow-y: auto;
  padding: var(--spacing-sm);
}

.sessions-sidebar-list::-webkit-scrollbar {
  width: 10px;
}

.sessions-sidebar-list::-webkit-scrollbar-track {
  background: transparent;
}

.sessions-sidebar-list::-webkit-scrollbar-thumb {
  background: var(--dc-line);
  border-radius: 5px;
}

.session-sidebar-item {
  position: relative;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  gap: var(--spacing-sm);
  margin-bottom: 2px;
  user-select: none;
  -webkit-user-select: none;
}
.session-sidebar-item[draggable="true"] {
  cursor: grab;
}
.session-sidebar-item[draggable="true"]:active {
  cursor: grabbing;
}

.session-sidebar-item:hover {
  background: var(--dc-band);
  box-shadow: inset 0 0 0 1px var(--dc-line-hover);
}

.session-sidebar-item.active {
  background: var(--dc-paper);
  border-left: 3px solid var(--dc-accent);
  padding-left: 9px;
}

.session-sidebar-item:focus-visible,
.session-folder-header:focus-visible {
  outline: 2px solid var(--dc-accent);
  outline-offset: -2px;
}

.session-sidebar-icon {
  font-size: 14px;
  opacity: 0.7;
  flex-shrink: 0;
}

.session-sidebar-title {
  flex: 1;
  font-size: var(--font-size-base);
  color: var(--dc-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.session-sidebar-actions {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  background: var(--dc-band);
  border-radius: var(--radius-sm);
  padding: 1px 2px;
}

.session-sidebar-item:hover .session-sidebar-actions {
  opacity: 1;
  pointer-events: auto;
}

.session-sidebar-rename,
.session-sidebar-move,
.session-sidebar-delete,
.session-sidebar-share,
.session-sidebar-unshare {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--dc-ink-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.session-sidebar-rename:hover {
  background: var(--dc-accent);
  color: white;
}

.session-sidebar-move:hover {
  background: var(--dc-accent);
  color: white;
}

.session-sidebar-delete:hover {
  background: var(--accent-error);
  color: white;
}

.session-sidebar-share:hover,
.session-sidebar-unshare:hover {
  background: var(--accent-primary);
  color: white;
}

.sessions-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xl);
  color: var(--dc-ink-2);
  font-size: 13px;
  gap: var(--spacing-sm);
}

/* ── Session Folders ── */
.session-folder { margin-bottom: 0; }

.session-folder-header {
  display: flex;
  align-items: center;
  padding: 4px 12px;
  cursor: pointer;
  border-radius: var(--radius-md);
  gap: 6px;
  user-select: none;
  position: relative;
}
.session-folder-header:hover {
  background: var(--dc-band);
  box-shadow: inset 0 0 0 1px var(--dc-line-hover);
}

.folder-collapse-icon {
  font-size: 10px;
  transition: transform 0.15s ease;
  color: var(--dc-ink-2);
  width: 12px;
  text-align: center;
}
.session-folder.collapsed .folder-collapse-icon { transform: rotate(-90deg); }

.folder-icon { font-size: 13px; }
.folder-name {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--dc-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-count {
  font-size: 11px;
  color: var(--dc-ink-2);
  margin-left: 4px;
}

.session-folder-items { padding-left: 4px; position: relative; }
.session-folder.collapsed .session-folder-items { display: none; }

/* Items inside a folder — tight rows with L-bar tree connectors (fork items excluded) */
.session-folder-items .session-sidebar-item:not(.session-fork-item) {
  padding-top: 4px !important;
  padding-bottom: 4px !important;
  padding-left: 24px !important;
  margin-bottom: 0 !important;
  position: relative;
  font-size: 0.91em;
}

/* Vertical connector — full height by default (T-junction), trimmed for last item (L-shape) */
.session-folder-items .session-sidebar-item:not(.session-fork-item)::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--dc-line);
}

/* Horizontal tick — the L-bar arm */
.session-folder-items .session-sidebar-item:not(.session-fork-item)::after {
  content: '';
  position: absolute;
  left: 10px;
  top: 50%;
  width: 10px;
  height: 1px;
  background: var(--dc-line);
}

/* Last item — vertical line stops at mid-height, making a clean └ */
.session-folder-items .session-sidebar-item:not(.session-fork-item):last-child::before {
  bottom: 50%;
}

/* First item — start just below folder header */
.session-folder-items .session-sidebar-item:not(.session-fork-item):first-child::before {
  top: -2px;
}

.folder-actions {
  /* P20.C.2 (2026-05-19): absolute overlay matches .session-sidebar-actions
     pattern so .folder-name reclaims the reserved-icon-strip width and stops
     truncating. Visible on header hover only; bg mask covers underlying text. */
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  background: var(--dc-band);
  border-radius: var(--radius-sm);
  padding: 1px 2px;
  flex-shrink: 0;
}
.session-folder-header:hover .folder-actions {
  opacity: 1;
  pointer-events: auto;
}

.folder-rename, .folder-move, .folder-delete {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--dc-ink-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all var(--transition-fast);
}
.folder-rename:hover, .folder-move:hover, .folder-delete:hover {
  background: var(--dc-band);
  color: var(--dc-ink);
}

/* Nested folder indentation */
.session-folder--nested {
  margin-left: 14px;
  position: relative;
}
.session-folder--nested > .session-folder-header {
  font-size: 0.93em;
}

/* System folder (Scratch-pad) header — subtle tinted background */
.session-folder[data-is-system="1"] > .session-folder-header {
  background: var(--dc-band);
  border-radius: var(--radius-sm);
  opacity: 0.9;
}

/* Move-to-folder dropdown */
.move-folder-menu {
  position: fixed;
  z-index: 9999;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  max-height: 280px;
  overflow-y: auto;
  padding: 4px 0;
}
.move-folder-option {
  display: block;
  width: 100%;
  padding: 6px 12px;
  border: none;
  background: none;
  text-align: left;
  color: var(--text-primary);
  font-size: 12px;
  cursor: pointer;
}
.move-folder-option:hover,
.move-folder-option.kb-focus {
  background: var(--bg-hover, var(--bg-tertiary));
}
.move-folder-option:hover { background: var(--bg-hover); }

/* P21 (2026-05-20): collapsible folder-tree picker */
.folder-tree-menu {
  min-width: 240px;
  max-width: 360px;
  max-height: 420px;
  padding: 6px 0;
  font-size: 13px;
}
.folder-tree-node { display: block; }
.folder-tree-row {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.folder-tree-row:hover { background: var(--bg-hover, var(--bg-tertiary)); }
.folder-tree-row.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.folder-tree-row.disabled:hover { background: transparent; }
.folder-tree-row.top-level {
  font-style: italic;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 4px;
}
.folder-tree-toggle {
  display: inline-block;
  width: 14px;
  text-align: center;
  margin-right: 4px;
  color: var(--text-secondary);
  font-size: 10px;
  flex-shrink: 0;
}
.folder-tree-toggle.empty { visibility: hidden; }
.folder-tree-toggle:hover { color: var(--text-primary); }
.folder-tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}
.folder-tree-children { display: none; }

/* Drag-and-drop feedback */
.session-folder-header.drag-over {
  background: var(--bg-tertiary);
  outline: 2px dashed var(--accent-color);
  outline-offset: -2px;
}
.drop-zone-top {
  min-height: 4px;
}
.drop-zone-top.drag-over {
  background: var(--bg-tertiary);
  outline: 2px dashed var(--accent-color);
  outline-offset: -2px;
  border-radius: var(--radius-md);
}
.session-sidebar-item.dragging {
  opacity: 0.4;
}
.session-sidebar-item.is-moving,
.session-sidebar-item.is-deleting,
.session-folder.is-moving > .session-folder-header {
  background: var(--bg-tertiary);
  outline: 2px solid var(--accent-color);
  outline-offset: -2px;
}
.session-sidebar-item.is-deleting {
  opacity: 0.75;
}
.sessions-empty-folder {
  padding: 4px 12px 4px 24px;
  font-size: 0.91em;
  color: var(--dc-ink-2);
  font-style: italic;
  position: relative;
}

/* L-bar connector on the empty-folder placeholder — same as a normal session item */
.sessions-empty-folder::before {
  content: '';
  position: absolute;
  left: 10px;
  top: -2px;
  bottom: 50%;
  width: 1px;
  background: var(--dc-line);
}

.sessions-empty-folder::after {
  content: '';
  position: absolute;
  left: 10px;
  top: 50%;
  width: 10px;
  height: 1px;
  background: var(--dc-line);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-sm) var(--spacing-md);
  border-top: 1px solid var(--dc-line);
  background: var(--dc-sunk, var(--dc-band));
  gap: var(--spacing-sm);
  flex-shrink: 0;
}

.sidebar-footer-btn {
  padding: 4px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--dc-ink-2);
  cursor: pointer;
  font-size: 12px;
  transition: all var(--transition-fast);
}

.sidebar-footer-btn:hover {
  background: var(--dc-band);
  color: var(--dc-accent);
}

.sidebar-footer-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sidebar-footer-btn.loading {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Query-running dot. Visibility is owned only by app.isProcessing via
   sessions.js row class sync; server isLive/current selection must not show it. */
.session-processing-dot {
  display: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #2ecc71;
  box-shadow: 0 0 6px rgba(46, 204, 113, 0.7);
  margin-right: 6px;
  flex-shrink: 0;
  animation: pulse 1.2s ease-in-out infinite;
  vertical-align: middle;
}

.session-sidebar-item.is-processing .session-processing-dot {
  display: inline-block;
}

.session-sidebar-item.is-live .session-sidebar-title {
  font-weight: 600;
}

.phase-status-container {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 800px;
  margin: 0 auto var(--spacing-sm);
  padding: 12px 16px;
  border: 1px dashed var(--border-color, rgba(255, 255, 255, 0.18));
  border-radius: 14px;
  background: rgba(156, 39, 176, 0.06);
  color: var(--text-primary, #fff);
  font-size: 13px;
  font-weight: 600;
  animation: pulse 2s ease-in-out infinite;
}

.phase-status-container.hidden {
  display: none;
}

.phase-status-container .phase-status-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.phase-status-container .phase-status-text {
  flex: 1;
}

.sessions-count-label {
  font-size: 11px;
  color: var(--dc-ink-2);
}

.sidebar-footer .btn-clear-sessions {
  padding: 4px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--dc-ink-2);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sidebar-footer .btn-clear-sessions:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--accent-error);
}

/* =============================================
   CHAT CENTER AREA (contains chat + input)
   ============================================= */

.chat-center-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* =============================================
   CHAT CONTAINER
   ============================================= */

.chat-container {
  flex: 1;
  overflow-y: auto;
  scroll-padding-top: calc(var(--spacing-md) + var(--lsb-height));
  padding: var(--spacing-md) var(--spacing-xl) var(--spacing-lg);
  background-color: var(--bg-primary);
}

.chat-container.canvas-page-active .chat-messages {
  display: none !important;
}

/* Canvas page overlay: when any canvas page is active, the page panel fills the
   entire main canvas (chat-container) as a flush overlay AND replaces the
   composer/input-container below it, so the page occupies the full
   chat-center-area both vertically and horizontally. */
.chat-container.canvas-page-active {
  position: relative;
  overflow: hidden;
  padding: 0;
}
.chat-container.canvas-page-active ~ .input-container,
.chat-container.canvas-page-active ~ .conversation-float-rail,
.chat-container.canvas-page-active ~ .activity-drawer {
  display: none !important;
}

/* Conversation-only chrome has no meaningful action while the welcome shell
   is the sole canvas content. The nodes stay mounted and return immediately
   when #welcomeMessage is removed for a real conversation. */
.chat-center-area:has(#welcomeMessage .home-shell) > .conversation-float-rail,
.chat-center-area:has(#welcomeMessage .home-shell) > .activity-drawer {
  display: none !important;
}

.chat-container.canvas-page-active > .canvas-workspace-page:not(.hidden) {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
}
.chat-container.canvas-page-active > .canvas-workspace-page:not(.hidden).canvas-page-panel,
.chat-container.canvas-page-active > .canvas-workspace-page:not(.hidden) > .canvas-page-panel {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-container.canvas-page-active > .canvas-workspace-page:not(.hidden) > .canvas-page-header,
.chat-container.canvas-page-active > .canvas-workspace-page:not(.hidden) > .canvas-page-panel > .canvas-page-header {
  flex: 0 0 auto;
}
.chat-container.canvas-page-active > .canvas-workspace-page:not(.hidden) > .canvas-page-body,
.chat-container.canvas-page-active > .canvas-workspace-page:not(.hidden) > .canvas-page-panel > .canvas-page-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.chat-messages {
  /* P6 §6.3.2 — when an anchor scrolls a chat message to the top of the
     viewport, reserve `--lsb-height` so the message clears the sticky
     LiveStatusBar instead of being hidden behind it. */
  scroll-padding-top: var(--lsb-height);
  max-width: calc(100% - 64px);
  margin: 0 32px;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
}


/* =============================================
   DEBUG/INSIGHTS PANEL
   ============================================= */

.debug-panel {
  width: 380px;
  min-width: 380px;
  height: 100%;
  background-color: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: margin-right var(--transition-normal), opacity var(--transition-normal);
  overflow: hidden;
}

.debug-panel.collapsed {
  margin-right: -380px;
  opacity: 0;
  pointer-events: none;
}

.debug-header {
  padding: 10px var(--spacing-lg);
  background-color: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.debug-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

/* Accordion Sections */
.debug-sections {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-sm);
}

.debug-section {
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  margin-bottom: var(--spacing-sm);
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  padding: 10px var(--spacing-md);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--transition-normal);
}

.section-header:hover {
  background-color: var(--bg-hover);
}

.section-toggle {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-right: var(--spacing-sm);
  transition: transform var(--transition-normal);
}

.section-header.expanded .section-toggle {
  transform: rotate(90deg);
}

.section-title {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
}

.section-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: normal;
}

.section-content {
  max-height: 400px;
  overflow-y: auto;
  transition: max-height var(--transition-slow), padding var(--transition-slow);
  padding: 0 var(--spacing-md) var(--spacing-md) var(--spacing-md);
}

.section-content.collapsed {
  max-height: 0;
  padding: 0 var(--spacing-md);
  overflow: hidden;
}

/* =============================================
   SESSIONS SIDEBAR (Debug Panel)
   ============================================= */

.sessions-sidebar-section {
  background-color: var(--bg-tertiary);
}

.sessions-sidebar-section .section-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.sessions-sidebar-section .btn-new-session {
  margin-left: auto;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--radius-round);
  background: var(--accent-primary);
  color: white;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.sessions-sidebar-section .btn-new-session:hover {
  background: var(--accent-hover);
  transform: scale(1.1);
}

.sessions-search-wrapper {
  margin-bottom: var(--spacing-sm);
}

.sessions-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--dc-line);
  border-radius: var(--radius-md);
  background: var(--dc-paper);
  color: var(--dc-ink);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.sessions-search-input:focus {
  border-color: var(--dc-accent);
}

.sessions-search-input::placeholder {
  color: var(--dc-ink-2);
}

/* Note: .sessions-sidebar-list main styles are defined above in LEFT SIDEBAR section */

.sessions-sidebar-list::-webkit-scrollbar {
  width: 10px;
}

.sessions-sidebar-list::-webkit-scrollbar-track {
  background: transparent;
}

.sessions-sidebar-list::-webkit-scrollbar-thumb {
  background: var(--dc-line);
  border-radius: 5px;
}

.session-sidebar-item {
  position: relative;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  gap: var(--spacing-sm);
}

.session-sidebar-item:hover {
  background: var(--dc-band);
  box-shadow: inset 0 0 0 1px var(--dc-line-hover);
}

.session-sidebar-item.active {
  background: var(--dc-paper);
  border-left: 2px solid var(--dc-accent);
}

.session-sidebar-icon {
  font-size: 12px;
  opacity: 0.7;
}

.session-sidebar-title {
  flex: 1;
  font-size: var(--font-size-sm);
  color: var(--dc-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Session sidebar actions already defined above in primary sidebar styles */

.sessions-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-lg);
  color: var(--dc-ink-2);
  font-size: 12px;
  gap: var(--spacing-xs);
}

.sessions-sidebar-footer {
  padding-top: var(--spacing-sm);
  border-top: 1px solid var(--dc-line);
}

.btn-clear-sessions {
  width: 100%;
  padding: 6px 10px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--dc-ink-2);
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-clear-sessions:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--accent-error);
}

/* =============================================
   INPUT CONTAINER
   ============================================= */

.input-container {
  padding: var(--spacing-md) var(--spacing-xl) var(--spacing-sm);
  background-color: var(--dc-ground);
  flex-shrink: 0;
}

.app-legal-footer {
  max-width: 1040px;
  width: calc(100% - 80px);
  margin: 11px auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--dc-ink-2);
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
}

/* Data Privacy Notice is a REQUIRED link. It blends by colour but must still
   read as a link: the affordance is carried by a PERSISTENT underline, a
   non-colour cue (WCAG 1.4.1) - so it can share the footer's ink without
   becoming invisible. Never remove the underline. */
.app-legal-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--dc-ink-2) 45%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.app-legal-link:hover,
.app-legal-link:focus-visible {
  color: var(--dc-ink);
  text-decoration-color: currentColor;
}

.app-legal-link:focus-visible {
  outline: 2px solid var(--dc-accent);
  outline-offset: 2px;
}

.app-legal-separator {
  color: var(--dc-line);
}

.input-wrapper {
  width: min(1040px, calc(100vw - 128px));
  max-width: 100%;
  margin: 0 auto;
  background-color: var(--dc-paper);
  border: 1px solid var(--dc-line);
  border-radius: 20px;
  padding: var(--spacing-sm) var(--spacing-sm) 6px var(--spacing-md);
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
  display: flex;
  flex-direction: column;
  position: relative;
}

.input-wrapper:focus-within {
  border-color: var(--dc-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--dc-accent) 15%, transparent);
}

.input-wrapper.is-processing {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(0, 122, 204, 0.15);
}

.input-wrapper.is-processing::before,
.input-wrapper.is-processing::after {
  content: "";
  position: absolute;
  border-radius: inherit;
  pointer-events: none;
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: query-box-border-shimmer 3.2s linear infinite;
}

.input-wrapper.is-processing::before {
  inset: -6px;
  padding: 6px;
  background:
    linear-gradient(90deg, transparent 0%, rgba(153, 205, 255, 0.52) 48%, transparent 100%) top left / 34% 12px no-repeat,
    linear-gradient(180deg, transparent 0%, rgba(153, 205, 255, 0.42) 48%, transparent 100%) top right / 12px 72% no-repeat,
    linear-gradient(270deg, transparent 0%, rgba(153, 205, 255, 0.52) 48%, transparent 100%) bottom right / 34% 12px no-repeat,
    linear-gradient(0deg, transparent 0%, rgba(153, 205, 255, 0.42) 48%, transparent 100%) bottom left / 12px 72% no-repeat;
  filter: blur(4px);
  opacity: 0.64;
  animation: query-box-border-glow 3.2s linear infinite;
}

.input-wrapper.is-processing::after {
  inset: -1px;
  padding: 1px;
  background:
    linear-gradient(90deg, transparent 0%, rgba(153, 205, 255, 0.95) 45%, rgba(0, 122, 204, 0.95) 58%, transparent 100%) top left / 24% 2px no-repeat,
    linear-gradient(180deg, transparent 0%, rgba(153, 205, 255, 0.92) 45%, rgba(0, 122, 204, 0.92) 58%, transparent 100%) top right / 2px 45% no-repeat,
    linear-gradient(270deg, transparent 0%, rgba(153, 205, 255, 0.95) 45%, rgba(0, 122, 204, 0.95) 58%, transparent 100%) bottom right / 24% 2px no-repeat,
    linear-gradient(0deg, transparent 0%, rgba(153, 205, 255, 0.92) 45%, rgba(0, 122, 204, 0.92) 58%, transparent 100%) bottom left / 2px 45% no-repeat;
  opacity: 0.9;
  animation: query-box-border-segment 3.2s linear infinite;
}

@keyframes query-box-border-glow {
  0% {
    background-position: 0% 0%, 100% 0%, 100% 100%, 0% 100%;
    opacity: 0.62;
  }
  25% {
    background-position: 72% 0%, 100% 0%, 100% 100%, 0% 100%;
    opacity: 0.70;
  }
  50% {
    background-position: 100% 0%, 100% 62%, 100% 100%, 0% 100%;
    opacity: 0.62;
  }
  75% {
    background-position: 100% 0%, 100% 100%, 28% 100%, 0% 100%;
    opacity: 0.70;
  }
  100% {
    background-position: 100% 0%, 100% 100%, 0% 100%, 0% 18%;
    opacity: 0.62;
  }
}

@keyframes query-box-border-segment {
  0% {
    background-position: 0% 0%, 100% 0%, 100% 100%, 0% 100%;
  }
  25% {
    background-position: 76% 0%, 100% 0%, 100% 100%, 0% 100%;
  }
  50% {
    background-position: 100% 0%, 100% 55%, 100% 100%, 0% 100%;
  }
  75% {
    background-position: 100% 0%, 100% 100%, 24% 100%, 0% 100%;
  }
  100% {
    background-position: 100% 0%, 100% 100%, 0% 100%, 0% 55%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .input-wrapper.is-processing::before,
  .input-wrapper.is-processing::after,
  .input-actions::before {
    animation: none;
  }
}

/* Input Modes */
.input-mode {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.input-mode.hidden {
  display: none;
}

.input-mode-normal {
  align-items: flex-end;
}

.input-mode-recording {
  padding: var(--spacing-xs) 0;
}

/* Textarea */
#queryInput {
  flex: 1;
  padding: var(--spacing-sm) var(--spacing-xs);
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: var(--font-size-lg);
  resize: none;
  max-height: 200px;
  line-height: 1.5;
  outline: none;
  font-family: inherit;
  min-height: 24px;
}

#queryInput::placeholder {
  color: var(--text-muted);
}

/* Input Actions */
.input-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  flex-shrink: 0;
}

.input-actions::before {
  content: "";
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 122, 204, 0.22);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: query-input-spinner 0.85s linear infinite;
}

.input-wrapper.is-processing .input-actions::before {
  display: inline-block;
}

@keyframes query-input-spinner {
  to {
    transform: rotate(360deg);
  }
}

/* Input Hint */
.input-hint {
  max-width: 1040px;
  margin: var(--spacing-sm) auto 0;
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  text-align: center;
  opacity: 0.7;
}

/* Drag Over State */
.input-container.drag-over {
  background: var(--bg-hover);
  border-color: var(--accent-primary);
  outline: 2px dashed var(--accent-primary);
  outline-offset: -4px;
}

/* =============================================
   LOADING OVERLAY
   ============================================= */

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.7);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-lg);
  z-index: var(--z-modal);
}

.loading-overlay.active {
  display: flex;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg-tertiary);
  border-top-color: var(--accent-primary);
  border-radius: var(--radius-round);
  animation: spin 1s linear infinite;
}

.loading-overlay p {
  color: var(--text-primary);
  font-size: var(--font-size-lg);
}

/* =============================================
   STARTUP OVERLAY
   ============================================= */

.startup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #1e1e1e 0%, #2d2d2d 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-overlay);
  transition: opacity 0.5s ease-out;
}

.startup-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.startup-content {
  text-align: center;
  animation: fadeIn 0.5s ease-out;
}

.startup-logo {
  font-size: 72px;
  margin-bottom: var(--spacing-lg);
  animation: pulse 2s ease-in-out infinite;
}

.startup-title {
  font-size: 28px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: var(--spacing-2xl);
}

.startup-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-primary);
  border-radius: var(--radius-round);
  animation: spin 1s linear infinite;
  margin: 0 auto var(--spacing-lg);
}

.startup-status {
  color: #888;
  font-size: 14px;
  margin-bottom: var(--spacing-lg);
}

.startup-progress {
  width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
  margin: 0 auto;
}

.startup-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #0078d4, #00bcf2);
  width: 0%;
  transition: width var(--transition-slow);
}
