/* ═══════════════════════════════════════════════════════════════════
   Layout: FluideUI — 5-Sector Application Framework
   ASGARD Design System — CDN: dash.asgard/themes/

   Structure:
   ┌─────────────────────────────────────────────────┐
   │  HEADER (H) — Logo, tabs, services, user        │
   ├──────────┬──────────────────────┬────────────────┤
   │ SECTOR 1 │ R │   SECTOR 2      │ R │ SECTOR 3   │
   │  (NAV)   │ E │   (STAGE)       │ E │ (CONTEXT)  │
   │          │ S │                  │ S │            │
   │          │ I │                  │ I │            │
   │          │ Z │                  │ Z │            │
   │          │ E │                  │ E │            │
   │          │ R │                  │ R │            │
   ├──────────┴───┴──────────────────┴───┴────────────┤
   │  FOOTER (F) — Status, workspace, activity, clock │
   └─────────────────────────────────────────────────┘

   This CSS is design-agnostic. Uses only --p3x-* variables from core.css.
   Apply a design CSS (standard, lcars, etc.) for visual styling.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Main Container ── */

.p3x-app {
    display: grid;
    grid-template-rows: var(--p3x-header-h) 1fr var(--p3x-footer-h);
    grid-template-areas:
        "header"
        "main"
        "footer";
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ── Header (Sector H) ── */

.p3x-header {
    grid-area: header;
    display: flex;
    align-items: center;
    gap: var(--p3x-gap-lg);
    padding: 0 var(--p3x-gap-lg);
    border-bottom: 1px solid var(--p3x-bg-border);
    z-index: var(--p3x-z-panel);
}

.p3x-header-logo {
    font-family: var(--p3x-font-display);
    font-size: 16px;
    font-weight: 600;
    color: var(--p3x-accent);
    letter-spacing: 2px;
    text-transform: uppercase;
    white-space: nowrap;
}

.p3x-header-tabs {
    display: flex;
    gap: 2px;
    flex: 1;
}

.p3x-header-tab {
    padding: 0 var(--p3x-gap-lg);
    height: var(--p3x-header-h);
    display: flex;
    align-items: center;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--p3x-text-secondary);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--p3x-transition);
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}
.p3x-header-tab:hover {
    color: var(--p3x-text);
    background: var(--p3x-accent-dim);
}
.p3x-header-tab.active {
    color: var(--p3x-accent);
    border-bottom-color: var(--p3x-accent);
}

.p3x-header-services {
    display: flex;
    gap: var(--p3x-gap-md);
    align-items: center;
}

.p3x-header-user {
    display: flex;
    align-items: center;
    gap: var(--p3x-gap-sm);
    color: var(--p3x-text-secondary);
    font-size: 11px;
}

/* ── Main Content Area (3 sectors + 2 resizers) ── */

.p3x-main {
    grid-area: main;
    display: flex;
    overflow: hidden;
}

/* ── Sector 1 (NAV — Left Panel) ── */

.p3x-nav {
    width: var(--p3x-nav-w);
    min-width: 180px;
    max-width: 50vw;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--p3x-bg-border);
    overflow: hidden;
}

.p3x-nav.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
}

/* ── Sector 2 (STAGE — Central Area) ──
   Stage width is set by resizer positions (inline style), NOT by flex.
   When S1/S3 collapse, Stage keeps its width — empty space remains. */

.p3x-stage {
    flex: 0 0 auto;
    width: var(--p3x-stage-w, calc(100% - var(--p3x-nav-w) - var(--p3x-ctx-w) - 2 * var(--p3x-resizer-w)));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 200px;
}

/* ── Sector 3 (CONTEXT — Right Panel) ── */

.p3x-ctx {
    width: var(--p3x-ctx-w);
    min-width: 200px;
    max-width: 50vw;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--p3x-bg-border);
    overflow: hidden;
}

.p3x-ctx.collapsed {
    width: 0;
    min-width: 0;
    border-left: none;
}

/* ── Panel Reveal Buttons (from Nemesis Control) ──
   Shown when S1/S3 panels are collapsed — positioned in Stage corners.
   Managed by JS togglePanel(). */

.p3x-panel-reveal {
    position: absolute;
    top: var(--p3x-gap-md);
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--p3x-bg-border);
    color: var(--p3x-text-secondary);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    z-index: 30;
    backdrop-filter: blur(4px);
    transition: all var(--p3x-transition);
}
.p3x-panel-reveal:hover {
    border-color: var(--p3x-accent);
    color: var(--p3x-accent);
    background: var(--p3x-accent-dim);
}
.p3x-panel-reveal-left  { left: var(--p3x-gap-md); }
.p3x-panel-reveal-right { right: var(--p3x-gap-md); }

/* ── Panel Detached Mode (from Nemesis Control — FluideUI §3.3) ──
   Panels can float as independent windows with glass morphism.
   3 modes: attached (default), detached-stacked, detached-unstacked. */

