/* =========================================================
   Obras — folha de estilos
   Pensada para ecrã de telemóvel (375–430 px de largura).
   ========================================================= */

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --ink: #11131a;
  --ink-soft: #6b7180;
  --line: #e3e4e9;
  --accent: #2f6df6;
  --accent-ink: #ffffff;
  --ok: #0f9d6a;
  --warn: #d98416;
  --late: #d93b3b;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;

  --tap: 44px; /* alvo mínimo de toque */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0e12;
    --surface: #171920;
    --surface-2: #21242d;
    --ink: #f2f3f7;
    --ink-soft: #9aa0ae;
    --line: #262932;
    --accent: #5b8cff;
    --accent-ink: #0d0e12;
    --ok: #35c48d;
    --warn: #e8a33d;
    --late: #ef5f5f;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0e12;
  --surface: #171920;
  --surface-2: #21242d;
  --ink: #f2f3f7;
  --ink-soft: #9aa0ae;
  --line: #262932;
  --accent: #5b8cff;
  --accent-ink: #0d0e12;
  --ok: #35c48d;
  --warn: #e8a33d;
  --late: #ef5f5f;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body { overflow-x: hidden; }

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- barra de topo ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(12px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
}
.eyebrow {
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 2px;
}
h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
  font-weight: 650;
  letter-spacing: -0.022em;
  flex: 1;
  min-width: 0;
}
h1.sm { font-size: 20px; }

.back {
  appearance: none;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 16px;
  padding: 6px 8px 6px 0;
  margin-left: -8px;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.back svg { width: 20px; height: 20px; }

.icon-btn {
  appearance: none;
  border: 0;
  background: none;
  color: var(--accent);
  padding: 8px;
  margin-right: -8px;
  min-width: var(--tap);
  min-height: var(--tap);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; }

/* ---------- área de conteúdo ---------- */
main {
  flex: 1;
  padding: 16px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  outline: none;
}

h2 {
  margin: 4px 0 -4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.muted { color: var(--ink-soft); }

.empty {
  text-align: center;
  color: var(--ink-soft);
  font-size: 15px;
  padding: 36px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--r-lg);
}

/* ---------- cartões de número ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 8px;
  text-align: center;
}
.stat b {
  display: block;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat span {
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: .02em;
}
.stat.is-late b { color: var(--late); }

/* ---------- listas ---------- */
.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: inherit;
  font: inherit;
  min-height: var(--tap);
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:active { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.row .name {
  font-size: 16px;
  font-weight: 550;
  letter-spacing: -0.01em;
  margin: 0 0 3px;
}
.row .meta {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

/* ---------- etiquetas de estado ---------- */
.pill {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  padding: 5px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill.ok   { color: var(--ok);   background: color-mix(in srgb, var(--ok) 14%, transparent); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }
.pill.late { color: var(--late); background: color-mix(in srgb, var(--late) 14%, transparent); }

/* ---------- barra de progresso ---------- */
.bar {
  height: 5px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  margin-top: 8px;
}
.bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}
.bar.late > i { background: var(--late); }

/* ---------- painel / ficha ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
}
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  font-size: 15px;
}
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; text-align: right; font-weight: 500; }

/* ---------- botões ---------- */
.cta {
  appearance: none;
  border: 0;
  width: 100%;
  padding: 15px;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  min-height: var(--tap);
  cursor: pointer;
}
.cta:active { opacity: .85; }
.cta.ghost {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--line);
}
.cta.danger { background: none; color: var(--late); border: 1px solid var(--line); }
.cta:disabled { opacity: .45; cursor: default; }

/* ---------- formulário ---------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field > label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink-soft);
}
input, select, textarea {
  font: inherit;
  font-size: 16px; /* 16px evita o zoom automático do iOS ao focar */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 13px 12px;
  width: 100%;
  min-height: var(--tap);
}
textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* escolha segmentada de estado */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  display: grid;
  place-items: center;
  padding: 11px 4px;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
}
.seg input:checked + label { border-color: currentColor; }
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg .s-ok   { color: var(--ok); }
.seg .s-warn { color: var(--warn); }
.seg .s-late { color: var(--late); }
.seg input:checked + .s-ok   { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.seg input:checked + .s-warn { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.seg input:checked + .s-late { background: color-mix(in srgb, var(--late) 12%, transparent); }

/* fotografias */
.photos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.photo {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo button {
  position: absolute;
  top: 4px; right: 4px;
  width: 26px; height: 26px;
  border: 0;
  border-radius: 999px;
  background: rgba(0,0,0,.62);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.photo-add {
  aspect-ratio: 1;
  border: 1px dashed var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  gap: 3px;
  font-size: 11px;
  cursor: pointer;
}
.photo-add svg { width: 22px; height: 22px; }

/* ---------- visitas ---------- */
.visit {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.visit:last-child { border-bottom: 0; }
.visit-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.visit-head time {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  font-variant-numeric: tabular-nums;
}
.visit p { margin: 0; font-size: 14px; line-height: 1.5; }
.visit .thumbs {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.visit .thumbs img {
  width: 56px; height: 56px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

/* ---------- barra de separadores ---------- */
nav {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  padding-bottom: var(--safe-bottom);
}
nav button {
  appearance: none;
  border: 0;
  background: none;
  padding: 9px 0 11px;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--ink-soft);
  font: inherit;
  font-size: 10px;
  letter-spacing: .02em;
  cursor: pointer;
}
nav button[aria-current="page"] { color: var(--accent); }
nav svg { width: 23px; height: 23px; display: block; }

/* ---------- aviso flutuante ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 550;
  padding: 11px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 60;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
