/*
 * CHANGE LOG
 * -----------------------------------------------------------------------------
 * SEQ                 | AUTHOR                      | DESCRIPTION
 * -----------------------------------------------------------------------------
 * 1 | maintainer@emeraldcoastsystemsgroup.com   | Rebalanced the cockpit header after removing the dead global search field during the header-audit pass
 * 2 | maintainer@emeraldcoastsystemsgroup.com   | Added cockpit workspace-focus layout rules so heavyweight header tools can temporarily take over the main stage
 * 3 | maintainer@emeraldcoastsystemsgroup.com   | Added a wider workspace-focus stage option so operators can choose between standard and expanded tool width
 * 4 | maintainer@emeraldcoastsystemsgroup.com   | Added draggable workspace-focus width handling so operators can fine-tune heavyweight tool width
 * 5 | maintainer@emeraldcoastsystemsgroup.com   | Disabled chat-panel width animation in workspace focus so heavy header tools open at full working width immediately
 * 6 | maintainer@emeraldcoastsystemsgroup.com   | Fixed haywire Main↔Chat drag-resize: kill the chat-panel width transition during drag (was chasing the cursor) and disable iframe pointer-events so the embedded app surface stops swallowing mousemove
 * 7 | maintainer@emeraldcoastsystemsgroup.com   | Zen (full-window focus) mode: body.zen-mode hides all cockpit chrome (header, ribbon, status bar, chat rail, per-surface title bar) so the active surface gets the whole window — the desktop analogue of the phone full-bleed rules below. Plus the floating semi-transparent exit button.
 * 8 | maintainer@emeraldcoastsystemsgroup.com   | :root[data-oshal-status-bar-hidden="true"] .status-bar {display:none} — the manifest-declared per-app hide of the status bar (ribbon.hideStatusBar, set on the root by app.js). Zen mode hides it for everyone in a session; this drops it permanently for one app.
 * 9 | maintainer@emeraldcoastsystemsgroup.com | Keep Home singular and group secondary actions in a theme-aware options disclosure.
 * 10 | maintainer@emeraldcoastsystemsgroup.com | Keep the sidebar utility disclosure opaque over application content.
 * 11 | maintainer@emeraldcoastsystemsgroup.com | Styled the status-bar durable-storage indicator (.status-persistence) for the degraded and unreadable states, matching the existing cost-indicator colours.
 * 12 | maintainer@emeraldcoastsystemsgroup.com   | Shell-lock doors: a header door (data-shell-door) with the hidden attribute is not displayed, whatever its own display rule — the Nexus and Simple entries carry an inline display:flex and .header-btn sets display, both of which beat the user-agent [hidden] rule, so a "hidden" door was still drawn.
 * 13 | maintainer@emeraldcoastsystemsgroup.com | Phones keep the application screen's bar as one slim row (name, icon-only Reload and Open tab) instead of hiding it: application links open in Today again (owner decision 2026-10-13) and a phone otherwise had no way to reload a screen or open it in its own tab.
 */

/* ===== Layout — Cockpit Shell (Apple Liquid Glass) ===== */

body {
  margin: 0;
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  overflow: hidden;
}

/* ---------- Header Bar ---------- */
.header-bar {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 20px;
  background: var(--bg-secondary);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--panel-shadow);
  z-index: 100;
  gap: 16px;
  position: relative;
}

.header-bar::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 10%, rgba(255,255,255,0.08) 50%, transparent 90%);
  pointer-events: none;
}

.header-left { display: flex; align-items: center; gap: 12px; flex: 1; }

.header-left .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--accent-primary);
}

.logo-text {
  font-family: var(--font-family-display);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-transform: tracking-tight;
}

.header-right { display: flex; gap: 6px; align-items: center; margin-left: auto; }

.header-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.header-btn:hover {
  background: var(--glass-bg-heavy);
  color: var(--text-primary);
  transform: scale(1.05);
}

.header-btn:active { transform: scale(0.95); }

#cockpitHomeLink { text-decoration: none; }
#cockpitHomeLink:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 4px; border-radius: var(--radius-sm); }
.workspace-home-label { display: none; }
[data-navigation-layout="workspaces"] #cockpitHomeLink .logo-text:not(.workspace-home-label) { display: none; }
[data-navigation-layout="workspaces"] #cockpitHomeLink .workspace-home-label { display: block; }
.header-options { position: relative; }
.header-options[hidden] { display: none; }
[data-shell-door][hidden] { display: none !important; }
.header-options > summary { list-style: none; }
.header-options > summary::-webkit-details-marker { display: none; }
.header-options > .header-utilities {
  position: absolute; top: calc(100% + 8px); right: 0; width: min(260px, calc(100vw - 24px));
  max-height: calc(100dvh - 80px); overflow-y: auto; z-index: 110;
  padding: 8px; border: 1px solid var(--border-color); border-radius: var(--radius-lg);
  background: var(--bg-primary); color: var(--text-primary); box-shadow: var(--panel-shadow);
}
.header-utilities-label { padding: 8px 10px; font-size: 12px; font-weight: 700; color: var(--text-secondary); }
#cockpitHeaderUtilities .header-btn {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px;
  width: 100%; height: auto; min-height: 40px; padding: 10px; font: inherit;
  font-size: 13px; text-align: left; white-space: normal; color: var(--text-primary);
}
#cockpitHeaderUtilities .header-btn svg { flex: 0 0 auto; }
#cockpitHeaderUtilities .header-btn:hover { transform: none; background: var(--bg-tertiary); }
#cockpitHeaderUtilities .header-btn:focus-visible, .header-options > summary:focus-visible {
  outline: 2px solid var(--accent-primary); outline-offset: -2px;
}
:root[data-oshal-assistant-hidden="true"] #cockpitHeaderUtilities #agentsBtn { display: none; }

