/* ===============================================
   Window System - SAGE-style window management
   Matches system context bar aesthetic
   =============================================== */

/* Window Base Styles */
.sage-window {
    position: absolute;
    background: var(--bg-panel);
    border: 0px solid var(--border-color);
    border-radius: 7px;
    box-shadow: none;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: windowFadeIn 0.3s ease;
    transform-origin: top center; /* Scale from top center */
    user-select: none; /* Disable text selection in all windows */
}

/* Titlebar should never shrink so body can scroll */
.window-titlebar {
    flex-shrink: 0;
}

@keyframes windowFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.sage-window.dragging {
    opacity: 0.9;
    transition: none;
}

.sage-window.resizing {
    transition: none;
}

.sage-window.resizing .window-content {
    pointer-events: none;
}

.sage-window.active {
    border-color: rgba(0, 217, 255, 0.3);
    box-shadow: none;
}

/* Window States */
.sage-window.floating {
    resize: none; /* We handle resize manually */
}

.sage-window.minified {
    height: auto !important;
}

.sage-window.docked,
.sage-window.iconized,
.sage-window.closed {
    display: none !important;
}

/* Title Bar - match context bar height (32px + padding = 44px total) */
.window-titlebar {
    display: flex;
    align-items: center;
    height: 32px;
    background: transparent;
    border-bottom: 0px solid var(--border-color);
    cursor: move;
    user-select: none;
    padding: 6px 6px 6px 8px; /* Less padding on right for tight corner */
}

.window-title-left {
    display: flex;
    align-items: center;
    position: relative;
    margin-right: 12px;
}

.window-icon-marker {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
}

.window-notification-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgb(236, 133, 65);
    border: 1.5px solid rgba(15, 20, 35, 0.98);
    z-index: 3;
    pointer-events: none;
}

.window-icon-marker svg {
    width: 14px;
    height: 14px;
    stroke: var(--accent-primary);
    stroke-width: 2;
}

.window-accent-line {
    display: none; /* Remove accent line for cleaner look */
}

.window-title {
    flex: 1;
    font-family: 'Orbitron', var(--font-title), monospace;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: var(--text-primary);
    margin: 0;
    text-transform: uppercase;
}

/* Remove outline from editable title */
.window-title .title-text[contenteditable="true"] {
    outline: none;
}

/* Title hidden state */
.sage-window.title-hidden .window-title {
    display: none;
}

/* In docked mode with hidden title, hide title and center the summary */
.docked-window.title-hidden .docked-title {
    display: none;
}

.docked-window.title-hidden .docked-text {
    justify-content: center;
}

/* Window Controls - smaller buttons with more gap */
.window-controls {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.window-controls button {
    width: 28px;
    height: 28px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-family: var(--font-mono);
}

.window-controls button svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.window-controls button:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: transparent;
    color: var(--text-primary);
}

.window-close:hover {
    background: rgba(255, 0, 110, 0.15);
    border-color: transparent;
    color: var(--accent-tertiary);
}

.window-close svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.5;
}

/* Content Area */
.window-content {
    flex: 1;
    padding: 0;
    overflow: hidden; /* Scroll container is .window-body */
    position: relative;
    z-index: 1;
    min-height: 0; /* Critical for flex scrolling */
    display: flex;
    flex-direction: column;
}

/* ===============================================
   Window Groups - Tab Bar under title bar
   =============================================== */
.window-tabs {
    position: relative;
    height: 32px;
    display: none; /* only for grouped windows */
    align-items: center;
    justify-content: center; /* center tabs under title bar */
    gap: 4px;
    padding: 4px 0; /* No horizontal padding - tabs go edge to edge */
}

.sage-window.grouped .window-tabs {
    display: flex;
}

.window-tab {
    height: 26px;
    padding: 0 12px;
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    border: 1px solid transparent;
    font-family: 'Orbitron', monospace;
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.08em;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    user-select: none;
    cursor: pointer;
    transition: all 0.15s ease;
    text-transform: uppercase;
    position: relative; /* For minified badge positioning */
}

.window-tab .tab-text {
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap; /* Prevent text wrapping */
    margin: 0;
    padding: 0;
    line-height: 1;
    transform: translateY(0.75px); /* Drop text by 0.75px */
}

