/* ==========================================================================
   DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
  --font-family: 'Outfit', sans-serif;
  
  /* Color Palette (Deep dark theme with bright neon accents) */
  --bg-primary: #0a0d14;
  --bg-secondary: #111625;
  --bg-tertiary: #1b233a;
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  
  --accent-cyan: #06b6d4;
  --accent-blue: #3b82f6;
  
  --status-online: #10b981;
  --status-offline: #ef4444;
  --status-online-glow: rgba(16, 185, 129, 0.2);
  --status-offline-glow: rgba(239, 68, 68, 0.2);
  
  --glass-bg: rgba(17, 22, 37, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: rgba(0, 0, 0, 0.3);
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --border-radius-sm: 8px;
  --border-radius-md: 12px;
  --border-radius-lg: 20px;
}

/* ==========================================================================
   RESET & GLOBAL STYLES
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: var(--font-family);
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

/* Scrollbar styles */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: #3b4b72;
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-cyan);
}

/* ==========================================================================
   LAYOUT STRUCTURE
   ========================================================================== */
.app-container {
  display: grid;
  grid-template-rows: 70px 1fr;
  grid-template-columns: 360px 1fr;
  grid-template-areas: 
    "header header"
    "sidebar map";
  height: 100vh;
  width: 100vw;
}

/* ==========================================================================
   HEADER SECTION
   ========================================================================== */
.app-header {
  grid-area: header;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 24px;
  color: var(--accent-cyan);
  text-shadow: 0 0 10px rgba(6, 182, 212, 0.4);
}

.header-logo h1 {
  font-size: 20px;
  font-weight: 600;
}

.header-logo h1 span {
  color: var(--accent-cyan);
}

.header-search {
  position: relative;
  width: 400px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

#search-input {
  width: 100%;
  padding: 10px 16px 10px 48px;
  background: var(--bg-primary);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-lg);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: var(--transition-smooth);
}

#search-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.2);
}

.btn-action {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  padding: 10px 20px;
  border-radius: var(--border-radius-md);
  color: var(--text-main);
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition-smooth);
}

.btn-action:hover {
  background: var(--accent-cyan);
  color: var(--bg-primary);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.4);
}

/* ==========================================================================
   SIDEBAR SECTION
   ========================================================================== */
.app-sidebar {
  grid-area: sidebar;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--glass-border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: calc(100vh - 70px);
  overflow: hidden;
  z-index: 990;
}

.sidebar-section {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  padding: 16px;
}

.sidebar-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* KPIs cards */
.kpi-section {
  padding: 0;
  background: none;
  border: none;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.kpi-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  padding: 12px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.kpi-icon {
  font-size: 16px;
}

.kpi-card.online .kpi-icon { color: var(--status-online); }
.kpi-card.offline .kpi-icon { color: var(--status-offline); }
.kpi-card.clients .kpi-icon { color: var(--accent-blue); }

.kpi-value {
  font-size: 18px;
  font-weight: 700;
  display: block;
}

.kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Frequency saturation bar chart */
.channels-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 120px;
  overflow-y: auto;
}

.channel-bar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.channel-label {
  width: 70px;
  font-weight: 500;
}

.channel-bar-wrapper {
  flex-grow: 1;
  background: var(--bg-primary);
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
}

.channel-bar-fill {
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
  height: 100%;
  border-radius: 4px;
  transition: width 0.8s ease-in-out;
}

.channel-count {
  width: 24px;
  text-align: right;
  color: var(--text-muted);
  font-weight: 600;
}

