[hidden] { display: none !important; }
:root {
  --bg: #f7f2ee;
  --paper: #fffdfa;
  --ink: #2f2823;
  --muted: #8a7d72;
  --line: #e9dfd5;
  --gold: #b08a4a;
  --gold-dark: #8c6a33;
  --gold-soft: #f1e6d3;
  --green: #4f7a5a;
  --green-soft: #e3eee4;
  --red: #a8473f;
  --red-soft: #f6e1de;
  --blue: #546f8f;
  --blue-soft: #e2e9f1;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 40 20 / 5%), 0 4px 16px rgb(60 40 20 / 6%);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Jost', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --nav-h: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: .01em; font-variant-numeric: lining-nums; }
h1 { font-size: 2rem; line-height: 1.1; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }

/* ---------- Estrutura ---------- */
.shell { min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgb(247 242 238 / 92%);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .logo { height: 34px; width: auto; }
main { padding: 18px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(6, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper);
  border-top: 1px solid var(--line);
}
nav.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .68rem; color: var(--muted); letter-spacing: 0;
}
nav.tabs a svg { width: 22px; height: 22px; }
nav.tabs a.active { color: var(--gold-dark); }
nav.tabs a.active svg { stroke: var(--gold); }
nav.tabs .side-logo { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 230px 1fr; }
  .topbar { display: none; }
  nav.tabs {
    position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 4px;
    padding: 28px 14px; border-top: 0; border-right: 1px solid var(--line);
  }
  nav.tabs .side-logo { display: block; padding: 0 10px 26px; }
  nav.tabs a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: .95rem; }
  nav.tabs a.active { background: var(--gold-soft); }
  main { padding: 34px 40px 60px; }
}

