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

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #22263a;
  --border:    #2e3347;
  --accent:    #4f9cf9;
  --accent2:   #6ee7b7;
  --danger:    #f87171;
  --text:      #e2e8f0;
  --text-muted:#8892a4;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,0.45);
}

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

/* ── Screens ────────────────────────────────────────────────────────── */
.screen { display: none !important; }
.screen.active { display: flex !important; align-items: center; justify-content: center; min-height: 100vh; }
#appScreen.active { display: block !important; min-height: auto; }

/* ── Auth cards ─────────────────────────────────────────────────────── */
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.auth-card-wide { max-width: 600px; }

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo .logo-icon { font-size: 42px; display: block; margin-bottom: 6px; }
.auth-logo .logo-img { height: 80px; margin-bottom: 10px; }
.auth-logo h1 { font-size: 22px; font-weight: 700; }
.auth-logo p { color: var(--text-muted); margin-top: 4px; font-size: 13px; }

.topbar-logo { height: 32px; }

.auth-links {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
  gap: 12px;
  flex-wrap: wrap;
}
.auth-links a {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}
.auth-links a:hover { text-decoration: underline; }

/* ── Forms ──────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}
.form-group label .hint { font-weight: 400; font-style: italic; }
.form-group input, .form-group select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); }
.input-disabled { opacity: .6; cursor: not-allowed; }

/* ── Handle input ───────────────────────────────────────────────────── */
.handle-input-wrap {
  display: flex;
  align-items: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.handle-input-wrap:focus-within { border-color: var(--accent); }
.handle-prefix {
  padding: 10px 0 10px 12px;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  user-select: none;
}
.handle-input-wrap input {
  border: none !important;
  background: transparent !important;
  padding-left: 2px !important;
  border-radius: 0 !important;
}
.handle-suggestion {
  margin-top: 6px;
  padding: 8px 12px;
  background: rgba(79,156,249,.1);
  border: 1px solid rgba(79,156,249,.3);
  border-radius: 8px;
  font-size: 13px;
  color: var(--accent);
}
.handle-suggestion .suggestion-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 3px 10px;
  margin-left: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ── Password requirements ──────────────────────────────────────────── */
.password-requirements {
  background: var(--surface2);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-muted);
}
.password-requirements p { margin-bottom: 4px; font-weight: 600; }
.password-requirements ul { list-style: none; padding-left: 0; }
.password-requirements li { padding: 2px 0; }
.password-requirements li::before { content: "\\2022 "; color: var(--border); margin-right: 6px; }
.password-requirements li.met { color: var(--accent2); }
.password-requirements li.met::before { content: "\\2713 "; color: var(--accent2); }