.p3x-nav[data-mode="detached-stacked"],
.p3x-nav[data-mode="detached-unstacked"],
.p3x-ctx[data-mode="detached-stacked"],
.p3x-ctx[data-mode="detached-unstacked"],
.p3x-nav.p3x-detached,
.p3x-ctx.p3x-detached {
    position: fixed;
    z-index: var(--p3x-z-sector-float);
    background: var(--p3x-bg-glass);
    backdrop-filter: var(--p3x-bg-glass-blur);
    border: 1px solid var(--p3x-bg-border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    cursor: move;
    min-width: 250px;
    min-height: 200px;
    width: 350px;
    top: 60px;
    resize: both;
    overflow: auto;
}
.p3x-nav.p3x-detached { left: 20px; }
.p3x-ctx.p3x-detached { right: 20px; }

/* ── Panel Resize Handle (edge drag for attached panels) ── */

.p3x-panel-resize-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    z-index: 25;
}
.p3x-nav .p3x-panel-resize-handle { right: 0; }
.p3x-ctx .p3x-panel-resize-handle { left: 0; }
.p3x-panel-resize-handle:hover {
    background: var(--p3x-accent);
    opacity: 0.3;
}

/* ── Buttonbar (footer of S1/S3 — from Nemesis Control) ──
   Action buttons at the bottom of NAV/CTX panels.
   Reference: FluideUI §5 NAV.BUTTONBAR / §6 CTX.BUTTONBAR */

.p3x-buttonbar {
    display: flex;
    align-items: center;
    gap: var(--p3x-gap-sm);
    padding: var(--p3x-gap-sm) var(--p3x-gap-md);
    border-top: 1px solid var(--p3x-bg-border);
    flex-shrink: 0;
    min-height: 28px;
}

.p3x-buttonbar-btn {
    background: none;
    border: 1px solid var(--p3x-bg-border);
    color: var(--p3x-text-secondary);
    padding: 3px 8px;
    font-size: 12px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all var(--p3x-transition);
}
.p3x-buttonbar-btn:hover {
    border-color: var(--p3x-accent);
    color: var(--p3x-accent);
}

.p3x-buttonbar-count {
    font-size: 12px;
    color: var(--p3x-text-secondary);
    margin-left: auto;
}

/* ── Resizer (draggable divider between sectors) ── */

.p3x-resizer {
    width: var(--p3x-resizer-w);
    cursor: col-resize;
    background: transparent;
    position: relative;
    flex-shrink: 0;
    z-index: calc(var(--p3x-z-panel) + 1);
    transition: background var(--p3x-transition);
}

.p3x-resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 40px;
    background: var(--p3x-bg-border);
    border-radius: 1px;
    transition: all var(--p3x-transition);
}

.p3x-resizer:hover {
    background: var(--p3x-accent-dim);
}
.p3x-resizer:hover::after {
    background: var(--p3x-accent);
    height: 60px;
}
.p3x-resizer.dragging {
    background: var(--p3x-accent-dim);
}

/* ── Horizontal Resizer (between viewport and console in Stage) ──
   Improved in Nemesis Control: 16px grab target, visual centered handle,
   user-select:none to prevent text selection during drag. */

.p3x-resizer-h {
    height: 16px;
    min-height: 16px;
    cursor: row-resize;
    background: transparent;
    position: relative;
    flex-shrink: 0;
    flex-grow: 0;
    z-index: calc(var(--p3x-z-panel) + 10);
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

.p3x-resizer-h::after {
    content: '';
    width: 60px;
    height: 3px;
    background: var(--p3x-bg-border);
    border-radius: 2px;
    transition: all var(--p3x-transition);
}

.p3x-resizer-h:hover::after {
    width: 80px;
    background: var(--p3x-accent);
    box-shadow: var(--p3x-glow-accent);
}
.p3x-resizer-h.dragging::after {
    background: var(--p3x-accent);
    box-shadow: 0 0 12px var(--p3x-accent-dim);
}

/* ── Footer (Sector F) ── */

.p3x-footer {
    grid-area: footer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--p3x-gap-lg);
    border-top: 1px solid var(--p3x-bg-border);
    font-size: 11px;
    color: var(--p3x-text-muted);
    z-index: var(--p3x-z-panel);
}

.p3x-footer-left,
.p3x-footer-center,
.p3x-footer-right {
    display: flex;
    align-items: center;
    gap: var(--p3x-gap-md);
}

.p3x-footer-sep {
    color: var(--p3x-bg-border);
}

/* ── Sector internals (shared structure for NAV and CTX) ── */

.p3x-sector-header {
    height: 36px;
    display: flex;
    align-items: center;
    padding: 0 var(--p3x-gap-md);
    border-bottom: 1px solid var(--p3x-bg-border);
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--p3x-text-secondary);
    flex-shrink: 0;
}

.p3x-sector-search {
    padding: var(--p3x-gap-sm) var(--p3x-gap-md);
    border-bottom: 1px solid var(--p3x-bg-border);
    flex-shrink: 0;
}

.p3x-sector-search input {
    width: 100%;
    background: transparent;
    border: 1px solid var(--p3x-bg-border);
    padding: 4px 8px;
    color: var(--p3x-text);
    font-size: 12px;
    border-radius: var(--p3x-radius-sm);
}
.p3x-sector-search input:focus {
    border-color: var(--p3x-accent);
    outline: none;
    box-shadow: 0 0 0 2px var(--p3x-accent-dim);
}

