:root {
  --fundo: #f4f6fb;
  --painel: #ffffff;
  --texto: #1b2333;
  --suave: #5d6880;
  --borda: #dfe4ee;
  --primaria: #1d4ed8;
  --primaria-txt: #ffffff;
  --primaria-suave: #e6edff;
  --ok: #15803d;
  --ok-suave: #e3f6e9;
  --alerta: #b45309;
  --alerta-suave: #fdf1dc;
  --perigo: #b91c1c;
  --perigo-suave: #fde6e6;
  --sombra: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .05);
  --raio: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #0f1420;
    --painel: #171e2d;
    --texto: #e6eaf2;
    --suave: #9aa5bb;
    --borda: #2a3448;
    --primaria: #5b8cff;
    --primaria-txt: #0b1020;
    --primaria-suave: #1f2c4d;
    --ok: #4ade80;
    --ok-suave: #163322;
    --alerta: #fbbf24;
    --alerta-suave: #3a2c10;
    --perigo: #f87171;
    --perigo-suave: #3d1717;
    --sombra: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fundo);
  color: var(--texto);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primaria); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.carregando { padding: 3rem; text-align: center; color: var(--suave); }
.suave { color: var(--suave); }
.pequeno { font-size: .85rem; }
.direita { text-align: right; }
.forte { font-weight: 600; }
.oculto, [hidden] { display: none !important; }
.campo input[name="placa"] { text-transform: uppercase; }