/* ── Tier selection ─────────────────────────────────────────────────── */
.tier-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.tier-card {
  position: relative;
  cursor: pointer;
}
.tier-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.tier-content {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
  transition: border-color .2s, background .2s;
}
.tier-card input:checked + .tier-content {
  border-color: var(--accent);
  background: rgba(79,156,249,.1);
}
.tier-name { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.tier-detail { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.tier-price { font-size: 12px; color: var(--accent2); font-weight: 600; }
.tier-card-sm .tier-content { padding: 10px 8px; }
.tier-card-sm .tier-name { font-size: 13px; }

/* ── Messages ───────────────────────────────────────────────────────── */
.error-msg {
  background: rgba(248,113,113,.1);
  border: 1px solid rgba(248,113,113,.3);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
}
.success-msg {
  background: rgba(110,231,183,.1);
  border: 1px solid rgba(110,231,183,.3);
  color: var(--accent2);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
}

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity .15s, background .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { opacity: .85; }
.btn-secondary { background: var(--surface2); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-full { width: 100%; }
.btn-lg { padding: 13px 20px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── Top bar ────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo-icon-sm { font-size: 22px; }
.topbar-title { font-weight: 700; font-size: 16px; }
.topbar-center { display: flex; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ── Storage badge ──────────────────────────────────────────────────── */
.storage-badge {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  background: rgba(110,231,183,.08);
  border: 1px solid rgba(110,231,183,.25);
  border-radius: 8px;
  padding: 4px 12px;
}
.storage-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.storage-value { font-size: 13px; font-weight: 700; color: var(--accent2); }

/* ── Tab nav ────────────────────────────────────────────────────────── */
.tab-nav { display: flex; gap: 4px; }
.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 16px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
}
.tab-btn:hover { color: var(--text); background: var(--surface2); }
.tab-btn.active { color: var(--accent); background: rgba(79,156,249,.12); }

.tab-content { display: none; }
.tab-content.active { display: block; }

.page-content { max-width: 900px; margin: 0 auto; padding: 32px 24px; }
.empty-state { color: var(--text-muted); text-align: center; padding: 60px 0; }

/* ── Modal ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow);
}
.modal-card-wide { max-width: 680px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 { font-size: 18px; }
.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Profile sections ───────────────────────────────────────────────── */
.profile-section {
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.profile-section h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 12px;
}

/* ── Cameras grid ────────────────────────────────────────────────────── */
.cameras-header { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.cameras-header h2 { flex: 1; }
.camera-count-label { font-size: 13px; color: var(--text-muted); }
.cameras-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.camera-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color .15s;
}
.camera-card:hover { border-color: var(--accent); }
.camera-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.camera-card-name { font-size: 16px; font-weight: 700; flex: 1; }
.camera-card-edit { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; }
.camera-card-edit:hover { color: var(--accent); }
.camera-card-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 14px; }
.camera-card-actions { margin-top: 10px; display: flex; gap: 8px; justify-content: flex-end; }

.add-camera-form {
  display: flex; align-items: center; gap: 10px; margin-top: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px;
}
.add-camera-form input { flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; color: var(--text); font-size: 14px; outline: none; }
.add-camera-form input:focus { border-color: var(--accent); }

/* ── Upload panel ───────────────────────────────────────────────────── */
.upload-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.upload-panel h2 { margin-bottom: 20px; }
.form-section { margin-bottom: 20px; }
.section-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; display: block; }
.form-select { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; color: var(--text); font-size: 14px; outline: none; }
.form-select:focus { border-color: var(--accent); }

.animal-checkboxes { display: flex; gap: 10px; flex-wrap: wrap; }
.animal-check { display: flex; align-items: center; gap: 6px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px; font-weight: 600; }
.animal-check:hover { border-color: var(--accent); }
.animal-check input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.animal-check-group { display: flex; flex-direction: column; gap: 6px; }
.deer-sub-options { display: none; padding-left: 10px; border-left: 2px solid var(--border); margin-left: 10px; }
.deer-sub-options.visible { display: flex; flex-direction: column; gap: 4px; }
.sub-radio { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; cursor: pointer; }
.sub-radio input { accent-color: var(--accent); cursor: pointer; }

.slider { -webkit-appearance: none; width: 100%; height: 6px; background: var(--surface2); border-radius: 3px; outline: none; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; background: var(--accent); border-radius: 50%; cursor: pointer; }

.file-options { display: flex; gap: 10px; flex-wrap: wrap; }
.file-option-btn { display: flex; align-items: center; gap: 6px; padding: 12px 18px; background: var(--surface2); border: 1px dashed var(--border); border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.file-option-btn:hover { border-color: var(--accent); color: var(--accent); }
.file-icon { font-weight: 700; }
.hidden-input { display: none; }

.files-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 13px; color: var(--text-muted); }
.files-list { max-height: 150px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.file-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--surface2); border-radius: 6px; font-size: 12px; }
.file-row-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row-size { color: var(--text-muted); }

.progress-panel { margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px 28px; }
.progress-panel h3 { margin-bottom: 12px; font-size: 15px; }
.progress-bar-wrap { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 4px; transition: width .3s; }
.progress-detail { font-size: 13px; color: var(--text-muted); }

/* ── Results/Gallery overlay ────────────────────────────────────────── */
.results-view { position: fixed; inset: 0; background: var(--bg); z-index: 200; display: flex; flex-direction: column; overflow-y: auto; }
.results-header { display: flex; align-items: center; gap: 14px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
.results-title { flex: 1; }
.results-title h2 { font-size: 17px; }
.subtitle { font-size: 12px; color: var(--text-muted); }
.results-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page-size-wrap { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); }
.page-size-select { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 4px 8px; font-size: 12px; cursor: pointer; }

.animal-tabs { display: flex; gap: 4px; padding: 10px 24px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.animal-tab-btn { background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-muted); padding: 7px 16px; font-size: 13px; font-weight: 600; cursor: pointer; margin-bottom: -1px; }
.animal-tab-btn:hover { color: var(--text); }
.animal-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.animal-tab-count { background: var(--surface2); border-radius: 10px; padding: 1px 6px; font-size: 11px; margin-left: 4px; }

.thumbnail-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; padding: 16px 24px; }
.thumb-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; transition: transform .15s, border-color .15s; position: relative; }
.thumb-card:hover { transform: scale(1.02); border-color: var(--accent); }
.thumb-card.selected { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(248,113,113,.3); }
.thumb-img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: var(--surface2); }
.thumb-video-placeholder { width: 100%; aspect-ratio: 4/3; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--text-muted); }
.thumb-info { padding: 6px 8px; }
.thumb-name { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.confidence-chip { display: inline-block; background: rgba(110,231,183,.15); border: 1px solid rgba(110,231,183,.3); color: var(--accent2); border-radius: 4px; padding: 1px 6px; font-size: 10px; font-weight: 700; }
.thumb-checkbox { position: absolute; top: 6px; left: 6px; width: 18px; height: 18px; accent-color: var(--danger); cursor: pointer; z-index: 5; }

.pagination-bar { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 16px 24px; border-top: 1px solid var(--border); }
.page-info { font-size: 12px; color: var(--text-muted); min-width: 100px; text-align: center; }

/* ── Upload card in camera uploads list ──────────────────────────────── */
.upload-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px; margin-bottom: 10px; cursor: pointer; transition: border-color .15s; display: flex; align-items: center; gap: 16px; }
.upload-card:hover { border-color: var(--accent); }
.upload-card-info { flex: 1; }
.upload-card-date { font-weight: 700; font-size: 14px; }
.upload-card-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; display: flex; gap: 12px; flex-wrap: wrap; }
.upload-card-counts { text-align: right; font-size: 13px; color: var(--accent2); font-weight: 700; }
.upload-card-actions { display: flex; gap: 6px; }

