/* Mobile-first: o estilo base é o do celular; telas maiores só acrescentam. */
:root {
  --bg: #f5f2ee;
  --surface: #ffffff;
  --ink: #26221f;
  --muted: #7a726b;
  --line: #e8e2db;
  --turmalina: #c8326e;
  --turmalina-soft: #fbe8f0;
  --vale: #25836a;
  --vale-soft: #e3f4ee;
  --accent: var(--turmalina);
  --accent-soft: var(--turmalina-soft);
  --warn: #b9770e;  --warn-soft: #fdf1da;
  --info: #2563a8;  --info-soft: #e5eefa;
  --ok: #1f7a4d;    --ok-soft: #e0f4e8;
  --danger: #b3261e;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 18px rgba(60, 40, 20, .05);
  --tap: 48px;                 /* alvo mínimo de toque */
  --nav-h: 64px;               /* altura da barra inferior */
  --safe-b: env(safe-area-inset-bottom, 0px);
}
body.casa-vale { --accent: var(--vale); --accent-soft: var(--vale-soft); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* espaço para a barra inferior fixa */
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
}
body.bare { padding-bottom: 0; }
body.viewer-open { overflow: hidden; }
h1 { font-size: 1.45rem; line-height: 1.2; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
h2 small { font-weight: 400; font-size: .82rem; margin-left: .35rem; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.mt { margin-top: 1.2rem; }

.wrap { width: min(1040px, 100% - 28px); margin-inline: auto; }
main.wrap { padding: 16px 0 32px; }

/* Topo (celular: marca à esquerda, conta à direita) */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: #fff;
}

/* Navegação: barra fixa embaixo no celular */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(60, 40, 20, .06);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600;
}
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav a.on { color: var(--accent); }
.nav a.on svg { stroke-width: 2.4; }