.p3x-sector-tabs {
    display: flex;
    border-bottom: 1px solid var(--p3x-bg-border);
    flex-shrink: 0;
}

.p3x-sector-tab {
    flex: 1;
    padding: 6px 0;
    text-align: center;
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--p3x-text-muted);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--p3x-transition);
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}
.p3x-sector-tab:hover { color: var(--p3x-text-secondary); }
.p3x-sector-tab.active {
    color: var(--p3x-accent);
    border-bottom-color: var(--p3x-accent);
    background: var(--p3x-accent-dim);
}

.p3x-sector-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--p3x-gap-sm);
}

.p3x-sector-actions {
    display: flex;
    gap: var(--p3x-gap-sm);
    padding: var(--p3x-gap-sm) var(--p3x-gap-md);
    border-top: 1px solid var(--p3x-bg-border);
    flex-shrink: 0;
}

/* ── SectorPanel — Detachable sector wrapper ──
   3 modes: attached (inline) / detached-stacked (floating single) /
   detached-unstacked (each view = its own floating panel).
   Sectors 1 and 3 can be detached; multi-view sectors can be unstacked.
   Reference: 3D Factory SectorPanel.tsx */

.p3x-sector-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Attached mode (default — inline in layout flow) */
.p3x-sector-panel[data-mode="attached"] {
    position: relative;
}

/* Floating modes (detached-stacked + detached-unstacked) */
.p3x-sector-panel[data-mode="detached-stacked"],
.p3x-sector-panel[data-mode="detached-unstacked"] {
    position: fixed;
    z-index: var(--p3x-z-sector-float);
    background: var(--p3x-bg-glass);
    backdrop-filter: var(--p3x-bg-glass-blur);
    -webkit-backdrop-filter: var(--p3x-bg-glass-blur);
    border: 1px solid var(--p3x-bg-border);
    border-radius: var(--p3x-radius-lg);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.7);
    resize: both;
    overflow: hidden;
}

/* Unstacked panels have individual min constraints */
.p3x-sector-panel[data-mode="detached-unstacked"] {
    min-width: 250px;
    min-height: 200px;
}

/* Mirror icons for right-side sector (S3) */
.p3x-sector-panel[data-side="right"] .p3x-sector-icon-mirror {
    transform: scaleX(-1);
}

/* ── Sector control buttons (detach/attach/collapse/expand/stack/unstack) ──
   Always present in the code — the applicatif decides which to show.
   Default: borderless, icon-only, very subtle (opacity 0.15 idle).
   Position: header line 1, left side of sector header.
   Mirror: icons mirrored via .p3x-sector-icon-mirror for right-side sectors. */

.p3x-sector-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: transparent;
    border: 1px solid transparent;
    color: rgba(255, 255, 255, 0.15);
    border-radius: var(--p3x-radius-sm);
    cursor: pointer;
    transition: all var(--p3x-transition);
    padding: 0;
    flex-shrink: 0;
}

.p3x-sector-btn:hover {
    color: var(--p3x-accent);
    background: var(--p3x-accent-dim);
    border-color: rgba(255, 255, 255, 0.08);
}

.p3x-sector-btn.active {
    color: var(--p3x-accent);
}

/* Sector header line 1 (drag handle when floating) */

.p3x-sector-header-line1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 20px;
    padding: 2px 0;
}

.p3x-sector-header-line1.draggable {
    cursor: grab;
}
.p3x-sector-header-line1.draggable:active {
    cursor: grabbing;
}

.p3x-sector-header-left,
.p3x-sector-header-right {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    min-width: 24px;
}

.p3x-sector-header-title {
    flex: 1;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--p3x-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Re-attach indicator (shown in layout when sector is detached) */
.p3x-sector-reattach {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--p3x-text-muted);
    font-size: 11px;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: color var(--p3x-transition);
    border: 1px dashed var(--p3x-bg-border);
    border-radius: var(--p3x-radius-sm);
    margin: var(--p3x-gap-sm);
}
.p3x-sector-reattach:hover {
    color: var(--p3x-accent);
    border-color: var(--p3x-accent-dim);
}

/* ── Stage internals ── */

.p3x-stage-viewport {
    flex: var(--p3x-stage-viewport-flex, 1);
    position: relative;
    overflow: hidden;
    min-height: 20%;
}

.p3x-stage-toolbar {
    display: flex;
    align-items: center;
    gap: var(--p3x-gap-sm);
    padding: var(--p3x-gap-sm) var(--p3x-gap-md);
    border-bottom: 1px solid var(--p3x-bg-border);
    flex-shrink: 0;
    min-height: 32px;
}

.p3x-stage-toolbar-left,
.p3x-stage-toolbar-center,
.p3x-stage-toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--p3x-gap-sm);
}

.p3x-stage-toolbar-left {
    flex: 0 0 auto;
}

.p3x-stage-toolbar-center {
    flex: 1;
    justify-content: center;
}

