:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #657386;
  --line: #d9e1ea;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-2: #1d4ed8;
  --danger: #b42318;
  --ok: #18794e;
  --bg: #eef3f7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Segoe UI, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand,
.topbar a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}

.topbar nav {
  display: flex;
  gap: 18px;
}

main {
  padding: 24px;
}

.home-shell {
  width: min(1040px, 100%);
  margin: 24px auto 0;
  display: grid;
  gap: 22px;
}

.home-visual {
  display: grid;
  place-items: center;
  padding: 18px;
  background: #ffffff;
  border: 1px solid var(--line);
}

.home-visual img {
  width: min(520px, 100%);
  height: auto;
  display: block;
}

.entry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  width: 100%;
}

.single-entry {
  max-width: 520px;
  margin: 0 auto;
}

.entry-panel {
  min-height: 180px;
  padding: 26px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  color: #fff;
  text-decoration: none;
}

.entry-panel.admin {
  background: #1f4f78;
}

.entry-panel.portal {
  background: #157a62;
}

.entry-panel span {
  font-size: 15px;
  opacity: .9;
}

.entry-panel strong {
  font-size: 24px;
  line-height: 1.2;
}

.login-shell,
.portal-shell {
  min-height: calc(100vh - 104px);
  display: grid;
  place-items: center;
}

.portal-stack {
  width: min(560px, 100%);
  display: grid;
  gap: 18px;
}

.portal-stack.wide {
  width: min(720px, 100%);
}

.portal-visual img {
  width: min(360px, 100%);
}

.login-box,
.portal-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 28px;
}

.portal-card {
  margin: 0 auto;
}

.register-card {
  width: 100%;
}

.event-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.event-badge {
  min-height: 46px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: #157a62;
  font-weight: 800;
}

.capture-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.capture-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.capture-panel strong {
  font-size: 15px;
}

.capture-panel span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.camera-mode {
  margin-bottom: 0;
}

.map-preview {
  min-height: 170px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #d9e1ea;
}

.map-preview iframe {
  width: 100%;
  height: 100%;
  min-height: 170px;
  display: block;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.map-preview iframe.ready {
  opacity: 1;
}

.map-pin {
  width: 18px;
  height: 18px;
  position: absolute;
  z-index: 2;
  border: 3px solid #ffffff;
  border-radius: 999px 999px 999px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .32);
  pointer-events: none;
  transform: translate(-50%, -100%) rotate(-45deg);
}

.map-pin::after {
  content: "";
  width: 6px;
  height: 6px;
  position: absolute;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #ffffff;
}

.map-pin.current {
  background: #1d4ed8;
}

.map-pin.zone {
  background: #facc15;
  border-color: #78350f;
}

.map-legend {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.map-legend code {
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-weight: 700;
}

.allowed-zone-data {
  display: none;
}

.legend-dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 50%;
}

.legend-dot.current {
  background: #1d4ed8;
}

.legend-dot.zone {
  background: #facc15;
  border: 1px solid #78350f;
}

.map-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 600;
  background: linear-gradient(135deg, #e9eff5, #cfdbe7);
}

#cameraPreview,
.photo-preview {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #d9e1ea;
}

.signature-panel {
  grid-column: 1 / -1;
}

.signature-canvas {
  width: 100%;
  height: 170px;
  display: block;
  background: #ffffff;
  border: 1px solid var(--line);
  touch-action: none;
}

.signature-actions {
  display: flex;
  justify-content: flex-end;
}

.hidden {
  display: none;
}

h1 {
  margin: 0 0 18px;
  font-size: 26px;
}

h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid #b9c5d2;
  background: #fff;
  color: var(--ink);
}

button {
  min-height: 36px;
  border: 0;
  padding: 8px 14px;
  color: #fff;
  background: var(--accent-2);
  font-weight: 600;
  cursor: pointer;
}

