:root {
  --bg: #f4f6f8; --card: #fff; --ink: #1c2733; --muted: #6b7a89; --line: #e3e8ee;
  --brand: #0e6b7a; --brand-d: #0a525e; --side: #0f2b33; --wa: #1fa855;
  --red: #d64545; --orange: #e08a1e; --yellow: #c9a400; --green: #2e9e5b;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center-text { text-align: center; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex: none; background: var(--side); color: #cfe1e6; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-size: 1.15rem; letter-spacing: .08em; color: #fff; padding: .25rem .5rem 1rem; }
.brand strong { color: #5fd0e0; }
.brand small { display: block; font-size: .7rem; letter-spacing: .2em; text-transform: uppercase; color: #8fb2ba; }
.brand-lg { text-align: center; font-size: 1.6rem; color: var(--side); padding-bottom: 1.25rem; }
.brand-lg strong { color: var(--brand); }
.brand-lg small { color: var(--muted); }
.nav-item { display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem; border-radius: 8px; color: #cfe1e6; font-size: .92rem; }
.nav-item:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-item.disabled { opacity: .45; cursor: default; }
.nav-item.disabled:hover { background: none; }
.nav-item em { margin-left: auto; font-size: .62rem; font-style: normal; text-transform: uppercase; letter-spacing: .05em; }
.ic { width: 1.4rem; text-align: center; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .7rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.menu-btn { display: none; background: none; border: 0; font-size: 1.4rem; cursor: pointer; }
.search { flex: 1; max-width: 520px; }
.search input { width: 100%; }
.user { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.user small { color: var(--muted); display: block; font-size: .72rem; text-align: right; }
.content { padding: 1.5rem; max-width: 1280px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: .15rem 0 0; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.center { text-align: center; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; color: var(--ink); display: block; }
.stat:hover { border-color: var(--brand); text-decoration: none; }
.stat span { display: block; color: var(--muted); font-size: .8rem; }
.stat strong { font-size: 1.8rem; line-height: 1.2; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.25rem; }
.grid-2 > .card { margin-bottom: 1.25rem; }

/* Alertas */
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert-ok { background: #eaf7ef; border-color: #b7e2c6; color: #1d6a3c; }
.alert-error { background: #fdeeee; border-color: #f2c0c0; color: #9b2a2a; }
.alert-warn { background: #fff6e5; border-color: #f2d9a3; color: #8a5a00; }
.alerts, .plain-list { list-style: none; margin: 0 0 .75rem; padding: 0; }
.plain-list li { padding: .3rem 0; }
.alert-row { padding: .55rem .8rem; border-radius: 8px; margin-bottom: .5rem; border-left: 4px solid; background: #f8fafb; }
.alert-row.red { border-color: var(--red); } .alert-row.orange { border-color: var(--orange); } .alert-row.yellow { border-color: var(--yellow); }
.alert-row a { color: var(--ink); display: block; }

/* Formulários */
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .75rem; }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; padding: .55rem .7rem; border: 1px solid #cdd6df; border-radius: 8px; font: inherit; color: var(--ink); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(14,107,122,.35); border-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 1rem; }
.span-2 { grid-column: 1 / -1; }
.actions { display: flex; gap: .6rem; margin-top: .25rem; }
.filters { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1.25rem; }
.filters label { margin: 0; }
.filters input[type=search] { min-width: 280px; margin: 0; }
form.inline { display: inline; }
.st-select { width: auto; margin: 0; padding: .25rem .4rem; font-size: .82rem; }

/* Botões */
.btn { display: inline-block; padding: .55rem 1rem; border: 1px solid var(--brand); background: var(--brand); color: #fff; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--brand-d); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--brand); }
.btn-ghost:hover { background: #eaf4f6; }
.btn-wa { background: var(--wa); border-color: var(--wa); }
.btn-wa:hover { background: #178a46; }
.btn-sm { padding: .3rem .65rem; font-size: .82rem; }
.btn-block { width: 100%; text-align: center; }
.btn-row { display: flex; gap: .5rem; align-items: center; }
.btn-row.wrap { flex-wrap: wrap; }

/* Tabelas */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .65rem .9rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.right, .table th.right { text-align: right; }
.table td small { display: block; }

/* Badges de status */
.badge, .st-select { border-radius: 999px; border: 1px solid transparent; }
.badge { display: inline-block; padding: .1rem .6rem; font-size: .76rem; font-weight: 600; }
.st-agendada { background: #e8f1fb; color: #1f5fa8; }
.st-confirmada { background: #e3f6ee; color: #1b7a4b; }
.st-realizada { background: #e8f7e8; color: #2a7a2a; }
.st-faltou { background: #fdeaea; color: #a42d2d; }
.st-cancelada { background: #eee; color: #666; }
.st-encaixe { background: #fff3dc; color: #8a5a00; }

/* Etapa 2: comercial */
[hidden] { display: none !important; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: .5rem 0; }
.stat small { display: block; color: var(--muted); font-size: .75rem; }
.text-red { color: var(--red); }
label.check { display: flex; align-items: center; gap: .4rem; margin-bottom: .55rem; }
label.check input { width: auto; margin: 0; }
.fs { border: 0; padding: 0; margin: 0; min-width: 0; }
.mt { margin-top: 1rem; }
.tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.tab { padding: .4rem .8rem; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink); font-size: .85rem; }
.tab b { color: var(--muted); margin-left: .2rem; }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tab.active b { color: #d7eef2; }
.tab:hover { text-decoration: none; border-color: var(--brand); }
.days { display: inline-block; min-width: 3rem; text-align: center; padding: .1rem .55rem; border-radius: 999px; font-weight: 700; font-size: .8rem; }
.d-green { background: #e3f6ee; color: #1b7a4b; } .d-yellow { background: #fff6cc; color: #7a6500; }
.d-orange { background: #ffe9cf; color: #9a5300; } .d-red { background: #fde0e0; color: #a42d2d; } .d-none { background: #eee; color: #666; }
.lead-novo, .lead-primeiro_contato { background: #e8f1fb; color: #1f5fa8; }
.lead-agendamento, .lead-avaliacao_realizada { background: #efe9fb; color: #5b3aa8; }
.lead-orcamento_apresentado, .lead-negociacao, .lead-aguardando_retorno { background: #fff3dc; color: #8a5a00; }
.lead-fechado, .lead-tratamento_andamento, .lead-tratamento_concluido { background: #e3f6ee; color: #1b7a4b; }
.lead-nao_fechou, .lead-sem_interesse { background: #eee; color: #666; }
.bud-rascunho, .bud-cancelado { background: #eee; color: #666; }
.bud-apresentado { background: #e8f1fb; color: #1f5fa8; }
.bud-em_negociacao, .bud-aguardando_retorno { background: #fff3dc; color: #8a5a00; }
.bud-fechado { background: #e3f6ee; color: #1b7a4b; }
.bud-perdido { background: #fdeaea; color: #a42d2d; }
.items { margin-bottom: .6rem; }
.item-row { display: grid; grid-template-columns: 1fr 90px 170px 40px; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.item-row input { margin: 0; }
.item-head { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.totals { align-self: end; text-align: right; font-size: 1rem; line-height: 1.8; }
.funnel-row { display: grid; grid-template-columns: 200px 1fr 260px; gap: 1rem; align-items: center; margin-bottom: .7rem; }
.funnel-bar { background: #eef2f5; border-radius: 6px; height: 26px; overflow: hidden; }
.funnel-bar span { display: block; height: 100%; background: var(--brand); border-radius: 6px; min-width: 2px; }
.funnel-meta { font-size: .85rem; }
tfoot td { border-top: 2px solid var(--line); background: #fafbfc; }

/* Etapa 3: convênios e calendário */
.bil-aberto, .bil-em_conferencia { background: #e8f1fb; color: #1f5fa8; }
.bil-pronto_envio { background: #efe9fb; color: #5b3aa8; }
.bil-enviado, .bil-em_analise { background: #fff3dc; color: #8a5a00; }
.bil-glosado_parcialmente { background: #ffe9cf; color: #9a5300; }
.bil-recebido { background: #e3f6ee; color: #1b7a4b; }
.bil-atrasado { background: #fdeaea; color: #a42d2d; }
.cal-title { min-width: 9.5rem; text-align: center; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: #fafbfc; padding: .4rem; text-align: center; font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.cal-day { background: var(--card); min-height: 96px; padding: .3rem; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-day.empty { background: #fafbfc; }
.cal-day.today { background: #f0fafc; box-shadow: inset 0 0 0 2px var(--brand); }
.cal-num { font-size: .75rem; color: var(--muted); font-weight: 700; }
.chip { display: block; padding: 1px 6px; border-radius: 4px; font-size: .7rem; line-height: 1.5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; }
.legend .chip { display: inline-block; }
a.chip:hover { text-decoration: none; filter: brightness(1.1); }
.chip.done { opacity: .45; text-decoration: line-through; }
.ev-fechamento { background: #6b4fbb; } .ev-envio { background: #d9822b; } .ev-pagamento { background: #2e9e5b; }
.ev-conferencia { background: #2f7fc1; } .ev-glosa { background: #c0392b; } .ev-recurso { background: #a23b72; } .ev-outra { background: #6b7a89; }

/* Etapa 4: financeiro */
.chart { display: flex; align-items: flex-end; gap: .75rem; height: 180px; padding-top: .5rem; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.chart-bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.bar { display: block; width: 40%; max-width: 28px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-sold { background: #6b4fbb; } .bar-rec { background: #2e9e5b; }
.chart-col small { color: var(--muted); font-size: .7rem; margin-top: .25rem; }
.chip.bar-sold, .chip.bar-rec { display: inline-block; }

/* Etapa 5: integrações */
.filters .grow { flex: 1; min-width: 260px; }
.steps { margin: .5rem 0 0; padding-left: 1.2rem; }
.steps li { margin-bottom: .3rem; }
.sync-box { display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: center; background: #f6fafb; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1rem; letter-spacing: .04em; }
.code, pre.code { background: #0f2b33; color: #d7eef2; padding: .7rem .9rem; border-radius: 8px; overflow-x: auto; font-size: .82rem; }
code { background: #eef2f5; padding: 0 .3rem; border-radius: 4px; font-size: .85em; }

/* Etapa 6: base própria */
.timeline.tall { max-height: 520px; }
.timeline.tall li span:not(.tl-ic) { white-space: normal; }

/* Dados do paciente */
.dl { display: grid; grid-template-columns: 120px 1fr; gap: .45rem .75rem; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
.timeline li { display: flex; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border: 0; }
.timeline li div { display: flex; flex-direction: column; }
.tl-ic { font-size: 1.1rem; width: 1.6rem; text-align: center; }

/* Login / páginas simples */
body.plain { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.plain-box { width: 100%; max-width: 400px; }
.plain-box .card { padding: 1.5rem; }

/* Responsivo */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .menu-btn { display: block; }
  .topbar { padding: .6rem 1rem; gap: .6rem; }
  .user span { display: none; }
  .content { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 100px 1fr; }
  .item-row { grid-template-columns: 1fr 70px 110px 36px; }
  .item-head span:nth-child(3) { font-size: .65rem; }
  .funnel-row { grid-template-columns: 1fr; gap: .25rem; }
  .cal-day { min-height: 64px; padding: .15rem; }
  .cal .chip { font-size: .6rem; padding: 0 3px; }
}
