/* ═══════════════════════════════════════════════════════════════════════════
   Chroma Conductor — Hub Shell Styles
   Max Chroma Design System: deep purple-blue palette, glassmorphism, 
   micro-animations, premium feel.
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ─── CSS Custom Properties ──────────────────────────────────────────────── */

:root {
    /* Core palette */
    --cc-bg-deepest: #07060e;
    --cc-bg-deep: #0d0a1a;
    --cc-bg-surface: #151127;
    --cc-bg-elevated: #1c1636;
    --cc-bg-hover: #241e45;

    /* Accent colors */
    --cc-accent-primary: #a855f7;
    --cc-accent-secondary: #6366f1;
    --cc-accent-glow: rgba(168, 85, 247, 0.3);
    --cc-accent-gradient: linear-gradient(135deg, #a855f7 0%, #6366f1 50%, #3b82f6 100%);
    --cc-accent-gradient-subtle: linear-gradient(135deg, rgba(168, 85, 247, 0.15) 0%, rgba(99, 102, 241, 0.1) 100%);

    /* Text */
    --cc-text-primary: #f1f0f5;
    --cc-text-secondary: #9b96b0;
    --cc-text-muted: #6b6580;
    --cc-text-accent: #c084fc;

    /* Status colors */
    --cc-status-online: #34d399;
    --cc-status-offline: #ef4444;
    --cc-status-warning: #f59e0b;
    --cc-status-idle: #6b7280;

    /* Glass */
    --cc-glass-bg: rgba(21, 17, 39, 0.85);
    --cc-glass-border: rgba(168, 85, 247, 0.15);
    --cc-glass-blur: 20px;

    /* Sizing */
    --cc-sidebar-width: 260px;
    --cc-statusbar-height: 36px;
    --cc-transition-speed: 0.25s;

    /* Shadows */
    --cc-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --cc-shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --cc-shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --cc-shadow-glow: 0 0 20px rgba(168, 85, 247, 0.2);
}

/* ─── Reset & Base ───────────────────────────────────────────────────────── */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--cc-bg-deepest);
    color: var(--cc-text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── Hub Layout ─────────────────────────────────────────────────────────── */

#hub-shell {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */

#hub-sidebar {
    width: var(--cc-sidebar-width);
    min-width: var(--cc-sidebar-width);
    height: 100%;
    background: var(--cc-glass-bg);
    backdrop-filter: blur(var(--cc-glass-blur));
    -webkit-backdrop-filter: blur(var(--cc-glass-blur));
    border-right: 1px solid var(--cc-glass-border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--cc-transition-speed) ease;
    overflow: hidden;
}

#hub-sidebar.collapsed {
    transform: translateX(calc(-1 * var(--cc-sidebar-width)));
    min-width: 0;
    width: 0;
}

/* Sidebar header / brand */
.sidebar-brand {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--cc-glass-border);
    user-select: none;
}

.sidebar-brand h1 {
    font-size: 16px;
    font-weight: 700;
    background: var(--cc-accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.3px;
    margin-bottom: 2px;
}

.sidebar-brand .brand-sub {
    font-size: 10px;
    font-weight: 500;
    color: var(--cc-text-muted);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

/* Mode switcher */
.mode-switcher {
    display: flex;
    gap: 2px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--cc-glass-border);
}

.mode-btn {
    flex: 1;
    padding: 6px 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--cc-text-secondary);
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--cc-transition-speed) ease;
    letter-spacing: 0.2px;
}

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

.mode-btn.active {
    background: var(--cc-accent-gradient-subtle);
    color: var(--cc-text-accent);
    box-shadow: inset 0 0 0 1px rgba(168, 85, 247, 0.25);
}

/* Module list */
.module-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--cc-bg-hover) transparent;
}

.module-list::-webkit-scrollbar {
    width: 4px;
}

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

.module-list::-webkit-scrollbar-thumb {
    background: var(--cc-bg-hover);
    border-radius: 2px;
}

.module-section-title {
    font-size: 10px;
    font-weight: 600;
    color: var(--cc-text-muted);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding: 12px 8px 6px;
}

/* Module cards */
.module-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--cc-transition-speed) ease;
    margin-bottom: 2px;
    position: relative;
    overflow: hidden;
}