.engineering-link { text-decoration: none; }

/* ---------- Tools Dropdown ---------- */
.tools-dropdown { position: relative; }

.tools-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  background: linear-gradient(145deg, rgba(30, 30, 45, 0.7) 0%, rgba(20, 20, 35, 0.85) 100%);
  backdrop-filter: blur(40px) saturate(150%);
  -webkit-backdrop-filter: blur(40px) saturate(150%);
  border: 1px solid var(--border-light);
  border-top: 1.5px solid var(--border-highlight);
  border-left: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-md);
  box-shadow: var(--depth-shadow), inset 0 0 20px rgba(255,255,255,0.05);
  padding: 8px;
  z-index: 200;
  opacity: 0;
  transform: translateY(-8px) scale(0.96);
  pointer-events: none;
  transition: all 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

.tools-menu.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.tools-menu-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 10px 4px;
}

.tools-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--font-size-sm);
  transition: all var(--transition-fast);
}

.tools-menu a:hover {
  background: var(--glass-bg-heavy);
  color: var(--text-primary);
}

.tools-menu a .tool-icon { font-size: 16px; width: 20px; text-align: center; }

.tools-menu-divider {
  height: 1px;
  background: var(--border-color);
  margin: 6px 0;
}

/* ---------- Main Body ---------- */
.cockpit-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  min-height: 0;
  padding: 12px;
  gap: 12px;
}

/* ---------- Main Content Area (center, switches based on ribbon) ---------- */
.main-content {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: var(--bg-secondary);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--panel-shadow);
  position: relative;
}

.cockpit-body.workspace-focus-mode {
  gap: 0;
}

.cockpit-body.workspace-focus-mode .main-content,
.cockpit-body.workspace-focus-mode .panel-resize-handle {
  display: none;
}

.cockpit-body.workspace-focus-mode .chat-panel {
  width: var(--workspace-focus-width, min(1120px, calc(100vw - 96px))) !important;
  min-width: 520px;
  max-width: none;
  flex: 0 0 auto;
  margin-left: auto;
  border-radius: 22px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  transition-property: opacity, margin;
}

.cockpit-body.workspace-focus-mode.workspace-focus-wide {
  --workspace-focus-width: calc(100vw - 40px);
}

.cockpit-body.workspace-focus-mode .chat-native-frame-shell {
  padding: 12px;
}

/* ---------- Status Bar ---------- */
/* Per-app hide (manifest ribbon.hideStatusBar → profile.hideStatusBar → app.js sets this root attr):
   apps that are not ticket/queue-shaped drop the operational status bar entirely, and the flex column
   reclaims its height for the app surface. */
