/* ============================================================
   Rota — controle de visitas em imobiliárias
   Direção visual: "caderneta de campo". Papel claro para leitura
   sob sol, dados sempre em monoespaçada (coordenada é dado, não
   texto), e o carimbo de comprovação como elemento de assinatura.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@600;700&family=Instrument+Sans:wght@400;500;600&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  --paper: #EFF2F1;
  --surface: #FFFFFF;
  --surface-2: #F7F9F8;
  --ink: #0F1418;
  --slate: #5B6672;
  --slate-2: #8A939D;
  --line: #DBE0E0;
  --line-strong: #C3CACA;

  --carimbo: #26418F;
  --carimbo-soft: #E7ECF7;
  --ok: #16785D;
  --ok-soft: #E1F0EB;
  --alerta: #AE3A1E;
  --alerta-soft: #F8E9E4;
  --aviso: #8A6100;
  --aviso-soft: #FBF0DA;

  --r: 6px;
  --r-lg: 10px;
  --shadow: 0 1px 2px rgba(15, 20, 24, .06), 0 8px 24px -16px rgba(15, 20, 24, .28);

  --display: 'Archivo', system-ui, sans-serif;
  --body: 'Instrument Sans', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;

  --tab-h: 62px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { font-family: var(--display); font-weight: 700; letter-spacing: -.015em; margin: 0; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .6rem; }
a { color: var(--carimbo); }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.eyebrow {
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--slate-2);
  font-weight: 600;
}

/* ---------------- Estrutura ---------------- */

#app { min-height: 100dvh; }

.shell { display: block; }

.rail { display: none; }

.main {
  padding: 16px 16px calc(var(--tab-h) + 28px);
  max-width: 780px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar .brand {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -.02em;
  font-size: 1.02rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  width: 22px; height: 22px; border-radius: 5px;
  background: var(--carimbo);
  display: grid; place-items: center;
  color: #fff; font-family: var(--mono); font-size: .66rem; font-weight: 600;
}

.topbar .spacer { flex: 1; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--carimbo-soft); color: var(--carimbo);
  display: grid; place-items: center;
  font-family: var(--display); font-weight: 700; font-size: .8rem;
  border: 1px solid var(--line); cursor: pointer;
}

/* Barra de abas (mobile) */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
}

.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; text-decoration: none; color: var(--slate-2);
  font-size: .66rem; font-weight: 500; letter-spacing: .01em;
}
.tabbar a svg { width: 21px; height: 21px; }
.tabbar a[aria-current="page"] { color: var(--carimbo); }
.tabbar a[aria-current="page"] svg { stroke-width: 2.1; }

@media (min-width: 920px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100dvh; }
  .rail {
    display: block; border-right: 1px solid var(--line); background: var(--surface);
    padding: 18px 14px; position: sticky; top: 0; height: 100dvh;
  }
  .rail nav { display: flex; flex-direction: column; gap: 2px; margin-top: 18px; }
  .rail nav a {
    display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: var(--r);
    text-decoration: none; color: var(--slate); font-weight: 500; font-size: .92rem;
  }
  .rail nav a svg { width: 18px; height: 18px; }
  .rail nav a:hover { background: var(--surface-2); color: var(--ink); }
  .rail nav a[aria-current="page"] { background: var(--carimbo-soft); color: var(--carimbo); font-weight: 600; }
  .tabbar { display: none; }
  .main { padding: 24px 32px 60px; max-width: 900px; margin: 0; }
  .topbar { padding: 14px 32px; }
  .topbar .brand { display: none; }
}

/* ---------------- Cartões e listas ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 14px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head .spacer { flex: 1; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit; width: 100%; text-align: left;
  background: none; border-left: 0; border-right: 0; border-top: 0; font: inherit; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; font-size: .94rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { color: var(--slate); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .chev { color: var(--slate-2); flex-shrink: 0; }

.empty {
  text-align: center; padding: 34px 20px; color: var(--slate);
}
.empty h3 { margin-bottom: 6px; }
.empty p { font-size: .88rem; }

/* ---------------- Botões ---------------- */

.btn {
  appearance: none; border: 1px solid transparent; border-radius: var(--r);
  font-family: var(--body); font-size: .92rem; font-weight: 600;
  padding: 11px 16px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--carimbo); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1d3576; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--alerta-soft); color: var(--alerta); border-color: #E9C9BE; }
