/* theme.css: Feedback Pin. Direction: surveyor's field notebook.
   Signature: the camera readout tag (.fp-readout) under every map screenshot.
   The "Control" section below is self-contained (tokens on .fp-scope) and is also shipped as the
   control's own stylesheet for host pages. */

/* ===== Tokens ===== */
.fp-scope {
  /* palette (light) */
  --bg: #f6f5f1;
  --surface: #ffffff;
  --raised: #fbfaf7;
  --text: #1d2321;
  --muted: #4f5955;
  --border: #d6d3ca;
  --border-strong: #a8a499;
  --accent: #0f6b5c;
  --accent-hover: #0b5a4d;
  --accent-active: #084a3f;
  --accent-soft: #e3f0ec;
  --on-accent: #ffffff;
  --success: #1f7a3d;
  --success-soft: #e6f3ea;
  --warning: #8a5a00;
  --warning-soft: #fbf1dc;
  --danger: #b42318;
  --danger-soft: #fbe9e7;
  --ink: #1d2321;          /* readout tag background */
  --on-ink: #e8ebe7;
  --on-ink-muted: #9fb5ac;
  --scrim: rgb(29 35 33 / 0.45);

  /* type */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: 0.8125rem;  /* 13 */
  --fs-sm: 0.9375rem;  /* 15 */
  --fs-md: 1.0625rem;  /* 17 */
  --fs-lg: 1.25rem;    /* 20 */
  --fs-xl: 1.625rem;   /* 26 */
  --fs-2xl: clamp(2rem, 5.5vw, 2.5rem); /* 32-40 */

  /* space */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  /* shape */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --shadow-1: 0 1px 2px rgb(29 35 33 / 0.08), 0 2px 6px rgb(29 35 33 / 0.06);
  --shadow-2: 0 8px 28px rgb(29 35 33 / 0.18), 0 2px 6px rgb(29 35 33 / 0.08);
  --ring: 0 0 0 3px var(--accent);

  --t-fast: 160ms;
  --t-med: 180ms;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
    .fp-scope {
    --bg: #121614;
    --surface: #1a1f1d;
    --raised: #222826;
    --text: #e8ebe7;
    --muted: #a9b3ae;
    --border: #343b38;
    --border-strong: #56605b;
    --accent: #5cc8b0;
    --accent-hover: #74d4be;
    --accent-active: #8fdecb;
    --accent-soft: #173029;
    --on-accent: #0b1512;
    --success: #6fd08c;
    --success-soft: #16301f;
    --warning: #e7b453;
    --warning-soft: #3a2e12;
    --danger: #ff8a7a;
    --danger-soft: #3a1c19;
    --ink: #0b0f0d;
    --on-ink: #e8ebe7;
    --on-ink-muted: #9fb5ac;
    --scrim: rgb(0 0 0 / 0.6);
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-2: 0 10px 30px rgb(0 0 0 / 0.55);
  }
}

