:root {
  --teal: #0f766e;
  --teal-dark: #115e59;
  --teal-light: #ccfbf1;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
.spacer { height: 40px; }
.muted { color: var(--muted); font-size: 14px; }

/* ---------- Telas ---------- */
.view { display: none; min-height: 100%; flex-direction: column; }
.view.active { display: flex; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 12px;
  background: var(--teal);
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar-main { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.1; }
.client-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { display: block; font-size: 12.5px; opacity: .9; margin-top: 2px; }
.icon-btn {
  flex: none;
  width: 42px; height: 42px;
  border: none; border-radius: 50%;
  background: rgba(255,255,255,.15);
  color: #fff; font-size: 24px; line-height: 1;
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.3); }

/* ---------- Busca ---------- */
.search-wrap { padding: 12px 14px 6px; position: sticky; top: 64px; z-index: 15; background: var(--bg); }
#search {
  width: 100%; padding: 13px 16px;
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 16px; background: var(--card);
}
#search:focus { outline: 2px solid var(--teal-light); border-color: var(--teal); }

/* ---------- Lista de clientes ---------- */
.list-area { flex: 1; overflow-y: auto; padding-bottom: 24px; }
.client-list { list-style: none; margin: 0; padding: 0; }
.az-header {
  position: sticky; top: 0;
  padding: 6px 16px; font-size: 13px; font-weight: 700;
  color: var(--teal-dark); background: var(--teal-light);
}
.client-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; background: var(--card);
}
.client-item:active { background: #f1f5f9; }
.client-avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--teal-light); color: var(--teal-dark);
  font-weight: 700; display: grid; place-items: center; font-size: 17px;
}
.client-info { flex: 1; min-width: 0; }
.client-info .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-info .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.badge {
  flex: none; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
}
.badge.pend { background: #fff7ed; color: var(--warn); }
.badge.done { background: #f0fdf4; color: var(--ok); }
.dot { font-size: 12px; }

/* ---------- Trilha A-Z ---------- */
.az-rail {
  position: fixed; right: 2px; top: 120px; bottom: 16px; z-index: 16;
  display: flex; flex-direction: column; justify-content: center;
  gap: 0; padding: 4px 2px;
}
.az-rail button {
  border: none; background: none; color: var(--teal-dark);
  font-size: 10.5px; font-weight: 700; line-height: 1.25;
  padding: 0 4px; cursor: pointer;
}

/* ---------- Empty ---------- */
.empty-state { text-align: center; padding: 60px 24px; color: var(--muted); }
.empty-emoji { font-size: 48px; margin: 0 0 8px; }

/* ---------- Detalhe do cliente ---------- */
.client-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.section, .data-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.section-head h2 { margin: 0; font-size: 16px; }
.hint { font-size: 11.5px; color: var(--muted); text-align: right; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; margin-bottom: 10px; }
.thumbs:empty { display: none; }
.thumb {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: #f1f5f9; cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .star {
  position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; border: none; font-size: 14px; line-height: 1;
  background: rgba(0,0,0,.45); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.thumb .star.on { background: var(--warn); }
.thumb .num {
  position: absolute; bottom: 3px; right: 3px;
  background: rgba(0,0,0,.55); color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px;
}

.section-actions { display: flex; gap: 8px; }

/* ---------- Botões ---------- */
.btn {
  border: none; border-radius: 10px; padding: 12px 14px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  background: var(--teal-light); color: var(--teal-dark);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn.cam { background: var(--teal); color: #fff; flex: 1; }
.btn.ghost { background: #f1f5f9; color: var(--text); flex: 1; }
.btn.primary { background: var(--teal); color: #fff; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.big { width: 100%; padding: 16px; font-size: 17px; }
.btn.full { width: 100%; margin-top: 10px; }
.btn.danger { background: #fef2f2; color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- Card de dados ---------- */
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
}
.field input:focus { outline: 2px solid var(--teal-light); border-color: var(--teal); }
.filename-preview { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; word-break: break-all; }
.filename-preview strong { color: var(--teal-dark); }
.ocr-status {
  font-size: 13px; color: var(--teal-dark); background: var(--teal-light);
  padding: 8px 12px; border-radius: 8px; margin-bottom: 12px;
}

/* ---------- Modais ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.5); display: flex; align-items: flex-end; justify-content: center; }
.modal-card {
  background: var(--card); width: 100%; max-width: 460px;
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(env(safe-area-inset-bottom) + 18px);
  animation: slideup .2s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-card h2 { margin: 0 0 6px; font-size: 18px; }
.modal-card textarea {
  width: 100%; margin-top: 10px; padding: 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 10px; resize: vertical; font-family: inherit;
}
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

.sheet { padding: 8px; }
.sheet-item {
  display: block; width: 100%; text-align: left;
  padding: 16px; border: none; background: none; font-size: 16px;
  border-radius: 10px; cursor: pointer; color: var(--text);
}
.sheet-item:active { background: #f1f5f9; }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel { text-align: center; font-weight: 700; color: var(--muted); margin-top: 4px; }

/* ---------- Viewer de foto ---------- */
.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 20px; }
.viewer img { max-width: 100%; max-height: 75vh; object-fit: contain; border-radius: 8px; }
.viewer-close { position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 16px; background: rgba(255,255,255,.2); color: #fff; border: none; width: 42px; height: 42px; border-radius: 50%; font-size: 20px; cursor: pointer; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 12px 20px; border-radius: 999px;
  font-size: 14px; z-index: 70; box-shadow: var(--shadow); max-width: 90%; text-align: center;
  animation: fadein .2s ease;
}
@keyframes fadein { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Overlay de processamento ---------- */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(248,250,252,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }
.spinner { width: 46px; height: 46px; border: 4px solid var(--teal-light); border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#overlay-text { color: var(--teal-dark); font-weight: 600; }

/* Rótulo auxiliar dentro dos campos (ex.: "(legenda do PDF)") */
.field span em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 11px; }

/* Item selecionado (destaque, principalmente no PC) */
.client-item.selected { background: var(--teal-light); }

/* Placeholder do PC quando nenhum cliente está selecionado */
.client-empty { display: none; }

/* ---------- Tablet: coluna central confortável ---------- */
@media (min-width: 560px) and (max-width: 899px) {
  .view { max-width: 560px; margin: 0 auto; box-shadow: var(--shadow); background: var(--bg); }
  .az-rail { right: calc(50% - 280px); }
}

/* ---------- PC / Notebook: lista + detalhe lado a lado ---------- */
@media (min-width: 900px) {
  html, body { height: 100vh; overflow: hidden; }
  body { display: flex; flex-direction: row; align-items: stretch; }
  .view { display: flex !important; height: 100vh; max-width: none; margin: 0; box-shadow: none; }

  #view-list { width: 380px; flex: none; border-right: 1px solid var(--border); background: var(--card); }
  #view-client { flex: 1; min-width: 0; position: relative; background: var(--bg); }

  #btn-back { display: none; }   /* a lista já está sempre visível */
  .az-rail { display: none; }

  /* Sem cliente selecionado: mostra o aviso e esconde o detalhe */
  body:not(.client-open) #view-client .topbar,
  body:not(.client-open) #view-client .client-body { display: none; }
  body:not(.client-open) #client-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; gap: 6px; color: var(--muted); text-align: center; padding: 24px;
  }
  body:not(.client-open) #client-empty .empty-emoji { font-size: 44px; margin: 0; }

  /* Com cliente selecionado: esconde o aviso */
  body.client-open #client-empty { display: none; }

  /* Conteúdo do detalhe centralizado e legível em telas largas */
  .client-body { align-items: center; }
  .client-body > .section,
  .client-body > .data-card,
  .client-body > .btn.big { width: 100%; max-width: 720px; }
}
