body {
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

main.admin-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height, 136px));
  padding: 24px;
  overflow: hidden;
}

.admin-list-panel,
.admin-editor {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(31, 41, 51, 0.06);
}

/* One merged header block for the sidebar: title/status, page-level actions,
   and the project search/add controls all stack here instead of splitting
   into two bordered sections — flex's default cross-axis stretch is what
   makes the search input and buttons fill the column without extra CSS. */
.admin-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.admin-toolbar h1 {
  margin: 0;
  color: var(--city-blue);
  font-size: clamp(1.1rem, 2vw, 1.35rem);
}

.admin-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

/* Save Changes is the one action worth a full-width, high-emphasis button —
   everything else in the toolbar (search+add, reload/export/print) is
   secondary and stays visually lighter so the sidebar reads as one compact
   block instead of a stack of equally-loud buttons. */
.admin-save-action {
  width: 100%;
}

.admin-search-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.admin-search-row input {
  flex: 1 1 auto;
}

.admin-icon-button {
  flex: 0 0 auto;
  width: 42px;
  padding: 0;
  display: grid;
  place-items: center;
}

.admin-icon-button svg {
  width: 18px;
  height: 18px;
}

/* Reload/Export JSON/Print Book are infrequent, lower-stakes actions — one
   slim row of understated (not full button-weight) controls instead of
   three of admin.css's normal bordered buttons stacked up. */
.admin-actions-secondary {
  display: flex;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.admin-actions-secondary button,
.admin-actions-secondary a {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 8px;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}

.admin-actions-secondary button + button,
.admin-actions-secondary button + a,
.admin-actions-secondary a + a {
  border-left: 1px solid var(--border);
}

.admin-actions-secondary button:hover,
.admin-actions-secondary a:hover,
.admin-actions-secondary button:focus-visible,
.admin-actions-secondary a:focus-visible {
  background: var(--accent-soft);
  color: var(--city-blue);
}

.editor-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.admin-list-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.admin-list-panel input,
.field-control,
.field-textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.admin-list-panel input {
  min-height: 42px;
  padding: 9px 10px;
}

/* Slightly shorter than the sidebar's search input — the project editor has
   a dozen-plus of these stacked, so shaving a few px each adds up to real
   scroll savings without the fields feeling cramped. */
.field-control {
  min-height: 38px;
  padding: 7px 10px;
}

.field-textarea {
  min-height: 88px;
  padding: 10px;
  resize: vertical;
}

.project-count {
  padding: 10px 16px;
  color: var(--muted);
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.admin-project-list {
  display: grid;
  /* align-content defaults to `normal`, which a grid container resolves as
     `stretch` — with few rows inside this flex:1 (tall, mostly-empty-when-
     filtered) container, that stretches each auto-sized row to fill an
     even share of all the leftover height instead of leaving them at their
     natural size, packed at the top. */
  align-content: start;
  gap: 10px;
  min-height: 0;
  margin: 0;
  padding: 12px;
  list-style: none;
  flex: 1 1 auto;
  overflow: auto;
}

/* Individual rows reuse .project-list-item and friends from styles.css so
   the admin list reads as the same list as the public map. */

.admin-editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 16px;
  overflow: hidden;
}

#projectEditorForm {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 0;
  overflow: auto;
  padding-right: 4px;
}

.editor-title {
  margin: 0 0 10px;
  color: var(--city-blue);
  font-size: clamp(1.1rem, 1.6vw, 1.5rem);
  line-height: 1.2;
  text-align: center;
}

.editor-title--empty {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
}

.admin-photo-frame {
  position: relative;
  width: min(100%, 300px);
  min-height: 130px;
  margin-bottom: 12px;
  margin-inline: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(135deg, #dfeff4 0%, #f8fafc 100%);
}

.admin-photo-frame img {
  width: 100%;
  height: 100%;
  min-height: 130px;
  display: block;
  object-fit: cover;
  transition: opacity 0.2s ease;
}

.admin-photo-frame.is-loading img {
  opacity: 0.35;
}

.admin-photo-loader {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
}

.admin-photo-loader::before {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(31, 41, 51, 0.18);
  border-top-color: var(--city-blue);
  border-radius: 999px;
  content: "";
  animation: admin-photo-spin 0.8s linear infinite;
}

.admin-photo-frame.is-loading .admin-photo-loader {
  display: grid;
}

@keyframes admin-photo-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Matches .admin-photo-frame's width so the Photo URL/Upload control reads
   as one cluster with the preview image above it, instead of a full-width
   field down in the general grid. */
.admin-photo-controls {
  width: min(100%, 300px);
  margin: 0 auto 14px;
}

.editor-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* `display: grid`/`flex` above beats the browser's default [hidden] rule at
   equal specificity (author styles always win over the UA stylesheet), so
   without this the Delete button and field grid stayed visible even while
   `hidden` was set with no project selected. */
.editor-fields[hidden],
.editor-actions[hidden] {
  display: none;
}

/* Same [hidden]-vs-author-styles issue as above — .city-nav a (styles.css)
   sets display: inline-flex, which would otherwise keep Manage Users
   visible in the header nav even while hidden for non-admins. */
#manageUsersButton[hidden] {
  display: none;
}

.field-group {
  display: grid;
  gap: 5px;
}

.field-group--wide {
  grid-column: 1 / -1;
}

.field-group label {
  color: var(--city-ink);
  font-weight: 700;
}

.field-checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  cursor: pointer;
}

.field-checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--city-blue);
}

.field-hint {
  color: var(--muted);
  font-size: 0.85rem;
}