.window-tab .window-notification-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgb(236, 133, 65);
    border: 1.5px solid rgba(15, 20, 35, 0.98);
    flex-shrink: 0;
    pointer-events: none;
    position: static; /* Ensure it's inline, not absolute */
    transform: translate(1px, 0.2px); /* Nudge badge right by 1px and down by 0.2px */
}

/* Minified mode - badge at bottom-right corner */
.sage-window.minified .window-tab {
    position: relative;
}

.sage-window.minified .window-tab .window-notification-badge {
    position: absolute !important;
    bottom: -2px;
    right: -2px;
    margin-left: 0 !important;
    margin-right: 0 !important; /* Reset margin in minified mode */
    display: block;
    vertical-align: auto;
    transform: none; /* Reset transform */
}

.window-tab:hover { 
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.7);
}

.window-tab.active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: transparent;
}

.window-tab .tab-icon {
    width: 14px;
    height: 14px;
    display: none; /* Hide icon container in normal mode */
    align-items: center;
    justify-content: center;
    position: relative;
}

.window-tab .tab-icon svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    stroke-width: 2;
}

.window-tab .tab-text {
    display: inline-block; /* show in normal mode */
}

/* Minified mode - show icons only */
.sage-window.minified .window-tab .tab-text {
    display: none;
}

.sage-window.minified .window-tab .tab-icon {
    display: inline-flex;
}

.sage-window.minified .window-tab .tab-icon svg {
    display: block; /* Show SVG in minified mode */
}

.sage-window.minified .window-tab {
    padding: 0 4px;
    min-width: 24px;
}

/* Tab close button removed - using context menu instead */

/* Tab placeholder during drag */
.tab-placeholder {
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    transition: opacity 0.2s ease;
}

/* The body should account for tabs when present */
.sage-window.grouped .window-body { 
    /* title height (32+padding 12) + tabs 32 already in layout; body flex handles height */
}

/* Ghost tab bar shown when dragging a window over another to indicate grouping */
.tabs-ghost {
    display: none;
    height: 26px;
    align-items: center;
    justify-content: center;
    margin: 4px 8px;
    border-radius: 6px;
    background: rgba(0, 217, 255, 0.12);
    animation: pulseGlow 1.5s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.tabs-ghost::after {
    content: 'Drop to join window group';
    font-family: 'Orbitron', monospace;
    font-size: 9px;
    letter-spacing: 0.12em;
    color: var(--accent-primary);
    text-transform: uppercase;
}

.sage-window.group-drop-hover .tabs-ghost { display: flex; }

/* Dedicated scroll container for window content */
.window-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto; /* Always be the scroll container */
    overflow-x: hidden;
    max-height: 100%;
}

/* Add padding back for regular content */
.window-content > *:not(.locations-panel):not(.controls-panel):not(.help-panel) {
    padding: 16px;
    padding-bottom: 24px;
}

/* For locations panel - fill parent, internal list scrolls */
/* Remove :has dependency - treat all bodies the same */

/* Special handling for locations panel */
.window-content .locations-panel {
    display: flex !important;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* Allow shrinking */
    /* no explicit height to allow flex sizing */
}

/* Controls panel - window content scrolls */
.window-content .controls-panel {
    padding: 12px;
    height: auto; /* Allow natural height */
}

/* Help panel - window content scrolls */
.window-content .help-panel {
    padding: 12px;
    height: auto; /* Allow natural height */
}

/* Custom scrollbar - dim grey with padding */
.window-body {
    padding-right: 4px; /* Space between content and scrollbar */
}

.window-body::-webkit-scrollbar {
    width: 6px;
}

.window-body::-webkit-scrollbar-track {
    background: transparent;
    margin: 4px 0; /* Padding top and bottom */
}

.window-body::-webkit-scrollbar-thumb {
    background: rgba(160, 170, 180, 0.15);
    border-radius: 3px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.window-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 217, 255, 0.3);
    background-clip: padding-box;
}

/* Summary (Minified State) - match context bar height (44px total) */
.window-summary {
    padding: 8px 0; /* No horizontal padding for minified windows */
    border-top: 0px solid var(--border-color);
    background: transparent;
    font-family: 'Orbitron', monospace;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0.06em;
    display: flex;
    align-items: center;
    justify-content: center; /* Center summary content horizontally */
    min-height: 12px; /* Ensure consistent height */
    user-select: none; /* Prevent text selection for dragging */
}

.summary-text {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.6);
    font-family: 'Orbitron', monospace;
    display: block; /* allow width and text-align to take effect */
    width: 100%;
    text-align: center;
    transform: translateY(-3px); /* visually nudge label up without changing height */
}

