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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f0f23;
  color: #e0e0e0;
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: #1a1a2e;
  border-bottom: 1px solid #2a2a4a;
}

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

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}

header h1 {
  font-size: 22px;
  font-weight: 600;
  color: #fff;
}

#device-count {
  background: #16213e;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: #888;
}

main {
  padding: 16px;
}

/* Map */
#map-container {
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
  border: 1px solid #2a2a4a;
}

#map {
  height: 50vh;
  min-height: 350px;
  background: #16213e;
}

/* Bottom panels */
#bottom-panels {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 16px;
}

/* Device panel */
#devices-panel, #history-panel {
  background: #1a1a2e;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid #2a2a4a;
}

#devices-panel h2, #history-panel h2 {
  font-size: 16px;
  margin-bottom: 12px;
  color: #fff;
}

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

.panel-header h2 {
  margin-bottom: 0;
}

#mode-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  background: #16213e;
  color: #888;
}

#mode-indicator .mode-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

#mode-indicator.live .mode-dot { background: #4CAF50; box-shadow: 0 0 6px #4CAF50; }
#mode-indicator.historical .mode-dot { background: #FF9800; box-shadow: 0 0 6px #FF9800; }
#mode-indicator.historical { color: #FF9800; }

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  padding: 10px;
  background: #16213e;
  border-radius: 8px;
  margin-bottom: 12px;
}

.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #666;
  flex: 1 1 auto;
  min-width: 120px;
}

.filter-bar select,
.filter-bar input[type="datetime-local"] {
  padding: 6px 8px;
  background: #0f0f23;
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 12px;
  outline: none;
  font-family: inherit;
}

.filter-bar select:focus,
.filter-bar input[type="datetime-local"]:focus {
  border-color: #2196F3;
}

.filter-bar input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
  cursor: pointer;
}

.filter-bar button {
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  background: #2196F3;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  align-self: flex-end;
}

.filter-bar button:hover {
  background: #1976D2;
}

.filter-bar button.secondary {
  background: #2a2a4a;
}

.filter-bar button.secondary:hover {
  background: #3a3a5a;
}

.placeholder {
  color: #555;
  font-size: 14px;
  text-align: center;
  padding: 24px 0;
}

/* Device cards */
.device-card {
  background: #16213e;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  border-left: 4px solid #555;
  cursor: pointer;
  transition: border-color 0.2s;
}

.device-card:hover {
  border-left-color: #4CAF50;
}

.device-card.selected {
  border-left-color: #2196F3;
}

.device-card .device-name {
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  margin-bottom: 8px;
}

.device-card .device-meta {
  font-size: 11px;
  color: #666;
  margin-bottom: 8px;
}

.device-card .data-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.device-card .data-item {
  font-size: 12px;
}

.device-card .data-item .label {
  color: #666;
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.device-card .data-item .value {
  color: #ccc;
  font-family: 'SF Mono', 'Consolas', monospace;
}

/* Freshness indicators */
.freshness-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.fresh { background: #4CAF50; }
.stale { background: #FFC107; }
.offline { background: #f44336; }

/* Detail card */
.detail-card {
  background: #16213e;
  border-radius: 10px;
  border-left: 4px solid #555;
  padding: 14px;
  margin-bottom: 12px;
}

.detail-card.empty {
  border-left-color: #2a2a4a;
  text-align: center;
}

.detail-card .placeholder {
  padding: 12px 0;
}

.detail-header {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #2a2a4a;
}

.detail-header .detail-name {
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  margin-bottom: 4px;
}

.detail-header .detail-meta {
  font-size: 11px;
  color: #666;
  margin-bottom: 2px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}

.detail-row {
  font-size: 12px;
  min-width: 0;
}

.detail-row.full {
  grid-column: 1 / -1;
}

.detail-row .label {
  color: #666;
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.detail-row .value {
  color: #ccc;
  font-family: 'SF Mono', 'Consolas', monospace;
  word-break: break-all;
}

.detail-row .value.placeholder-dash {
  color: #444;
}

.copy-button {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  background: #2a2a4a;
  color: #e0e0e0;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.copy-button:hover { background: #3a3a5a; }
.copy-button.copied { background: #4CAF50; color: #fff; }

/* History panel */
#history-controls {
  margin-bottom: 12px;
}

#device-selector {
  width: 100%;
  padding: 8px 12px;
  background: #16213e;
  border: 1px solid #2a2a4a;
  border-radius: 8px;
  color: #e0e0e0;
  font-size: 14px;
  outline: none;
}

#device-selector:focus {
  border-color: #2196F3;
}

#history-table-wrapper {
  max-height: 400px;
  overflow-y: auto;
}

#history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

#history-table thead {
  position: sticky;
  top: 0;
  background: #1a1a2e;
}

#history-table th {
  text-align: left;
  padding: 8px 6px;
  color: #666;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #2a2a4a;
}

#history-table td {
  padding: 7px 6px;
  color: #bbb;
  font-family: 'SF Mono', 'Consolas', monospace;
  border-bottom: 1px solid #1a1a3e;
}

#history-table tbody tr:hover {
  background: #16213e;
}

/* Scrollbar */
#history-table-wrapper::-webkit-scrollbar {
  width: 6px;
}

#history-table-wrapper::-webkit-scrollbar-track {
  background: #16213e;
}

#history-table-wrapper::-webkit-scrollbar-thumb {
  background: #2a2a4a;
  border-radius: 3px;
}

/* Responsive */
@media (max-width: 768px) {
  #bottom-panels {
    grid-template-columns: 1fr;
  }

  header h1 {
    font-size: 18px;
  }

  #map {
    height: 40vh;
    min-height: 250px;
  }
}