.field-hint--warning {
  color: #b45309;
  font-weight: 600;
}

.photo-upload {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.photo-upload__input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.photo-upload__button {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--city-blue);
  border-radius: 4px;
  background: #fff;
  color: var(--city-blue);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
}

.photo-upload__button:hover {
  background: var(--accent-soft);
}

.photo-upload__button.is-disabled {
  border-color: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

.photo-upload__remove {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid #dc2626;
  border-radius: 4px;
  background: #fff;
  color: #b91c1c;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
}

.photo-upload__remove:hover,
.photo-upload__remove:focus-visible {
  background: #fee2e2;
  border-color: #b91c1c;
  color: #991b1b;
}

.photo-current-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}

.photo-upload__status {
  color: var(--muted);
  font-size: 0.85rem;
}

.photo-upload__status.is-error {
  color: #b91c1c;
  font-weight: 600;
}

.field-section-title {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--border);
  color: var(--city-blue);
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-section-title:first-child {
  margin-top: 0;
}

.location-section {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}

.location-fields-col {
  display: grid;
  align-content: start;
  gap: 10px;
}

.location-map-col {
  display: grid;
}

.address-input-row {
  display: flex;
  gap: 8px;
}

.address-input-row .field-control {
  flex: 1;
  min-width: 0;
}

.address-search-button {
  padding: 6px 14px;
  border: 1px solid var(--city-blue);
  border-radius: 4px;
  background: var(--city-blue);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.address-search-button:hover,
.address-search-button:focus-visible {
  filter: brightness(1.1);
}

.address-search-button:disabled {
  opacity: 0.6;
  cursor: default;
}

/* :not([hidden]) rather than a plain selector — an author-stylesheet
   `display` rule otherwise beats the browser's own `[hidden] { display:
   none }` default, which left this rendering as an empty bordered box
   whenever it had no results instead of actually disappearing. */
.location-address-results:not([hidden]) {
  display: grid;
  gap: 4px;
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px;
  list-style: none;
}

.location-address-result {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border: none;
  border-radius: 3px;
  background: none;
  text-align: left;
  font-size: 0.85rem;
  line-height: 1.3;
  cursor: pointer;
}

.location-address-result:hover,
.location-address-result:focus-visible {
  background: #eff6ff;
  color: var(--city-blue);
}

.location-preview-map {
  width: 100%;
  aspect-ratio: 5 / 3;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #e2e8f0;
  cursor: crosshair;
}

/* A plain button under the map rather than an overlay on top of it, so it
   doesn't have to compete with Leaflet's own pane/control stacking. */
.location-preview-clear {
  justify-self: start;
  padding: 6px 12px;
  border: 1px solid #dc2626;
  border-radius: 4px;
  background: #fff;
  color: #b91c1c;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.location-preview-clear:hover,
.location-preview-clear:focus-visible {
  background: #fee2e2;
  border-color: #b91c1c;
  color: #991b1b;
}

.editor-actions {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.primary-action {
  border-color: var(--city-blue);
  background: var(--city-blue);
  color: #fff;
}

.primary-action:hover,
.primary-action:focus-visible {
  background: #245f73;
  color: #fff;
}

.danger-action {
  border-color: #dc2626;
  color: #b91c1c;
}

.danger-action:hover,
.danger-action:focus-visible {
  background: #fee2e2;
  border-color: #b91c1c;
  color: #991b1b;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.user-manager-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-manager-modal[hidden] {
  display: none;
}

.user-manager-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
}

.user-manager-modal__content {
  position: relative;
  width: min(92vw, 480px);
  max-height: 88vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 72px rgba(15, 23, 42, 0.28);
}

.user-manager-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.user-manager-modal__header h2 {
  margin: 0;
  color: var(--city-blue);
  font-size: 1.2rem;
}

#userManagerClose {
  min-height: 32px;
  min-width: 32px;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

#userManagerClose:hover,
#userManagerClose:focus-visible {
  color: var(--text);
}

.user-manager-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.user-row__name {
  font-weight: 700;
  color: var(--city-ink);
  margin-right: auto;
}

.user-row__you {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.82rem;
}

.user-row__role {
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  font-size: 0.85rem;
}

.user-row__reset,
.user-row__remove {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 0.82rem;
}

.user-manager-add-form {
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.user-manager-add-form h3 {
  margin: 0;
  color: var(--city-blue);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#sessionExpiredForm {
  display: grid;
  gap: 10px;
}

.session-expired-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

@media (max-width: 900px) {
  main.admin-shell {
    padding: 16px 0.75rem 20px;
    height: auto;
    min-height: calc(100vh - var(--header-height, 136px));
    overflow: auto;
  }

  .editor-actions {
    justify-content: stretch;
  }

  .editor-actions button {
    flex: 1 1 140px;
    text-align: center;
  }

  .admin-layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .admin-project-list {
    min-height: 240px;
    max-height: 320px;
  }

  .editor-fields {
    grid-template-columns: 1fr;
  }

  .location-section {
    grid-template-columns: 1fr;
  }

  .location-preview-map {
    aspect-ratio: 16 / 9;
  }
}

.login-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-height, 96px));
  padding: 24px;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(100%, 360px);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 10px rgba(31, 41, 51, 0.06);
}

.login-card h1 {
  margin: 0;
  color: var(--city-blue);
  font-size: 1.4rem;
}

.login-card .field-hint {
  margin: -6px 0 4px;
}

.login-card .primary-action {
  margin-top: 4px;
}

.login-error {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #dc2626;
  border-radius: 4px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 0.88rem;
  font-weight: 600;
}
