body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #020617;
  color: #e5e7eb;
}

a { color: #38bdf8; text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #020617;
  border-bottom: 1px solid #1f2937;
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo {
  font-weight: 600;
  font-size: 16px;
}

.menu a {
  margin-right: 10px;
}

.user-info {
  margin-right: 10px;
  font-size: 14px;
}

.btn-logout {
  padding: 4px 10px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
}

.main {
  padding: 16px;
  max-width: 1440px;
  margin: 0 auto;
}

.footer {
  padding: 10px 16px;
  text-align: center;
  font-size: 12px;
  border-top: 1px solid #1f2937;
  background: #020617;
}

/* Login */
.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: radial-gradient(circle at top, #1d4ed8, #020617);
}

.login-wrapper {
  max-width: 360px;
  width: 100%;
  padding: 24px;
  color: #e5e7eb;
}

.login-wrapper h1 {
  text-align: center;
  margin-bottom: 16px;
}

.card {
  background: linear-gradient(135deg, rgba(15,23,42,0.96), rgba(15,23,42,0.98));
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 18px 45px rgba(0,0,0,0.6);
  border: 1px solid rgba(148,163,184,0.12);
}

.card label {
  display: block;
  margin-bottom: 10px;
  font-size: 14px;
}

.card input,
.card select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #374151;
  background: #020617;
  color: #e5e7eb;
  margin-top: 4px;
}

.btn {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: #4b5563;
  color: #e5e7eb;
  font-size: 13px;
}

.btn.primary {
  background: #2563eb;
  color: #fff;
}

.btn:hover {
  opacity: .92;
}

.alert {
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 10px;
  font-size: 13px;
}

.alert-error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid #f87171;
}

.alert-success {
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid #34d399;
}

.forgot {
  margin-top: 10px;
  text-align: center;
}

/* Tables and forms */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 14px;
}

.table th,
.table td {
  border-bottom: 1px solid #1f2937;
  padding: 6px 8px;
}

.table th {
  text-align: left;
  background: #020617;
}

.link-danger {
  background: transparent;
  border: none;
  color: #f87171;
  cursor: pointer;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 4px 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.form-grid button.btn {
  grid-column: 1 / -1;
  justify-self: flex-start;
}

.perm-fieldset {
  border: 1px solid #1f2937;
  border-radius: 6px;
  padding: 8px;
  grid-column: 1 / -1;
}

/* Dashboard controls */
.dash-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.dash-summary {
  display: flex;
  gap: 16px;
  align-items: stretch;
}

.summary-item {
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(15,23,42,0.9);
  border: 1px solid rgba(30,64,175,0.7);
  min-width: 90px;
}

.summary-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #9ca3af;
}

.summary-value {
  font-size: 20px;
  font-weight: 600;
  margin-top: 4px;
}

.dash-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

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

.inline-label {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.inline-label input,
.inline-label select {
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid #374151;
  background: #020617;
  color: #e5e7eb;
  font-size: 12px;
}

.dash-legend {
  margin: 10px 0 6px;
  font-size: 11px;
  display: flex;
  gap: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend-item::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
}

.legend-online::before {
  background: #22c55e;
}

.legend-offline::before {
  background: #ef4444;
}

.legend-reconnecting::before {
  background: #f97316;
}

/* Camera grid */
.camera-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

/* Layout modes */
.grid-mode-fill {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.grid-mode-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-mode-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-mode-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.camera-tile {
  position: relative;
  background: radial-gradient(circle at top, #1e293b, #020617);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(30,64,175,0.75);
  min-height: 180px;
  box-shadow: 0 16px 40px rgba(15,23,42,0.8);
  transition: transform 0.12s ease-out, box-shadow 0.12s ease-out, border-color 0.12s;
}

.camera-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 50px rgba(15,23,42,0.9);
  border-color: rgba(56,189,248,0.9);
}

.camera-tile.focused {
  grid-column: 1 / -1;
  min-height: 420px;
}

.camera-header {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #f9fafb;
  z-index: 5;
  text-shadow: 0 0 3px rgba(0,0,0,0.8);
}

.camera-title {
  font-weight: 600;
}

.camera-status {
  font-weight: 600;
}

.camera-controls {
  display: flex;
  gap: 4px;
}

.camera-controls button {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.85);
  color: #e5e7eb;
}

.camera-video,
.camera-fallback {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.camera-tile.offline .camera-video {
  display: none;
}

.camera-tile.offline .camera-fallback {
  display: block;
}

.camera-tile.online .camera-video {
  display: block;
}

.camera-tile.online .camera-fallback {
  display: none;
}

.camera-tile.reconnecting {
  outline: 2px dashed #f97316;
  outline-offset: -2px;
}

/* Status colors */
.camera-status.online {
  color: #22c55e;
}

.camera-status.offline {
  color: #ef4444;
}

.camera-status.reconnecting {
  color: #f97316;
}
