/* ============================================================
   EAST SOLUTIONS SCADA — COMPONENT STYLES
   ============================================================ */

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: width var(--transition-med);
  overflow: hidden;
}

/* Mobile sidebar — overlay drawer */
@media (max-width: 900px) {
  .sidebar {
    width: 280px !important;
    z-index: 1001;
    transform: translateX(-100%);
    transition: transform var(--transition-med);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.mobile-open {
    transform: translateX(0) !important;
  }

  .sidebar.collapsed {
    width: 280px !important;
  }

  .sidebar.collapsed .sidebar-section-label {
    opacity: 1;
  }

  .sidebar.collapsed .nav-label {
    display: inline;
  }

  .sidebar.collapsed .sidebar-logo-text {
    display: flex;
  }
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-logo-mark {
  width: 44px; height: 44px;
  background: var(--brand-orange);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}

img.sidebar-logo-mark {
  background: none;
  border-radius: 0;
  object-fit: contain;
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-logo-name {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.sidebar-logo-sub {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--brand-orange);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 0;
}

.sidebar-section {
  margin-bottom: 4px;
}

.sidebar-section-label {
  font-size: 0.5625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  padding: 8px 20px 4px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--transition-med);
}

.sidebar.collapsed .sidebar-section-label {
  opacity: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  margin: 1px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(232,98,10,0.15);
  color: var(--brand-orange);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--brand-orange);
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  width: 20px; height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.nav-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-badge {
  background: var(--status-critical);
  color: #fff;
  font-size: 0.5625rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border-primary);
  flex-shrink: 0;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 8px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid var(--border-primary);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.875rem;
}

.sidebar-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-secondary);
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  transition: left var(--transition-med);
}

.topbar.sidebar-collapsed {
  left: var(--sidebar-collapsed);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Site selector */
.site-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.8125rem;
  color: var(--text-primary);
  min-width: 180px;
}

.site-selector:hover {
  border-color: var(--brand-orange);
  color: var(--brand-orange);
}

/* Search */
.topbar-search {
  position: relative;
  flex: 1;
  max-width: 360px;
}

.topbar-search input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 7px 12px 7px 36px;
  font-size: 0.8125rem;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.topbar-search input:focus {
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px rgba(232,98,10,0.1);
}

.topbar-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.875rem;
  pointer-events: none;
}

/* Topbar icon buttons */
.topbar-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition-fast);
  position: relative;
}

.topbar-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-primary);
  color: var(--text-primary);
}

.topbar-btn .alarm-count {
  position: absolute;
  top: 4px; right: 4px;
  width: 16px; height: 16px;
  background: var(--status-critical);
  color: #fff;
  font-size: 0.5rem;
  font-weight: 700;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: blink 2s infinite;
}

/* User menu */
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.user-menu:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-primary);
}

.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--brand-orange);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.user-role {
  font-size: 0.625rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Dropdown */
.dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 500;
  animation: slideUp 0.2s ease;
  overflow: hidden;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.dropdown-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.dropdown-item.danger { color: var(--status-critical); }
.dropdown-item.danger:hover { background: rgba(239,68,68,0.1); }

.dropdown-divider {
  height: 1px;
  background: var(--border-primary);
  margin: 4px 0;
}

/* ============================================================
   ALARM BANNER
   ============================================================ */
.alarm-banner {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}

.alarm-banner-icon {
  font-size: 1.125rem;
  color: var(--status-critical);
  animation: blink 1.5s infinite;
  flex-shrink: 0;
}

.alarm-banner-text {
  flex: 1;
  font-size: 0.8125rem;
  color: var(--text-primary);
}

.alarm-banner-count {
  font-weight: 700;
  color: var(--status-critical);
}

/* ============================================================
   SITE CARDS
   ============================================================ */
.site-card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.site-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: var(--status-healthy);
  transform: scaleX(0);
  transition: transform var(--transition-fast);
}