.module-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    background: var(--cc-accent-gradient);
    opacity: 0;
    transition: opacity var(--cc-transition-speed) ease;
    z-index: -1;
}

.module-card:hover {
    background: var(--cc-bg-hover);
}

.module-card:hover::before {
    opacity: 0.08;
}

.module-card.active {
    background: var(--cc-bg-hover);
}

.module-card.active::before {
    opacity: 0.12;
}

.module-card-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    background: var(--cc-bg-surface);
    box-shadow: var(--cc-shadow-sm);
}

.module-card-info {
    flex: 1;
    min-width: 0;
}

.module-card-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--cc-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.module-card-desc {
    font-size: 10px;
    color: var(--cc-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Status Bar ─────────────────────────────────────────────────────────── */

#hub-statusbar {
    height: var(--cc-statusbar-height);
    min-height: var(--cc-statusbar-height);
    background: var(--cc-bg-surface);
    border-top: 1px solid var(--cc-glass-border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 16px;
    font-size: 11px;
    color: var(--cc-text-secondary);
    z-index: 100;
}

.status-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

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

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

.status-dot.offline {
    background: var(--cc-status-offline);
}

.status-dot.idle {
    background: var(--cc-status-idle);
}

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

.status-separator {
    width: 1px;
    height: 16px;
    background: var(--cc-glass-border);
}

.status-label {
    font-weight: 500;
    color: var(--cc-text-muted);
}

.status-value {
    color: var(--cc-text-primary);
    font-weight: 500;
}

/* ─── Main Viewport ──────────────────────────────────────────────────────── */

#hub-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    min-width: 0;
}

#hub-viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--cc-bg-deep);
}

/* Composer mode — the WebGPU canvas fills viewport */
#hub-viewport.mode-composer #composer-container {
    display: block;
}

#hub-viewport.mode-composer #applet-container {
    display: none;
}

/* Applet mode — single applet fills viewport */
#hub-viewport.mode-applet #composer-container {
    display: none;
}

#hub-viewport.mode-applet #applet-container {
    display: block;
}

#composer-container {
    width: 100%;
    height: 100%;
    position: relative;
}

#composer-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#applet-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: none;
}

#applet-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: var(--cc-bg-deepest);
}

/* Applet empty state */
.applet-empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--cc-text-muted);
    gap: 12px;
    user-select: none;
}

.applet-empty-icon {
    font-size: 48px;
    opacity: 0.3;
}

.applet-empty-text {
    font-size: 14px;
    font-weight: 500;
}

.applet-empty-hint {
    font-size: 11px;
    color: var(--cc-text-muted);
    opacity: 0.6;
}

/* ─── Sidebar Toggle Button ──────────────────────────────────────────────── */

#sidebar-toggle {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 200;
    width: 28px;
    height: 28px;
    border: 1px solid var(--cc-glass-border);
    border-radius: 6px;
    background: var(--cc-glass-bg);
    backdrop-filter: blur(12px);
    color: var(--cc-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all var(--cc-transition-speed) ease;
    opacity: 0;
    pointer-events: none;
}

#hub-sidebar.collapsed ~ #hub-main #sidebar-toggle {
    opacity: 1;
    pointer-events: auto;
}

#sidebar-toggle:hover {
    background: var(--cc-bg-hover);
    color: var(--cc-text-primary);
    border-color: var(--cc-accent-primary);
}

/* ─── Connection Indicators (Status Bar) ─────────────────────────────────── */

.connection-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--cc-bg-elevated);
    font-size: 10px;
    font-weight: 600;
    transition: all var(--cc-transition-speed) ease;
}

.connection-badge.connected {
    background: rgba(52, 211, 153, 0.1);
    color: var(--cc-status-online);
    border: 1px solid rgba(52, 211, 153, 0.2);
}

.connection-badge.disconnected {
    background: rgba(239, 68, 68, 0.1);
    color: var(--cc-status-offline);
    border: 1px solid rgba(239, 68, 68, 0.15);
}

/* ─── Utility ────────────────────────────────────────────────────────────── */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ─── Asset Tray Panel ────────────────────────────────────────────────────── */

