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

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: rgba(255, 255, 255, 0.05);
  --border-color: rgba(255, 255, 255, 0.1);
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #4facfe;
  --accent-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --success: #34c759;
  --warning: #ff9500;
  --danger: #ff3b30;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

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

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

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

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

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

.status-dot.connected {
  background: var(--success);
}

.status-dot.disconnected {
  background: var(--danger);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-primary {
  background: var(--accent-gradient);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #ff5a4f;
}

.btn-icon {
  padding: 8px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
}

.btn-icon:hover {
  color: var(--text-primary);
}

/* Select */
.select {
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}

.select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Main Layout */
.main {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
  padding: 24px;
  flex: 1;
}

@media (max-width: 1024px) {
  .main {
    grid-template-columns: 1fr;
  }
}

/* Panels */
.panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
  font-size: 16px;
  font-weight: 600;
}

/* Camera Panel */
.camera-panel {
  display: flex;
  flex-direction: column;
}

.video-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-height: 400px;
}

.video-placeholder {
  text-align: center;
  color: var(--text-muted);
}

.video-placeholder svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

.video-placeholder p {
  font-size: 14px;
}

#videoCanvas {
  max-width: 100%;
  max-height: 100%;
}

.video-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
}

.stream-status {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Events Panel */
.events-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 120px);
}

.section {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.section:last-child {
  border-bottom: none;
}

.section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.events-section {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Devices List */
.devices-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--bg-card);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

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

.device-item.active {
  border: 1px solid var(--accent);
}

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

.device-name {
  font-size: 14px;
  font-weight: 500;
}

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

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

.device-battery {
  font-size: 12px;
  color: var(--text-secondary);
}

.streaming-badge {
  padding: 4px 8px;
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 600;
  border-radius: 4px;
  text-transform: uppercase;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  background: var(--bg-card);
  border-radius: 8px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--accent);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Events List */
.events-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: 8px;
}

.event-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  flex-shrink: 0;
}

.event-icon.motion {
  background: rgba(255, 149, 0, 0.2);
  color: var(--warning);
}

.event-icon.person {
  background: rgba(79, 172, 254, 0.2);
  color: var(--accent);
}

.event-icon.detection {
  background: rgba(52, 199, 89, 0.2);
  color: var(--success);
}

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

.event-title {
  font-size: 14px;
  font-weight: 500;
}

.event-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.event-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Detection Toast */
.detection-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
}

.detection-toast.show {
  transform: translateY(0);
  opacity: 1;
}

.detection-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(79, 172, 254, 0.2);
  border-radius: 10px;
  color: var(--accent);
}

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

.detection-title {
  font-size: 14px;
  font-weight: 600;
}

.detection-detail {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Utilities */
.muted {
  color: var(--text-muted);
  font-size: 14px;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}