/* Resize Handle - rounded corner following radius rule */
.window-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 100; /* Higher z-index */
    pointer-events: auto; /* Ensure it's clickable */
    background: transparent;
    border-bottom-right-radius: 7px; /* Match window border-radius */
}

/* Hide resize handle in minified state */
.sage-window.minified .window-resize-handle {
    display: none !important;
}

.window-resize-handle::before {
    content: '';
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    border-right: 2px solid rgba(160, 170, 180, 0.25);
    border-bottom: 2px solid rgba(160, 170, 180, 0.25);
    border-bottom-right-radius: 2px;
}

.sage-window:hover .window-resize-handle {
    opacity: 1;
}

/* Always show resize handle when resizing */
.sage-window.resizing .window-resize-handle {
    opacity: 1;
}

/* ===============================================
   Docking Sidebar
   =============================================== */

.docking-sidebar {
    position: fixed;
    right: 4px; /* inset from viewport to add breathing room */
    top: 60px; /* Below menu bar */
    bottom: 0;
    width: 240px; /* Reduced from 280px (14% smaller) */
    pointer-events: none;
    z-index: 900;
    display: flex;
    flex-direction: column;
    /* Proximity-driven intensity for drop-ready gradients */
    --dock-prox-strong: 0.06;
    --dock-prox-mid: 0.03;
    --dock-prox-weak: 0.01;
}

.dock-label {
    font-family: 'Orbitron', var(--font-title), sans-serif;
    font-size: 6px;
    letter-spacing: 0.15em;
    color: rgba(180, 190, 200, 0.35);
    text-align: right;
    padding: 8px 12px 4px 0;
    pointer-events: none;
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 0.2s ease;
    font-weight: 500;
}

/* Show label when dragging */
.docking-sidebar.drop-active .dock-label {
    opacity: 1;
}

/* Dock slots container */
.dock-slots-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0 40px 8px; /* top right bottom left - no right padding */
    overflow: hidden; /* Never show scrollbar; content never scrolls */
}

/* Remove scrollbar styles - not needed */

/* Dock Slots - match minified window height exactly (44px) */
.dock-slot {
    min-height: 44px;
    max-height: 44px;
    height: 44px;
    flex-shrink: 0; /* Don't shrink slots */
    background: transparent;
    border: none;
    border-radius: 7px;
    transition: all 0.3s ease;
    position: relative; /* For absolute positioning of iconized windows */
    pointer-events: none; /* Don't block camera controls by default */
}

/* Occupied slots show docked window content */
.dock-slot.occupied {
    background: var(--bg-panel);
    border: 0px solid var(--border-color);
    pointer-events: auto; /* Enable pointer events for docked windows */
}

/* When iconized, slot should be transparent */
.dock-slot.has-iconized-window {
    background: transparent !important;
    border: none !important;
}

/* Empty slots are invisible by default */
.dock-slot.empty {
    background: transparent;
    border: none;
}

.dock-slot.drop-ready {
    border: none;
    background: transparent;
    /* Inner glow effect - brighter on right, fades to left, doesn't extend far */
    /* Glow starts at right edge, fades out ~10-12px from right edge */
    /* Shadow format: inset offset-x offset-y blur-radius spread-radius color */
    box-shadow: inset 
        -4px 0 8px -2px rgba(100, 110, 120, calc(var(--dock-prox-strong) * 0.6)),  /* Fades ~6px from right */
        inset -8px 0 12px -4px rgba(100, 110, 120, calc(var(--dock-prox-mid) * 0.4)),  /* Fades ~8px from right */
        inset -12px 0 16px -6px rgba(100, 110, 120, calc(var(--dock-prox-weak) * 0.2)); /* Fades ~10px from right */
    pointer-events: auto; /* Enable pointer events when dragging */
}

.dock-slot.drop-hover {
    border-color: transparent;
    background: transparent;
    /* Inner glow effect for hover - brighter on right, fades to left, doesn't extend far */
    /* Glow starts at right edge, fades out ~10-12px from right edge */
    /* Shadow format: inset offset-x offset-y blur-radius spread-radius color */
    box-shadow: inset 
        -4px 0 8px -2px rgba(0, 217, 255, 0.10),  /* Fades ~6px from right */
        inset -8px 0 12px -4px rgba(0, 217, 255, 0.05),  /* Fades ~8px from right */
        inset -12px 0 16px -6px rgba(0, 217, 255, 0.02); /* Fades ~10px from right */
    pointer-events: auto; /* Enable pointer events when hovering during drag */
}