.site-card:hover {
  border-color: var(--border-secondary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.site-card:hover::after { transform: scaleX(1); }
.site-card.warning::after { background: var(--status-warning); }
.site-card.critical::after { background: var(--status-critical); }
.site-card.offline::after { background: var(--status-offline); }

.site-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.site-card-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.site-card-location {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.site-card-kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-primary);
}

.site-kpi {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.site-kpi-label {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.site-kpi-value {
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.site-kpi-unit {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.site-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-primary);
  font-size: 0.6875rem;
  color: var(--text-muted);
}

/* ============================================================
   POWER FLOW DIAGRAM
   ============================================================ */
.power-flow {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  overflow-x: auto;
}

.pf-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 90px;
}

.pf-icon {
  width: 56px; height: 56px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  border: 2px solid;
  position: relative;
}

.pf-icon.grid    { background: rgba(59,130,246,0.1);  border-color: rgba(59,130,246,0.4);  color: #60A5FA; }
.pf-icon.solar   { background: rgba(245,158,11,0.1);  border-color: rgba(245,158,11,0.4);  color: #F59E0B; }
.pf-icon.battery { background: rgba(34,197,94,0.1);   border-color: rgba(34,197,94,0.4);   color: #22C55E; }
.pf-icon.gen     { background: rgba(168,85,247,0.1);  border-color: rgba(168,85,247,0.4);  color: #A855F7; }
.pf-icon.load    { background: rgba(232,98,10,0.1);   border-color: rgba(232,98,10,0.4);   color: var(--brand-orange); }
.pf-icon.tx      { background: rgba(96,165,250,0.1);  border-color: rgba(96,165,250,0.4);  color: #60A5FA; }

.pf-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-align: center;
}

.pf-value {
  font-size: 0.875rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  text-align: center;
}

.pf-arrow {
  display: flex;
  align-items: center;
  padding: 0 8px;
  color: var(--text-muted);
  font-size: 1.25rem;
  flex-shrink: 0;
}

.pf-arrow.active { color: var(--brand-orange); }
.pf-arrow.reverse { transform: scaleX(-1); }

/* ============================================================
   ASSET LIST
   ============================================================ */
.asset-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.asset-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.asset-item:hover {
  border-color: var(--border-secondary);
  background: var(--bg-card-hover);
}

.asset-item-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.asset-item-info { flex: 1; min-width: 0; }
.asset-item-name { font-size: 0.875rem; font-weight: 600; color: var(--text-primary); }
.asset-item-sub  { font-size: 0.75rem; color: var(--text-muted); }

/* Admin-only asset reorder / change-icon buttons (desktop only — see
   _renderAssetRow). Replaces former inline padding/font-size. */
.asset-reorder-btn {
  padding: 2px 6px;
  font-size: 0.75rem;
}
.asset-icon-btn {
  padding: 2px 6px;
  font-size: 0.875rem;
}

.asset-item-values {
  display: flex;
  gap: 16px;
  align-items: center;
}

.asset-value {
  text-align: right;
}

.asset-value-num {
  font-size: 0.875rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.asset-value-unit {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

/* ============================================================
   ALARM TABLE ROWS
   ============================================================ */
.alarm-row-critical td:first-child {
  border-left: 3px solid var(--status-critical);
}
.alarm-row-warning td:first-child {
  border-left: 3px solid var(--status-warning);
}
.alarm-row-advisory td:first-child {
  border-left: 3px solid var(--status-advisory);
}

.alarm-unack {
  background: rgba(239,68,68,0.04);
}

/* Recent-alarms description cell: single-line ellipsis on desktop.
   On mobile the .table-cards / .cell-primary rules let it wrap full-width. */
.alarm-desc-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* On mobile, the engineer must read the full alarm text without drilling in,
   so explicitly lift every truncation constraint at phone widths. */
@media (max-width: 600px) {
  .alarm-desc-cell {
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    word-break: break-word;
  }
}

/* ============================================================
   ALARMS PAGE — MOBILE CARD VIEW
   The alarms table uses the shared .table-cards pattern. These rules adapt the
   alarm-specific cells (severity bar, empty state, actions) for card mode and
   size the acknowledge action for touch.
   ============================================================ */

/* Filter bar: flex row on desktop (preserves the original inline layout). */
.alarm-filters {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.alarm-filter-search {
  flex: 1;
  min-width: 200px;
  position: relative;
}
.alarm-filter-site {
  width: 180px;
}

@media (max-width: 600px) {
  /* Stack the filters and let each control take the full width for easy use. */
  .alarm-filters {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .alarm-filter-search {
    min-width: 0;
    width: 100%;
  }
  .alarm-filter-site {
    width: 100%;
  }
  .alarm-filter-tabs {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 600px) {
  /* Summary KPI tiles stay 2-up rather than one tall column. */
  #alarms-summary.grid-4 {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  /* The thin 4px severity colour bar makes no sense as a stacked card row —
     hide it and instead colour the whole card's left border by severity. */
  .table-cards .alarm-sev-bar {
    display: none;
  }

  .alarm-card {
    border-left-width: 4px !important;
  }
  .alarm-card-critical { border-left-color: var(--status-critical) !important; }
  .alarm-card-warning  { border-left-color: var(--status-warning) !important; }
  .alarm-card-advisory { border-left-color: var(--status-advisory) !important; }

  /* Unacknowledged alarms get a subtle tinted card so they stand out in the list. */
  .alarm-card.alarm-unack {
    background: rgba(239,68,68,0.06);
  }

  /* Empty-state row should not be turned into a card. */
  .table-cards tr.no-card {
    display: table-row;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
  }
  .table-cards tr.no-card td {
    display: table-cell;
    border: none;
  }
  .table-cards tr.no-card td::before { content: none; }

  /* Actions cell: full-width, large ACK button so it's an easy, deliberate tap. */
  .table-cards .alarm-actions-cell {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
  }
  .table-cards .alarm-actions-cell::before {
    margin-bottom: 4px;
  }
  .alarm-actions {
    display: flex;
    gap: 10px;
    width: 100%;
  }
  .alarm-ack-btn {
    flex: 1;
    min-height: 46px;
    font-size: 0.9375rem;
    font-weight: 700;
  }
}

/* ============================================================
   CHART CONTAINERS
   ============================================================ */
.chart-container {
  position: relative;
  width: 100%;
}

.chart-canvas-wrapper {
  position: relative;
  width: 100%;
}

/* ============================================================
   COMMS STATUS INDICATORS
   ============================================================ */
.comms-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
}

.comms-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.comms-dot.online  { background: var(--status-healthy); box-shadow: 0 0 6px var(--status-healthy); }
.comms-dot.offline { background: var(--status-critical); }
.comms-dot.warning { background: var(--status-warning); }

/* ============================================================
   GATEWAY STATUS CARDS
   ============================================================ */
.gateway-card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.gateway-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.gateway-info { flex: 1; min-width: 0; }
.gateway-name { font-size: 0.8125rem; font-weight: 600; color: var(--text-primary); }
.gateway-ip   { font-size: 0.6875rem; font-family: var(--font-mono); color: var(--text-muted); }

/* ============================================================
   PERMISSION MATRIX
   ============================================================ */
.permission-matrix {
  overflow-x: auto;
}

.permission-matrix table th,
.permission-matrix table td {
  text-align: center;
  padding: 10px 12px;
}

.permission-matrix table th:first-child,
.permission-matrix table td:first-child {
  text-align: left;
}

.perm-check {
  width: 18px; height: 18px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.perm-check.granted {
  background: rgba(34,197,94,0.2);
  color: var(--status-healthy);
  border: 1px solid rgba(34,197,94,0.4);
}

.perm-check.denied {
  background: rgba(107,114,128,0.1);
  color: var(--text-muted);
  border: 1px solid var(--border-primary);
}

/* ============================================================
   TREND CHART CONTROLS
   ============================================================ */
.trend-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.time-range-btn {
  padding: 5px 12px;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.time-range-btn:hover { color: var(--text-primary); border-color: var(--border-secondary); }
.time-range-btn.active {
  background: var(--brand-orange);
  border-color: var(--brand-orange);
  color: #fff;
}

/* ============================================================
   SEARCH RESULTS DROPDOWN
   ============================================================ */
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 600;
  max-height: 320px;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

/* Mobile search overlay */
@media (max-width: 900px) {
  .search-results {
    position: fixed;
    top: 60px;
    left: 12px;
    right: 12px;
    z-index: 700;
  }
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: 0.8125rem;
}

.search-result-item:hover { background: var(--bg-tertiary); }

.search-result-icon {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.search-result-name { font-weight: 500; color: var(--text-primary); }
.search-result-path { font-size: 0.6875rem; color: var(--text-muted); }

/* ============================================================
   LIVE DATA PULSE
   ============================================================ */
.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--status-healthy);
}

.live-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--status-healthy);
  animation: pulse-dot 1.5s infinite;
}

/* ============================================================
   STAT ROW
   ============================================================ */
.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-primary);
  font-size: 0.8125rem;
}

.stat-row:last-child { border-bottom: none; }
.stat-row-label { color: var(--text-muted); }
.stat-row-value { font-weight: 600; font-family: var(--font-mono); color: var(--text-primary); }

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.progress-fill.green  { background: var(--status-healthy); }
.progress-fill.orange { background: var(--brand-orange); }
.progress-fill.yellow { background: var(--status-warning); }
.progress-fill.red    { background: var(--status-critical); }
.progress-fill.blue   { background: var(--status-advisory); }

/* ============================================================
   SECTION DIVIDER WITH LABEL
   ============================================================ */
.section-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 16px;
}

.section-divider-line {
  flex: 1;
  height: 1px;
  background: var(--border-primary);
}

.section-divider-label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ============================================================
   MOBILE RESPONSIVE — COMPONENT OVERRIDES
   ============================================================ */

/* Topbar mobile adjustments */
@media (max-width: 900px) {
  .topbar {
    left: 0 !important;
  }

  .topbar.sidebar-collapsed {
    left: 0 !important;
  }

  /* Dropdown positioning on mobile */
  .dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    min-width: unset;
    max-height: 60vh;
    overflow-y: auto;
    animation: slideUpMobile 0.2s ease;
  }

  .dropdown-item {
    padding: 14px 20px;
    font-size: 0.9375rem;
  }
}

@media (max-width: 600px) {
  /* Sidebar nav items larger touch targets */
  .nav-item {
    padding: 12px 16px;
    font-size: 0.875rem;
  }

  /* Site cards mobile */
  .site-card {
    padding: 14px;
  }

  .site-card-header {
    margin-bottom: 10px;
  }

  .site-card-name {
    font-size: 0.9375rem;
  }

  /* Gateway card layout stacking */
  .gateway-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* Power flow compact */
  .pf-node {
    min-width: 70px;
  }

  .pf-icon {
    width: 44px;
    height: 44px;
    font-size: 1.125rem;
  }

  .pf-label {
    font-size: 0.5625rem;
  }

  .pf-value {
    font-size: 0.75rem;
  }

  /* Trend controls wrap */
  .trend-controls {
    gap: 6px;
  }

  .time-range-btn {
    padding: 6px 10px;
    font-size: 0.6875rem;
  }

  /* Comms indicator */
  .comms-indicator {
    font-size: 0.6875rem;
  }

  /* Permission matrix scroll */
  .permission-matrix {
    -webkit-overflow-scrolling: touch;
  }

  /* Card header stacking */
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

/* Gateway card header — responsive */
.gw-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.gw-card-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .gw-card-header {
    flex-direction: column;
  }

  .gw-card-actions {
    width: 100%;
  }

  .gw-card-actions .btn {
    flex: 1;
  }
}

/* VPN peer rows — responsive */
@media (max-width: 600px) {
  /* VPN peer items stack on mobile */
  #vpn-peers-list > div {
    flex-wrap: wrap !important;
  }

  /* Entity discovery labels wrap */
  .device-entities label {
    flex-wrap: wrap;
  }

  .device-entities label > div:last-child {
    width: 100%;
    text-align: left !important;
    margin-top: 2px;
  }
}

/* Asset page 2-column layout — responsive */
.asset-page-grid {
  grid-template-columns: 1fr 340px;
  gap: 20px;
}

/* Site overview 2-column layout — responsive */
.site-overview-grid {
  grid-template-columns: 1fr 340px;
  gap: 20px;
}

@media (max-width: 900px) {
  .asset-page-grid,
  .site-overview-grid {
    grid-template-columns: 1fr !important;
  }

  /* Power flow diagram is fixed-layout (we don't reflow it). Let it scroll
     horizontally inside its card on smaller screens rather than squashing. */
  #power-flow-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 600px) {
  /* Keep the site-overview KPI live-value cards glanceable: 2-up grid instead
     of one tall column, regardless of how many KPIs are configured. These use
     grid-2..grid-5 depending on count, so override them all within the row. */
  #kpi-cards-row.grid-2,
  #kpi-cards-row.grid-3,
  #kpi-cards-row.grid-4,
  #kpi-cards-row.grid-5 {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  /* A configured "+" placeholder card that spans the full row should keep
     spanning so it doesn't look like a broken KPI tile. */
  #kpi-cards-row .kpi-card[style*="1/-1"] {
    grid-column: 1 / -1;
  }
}

/* Embedded SLD on asset page — responsive */
#embedded-sld {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 600px) {
  #embedded-sld {
    min-height: 200px !important;
  }
}

/* ============================================================
   TRENDS PAGE
   ============================================================ */
.trends-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.trends-controls-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.trends-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.trends-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 20px;
  font-size: 0.75rem;
  border-left-width: 3px;
}

