/**
 * Artemis Global Layout System
 * Version: 2.0.0
 * Date: October 29, 2025
 * Purpose: Enterprise-level unified header and sidebar layout
 *
 * This CSS file provides a standardized layout system for ALL Artemis pages.
 * It ensures consistent header positioning, sidebar alignment, and responsive behavior.
 *
 * Architecture:
 * - Fixed header at top (always visible, full-width)
 * - Sidebar below header (fixed left, responsive on mobile)
 * - Main content beside sidebar (flexible width)
 *
 * Replaces: Inconsistent patterns across index.html, geofencing-enterprise.html,
 *           html5-ads-enhanced.html, campaigns.html, ai-assistant.html
 */

/* ============================================================================
   LAYOUT CONSTANTS
   Enterprise-level standardization across all pages
   ============================================================================ */

:root {
    /* Dimensions */
    --artemis-header-height: 73px;
    --artemis-sidebar-width: 200px;
    --artemis-sidebar-width-mobile: 200px;

    /* Z-index Scale (systematic layering) - UPDATED Oct 29, 2025 */
    --artemis-z-base: 1;
    --artemis-z-sidebar: 1030;      /* Updated from 900 to match unified standard */
    --artemis-z-header: 1020;       /* Updated from 1000 to match unified standard */
    --artemis-z-sticky: 1020;       /* Added for backwards compatibility */
    --artemis-z-fixed: 1030;        /* Added for backwards compatibility */
    --artemis-z-chat-widget: 9999;  /* Added for chat widget */
    --artemis-z-overlay: 1100;
    --artemis-z-modal: 1200;

    /* Spacing */
    --artemis-header-padding: 16px; /* P1 Fix (Nov 8, 2025): Reduced from 24px to fix whitespace issue */
    --artemis-sidebar-padding: 16px;
    --artemis-content-padding: 24px;

    /* Transitions */
    --artemis-transition-sidebar: transform 0.3s ease;
    --artemis-transition-fade: opacity 0.2s ease;

    /* Breakpoints (for reference in media queries) */
    --artemis-breakpoint-mobile: 768px;
    --artemis-breakpoint-tablet: 1024px;
}

/* ============================================================================
   GLOBAL HEADER
   Fixed at top, full-width, always visible across ALL pages
   ============================================================================ */

