/* Entregation — base: tokens, tipografia, formulários, botões, diálogos.
   Layout do mapa, sheet, cartão e pinos ficam em map.css. */

:root {
  color-scheme: light;
  --surface: #ffffff;
  --surface-2: #f1f3f4;
  --surface-3: #e8eaed;
  --text: #1f1f1f;
  --text-2: #5f6368;
  --line: #dadce0;
  --primary: #1a73e8;
  --primary-hover: #1765cc;
  --on-primary: #ffffff;
  --tonal: #e8f0fe;
  --on-tonal: #0b57d0;
  --ok: #137333;
  --ok-tonal: #e6f4ea;
  --bad: #c5221f;
  --bad-tonal: #fce8e6;
  --warn-tonal: #fef7e0;
  --on-warn: #7a4f01;
  --focus: #0b57d0;
  --scrim: rgba(32, 33, 36, .4);
  --shadow-1: 0 1px 2px rgba(60, 64, 67, .3), 0 1px 3px 1px rgba(60, 64, 67, .15);
  --shadow-2: 0 1px 3px rgba(60, 64, 67, .3), 0 4px 8px 3px rgba(60, 64, 67, .15);
  --shadow-3: 0 4px 4px rgba(60, 64, 67, .3), 0 8px 12px 6px rgba(60, 64, 67, .15);
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 28px;
  --font: "Google Sans", Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.2, 0, 0, 1);
  --ease-out: cubic-bezier(.05, .7, .1, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

/* Tema escuro: segue o sistema (auto) ou a escolha no menu (data-theme no <html>). */
:root[data-theme="dark"] {
    color-scheme: dark;
    --surface: #1f1f1f;
    --surface-2: #2a2a2c;
    --surface-3: #37373a;
    --text: #e8eaed;
    --text-2: #a8adb3;
    --line: #3c4043;
    --primary: #a8c7fa;
    --primary-hover: #c2d7fb;
    --on-primary: #062e6f;
    --tonal: #283a57;
    --on-tonal: #d3e3fd;
    --ok: #6dd58c;
    --ok-tonal: #1e3a26;
    --bad: #f2b8b5;
    --bad-tonal: #4a2321;
    --warn-tonal: #44380f;
    --on-warn: #ffdf99;
    --focus: #a8c7fa;
    --scrim: rgba(0, 0, 0, .55);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .5), 0 1px 3px 1px rgba(0, 0, 0, .3);
    --shadow-2: 0 1px 3px rgba(0, 0, 0, .5), 0 4px 8px 3px rgba(0, 0, 0, .3);
    --shadow-3: 0 4px 4px rgba(0, 0, 0, .5), 0 8px 12px 6px rgba(0, 0, 0, .3);
  }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface: #1f1f1f;
    --surface-2: #2a2a2c;
    --surface-3: #37373a;
    --text: #e8eaed;
    --text-2: #a8adb3;
    --line: #3c4043;
    --primary: #a8c7fa;
    --primary-hover: #c2d7fb;
    --on-primary: #062e6f;
    --tonal: #283a57;
    --on-tonal: #d3e3fd;
    --ok: #6dd58c;
    --ok-tonal: #1e3a26;
    --bad: #f2b8b5;
    --bad-tonal: #4a2321;
    --warn-tonal: #44380f;
    --on-warn: #ffdf99;
    --focus: #a8c7fa;
    --scrim: rgba(0, 0, 0, .55);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .5), 0 1px 3px 1px rgba(0, 0, 0, .3);
    --shadow-2: 0 1px 3px rgba(0, 0, 0, .5), 0 4px 8px 3px rgba(0, 0, 0, .3);
    --shadow-3: 0 4px 4px rgba(0, 0, 0, .5), 0 8px 12px 6px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  background: var(--surface-2);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; }
h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -.01em; }

svg:not(.leaflet-zoom-animated) { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }

/* ---------- campos ---------- */
.field {
  display: flex; flex-direction: column; gap: 6px;
  font-size: .8125rem; font-weight: 500; color: var(--text-2);
  margin: 0 0 12px;
}
input[type="text"], input[type="number"], input[type="search"], input[type="time"], select, textarea, .note {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font: inherit; font-size: 1rem; font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; line-height: 1.5; min-height: 160px; }
input:focus, select:focus, textarea:focus, .note:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
input::placeholder, textarea::placeholder { color: var(--text-2); opacity: .8; }
input[type="file"] { font: inherit; font-size: .875rem; color: var(--text); }