.p3x-stage-toolbar-right {
    flex: 0 0 auto;
    margin-left: auto;
}

/* Console: overflow:visible (fix from Nemesis — resizer-h must remain interactive),
   border-top removed (resizer-h handles visual separation). */
.p3x-stage-console {
    flex: var(--p3x-stage-console-flex, 0 1 auto);
    height: var(--p3x-stage-console-h, 50%);
    min-height: var(--p3x-stage-console-min, 100px);
    max-height: var(--p3x-stage-console-max, 80%);
    border-top: none;
    overflow: visible;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 2;
    max-width: 100%;
}

/* ── Console tabs (TerminalPool — workspace-filtered tab bar) ──
   Reference: 3D Factory DialogueZone.css @FluideUI:S2-Console
   Structure: .p3x-console > .p3x-console-tabs + .p3x-console-content */

.p3x-console-tabs {
    display: flex;
    background: transparent;
    border-bottom: 1px solid var(--p3x-bg-border);
    flex-shrink: 0;
}

.p3x-console-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--p3x-gap-sm);
    padding: var(--p3x-gap-md) var(--p3x-gap-lg);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--p3x-text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--p3x-transition);
    white-space: nowrap;
}

.p3x-console-tab:hover {
    color: var(--p3x-text);
    background: rgba(255, 255, 255, 0.03);
}

.p3x-console-tab.active {
    color: var(--p3x-accent);
    border-bottom-color: var(--p3x-accent);
    background: var(--p3x-accent-dim);
}

.p3x-console-tab-icon {
    display: inline-flex;
    align-items: center;
    opacity: 0.85;
}

.p3x-console-tab-status {
    font-size: 8px;
    margin-left: 4px;
}
.p3x-console-tab-status.ok    { color: var(--p3x-status-ok); }
.p3x-console-tab-status.warn  { color: var(--p3x-status-warn); }
.p3x-console-tab-status.error { color: var(--p3x-status-critical); }

/* Console content zone (one visible at a time) */

.p3x-console-content {
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.p3x-console-content.hidden {
    display: none;
}

.p3x-console-content.visible {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Console placeholder (tabs not yet implemented) */

.p3x-console-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--p3x-text-muted);
    gap: var(--p3x-gap-md);
    font-size: 14px;
}

.p3x-console-placeholder-hint {
    font-size: 12px;
    opacity: 0.5;
}

/* ── Console Allview Mode (from Nemesis Control) ──
   All console tabs visible side by side. Toggle via .p3x-console-mode-toggle.
   Vertical resizers between console panes for proportional sizing. */

.p3x-stage-console.allview .fui-console-content,
.p3x-stage-console.allview .p3x-console-content { display: flex !important; }
.p3x-stage-console.allview .fui-console-content.hidden,
.p3x-stage-console.allview .p3x-console-content.hidden { display: flex !important; }

.p3x-stage-console.allview .p3x-console-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.p3x-stage-console.allview .p3x-console-content {
    flex: 1;
    min-width: 0;
    border-right: 1px solid var(--p3x-bg-border);
    flex-direction: column;
}
.p3x-stage-console.allview .p3x-console-content:last-child { border-right: none; }

/* In allview, tabs become non-interactive labels */
.p3x-stage-console.allview .p3x-console-tab {
    pointer-events: none;
    border-bottom-color: var(--p3x-accent);
    color: var(--p3x-accent);
    opacity: 0.7;
}
.p3x-stage-console.allview .p3x-console-tab.active { opacity: 1; }

/* Vertical resizer between console panes (allview only) */
.p3x-console-resizer-v {
    width: 6px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5;
}
.p3x-stage-console.allview .p3x-console-resizer-v { display: flex; }

.p3x-console-resizer-v::after {
    content: '';
    width: 2px;
    height: 30px;
    background: var(--p3x-bg-border);
    border-radius: 1px;
    transition: all var(--p3x-transition);
}
.p3x-console-resizer-v:hover::after {
    background: var(--p3x-accent);
    height: 40px;
    box-shadow: var(--p3x-glow-accent);
}

/* Console mode toggle button (tab vs allview) — positioned in tab bar */
.p3x-console-mode-toggle {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    color: var(--p3x-text-secondary);
    font-size: 12px;
    padding: 0 var(--p3x-gap-md);
    cursor: pointer;
    margin-left: auto;
    flex-shrink: 0;
    gap: var(--p3x-gap-sm);
    transition: color var(--p3x-transition);
}
.p3x-console-mode-toggle:hover { color: var(--p3x-accent); }
.p3x-console-mode-toggle.allview { color: var(--p3x-accent); }

/* ── Chat interface (reusable IA chat pattern for console tabs) ──
   Reference: 3D Factory CadCopilot @FluideUI:S2-Console:CSS-CHAT */

.p3x-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: transparent;
}

.p3x-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--p3x-gap-lg);
    display: flex;
    flex-direction: column;
    gap: var(--p3x-gap-md);
}

.p3x-chat-message {
    padding: var(--p3x-gap-md) var(--p3x-gap-lg);
    border-radius: var(--p3x-radius-md);
    font-size: 13px;
    line-height: 1.5;
}

