:root {
  --primary: #66BB6A;
  --primary-dark: #0D3B14;
  --primary-light: #81C784;
  --primary-bg: #1B3A22;
  --accent: #64B5F6;
  --bg: #0A0C10;
  --bg-dark: #0A0D12;
  --surface: #161B22;
  --surface-alt: #1D242E;
  --text: #FFFFFF;
  --text-secondary: #B0BEC5;
  --text-muted: #90A4AE;
  --border: #2A323C;
  --border-dark: #3A4553;
  
  --good: #2E7D32;
  --moderate: #FFA000;
  --warning: #E65100;
  --critical: #C62828;
  --offline: #757575;
  --info: #1565C0;
  
  --success: #2E7D32;
  --warning-color: #FFA000;
  --danger: #C62828;
  --info-color: #1565C0;

  --alert-bg-critical: rgba(198, 40, 40, 0.14);
  --alert-bg-warning: rgba(255, 160, 0, 0.12);
  --alert-bg-info: rgba(21, 101, 192, 0.12);
  --warn-bg: rgba(255, 160, 0, 0.12);
  --warn-border: rgba(255, 160, 0, 0.35);
  --info-bg: rgba(21, 101, 192, 0.12);
  --info-border: rgba(21, 101, 192, 0.35);
  
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
  
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --sidebar-width: 0px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-primary);
  background:
    linear-gradient(rgba(10, 12, 16, 0.82), rgba(10, 12, 16, 0.82)),
    url('../assets/BG_.png') center / cover fixed no-repeat;
  background-color: #0A0C10;
  color: #FFFFFF;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

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

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

.text-success {
  color: var(--success);
}

.text-error {
  color: var(--danger);
}

/* ============ HEADER ============ */

#header {
  background: var(--surface);
  color: var(--text);
  position: sticky;
  top: 0;
  z-index: 90;
  border-bottom: 1px solid var(--border-dark);
}

.header-container {
  max-width: 1520px;
  margin: 0 auto;
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}
.header-logo svg {
  width: 36px;
  height: 36px;
}

.header-title-group {
  display: flex;
  flex-direction: column;
}

.header-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  line-height: 1.2;
}

.header-subtitle {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 3px;
  flex-wrap: wrap;
}

.device-tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 2px 10px;
  border-radius: 4px;
}

.header-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.nav-item {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
}

.nav-badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 4px;
  min-width: 18px;
  display: inline-block;
  text-align: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-time {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.time-current {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.header-timestamps {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.72rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.time-label {
  color: var(--text-muted);
}

.btn-header-refresh {
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px solid var(--primary-light);
}

.btn-header-refresh:hover {
  background: var(--primary-light);
  color: #fff;
}

/* ============ LOCATION BAR ============ */

.location-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary-light);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.location-icon {
  font-size: 1.1rem;
}

.location-text {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.location-device {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 2px 10px;
  border-radius: 4px;
}

.location-bar .btn {
  margin-left: auto;
}

/* ============ SIDEBAR ============ */

.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  height: 100vh;
  border-right: 1px solid var(--border-dark);
  box-shadow: 1px 0 6px rgba(0, 0, 0, 0.04);
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo svg, .sidebar-logo img {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
}

.sidebar-brand-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.sidebar-brand-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.sidebar-section {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-transform: uppercase;
}

.sidebar-device-card {
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-device-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.sidebar-device-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.sidebar-device-value {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-device-status {
  font-size: 0.72rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
}

.status-online-text {
  color: #27AE60;
}

.status-offline-text {
  color: #E74C3C;
}

.sidebar-reading-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-reading {
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 10px 12px;
}

.sidebar-reading-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.sidebar-reading-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-reading-pill {
  font-size: 0.58rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.sidebar-reading-value-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.sidebar-reading-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.sidebar-reading-unit {
  font-size: 0.65rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.sidebar-system-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.sidebar-system-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
}

.sidebar-system-label {
  color: var(--text-secondary);
}

.sidebar-system-value {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
}

.sidebar-system-value .status-dot {
  width: 6px;
  height: 6px;
}

.sidebar-system-value.sys-ok {
  color: #27AE60;
}
.sidebar-system-value.sys-ok .status-dot {
  background: #27AE60;
}
.sidebar-system-value.sys-error {
  color: #E74C3C;
}
.sidebar-system-value.sys-error .status-dot {
  background: #E74C3C;
}
.sidebar-system-value.sys-warn {
  color: #F39C12;
}
.sidebar-system-value.sys-warn .status-dot {
  background: #F39C12;
}

.sidebar-nav {
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-primary);
  font-size: 0.92rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
  text-align: left;
}

.sidebar-nav-item:hover {
  background: var(--primary-bg);
  color: var(--primary);
}

.sidebar-nav-item.active {
  background: var(--primary-light);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(46, 125, 50, 0.3);
}

.sidebar-nav-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
}

.sidebar-nav-label {
  flex: 1;
}

.sidebar-nav-badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface-alt);
}

.sidebar-footer-loc {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
}

.sidebar-footer-device {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
}

body {
  display: flex;
  flex-direction: column;
}

.layout {
  display: flex;
  min-height: 100vh;
}

.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-left: 220px;
}

#app {
  flex: 1;
  padding: 24px 28px 60px;
}