/* ------------------------------------------------ estrutura */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.lateral {
  background: var(--painel);
  border-right: 1px solid var(--borda);
  padding: 1rem .75rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: .25rem;
}
.marca { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; padding: .25rem .5rem 1rem; }
.marca img { width: 32px; height: 32px; }
.lateral a.item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .7rem; border-radius: 9px; color: var(--texto);
}
.lateral a.item:hover { background: var(--fundo); text-decoration: none; }
.lateral a.item.ativo { background: var(--primaria-suave); color: var(--primaria); font-weight: 600; }
.lateral .ico { width: 1.4rem; text-align: center; }
.lateral .grupo { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--suave); padding: .9rem .7rem .3rem; }
.lateral .rodape { margin-top: auto; padding: .75rem .5rem 0; border-top: 1px solid var(--borda); font-size: .85rem; }
.conteudo { padding: 1.5rem clamp(1rem, 3vw, 2.25rem) 4rem; max-width: 1280px; width: 100%; min-width: 0; }
.topo-movel { display: none; }
.cortina { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .lateral {
    position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 40;
    transform: translateX(-105%); transition: transform .2s ease;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
  }
  .menu-aberto .lateral { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .menu-aberto .cortina { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  .topo-movel {
    display: flex; align-items: center; gap: .75rem;
    position: sticky; top: 0; z-index: 20;
    background: var(--painel); border-bottom: 1px solid var(--borda);
    padding: calc(.6rem + env(safe-area-inset-top, 0px)) 1rem .6rem;
    font-weight: 700;
  }
  .topo-movel button { font-size: 1.3rem; padding: .2rem .55rem; }
  .conteudo { padding-top: 1rem; }
}

/* ------------------------------------------------ componentes */
.cabecalho { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.cabecalho h1 { flex: 1 1 auto; }
.cabecalho .acoes { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

button, .botao {
  font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: 9px;
  border: 1px solid var(--borda); background: var(--painel); color: var(--texto);
  text-decoration: none; white-space: nowrap;
}
button:hover, .botao:hover { text-decoration: none; filter: brightness(.97); }
button:disabled { opacity: .55; cursor: default; }
.primario { background: var(--primaria); border-color: var(--primaria); color: var(--primaria-txt); font-weight: 600; }
.perigo { color: var(--perigo); border-color: var(--perigo); background: transparent; }
.discreto { border-color: transparent; background: transparent; }
.mini { padding: .3rem .6rem; font-size: .85rem; }

.cartao {
  background: var(--painel); border: 1px solid var(--borda); border-radius: var(--raio);
  box-shadow: var(--sombra); padding: 1.1rem 1.2rem; margin-bottom: 1rem; min-width: 0;
}
.grade { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.kpis { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 1rem; }
.kpi { background: var(--painel); border: 1px solid var(--borda); border-radius: var(--raio); padding: .9rem 1rem; box-shadow: var(--sombra); }
.kpi .rot { color: var(--suave); font-size: .82rem; }
.kpi .val { font-size: 1.45rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.kpi .det { color: var(--suave); font-size: .8rem; }

.selo { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--fundo); color: var(--suave); }
.selo.ok { background: var(--ok-suave); color: var(--ok); }
.selo.alerta { background: var(--alerta-suave); color: var(--alerta); }
.selo.perigo { background: var(--perigo-suave); color: var(--perigo); }
.selo.info { background: var(--primaria-suave); color: var(--primaria); }

.lista-alertas { list-style: none; margin: 0; padding: 0; }
.lista-alertas li { padding: .55rem 0; border-top: 1px solid var(--borda); display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.lista-alertas li:first-child { border-top: 0; }
.vazio { color: var(--suave); padding: 1rem 0; text-align: center; }

/* tabelas: viram cartões no celular */
.tabela-wrap { overflow-x: auto; }
table.dados { width: 100%; border-collapse: collapse; }
table.dados th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--suave); font-weight: 600; padding: .55rem .6rem; border-bottom: 1px solid var(--borda); white-space: nowrap; }
table.dados td { padding: .6rem; border-bottom: 1px solid var(--borda); vertical-align: top; }
table.dados tr.clicavel { cursor: pointer; }
table.dados tr.clicavel:hover td { background: var(--fundo); }
table.dados td.num, table.dados th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.dados tfoot td { font-weight: 700; border-bottom: 0; }
@media (max-width: 700px) {
  table.dados.responsiva thead { display: none; }
  table.dados.responsiva, table.dados.responsiva tbody, table.dados.responsiva tr, table.dados.responsiva td { display: block; width: 100%; }
  table.dados.responsiva tr { border: 1px solid var(--borda); border-radius: 10px; margin-bottom: .6rem; padding: .35rem .2rem; background: var(--painel); }
  table.dados.responsiva td { border: 0; padding: .2rem .7rem; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  table.dados.responsiva td::before { content: attr(data-rot); color: var(--suave); font-size: .82rem; text-align: left; }
  table.dados.responsiva td.num { justify-content: space-between; }
  table.dados.responsiva tfoot tr { border: 0; }
}

/* filtros */
.filtros { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .9rem; }
.filtros input, .filtros select { width: auto; flex: 1 1 180px; max-width: 320px; }

/* formulários */
input, select, textarea {
  font: inherit; width: 100%;
  padding: .55rem .7rem; border-radius: 9px;
  border: 1px solid var(--borda); background: var(--painel); color: var(--texto);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primaria); outline-offset: -1px; border-color: var(--primaria); }
input:disabled, select:disabled, textarea:disabled { background: var(--fundo); color: var(--texto); opacity: 1; }
textarea { resize: vertical; }
.secao { margin-bottom: 1rem; }
.campos { display: grid; gap: .8rem 1rem; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.campo { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.campo > span { font-size: .82rem; color: var(--suave); font-weight: 500; }
.campo.w2 { grid-column: span 2; }
.campo.w3 { grid-column: span 3; }
.campo.w4 { grid-column: 1 / -1; }
@media (max-width: 900px) { .campos { grid-template-columns: repeat(2, minmax(0, 1fr)); } .campo.w3 { grid-column: 1 / -1; } }
@media (max-width: 520px) { .campos { grid-template-columns: 1fr; } .campo.w2, .campo.w3 { grid-column: auto; } }
.barra-salvar {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end;
  padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(transparent, var(--fundo) 35%);
}
.barra-salvar .esq { margin-right: auto; }

/* abas */
.abas { display: flex; gap: .25rem; border-bottom: 1px solid var(--borda); margin-bottom: 1rem; overflow-x: auto; }
.abas a { padding: .6rem .9rem; color: var(--suave); border-bottom: 2px solid transparent; white-space: nowrap; }
.abas a:hover { text-decoration: none; color: var(--texto); }
.abas a.ativo { color: var(--primaria); border-bottom-color: var(--primaria); font-weight: 600; }

.ficha { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem 1.2rem; }
.ficha div span { display: block; font-size: .78rem; color: var(--suave); }

/* fotos */
.semana { margin-bottom: 1.5rem; }
.semana > h3 { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.miniaturas { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.miniaturas button { padding: 0; border: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: var(--fundo); position: relative; }
.miniaturas img { width: 100%; height: 100%; object-fit: cover; display: block; }
.miniaturas .leg { position: absolute; left: 0; right: 0; bottom: 0; padding: .2rem .4rem; font-size: .72rem; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.65)); text-align: left; }
.previas { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.previas img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.progresso { height: 8px; background: var(--fundo); border-radius: 99px; overflow: hidden; margin-top: .6rem; }
.progresso div { height: 100%; width: 0; background: var(--primaria); transition: width .2s; }

.visor { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; flex-direction: column; color: #fff; }
.visor .barra { display: flex; gap: .5rem; align-items: center; padding: calc(.6rem + env(safe-area-inset-top, 0px)) .8rem .6rem; }
.visor .barra .info { flex: 1; font-size: .9rem; min-width: 0; }
.visor .barra button { background: rgba(255,255,255,.12); color: #fff; border-color: transparent; }
.visor .img { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: .5rem; }
.visor .img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.visor .nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 1.6rem; background: rgba(255,255,255,.15); color: #fff; border: 0; width: 46px; height: 46px; border-radius: 50%; }
.visor .nav.ant { left: .6rem; }
.visor .nav.prox { right: .6rem; }

/* login */
.tela-login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.tela-login .cartao { width: min(100%, 400px); padding: 1.75rem; }
.tela-login form { display: grid; gap: .9rem; }
.tela-login .marca { justify-content: center; padding-bottom: .5rem; font-size: 1.35rem; }

/* avisos (toast) */
#avisos { position: fixed; z-index: 80; left: 50%; transform: translateX(-50%); bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); display: grid; gap: .5rem; width: min(92vw, 420px); }
.aviso { padding: .75rem 1rem; border-radius: 10px; background: #1b2333; color: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.aviso.erro { background: #b91c1c; }
.aviso.ok { background: #15803d; }

.caixa-link { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.caixa-link input { flex: 1 1 260px; font-family: ui-monospace, monospace; font-size: .85rem; }

/* documento do contrato */
.documento { background: #fff; color: #111; max-width: 820px; margin: 0 auto; padding: 2.5rem 3rem; border-radius: 6px; box-shadow: var(--sombra); font-family: Georgia, "Times New Roman", serif; font-size: 15px; line-height: 1.6; }
.documento h1 { text-align: center; font-size: 1.2rem; letter-spacing: .03em; margin-bottom: 1.5rem; }
.documento h2 { font-size: 1rem; margin: 1.25rem 0 .4rem; }
.documento p { margin: .4rem 0; text-align: justify; }
.documento .clausulas { white-space: pre-wrap; text-align: justify; }
.documento .assinaturas { display: grid; grid-template-columns: 1fr 1fr; gap: 2.5rem 2rem; margin-top: 3rem; }
.documento .assinaturas div { border-top: 1px solid #111; padding-top: .3rem; text-align: center; font-size: .9rem; }
.documento p.item { padding-left: 1.5rem; }
.documento .lacuna { background: #fde68a; color: #92400e; padding: 0 .2rem; border-radius: 3px; }
@media (max-width: 600px) { .documento { padding: 1.25rem; } .documento .assinaturas { grid-template-columns: 1fr; } }
@media print {
  .lateral, .topo-movel, .nao-imprimir, #avisos { display: none !important; }
  .layout { display: block; }
  .conteudo { padding: 0; max-width: none; }
  body { background: #fff; }
  .documento { box-shadow: none; padding: 0; max-width: none; }
  .documento .lacuna { background: none; color: inherit; }
}
.documento .assinaturas .parte { grid-column: 1 / -1; justify-self: center; width: min(100%, 360px); }

/* vínculos */
.vinc { display: grid; grid-template-columns: 150px 1fr; gap: .5rem 1rem; padding: .55rem 0; border-top: 1px solid var(--borda); align-items: baseline; }
.vinc:first-of-type { border-top: 0; }
.vinc .rot { color: var(--suave); font-size: .85rem; font-weight: 600; }
.vinc .sep { color: var(--suave); margin: 0 .45rem; }
@media (max-width: 600px) { .vinc { grid-template-columns: 1fr; gap: .2rem; } }

/* folha para salvar PDF (modelos de contrato) */
.folha-pdf { position: fixed; inset: 0; z-index: 70; overflow: auto; background: var(--fundo); padding: 1rem; }
.folha-pdf .barra-pdf { position: sticky; top: 0; z-index: 1; display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: flex-end;
  max-width: 820px; margin: 0 auto 1rem; padding: .7rem 1rem; background: var(--painel); border: 1px solid var(--borda); border-radius: var(--raio); }
.folha-pdf .barra-pdf span { margin-right: auto; font-size: .9rem; }
@media print {
  body.modo-pdf #app { display: none !important; }
  body.modo-pdf .folha-pdf { position: static; overflow: visible; padding: 0; background: #fff; }
}

/* editor de modelo com etiquetas */
.editor-modelo { white-space: pre-wrap; word-break: break-word; font: .84rem/1.6 ui-monospace, Consolas, monospace; min-height: 22rem; max-height: 75vh; overflow: auto;
  padding: .7rem .8rem; border: 1px solid var(--borda); border-radius: 9px; background: var(--painel); color: var(--texto); }
.editor-modelo:focus { outline: 2px solid var(--primaria); outline-offset: -1px; }
.tag-modelo { display: inline-block; padding: 0 .4rem; margin: 0 .05rem; border-radius: 6px; background: var(--primaria-suave); color: var(--primaria);
  font: 600 .74rem/1.55 system-ui, sans-serif; letter-spacing: .02em; cursor: default; user-select: all; vertical-align: baseline; }
.tag-modelo.desconhecida { background: var(--perigo-suave); color: var(--perigo); }
button.botao-tag { border: 0; cursor: pointer; }
.modelo-lado { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; margin-top: 1rem; }
.modelo-lado h3 { margin-bottom: .4rem; }
.previa-viva { max-height: 75vh; overflow: auto; border: 1px solid var(--borda); border-radius: 9px; background: #e9ecf2; padding: .6rem; }
.previa-viva .documento { padding: 1.4rem 1.6rem; font-size: 13px; max-width: none; }
.previa-viva .aviso-faltando { margin: 0 0 .5rem; color: #92400e; }
@media (max-width: 1100px) { .modelo-lado { grid-template-columns: 1fr; } .editor-modelo { min-height: 14rem; } }

/* aviso de nova versão */
#aviso-versao { position: fixed; z-index: 90; top: calc(.8rem + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%);
  display: flex; gap: .8rem; align-items: center; padding: .6rem .8rem .6rem 1rem; border-radius: 12px;
  background: #1b2333; color: #fff; box-shadow: 0 8px 28px rgba(0,0,0,.3); font-weight: 600; }

/* leitura de documentos por IA */
.cartao-ia { border-color: #c4b5fd; background: linear-gradient(180deg, rgba(167,139,250,.10), transparent 70%), var(--painel); }
.cartao-ia input[type=file] { flex: 1 1 260px; }
.aviso-ia { color: var(--alerta); margin: .5rem 0 0; }
.resultado-ia { margin-top: .9rem; border-top: 1px solid var(--borda); padding-top: .7rem; }
.resultado-ia p { margin: .3rem 0; }
.campo.preenchido-ia input, .campo.preenchido-ia select, .campo.preenchido-ia textarea { outline: 2px solid #a855f7; outline-offset: -1px; background: rgba(168,85,247,.08); }
.campo.preenchido-ia > span::after { content: ' · IA'; color: #a855f7; font-weight: 700; }

/* foto das pessoas */
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; display: inline-flex; align-items: center; justify-content: center;
  background: var(--primaria-suave); color: var(--primaria); font: 700 .75rem/1 system-ui, sans-serif; vertical-align: middle; }
.avatar.mini { width: 22px; height: 22px; font-size: .6rem; }
.avatar.grande { width: 112px; height: 112px; font-size: 2rem; border: 3px solid var(--painel); box-shadow: var(--sombra); }
.com-avatar { display: inline-flex; align-items: center; gap: .55rem; }
.cartao-foto { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.cartao-foto h2 { margin-bottom: .3rem; }
@media (max-width: 700px) { table.dados.responsiva td .com-avatar { flex-direction: row-reverse; } }
