:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e2e6ee;
  --accent: #1a56db;
  --accent-soft: #e8efff;
  --ok: #0a7c45; /* verde com contraste 5:1 sobre branco */
  --warn-bg: #fff7e0;
  --warn-ink: #7a5a00;
  --danger: #c62828;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}
[hidden] { display: none !important; }
h1 { font-size: 1.4rem; margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center-text { text-align: center; }
em { font-style: normal; color: var(--muted); font-weight: 400; }

.view { min-height: 100dvh; }
.view.center { display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 24px 20px; box-shadow: 0 2px 12px rgba(17,24,39,.06); width: 100%; }
.card.narrow { max-width: 420px; }
.logo { width: 56px; height: 56px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 700; font-size: 1.05rem; }
.topbar-sub { color: var(--muted); font-size: .8rem; }
.step-count { color: var(--muted); font-size: .9rem; min-width: 64px; text-align: right; }
.progress { height: 3px; background: var(--line); position: sticky; top: 57px; z-index: 5; }
.progress > div { height: 100%; background: var(--accent); width: 20%; transition: width .25s; }

.content { padding: 16px; max-width: 640px; margin: 0 auto; }
#contract-form { padding-bottom: calc(96px + var(--safe-bottom)); }

.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; gap: 10px; padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.bottombar .btn { flex: 1; }
.bottombar .btn.primary { flex: 2; }

label { display: block; font-size: .85rem; font-weight: 600; color: #374151; margin-bottom: 14px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; font-size: 16px; /* evita zoom automático no iPhone */
  padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input.invalid { border-color: var(--danger); background: #fff6f6; }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 8px 0 18px; }
legend { font-weight: 700; font-size: .95rem; margin-bottom: 10px; padding: 0; }
.hint { display: block; font-weight: 400; color: var(--muted); margin-top: 4px; font-size: .8rem; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.row > .w-30 { flex: 0 0 30%; }
.input-action { display: flex; gap: 8px; align-items: stretch; }
.input-action input { flex: 1; }
.input-action .btn { margin-top: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.block { display: flex; width: 100%; margin-bottom: 10px; }
.btn.big { padding: 16px; font-size: 17px; }
.btn:disabled { opacity: .5; }
.btn.upload { margin: 0 0 14px; font-weight: 600; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }

.segmented { display: flex; background: #e9edf4; border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.segmented label { flex: 1; margin: 0; }
.segmented input { display: none; }
.segmented span { display: block; text-align: center; padding: 10px 6px; border-radius: 9px; font-size: .9rem; }
.segmented input:checked + span { background: var(--surface); color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chips label { margin: 0; }
.chips input { display: none; }
.chips span { display: inline-block; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 500; }
.chips input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.check { display: flex; gap: 12px; align-items: flex-start; font-weight: 500; font-size: .95rem; background: var(--surface); padding: 14px; border-radius: 12px; border: 1px solid var(--line); }
.check input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--accent); }

.banner { background: var(--warn-bg); color: var(--warn-ink); padding: 12px 14px; border-radius: 12px; font-size: .88rem; margin-bottom: 14px; }
.banner.subtle { background: var(--accent-soft); color: var(--ink); margin-top: 6px; }
.section-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.list-item { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; font: inherit; color: inherit; cursor: pointer; }
.list-item .li-top { display: flex; justify-content: space-between; gap: 10px; }
.list-item .li-name { font-weight: 600; }
.list-item .li-meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.pill { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: #e7f6ee; color: var(--ok); white-space: nowrap; align-self: flex-start; }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

.image-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.image-item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; position: relative; }
.image-item img { width: 100%; height: 140px; object-fit: cover; display: block; }
.image-item input { margin: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0; font-size: 14px; padding: 8px 10px; }
.image-item .remove { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 16px; cursor: pointer; }

.contract-preview { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 16px; font-family: Georgia, "Times New Roman", serif; font-size: .92rem; line-height: 1.55; }
.contract-preview h3 { font-family: inherit; font-size: 1rem; text-align: center; margin: 0 0 14px; }
.contract-preview h4 { font-family: inherit; font-size: .85rem; margin: 16px 0 6px; }
.contract-preview p { margin: 0 0 8px; text-align: justify; }

.summary { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; font-size: .92rem; }
.summary div { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.summary span:first-child { color: var(--muted); }
.summary span:last-child { font-weight: 600; text-align: right; }

.sign-block { margin: 16px 0 20px; }
.sign-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sign-pad { width: 100%; height: 200px; background: #fff; border: 2px dashed #c3cad8; border-radius: 12px; touch-action: none; display: block; }
.sign-pad.signed { border-style: solid; border-color: var(--accent); }

.error { color: var(--danger); font-size: .9rem; font-weight: 500; margin: 8px 0 0; white-space: pre-line; }

.done-icon { width: 64px; height: 64px; border-radius: 50%; background: #e7f6ee; color: var(--ok); font-size: 32px; display: grid; place-items: center; margin: 0 auto 8px; }
.status-list { list-style: none; padding: 0; margin: 14px 0 20px; text-align: left; font-size: .92rem; }
.status-list li { padding: 8px 12px; background: var(--bg); border-radius: 10px; margin-bottom: 6px; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(17,24,39,.45); z-index: 20; display: flex; align-items: flex-end; }
.sheet { background: var(--surface); width: 100%; border-radius: 18px 18px 0 0; padding: 20px 16px calc(16px + var(--safe-bottom)); max-width: 640px; margin: 0 auto; }
.sheet-title { font-weight: 700; font-size: 1.1rem; }
.sheet-sub { margin-bottom: 16px; }
#sheet-sub { margin-bottom: 16px; }

.loading { position: fixed; inset: 0; background: rgba(255,255,255,.85); z-index: 30; display: grid; place-content: center; justify-items: center; gap: 14px; font-weight: 600; }
.spinner { width: 40px; height: 40px; border: 4px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-bottom)); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 40; font-size: .9rem; max-width: calc(100% - 32px); }

/* Cartões de plano / pilares */
.options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.option { display: block; margin: 0; background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; font-weight: 400; cursor: pointer; }
.option > input { display: none; }
.option-head { display: flex; align-items: center; gap: 10px; }
.option-mark { width: 20px; height: 20px; flex: none; border: 2px solid #c3cad8; border-radius: 50%; }
.option.checkbox .option-mark { border-radius: 6px; }
.option-title { font-weight: 700; font-size: 1rem; color: var(--ink); }
.option-sub { color: var(--muted); font-size: .82rem; }
.option-price { margin-left: auto; text-align: right; font-weight: 700; color: var(--ink); white-space: nowrap; font-size: .95rem; }
.option-price small { display: block; font-weight: 400; color: var(--muted); font-size: .72rem; }
.option-details { display: none; margin: 10px 0 0 30px; padding: 0; list-style: none; font-size: .85rem; color: #374151; }
.option-details li { padding: 3px 0; border-top: 1px dashed var(--line); }
.option-details b { color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; display: block; }
.option:has(> input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option:has(> input:checked) .option-mark { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--accent-soft); }
.option:has(> input:checked) .option-details { display: block; }
.summary .total span:last-child { color: var(--accent); font-size: 1.05rem; }
.contract-preview .annex-title { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.contract-preview p.note { font-size: .8rem; color: var(--muted); font-style: italic; margin: 0 0 4px; }

.brand-logo { display: block; width: 100%; max-width: 300px; height: auto; margin: -8px auto 4px; }
#view-login h1, #view-login .muted { text-align: center; }
.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo { height: 34px; width: auto; }

/* ---------- App com abas ---------- */
.tab-content { padding-bottom: calc(90px + var(--safe-bottom)); }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.tabbar button { flex: 1; background: none; border: 0; padding: 8px 4px 10px; font: inherit; font-size: .72rem; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabbar button.active { color: var(--accent); }
.tab-ico { font-size: 1.25rem; line-height: 1.2; }
.hello { font-size: 1.15rem; font-weight: 700; margin: 2px 0 14px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.kpi.wide { grid-column: 1 / -1; background: var(--accent); border-color: var(--accent); color: #fff; }
.kpi .kpi-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.kpi.wide .kpi-label, .kpi.wide .kpi-sub { color: rgba(255,255,255,.85); }
.kpi .kpi-value { font-size: 1.35rem; font-weight: 800; margin-top: 4px; }
.kpi.wide .kpi-value { font-size: 1.7rem; }
.kpi .kpi-sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.rank-item { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.rank-pos { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; display: grid; place-items: center; flex: none; }
.rank-main { flex: 1; min-width: 0; }
.rank-name { font-weight: 700; }
.rank-meta { font-size: .8rem; color: var(--muted); }
.rank-value { font-weight: 800; white-space: nowrap; }
.search { margin: 0 0 12px; }
.filter-chips { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 10px; padding-bottom: 2px; }
.filter-chips button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; font: inherit; font-size: .88rem; font-weight: 600; color: var(--ink); cursor: pointer; }
.filter-chips button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill.negociando { background: #fff4d6; color: #8a5a00; }
.pill.fechado { background: #e7f6ee; color: var(--ok); }
.pill.perdido { background: #f1f2f5; color: var(--muted); }
.pill.late { background: #fde8e8; color: var(--danger); }
.card.flat { box-shadow: none; border: 1px solid var(--line); padding: 16px; margin-bottom: 4px; }
.account-name { font-size: 1.15rem; font-weight: 800; }
.logout-btn { margin-top: 24px; }
.seller-line { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 18px 0 0; }
.sheet.tall { max-height: 92dvh; overflow-y: auto; }
.client-quick { display: flex; gap: 8px; margin: 10px 0 14px; flex-wrap: wrap; }
.status-seg { margin-top: 12px; }
.btn.danger { color: var(--danger); }
.user-off { opacity: .55; }
.filter-chips { scrollbar-width: none; }
.filter-chips::-webkit-scrollbar { display: none; }

/* Botão de mostrar/esconder senha */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 52px; }
.pw-eye { position: absolute; right: 4px; bottom: 4px; height: calc(100% - 8px); max-height: 42px; width: 44px; border: 0; background: none; cursor: pointer; color: var(--muted); display: grid; place-items: center; border-radius: 8px; }
.pw-eye:active { background: var(--accent-soft); }
.pw-eye svg { width: 22px; height: 22px; }
.register-hint { margin: 18px 0 0; line-height: 1.8; }

/* Serviços combinados (formulário) */
.extra-row { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.extra-row input, .extra-row select { margin-top: 0; }
.extra-row .row { margin-top: 8px; align-items: center; }
.extra-row .extra-remove { flex: 0 0 auto; border: 0; background: none; color: var(--danger); font: inherit; font-weight: 600; cursor: pointer; padding: 8px; }

/* Contratos do cliente (pasta) */
.client-contracts-title { font-weight: 700; font-size: .95rem; margin: 18px 0 8px; }
.cc-card { background: var(--bg); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.cc-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; margin-bottom: 6px; }
.cc-head span:last-child { color: var(--muted); font-weight: 500; font-size: .85rem; }
.cc-line { display: flex; justify-content: space-between; gap: 10px; font-size: .88rem; padding: 3px 0; }
.cc-line span:last-child { font-weight: 600; white-space: nowrap; }
.cc-total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
.cc-card .btn { margin-top: 8px; }
.extra-row .extra-remove { font-size: 1.1rem; width: 40px; }

/* ---------- Acabamento de UI/UX ---------- */
:root { --ease: cubic-bezier(.2, .7, .2, 1); --focus: 0 0 0 3px rgba(26, 86, 219, .35); }
.ico { width: 22px; height: 22px; flex: none; }
.tabbar .ico { width: 24px; height: 24px; }
.tabbar button { min-height: 58px; transition: color .15s var(--ease); }
.tabbar button.active .ico { stroke-width: 2.4; }
.btn.upload .ico { width: 20px; height: 20px; }

/* Alvos de toque de pelo menos 44px */
.btn { min-height: 44px; transition: background-color .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), opacity .15s var(--ease); }
.btn.small { min-height: 40px; }
.btn:active { transform: none; opacity: .82; }
.btn.primary:hover { background: #1647b8; }
.btn:not(.primary):not(.ghost):hover { border-color: #c8d0de; }
.link { min-height: 36px; padding: 6px 2px; }
.list-item { transition: border-color .15s var(--ease), background-color .15s var(--ease); }
.list-item:hover { border-color: #c8d0de; }
.list-item:active { background: #f7f9fc; }
.option { transition: border-color .15s var(--ease), background-color .15s var(--ease); }

/* Foco visível para teclado */
:where(a, button, input, select, textarea, label.option, .list-item, summary):focus-visible { outline: none; box-shadow: var(--focus); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }

/* Números alinhados em valores */
.kpi-value, .rank-value, .summary span:last-child, .cc-line span:last-child, .option-price, .table .num { font-variant-numeric: tabular-nums; }

/* Títulos com peso consistente */
h1, .hello, .account-name, .topbar-title, .kpi-value { letter-spacing: -0.01em; }

/* Janelas de baixo entram suavemente */
.sheet { animation: sheet-in .22s var(--ease); }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast { animation: toast-in .2s var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .spinner { animation: spin 1.6s linear infinite !important; }
}
