/* =================================================================
   GRAPH TAB SYSTEM - Multi-Panel Dashboard Controls
   ================================================================= */

/* Chart header layout */
.chart-header {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 0;
    flex-shrink: 0;
}

/* Auto-rotate toggle (top-right) */
.chart-controls {
    position: relative;
    top: auto;
    right: auto;
    z-index: 10;
    display: flex;
    align-items: flex-end;
    padding-bottom: 12px;
}

.auto-rotate-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: #948a67;
    cursor: pointer;
    user-select: none;
    transition: color 0.3s ease;
}

.auto-rotate-toggle:hover {
    color: #ffffff;
}

.auto-rotate-toggle input {
    display: none;
}

.toggle-slider {
    width: 36px;
    height: 20px;
    background: rgba(148, 138, 103, 0.3);
    border-radius: 20px;
    position: relative;
    transition: background 0.3s ease;
    border: 1px solid rgba(148, 138, 103, 0.5);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #948a67;
    top: 1px;
    left: 2px;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.auto-rotate-toggle input:checked + .toggle-slider {
    background: rgba(148, 138, 103, 0.6);
}

.auto-rotate-toggle input:checked + .toggle-slider::before {
    transform: translateX(16px);
    background: #ffffff;
}

.toggle-label {
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Graph tabs container */
.graph-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1;
    overflow: visible;
}

/* Chart time range selector in chart area */
.chart-time-range {
    position: absolute;
    bottom: 5px;
    right: 15px;
    z-index: 150;
    font-family: 'Barlow', sans-serif;
    font-size: 0.75rem;
    color: rgba(148, 138, 103, 0.9);
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid rgba(148, 138, 103, 0.2);
    border-radius: 4px;
    padding: 6px 10px;
    backdrop-filter: blur(8px);
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.chart-time-range:hover {
    background: rgba(26, 26, 26, 0.9);
    border-color: rgba(148, 138, 103, 0.5);
    color: #948a67;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.chart-time-range .range-text {
    font-weight: 500;
    opacity: 0.8;
}

.chart-time-range .range-value {
    color: #948a67;
    font-weight: 700;
}

.time-range-dropdown {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 4px;
    background: rgba(0, 0, 0, 0.95);
    border: 1px solid rgba(148, 138, 103, 0.3);
    border-radius: 6px;
    padding: 6px;
    min-width: 120px;
    max-width: 140px;
    z-index: 200;
    display: none;
    backdrop-filter: blur(15px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    max-height: 200px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 138, 103, 0.3) transparent;
}

.time-range-dropdown::-webkit-scrollbar {
    width: 6px;
}

.time-range-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.time-range-dropdown::-webkit-scrollbar-thumb {
    background: rgba(148, 138, 103, 0.3);
    border-radius: 3px;
}

.time-range-dropdown.show {
    display: block;
    animation: dropdownFade 0.2s ease-out;
}

@keyframes dropdownFade {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.time-range-option {
    display: block;
    width: 100%;
    padding: 6px 8px;
    background: transparent;
    border: none;
    color: rgba(148, 138, 103, 0.7);
    font-family: 'Barlow', sans-serif;
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.15s ease;
    text-align: left;
    white-space: nowrap;
}

.time-range-option:hover {
    background: rgba(148, 138, 103, 0.15);
    color: #948a67;
}

.time-range-option.selected {
    background: rgba(148, 138, 103, 0.25);
    color: #948a67;
    font-weight: 700;
}

/* Clean tactical tab system */
.folder {
    margin: 0;
    width: 100%;
    position: relative;
    margin-bottom: -1px; /* Connect to chart container */
}

.tabs {
    padding: 0;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    -ms-overflow-style: none;
    display: flex;
    gap: 4px;
}

.tabs::-webkit-scrollbar {
    background: transparent;
    display: none;
}

.tab {
    font-family: 'Barlow', 'Inter', 'Segoe UI', sans-serif;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(26, 26, 26, 0.6);
    border: 1px solid rgba(148, 138, 103, 0.2);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    padding: 12px 24px 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
    white-space: nowrap;
    min-width: fit-content;
}

.tab:hover {
    background: rgba(148, 138, 103, 0.1);
    border-color: rgba(148, 138, 103, 0.4);
    border-bottom: none;
}

.tab span {
    font-size: 0.75rem;
    color: rgba(148, 138, 103, 0.8);
    transition: color 0.3s ease;
}

.tab:hover span {
    color: #948a67;
}

.tab.active {
    background: #1a1a1a;
    border-color: rgba(148, 138, 103, 0.2);
    border-bottom: 1px solid #1a1a1a;
    border-left: 1px solid rgba(148, 138, 103, 0.2);
    border-right: 1px solid rgba(148, 138, 103, 0.2);
    border-top: 1px solid rgba(148, 138, 103, 0.2);
    z-index: 50;
    margin-bottom: -1px;
    padding-bottom: 9px;
}

.tab.active span {
    color: #948a67;
    font-weight: 700;
    text-shadow: 0 0 4px rgba(148, 138, 103, 0.3);
}

/* Tab overflow system (legacy) */
.tabs-wrapper {
    display: flex;
    width: 100%;
    overflow: hidden;
}

.tabs-scroller {
    display: flex;
    gap: 8px;
    align-items: center;
    width: 100%;
}

.graph-tab-overflow {
    position: relative;
    display: inline-block;
}

.overflow-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: rgba(26, 26, 26, 0.95);
    border: 1px solid rgba(148, 138, 103, 0.3);
    border-radius: 8px;
    padding: 8px;
    margin-top: 8px;
    min-width: 200px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.overflow-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.overflow-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: rgba(148, 138, 103, 0.7);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    text-align: left;
}

.overflow-tab:hover {
    background: rgba(148, 138, 103, 0.1);
    color: #948a67;
    transform: translateX(4px);
}

.overflow-tab i {
    width: 16px;
    font-size: 0.9rem;
}

.overflow-tab span {
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.graph-tab {
    font-family: 'Barlow', 'Inter', 'Segoe UI', sans-serif;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(26, 26, 26, 0.6);
    border: 1px solid rgba(148, 138, 103, 0.2);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    padding: 12px 24px 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
    white-space: nowrap;
    min-width: fit-content;
    gap: 6px;
    font-size: 0.75rem;
    color: rgba(148, 138, 103, 0.8);
}

.graph-tab:hover {
    background: rgba(148, 138, 103, 0.1);
    border-color: rgba(148, 138, 103, 0.4);
    border-bottom: none;
    color: #948a67;
}

.graph-tab.active {
    background: #1a1a1a;
    border-color: rgba(148, 138, 103, 0.2);
    border-bottom: 1px solid #1a1a1a;
    border-left: 1px solid rgba(148, 138, 103, 0.2);
    border-right: 1px solid rgba(148, 138, 103, 0.2);
    border-top: 1px solid rgba(148, 138, 103, 0.2);
    z-index: 50;
    color: #948a67;
    font-weight: 700;
    text-shadow: 0 0 4px rgba(148, 138, 103, 0.3);
    margin-bottom: -1px;
    padding-bottom: 11px;
}

.graph-tab i {
    font-size: 0.9rem;
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.3));
}

.graph-tab.rotating {
    animation: tabRotate 0.3s ease;
}

@keyframes tabRotate {
    0%, 100% { transform: translateY(-2px) scale(1); }
    50% { transform: translateY(-2px) scale(1.05); }
}

/* Chart container */
.chart-container {
    flex: 1;
    border-radius: 8px 0 20px 20px;
    overflow: hidden;
    background: #1a1a1a;
    border: 1px solid rgba(148, 138, 103, 0.2);
    position: relative;
    min-height: 600px;
    height: 100%;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 10px;
    box-sizing: border-box;
}

.chart-container .grafana-chart {
    width: 100% !important;
    height: 100% !important;
    border: none;
    border-radius: 8px;
    background: transparent;
    transition: opacity 0.3s ease;
    display: block;
    transform: none !important;
    margin: 0;
    padding: 0;
}

/* Chart loading indicator */
.chart-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #948a67;
    font-size: 0.9rem;
    z-index: 5;
    font-family: 'Barlow', sans-serif;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.chart-loading.show {
    display: flex;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(148, 138, 103, 0.3);
    border-top: 3px solid #948a67;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Auto-rotate animation */
.auto-rotating .graph-tab.active {
    animation: autoRotatePulse 2s ease-in-out;
}

@keyframes autoRotatePulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(148, 138, 103, 0.3); }
    50% { box-shadow: 0 4px 16px rgba(148, 138, 103, 0.5); }
}