#hub-asset-tray {
    background: var(--cc-glass-bg);
    backdrop-filter: blur(var(--cc-glass-blur));
    -webkit-backdrop-filter: blur(var(--cc-glass-blur));
    border-top: 1px solid var(--cc-glass-border);
    display: flex;
    flex-direction: column;
    z-index: 95;
    transition: height var(--cc-transition-speed) ease;
    height: 180px; /* Default expanded height */
    position: relative;
}

#hub-asset-tray.collapsed {
    height: 38px; /* Header-only height */
}

/* Tray Header */
.tray-header {
    height: 38px;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    cursor: pointer;
    background: rgba(7, 6, 14, 0.4);
    border-bottom: 1px solid rgba(168, 85, 247, 0.05);
    user-select: none;
}

.tray-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tray-icon {
    font-size: 14px;
}

.tray-title {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--cc-text-primary);
}

.tray-count {
    font-size: 10px;
    color: var(--cc-text-muted);
    background: rgba(168, 85, 247, 0.1);
    padding: 1px 6px;
    border-radius: 10px;
    border: 1px solid rgba(168, 85, 247, 0.15);
}

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

.tray-btn {
    background: var(--cc-bg-surface);
    border: 1px solid var(--cc-glass-border);
    color: var(--cc-text-secondary);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--cc-transition-speed) ease;
}

.tray-btn:hover {
    background: var(--cc-bg-hover);
    color: var(--cc-text-primary);
    border-color: var(--cc-accent-primary);
}

.tray-btn.btn-danger {
    color: var(--cc-status-offline);
    border-color: rgba(239, 68, 68, 0.2);
}

.tray-btn.btn-danger:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: var(--cc-status-offline);
}

/* Tray Content */
.tray-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#hub-asset-tray.collapsed .tray-content {
    display: none;
}

.tray-empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--cc-text-muted);
    gap: 8px;
    pointer-events: none;
}

.tray-empty-icon {
    font-size: 32px;
    opacity: 0.3;
}

.tray-empty-text {
    font-size: 11px;
}

.tray-grid {
    width: 100%;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--cc-bg-hover) transparent;
}

.tray-grid::-webkit-scrollbar {
    height: 6px;
}

.tray-grid::-webkit-scrollbar-track {
    background: transparent;
}

.tray-grid::-webkit-scrollbar-thumb {
    background: var(--cc-bg-hover);
    border-radius: 3px;
}

/* Tray Item Card */
.tray-item {
    width: 110px;
    height: 110px;
    background: rgba(7, 6, 14, 0.5);
    border: 1px solid var(--cc-glass-border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 6px;
    cursor: grab;
    user-select: none;
    position: relative;
    transition: all var(--cc-transition-speed) ease;
    flex-shrink: 0;
}

.tray-item:hover {
    border-color: var(--cc-accent-primary);
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.15);
    transform: translateY(-2px);
}

.tray-item.dragging {
    opacity: 0.4;
    cursor: grabbing;
}

.tray-item-thumb {
    flex: 1;
    border-radius: 4px;
    overflow: hidden;
    background: var(--cc-bg-deepest);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.tray-item-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.tray-item-info {
    margin-top: 4px;
    font-size: 9px;
    color: var(--cc-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    width: 100%;
}

/* Delete button overlay on hover */
.tray-item-delete {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(7, 6, 14, 0.8);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--cc-status-offline);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--cc-transition-speed) ease, background var(--cc-transition-speed) ease;
}

.tray-item:hover .tray-item-delete {
    opacity: 1;
}

.tray-item-delete:hover {
    background: var(--cc-status-offline);
    color: var(--cc-text-primary);
}

/* Overlay for iframes during dragging */
.dragging-active iframe {
    pointer-events: none !important;
}

.drag-overlay {
    position: absolute;
    inset: 0;
    background: rgba(168, 85, 247, 0.05);
    border: 2px dashed var(--cc-accent-primary);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cc-text-accent);
    font-weight: 600;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--cc-transition-speed) ease;
    border-radius: 6px;
}

.dragging-active .drag-overlay {
    opacity: 1;
}

.drag-overlay-box {
    background: rgba(7, 6, 14, 0.9);
    border: 1px solid var(--cc-glass-border);
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: var(--cc-shadow-lg);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