/* Neighbor glow removed per design */

/* Removed - using .empty class instead for uniform styling */

/* Drop Zone */
.dock-drop-zone {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 16px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none; /* Don't block camera controls */
}

.docking-sidebar.drop-active .dock-drop-zone {
    opacity: 1;
    pointer-events: auto; /* Enable pointer events only when actively dragging */
}

.drop-indicator { 
    text-align: left;
    display: none; /* Hide "DOCK HERE" text */
}

.drop-icon { display: none; }

.drop-text { display: none; }

/* Docked Window - match minified height exactly (44px) */
.docked-window {
    height: 44px; /* Fixed height to match minified window */
    min-height: 44px;
    max-height: 44px;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    border-radius: 7px; /* consistent with window radius */
    overflow: hidden;
}

.docked-header {
    display: flex;
    align-items: center;
    height: 100%; /* Fill the entire 44px */
    padding: 6px 6px 6px 8px;
    background: transparent;
    border-bottom: 0px solid var(--border-color);
    cursor: move;
    transition: background 0.2s ease;
    width: 100%;
}

.docked-window:hover {
    background: rgba(255, 255, 255, 0.04);
}

.docked-icon {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.docked-icon svg {
    width: 14px;
    height: 14px;
    stroke: var(--accent-primary);
}

/* Notification badge on docked icon */
.docked-icon {
    position: relative;
}

.dock-notification-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgb(236, 133, 65);
    border: 1.5px solid rgba(15, 20, 35, 0.98);
}

.dock-icon-wrapper {
    position: relative;
}

.dock-icon-wrapper .dock-notification-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgb(236, 133, 65);
    border: 1.5px solid rgba(15, 20, 35, 0.98);
}

.docked-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    min-height: 32px; /* Ensure clickable area even when title hidden */
    user-select: none; /* Prevent text selection for dragging */
    cursor: context-menu; /* Show context menu cursor for groups */
}

.docked-title {
    font-family: 'Orbitron', var(--font-title), monospace;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: var(--text-primary);
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1;
}

.docked-summary-inline {
    font-family: 'Orbitron', monospace;
    font-size: 7px;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 0.06em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1;
}

.docked-controls {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.docked-controls button {
    width: 28px;
    height: 28px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-family: var(--font-mono);
    line-height: 1;
}

.docked-controls button svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.docked-controls button:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: transparent;
    color: var(--text-primary);
}

.dock-close:hover {
    background: rgba(255, 0, 110, 0.15);
    border-color: transparent;
    color: var(--accent-tertiary);
}

.dock-close svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.5;
}

/* Iconized State - just icon button on the right */
.docked-window.iconized {
    /* Pin the icon container to the right edge of the slot and center vertically */
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0; /* center vertically within the 44px slot */
    height: 100%;
    display: flex;
    flex-direction: row; /* override base column to prevent bottom alignment */
    align-items: center;
    justify-content: flex-end;
    cursor: pointer;
    background: transparent !important;
    padding: 0 8px 0 0; /* 8px from right edge */
    width: auto;
}

.dock-slot.occupied .docked-window.iconized {
    background: transparent !important;
}

.dock-icon-wrapper {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid transparent;
    border-radius: 7px; /* match slot/window radius */
    transition: all 0.2s ease;
}

.dock-icon-wrapper svg {
    width: 14px;
    height: 14px;
    stroke: var(--accent-primary);
}

.docked-window.iconized:hover .dock-icon-wrapper {
    background: rgba(255, 255, 255, 0.08);
    border-color: transparent;
}

/* Badge */
.dock-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: var(--accent-tertiary);
    color: white;
    font-size: 9px;
    font-weight: 600;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Orbitron', monospace;
}

/* Tooltip */
.dock-tooltip {
    position: absolute;
    left: -150px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-panel);
    border: 0px solid var(--border-color);
    padding: 6px 12px;
    font-size: 9px;
    font-family: 'Orbitron', monospace;
    letter-spacing: 0.08em;
    color: var(--text-primary);
    border-radius: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    white-space: nowrap;
    text-transform: uppercase;
}

.docked-window.iconized:hover .dock-tooltip {
    opacity: 1;
}