.p3x-chat-message.user {
    background: var(--p3x-accent-dim);
    border-left: 3px solid var(--p3x-accent);
}

.p3x-chat-message.assistant {
    background: rgba(255, 255, 255, 0.04);
    border-left: 3px solid var(--p3x-status-ok);
}

.p3x-chat-message.system {
    background: rgba(255, 170, 0, 0.06);
    border-left: 3px solid var(--p3x-status-warn);
    font-size: 12px;
}

.p3x-chat-message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--p3x-gap-sm);
}

.p3x-chat-message-role {
    font-weight: 600;
    font-size: 11px;
    color: var(--p3x-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.p3x-chat-message-time {
    font-size: 10px;
    color: var(--p3x-text-muted);
    font-family: var(--p3x-font-mono);
}

.p3x-chat-message-content {
    color: var(--p3x-text);
    font-family: var(--p3x-font-mono);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.p3x-chat-typing {
    color: var(--p3x-accent);
    animation: p3x-pulse 1s ease-in-out infinite;
}

/* Chat input area */

.p3x-chat-input-area {
    display: flex;
    gap: var(--p3x-gap-md);
    padding: var(--p3x-gap-md) var(--p3x-gap-lg);
    border-top: 1px solid var(--p3x-bg-border);
    background: transparent;
    align-items: flex-end;
}

.p3x-chat-input {
    flex: 1;
    padding: var(--p3x-gap-md) var(--p3x-gap-lg);
    background: transparent;
    border: 1px solid var(--p3x-bg-border);
    border-radius: var(--p3x-radius-md);
    color: var(--p3x-text);
    font-size: 13px;
    font-family: var(--p3x-font-mono);
    resize: none;
    outline: none;
    transition: border-color var(--p3x-transition);
    min-height: 36px;
    max-height: 100px;
}

.p3x-chat-input:focus {
    border-color: var(--p3x-accent);
    box-shadow: 0 0 0 2px var(--p3x-accent-dim);
}

.p3x-chat-send {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--p3x-accent-dim);
    border: 1px solid var(--p3x-accent);
    border-radius: var(--p3x-radius-md);
    color: var(--p3x-accent);
    font-size: 16px;
    cursor: pointer;
    transition: all var(--p3x-transition);
    flex-shrink: 0;
}

.p3x-chat-send:hover:not(:disabled) {
    background: rgba(52, 152, 219, 0.25);
    box-shadow: var(--p3x-glow-accent);
}

.p3x-chat-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Chat footer (model info, connection status) */

.p3x-chat-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--p3x-gap-sm) var(--p3x-gap-lg);
    background: transparent;
    border-top: 1px solid var(--p3x-bg-border);
    font-size: 10px;
    flex-shrink: 0;
    color: var(--p3x-text-muted);
    font-family: var(--p3x-font-mono);
}

/* ── Universal button ──
   FluideUI default: borderless (text/icon only).
   The button IS its label or icon — no frame, no background.
   Color = state (muted=idle, accent=hover, specific=active).
   Use .p3x-btn.outlined for explicit borders (opt-in). */

.p3x-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--p3x-gap-sm);
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    border: none;
    background: none;
    color: var(--p3x-text-secondary);
    border-radius: var(--p3x-radius-sm);
    cursor: pointer;
    transition: all var(--p3x-transition);
    opacity: 0.7;
}
.p3x-btn:hover {
    color: var(--p3x-text);
    opacity: 1;
}
.p3x-btn.active {
    color: var(--p3x-accent);
    opacity: 1;
}
.p3x-btn.danger {
    color: var(--p3x-status-critical);
    opacity: 0.5;
}
.p3x-btn.danger:hover {
    opacity: 1;
}
.p3x-btn.primary {
    color: var(--p3x-accent);
    opacity: 1;
}
.p3x-btn.primary:hover {
    text-shadow: var(--p3x-glow-accent);
}

/* Opt-in: outlined button (with border) — pour les actions
   qui nécessitent un cadre explicite (CTA, formulaires) */
.p3x-btn.outlined {
    border: 1px solid var(--p3x-bg-border);
    opacity: 1;
    padding: 4px 12px;
}
.p3x-btn.outlined:hover {
    border-color: var(--p3x-accent);
    background: var(--p3x-accent-dim);
}
.p3x-btn.outlined.primary {
    border-color: var(--p3x-accent);
    background: var(--p3x-accent-dim);
}
.p3x-btn.outlined.primary:hover {
    background: var(--p3x-accent);
    color: var(--p3x-text-inverse);
}
.p3x-btn.outlined.danger {
    border-color: var(--p3x-status-critical);
}
.p3x-btn.outlined.danger:hover {
    background: rgba(255, 51, 68, 0.15);
}

/* ── Universal input ── */

.p3x-input {
    background: transparent;
    border: 1px solid var(--p3x-bg-border);
    color: var(--p3x-text);
    padding: 4px 8px;
    font-size: 12px;
    font-family: var(--p3x-font);
    border-radius: var(--p3x-radius-sm);
    transition: border-color var(--p3x-transition);
}
.p3x-input:focus {
    border-color: var(--p3x-accent);
    outline: none;
    box-shadow: 0 0 0 3px var(--p3x-accent-dim);
}