:root[data-oshal-status-bar-hidden="true"] .status-bar { display: none; }
.status-bar {
  height: var(--status-bar-height);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  backdrop-filter: blur(var(--glass-blur-light));
  -webkit-backdrop-filter: blur(var(--glass-blur-light));
  border-top: 1px solid var(--border-color);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.status-item { 
  display: flex; 
  align-items: center; 
  gap: 6px; 
}
.status-item i {
  font-size: 14px;
}

/* Durable-storage indicator — silent unless a store advertised as durable is not. */
.status-persistence {
  cursor: help;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.status-persistence.status-error { color: #ef4444; }
.status-persistence.status-warning { color: #f59e0b; }

/* Cost indicator states */
.status-cost {
  cursor: help;
  font-weight: 500;
  transition: color var(--transition-fast);
}

.status-cost.status-normal {
  color: var(--text-muted);
}

.status-cost.status-warning {
  color: #f59e0b;
  animation: pulse-warning 2s ease-in-out infinite;
}

.status-cost.status-error {
  color: #ef4444;
  animation: pulse-error 1.5s ease-in-out infinite;
}

@keyframes pulse-warning {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

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

.status-dot { width: 7px; height: 7px; border-radius: 50%; }

.status-dot.online {
  background: var(--status-success);
  box-shadow: 0 0 8px var(--status-success), 0 0 2px var(--status-success);
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 8px var(--status-success), 0 0 2px var(--status-success); }
  50% { box-shadow: 0 0 14px var(--status-success), 0 0 4px var(--status-success); }
}

/* ---------- Panel Shared ---------- */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
}

.panel-title {
  font-weight: 600;
  font-size: var(--font-size-sm);
  letter-spacing: -0.2px;
}

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

/* ---------- Resize Handles ---------- */
.panel-resize-handle {
  width: 6px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  flex-shrink: 0;
  z-index: 10;
  transition: background 0.2s;
}
.panel-resize-handle:hover,
.panel-resize-handle.dragging {
  background: var(--accent-primary);
  border-radius: 3px;
}
.panel-resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 30px;
  background: transparent;
  border-radius: 1px;
  opacity: 0;
  transition: opacity 0.2s ease, background 0.2s ease;
}
.panel-resize-handle:hover::after,
.panel-resize-handle.dragging::after {
  opacity: 1;
  background: rgba(255,255,255,0.34);
}
body.resizing { cursor: col-resize !important; user-select: none !important; }
body.resizing * { cursor: col-resize !important; }
/* While dragging the Main↔Chat handle: (1) kill the chat-panel width transition
   so it tracks the cursor 1:1 instead of laggily chasing it, and (2) disable
   pointer-events on embedded iframes (e.g. the focused app surface) so the
   iframe doesn't swallow mousemove and break the drag mid-stroke. */
body.resizing .chat-panel { transition: none !important; }
body.resizing iframe { pointer-events: none !important; }

/* ERROR #7: GPU-accelerated panel resize */
.chat-panel, .work-board, .insights-panel {
  will-change: width;
}

/* The Agents button is mobile-only: on desktop the chat panel + its bot selector
   are always visible, so the shortcut is redundant. Shown inside the mobile block. */
#agentsBtn { display: none; }

/* ============================================================================
   MOBILE SHELL (<=640px) — the desktop 3-column layout (ribbon | main | chat)
   crushed the main content to ~4px on a phone because the side chat panel never
   yielded. On mobile we go single-pane: main content takes the full width, the
   chat panel becomes a slide-up full-screen sheet (see chat.css), the resize
   handle and bottom status bar are removed, and the header is compacted so the
   wordmark + tool icons stop wrapping. Pairs with the ribbon drawer in ribbon.css.
   ========================================================================== */
@media (max-width: 640px) {
  /* Slim header: it was 56px of mostly-empty chrome. Drop the wordmark to the
     diamond mark and cut the height so the app gets that vertical space back. */
  .header-bar { height: 46px; padding: 0 8px; gap: 6px; }
  .logo-text { display: none; }
  [data-navigation-layout="workspaces"] #cockpitHomeLink .workspace-home-label { display: none; }
  .header-left .logo svg { width: 22px; height: 22px; }
  .header-right { gap: 2px; }
  .header-btn { width: 36px; height: 36px; }
  /* Drop the desktop-only RAG ingestion (upload) tool that has no place on a
     phone header. Keep theme/apps/profile. */
  #ragBtn { display: none; }
  /* ...but DO show the Agents shortcut on mobile (opens the chat sheet + bot picker). */
  #agentsBtn { display: flex; }

  /* Full-bleed: kill the body padding/gap AND the main surface's card border +
     rounded corners. Those gutters and the framed card were the wasted left/
     right margin — on a phone the app surface should run edge-to-edge. */
  .cockpit-body { padding: 0; gap: 0; }
  .main-content {
    width: 100%;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  /* No side-by-side resize handle on a phone. */
  .panel-resize-handle { display: none !important; }

  /* Reclaim vertical space: the placeholder status bar is desktop chrome. */
  .status-bar { display: none; }

  /* The per-surface bar is one slim row on a phone: the screen's name and its Reload and
     Open tab controls, icon only. Application links open here (owner decision 2026-10-13)
     and those controls were the operator shell's application bar; hiding the whole bar left
     a phone no way to reload a screen or open it in its own tab. */
  .tool-view-header { padding: 4px 10px !important; gap: 6px !important; font-size: 13px; }
  .tool-view-header > i { display: none; }
  .tool-view-action-label { display: none; }
}

/* ---------- Zen (full-window focus) mode ---------- */
/* The desktop analogue of the phone full-bleed rules above: every piece of cockpit
   chrome disappears and the active surface owns the window. Toggled from the header
   arrows-out button; the floating exit button (or Esc) restores the chrome. */
body.zen-mode .header-bar,
body.zen-mode .status-bar,
body.zen-mode #ribbonContainer,
body.zen-mode .ribbon-backdrop,
body.zen-mode .chat-panel,
body.zen-mode .panel-resize-handle,
body.zen-mode .tool-view-header {
  display: none !important;
}

body.zen-mode .cockpit-body { padding: 0; gap: 0; }

body.zen-mode .main-content {
  width: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

/* The one control left on screen: quiet until hovered, always reachable. */
.zen-exit-btn {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 5000;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  opacity: 0.35;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.zen-exit-btn:hover,
.zen-exit-btn:focus-visible { opacity: 1; }

.zen-exit-btn.hidden { display: none; }