.btn-block { width: 100%; }
.btn-lg { padding: 15px 20px; font-size: 1rem; }
.btn svg { width: 18px; height: 18px; }

.btn-checkin {
  width: 100%; padding: 20px; border-radius: var(--r-lg);
  background: var(--carimbo); color: #fff; border: 0; cursor: pointer;
  display: flex; align-items: center; gap: 14px; text-align: left;
  font-family: var(--display); font-weight: 700; font-size: 1.1rem;
  box-shadow: var(--shadow);
}
.btn-checkin .sub { font-family: var(--body); font-weight: 400; font-size: .8rem; opacity: .78; display: block; letter-spacing: 0; }
.btn-checkin .ico {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,.16); display: grid; place-items: center;
}
.btn-checkin .ico svg { width: 22px; height: 22px; }

/* ---------------- Formulários ---------------- */

.field { margin-bottom: 13px; }
.field label {
  display: block; font-size: .78rem; font-weight: 600; color: var(--slate);
  margin-bottom: 5px; letter-spacing: .01em;
}
.field .hint { font-size: .74rem; color: var(--slate-2); margin-top: 4px; }

input, select, textarea {
  width: 100%; font-family: var(--body); font-size: .95rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r); padding: 11px 12px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .row:focus-visible {
  outline: 2px solid var(--carimbo); outline-offset: 1px;
}
textarea { min-height: 82px; resize: vertical; }
input[type="file"] { padding: 8px; font-size: .85rem; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%235B6672' stroke-width='2'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
@media (max-width: 520px) { .grid-3 { grid-template-columns: 1fr 1fr; } }

fieldset { border: 0; padding: 0; margin: 0 0 4px; }
legend { padding: 0; }

.section-title {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .16em; text-transform: uppercase;
  color: var(--slate-2); font-weight: 600; margin: 20px 0 10px;
  display: flex; align-items: center; gap: 10px;
}
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.section-title:first-child { margin-top: 0; }

.check { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 9px; font-size: .9rem; }
.check input { width: auto; margin-top: 3px; }

/* ---------------- Carimbo (elemento de assinatura) ---------------- */

.carimbo {
  border: 2px solid var(--ok); color: var(--ok); border-radius: 5px;
  padding: 12px 16px; margin: 4px 0 14px;
  font-family: var(--mono); text-transform: uppercase; letter-spacing: .1em;
  transform: rotate(-1.8deg); position: relative; background: var(--ok-soft);
  animation: stamp .28s cubic-bezier(.2, .9, .3, 1.2) both;
}
.carimbo::after {
  content: ''; position: absolute; inset: 4px; border: 1px dashed currentColor;
  border-radius: 3px; opacity: .5; pointer-events: none;
}
.carimbo .verdict { font-size: .92rem; font-weight: 600; }
.carimbo .meta { font-size: .68rem; letter-spacing: .06em; opacity: .85; margin-top: 5px; line-height: 1.5; }
.carimbo.fora { border-color: var(--alerta); color: var(--alerta); background: var(--alerta-soft); transform: rotate(1.4deg); }

@keyframes stamp {
  from { opacity: 0; transform: rotate(-9deg) scale(1.5); }
  to { opacity: 1; transform: rotate(-1.8deg) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .carimbo { animation: none; }
  * { transition: none !important; }
}

/* ---------------- Etiquetas ---------------- */

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: .66rem; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 4px;
  background: var(--surface-2); color: var(--slate); border: 1px solid var(--line);
}
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: #BEDFD5; }
.tag.alerta { background: var(--alerta-soft); color: var(--alerta); border-color: #E9C9BE; }
.tag.aviso { background: var(--aviso-soft); color: var(--aviso); border-color: #EBD9AE; }
.tag.info { background: var(--carimbo-soft); color: var(--carimbo); border-color: #C7D3EC; }

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------------- Métricas ---------------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px;
}
.stat .n { font-family: var(--display); font-size: 1.5rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .7rem; color: var(--slate); margin-top: 2px; line-height: 1.25; }

.meter { height: 7px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 9px; }
.meter i { display: block; height: 100%; background: var(--carimbo); border-radius: 4px; transition: width .5s ease; }
.meter i.done { background: var(--ok); }

.kv { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--slate); min-width: 128px; flex-shrink: 0; }
.kv dd { margin: 0; flex: 1; font-weight: 500; word-break: break-word; }

/* ---------------- Diversos ---------------- */

#map { height: 320px; border-radius: var(--r-lg); border: 1px solid var(--line); z-index: 1; }

.toast-wrap { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tab-h) + 14px); z-index: 90; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
@media (min-width: 920px) { .toast-wrap { left: auto; right: 24px; bottom: 24px; width: 340px; } }
.toast {
  background: var(--ink); color: #fff; padding: 12px 14px; border-radius: var(--r);
  font-size: .88rem; box-shadow: var(--shadow); animation: rise .22s ease both;
}
.toast.err { background: var(--alerta); }
.toast.ok { background: var(--ok); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.loading { display: flex; align-items: center; gap: 10px; color: var(--slate); font-size: .9rem; padding: 20px 0; }
.spin { width: 17px; height: 17px; border: 2px solid var(--line-strong); border-top-color: var(--carimbo); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.photo-preview { width: 100%; border-radius: var(--r); border: 1px solid var(--line); margin-top: 8px; display: block; }

.sticky-actions {
  position: sticky; bottom: calc(var(--tab-h) + 8px); background: var(--paper);
  padding: 10px 0 0; margin-top: 16px; border-top: 1px solid var(--line);
}
@media (min-width: 920px) { .sticky-actions { bottom: 12px; } }

.back {
  display: inline-flex; align-items: center; gap: 5px; color: var(--slate);
  text-decoration: none; font-size: .85rem; font-weight: 500; margin-bottom: 12px;
}
.back:hover { color: var(--ink); }

.searchbar { position: relative; margin-bottom: 12px; }
.searchbar input { padding-left: 36px; }
.searchbar svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--slate-2); width: 17px; height: 17px; }

/* ---------------- Tela de acesso ---------------- */

.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1100px 460px at 50% -10%, #E3E9F5 0%, transparent 65%),
    var(--paper);
}
.auth-box { width: 100%; max-width: 400px; }
.auth-logo {
  display: flex; align-items: center; gap: 10px; margin-bottom: 22px;
  font-family: var(--display); font-weight: 700; font-size: 1.3rem; letter-spacing: -.02em;
}
.auth-logo .brand-mark { width: 30px; height: 30px; border-radius: 7px; font-size: .8rem; }
.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--r); margin-bottom: 18px; border: 1px solid var(--line); }
.auth-tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 4px; font-family: var(--body); font-weight: 600; font-size: .88rem; color: var(--slate); cursor: pointer; }
.auth-tabs button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.07); }
.auth .card { box-shadow: var(--shadow); }
.auth-foot { text-align: center; font-size: .78rem; color: var(--slate-2); margin-top: 16px; }

