/*
  Palette drawn from the two brand marks used in the header:
  - Age of Aquarius (navy / teal-green / gold arrow) → primary chrome,
    functional colors (success, map dots, focus rings).
  - DMLRD Tech (cyan → magenta gradient) → the signature gradient reserved
    for primary call-to-action moments (FAB, "Check In", "Save").
*/
:root {
  --navy: #14283f;
  --teal: #0f9d70;
  --teal-dark: #0b7d59;
  --teal-soft: #e1f5ec;
  --gold: #e2a53a;
  --cyan: #14c8d4;
  --magenta: #c92fd0;
  --gradient-brand: linear-gradient(135deg, var(--cyan), var(--magenta));

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-tint: #eef1f4;
  --border: #e3e7ec;
  --text: #16212b;
  --text-muted: #67727d;

  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: var(--teal-dark);
  --ok-soft: var(--teal-soft);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(20, 40, 63, 0.05), 0 1px 1px rgba(20, 40, 63, 0.04);
  --shadow-md: 0 8px 24px rgba(20, 40, 63, 0.1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

h2, h3 { font-family: var(--font); margin: 0; color: var(--text); }
h2 { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 16px; }
h3 { font-size: 0.95rem; font-weight: 700; margin: 22px 0 10px; }

/* ---------------------------------------------------------------- header */

.app-header {
  position: relative;
  background: var(--surface);
  color: var(--text);
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  box-shadow: 0 1px 0 var(--border);
  z-index: 10;
}
.app-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 2px;
  background: var(--gradient-brand);
}

.brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  line-height: 1.3;
  border: none;
  background: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font-family: var(--font);
}
.brand-logo { height: 34px; width: 34px; object-fit: contain; flex-shrink: 0; }
.brand-title { font-weight: 700; font-size: 1.02rem; letter-spacing: -0.01em; }

.partner-logo { height: 22px; width: auto; object-fit: contain; }

/* ---------------------------------------------------------------- layout */

#view-root {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view { padding: 18px; padding-bottom: 100px; max-width: 640px; margin: 0 auto; }

