* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  padding: 0;
  background: #f9fafb;
  color: #1f2933;
}

body.checkin-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body.checkin-page .container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.appbar {
  background: #111827;
}

.appbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.appbar-inner-center {
  justify-content: center;
}

.brand {
  color: #f9fafb;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: 0.06em;
  text-decoration: none;
}

.brand-dot {
  color: #eab308;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.page-head {
  margin-bottom: 28px;
}

.sound-toggle {
  width: auto;
  margin-top: 12px;
  padding: 8px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  color: #6b7280;
}

.sound-toggle.active {
  background: #fefce8;
  border-color: #fde68a;
  color: #92400e;
}

h1 {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #111827;
  margin-bottom: 4px;
}

.subtitle {
  color: #6b7280;
  font-size: 0.9rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: #6b7280;
  margin-bottom: 6px;
  margin-top: 18px;
}

select, input, button {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  color: #1f2933;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}

select:disabled {
  cursor: not-allowed;
}

select:focus, input:focus {
  outline: none;
  border-color: #eab308;
  box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.15);
}

button {
  margin-top: 28px;
  background: #eab308;
  border: 1px solid #eab308;
  color: #1f2933;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  background: #f3f4f6;
  border-color: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
}

button:active:not(:disabled) {
  background: #ca8a04;
  border-color: #ca8a04;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: auto;
  margin: 0;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  box-shadow: none;
  color: #9ca3af;
  cursor: pointer;
}

.password-toggle:hover {
  color: #6b7280;
}

.link-button {
  width: auto;
  margin-top: 0;
  padding: 0;
  background: none;
  border: none;
  color: #ca8a04;
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
}

.auto-guard {
  width: 100%;
  margin-top: 18px;
  padding: 16px;
  border-radius: 10px;
  background: #fefce8;
  border: 1px solid #fde68a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.auto-guard span {
  font-weight: 600;
  color: #78350f;
}

.corner-logout {
  position: absolute;
  top: 20px;
  right: 20px;
  width: auto;
  white-space: nowrap;
  margin-top: 0;
  padding: 6px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  color: #6b7280;
  border-radius: 999px;
}

.corner-logout:active {
  background: #f3f4f6;
}

.add-name-link {
  display: inline-block;
  margin-top: 16px;
  font-size: 1rem;
}

.card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.status {
  margin-top: 20px;
  padding: 16px;
  border-radius: 10px;
  text-align: center;
  font-weight: 600;
  display: none;
}

.status.ok {
  background: #dcfce7;
  color: #166534;
  display: block;
}

.status.error {
  background: #fee2e2;
  color: #991b1b;
  display: block;
}

.status.pending {
  background: #fef9c3;
  color: #854d0e;
  display: block;
}

.checkin-card {
  position: relative;
  margin-bottom: 0;
  padding: 28px 24px;
}

.checkin-card h1 {
  margin-bottom: 16px;
}

.checkpoint-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fefce8;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 7px 14px 7px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.checkpoint-chip svg {
  flex-shrink: 0;
}

.container.wide {
  max-width: 1000px;
}

nav.topnav {
  display: flex;
  align-items: center;
  gap: 2px;
}

nav.topnav a {
  color: #9ca3af;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 8px;
  border-bottom: 4px solid transparent;
  line-height: 1;
}

nav.topnav a.active {
  color: #f9fafb;
  border-bottom-color: #eab308;
}

nav.topnav a:active {
  background: rgba(255, 255, 255, 0.08);
}

.nav-divider {
  width: 1px;
  height: 18px;
  background: #374151;
  margin: 0 6px;
  flex-shrink: 0;
}

.nav-logout {
  color: #f87171 !important;
}

.nav-logout:active {
  background: rgba(248, 113, 113, 0.14) !important;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 32px;
}

.status-card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.status-card.warning {
  border-color: #fde68a;
  background: #fffdf5;
}

.status-card.critical {
  border-color: #fecaca;
  background: #fef2f2;
}

.status-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}

.status-card .name {
  font-weight: 700;
  font-size: 0.85rem;
  flex: 1;
  min-width: 0;
}

.status-card .detail {
  font-size: 0.68rem;
  color: #6b7280;
  margin-top: 6px;
}

.status-card .detail div + div {
  margin-top: 2px;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  white-space: nowrap;
  margin-top: 2px;
}

/* Status palette — fixed, never reused for anything but state. */
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #0ca30c;
  flex-shrink: 0;
}

.dot.warning {
  background: #fab219;
}

.dot.critical {
  background: #d03b3b;
}

.badge-new-device {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fef9c3;
  color: #854d0e;
  vertical-align: middle;
}