table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data th { text-align: left; font-family: var(--mono); font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--slate-2); padding: 8px; border-bottom: 1px solid var(--line-strong); }
table.data td { padding: 9px 8px; border-bottom: 1px solid var(--line); }
.table-scroll { overflow-x: auto; }

/* ---------------- Dashboard da gestão (aba Visão) ---------------- */

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 14px 10px 12px; text-align: center;
}
.kpi .big { font-family: var(--display); font-size: 1.8rem; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: .7rem; color: var(--slate); margin-top: 5px; line-height: 1.25; }
.kpi .sub { font-size: .66rem; color: var(--slate-2); margin-top: 3px; line-height: 1.3; }

.donut { width: 74px; height: 74px; margin: 0 auto; display: block; }
.donut-n { font-family: var(--display); font-weight: 700; font-size: 17px; fill: var(--ink); }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 30px; margin-top: 10px; }
.spark i { flex: 1; background: #C7D3EC; border-radius: 2px 2px 0 0; min-height: 3px; }
.spark i:last-child { background: var(--carimbo); }

.hbar { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.hbar-nome { width: 112px; flex-shrink: 0; font-size: .8rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { flex: 1; height: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; position: relative; }
.hbar-track i { position: absolute; top: 0; bottom: 0; left: 0; background: var(--carimbo); border-radius: 7px; transition: width .5s ease; }
.hbar-track i.ok { background: var(--ok); }
.hbar-track b.meta { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .45; border-radius: 1px; }
.hbar-val { width: 58px; text-align: right; font-family: var(--mono); font-size: .78rem; color: var(--slate); flex-shrink: 0; }
@media (max-width: 520px) { .hbar-nome { width: 88px; } }
