:root {
  --bg: #111418;
  --panel: #1a1e24;
  --panel-2: #232830;
  --border: #2e343d;
  --text: #eef1f4;
  --muted: #9aa4b1;
  --primary: #ff9f0a;
  --primary-text: #1a1204;
  --danger: #ff453a;
  --radius: 12px;
  --panel-width: 360px;
  --sheet-peek: 56px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: normal; }

/* Layout */
.app {
  display: grid;
  grid-template-columns: 1fr var(--panel-width);
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
}
.map-wrap { grid-column: 1; grid-row: 1 / 3; }
.banner, .panel { grid-column: 2; }
.banner {
  grid-row: 1; padding: 12px 16px; font-size: 14px; line-height: 1.4;
  background: #3a2a06; color: #ffe2a8; border-left: 1px solid var(--border); border-bottom: 1px solid #5c430c;
}
.banner a { color: var(--primary); font-weight: 600; }
.map-wrap { position: relative; min-width: 0; }
.map { position: absolute; inset: 0; background: #20252c; }

/* Drawing mode */
.is-drawing .map { cursor: crosshair; touch-action: none !important; }
.is-drawing .leaflet-interactive { pointer-events: none; }
.hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 1000; background: rgba(17, 20, 24, 0.9); padding: 10px 16px;
  border-radius: 999px; font-size: 14px; text-align: center; width: max-content; max-width: calc(100% - 32px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4); pointer-events: none;
}

/* Buttons */
.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; cursor: pointer;
  font-weight: 600; line-height: 1.2; touch-action: manipulation;
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

.map-actions {
  position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 1000; display: flex; gap: 8px;
}
.map-actions .btn { padding: 14px 22px; font-size: 16px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45); white-space: nowrap; }

/* Submission form */
.form-card {
  position: absolute; left: 16px; bottom: 16px; z-index: 1100;
  width: min(380px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.form-card h2 { margin: 0 0 8px; font-size: 17px; }
.form-card label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.form-card input[type="text"], .form-card input[type="datetime-local"], .form-card textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  font-size: 16px; /* 16px stops iOS zooming on focus */
}
.form-card textarea { resize: vertical; }
.form-errors { color: var(--danger); font-size: 14px; margin: 0 0 8px; }
.form-errors:empty { display: none; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.toast {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 1200;
  background: #30d158; color: #06240f; font-weight: 600; padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4); width: max-content; max-width: calc(100% - 32px);
}

/* Timeline panel */
.panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-left: 1px solid var(--border);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 16px; background: none; border: 0; border-bottom: 1px solid var(--border);
  color: inherit; text-align: left; cursor: default;
}
.panel-title { display: flex; flex-direction: column; gap: 2px; }
.panel-title strong { font-size: 18px; }
.panel-chevron { display: none; }
.panel-actions { padding: 12px 16px 4px; }
.btn-block { width: 100%; padding: 12px 18px; }
.panel-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.timeline { list-style: none; margin: 0; padding: 8px; }
.empty { padding: 16px; margin: 0; }
.timeline:has(li) + .empty { display: none; }

.entry {
  display: flex; gap: 12px; padding: 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; outline: none;
}
.entry:hover, .entry:focus-visible { background: var(--panel-2); }
.entry.is-active { background: var(--panel-2); border-color: var(--border); }
.swatch { flex: none; width: 14px; height: 14px; margin-top: 3px; border-radius: 4px; display: inline-block; }
.entry-body { min-width: 0; flex: 1; }
.entry-head { display: flex; justify-content: space-between; gap: 8px; }
.entry-name { overflow-wrap: anywhere; }
.entry-head .muted { white-space: nowrap; font-size: 13px; }
.entry-time { display: block; font-size: 13px; margin-top: 2px; }
.entry-comments { margin: 6px 0 0; font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }

/* Leaflet popup */
.popup strong { display: block; font-size: 14px; }
.popup div { color: #555; font-size: 12px; }
.popup p { margin: 6px 0 0 !important; white-space: pre-line; }

/* Phones: timeline becomes a bottom sheet */
@media (max-width: 767px) {
  .app { display: flex; flex-direction: column; position: relative; overflow: hidden; }
  .banner { flex: none; border-left: 0; padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top)); font-size: 13px; }
  .map-wrap { flex: 1; margin-bottom: var(--sheet-peek); }
  .map-actions { bottom: 20px; }

  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 1050;
    height: var(--sheet-peek); border-left: 0; border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0; box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
    transition: height 0.25s ease; padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.is-expanded { height: 70dvh; }
  .panel-header { cursor: pointer; padding: 10px 16px; min-height: var(--sheet-peek); border-bottom: 0; }
  .panel-title { flex-direction: row; align-items: baseline; gap: 8px; }
  .panel-title strong { font-size: 16px; }
  .panel-chevron {
    display: block; width: 10px; height: 10px; border: solid var(--muted); border-width: 2px 2px 0 0;
    transform: rotate(-45deg); transition: transform 0.25s ease; margin-right: 4px;
  }
  .panel.is-expanded .panel-chevron { transform: rotate(135deg); }
  .panel.is-expanded .panel-header { border-bottom: 1px solid var(--border); }

  .form-card {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 75dvh;
    border-radius: 16px 16px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .has-form .panel { visibility: hidden; }
}

/* Admin */
.admin { padding: 24px; max-width: 1100px; margin: 0 auto; }
.admin a { color: var(--primary); }
.admin table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin th, .admin td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin .comments { max-width: 320px; white-space: pre-line; }
.admin tr.is-hidden td { opacity: 0.5; }
.admin-actions { display: flex; gap: 6px; }
.admin-actions form { margin: 0; }
.notice { color: #30d158; }

.entry-edit {
  margin-top: 8px; padding: 4px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600;
  background: transparent; color: var(--primary); border: 1px solid var(--primary);
}
.entry-edit:hover { background: var(--primary); color: var(--primary-text); }

/* Missing-person appeal at the top of the sidebar */
.appeal { padding: 12px 16px 4px; font-size: 14px; line-height: 1.45; border-bottom: 1px solid var(--border); }
.appeal p { margin: 0 0 8px; }
.appeal-call {
  padding: 10px 12px; border-radius: 8px;
  background: #3a0d0b; border: 1px solid #7a1d17; color: #ffd9d6;
}
.appeal-call a { color: #fff; font-weight: 700; }

/* Shown instead of the map once the search is closed */
.closed { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.closed-banner {
  max-width: 560px; width: 100%; text-align: center; padding: 40px 24px; border-radius: 16px;
  background: #0f3d1e; border: 1px solid #1f7a3d; color: #d6ffe2;
}
.closed-banner h1 { margin: 0 0 8px; font-size: clamp(26px, 6vw, 38px); color: #fff; }
.closed-banner p { margin: 0; font-size: 18px; }