/* Mobile responsive */
@media (max-width: 768px) {
    .graph-tabs {
        max-width: calc(100% - 100px);
    }
    
    .graph-tab {
        padding: 6px 8px;
        font-size: 0.7rem;
    }
    
    .graph-tab span {
        display: none;
    }
    
    .toggle-label {
        display: none;
    }
    
    .chart-controls {
        top: -5px;
        right: -5px;
    }
}

/* Enhanced mobile touch support */
@media (max-width: 480px) {
    .graph-tabs {
        flex-wrap: wrap;
        gap: 0.25rem;
        max-width: 100%;
        padding: 0.25rem;
    }

    .graph-tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.7rem;
        min-height: 36px;
        flex: 1 1 auto;
        white-space: nowrap;
    }

    .chart-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }

    .chart-controls {
        position: static;
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .auto-rotate-toggle {
        width: 100%;
        justify-content: center;
    }

    .chart-time-range {
        right: 0.5rem;
        top: 0.5rem;
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }

    .time-range-dropdown {
        right: 0;
        min-width: 120px;
    }

    .time-range-option {
        padding: 0.5rem;
        font-size: 0.75rem;
    }
}

/* Tablet portrait optimizations */
@media (min-width: 481px) and (max-width: 767px) {
    .graph-tab {
        padding: 0.65rem 1rem;
        font-size: 0.8rem;
        min-height: 40px;
    }

    .chart-time-range {
        font-size: 0.8rem;
    }
}

/* Touch-specific improvements */
@media (hover: none) and (pointer: coarse) {
    .graph-tab {
        min-height: 44px;
        -webkit-tap-highlight-color: rgba(148, 138, 103, 0.2);
    }

    .graph-tab:active {
        transform: scale(0.98);
        background: rgba(148, 138, 103, 0.3);
    }

    .time-range-option:active {
        transform: scale(0.98);
        background: rgba(148, 138, 103, 0.4);
    }

    /* Prevent text selection on touch */
    .graph-tab,
    .time-range-option,
    .auto-rotate-toggle {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }

    /* Better touch scroll for dropdown */
    .time-range-dropdown {
        -webkit-overflow-scrolling: touch;
        max-height: 60vh;
        overflow-y: auto;
    }
}