/* Mige Premium Design System - High Contrast Edition */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;700&display=swap');

:root {
    /* High Contrast Palette */
    --bg-dark: #0f172a;
    /* Deep Slate */
    --bg-panel: #1e293b;
    /* Lighter Slate for Panels */
    --bg-card: #334155;
    /* Even Light Slate for Cards */

    --primary: #38bdf8;
    /* Sky Blue */
    --primary-dim: rgba(56, 189, 248, 0.2);

    --secondary: #818cf8;
    /* Indigo */
    --accent: #f59e0b;
    /* Amber - High Visibility */

    --text-main: #ffffff;
    /* Pure White */
    --text-sub: #cbd5e1;
    /* Light Grey - High Contrast */
    --text-muted: #94a3b8;
    /* Muted but readable */

    --border-color: #475569;
    /* Solid border */
    --border-highlight: #64748b;
}

body {
    background: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Panel Utilities */
.glass-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}

/* Layout */
.app-container {
    display: flex;
    flex: 1;
    gap: 20px;
    padding: 20px;
    padding: 20px;
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
    overflow: hidden;
    /* Prevent body scroll */
}

.sidebar {
    flex: 0 0 460px;
    /* [Fix] Increased for scrollbar */
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    /* Important for flex scroll */
    overflow: hidden;
}

#agent-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    /* Important */
    padding-right: 12px;
    /* [Fix] Increased padding */
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Header */
.navbar {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
    text-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

.status-badge {
    padding: 4px 12px;
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.5);
    border-radius: 20px;
    color: #34d399;
    /* Emerald */
    font-size: 0.85rem;
    font-weight: 600;
}

/* Host List Cards - Redesigned for Readability */
.host-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    transition: transform 0.2s, border-color 0.2s;
    margin-bottom: 12px;
}

.host-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    background: #3e4c63;
}

.host-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
}

.host-name {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--text-main);
}

/* Metrics Grid - New for V1.5 (Tabular Avg view) */
.metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.metric-item {
    background: rgba(0, 0, 0, 0.2);
    padding: 8px;
    border-radius: 6px;
    text-align: center;
}

.metric-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-sub);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.metric-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
}

.metric-unit {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Buttons */
.btn-neon {
    background: var(--bg-dark);
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 6px 14px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-neon:hover {
    background: var(--primary);
    color: var(--bg-dark);
}

/* Network Viz */
#network-viz {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    background: #0b1120;
    /* Darker bg for map contrast */
    border: 1px solid var(--border-color);
    overflow: hidden;
    /* [V12.1] Prevent labels from overlapping other sections */
    position: relative;
}

/* Modal */
.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--border-highlight);
    color: var(--text-main);
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
}

.btn-close {
    filter: invert(1);
    opacity: 0.8;
}

/* Text Utilities */
.text-muted {
    color: var(--text-muted) !important;
}

.text-light {
    color: var(--text-sub) !important;
}

.text-accent {
    color: var(--accent) !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: #94a3b8;
    /* Brighter thumb */
    border-radius: 5px;
    border: 2px solid var(--bg-dark);
}

/* [V9.5] Print Styling for PDF */
@media print {
    body {
        visibility: hidden;
        overflow: visible !important;
        height: auto !important;
        background: white !important;
    }

    nav,
    .app-container {
        display: none !important;
    }

    #aiModal {
        visibility: visible !important;
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: auto;
        overflow: visible !important;
        background: white !important;
    }

    #aiModal .modal-dialog {
        margin: 0;
        width: 100%;
        max-width: 100%;
    }

    #aiModal .modal-content {
        border: none;
        box-shadow: none;
    }

    #aiModal .modal-body {
        padding: 0;
        overflow: visible !important;
    }

    #aiModal * {
        visibility: visible !important;
        color: black !important;
        text-shadow: none !important;
    }

    /* Hide UI Elements */
    .btn-close,
    .action-container {
        display: none !important;
    }

    /* Ensure Graphics Render */
    canvas,
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    ::-webkit-scrollbar {
        display: none;
    }

    /* Layout Fixes */
    h1,
    h2,
    h3,
    h4 {
        border-bottom: 1px solid #ddd;
        padding-bottom: 10px;
        margin-top: 20px;
    }

    pre {
        border: 1px solid #ddd;
        background: #f8f8f8 !important;
        padding: 10px;
        white-space: pre-wrap;
    }

    code {
        color: #d63384 !important;
        background: #f4f4f4 !important;
    }
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-highlight);
}