/* ── Lightbox ───────────────────────────────────────────────────────── */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 500; display: flex; align-items: center; justify-content: center; }
.lightbox-content { display: flex; flex-direction: column; align-items: center; max-width: calc(100vw - 140px); max-height: 100vh; }
#lightboxImg, #lightboxVideo { max-width: 100%; max-height: calc(100vh - 80px); border-radius: 8px; object-fit: contain; }
.lightbox-info { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; justify-content: center; font-size: 13px; color: var(--text-muted); }
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); color: #fff; border-radius: 50%; width: 48px; height: 48px; font-size: 26px; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 10; }
.lightbox-nav:hover { background: rgba(255,255,255,.18); }
.lightbox-prev { left: 14px; }
.lightbox-next { right: 14px; }
.lightbox-close { position: absolute; top: 14px; right: 14px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); color: #fff; border-radius: 50%; width: 38px; height: 38px; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 10; }
.slideshow-controls { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--text-muted); }
.slideshow-status { color: var(--accent2); font-weight: 600; min-width: 60px; }
.pause-hint { font-size: 12px; color: var(--text-muted); font-style: italic; }

/* ── Modal warning ──────────────────────────────────────────────────── */
.modal-warning { background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.3); border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--danger); margin-bottom: 16px; }

/* ── Utilities ──────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Scrollbar ──────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .auth-card { padding: 28px 20px; margin: 16px; }
  .form-row { flex-direction: column; gap: 0; }
  .topbar { padding: 0 14px; }
  .topbar-title { display: none; }
  .tier-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-card { padding: 20px; }
}