/* Groups/Regions Tree Accordion */
.groups-section {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.groups-accordion {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

.group-item {
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  background: var(--glass-bg);
  overflow: hidden;
  transition: var(--transition-smooth);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.group-item:hover {
  border-color: rgba(6, 182, 212, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(6, 182, 212, 0.1);
}

.group-header {
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.group-title-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.group-title {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff !important;
  letter-spacing: 0.5px;
}

.group-meta-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  width: 100%;
  margin-top: 2px;
}

.group-health-bar-container {
  width: 100%;
  background: var(--bg-primary);
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.group-health-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s ease;
}

.group-arrow {
  font-size: 11px;
  transition: transform 0.3s ease;
  color: var(--text-muted);
}

.group-item.open .group-arrow {
  transform: rotate(90deg);
  color: var(--accent-cyan);
}

.group-content {
  display: none;
  background: rgba(0, 0, 0, 0.25);
  border-top: 1px solid var(--glass-border);
  padding: 8px;
}

.group-item.open .group-content {
  display: block;
}

/* Device items list */
.device-item {
  padding: 8px 10px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.device-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.device-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.device-name {
  font-weight: 500;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-sub {
  font-size: 10px;
  color: var(--text-muted);
}

.device-meta {
  text-align: right;
}

.device-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
}

.device-status.online {
  background: var(--status-online);
  box-shadow: 0 0 8px var(--status-online);
}

.device-status.offline {
  background: var(--status-offline);
  box-shadow: 0 0 8px var(--status-offline);
}

/* ==========================================================================
   MAP CONTAINER & CANVAS
   ========================================================================== */
.app-map-container {
  grid-area: map;
  width: 100%;
  height: calc(100vh - 70px);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 55%;
  flex-shrink: 0;
}

/* Google Maps Custom Markers styles */
.custom-google-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: transform 0.2s ease-in-out;
}

.custom-google-marker:hover {
  transform: scale(1.3);
}

.custom-google-marker.online {
  background-color: var(--status-online);
  box-shadow: 0 0 12px var(--status-online);
}

.custom-google-marker.offline {
  background-color: var(--status-offline);
  box-shadow: 0 0 12px var(--status-offline);
}



/* Google Maps InfoWindow overrides to match our premium dark theme */
.gm-style .gm-style-iw-c {
  background-color: var(--bg-secondary) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: var(--border-radius-md) !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5) !important;
  padding: 12px !important;
}

.gm-style .gm-style-iw-t::after {
  background: var(--bg-secondary) !important;
}

.gm-style .gm-style-iw-d {
  overflow: auto !important;
  max-height: none !important;
  color: var(--text-main) !important;
}

.gm-ui-hover-close {
  filter: invert(1) !important;
}

.popup-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: var(--font-family);
  min-width: 180px;
}

.popup-details h4 {
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 4px;
  margin-bottom: 4px;
  color: var(--accent-cyan);
}

.popup-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}

.popup-row span:first-child {
  color: var(--text-muted);
}

.popup-row span:last-child {
  font-weight: 500;
}

/* ==========================================================================
   LOADING OVERLAY & SPINNER
   ========================================================================== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 13, 20, 0.85);
  backdrop-filter: blur(12px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.loading-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.loading-spinner {
  text-align: center;
}

.loading-spinner i {
  font-size: 50px;
  color: var(--accent-cyan);
  margin-bottom: 20px;
  text-shadow: 0 0 20px rgba(6, 182, 212, 0.5);
}

.loading-spinner p {
  font-size: 16px;
  color: var(--text-main);
  font-weight: 500;
}

/* ==========================================================================
   RESPONSIVE DESIGN (Adaptive drawer layout)
   ========================================================================== */
@media (max-width: 768px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-areas: 
      "header"
      "map";
  }

  .app-sidebar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40vh;
    border-right: none;
    border-top: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.5);
    z-index: 1001;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .app-sidebar.active {
    transform: translateY(0);
  }
}

.custom-tooltip {
  background-color: rgba(17, 22, 37, 0.9) !important;
  border: 1px solid var(--glass-border) !important;
  color: var(--text-main) !important;
  border-radius: 4px !important;
  font-size: 10px !important;
  font-weight: 500 !important;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4) !important;
  padding: 4px 8px !important;
}

.custom-tooltip::before {
  border-top-color: rgba(17, 22, 37, 0.9) !important;
}

/* ==========================================================================
   SPECTRUM & SECTORIAL DETAILS PANEL (BOTTOM RIGHT)
   ========================================================================== */
.spectrum-panel {
  flex-grow: 1;
  height: 45%;
  background: var(--bg-secondary);
  border-top: 1px solid var(--glass-border);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25);
  z-index: 900;
}

.spectrum-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 12px;
  text-align: center;
}

.spectrum-placeholder i {
  font-size: 32px;
  color: var(--accent-cyan);
  text-shadow: 0 0 10px rgba(6, 182, 212, 0.3);
}

.spectrum-placeholder p {
  font-size: 14px;
  font-weight: 500;
  max-width: 400px;
}

/* Active panel layout */
.spectrum-active-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 12px;
}

.spectrum-active-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.spectrum-active-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-cyan);
}

.spectrum-active-header .header-stats {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 14px;
}

.spectrum-active-header .header-stats span strong {
  color: var(--text-main);
}

/* Grid layout for sectorials list */
.sectorials-table-wrapper {
  flex-grow: 1;
  overflow-y: auto;
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-sm);
  background: rgba(0,0,0,0.15);
}

.sectorials-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  text-align: left;
}

.sectorials-table th {
  background: var(--bg-tertiary);
  padding: 8px 12px;
  font-weight: 600;
  color: var(--accent-cyan);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--glass-border);
}

.sectorials-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  color: var(--text-main);
  white-space: nowrap;
}

.sectorials-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.sectorials-table tr:last-child td {
  border-bottom: none;
}

/* Graphical Spectrum Analyzer timeline styling */
.spectrum-analyzer-container {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.spectrum-axis {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 500;
  padding: 0 4px;
  user-select: none;
}

.spectrum-bar-wrapper {
  position: relative;
  background: linear-gradient(180deg, #182030 0%, #101520 100%);
  height: 42px;
  border-radius: var(--border-radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.5);
}

/* Background grid ticks for every 100 MHz */
.spectrum-bar-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.spectrum-grid-tick {
  width: 1px;
  height: 100%;
  background: rgba(255, 255, 255, 0.04);
}

/* Dynamic channel blocks */
.spectrum-channel-block {
  position: absolute;
  top: 4px;
  height: 34px;
  background: rgba(6, 182, 212, 0.25);
  border: 1px solid var(--accent-cyan);
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.15);
  cursor: pointer;
  transition: var(--transition-smooth);
  display: flex;
  align-items: center;
  justify-content: center;
}

.spectrum-channel-block:hover {
  background: rgba(6, 182, 212, 0.4);
  box-shadow: 0 0 14px rgba(6, 182, 212, 0.35);
  border-color: #ffffff;
  z-index: 100;
}

.spectrum-axis-bottom {
  position: relative;
  height: 16px;
  width: 100%;
}

.spectrum-center-freq-label {
  position: absolute;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-cyan);
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  pointer-events: none;
}