.page-section {
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.section-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
}

.section-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.demo-data-banner {
  background: #FFF8E1;
  border: 1px solid #FFE082;
  color: #F57F17;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 20px;
}

.demo-banner-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============ CARDS ============ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 20px;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--card-shadow-hover);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

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

.card-title h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.sensor-card .card-title h3 {
  font-size: 1.2rem;
  font-weight: 700;
}

.demo-badge {
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--primary-light);
}

/* ============ BUTTONS ============ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary-light);
  color: #fff;
  border-color: var(--primary-light);
}

.btn-primary:hover {
  background: var(--primary);
}

.btn-success {
  background: #E8F5E9;
  color: var(--success);
  border: 1px solid var(--success);
}

.btn-success:hover {
  background: var(--success);
  color: #fff;
}

.btn-warning {
  background: #FFF8E1;
  color: #F57F17;
  border: 1px solid #F57F17;
}

.btn-warning:hover {
  background: #F57F17;
  color: #fff;
}

.btn-danger {
  background: #FFEBEE;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-dark);
}

.btn-outline:hover {
  border-color: var(--primary-light);
  color: var(--primary-light);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.78rem;
}

.refresh-icon {
  display: inline-block;
  transition: transform 0.3s;
}

.refresh-icon.spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ============ STATUS ============ */

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

.status-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 12px;
  letter-spacing: 0.05em;
}

.status-badge .status-dot {
  width: 6px;
  height: 6px;
}

.status-online {
  background: rgba(46, 125, 50, 0.15);
  color: #81C784;
  border: 1px solid rgba(46, 125, 50, 0.3);
}

.status-offline {
  background: rgba(198, 40, 40, 0.15);
  color: #EF5350;
  border: 1px solid rgba(198, 40, 40, 0.3);
}

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
}

.pill-success {
  background: var(--good);
  color: #fff;
}

.pill-warning {
  background: var(--moderate);
  color: #fff;
}

/* ============ SENSOR CARDS ============ */

.sensor-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.sensor-card {
  border-top: 3px solid var(--primary-light);
  position: relative;
}

.sensor-icon {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--primary-bg);
  position: relative;
}

.sensor-icon.src-pm {
  background: var(--primary-bg);
}
.sensor-icon.src-pm::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 2px solid var(--primary-light);
}