/* ===== Control ===== */
/* Everything below is self-contained for host pages; scope with .fp-scope. */
.fp-scope {
  font-family: var(--font-sans);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.fp-scope *, .fp-scope *::before, .fp-scope *::after { box-sizing: border-box; }
.fp-scope :focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* map button */
.fp-ctrl-wrap { position: relative; }
.maplibregl-ctrl.fp-ctrl-wrap { margin: 0 var(--s-3) var(--s-3) 0; }
.fp-ctrl {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-width: 44px; height: 44px;
  margin: 0;
  padding: 0 var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-1);
  font: 600 var(--fs-sm)/1 var(--font-sans);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.fp-ctrl svg { width: 22px; height: 22px; flex: none; }
.fp-ctrl:hover { background: var(--accent-soft); border-color: var(--accent); }
.fp-ctrl:active { transform: scale(0.96); }
.fp-ctrl[aria-busy="true"] { cursor: progress; color: var(--muted); }
.fp-ctrl:disabled { opacity: 1; }
.fp-ctrl-label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
@media (min-width: 640px) {
  .fp-ctrl { padding: 0 var(--s-4) 0 var(--s-3); }
  .fp-ctrl-label { position: static; width: auto; height: auto; overflow: visible; clip: auto; color: var(--text); }
}

.fp-spinner {
  width: 20px; height: 20px; flex: none;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: fp-spin 0.8s linear infinite;
}
@keyframes fp-spin { to { transform: rotate(360deg); } }

/* capture-failed callout above the button */
.fp-toast {
  position: absolute;
  right: 0; bottom: calc(100% + var(--s-2));
  display: flex; align-items: flex-start; gap: var(--s-2);
  width: max-content; max-width: min(18rem, calc(100vw - 32px));
  padding: var(--s-2) var(--s-1) var(--s-2) var(--s-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm);
  line-height: 1.4;
  animation: fp-rise var(--t-med) var(--ease) both;
}
.fp-toast p { margin: 0; padding-block: var(--s-2); }
.fp-toast .fp-close { margin: -2px 0; }

/* dialog */
dialog.fp-dialog {
  width: min(30rem, calc(100vw - 32px));
  max-width: none;
  max-height: min(92dvh, 52rem);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-md);
  line-height: 1.5;
  overflow: hidden;
}
dialog.fp-dialog[open] {
  display: flex; flex-direction: column;
  animation: fp-rise var(--t-med) var(--ease) both;
}
dialog.fp-dialog::backdrop { background: var(--scrim); }
@media (max-width: 639.98px) {
  dialog.fp-dialog {
    width: 100vw;
    margin: auto 0 0;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: 0;
    max-height: 92dvh;
  }
  dialog.fp-dialog[open] { animation-name: fp-sheet; }
}
@keyframes fp-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fp-sheet { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.fp-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-2) var(--s-2) var(--s-2) var(--s-5);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.fp-title { margin: 0; font-size: var(--fs-lg); font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.fp-close {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; min-height: 44px; flex: none;
  padding: 0;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease);
}
.fp-close svg { width: 20px; height: 20px; }
.fp-close:hover { background: var(--raised); color: var(--text); }
.fp-close:active { background: var(--border); }

.fp-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s-4) var(--s-5) var(--s-2);
}

/* preview + the readout tag (signature) */
.fp-preview {
  margin: 0 0 var(--s-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--raised);
}
.fp-preview img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 40dvh;
  object-fit: contain;
  background: var(--raised);
}
@media (min-width: 640px) { .fp-preview img { max-height: 18rem; } }

.fp-readout {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: var(--s-1) var(--s-3);
  margin: 0;
  padding: var(--s-2) var(--s-3);
  border-left: 3px solid var(--accent);
  background: var(--ink);
  color: var(--on-ink);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}
