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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: #1a1a2e;
  color: #e0e0e0;
}

/* Sidebar */
#sidebar {
  width: 280px;
  min-width: 280px;
  background: #16213e;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid #0f3460;
  z-index: 10;
}

#header {
  padding: 16px;
  border-bottom: 1px solid #0f3460;
  background: #0f3460;
}

#user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 11px;
  color: #a0aec0;
}

#user-info #user-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#logout-btn {
  font-size: 11px;
  padding: 2px 8px;
  background: transparent;
  border: 1px solid #4a5568;
  border-radius: 3px;
  color: #a0aec0;
  cursor: pointer;
  flex-shrink: 0;
}

#logout-btn:hover {
  background: #2d3748;
  color: #e0e0e0;
}

#header h1 {
  font-size: 16px;
  font-weight: 700;
  color: #e0e0e0;
  letter-spacing: 0.5px;
}

/* Panels */
.panel {
  border-bottom: 1px solid #0f3460;
}

.panel-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #a0a0c0;
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.panel-title:hover {
  background: #0f3460;
}

.toggle-icon {
  margin-left: auto;
  transition: transform 0.2s;
}

.panel-title.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

.panel-body {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-body.hidden {
  display: none;
}

/* Form elements */
label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: #a0a0c0;
  font-size: 11px;
}

input[type="text"],
input[type="number"],
input[type="password"] {
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-radius: 4px;
  color: #e0e0e0;
  padding: 5px 8px;
  font-size: 12px;
  width: 100%;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: #4a90d9;
}

.row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.grow { flex: 1; }
.shrink { flex-shrink: 0; }

.shrink label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding-bottom: 5px;
}

.button-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

button {
  background: #4a90d9;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover { background: #357abd; }
button.disconnect { background: #c0392b; }
button.disconnect:hover { background: #a93226; }

/* Status */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.connected { background: #27ae60; }
.status-dot.connecting { background: #f39c12; }
.status-dot.disconnected { background: #7f8c8d; }
.status-dot.error { background: #c0392b; }

#mqtt-status-text {
  font-size: 11px;
  color: #7f8c8d;
}

#mqtt-status-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-bottom: 1px solid #0f3460;
  font-size: 11px;
  color: #7f8c8d;
}

.badge {
  background: #0f3460;
  color: #a0a0c0;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: normal;
}

/* Drone list */
.no-drones {
  color: #555;
  font-style: italic;
  text-align: center;
  padding: 12px 0;
}

.drone-item {
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.drone-item:hover { border-color: #4a90d9; }
.drone-item.selected { border-color: #4a90d9; background: #0f3460; }

.drone-item-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}

.drone-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.drone-dot.active { background: #27ae60; }
.drone-dot.stale { background: #f39c12; }
.drone-dot.lost { background: #c0392b; }

.drone-name {
  font-weight: 600;
  color: #e0e0e0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drone-mode {
  font-size: 10px;
  color: #a0a0c0;
  text-transform: uppercase;
}

.drone-coords {
  font-size: 11px;
  color: #7f8c8d;
  font-family: monospace;
}

/* Map */
#map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

#map-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
}

#map-style-select {
  background: rgba(22, 33, 62, 0.9);
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
}

/* Drone detail panel */
#drone-detail {
  position: absolute;
  bottom: 20px;
  right: 10px;
  width: 240px;
  background: rgba(22, 33, 62, 0.95);
  border: 1px solid #0f3460;
  border-radius: 8px;
  z-index: 10;
  overflow: hidden;
}

#drone-detail.hidden { display: none; }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #0f3460;
  font-size: 13px;
  color: #e0e0e0;
}

.detail-header button {
  background: transparent;
  padding: 0;
  font-size: 14px;
  color: #a0a0c0;
  line-height: 1;
}

.detail-header button:hover { color: #e0e0e0; background: transparent; }

.detail-grid {
  padding: 8px 0;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 12px;
  font-size: 12px;
}

.detail-row span:first-child { color: #a0a0c0; }
.detail-row span:last-child { color: #e0e0e0; font-family: monospace; }

.hidden { display: none !important; }

/* Raw messages */
.raw-item {
  border-bottom: 1px solid #0f3460;
  padding: 6px 0;
  font-size: 11px;
}

.raw-topic {
  color: #4a90d9;
  font-family: monospace;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.raw-time {
  color: #555;
  font-size: 10px;
  margin-bottom: 2px;
}

.raw-body {
  color: #a0a0c0;
  font-family: monospace;
  font-size: 10px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 80px;
  overflow: hidden;
  margin: 0;
}

/* Mobile layout */
#sidebar-toggle {
  display: none;
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 20;
  background: rgba(15, 52, 96, 0.92);
  border: 1px solid #0f3460;
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 18px;
  padding: 6px 10px;
  cursor: pointer;
  line-height: 1;
}

@media (max-width: 640px) {
  body {
    flex-direction: column;
  }

  #sidebar-toggle {
    display: block;
  }

  #sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85vw;
    max-width: 320px;
    z-index: 15;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,0.5);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #map-container {
    flex: 1;
    width: 100%;
  }

  #drone-detail {
    width: calc(100vw - 20px);
    left: 10px;
    right: 10px;
  }
}