.button {
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 8px 14px;
  color: #fff;
  background: var(--accent-2);
  font-weight: 600;
  text-decoration: none;
}

.button.secondary {
  color: var(--accent-2);
  background: #f8fafc;
  border: 1px solid var(--line);
}

.alert-message,
.status-message,
.portal-result {
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.alert-message,
.portal-result.fail {
  color: var(--danger);
}

.portal-result.ok {
  color: var(--ok);
}

.admin-menu,
.work-surface {
  max-width: 1280px;
  margin: 0 auto;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.menu-grid a {
  padding: 22px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  text-decoration: none;
  font-weight: 700;
}

.surface-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.surface-title a {
  color: var(--accent-2);
  text-decoration: none;
  font-weight: 600;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.create-panel {
  margin-bottom: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.create-panel summary {
  padding: 12px 16px;
  color: var(--accent-2);
  cursor: pointer;
  font-weight: 700;
}

.edit-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  max-height: 260px;
  overflow: auto;
  margin-bottom: 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.edit-grid.compact label {
  margin-bottom: 0;
}

.edit-grid.compact input,
.edit-grid.compact select {
  min-height: 32px;
}

.search-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.search-bar label {
  margin: 0;
}

.search-bar a {
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 8px 14px;
  color: var(--accent-2);
  background: #f8fafc;
  border: 1px solid var(--line);
  text-decoration: none;
  font-weight: 600;
}

.edit-grid h2 {
  grid-column: 1 / -1;
}

.data-table-wrap {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
}

.zone-help {
  padding: 10px 12px;
  margin-bottom: 12px;
  color: var(--muted);
  background: #f8fafc;
  border: 1px solid var(--line);
}

.zone-help code {
  color: var(--accent-2);
  font-weight: 700;
}

.zone-selector {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.zone-selector strong {
  font-size: 14px;
}

.zone-selector label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
  font-weight: 500;
}

.zone-selector input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

.zone-selector.in-table {
  min-width: 260px;
  max-height: 180px;
  overflow: auto;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.page-size-form {
  display: flex;
  align-items: end;
  gap: 8px;
}

.page-size-form label {
  margin: 0;
  min-width: 110px;
}

.page-size-form input {
  min-height: 34px;
  width: 96px;
}

.page-size-form button {
  min-height: 34px;
}

.column-filter-form {
  margin: 0;
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.filter-actions a {
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 8px 14px;
  color: var(--accent-2);
  background: #f8fafc;
  border: 1px solid var(--line);
  text-decoration: none;
  font-weight: 600;
}

.pager div {
  display: flex;
  gap: 8px;
}

.pager a {
  min-height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 7px 12px;
  color: #ffffff;
  background: var(--accent-2);
  text-decoration: none;
  font-weight: 600;
}

.pager a.disabled {
  pointer-events: none;
  opacity: .45;
}

.data-table {
  min-width: 900px;
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

.data-table th {
  background: #f4f7fa;
  position: sticky;
  top: 0;
}

.sort-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.filter-row th {
  top: 37px;
  background: #ffffff;
}

.filter-row input {
  width: 100%;
  min-width: 130px;
  min-height: 32px;
  padding: 6px 8px;
  font-size: 13px;
}

.data-table input {
  min-width: 140px;
}

.zone-map-preview {
  width: 240px;
  height: 150px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #e5edf5;
}

.record-map-preview {
  width: 190px;
  height: 120px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #e5edf5;
}

.record-map-preview iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.zone-map-preview iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.map-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 700;
}

.muted-cell {
  color: var(--muted);
}

.record-photo {
  width: 92px;
  height: 70px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.actions {
  display: flex;
  gap: 8px;
  min-width: 220px;
}

.actions button:last-child {
  background: var(--danger);
}

@media (max-width: 680px) {
  .search-bar {
    grid-template-columns: 1fr;
  }

  .pager,
  .page-size-form,
  .filter-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