/* ---------- Componentes ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: .9rem; margin-bottom: 8px; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card, .section + .section { margin-top: 14px; }
.section { margin-top: 26px; }
.section > h2 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.section > h2 .count { font-family: var(--sans); font-size: .8rem; font-weight: 500; background: var(--gold-soft); color: var(--gold-dark); border-radius: 99px; padding: 1px 9px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--gold); border-radius: 99px;
  background: var(--gold); color: #fff; font-weight: 500; letter-spacing: .02em;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--gold-dark); border-color: var(--gold-dark); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--gold-dark); }
.btn.ghost:hover { background: var(--gold-soft); }
.btn.quiet { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.quiet:hover { background: var(--bg); }
.btn.danger { background: transparent; border-color: var(--red-soft); color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.wa { background: #2f8a55; border-color: #2f8a55; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .88rem; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 25;
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--gold); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 20px rgb(140 106 51 / 35%); cursor: pointer;
}
@media (min-width: 900px) { .fab { bottom: 28px; right: 28px; } }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .75rem; font-weight: 500; letter-spacing: .02em;
  padding: 2px 9px; border-radius: 99px;
  background: var(--gold-soft); color: var(--gold-dark); white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.gray { background: #eeeae6; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: .88rem; }
.mono { font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 34px 12px; }
.empty .star { font-size: 28px; color: var(--gold); display: block; margin-bottom: 6px; }

/* Busca e filtros */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search { flex: 1 1 220px; position: relative; }
.search input { padding-left: 40px; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; stroke: var(--muted); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 14px; scrollbar-width: none; }
.chip {
  border: 1px solid var(--line); background: var(--paper); border-radius: 99px;
  padding: 6px 14px; font-size: .88rem; white-space: nowrap; cursor: pointer;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Formulários */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: .82rem; font-weight: 500; color: var(--muted); margin-bottom: 5px; letter-spacing: .02em; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgb(176 138 74 / 18%); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: #eee6dd; border-radius: 99px; padding: 4px; margin-bottom: 16px; }
.seg button { border: 0; background: transparent; border-radius: 99px; min-height: 40px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg button.active { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.hint { font-size: .82rem; color: var(--muted); margin-top: -8px; margin-bottom: 14px; }
.error-text { color: var(--red); font-size: .85rem; }

/* Produtos */
.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
@media (min-width: 900px) { .products { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; } }
.pcard { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.pcard .ph { aspect-ratio: 1; background: var(--gold-soft); position: relative; overflow: hidden; }
.pcard .ph img, .pcard .ph .noph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pcard .ph .badge { z-index: 1; }
.pcard .ph .badge { position: absolute; left: 8px; top: 8px; box-shadow: var(--shadow); }
.pcard .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.pcard .name { font-weight: 500; line-height: 1.25; }
.pcard .prices { font-size: .82rem; color: var(--muted); margin-top: auto; padding-top: 4px; }
.noph { width: 100%; height: 100%; display: grid; place-items: center; color: var(--gold); font-size: 34px; }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: var(--radius); scrollbar-width: none; }
.gallery figure { margin: 0; flex: 0 0 100%; scroll-snap-align: start; aspect-ratio: 1; background: var(--gold-soft); border-radius: var(--radius); overflow: hidden; position: relative; }
.gallery figure img, .gallery figure .noph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
@media (min-width: 700px) { .gallery figure { flex-basis: calc(50% - 4px); } }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.thumb { width: 64px; height: 64px; border-radius: 10px; overflow: hidden; position: relative; border: 1px solid var(--line); background: var(--gold-soft); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; border: 0; width: 24px; height: 24px; border-radius: 50%; font-size: 13px; line-height: 1; cursor: pointer; background: rgb(255 255 255 / 92%); }
.thumb .del { right: 3px; top: 3px; color: var(--red); }
.thumb .cov { left: 3px; top: 3px; color: var(--gold); }
.thumb.add { display: grid; place-items: center; font-size: 26px; color: var(--gold); cursor: pointer; border-style: dashed; border-color: var(--gold); background: transparent; }
.thumb.add input { display: none; }

.detail { display: grid; gap: 18px; }
@media (min-width: 900px) { .detail { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .stats.four { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-variant-numeric: lining-nums tabular-nums; font-family: var(--serif); font-size: 1.9rem; font-weight: 600; line-height: 1.1; }
.stat .l { font-size: .78rem; color: var(--muted); letter-spacing: .03em; text-transform: uppercase; }
.stat.hl { background: var(--gold-soft); border-color: transparent; }

dl.info { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: .95rem; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; }

/* Listas */
.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; gap: 12px; align-items: center;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow);
}
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.row .side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.row.overdue { border-left: 4px solid var(--red); }
.row .mini { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; flex-shrink: 0; background: var(--gold-soft); }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--gold-soft); color: var(--gold-dark); font-family: var(--serif); font-weight: 600; font-size: 1.2rem; flex-shrink: 0; }

.log .ico { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; font-size: 15px; font-weight: 600; }
.ico.in { background: var(--green-soft); color: var(--green); }
.ico.loss { background: var(--red-soft); color: var(--red); }
.ico.sale { background: var(--gold-soft); color: var(--gold-dark); }
.ico.rental_out { background: var(--blue-soft); color: var(--blue); }
.ico.rental_return { background: var(--green-soft); color: var(--green); }

/* Itens do contrato */
.items .item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.items .item:last-child { border-bottom: 0; }
.items .item .grow { flex: 1; min-width: 0; }
.items .item input { min-height: 38px; padding: 6px 10px; }
.items .item { flex-wrap: wrap; }
.items .item .inputs { flex-basis: 100%; display: flex; gap: 10px; padding-left: 58px; }
.items .item .inputs label { display: flex; align-items: center; gap: 6px; }
.items .qty { width: 64px; }
.items .price { width: 110px; }
@media (min-width: 700px) {
  .items .item { flex-wrap: nowrap; }
  .items .item .inputs { flex-basis: auto; padding-left: 0; order: 2; }
  .items .item .rm { order: 3; }
}
.total-line { display: flex; justify-content: space-between; align-items: baseline; padding-top: 12px; border-top: 1px solid var(--line); margin-top: 6px; }
.total-line .v { font-variant-numeric: lining-nums; font-family: var(--serif); font-size: 1.6rem; font-weight: 600; }

.picker { position: relative; }
.picker .results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 280px; overflow: auto; }
.picker .results button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line); }
.picker .results button:hover { background: var(--bg); }
.picked { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 8px; border: 1px solid var(--gold); background: var(--gold-soft); border-radius: 12px; }
.picked .main { flex: 1; }

.plist { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; max-height: 55dvh; overflow: auto; padding: 2px; }
.plist button { border: 1px solid var(--line); background: var(--paper); border-radius: 12px; overflow: hidden; padding: 0; text-align: left; cursor: pointer; }
.plist button[disabled] { opacity: .45; cursor: not-allowed; }
.plist .ph { aspect-ratio: 1; background: var(--gold-soft); position: relative; overflow: hidden; }
.plist .ph img, .plist .ph .noph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.plist .t { padding: 6px 8px 8px; font-size: .85rem; line-height: 1.25; }