/* ── Toast notifications ── */

.p3x-toast-container {
    position: fixed;
    bottom: calc(var(--p3x-footer-h) + var(--p3x-gap-md));
    right: var(--p3x-gap-lg);
    display: flex;
    flex-direction: column;
    gap: var(--p3x-gap-sm);
    z-index: var(--p3x-z-toast);
}

.p3x-toast {
    padding: var(--p3x-gap-md) var(--p3x-gap-lg);
    border-left: 3px solid var(--p3x-accent);
    border-radius: var(--p3x-radius-sm);
    font-size: 12px;
    animation: p3x-toast-in 0.3s ease;
}
.p3x-toast.success { border-left-color: var(--p3x-status-ok); }
.p3x-toast.error   { border-left-color: var(--p3x-status-critical); }
.p3x-toast.warning  { border-left-color: var(--p3x-status-warn); }

@keyframes p3x-toast-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Modal overlay ── */

.p3x-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--p3x-z-modal);
    animation: p3x-fade-in 0.2s ease;
}

.p3x-modal {
    border: 1px solid var(--p3x-bg-border);
    border-radius: var(--p3x-radius-lg);
    max-width: 90vw;
    max-height: 85vh;
    overflow: auto;
    animation: p3x-slide-in 0.3s ease;
}

@keyframes p3x-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes p3x-slide-in {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ── Data display helpers ── */

.p3x-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid var(--p3x-bg-border);
    font-size: 12px;
}

.p3x-label {
    color: var(--p3x-text-secondary);
    font-size: 11px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.p3x-value {
    font-family: var(--p3x-font-mono);
    color: var(--p3x-text);
}

/* ── Gauge bar ── */

.p3x-gauge {
    height: 4px;
    background: var(--p3x-bg-elevated);
    border-radius: 2px;
    overflow: hidden;
}
.p3x-gauge-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.8s ease, background var(--p3x-transition);
}
.p3x-gauge-fill.ok       { background: var(--p3x-status-ok); }
.p3x-gauge-fill.warn     { background: var(--p3x-status-warn); }
.p3x-gauge-fill.critical { background: var(--p3x-status-critical); }

/* ── Stage background options ── */

.p3x-stage-bg-none {
    background: transparent;
}

.p3x-stage-bg-solid {
    background: var(--p3x-bg);
}

.p3x-stage-bg-grid3d {
    position: relative;
    overflow: hidden;
    background: #000000;
    /* Color override: --p3x-grid3d-color: R, G, B  (default: cyan) */
}

.p3x-stage-bg-plasmawave {
    position: relative;
    overflow: hidden;
    background: radial-gradient(ellipse at center,
        rgba(0, 60, 20, 0.4) 0%,
        rgba(0, 20, 8, 0.2) 40%,
        transparent 70%);
}
.p3x-stage-bg-plasmawave::before {
    content: '';
    position: absolute;
    inset: -50%;
    width: 200%;
    height: 200%;
    background:
        /* Anneau externe — halo diffus */
        radial-gradient(ellipse at center,
            transparent 28%,
            rgba(0, 255, 80, 0.03) 30%,
            rgba(0, 200, 60, 0.06) 32%,
            transparent 35%) no-repeat center,
        /* Anneau principal — plasma dense */
        radial-gradient(ellipse at center,
            transparent 18%,
            rgba(0, 255, 100, 0.04) 20%,
            rgba(0, 220, 80, 0.08) 22%,
            rgba(0, 180, 60, 0.04) 24%,
            transparent 27%) no-repeat center,
        /* Noyau — coeur lumineux */
        radial-gradient(ellipse at center,
            rgba(0, 255, 120, 0.12) 0%,
            rgba(0, 220, 80, 0.08) 8%,
            rgba(0, 180, 60, 0.04) 14%,
            transparent 18%) no-repeat center,
        /* Filaments plasma — texture tourbillonnante */
        conic-gradient(from 0deg at 50% 50%,
            transparent 0deg,
            rgba(0, 255, 80, 0.03) 30deg,
            transparent 60deg,
            rgba(0, 200, 100, 0.04) 120deg,
            transparent 150deg,
            rgba(0, 255, 60, 0.03) 210deg,
            transparent 240deg,
            rgba(0, 180, 80, 0.04) 300deg,
            transparent 330deg,
            rgba(0, 255, 80, 0.03) 360deg);
    animation: borg-plasma-rotate 60s linear infinite;
    pointer-events: none;
}
.p3x-stage-bg-plasmawave::after {
    content: '';
    position: absolute;
    inset: -25%;
    width: 150%;
    height: 150%;
    background:
        /* Contre-rotation — anneaux secondaires */
        radial-gradient(ellipse at center,
            transparent 22%,
            rgba(0, 255, 80, 0.02) 24%,
            transparent 26%) no-repeat center,
        /* Filaments secondaires */
        conic-gradient(from 180deg at 50% 50%,
            transparent 0deg,
            rgba(0, 200, 60, 0.02) 45deg,
            transparent 90deg,
            rgba(0, 255, 80, 0.03) 180deg,
            transparent 225deg,
            rgba(0, 200, 100, 0.02) 315deg,
            transparent 360deg);
    animation: borg-plasma-rotate 45s linear infinite reverse;
    pointer-events: none;
}