.artemis-global-header,
.header.artemis-global-header {
    /* Positioning */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--artemis-header-height);
    z-index: var(--artemis-z-header);

    /* Layout */
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--artemis-header-padding);
    gap: 16px;

    /* Visual */
    background: var(--bg-primary, #ffffff);
    border-bottom: 1px solid var(--border-subtle, #e5e7eb);

    /* Ensure it stays on top */
    width: 100%;
    box-sizing: border-box;
}

/* Header sections */
.artemis-global-header .header-left {
    display: flex;
    align-items: center;
    gap: 8px; /* P1 Fix (Nov 8, 2025): Reduced from 12px to fix whitespace issue */
    flex-shrink: 0;
}

.artemis-global-header .header-title {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary, #111827);
    flex: 1;
    min-width: 0; /* Allow text to truncate if needed */
}

.artemis-global-header .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* Header logo - standardized sizing */
.artemis-global-header .header-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.artemis-global-header .header-logo img,
.artemis-global-header .logo-image {
    height: 40px;
    width: auto;
    object-fit: contain;
    display: block;
}

/* Hamburger menu - HIDDEN ON DESKTOP (Oct 29, 2025) */
.artemis-global-header .hamburger,
.artemis-global-header .hamburger-menu,
.artemis-global-header .menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: none; /* Hidden by default (desktop) */
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.artemis-global-header .hamburger:hover,
.artemis-global-header .hamburger-menu:hover,
.artemis-global-header .menu-toggle:hover {
    background: var(--bg-hover, rgba(0, 0, 0, 0.05));
}

/* ============================================================================
   APP CONTAINER
   Main layout wrapper below header
   ============================================================================ */

.artemis-app-container,
.app-container.artemis-app-container {
    /* Positioning */
    display: flex;
    margin-top: var(--artemis-header-height);
    min-height: calc(100vh - var(--artemis-header-height));

    /* Layout */
    position: relative;
    width: 100%;
}

/* ============================================================================
   SIDEBAR
   Fixed left, below header, consistent positioning
   ============================================================================ */

.artemis-sidebar,
.sidebar.artemis-sidebar,
aside.artemis-sidebar {
    /* Positioning - KEY FIX: Always below header */
    position: fixed;
    top: var(--artemis-header-height);  /* ← CRITICAL: Below header */
    left: 0;
    bottom: 0;
    width: var(--artemis-sidebar-width);
    z-index: var(--artemis-z-sidebar);

    /* Visual */
    background: var(--bg-primary, #ffffff);
    border-right: 1px solid var(--border-subtle, #e5e7eb);

    /* Scrolling */
    overflow-y: auto;
    overflow-x: hidden;

    /* Smooth transitions */
    transition: var(--artemis-transition-sidebar);
}

/* Sidebar navigation */
.artemis-sidebar .sidebar-nav,
.artemis-sidebar nav {
    display: flex;
    flex-direction: column;
    padding: var(--artemis-sidebar-padding);
    gap: 4px;
}

/* Navigation items - standardized sizing */
.artemis-sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-secondary, #6b7280);
    font-size: 16px;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
}

.artemis-sidebar .nav-item:hover {
    background: var(--bg-hover, rgba(0, 0, 0, 0.05));
    color: var(--text-primary, #111827);
}

.artemis-sidebar .nav-item.active {
    background: var(--primary-light, #eef2ff);
    color: var(--primary, #6366f1);
}

.artemis-sidebar .nav-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.artemis-sidebar .nav-item span {
    flex: 1;
}

/* ============================================================================
   MAIN CONTENT
   Flexible content area beside sidebar
   ============================================================================ */

.artemis-main-content,
.main-content.artemis-main-content,
main.artemis-main-content {
    /* Positioning */
    margin-left: var(--artemis-sidebar-width);
    flex: 1;

    /* Sizing */
    min-height: calc(100vh - var(--artemis-header-height));
    width: calc(100% - var(--artemis-sidebar-width));

    /* Layout */
    padding: var(--artemis-content-padding);
    box-sizing: border-box;

    /* Visual - Force white background (no black frames) - Oct 29 2025 */
    background: #FFFFFF;

    /* Scrolling */
    overflow-y: auto;
    overflow-x: hidden;
}

/* ============================================================================
   DARK MODE SUPPORT
   Consistent theming across header and sidebar
   ============================================================================ */

html.dark-mode .artemis-global-header,
html.dark-mode .artemis-sidebar,
[data-theme="dark"] .artemis-global-header,
[data-theme="dark"] .artemis-sidebar {
    background: var(--bg-primary, #1f2937);
    border-color: var(--border-subtle, #374151);
}

html.dark-mode .artemis-global-header .header-title,
[data-theme="dark"] .artemis-global-header .header-title {
    color: var(--text-primary, #f9fafb);
}

html.dark-mode .artemis-sidebar .nav-item,
[data-theme="dark"] .artemis-sidebar .nav-item {
    color: var(--text-secondary, #9ca3af);
}

html.dark-mode .artemis-sidebar .nav-item:hover,
[data-theme="dark"] .artemis-sidebar .nav-item:hover {
    background: var(--bg-hover, rgba(255, 255, 255, 0.05));
    color: var(--text-primary, #f9fafb);
}

html.dark-mode .artemis-sidebar .nav-item.active,
[data-theme="dark"] .artemis-sidebar .nav-item.active {
    background: var(--primary-dark, #4338ca);
    color: var(--text-primary, #f9fafb);
}

/* ============================================================================
   MOBILE RESPONSIVE
   Hamburger menu with sliding sidebar
   ============================================================================ */

@media (max-width: 768px) {
    /* Header adjustments */
    .artemis-global-header {
        padding: 0 16px;
    }

    .artemis-global-header .header-title {
        font-size: 18px;
    }

    /* SHOW hamburger menu on mobile ONLY (Oct 29, 2025) */
    .artemis-global-header .hamburger,
    .artemis-global-header .hamburger-menu,
    .artemis-global-header .menu-toggle {
        display: flex !important; /* Show on mobile */
        position: static !important; /* Force normal flow, not fixed */
        left: auto !important; /* Clear any fixed coordinates */
        top: auto !important; /* Clear any fixed coordinates */
        margin-right: 12px !important; /* Space between hamburger and logo */
        flex-shrink: 0 !important; /* Prevent shrinking */
        order: -1 !important; /* Ensure hamburger comes first */
    }

    /* FIX: Proper header-left layout - no overlap (Oct 29, 2025) */
    .artemis-global-header .header-left {
        gap: 0; /* Remove gap, use margin on hamburger instead */
    }

    /* P0 FIX: iOS HIG compliant touch targets - Oct 30, 2025 */
    /* Updated from 36px to 44px for iOS Human Interface Guidelines compliance */
    .artemis-global-header button,
    .artemis-global-header .btn-icon {
        min-width: 44px !important;
        min-height: 44px !important;
        width: 44px !important;
        height: 44px !important;
        font-size: 16px;
        padding: 10px;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* CRITICAL FIX: Hide sidebar completely on mobile (not just translate) */
    .artemis-sidebar,
    aside.artemis-sidebar,
    .sidebar.artemis-sidebar {
        display: none !important; /* Hide completely to prevent black bar */
    }

    /* Show sidebar when active (slide in from left) */
    .artemis-sidebar.active,
    .artemis-sidebar.open,
    aside.artemis-sidebar.active,
    aside.artemis-sidebar.open {
        display: flex !important;
        flex-direction: column;
        transform: translateX(0);
        width: var(--artemis-sidebar-width-mobile);
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    }

    /* Main content takes full width on mobile */
    .artemis-main-content,
    .main-content.artemis-main-content,
    main.artemis-main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 16px;
        box-sizing: border-box;
    }

    /* Overlay when sidebar is open - MOBILE FIX Oct 30, 2025 */
    /* Reduced opacity from 50% to 10% to prevent gray bar on mobile */
    .artemis-sidebar.active::before,
    .artemis-sidebar.open::before {
        content: '';
        position: fixed;
        top: var(--artemis-header-height);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.1); /* Changed from 0.5 to 0.1 */
        z-index: -1;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .artemis-sidebar {
        width: 180px;
    }

    .artemis-main-content {
        margin-left: 180px;
        width: calc(100% - 180px);
    }

    .artemis-sidebar .nav-item {
        font-size: 15px;
        padding: 10px 12px;
    }
}

/* ============================================================================
   ACCESSIBILITY ENHANCEMENTS
   WCAG 2.1 AA compliance
   ============================================================================ */

/* Focus indicators */
.artemis-global-header *:focus-visible,
.artemis-sidebar *:focus-visible {
    outline: 2px solid var(--primary, #6366f1);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .artemis-sidebar,
    .artemis-sidebar .nav-item,
    .artemis-global-header .hamburger {
        transition: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .artemis-global-header {
        border-bottom-width: 2px;
    }

    .artemis-sidebar {
        border-right-width: 2px;
    }

    .artemis-sidebar .nav-item.active {
        outline: 2px solid currentColor;
    }
}

/* Minimum tap target sizes (44x44px) */
.artemis-global-header button,
.artemis-sidebar .nav-item {
    min-height: 44px;
    min-width: 44px;
}

/* ============================================================================
   PRINT STYLES
   Optimize for printing
   ============================================================================ */

@media print {
    .artemis-global-header {
        position: static;
        border-bottom: 2px solid #000;
        height: auto;
        padding: 10px;
    }

    .artemis-sidebar {
        display: none; /* Hide sidebar in print */
    }

    .artemis-main-content {
        margin-left: 0;
        width: 100%;
        padding: 0;
    }

    .artemis-app-container {
        margin-top: 0;
    }
}

/* ============================================================================
   UTILITY CLASSES
   Helper classes for specific use cases
   ============================================================================ */

/* Force sidebar visibility (for debugging) */
.artemis-sidebar--visible {
    transform: translateX(0) !important;
}

/* Compact header variant */
.artemis-global-header--compact {
    height: 60px;
    padding: 0 16px;
}

.artemis-global-header--compact + .artemis-app-container {
    margin-top: 60px;
}

.artemis-global-header--compact + .artemis-app-container .artemis-sidebar {
    top: 60px;
}

/* Wide sidebar variant */
.artemis-sidebar--wide {
    width: 250px;
}

.artemis-sidebar--wide + .artemis-main-content {
    margin-left: 250px;
    width: calc(100% - 250px);
}

/* No sidebar layout */
.artemis-layout--no-sidebar .artemis-sidebar {
    display: none;
}

.artemis-layout--no-sidebar .artemis-main-content {
    margin-left: 0;
    width: 100%;
}

/* ============================================================================
   ANIMATION KEYFRAMES
   Smooth transitions for interactive elements
   ============================================================================ */

@keyframes artemis-sidebar-slide-in {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes artemis-sidebar-slide-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(-100%);
        opacity: 0;
    }
}

/* Apply animations on mobile */
@media (max-width: 768px) {
    .artemis-sidebar.active {
        animation: artemis-sidebar-slide-in 0.3s ease forwards;
    }

    .artemis-sidebar:not(.active) {
        animation: artemis-sidebar-slide-out 0.3s ease forwards;
    }
}

/* ============================================================================
   BROWSER COMPATIBILITY FIXES
   Ensure consistent behavior across browsers
   ============================================================================ */

/* Safari fix for sticky positioning */
@supports (-webkit-appearance: none) {
    .artemis-global-header {
        position: -webkit-sticky;
        position: sticky;
    }
}

/* Firefox scrollbar styling */
.artemis-sidebar {
    scrollbar-width: thin;
    scrollbar-color: var(--border-subtle, #e5e7eb) transparent;
}

/* Webkit scrollbar styling */
.artemis-sidebar::-webkit-scrollbar {
    width: 6px;
}

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

.artemis-sidebar::-webkit-scrollbar-thumb {
    background: var(--border-subtle, #e5e7eb);
    border-radius: 3px;
}

.artemis-sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--border-default, #d1d5db);
}

/* ============================================================================
   LEGACY COMPATIBILITY
   Gradual migration support - allows old class names to work
   ============================================================================ */

/* Map old header class to new system */
.header:not(.artemis-global-header) {
    /* Gradually migrate: add artemis-global-header class to headers */
}

/* Map old sidebar class to new system */
.sidebar:not(.artemis-sidebar) {
    /* Gradually migrate: add artemis-sidebar class to sidebars */
}

/* Map old app-container class to new system */
.app-container:not(.artemis-app-container) {
    /* Gradually migrate: add artemis-app-container class to containers */
}

/* ============================================================================
   END OF ARTEMIS GLOBAL LAYOUT SYSTEM
   ============================================================================ */