.fp-readout-item { white-space: nowrap; }
.fp-k {
  margin-right: var(--s-1);
  color: var(--on-ink-muted);
  font-size: 0.85em;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.fp-v { color: var(--on-ink); }
.fp-readout :focus-visible { outline-color: var(--on-ink); }

/* field */
.fp-field { margin: 0 0 var(--s-3); }
.fp-label {
  display: block;
  margin-bottom: var(--s-2);
  font-size: var(--fs-md);
  font-weight: 700;
}
.fp-textarea {
  display: block;
  width: 100%;
  min-height: calc(4 * 1.5em + 2 * var(--s-3));
  padding: var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: max(16px, var(--fs-md)); /* 16px+ stops iOS zoom on focus */
  line-height: 1.5;
  resize: vertical;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.fp-textarea::placeholder { color: var(--muted); opacity: 1; }
.fp-textarea:hover { border-color: var(--accent); }
.fp-textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.fp-textarea[aria-invalid="true"] { border-color: var(--danger); }
.fp-textarea[aria-invalid="true"]:focus-visible { box-shadow: 0 0 0 3px var(--danger); }
.fp-textarea:disabled { opacity: 0.6; cursor: not-allowed; }

.fp-hint {
  display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-3);
  min-height: 1.5em;
  margin-top: var(--s-1);
  font-size: var(--fs-sm);
  line-height: 1.4;
}
.fp-error { color: var(--danger); font-weight: 600; }
.fp-count {
  margin-left: auto;
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.fp-count[data-level="near"] { color: var(--warning); font-weight: 600; }
.fp-count[data-level="over"] { color: var(--danger); font-weight: 700; }

/* disclosure */
.fp-notice {
  display: flex; gap: var(--s-2); align-items: flex-start;
  margin: 0 0 var(--s-3);
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.45;
}
.fp-notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; color: var(--accent); }

/* status line, space reserved */
.fp-status {
  min-height: 1.5em;
  margin: 0 0 var(--s-2);
  font-size: var(--fs-sm);
  line-height: 1.45;
}
.fp-status:empty { margin: 0; }
.fp-status[data-tone] {
  padding: var(--s-3) var(--s-4);
  border-left: 3px solid currentColor;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  animation: fp-fade var(--t-med) var(--ease) both;
}
.fp-status[data-tone="error"] { color: var(--danger); background: var(--danger-soft); }
.fp-status[data-tone="warning"] { color: var(--warning); background: var(--warning-soft); }
.fp-status[data-tone="success"] { color: var(--success); background: var(--success-soft); }
@keyframes fp-fade { from { opacity: 0; } to { opacity: 1; } }

/* actions */
.fp-actions {
  display: flex; gap: var(--s-2); justify-content: flex-end;
  flex: none;
  padding: var(--s-3) var(--s-5) max(var(--s-4), env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
@media (max-width: 639.98px) {
  .fp-actions > * { flex: 1 1 0; }
}
.fp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 48px;
  min-width: 8.5rem; /* "Send report" / "Sending…" / "Send again" keep one width */
  margin: 0;
  padding: 0 var(--s-5);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font: 650 var(--fs-md)/1.2 var(--font-sans);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.fp-btn:active { transform: translateY(1px); }
.fp-btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-1); }
.fp-btn-primary:hover { background: var(--accent-hover); }
.fp-btn-primary:active { background: var(--accent-active); }
.fp-btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.fp-btn-secondary:hover { background: var(--raised); border-color: var(--accent); }
.fp-btn-secondary:active { background: var(--border); }
.fp-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.fp-btn[aria-busy="true"] { opacity: 0.85; cursor: progress; }
.fp-btn .fp-spinner { width: 18px; height: 18px; border-color: rgb(255 255 255 / 0.35); border-top-color: var(--on-accent); }

/* sent state */
.fp-sent {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--s-7) var(--s-5) var(--s-5);
}
.fp-check {
  display: grid; place-items: center;
  width: 64px; height: 64px;
  margin-bottom: var(--s-4);
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success);
  animation: fp-pop var(--t-fast) var(--ease) both;
}
.fp-check svg { width: 32px; height: 32px; }
.fp-sent .fp-title { font-size: var(--fs-xl); margin-bottom: var(--s-2); }
.fp-sent p { margin: 0 0 var(--s-5); max-width: 28ch; color: var(--muted); }
.fp-sent .fp-btn { width: 100%; max-width: 16rem; }
@keyframes fp-pop { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  .fp-scope, .fp-scope *, .fp-scope *::before, .fp-scope *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .fp-spinner { animation: none; border-top-color: var(--accent); border-right-color: var(--accent); }
}

/* Control layout */
.fp-scope .fp-visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.fp-scope .fp-btn[aria-busy="true"] { padding-inline: var(--s-2); }
.fp-scope .fp-status:focus { scroll-margin-block: var(--s-2); }
.fp-scope .fp-textarea { overflow-wrap: anywhere; }
@media (max-width: 639.98px) {
  .fp-scope .fp-ctrl { width: 44px; padding: 0; }
  .fp-scope .fp-actions .fp-btn { min-width: 0; padding-inline: var(--s-2); }
  .fp-scope .fp-head, .fp-scope .fp-body, .fp-scope .fp-actions { padding-inline: var(--s-4); }
}