.view-dashboard { padding: 0; display: flex; flex-direction: column; height: 100%; max-width: none; }
.map {
  flex: 1;
  min-height: 42vh;
  margin: 14px 14px 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.dashboard-list { padding: 16px 14px 100px; overflow-y: auto; max-width: 640px; margin: 0 auto; width: 100%; }

/* ---------------------------------------------------------------- picker */

.view-picker { display: flex; flex-direction: column; gap: 12px; }

.tile {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: none;
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.tile:active { transform: scale(0.98); box-shadow: var(--shadow-sm); }

.tile-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  background: var(--teal-soft);
}
.tile-icon-a { background: var(--teal-soft); }
.tile-icon-b { background: #ecf0ff; }
.tile-icon-c { background: #fdf0e6; }

.tile-text { display: flex; flex-direction: column; gap: 2px; }
.tile-title { font-weight: 600; font-size: 0.95rem; color: var(--text); }
.tile-sub { font-size: 0.78rem; color: var(--text-muted); }

/* ---------------------------------------------------------------- forms */

.field-group { margin-bottom: 16px; }
.field-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field-group label .required { color: var(--magenta); }
.field-group input,
.field-group select,
.field-group textarea {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--surface-tint);
  color: var(--text);
  font-family: var(--font);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}
.field-group textarea { resize: vertical; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint { color: var(--text-muted); font-size: 0.78rem; margin-top: 4px; }
.hint.success { color: var(--ok); }
.hint.error { color: var(--danger); }

.gps-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.gps-status { font-size: 0.78rem; color: var(--text-muted); }

.btn-primary, .btn-secondary {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 10px;
  cursor: pointer;
  font-family: var(--font);
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn-primary:active, .btn-secondary:active { transform: scale(0.98); }
.btn-primary { background: var(--gradient-brand); color: white; box-shadow: var(--shadow-sm); }
.btn-primary:disabled { background: #d4d8dd; color: #9aa3ac; box-shadow: none; }
.btn-secondary { background: var(--teal-soft); color: var(--teal-dark); }

.error { color: var(--danger); font-size: 0.85rem; min-height: 1.1em; }
.success { color: var(--ok); font-size: 0.85rem; min-height: 1.1em; }

.preview-img { width: 100%; max-height: 220px; object-fit: cover; border-radius: var(--radius-md); margin-bottom: 12px; box-shadow: var(--shadow-sm); }
.file-chip { background: var(--surface-tint); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 12px; }

.summary-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 0.85rem;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.summary-card div { padding: 3px 0; }

.details-note { margin-bottom: 16px; }
.details-note summary {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--teal-dark);
  cursor: pointer;
  padding: 4px 0;
  list-style: none;
}
.details-note summary::-webkit-details-marker { display: none; }
.details-note summary::before { content: "ℹ️  "; }
.details-note[open] summary { margin-bottom: 8px; }

.geology-note {
  font-size: 0.83rem;
  color: var(--text-muted);
  line-height: 1.55;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

/* ---------------------------------------------------------------- sync */

.sync-summary {
  display: flex;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: 0.9rem; }
.list-item-sub { font-size: 0.76rem; color: var(--text-muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.badge {
  font-size: 0.66rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.badge-pending { background: var(--warn-soft); color: var(--warn); }
.badge-synced { background: var(--ok-soft); color: var(--ok); }
.badge-error { background: var(--danger-soft); color: var(--danger); }

.empty { text-align: center; color: var(--text-muted); padding: 40px 20px; font-size: 0.9rem; }

/* ---------------------------------------------------------------- nav */

.bottom-nav {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  box-shadow: 0 -1px 0 var(--border), 0 -8px 24px rgba(20, 40, 63, 0.06);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.bottom-nav button {
  border: none;
  background: none;
  padding: 10px 4px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
}
.bottom-nav button .icon { font-size: 1.15rem; transition: transform 0.15s ease; }
.bottom-nav button:active .icon { transform: scale(0.9); }
.bottom-nav button.active { color: var(--teal-dark); }
.bottom-nav button.fab .icon {
  background: var(--gradient-brand);
  color: white;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: 0 4px 14px rgba(201, 47, 208, 0.35);
  margin-top: -18px;
}
.bottom-nav button.fab { color: var(--text-muted); }

.icon-wrap { position: relative; display: inline-flex; }
.nav-badge {
  position: absolute;
  top: -6px;
  right: -10px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 8px;
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 15px;
  text-align: center;
  color: white;
  background: var(--text-muted);
}
.nav-badge:empty { display: none; }
.nav-badge.pending { background: var(--warn); }
.nav-badge.syncing { background: var(--cyan); }
.nav-badge.ok { background: transparent; }

/* ---------------------------------------------------------------- modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 63, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 16px;
  z-index: 9999;
  animation: modal-fade 0.15s ease;
}
.modal-overlay[hidden] { display: none; }

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  box-shadow: var(--shadow-md);
  margin: auto;
  animation: modal-pop 0.18s ease;
}

@keyframes modal-pop {
  from { transform: scale(0.97) translateY(6px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-card h2 { margin-bottom: 4px; }
.modal-sub { color: var(--text-muted); font-size: 0.85rem; margin: 0 0 18px; }

/* ---------------------------------------------------------------- check-in */

.checkin-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.checkin-logo { width: 40px; height: 40px; object-fit: contain; flex-shrink: 0; }
.checkin-header h2 { margin-bottom: 2px; }
.checkin-header .modal-sub { margin: 0; }

.camera-frame {
  position: relative;
  width: 168px;
  height: 168px;
  margin: 0 auto 20px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--navy);
  box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px var(--border), var(--shadow-md);
}
.camera-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror, like a selfie viewfinder */
}
.camera-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  font-size: 0.76rem;
  line-height: 1.35;
  color: white;
  background: rgba(20, 40, 63, 0.75);
  cursor: default;
}
.camera-status[hidden] { display: none; }
.camera-status-error { cursor: pointer; background: rgba(146, 32, 32, 0.85); }

.link-button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  padding: 8px;
  cursor: pointer;
  font-family: var(--font);
}
.link-button:hover { color: var(--teal-dark); }

/* ---------------------------------------------------------------- admin */

.admin-panel-card { max-width: 520px; }

.admin-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.admin-panel-header h2 { margin: 0; }
.admin-panel-header .link-button { width: auto; padding: 4px 8px; }

#admin-users-list { margin-bottom: 8px; }

.icon-btn {
  border: none;
  background: var(--surface-tint);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  font-size: 0.9rem;
  cursor: pointer;
  margin-left: 6px;
}
.icon-btn:active { transform: scale(0.94); }

/* ---------------------------------------------------------------- map popup */

.leaflet-popup-content-wrapper { border-radius: var(--radius-md); }
.leaflet-popup-content .popup { font-family: var(--font); }
.leaflet-popup-content .popup h4 { margin: 0 0 8px; font-size: 0.9rem; display: flex; align-items: center; gap: 8px; }
.leaflet-popup-content .popup .meta { color: var(--text-muted); font-size: 0.72rem; margin-top: 6px; }
.leaflet-popup-content .popup .notes { font-style: italic; margin-top: 4px; font-size: 0.82rem; }

@media (min-width: 700px) {
  .dashboard-list { max-width: 640px; }
}