/* Conta */
.who { position: relative; }
.who summary { list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: var(--tap); }
.who summary::-webkit-details-marker { display: none; }
.who-txt { display: none; flex-direction: column; line-height: 1.2; text-align: right; }
.who-txt small { color: var(--muted); font-size: .78rem; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none;
}
.who-menu {
  position: absolute; right: 0; top: 100%; min-width: 180px; padding: 6px; z-index: 40;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.who-menu a { display: flex; align-items: center; min-height: var(--tap); padding: 0 14px; border-radius: 10px; text-decoration: none; }
.who-menu a:active, .who-menu a:hover { background: var(--bg); }
.link-sm { font-size: .9rem; color: var(--muted); text-decoration: none; padding: 4px 6px; }

/* Estrutura */
.page-head { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.page-head p { margin: 0; }
.page-head .actions { margin-top: 0; }
.page-head .actions .btn { flex: 1; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel.narrow { max-width: 620px; margin-inline: auto; }
.cols { display: grid; gap: 14px; align-items: start; }
.cols > .stack { order: -1; }          /* documentos antes dos detalhes no celular */
.stack { display: grid; gap: 14px; }
.grid-2 { display: grid; gap: 0 14px; }
.back {
  display: inline-flex; align-items: center; min-height: 40px; margin-bottom: 4px;
  color: var(--muted); text-decoration: none; font-size: .95rem;
}

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 10px 20px; border-radius: 14px; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-weight: 600; text-decoration: none; transition: transform .05s, filter .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: #fff; border-color: #efc4c1; color: var(--danger); }
.btn-danger:hover { background: #fdeceb; }
.btn-sm { min-height: 40px; padding: 7px 14px; font-size: .9rem; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.actions .btn { flex: 1 1 auto; }

/* Formulários (16px evita o zoom automático do iOS) */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
.field small { font-weight: 400; color: var(--muted); }
input[type=text], input[type=password], input[type=month], input[type=date], select, textarea {
  width: 100%; min-height: var(--tap); padding: 11px 13px; border: 1px solid #d9d1c8; border-radius: 14px; background: #fff;
  font: inherit; font-size: 16px; color: inherit;
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
[hidden] { display: none !important; }

/* Avisos */
.flash { padding: 12px 16px; border-radius: 14px; margin-bottom: 14px; font-weight: 500; transition: opacity .5s; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-erro { background: #fdeceb; color: var(--danger); }
.flash.fade { opacity: 0; }

/* Selos */
.casa-tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600; white-space: nowrap; }
.casa-tag-turmalina { background: var(--turmalina-soft); color: var(--turmalina); }
.casa-tag-vale { background: var(--vale-soft); color: var(--vale); }
.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; align-self: flex-start; }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .9rem; }
.flow-lg { font-size: 1rem; margin: 6px 0 14px; }
.arrow { color: var(--muted); font-size: .85rem; }

/* Painel: cartões de resumo (2x2 no celular) */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); text-decoration: none; box-shadow: var(--shadow);
  border-top: 4px solid var(--line); min-height: 112px;
}
.stat-n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-t { font-weight: 600; font-size: .9rem; line-height: 1.25; }
.stat-d { display: none; color: var(--muted); font-size: .8rem; }
.stat-warn { border-top-color: #e5a53a; }
.stat-info { border-top-color: #4a8ad6; }
.stat-ok { border-top-color: #3ea974; }
.stat-mute { border-top-color: #cfc7be; }
.stat-hot.stat-warn { background: var(--warn-soft); }
.stat-hot.stat-info { background: var(--info-soft); }

/* Filtros: uma linha rolável de lado em vez de várias linhas */
.filters { display: grid; gap: 8px; margin: 0 -16px 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); text-decoration: none; font-size: .9rem; color: var(--muted); background: #fff;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip-turmalina.on { background: var(--turmalina); border-color: var(--turmalina); }
.chip-vale.on { background: var(--vale); border-color: var(--vale); }
.panel > .chips { margin: 0 -16px 10px; }

/* Lista */
.req-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.req {
  display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center;
  padding: 14px; border: 1px solid var(--line); border-radius: 14px; text-decoration: none; background: #fff;
}
.req:active { background: var(--bg); }
.req-type {
  width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 1.05rem;
}
.req-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.req-main strong { font-size: 1.02rem; }
.req-ref { color: var(--muted); font-size: .9rem; }
.req-side {
  grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px;
  padding-top: 10px; border-top: 1px dashed var(--line);
}
.req-side small { width: 100%; order: 3; }
.todo { color: var(--accent); font-weight: 700; font-size: .9rem; }
.empty { text-align: center; padding: 36px 10px; display: grid; gap: 4px; color: var(--muted); }
.empty strong { color: var(--ink); }

/* Passos: três colunas compactas */
.steps { list-style: none; margin: 0 0 14px; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.steps li {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 10px 6px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.steps b {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--bg); font-size: .85rem;
}
.steps span { display: flex; flex-direction: column; line-height: 1.2; font-weight: 600; font-size: .78rem; }
.steps small { display: none; font-weight: 400; font-size: .78rem; }
.steps li.done { color: var(--ink); border-color: #bfe3cf; background: #f4fbf7; }
.steps li.done b { background: var(--ok); color: #fff; }

/* Detalhes */
.meta { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; }
.meta dt { color: var(--muted); font-size: .9rem; }
.meta dd { margin: 0; font-weight: 500; }

/* Arquivos */
.files { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.files li { display: flex; align-items: center; gap: 8px; }
.files form { margin: 0; }
.file {
  flex: 1; display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-width: 0; min-height: 56px;
  border: 1px solid var(--line); border-radius: 14px; text-decoration: none; background: #fcfbf9;
}
.file:active { background: var(--accent-soft); }
.file-ext {
  flex: none; min-width: 44px; text-align: center; padding: 6px 4px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .72rem;
}
.file-info { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.file-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
.file-info small { color: var(--muted); font-size: .78rem; }
.file-ver { flex: none; color: var(--accent); font-size: .8rem; font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; font-size: 1.4rem; line-height: 1; color: var(--muted);
}
.icon-btn:hover { color: var(--danger); border-color: #efc4c1; }

.upload { display: grid; gap: 12px; }
.drop {
  display: flex; flex-direction: column; gap: 2px; align-items: center; text-align: center;
  padding: 22px 14px; border: 2px dashed #d9d1c8; border-radius: 14px; cursor: pointer; background: #fcfbf9;
  word-break: break-word; margin-bottom: 14px; position: relative;
}
.upload .drop { margin-bottom: 0; }
.drop:active, .drop.has-files { border-color: var(--accent); background: var(--accent-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop:focus-within { outline: 3px solid var(--accent-soft); }
.drop-names { color: var(--muted); font-size: .82rem; }

/* Visualizador (PDF e imagens) em tela cheia */
.viewer { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; background: #2b2724; color: #fff; }
.viewer-bar {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: #1d1a18;
}
.viewer-title { flex: 1; min-width: 0; font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-btn {
  flex: none; min-width: 44px; height: 44px; padding: 0 12px; border: 0; border-radius: 12px; cursor: pointer;
  background: rgba(255, 255, 255, .1); color: #fff; font: inherit; font-weight: 700; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.viewer-btn:active { background: rgba(255, 255, 255, .22); }
.viewer-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
.viewer-pages { display: flex; flex-direction: column; align-items: center; gap: 12px; width: max-content; min-width: 100%; }
.viewer-pages canvas, .viewer-pages img { display: block; background: #fff; box-shadow: 0 4px 18px rgba(0, 0, 0, .35); }
.viewer-pages img { max-width: none; height: auto; }
.viewer-msg { margin: 40px auto; text-align: center; color: #d9d1c8; max-width: 320px; }
.viewer-msg a { color: #fff; font-weight: 700; }

/* Login */
body.bare { min-height: 100vh; display: grid; place-items: center; background:
  radial-gradient(900px 500px at 10% -10%, var(--turmalina-soft), transparent 60%),
  radial-gradient(900px 500px at 100% 110%, var(--vale-soft), transparent 60%), var(--bg); }
.bare-main { padding: 24px 0; width: min(400px, 100% - 32px); }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 30px 22px;
  box-shadow: var(--shadow); text-align: center;
}
.login-card form { text-align: left; margin-top: 22px; }
.login-card .muted { margin: 4px 0 0; }
.brand-lg { display: flex; justify-content: center; margin-bottom: 12px; }
.brand-lg .brand-mark { width: 56px; height: 56px; border-radius: 16px; background: var(--turmalina); }

/* ---------- Telas maiores ---------- */
@media (min-width: 600px) {
  .wrap { width: min(1040px, 100% - 40px); }
  main.wrap { padding: 24px 0 48px; }
  h1 { font-size: 1.7rem; }
  .panel { padding: 22px; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .stat-d { display: block; }
  .steps li { flex-direction: row; text-align: left; padding: 12px 14px; gap: 12px; }
  .steps span { font-size: .92rem; }
  .steps small { display: block; }
  .page-head { flex-direction: row; justify-content: space-between; align-items: flex-start; }
  .page-head .actions .btn { flex: none; }
  .filters { margin: 0 0 18px; }
  .chips { flex-wrap: wrap; overflow: visible; padding: 0; }
  .panel > .chips { margin: 0 0 12px; }
  .who-txt { display: flex; }
}
@media (min-width: 860px) {
  body { padding-bottom: 0; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
  .stat { min-height: 0; padding: 16px 18px; transition: transform .15s; }
  .stat:hover { transform: translateY(-2px); }
  .stat-n { font-size: 2rem; }
  .cols { grid-template-columns: 300px 1fr; gap: 20px; }
  .cols > .stack { order: 0; }
  .stack { gap: 20px; }

  /* navegação volta para o topo */
  .topbar-in { gap: 24px; justify-content: flex-start; min-height: 64px; }
  .nav { position: static; display: flex; gap: 4px; height: auto; padding: 0; background: none; border: 0; box-shadow: none; }
  .nav a { flex-direction: row; gap: 8px; padding: 8px 14px; border-radius: 999px; font-size: 1rem; font-weight: 500; }
  .nav a:hover { background: var(--bg); color: var(--ink); }
  .nav a.on { background: var(--accent-soft); }
  .nav svg { width: 18px; height: 18px; }
  .who { margin-left: auto; }

  .req { grid-template-columns: auto 1fr auto; gap: 16px; padding: 14px 16px; transition: border-color .15s, box-shadow .15s; }
  .req:hover { border-color: var(--accent); box-shadow: 0 4px 16px rgba(60, 40, 20, .08); }
  .req-type { width: 46px; height: 46px; background: var(--bg); color: var(--muted); }
  .req-side { grid-column: auto; flex-direction: column; align-items: flex-end; text-align: right; padding: 0; border: 0; }
  .req-side small { width: auto; order: 0; }
  .file:hover { border-color: var(--accent); }
  .chip:hover { border-color: #cfc7be; color: var(--ink); }
  .viewer-pages { padding: 0; }
}