/* [V11.0] Mobile/Tablet Responsiveness */
/* [V11.0] Mobile/Tablet Responsiveness (Full Overhaul) */
@media (max-width: 900px) {
    body {
        height: auto;
        overflow-y: auto;
    }

    /* 1. Full Width Container - Remove all padding */
    .app-container {
        display: flex !important;
        flex-direction: column;
        height: auto !important;
        overflow: visible;
        padding: 0 !important;
        gap: 0 !important;
    }

    /* 2. Topology Map (Top) - Full Width */
    .main-content {
        order: 1;
        flex: none;
        width: 100%;
        height: 60vh;
        /* Adjust height relative to viewport */
        min-height: 500px;
        border-radius: 0;
        border: none;
        border-bottom: 5px solid var(--bg-dark);
        /* Visual separation */
    }

    /* Stack Controls in Header */
    .topology-header {
        flex-direction: column;
        height: auto !important;
        padding: 15px !important;
        gap: 15px;
        background: var(--bg-panel);
    }

    .topology-header>div {
        width: 100%;
        justify-content: space-between;
    }

    .topology-header h4 {
        margin-bottom: 0;
    }

    /* [V12.1] Prevent button text wrapping */
    .btn-group .btn {
        white-space: nowrap;
        min-width: fit-content;
        padding: 8px 12px;
    }

    /* 3. Agent List (Bottom) - Grid Layout */
    .sidebar {
        order: 2;
        flex: none !important;
        width: 100% !important;
        height: auto !important;
        padding: 10px;
        background: var(--bg-dark);
        margin: 0 !important;
    }

    #agent-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        /* 2 Columns Grid */
        gap: 10px;
        padding-right: 0 !important;
        overflow: visible !important;
    }

    /* Hide unnecessary mobile elements */
    #agent-list::-webkit-scrollbar {
        display: none;
    }

    /* [V11.1] Universal Mobile & Tablet Optimization (< 768px) */
    @media (max-width: 768px) {

        /* Stack Header Elements nicely */
        .d-flex.justify-content-between.align-items-center.mb-2 {
            flex-direction: column;
            align-items: stretch !important;
            gap: 12px;
        }

        /* Wrap Button Group */
        .d-flex.align-items-center.gap-2 {
            flex-wrap: wrap;
            width: 100%;
            justify-content: space-between;
        }

        .btn-group {
            flex: 1 1 auto;
            display: flex;
            min-width: 200px;
        }

        .btn-group .btn {
            flex: 1;
            padding: 10px 8px;
        }

        /* Adjust Select and Buttons for touch */
        #topology-days,
        .btn-sm,
        #btn-cluster {
            font-size: 0.85rem !important;
            padding: 8px 12px;
            min-height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        /* Full width buttons on mobile row */
        #btn-cluster,
        .btn-neon,
        #topology-days {
            flex: 1 1 auto;
        }

        /* Sidebar - Adaptive Grid */
        #agent-list {
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) !important;
        }

        /* Map Height Adjustment */
        .main-content {
            height: 50vh;
            min-height: 400px;
        }
    }

    /* [V11.2] Small Smartphones (≤ 480px) */
    @media (max-width: 480px) {

        /* Increase touch target sizes */
        .btn,
        .btn-sm,
        .btn-neon {
            min-height: 44px !important;
            padding: 10px 16px !important;
            font-size: 0.9rem !important;
        }

        /* Host card optimization */
        .host-card {
            padding: 12px;
        }

        .host-name {
            font-size: 1rem !important;
        }

        /* Badge spacing */
        .badge {
            font-size: 0.7rem;
            padding: 4px 8px;
        }

        /* Metric grid - stack on very small screens */
        .metric-grid {
            grid-template-columns: 1fr 1fr;
            gap: 6px;
        }

        /* Navbar brand size */
        .brand {
            font-size: 1.2rem;
        }

        /* Status badge */
        .status-badge {
            font-size: 0.75rem;
            padding: 3px 10px;
        }

        /* Simple topology cards */
        #simple-topology-view .glass-panel {
            padding: 10px !important;
        }

        #simple-topology-view .fw-bold {
            font-size: 0.95rem;
        }

        #simple-topology-view .badge {
            font-size: 0.65rem;
            padding: 3px 6px;
        }
    }

    /* [V11.3] Very Small Screens (≤ 375px) - iPhone SE, etc */
    @media (max-width: 375px) {

        /* Further reduce padding */
        .app-container {
            padding: 0 !important;
        }

        .navbar {
            padding: 10px 15px;
            flex-wrap: wrap;
            gap: 8px;
        }

        .brand {
            font-size: 1.1rem;
        }

        /* Stack navbar items */
        .navbar>div {
            width: 100%;
            justify-content: space-between;
        }

        /* Host card compact */
        .host-card {
            padding: 10px;
            margin-bottom: 8px;
        }

        .host-header {
            flex-direction: column;
            align-items: flex-start !important;
            gap: 8px;
        }

        .host-name {
            font-size: 0.95rem !important;
        }

        /* Single column metric grid */
        .metric-grid {
            grid-template-columns: 1fr;
        }

        /* Agent list single column */
        #agent-list {
            grid-template-columns: 1fr !important;
        }

        /* Buttons full width */
        .btn-group {
            width: 100%;
        }

        .btn-group .btn {
            font-size: 0.75rem;
            padding: 8px 6px;
        }

        /* Reduce icon sizes */
        #simple-topology-view img {
            width: 24px !important;
            height: 24px !important;
        }

        /* Compact text */
        .text-muted.small {
            font-size: 0.7rem !important;
        }
    }

    /* [V11.4] Landscape Mode Optimization */
    @media (max-height: 500px) and (orientation: landscape) {

        /* Reduce vertical spacing in landscape */
        .navbar {
            padding: 8px 15px;
        }

        .app-container {
            padding: 10px;
            gap: 10px;
        }

        .host-card {
            margin-bottom: 6px;
            padding: 8px;
        }

        .main-content {
            height: 70vh;
            min-height: 300px;
        }

        /* Compact headers */
        h3,
        h4,
        h5 {
            font-size: 0.95rem !important;
            margin-bottom: 6px !important;
        }

        /* Reduce modal padding */
        .modal-body {
            padding: 15px;
        }

        /* Compact metric items */
        .metric-item {
            padding: 6px;
        }

        /* [V12.1] Fix button wrapping in landscape */
        .btn-group {
            flex-wrap: nowrap;
        }

        .btn-group .btn {
            font-size: 0.7rem !important;
            padding: 6px 8px !important;
            white-space: nowrap;
        }

        /* Compact select and buttons */
        #topology-days {
            font-size: 0.7rem !important;
            padding: 4px 8px !important;
        }

        #btn-cluster {
            font-size: 0.65rem !important;
            padding: 6px 8px !important;
        }
    }

    /* [V11.5] Safe Area Support (iOS Notch, etc) */
    @supports (padding: max(0px)) {
        body {
            padding-left: max(0px, env(safe-area-inset-left));
            padding-right: max(0px, env(safe-area-inset-right));
        }

        .navbar {
            padding-left: max(15px, env(safe-area-inset-left));
            padding-right: max(15px, env(safe-area-inset-right));
        }

        .app-container {
            padding-left: max(15px, env(safe-area-inset-left));
            padding-right: max(15px, env(safe-area-inset-right));
            padding-bottom: max(15px, env(safe-area-inset-bottom));
        }
    }

    /* [V11.6] Touch-friendly Improvements */
    @media (hover: none) and (pointer: coarse) {

        /* Increase tap targets */
        a,
        button,
        .host-header {
            min-height: 44px;
            display: flex;
            align-items: center;
        }

        /* Remove hover effects on touch devices */
        .host-card:hover {
            transform: none;
        }

        /* Larger scrollbar for touch */
        ::-webkit-scrollbar {
            width: 12px;
        }

        ::-webkit-scrollbar-thumb {
            border-radius: 6px;
        }
    }
}