.trends-chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.trends-chip-label {
  font-weight: 600;
  color: var(--text-primary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trends-chip-unit {
  color: var(--text-muted);
  font-size: 0.6875rem;
}

.trends-chip-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  transition: color var(--transition-fast);
}

.trends-chip-remove:hover {
  color: var(--status-critical);
}

.trends-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-primary);
}

.trends-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.trends-legend-dot {
  width: 10px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Entity picker in modal */
.entity-pick-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-primary);
  transition: background var(--transition-fast);
}

.entity-pick-row:hover {
  background: var(--bg-tertiary);
}

.entity-pick-row input[type="checkbox"] {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

@media (max-width: 600px) {
  .trends-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .trends-controls-left {
    flex-direction: column;
    align-items: stretch;
  }

  .trends-controls-left select {
    width: 100% !important;
  }

  .trends-chip-label {
    max-width: 140px;
  }

  .trends-legend {
    gap: 8px;
    padding: 8px 12px;
  }
}

/* Trends chart sizing. Fixed height on desktop, shorter on phones so the chart
   plus its stats fit a small screen without excessive scrolling. The canvas
   fills this wrapper (width/height:100%). */
.trends-chart-wrap {
  height: 400px;
}

.trends-site-sel {
  width: 180px;
}

@media (max-width: 600px) {
  .trends-chart-wrap {
    height: 280px;
  }

  .trends-site-sel {
    width: 100%;
  }

  /* Time-range buttons: let them wrap and grow into easy tap targets. */
  .trends-controls .trend-controls {
    flex-wrap: wrap;
    gap: 6px;
  }

  .trends-controls .time-range-btn {
    flex: 1;
    min-width: 56px;
    min-height: 40px;
  }
}

/* ============================================================
   DASHBOARD PAGE
   ============================================================ */
.dash-two-col {
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .dash-two-col {
    grid-template-columns: 1fr !important;
  }
}

/* Dashboard KPI row: keep a 2-up grid on phones rather than a single tall
   column, so the four headline status figures stay glanceable on-site.
   Overrides the generic grid-4 → 1fr collapse from main.css at ≤600px. */
@media (max-width: 600px) {
  #dash-kpis.grid-4 {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}
