/* ── Reset & Base ────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #242836;
  --border: #2e3345;
  --text: #e4e6ef;
  --text-muted: #8b8fa3;
  --primary: #6c8cff;
  --primary-hover: #5a7af0;
  --danger: #ff6b6b;
  --success: #51cf66;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a {
  color: var(--primary);
  text-decoration: none;
}

/* ── Login Page ─────────────────────────────────────────── */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  text-align: center;
}

.login-card .subtitle {
  color: var(--text-muted);
  text-align: center;
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
  color: var(--text-muted);
}

.form-group input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.5rem;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

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

.btn-sm {
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn-outline:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.75rem;
  text-align: center;
  display: none;
}

/* ── Dashboard Layout ───────────────────────────────────── */
.dashboard {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 1.3rem;
  font-weight: 600;
}

.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar .user-info span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Camera Grid ────────────────────────────────────────── */
.camera-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.25rem;
}

.camera-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.camera-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.camera-card .preview {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.camera-card .preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-card .preview .no-image {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.camera-card .card-info {
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.camera-card .card-info h3 {
  font-size: 1rem;
  font-weight: 500;
}

.camera-card .card-info .meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.camera-card .card-info .card-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
}

.camera-card .card-info .interval-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  background: rgba(108, 140, 255, 0.15);
  color: var(--primary);
  border-radius: 20px;
}

.camera-card .card-info .motion-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  background: rgba(139, 143, 163, 0.15);
  color: var(--text-muted);
  border-radius: 20px;
  transition: background 0.3s, color 0.3s;
}

.camera-card .card-info .motion-badge.active {
  background: rgba(255, 107, 107, 0.2);
  color: var(--danger);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ── Gallery Modal ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90vw;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

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

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-header .close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.modal-header .close-btn:hover {
  color: var(--text);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.gallery-item {
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
  cursor: pointer;
  transition: transform 0.15s;
  position: relative;
}

.gallery-item:hover {
  transform: scale(1.02);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-item .timestamp {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.4rem 0.6rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  color: #fff;
  font-size: 0.72rem;
}

/* ── Settings Button on Cards ──────────────────────────── */
.settings-btn {
  background: rgba(108, 140, 255, 0.12);
  border: none;
  color: var(--primary);
  border-radius: 6px;
  padding: 0.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

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

/* ── Settings Modal ───────────────────────────────────── */
.settings-modal {
  max-width: 540px;
}

.settings-section {
  margin-bottom: 1.5rem;
}

.settings-section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.settings-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.settings-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.settings-modal .form-group {
  margin-bottom: 0.5rem;
}

.settings-modal .form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  color: var(--text-muted);
}

.settings-modal .form-group input,
.settings-modal .form-group select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.settings-modal .form-group input:focus,
.settings-modal .form-group select:focus {
  border-color: var(--primary);
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.settings-save-btn {
  width: auto;
  min-width: 120px;
}

/* ── Fullscreen Image Viewer ────────────────────────────── */
.fullscreen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.fullscreen-overlay.active {
  display: flex;
}

.fullscreen-overlay img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 4px;
}

/* ── Empty / Loading States ─────────────────────────────── */
.loading {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem;
  font-size: 0.95rem;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 4rem 2rem;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  opacity: 0.4;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 600px) {
  .camera-grid {
    grid-template-columns: 1fr;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .modal {
    width: 95vw;
    max-height: 90vh;
  }

  .login-card {
    padding: 1.5rem;
  }
}