/* Modal e aviso */
dialog#modal {
  border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 24px));
  background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px rgb(40 25 10 / 30%);
}
dialog#modal::backdrop { background: rgb(40 30 20 / 40%); backdrop-filter: blur(2px); }
dialog#modal .mbody { padding: 22px 20px 20px; max-height: 85dvh; overflow: auto; }
dialog#modal h2 { margin-bottom: 14px; }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 99px; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--red); }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 30%, #fffdfa 0%, var(--bg) 70%); }
.login .box { width: min(380px, 100%); text-align: center; }
.login img { width: 260px; margin: 0 auto 8px; }
.login p { color: var(--muted); margin: 0 0 26px; letter-spacing: .12em; text-transform: uppercase; font-size: .78rem; }
.login form { display: grid; gap: 12px; }

/* Comprovante para imprimir */
.print-sheet { background: #fff; color: #222; max-width: 760px; margin: 0 auto; padding: 36px 40px; border: 1px solid var(--line); border-radius: 6px; }
.print-sheet .head { text-align: center; border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 18px; }
.print-sheet .head img { width: 220px; margin: 0 auto; }
.print-sheet table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: .95rem; }
.print-sheet th, .print-sheet td { text-align: left; padding: 7px 6px; border-bottom: 1px solid #eee; }
.print-sheet td.r, .print-sheet th.r { text-align: right; }
.print-sheet .terms { white-space: pre-wrap; font-size: .85rem; color: #444; margin-top: 18px; }
.print-sheet .signs { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 60px; text-align: center; font-size: .85rem; }
.print-sheet .signs div { border-top: 1px solid #555; padding-top: 6px; }
@media print {
  body { background: #fff; }
  nav.tabs, .topbar, .fab, .no-print, #toast { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  .print-sheet { border: 0; padding: 0; }
}

/* Relatórios */
.stat-btn { text-align: left; cursor: pointer; font: inherit; color: inherit; display: block; transition: border-color .15s; }
.stat-btn:hover { border-color: var(--gold); }
.stat.alert { background: var(--red-soft); border-color: transparent; }
.stat.alert .v { color: var(--red); }
.filters .flabel { font-size: .82rem; font-weight: 500; color: var(--muted); margin-bottom: 6px; letter-spacing: .02em; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip.ghost { border-style: dashed; color: var(--muted); }
.filters details summary { cursor: pointer; color: var(--gold-dark); font-weight: 500; }
.filters input:disabled { background: var(--bg); color: var(--muted); }
.rtotals { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.rtotals div { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; display: flex; gap: 6px; align-items: baseline; }
.rtotals b { font-family: var(--serif); font-size: 1.35rem; font-variant-numeric: lining-nums; }
.rtotals span { color: var(--muted); font-size: .85rem; }
.rtable-wrap { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.rtable { width: 100%; border-collapse: collapse; font-size: .92rem; }
.rtable th { text-align: left; font-size: .75rem; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fbf8f4; }
.rtable td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rtable tr:last-child td { border-bottom: 0; }
.rtable .r { text-align: right; }
.rtable tbody tr { cursor: pointer; }
.rtable tbody tr:hover td { background: #fbf8f4; }
.rtable tr.late td:first-child { box-shadow: inset 4px 0 0 var(--red); }
.print-only { display: none; }
@media (max-width: 699px) {
  .rtable-wrap { background: none; border: 0; box-shadow: none; }
  .rtable thead { display: none; }
  .rtable, .rtable tbody { display: block; }
  .rtable tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 10px; }
  .rtable tr.late { border-left: 4px solid var(--red); }
  .rtable tr.late td:first-child { box-shadow: none; }
  .rtable td { display: block; padding: 0; border: 0; text-align: left !important; }
  .rtable td::before { content: attr(data-l); display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .rtable tbody tr:hover td { background: none; }
}
@media print {
  .print-only { display: block; margin-bottom: 6px; }
  .rtable-wrap { box-shadow: none; }
  .rtable thead { display: table-header-group !important; }
  .rtable, .rtable tbody { display: table !important; width: 100%; }
  .rtable tbody { display: table-row-group !important; }
  .rtable tbody tr { display: table-row !important; box-shadow: none; border: 0; padding: 0; margin: 0; }
  .rtable td { display: table-cell !important; padding: 6px 8px !important; border-bottom: 1px solid #ddd !important; }
  .rtable td::before { display: none; }
}