.p3x-stage-bg-borg,
.p3x-stage-bg-borg-v1 {
    position: relative;
    overflow: hidden;
    background: radial-gradient(ellipse at center,
        rgba(0, 40, 15, 0.15) 0%,
        transparent 60%);
    /* Color override: --p3x-borg-color: R, G, B  (default: Borg green) */
}

.p3x-stage-bg-matrix {
    position: relative;
    overflow: hidden;
    background: #000000;  /* opaque — required for trail fade overlay */
    /* Color override: --p3x-matrix-color: R, G, B  (default: Matrix green) */
}

.p3x-stage-bg-milkyway {
    position: relative;
    overflow: hidden;
    background:
        url('../shared/img/milkyway.jpg') center/cover no-repeat,
        radial-gradient(ellipse at center,
            rgba(10, 15, 30, 1) 0%,
            rgba(2, 3, 8, 1) 100%);
    /* Accent override: --p3x-milkyway-accent: R, G, B */
}

@keyframes borg-plasma-rotate {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════════════
   COMPONENTS — Universal reusable components
   Origin: PlexWAR (Weyland-Yutani theme) → standardized for FluideUI
   ═══════════════════════════════════════════════════════════════════ */

/* ── Panel (structured card with header/body/footer) ── */

.p3x-panel {
    background: var(--p3x-bg-panel);
    border: 1px solid var(--p3x-bg-border);
    display: flex;
    flex-direction: column;
    transition: all var(--p3x-transition);
}

.p3x-panel:hover {
    border-color: var(--p3x-accent-dim);
}

.p3x-panel-header {
    background: var(--p3x-bg-surface);
    border-bottom: 1px solid var(--p3x-bg-border);
    padding: var(--p3x-gap-md);
    color: var(--p3x-accent);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.p3x-panel-body {
    padding: var(--p3x-gap-md);
    flex: 1;
    overflow-y: auto;
}

.p3x-panel-footer {
    background: var(--p3x-bg-surface);
    border-top: 1px solid var(--p3x-bg-border);
    padding: var(--p3x-gap-md);
    display: flex;
    gap: var(--p3x-gap-sm);
    justify-content: flex-end;
    flex-shrink: 0;
}

/* ── Stat tiles (KPI display) ── */

.p3x-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--p3x-gap-lg);
}

.p3x-stat {
    background: var(--p3x-bg-panel);
    border: 1px solid var(--p3x-bg-border);
    padding: var(--p3x-gap-lg);
    text-align: center;
    transition: all var(--p3x-transition);
}

.p3x-stat:hover {
    border-color: var(--p3x-accent);
    box-shadow: var(--p3x-glow-accent);
}

.p3x-stat-value {
    font-size: 28px;
    font-weight: 700;
    font-family: var(--p3x-font-mono);
    color: var(--p3x-accent);
    line-height: 1;
    margin-bottom: var(--p3x-gap-sm);
}

.p3x-stat-label {
    font-size: 10px;
    color: var(--p3x-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.p3x-stat-change {
    font-size: 11px;
    margin-top: var(--p3x-gap-sm);
    font-weight: 600;
}
.p3x-stat-change.positive { color: var(--p3x-status-ok); }
.p3x-stat-change.negative { color: var(--p3x-status-critical); }
.p3x-stat-change.neutral  { color: var(--p3x-status-info); }

/* ── Badge (status label) ── */

.p3x-badge {
    display: inline-block;
    padding: 1px var(--p3x-gap-sm);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
    border: 1px solid;
    background: transparent;
    white-space: nowrap;
    border-radius: var(--p3x-radius-sm);
}

.p3x-badge.ok       { border-color: var(--p3x-status-ok);       color: var(--p3x-status-ok); }
.p3x-badge.warn     { border-color: var(--p3x-status-warn);     color: var(--p3x-status-warn); }
.p3x-badge.critical { border-color: var(--p3x-status-critical); color: var(--p3x-status-critical); }
.p3x-badge.info     { border-color: var(--p3x-status-info);     color: var(--p3x-status-info); }
.p3x-badge.accent   { border-color: var(--p3x-accent);          color: var(--p3x-accent); }

/* ── Progress bar (full-width track + fill) ── */

.p3x-progress {
    width: 100%;
    height: 6px;
    background: var(--p3x-bg-elevated);
    border: 1px solid var(--p3x-bg-border);
    overflow: hidden;
}

.p3x-progress-bar {
    height: 100%;
    background: var(--p3x-accent);
    transition: width 0.5s ease;
}
.p3x-progress-bar.ok       { background: var(--p3x-status-ok);       box-shadow: var(--p3x-glow-ok); }
.p3x-progress-bar.warn     { background: var(--p3x-status-warn);     box-shadow: var(--p3x-glow-warn); }
.p3x-progress-bar.critical { background: var(--p3x-status-critical); box-shadow: var(--p3x-glow-critical); }

.p3x-progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--p3x-text-muted);
    margin-bottom: var(--p3x-gap-xs);
}