.badge-mismatch {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fee2e2;
  color: #991b1b;
  vertical-align: middle;
}

.geo-map {
  width: 100%;
  height: 360px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  margin-bottom: 32px;
}

#dashboard-map.geo-map {
  height: 480px;
}

.level-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.level-tab {
  width: auto;
  margin-top: 0;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  color: #6b7280;
  border-radius: 999px;
}

.level-tab.active {
  background: #111827;
  border-color: #111827;
  color: #ffffff;
}

.locate-btn {
  width: auto;
  margin-top: 0;
  padding: 6px 12px;
  font-size: 0.78rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
}

.level-input {
  width: 130px;
  padding: 6px 10px;
  font-size: 0.85rem;
  box-shadow: none;
}

.cp-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.cp-card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.cp-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.cp-card-name {
  font-weight: 700;
  font-size: 1rem;
}

.cp-card-name-input {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 1rem;
  padding: 4px 6px;
  margin: -4px 0 -4px -6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  box-shadow: none;
}

.cp-card-name-input:hover {
  border-color: #e5e7eb;
}

.cp-card-name-input:focus {
  border-color: #2563eb;
  background: #ffffff;
  outline: none;
}

.save-indicator {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: normal;
  color: #166534;
  opacity: 0;
  transition: opacity 0.2s;
  margin-left: 6px;
}

.save-indicator.show {
  opacity: 1;
}

.cp-located-badge {
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.cp-located-badge.yes {
  background: #dcfce7;
  color: #166534;
}

.cp-located-badge.no {
  background: #f3f4f6;
  color: #6b7280;
}

.cp-card-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.cp-card-field label {
  margin-top: 0;
  margin-bottom: 4px;
  font-size: 0.7rem;
}

.cp-field-input {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.85rem;
  box-shadow: none;
}

.cp-card-primary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.cp-card-primary button {
  margin-top: 0;
  padding: 13px 10px;
  font-size: 0.85rem;
  font-weight: 700;
}

.cp-card-secondary {
  display: flex;
  gap: 8px;
}

.cp-card-secondary button {
  flex: 1;
  width: auto;
  margin-top: 0;
  padding: 9px 10px;
  font-size: 0.76rem;
  background: #f9fafb;
  border-color: #e5e7eb;
  color: #6b7280;
}

.cp-card-secondary button.danger {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
}

.cp-marker-label {
  background: #111827;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.cp-marker-label::before {
  border-top-color: #111827;
}

.geo-pin-popup {
  font-size: 0.85rem;
}

.geo-pin-popup .name {
  font-weight: 700;
  margin-bottom: 2px;
}

.geo-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  background: #0ca30c;
}

.geo-dot.warning {
  background: #fab219;
}

.geo-dot.critical {
  background: #d03b3b;
}

/* Breadcrumbs — a guard's actual GPS position at the moment they scanned, distinct
   from the checkpoint's own fixed pin above. A person icon (not just a plain dot)
   makes it read as "someone was here" at a glance. */
.scan-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 3px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  background: #2563eb;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-dot.mismatch {
  background: #d03b3b;
}

.scan-dot svg {
  width: 13px;
  height: 13px;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: #111827;
  line-height: 1.15;
}

.meter {
  height: 4px;
  border-radius: 999px;
  background: #f3f4f6;
  margin-top: 5px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: #0ca30c;
}

.meter-fill.warning {
  background: #fab219;
}

.meter-fill.critical {
  background: #d03b3b;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.filters label {
  margin-top: 0;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

.pagination button {
  width: auto;
  margin-top: 0;
  padding: 8px 16px;
  font-size: 0.85rem;
  background: #ffffff;
  border-color: #e5e7eb;
  color: #1f2933;
}

.pagination button:disabled {
  color: #d1d5db;
}

.page-info {
  font-size: 0.85rem;
  color: #6b7280;
}

.log-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  min-height: 20px;
}

.page-numbers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.pagination .page-numbers button {
  min-width: 38px;
  padding: 8px 10px;
}

.pagination .page-numbers button.active {
  background: #111827;
  border-color: #111827;
  color: #ffffff;
}

.page-ellipsis {
  align-self: center;
  color: #9ca3af;
  font-size: 0.85rem;
}

@media (max-width: 520px) {
  .pagination {
    gap: 8px;
  }
  .pagination > button {
    padding: 8px 10px;
  }
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

th, td {
  text-align: left;
  padding: 12px 14px;
  font-size: 0.88rem;
  border-bottom: 1px solid #e5e7eb;
}

th {
  color: #6b7280;
  font-weight: 600;
  background: #fafaf9;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr:nth-child(even) {
  background: #fafafa;
}

tbody tr:hover {
  background: #fefce8;
}

tr:last-child td {
  border-bottom: none;
}

td.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  color: #374151;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #111827;
  border-left: 3px solid #eab308;
  padding-left: 10px;
  padding-top: 22px;
  margin: 36px 0 14px;
  border-top: 1px solid #e5e7eb;
}

