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

:root {
  --bg: #111;
  --surface: #1a1a1a;
  --surface-2: #222;
  --border: #2a2a2a;
  --border-2: #333;
  --border-row: #1f1f1f;
  --text: #e0e0e0;
  --text-muted: #888;
  --text-dim: #aaa;
  --text-strong: #fff;
  --text-nav: #ccc;
  --text-small: #666;
  --link: #7db8f7;
  --badge-bg: #2a4a70;
  --badge-text: #7db8f7;
  --btn-secondary-bg: #333;
  --btn-secondary-hover: #444;
  --btn-secondary-border: #555;
  --btn-fav-bg: #5a4000;
  --btn-fav-hover: #6b4d00;
  --fav-star: #f4b942;
  --fav-btn-bg: rgba(0,0,0,0.55);
}

[data-theme="light"] {
  --bg: #f2f4f7;
  --surface: #fff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --border-2: #c8cdd5;
  --border-row: #e8eaed;
  --text: #111827;
  --text-muted: #6b7280;
  --text-dim: #374151;
  --text-strong: #000;
  --text-nav: #374151;
  --text-small: #9ca3af;
  --link: #2563eb;
  --badge-bg: #dbeafe;
  --badge-text: #1d4ed8;
  --btn-secondary-bg: #e5e7eb;
  --btn-secondary-hover: #d1d5db;
  --btn-secondary-border: #9ca3af;
  --btn-fav-bg: #fef3c7;
  --btn-fav-hover: #fde68a;
  --fav-star: #d97706;
  --fav-btn-bg: rgba(255,255,255,0.75);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.site-logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-strong);
  text-decoration: none;
}
.site-nav { display: flex; align-items: center; gap: 1.25rem; }
.site-nav a { color: var(--text-nav); font-size: 0.9rem; }
.site-nav a:hover { color: var(--text-strong); text-decoration: none; }
.nav-user { font-size: 0.85rem; color: var(--text-muted); }

/* Main */
main { padding: 2rem 1.5rem; max-width: 1200px; margin: 0 auto; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: #3a7bd5;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #2e6ab8; text-decoration: none; color: #fff; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-secondary { background: var(--btn-secondary-bg); border: 1px solid var(--btn-secondary-border); color: var(--text-nav); }
.btn-secondary:hover { background: var(--btn-secondary-hover); }
.btn-danger { background: #c0392b; }
.btn-danger:hover { background: #a93226; }
.btn-fav-active { background: var(--btn-fav-bg); color: var(--fav-star); }
.btn-fav-active:hover { background: var(--btn-fav-hover); color: var(--fav-star); }
.btn-link {
  background: none;
  border: none;
  color: var(--text-nav);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
}
.btn-link:hover { color: var(--text-strong); }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; }

/* Errors / hints */
.error { color: #e74c3c; margin-bottom: 1rem; }
.hint { color: var(--text-muted); }

/* Auth box */
.auth-box {
  max-width: 360px;
  margin: 4rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
}
.auth-box h1 { margin-bottom: 1.5rem; font-size: 1.4rem; }

/* Forms */
label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--text-dim);
}
label input, label textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.95rem;
}
label input:focus { outline: none; border-color: #3a7bd5; }
label small { display: block; margin-top: 0.3rem; color: var(--text-small); font-size: 0.8rem; }
.form-page { max-width: 560px; }
.form-page h1 { margin-bottom: 1.5rem; font-size: 1.4rem; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.mono { font-family: monospace; font-size: 0.85rem; }

/* Fieldset / checkboxes */
fieldset {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem;
  margin-bottom: 1rem;
}
fieldset legend { padding: 0 0.5rem; color: var(--text-dim); font-size: 0.85rem; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-nav);
  margin-bottom: 0.5rem;
  cursor: pointer;
}
.checkbox-label input { width: auto; display: inline; margin: 0; }

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
}
.data-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-row);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.actions { display: flex; gap: 0.4rem; align-items: center; }

/* Badge */
.badge {
  display: inline-block;
  font-size: 0.7rem;
  background: var(--badge-bg);
  color: var(--badge-text);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
}

/* Dashboard stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
}
.stat-value { font-size: 2.5rem; font-weight: 700; color: var(--text-strong); }
.stat-label { color: var(--text-muted); font-size: 0.85rem; margin: 0.3rem 0 0.75rem; }

/* Camera grid */
.camera-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.camera-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  color: var(--text-nav);
  transition: border-color 0.15s;
}
.camera-card:hover { border-color: #3a7bd5; text-decoration: none; color: var(--text-strong); }
.camera-name { font-size: 1rem; font-weight: 500; }

/* Gallery grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.gallery-item {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  color: var(--text-muted);
  transition: border-color 0.15s;
}
.gallery-item:hover { border-color: #3a7bd5; }
.gallery-link { display: block; color: var(--text-muted); }
.gallery-link:hover { text-decoration: none; }
.fav-btn {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  background: var(--fav-btn-bg);
  border: none;
  border-radius: 3px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  z-index: 1;
  transition: color 0.1s;
}
.fav-btn:hover, .fav-btn.active { color: var(--fav-star); }
.thumb-wrap {
  position: relative;
}
.thumb-wrap img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
}
.thumb-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  pointer-events: none;
}
.gallery-item img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
}
.video-thumb {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.play-icon { font-size: 2rem; color: var(--text-muted); }
.media-date { font-size: 0.72rem; padding: 0.3rem 0.5rem; }
.tile-camera { display: block; color: var(--link); font-size: 0.7rem; margin-bottom: 0.1rem; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: center;
  margin-top: 2rem;
  color: var(--text-muted);
}

/* Media view */
.media-view { max-width: 960px; margin-top: 1rem; }
.media-view img, .media-view video {
  width: 100%;
  border-radius: 6px;
  background: #000;
}
.media-view a img { display: block; }
.media-meta {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-top: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.media-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 1rem;
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: none;
  color: var(--text-nav);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0;
  line-height: 1;
}
.theme-toggle:hover { color: var(--text-strong); }

@media (max-width: 640px) {
  .site-header { flex-wrap: wrap; gap: 0.5rem; padding: 0.6rem 1rem; }
  .site-logo { font-size: 1rem; }
  .site-nav { gap: 0.75rem; flex-wrap: wrap; }
  main { padding: 1rem; }
  .page-header { flex-wrap: wrap; gap: 0.5rem; }
  .media-meta { flex-wrap: wrap; gap: 0.5rem; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.5rem; }
}