/* ── Terminal display (monospace output zone) ── */

.p3x-terminal {
    background: var(--p3x-bg);
    border: 1px solid var(--p3x-bg-border);
    color: var(--p3x-accent);
    padding: var(--p3x-gap-md);
    font-family: var(--p3x-font-mono);
    font-size: 12px;
    line-height: 1.6;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.p3x-terminal-line {
    display: block;
}

.p3x-terminal-line.error { color: var(--p3x-status-critical); }
.p3x-terminal-line.warn  { color: var(--p3x-status-warn); }
.p3x-terminal-line.info  { color: var(--p3x-status-info); }
.p3x-terminal-line.ok    { color: var(--p3x-status-ok); }

.p3x-terminal-cursor {
    display: inline-block;
    width: 8px;
    height: 1em;
    background: var(--p3x-accent);
    margin-left: 2px;
    animation: p3x-blink 1s ease-in-out infinite;
}

@keyframes p3x-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* ── Table (data table with header highlighting) ── */

.p3x-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--p3x-bg-panel);
    border: 1px solid var(--p3x-bg-border);
    font-size: 12px;
}

.p3x-table thead {
    background: var(--p3x-bg-surface);
    border-bottom: 2px solid var(--p3x-accent);
}

.p3x-table th {
    color: var(--p3x-accent);
    padding: var(--p3x-gap-md);
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.p3x-table td {
    padding: var(--p3x-gap-md);
    border-bottom: 1px solid var(--p3x-bg-border);
    color: var(--p3x-text);
}

.p3x-table tbody tr:hover {
    background: var(--p3x-bg-surface);
}

.p3x-table tbody tr:nth-child(even) {
    background: var(--p3x-bg-elevated);
}

/* ── Loading spinner ── */

.p3x-loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--p3x-bg-border);
    border-top-color: var(--p3x-accent);
    border-right-color: var(--p3x-accent);
    border-radius: 50%;
    animation: p3x-spin 0.8s linear infinite;
}

.p3x-loading.large {
    width: 40px;
    height: 40px;
    border-width: 3px;
}

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

/* ── Skeleton loader (placeholder shimmer) ── */

.p3x-skeleton {
    background: linear-gradient(
        90deg,
        var(--p3x-bg-panel),
        var(--p3x-bg-elevated),
        var(--p3x-bg-panel)
    );
    background-size: 200% 100%;
    animation: p3x-shimmer 1.5s infinite;
    border-radius: var(--p3x-radius-sm);
}

@keyframes p3x-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── CRT Scanlines overlay (design effect option) ── */

.p3x-fx-scanlines::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: var(--p3x-z-overlay);
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.06),
        rgba(0, 0, 0, 0.06) 1px,
        transparent 1px,
        transparent 2px
    );
}

/* ── Form group (label + input) ── */

.p3x-form-group {
    display: flex;
    flex-direction: column;
    gap: var(--p3x-gap-sm);
}

.p3x-form-group label {
    color: var(--p3x-accent);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.p3x-select {
    background: var(--p3x-bg-panel);
    color: var(--p3x-text);
    border: 1px solid var(--p3x-bg-border);
    padding: 4px 8px;
    font-family: var(--p3x-font);
    font-size: 12px;
    border-radius: var(--p3x-radius-sm);
    transition: border-color var(--p3x-transition);
}

.p3x-select:focus {
    border-color: var(--p3x-accent);
    outline: none;
    box-shadow: 0 0 0 3px var(--p3x-accent-dim);
}

/* ── Button color & size variants ── */

.p3x-btn.warning { color: var(--p3x-status-warn); }
.p3x-btn.info    { color: var(--p3x-status-info); }
.p3x-btn.ok      { color: var(--p3x-status-ok); }

.p3x-btn.outlined.warning { border-color: var(--p3x-status-warn); }
.p3x-btn.outlined.warning:hover { background: rgba(255, 170, 0, 0.15); }
.p3x-btn.outlined.info    { border-color: var(--p3x-status-info); }
.p3x-btn.outlined.info:hover    { background: rgba(52, 152, 219, 0.15); }

.p3x-btn.small { padding: 2px 6px; font-size: 10px; }
.p3x-btn.large { padding: 8px 16px; font-size: 13px; }
.p3x-btn.block { width: 100%; }

/* ── Responsive ── */

@media (max-width: 1024px) {
    .p3x-nav { width: 220px; min-width: 160px; }
    .p3x-ctx { width: 240px; min-width: 160px; }
}

@media (max-width: 768px) {
    .p3x-main { flex-direction: column; }
    .p3x-nav, .p3x-ctx { width: 100%; max-width: 100%; height: auto; border: none; }
    .p3x-resizer { display: none; }
    :root { --p3x-header-h: 40px; --p3x-footer-h: 28px; }
}