.sensor-icon.src-temp::before {
  content: '🌡';
  position: absolute;
  inset: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.sensor-icon.src-hum::before {
  content: '💧';
  position: absolute;
  inset: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.sensor-value-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 8px 0 4px;
}

.sensor-value {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}

.sensor-unit {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.sensor-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.sensor-status {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.sensor-trend {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.trend-up { color: var(--warning); }
.trend-down { color: var(--accent); }
.trend-stable { color: var(--good); }

.sensor-timestamp {
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ============ AQI ============ */

.aqi-card {
  border-top: 3px solid var(--primary-light);
}

.aqi-overview {
  border: 2px solid;
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  color: #1F1F1F;
}

.aqi-overview .aqi-value,
.aqi-overview .aqi-unit,
.aqi-overview .aqi-measure-label,
.aqi-overview .aqi-measure-value,
.aqi-overview .aqi-measure-value small {
  color: #1F1F1F;
}

.aqi-main {
  display: flex;
  align-items: center;
  gap: 16px;
}

.aqi-status-badge {
  font-size: 1rem;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: 6px;
  letter-spacing: 0.04em;
  min-width: 200px;
  text-align: center;
  text-transform: uppercase;
}

.aqi-description {
  display: flex;
  flex-direction: column;
}

.aqi-value {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.1;
}

.aqi-unit {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.aqi-measures {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.aqi-measure-item {
  display: flex;
  flex-direction: column;
}

.aqi-measure-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.aqi-measure-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
}

.aqi-measure-value small {
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 400;
}

.aqi-scale {
  position: relative;
  margin: 12px 0 8px;
  padding-top: 16px;
}

.aqi-scale-bar {
  display: flex;
  height: 18px;
  border-radius: 4px;
  overflow: hidden;
}

.aqi-scale-segment {
  display: flex;
}

.aqi-indicator {
  position: absolute;
  top: 8px;
  margin-left: -8px;
  transition: left 0.4s ease;
  z-index: 2;
}

.aqi-indicator span {
  display: block;
  width: 0;
  height: 30px;
  border-left: 2px solid;
  position: relative;
}

.aqi-indicator span::after {
  content: '▼';
  position: absolute;
  top: 30px;
  left: -6px;
  font-size: 12px;
}

.aqi-scale-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.aqi-legend {
  display: flex;
  gap: 14px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.aqi-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
}

.aqi-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.aqi-reading-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.aqi-reading {
  border: 1px solid;
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.aqi-reading-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.aqi-reading-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.aqi-reading-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.aqi-reading-value-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.aqi-reading-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.aqi-reading-unit {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ============ PM SCALE (SensorCard) ============ */

.pm-scale {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color, rgba(128, 128, 128, 0.2));
}

.pm-scale-bar {
  position: relative;
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: visible;
}

.pm-scale-seg {
  height: 100%;
}

.pm-scale-marker {
  position: absolute;
  top: -3px;
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: #fff;
  border: 2px solid #333;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%);
}

.pm-scale-labels {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 2px 8px;
  margin-top: 8px;
}

.pm-scale-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--text-secondary, #888);
  flex: 1 1 30%;
  white-space: nowrap;
}

.pm-scale-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pm-scale-name {
  font-weight: 600;
}

.pm-scale-range {
  opacity: 0.75;
}

/* ============ CHARTS ============ */

.chart-container {
  height: 320px;
  position: relative;
}

.chart-large {
  height: 400px;
}

.chart-actions {
  display: flex;
  gap: 6px;
}

.chart-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.chart-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.chart-modal-content {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 1600px;
  max-height: 92vh;
  background: var(--surface);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chart-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.chart-modal-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.chart-modal-body {
  flex: 1;
  min-height: 0;
  position: relative;
  padding: 14px;
}

.chart-modal-body canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.range-selector {
  display: flex;
  gap: 4px;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.date-range-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-alt);
}

.date-range-group .date-input {
  width: 150px;
  padding: 5px 10px;
  font-size: 0.78rem;
  background: var(--surface);
}

.date-range-sep {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.range-btn {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.range-btn:hover {
  border-color: var(--primary-light);
  color: var(--primary-light);
}

.range-btn.active {
  background: var(--primary-light);
  border-color: var(--primary-light);
  color: #fff;
}

.env-toggle {
  display: flex;
  gap: 4px;
}

.toggle-btn {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ============ STATISTICS ============ */

.statistics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  background: var(--surface-alt);
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.stat-card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.stat-pm25::before {
  background: linear-gradient(90deg, #2196F3, #64B5F6);
}
.stat-pm25 .stat-dot {
  background: #42A5F5;
  box-shadow: 0 0 8px #42A5F5;
}
.stat-pm25 .stat-pill {
  background: rgba(66, 165, 245, 0.14);
  color: #64B5F6;
  border: 1px solid rgba(66, 165, 245, 0.45);
}

.stat-pm10::before {
  background: linear-gradient(90deg, #FF9800, #FFB74D);
}
.stat-pm10 .stat-dot {
  background: #FFA726;
  box-shadow: 0 0 8px #FFA726;
}
.stat-pm10 .stat-pill {
  background: rgba(255, 167, 38, 0.14);
  color: #FFB74D;
  border: 1px solid rgba(255, 167, 38, 0.45);
}

.stat-temp::before {
  background: linear-gradient(90deg, #F44336, #EF9A9A);
}
.stat-temp .stat-dot {
  background: #EF5350;
  box-shadow: 0 0 8px #EF5350;
}
.stat-temp .stat-pill {
  background: rgba(239, 83, 80, 0.14);
  color: #EF9A9A;
  border: 1px solid rgba(239, 83, 80, 0.45);
}

.stat-hum::before {
  background: linear-gradient(90deg, #26A69A, #80CBC4);
}
.stat-hum .stat-dot {
  background: #26A69A;
  box-shadow: 0 0 8px #26A69A;
}
.stat-hum .stat-pill {
  background: rgba(38, 166, 154, 0.14);
  color: #80CBC4;
  border: 1px solid rgba(38, 166, 154, 0.45);
}

.stat-values {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 0.82rem;
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.stat-value {
  font-family: var(--font-mono);
  font-weight: 600;
}

.stat-value small {
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 400;
}

.stat-pill {
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 700;
}

.stat-min {
  color: #66BB6A;
}

.stat-max {
  color: #FF5252;
}

.stat-row.stat-highlight {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border-dark);
}

/* ============ PM GUIDE ============ */

.pm-guide-card {
  overflow: hidden;
}

.pmg-menu {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.pmg-menu-btn {
  --pmg: #90A4AE;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-dark);
  background: var(--surface-alt);
  color: var(--text-primary);
  font-size: 0.82rem;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.pmg-menu-btn:hover {
  transform: translateY(-2px);
  border-color: var(--pmg);
}

.pmg-menu-btn.active {
  background: var(--pmg);
  border-color: var(--pmg);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.pmg-content {
  position: relative;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 16px 18px;
  margin-bottom: 12px;
  overflow: hidden;
}

.pmg-stage {
  --pmg: #90A4AE;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 150px;
  position: relative;
}

.pmg-dot {
  position: relative;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 24px var(--pmg);
  animation: pmg-float 3s ease-in-out infinite;
}

.pmg-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--pmg);
  animation: pmg-pulse 2s ease-out infinite;
}

@keyframes pmg-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes pmg-pulse {
  from { transform: scale(1); opacity: 0.85; }
  to { transform: scale(6); opacity: 0; }
}

.pmg-floats {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pmg-floats span {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--pmg);
  opacity: 0.55;
  animation: pmg-drift 7s linear infinite;
}

@keyframes pmg-drift {
  0% { transform: translate(0, 0); }
  25% { transform: translate(8px, -16px); }
  50% { transform: translate(-10px, -6px); }
  75% { transform: translate(6px, 12px); }
  100% { transform: translate(0, 0); }
}

.pmg-info {
  min-width: 0;
}

.pmg-info-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.pmg-info-size {
  font-size: 0.86rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.pmg-info-size strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.pmg-info-desc {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.pmg-live {
  margin-bottom: 18px;
}

.pmg-mascot {
  --pmg: #4CAF50;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 20px;
  margin-bottom: 14px;
  border: 1px solid var(--pmg);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.pmg-mascot-face {
  font-size: 3.4rem;
  line-height: 1;
}

.pmg-mascot-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.pmg-mascot-label {
  font-size: 1.15rem;
  font-weight: 800;
}

.pmg-mascot-msg {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.pmg-mascot-value {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.pmg-mascot-value strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.pmg-mood-happy .pmg-mascot-face {
  animation: pmg-jump 1.1s ease-in-out infinite;
}

.pmg-mood-happy {
  animation: pmg-glow 1.6s ease-in-out infinite;
}

.pmg-mood-good .pmg-mascot-face {
  animation: pmg-nod 1.8s ease-in-out infinite;
}

.pmg-mood-neutral .pmg-mascot-face {
  animation: pmg-steady 3s ease-in-out infinite;
}

.pmg-mood-bad .pmg-mascot-face {
  animation: pmg-sway 1s ease-in-out infinite;
}

.pmg-mood-bad {
  animation: pmg-glow 1.4s ease-in-out infinite;
}

.pmg-mood-worst .pmg-mascot-face {
  animation: pmg-shake 0.4s ease-in-out infinite;
}

.pmg-mood-worst {
  animation: pmg-glow 0.9s ease-in-out infinite;
}

@keyframes pmg-jump {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-14px) scale(1.08); }
}

@keyframes pmg-nod {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-5px) rotate(-3deg); }
}

@keyframes pmg-steady {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes pmg-sway {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(6deg); }
}

@keyframes pmg-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@keyframes pmg-glow {
  0%, 100% { box-shadow: 0 0 6px var(--pmg); }
  50% { box-shadow: 0 0 18px var(--pmg); }
}

.pmg-meter {
  margin-bottom: 0;
}

.pmg-meter-label {
  font-size: 0.8rem;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.pmg-meter-label strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.pmg-meter-track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.pmg-meter-seg {
  flex: 1;
}

.pmg-meter-marker {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 18px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.5);
  border-radius: 2px;
  transform: translateX(-2px);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.45);
  transition: left 0.6s ease;
}

.pmg-meter-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.62rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.pmg-images {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 26px;
  margin-bottom: 18px;
}

.pmg-image {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  overflow: hidden;
}

.pmg-image img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
  border-bottom: 1px solid var(--border);
}

.pmg-image figcaption {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
}

.pmg-image-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.pmg-image-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.pmg-compare {
  border-top: 1px dashed var(--border-dark);
  padding-top: 14px;
}

.pmg-compare-track {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 10px;
}

.pmg-compare-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.pmg-compare-dot {
  border-radius: 50%;
  animation: pmg-float 2.6s ease-in-out infinite;
}

.pmg-compare-name {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.pmg-compare-size {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

@media (max-width: 700px) {
  .pmg-stage {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  .pmg-images {
    grid-template-columns: 1fr;
  }
}

/* ============ TABLE ============ */

.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table thead th {
  background: var(--surface-alt);
  color: var(--text-secondary);
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.data-table thead th.text-right {
  text-align: right;
}

.data-table thead th.text-center {
  text-align: center;
}

.data-table thead th:hover {
  color: var(--primary-light);
}

.data-table thead th small {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.68rem;
}

.data-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: var(--surface-alt);
}

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

.empty-row {
  text-align: center;
  color: var(--text-muted);
  padding: 30px !important;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.table-search input {
  min-width: 240px;
}

.table-controls {
  display: flex;
  gap: 8px;
}

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
  gap: 8px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-info {
  min-width: 50px;
  text-align: center;
  font-weight: 600;
}

/* ============ FORMS ============ */

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.form-hint {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  font-family: var(--font-primary);
  font-size: 0.85rem;
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.1);
}

.select {
  min-width: 120px;
  cursor: pointer;
}

.textarea {
  resize: vertical;
  min-height: 160px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.5;
}

.field-error {
  color: var(--danger);
  font-weight: 700;
}

.field-error-msg {
  font-size: 0.72rem;
  color: var(--danger);
  margin-top: 3px;
}

.form-error {
  font-size: 0.78rem;
  color: var(--danger);
  background: #FFEBEE;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #FFCDD2;
  margin-top: 8px;
}

/* ============ ALERT ============ */

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-item {
  display: flex;
  gap: 14px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  align-items: flex-start;
}

.alert-item.severity-critical {
  border-left: 4px solid var(--critical);
  background: var(--alert-bg-critical);
}

.alert-item.severity-warning {
  border-left: 4px solid var(--moderate);
  background: var(--alert-bg-warning);
}

.alert-item.severity-info {
  border-left: 4px solid var(--info);
  background: var(--alert-bg-info);
}

.alert-severity {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.severity-critical .alert-severity {
  background: #FFEBEE;
  color: var(--critical);
}

.severity-warning .alert-severity {
  background: #FFF8E1;
  color: #F57F17;
}

.severity-info .alert-severity {
  background: #E3F2FD;
  color: var(--info);
}

.alert-content {
  flex: 1;
  min-width: 0;
}

.alert-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.alert-type {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text);
}

.alert-time {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.alert-message {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.alert-meta {
  display: flex;
  gap: 12px;
  align-items: center;
}

.alert-device {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 1px 8px;
  border-radius: 3px;
}

.alert-status {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.alert-status.active {
  color: var(--moderate);
}

.alert-status.acked {
  color: var(--success);
}

.alert-actions {
  display: flex;
  gap: 4px;
}

.alert-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-alt);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
}

.empty-icon {
  font-size: 2rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #E8F5E9;
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.empty-state p {
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
  margin-top: 4px;
}

/* ============ SIMULATION ============ */

.sim-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sim-note {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.alert-sim-card {
  border-top: 3px solid var(--moderate);
}

.alert-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.alert-stat-card {
  text-align: center;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.alert-stat-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-light);
}

.alert-stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ============ DEVICE STATUS ============ */

.device-info, .db-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.device-row, .db-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
  font-size: 0.83rem;
}

.device-row:last-child, .db-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.device-label, .db-label {
  color: var(--text-secondary);
  white-space: nowrap;
}

.device-value, .db-value {
  font-family: var(--font-mono);
  font-weight: 500;
  text-align: right;
}

.device-id, .db-value.mono {
  color: var(--primary-light);
}

.device-status-value {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.85rem;
}

.system-status-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.system-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
}

.system-status-label {
  color: var(--text-secondary);
}

.system-status-value {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  font-size: 0.85rem;
}

.system-status-value.system-ok {
  color: var(--good);
}

.system-status-value.system-error {
  color: var(--danger);
}

.system-status-value.system-warn {
  color: var(--moderate);
}

.system-status-value .status-dot {
  width: 7px;
  height: 7px;
}

.system-ok .status-dot { background: var(--good); }
.system-error .status-dot { background: var(--danger); }
.system-warn .status-dot { background: var(--moderate); }

/* ============ API TESTER ============ */

.row {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 20px;
}

.col-4 {
  grid-column: span 4;
}

.col-6 {
  grid-column: span 6;
}

.col-12 {
  grid-column: span 12;
}

.method-tabs {
  display: flex;
  gap: 8px;
}

.method-tab {
  padding: 8px 20px;
  border: 2px solid var(--border-dark);
  background: var(--surface);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.method-tab.active-get {
  border-color: var(--info);
  background: #E3F2FD;
  color: var(--info);
}

.method-tab.active-post {
  border-color: var(--warning-color);
  background: #FFF8E1;
  color: #F57F17;
}

.headers-viewer {
  background: #1E2A30;
  color: #B0BEC5;
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 0.74rem;
  line-height: 1.8;
  white-space: pre;
  overflow-x: auto;
}

.api-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.api-console-card {
  background: #1E2A30;
  color: #E0E0E0;
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid #37474F;
}

.api-console-card h3 {
  color: #ffffff;
  font-size: 0.95rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.response-empty {
  text-align: center;
  padding: 40px 20px;
  color: #78909C;
}

.response-empty .empty-icon {
  background: rgba(255, 255, 255, 0.06);
  color: #78909C;
  margin: 0 auto 12px;
}

.response-empty p {
  font-weight: 500;
}

.response-empty .empty-subtitle {
  color: #546E7A;
}

.response-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.response-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
}

.response-label {
  color: #90A4AE;
}

.response-value {
  color: #E0E0E0;
}

.response-status {
  font-weight: 700;
  padding: 2px 12px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.http-success {
  background: #1B5E20;
  color: #A5D6A7;
}

.http-warning {
  background: #E65100;
  color: #FFCC80;
}

.http-error {
  background: #B71C1C;
  color: #EF9A9A;
}

.response-body {
  background: #1E2A30;
  border-radius: 6px;
  border: 1px solid #37474F;
}

.response-body-header {
  padding: 10px 14px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #B0BEC5;
  border-bottom: 1px solid #37474F;
}

.json-viewer {
  padding: 14px;
  font-size: 0.72rem;
  line-height: 1.6;
  overflow-x: auto;
  background: #1E2A30;
  color: #B2EBF2;
  white-space: pre;
}

.api-status-list, .api-endpoint-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.api-status-row, .endpoint-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.83rem;
}

.api-status-row span:first-child {
  color: var(--text-secondary);
}

.endpoint-row {
  background: var(--surface-alt);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 0.78rem;
}

.api-endpoint-list h4 {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 8px 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.method {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 3px;
  min-width: 50px;
  text-align: center;
}

.method-get {
  background: #E3F2FD;
  color: var(--info);
}

.method-post {
  background: #FFF8E1;
  color: #F57F17;
}

.security-note {
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  padding: 10px 14px;
  border-radius: 6px;
  margin-top: 10px;
  line-height: 1.6;
}

.arch-diagram {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.arch-layer {
  border: 2px solid;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  background: var(--surface-alt);
}

.arch-layer-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.arch-layer-desc {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

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

.arch-note {
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  padding: 12px 16px;
  border-radius: 6px;
  line-height: 1.6;
}

/* ============ ERROR SIM ============ */

.error-sim-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.error-state {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #FFEBEE;
  border: 1px solid #FFCDD2;
  color: var(--danger);
  padding: 12px 16px;
  border-radius: 6px;
  margin: 8px 0;
}

.error-icon {
  font-size: 1.2rem;
}

.error-message {
  font-size: 0.85rem;
}

/* ============ FILTERS ============ */

.filters-card {
  background: var(--surface);
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ============ GET TESTER ============ */

.get-endpoint-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.get-endpoint-btn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary-light);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-primary);
  transition: all 0.15s ease;
  width: 100%;
}

.get-endpoint-btn:hover {
  border-color: var(--primary-light);
  background: var(--primary-bg);
  border-left-width: 3px;
}

.get-endpoint-btn.active {
  border-color: var(--primary-light);
  border-left-width: 3px;
  background: var(--primary-bg);
  box-shadow: 0 0 0 1px var(--primary-light);
}

.get-endpoint-method {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--info);
  background: #E3F2FD;
  border: 1px solid #BBDEFB;
  padding: 2px 6px;
  border-radius: 3px;
  min-width: 38px;
  text-align: center;
  margin-top: 2px;
}

.get-endpoint-clear .method-clear {
  background: var(--surface-alt);
  border-color: var(--border);
  color: var(--text-muted);
}

.get-endpoint-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.get-endpoint-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.get-endpoint-path {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.get-endpoint-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.tdl-source {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 3px;
  min-width: 48px;
  text-align: center;
}

.tdl-source-get {
  color: #1565C0;
  background: #E3F2FD;
  border: 1px solid #90CAF9;
}

.tdl-source-post {
  color: #E65100;
  background: #FFF3E0;
  border: 1px solid #FFCC80;
}

/* ============ POST TESTER ============ */

.post-form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 16px;
}

.test-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* ============ NOTIFICATION ============ */

#notification-container {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.notification {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.25s ease;
  font-size: 0.85rem;
}

.notification-error {
  border-color: var(--danger);
  border-left: 4px solid var(--danger);
}

.notification-warning {
  border-color: var(--moderate);
  border-left: 4px solid var(--moderate);
}

.notification-info {
  border-color: var(--info);
  border-left: 4px solid var(--info);
}

.notification-icon {
  font-weight: 700;
  font-size: 1rem;
}

.notification-error .notification-icon { color: var(--danger); }
.notification-warning .notification-icon { color: #F57F17; }
.notification-info .notification-icon { color: var(--info); }

.notification-message {
  flex: 1;
}

.notification-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-muted);
  padding: 0 4px;
}

.notification.fade-out {
  opacity: 0;
  transform: translateX(20px);
  transition: all 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ============ HISTORY STATS ============ */

.history-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

/* ============ RESPONSIVE ============ */

@media (max-width: 1200px) {
  .sensor-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .aqi-reading-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .statistics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .history-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .alert-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .filters-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .post-form-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .arch-diagram {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .col-4, .col-6 {
    grid-column: span 12;
  }
}

@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 16px;
    gap: 12px;
  }
  
  .header-right {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  
  .header-time {
    align-items: flex-start;
  }
  
  .header-nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  
  .nav-item {
    flex: 1;
    min-width: max-content;
    text-align: center;
  }
  
  .sensor-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .sensor-value {
    font-size: 1.8rem;
  }
  
  .statistics-grid, .history-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .row {
    display: block;
  }
  
  .col-4, .col-6, .col-12 {
    margin-bottom: 16px;
  }
  
  .filters-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .post-form-grid {
    grid-template-columns: 1fr;
  }
  
  .arch-diagram {
    grid-template-columns: 1fr;
  }
  
  .chart-container {
    height: 280px;
  }
  
  .range-selector {
    flex-wrap: wrap;
  }
  
  .chart-toolbar {
    width: 100%;
  }
  
  .date-range-group {
    flex-wrap: wrap;
  }
  
  .date-range-group .date-input {
    width: 130px;
  }
  
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .table-search input {
    min-width: 100%;
    width: 100%;
  }
  
  .table-controls {
    flex-wrap: wrap;
  }
  
  .select {
    flex: 1;
  }
}

@media (max-width: 480px) {
  .header-title {
    font-size: 0.95rem;
  }

  .aqi-reading-grid {
    grid-template-columns: 1fr;
  }
  
  .sensor-grid {
    grid-template-columns: 1fr;
  }
  
  .statistics-grid, .history-stats-grid {
    grid-template-columns: 1fr;
  }
  
  .alert-stats-grid {
    grid-template-columns: 1fr;
  }
  
  .filters-grid {
    grid-template-columns: 1fr;
  }
  
  #app {
    padding: 16px;
  }
  
  .aqi-overview {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .aqi-main {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .aqi-status-badge {
    min-width: 100%;
  }
  
  .sim-buttons {
    flex-direction: column;
  }
  
  .sim-buttons .btn {
    width: 100%;
  }
}

/* ============ SETTINGS / THEME ============ */

.settings-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.theme-toggle-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 560px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-primary);
  transition: all 0.15s ease;
}

.theme-option:hover {
  border-color: var(--primary-light);
}

.theme-option.active {
  border-color: var(--primary-light);
  background: var(--primary-bg);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

.theme-icon {
  font-size: 1.6rem;
}

.theme-caption {
  display: flex;
  flex-direction: column;
}

.theme-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.theme-sub {
  font-size: 0.74rem;
  color: var(--text-secondary);
}

/* ============ LIGHT THEME ============ */

:root[data-theme="light"] {
  --primary: #2E7D32;
  --primary-dark: #1B5E20;
  --primary-light: #43A047;
  --primary-bg: #E8F5E9;
  --accent: #1565C0;
  --bg: #F5F7FA;
  --bg-dark: #ECEFF3;
  --surface: #FFFFFF;
  --surface-alt: #F0F2F5;
  --text: #1A2332;
  --text-secondary: #55606E;
  --text-muted: #7A8699;
  --border: #DFE4EA;
  --border-dark: #C3CDD8;
  --card-shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --card-shadow-hover: 0 6px 16px rgba(16, 24, 40, 0.12);
  --alert-bg-critical: #FFF5F5;
  --alert-bg-warning: #FFFBF0;
  --alert-bg-info: #F5F9FE;
  --warn-bg: #FFF8E1;
  --warn-border: #FFE082;
  --info-bg: #F5F9FE;
  --info-border: #BBDEFB;
}

:root[data-theme="light"] body {
  background:
    linear-gradient(rgba(245, 247, 250, 0.80), rgba(245, 247, 250, 0.80)),
    url('../assets/BG_.png') center / cover fixed no-repeat;
  background-color: #F5F7FA;
  color: var(--text);
}

@media (max-width: 768px) {
  .theme-toggle-group {
    grid-template-columns: 1fr;
  }
}

/* ---- Live Readings: time snapshot ---- */
.live-controls {
  display: grid;
  grid-template-columns: auto 1fr 1fr auto auto;
  align-items: center;
  justify-content: start;
  max-width: 520px;
  gap: 8px;
  margin-bottom: 14px;
}
.live-controls-label {
  font-size: .85rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.live-controls .input {
  width: 100%;
  min-width: 0;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
  cursor: pointer;
}
:root[data-theme="light"] input[type="date"]::-webkit-calendar-picker-indicator,
:root[data-theme="light"] input[type="time"]::-webkit-calendar-picker-indicator {
  filter: none;
}
@media (max-width: 640px) {
  .live-controls {
    grid-template-columns: 1fr 1fr;
  }
  .live-controls-label {
    grid-column: 1 / -1;
  }
  .live-controls .btn {
    width: 100%;
  }
}
.live-time-badge {
  margin-left: auto;
  font-size: .8rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.live-time-current {
  background: rgba(46, 125, 50, .12);
  color: #2E7D32;
  border: 1px solid rgba(46, 125, 50, .35);
}
.live-time-history {
  background: rgba(255, 152, 0, .14);
  color: #E65100;
  border: 1px solid rgba(255, 152, 0, .45);
}

/* ---- Historical: quick range chips ---- */
.filter-item-wide {
  grid-column: 1 / -1;
}
.range-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: .85rem;
  cursor: pointer;
  transition: all .15s ease;
}
.chip:hover {
  border-color: var(--info);
  color: var(--info);
}
.chip-active {
  background: var(--info);
  border-color: var(--info);
  color: #FFFFFF !important;
}