.subsection-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: #111827;
  margin: 6px 0 12px;
}

.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.inline-form input {
  width: auto;
  flex: 1;
  min-width: 140px;
}

.inline-form button {
  width: auto;
  margin-top: 0;
  padding: 10px 18px;
}

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

.row-actions button {
  width: auto;
  margin-top: 0;
  padding: 6px 12px;
  font-size: 0.8rem;
  background: #f3f4f6;
  border-color: #e5e7eb;
  white-space: nowrap;
}

.row-actions button:disabled {
  opacity: 0.5;
}

.row-actions button.danger {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
}

.table-scroll {
  overflow-x: auto;
}

/* --- Responsive: narrow phones (~640px and below) --- */
@media (max-width: 640px) {
  .appbar-inner {
    padding: 12px 16px;
  }

  .brand {
    font-size: 1.05rem;
  }

  nav.topnav {
    gap: 0;
  }

  /* Tap height stays the same as desktop (10px vertical padding) — only width
     shrinks, so links stay easy to hit on a phone even as they get more compact. */
  nav.topnav a {
    padding: 10px 8px;
    font-size: 0.78rem;
  }

  .nav-divider {
    margin: 0 2px;
  }

  .container.wide {
    padding: 18px 14px 48px;
  }

  h1 {
    font-size: 1.5rem;
  }

  .page-head {
    margin-bottom: 20px;
  }

  .geo-map {
    height: 260px;
    margin-bottom: 24px;
  }

  #dashboard-map.geo-map {
    height: 340px;
  }

  .cp-card-grid {
    grid-template-columns: 1fr;
  }

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

  .inline-form {
    flex-direction: column;
  }

  .inline-form input,
  .inline-form button {
    width: 100%;
    flex: none;
  }

  /* Tables keep their natural width and scroll horizontally inside .table-scroll
     instead of squeezing every column down to unreadable widths. */
  .table-scroll table {
    min-width: 560px;
  }

  th, td {
    padding: 10px 12px;
    font-size: 0.82rem;
  }

  .pagination {
    gap: 10px;
  }

  .filters {
    grid-template-columns: 1fr;
  }
}

/* --- Responsive: very narrow phones (~380px and below) --- */
@media (max-width: 380px) {
  nav.topnav a {
    padding: 10px 6px;
    font-size: 0.72rem;
  }

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

/* --- Dark mode (check-in page only; toggled + remembered per device) ---
   True black backgrounds are deliberate: the guard phones are AMOLED, where a
   black pixel draws essentially no power, so a dark check-in screen that's woken
   dozens of times a shift meaningfully helps battery life. */
.theme-toggle {
  width: auto;
  margin: 18px auto 0;
  display: block;
  padding: 9px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  color: #6b7280;
}

html.theme-dark body {
  background: #000000;
  color: #d1d5db;
}

html.theme-dark .appbar {
  background: #000000;
  border-bottom: 1px solid #1f1f1f;
}

html.theme-dark h1,
html.theme-dark .checkin-card h1 {
  color: #f5f5f5;
}

html.theme-dark label {
  color: #9ca3af;
}

html.theme-dark .card {
  background: #0d0d0d;
  border-color: #262626;
  box-shadow: none;
}

html.theme-dark select,
html.theme-dark input {
  background-color: #1a1a1a;
  border-color: #333333;
  color: #e5e7eb;
  box-shadow: none;
}

html.theme-dark select:focus,
html.theme-dark input:focus {
  border-color: #eab308;
  box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.18);
}

/* Primary check-in button keeps its yellow — high contrast on black is good here. */
html.theme-dark button:disabled {
  background: #1a1a1a;
  border-color: #333333;
  color: #6b7280;
}

html.theme-dark .theme-toggle,
html.theme-dark .corner-logout {
  background: #1a1a1a;
  border-color: #333333;
  color: #9ca3af;
}

html.theme-dark .checkpoint-chip,
html.theme-dark .auto-guard {
  background: #2a2000;
  border-color: #5c4700;
  color: #fde68a;
}

html.theme-dark .auto-guard span {
  color: #fde68a;
}

html.theme-dark .status.ok {
  background: #052e16;
  color: #86efac;
}

html.theme-dark .status.error {
  background: #3f1212;
  color: #fca5a5;
}

html.theme-dark .status.pending {
  background: #3a2c05;
  color: #fde047;
}