.check { display: flex; align-items: center; gap: 10px; min-height: 48px; font-size: .9375rem; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.btn-row.end { justify-content: flex-end; margin-top: 16px; }

.hint { color: var(--text-2); font-size: .8125rem; margin: 4px 0 8px; }

/* ---------- botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  font: inherit; font-size: .9375rem; font-weight: 600; letter-spacing: .01em;
  color: var(--on-tonal); background: var(--tonal);
  border: 0; border-radius: 999px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, box-shadow .15s, transform .1s var(--ease);
  user-select: none;
}
.btn:hover { filter: brightness(.97); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; transform: none; filter: none; }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); filter: none; box-shadow: var(--shadow-1); }
.btn.tonal { background: var(--tonal); color: var(--on-tonal); }
.btn.text { background: transparent; color: var(--primary); padding: 0 12px; }
.btn.text:hover { background: var(--tonal); }
.btn.ok { background: var(--ok); color: var(--surface); }
.btn.bad-outline { background: transparent; color: var(--bad); box-shadow: inset 0 0 0 1px var(--line); }
.btn.danger { background: var(--bad-tonal); color: var(--bad); }
.btn.active { background: var(--primary); color: var(--on-primary); }
.btn svg { width: 18px; height: 18px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 48px; height: 48px; flex: 0 0 auto;
  padding: 0; border: 0; border-radius: 50%;
  color: var(--text-2); background: transparent; cursor: pointer;
  transition: background-color .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  font: inherit; font-size: .875rem; font-weight: 500;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  cursor: pointer; white-space: nowrap;
  transition: background-color .15s;
}
.chip:hover { background: var(--surface-2); }
.chip:disabled { opacity: .45; cursor: default; }
.chip svg { width: 18px; height: 18px; color: var(--primary); }
.chip.danger { color: var(--bad); }

.badge { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.b-pending { background: var(--tonal); color: var(--on-tonal); }
.b-delivered { background: var(--ok-tonal); color: var(--ok); }
.b-failed { background: var(--bad-tonal); color: var(--bad); }

/* ---------- progresso ---------- */
.progress { display: flex; align-items: center; gap: 12px; }
.progress-track { flex: 1; height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--ok); border-radius: inherit; transition: width .5s var(--ease-out); }
.progress-text { font-size: .8125rem; font-weight: 600; color: var(--text-2); white-space: nowrap; }

/* ---------- diálogos ---------- */
.modal-dialog {
  border: 0; padding: 0;
  width: min(520px, calc(100% - 24px)); max-height: calc(100% - 48px);
  border-radius: var(--r-xl);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-3);
}
.modal-dialog[open] { animation: dlg-in .25s var(--ease-out); }
.modal-dialog::backdrop { background: var(--scrim); }
.modal-content { padding: 20px 24px 20px; }
.modal-content h2 { margin-bottom: 8px; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(16px) scale(.98); } }

.canvas-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); margin: 12px 0; touch-action: none; overflow: hidden; }
#signCanvas { width: 100%; height: 200px; display: block; touch-action: none; cursor: crosshair; }

.proof-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.proof-head h2 { margin: 0; }
.proof-body { font-size: .9375rem; line-height: 1.5; }
.proof-section { padding: 10px 0; border-bottom: 1px solid var(--line); }
.proof-section:last-child { border-bottom: 0; }
.proof-label { display: block; font-size: .75rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
.proof-val { display: block; font-size: 1rem; font-weight: 500; overflow-wrap: anywhere; }
.proof-img { max-width: 100%; max-height: 220px; border-radius: var(--r-sm); margin-top: 6px; display: block; }
.proof-signature { background: #fff; padding: 6px; border-radius: var(--r-sm); max-width: 100%; max-height: 120px; display: block; margin-top: 6px; }
.proof-offline-badge { display: inline-block; margin-top: 10px; padding: 4px 10px; background: var(--ok-tonal); color: var(--ok); border-radius: 999px; font-size: .8125rem; font-weight: 600; }

@media print {
  .app { display: none !important; }
  .modal-dialog { box-shadow: none; position: static; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
