:root {
  --navy: #04122f; --navy-2: #0c2148; --navy-3: #1a3463;
  --gold: #d9b45a; --gold-2: #e4c665; --gold-soft: #f4ead0;
  --bg: #f6f3ec; --card: #ffffff; --ink: #14203a; --muted: #5a6478; --line: #e2dccd;
  --ok: #1f6b4a; --ok-bg: #e5f3ec; --warn: #8a5a00; --warn-bg: #fdf1d8; --err: #9b1c1c; --err-bg: #fbe9e9; --info-bg: #eaf0fb;
  --radius: 14px; --shadow: 0 1px 2px rgba(4,18,47,.06), 0 6px 20px -10px rgba(4,18,47,.18);
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.5; -webkit-font-smoothing: antialiased; min-height: 100vh; }
a { color: var(--navy-3); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; color: var(--navy); }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: .35rem 0 .75rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* faixa de ambiente */
.envbar { background: repeating-linear-gradient(45deg, #8a5a00, #8a5a00 10px, #a36d06 10px, #a36d06 20px); color: #fff; text-align: center; font-size: .78rem; font-weight: 700; letter-spacing: .04em; padding: 4px 8px; position: sticky; top: 0; z-index: 50; }

/* topo */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 12px; padding: 10px 16px; position: sticky; top: 24px; z-index: 40; }
.topbar img { height: 34px; }
.topbar .who { margin-left: auto; text-align: right; font-size: .8rem; line-height: 1.2; }
.topbar .who b { display: block; font-size: .88rem; }
.topbar button { background: transparent; color: var(--gold-2); border: 1px solid rgba(228,198,101,.5); border-radius: 10px; padding: 6px 10px; font: inherit; font-size: .82rem; cursor: pointer; }

.wrap { max-width: 980px; margin: 0 auto; padding: 18px 16px 120px; }
.wrap.narrow { max-width: 560px; }

/* navegação */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.tabs a { white-space: nowrap; text-decoration: none; color: var(--navy); background: #fff; border: 1px solid var(--line); padding: 8px 12px; border-radius: 999px; font-size: .88rem; font-weight: 600; }
.tabs a.on { background: var(--navy); color: var(--gold-2); border-color: var(--navy); }
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 40; }
.bottomnav a { text-decoration: none; color: var(--muted); font-size: .72rem; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 6px; min-width: 56px; }
.bottomnav a .ic { font-size: 1.15rem; line-height: 1; }
.bottomnav a.on { color: var(--navy); font-weight: 700; }
.bottomnav a .badge { position: absolute; margin-left: 22px; margin-top: -4px; }

/* cartões */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.navy { background: var(--navy); color: #fff; border-color: var(--navy); }
.card.navy h2, .card.navy h3 { color: var(--gold-2); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* botões e campos */
.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; appearance: none; border: 0; border-radius: 12px; padding: 12px 16px; font: inherit; font-weight: 700; cursor: pointer; background: var(--navy); color: #fff; min-height: 46px; }
.btn:hover { background: var(--navy-2); }
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.btn.danger { background: var(--err); }
.btn.small { padding: 7px 11px; min-height: 34px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; display: flex; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
label.field { display: block; margin: 10px 0; font-weight: 600; font-size: .92rem; }
label.field > span { display: block; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=date], input[type=time], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid #cfc7b4; border-radius: 10px; padding: 11px 12px; min-height: 46px;
}
textarea { min-height: 96px; resize: vertical; }
.hint { font-weight: 400; color: var(--muted); font-size: .85rem; }

/* mensagens */
.alert { border-radius: 12px; padding: 12px 14px; margin: 10px 0; font-size: .93rem; border: 1px solid transparent; }
.alert.err { background: var(--err-bg); color: var(--err); border-color: #f1c4c4; }
.alert.ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe2cf; }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: #f0d9a8; }
.alert.info { background: var(--info-bg); color: var(--navy-3); border-color: #cfdcf3; }
.d010 { font-size: .8rem; color: var(--muted); border-top: 1px solid var(--line); margin-top: 22px; padding-top: 10px; }
.d010.box { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 10px; padding: 10px 12px; color: var(--ink); font-size: .9rem; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--gold-soft); color: var(--navy); }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.err { background: var(--err-bg); color: var(--err); } .badge.gray { background: #eceae4; color: #4a4a4a; }

/* login */
.auth { min-height: calc(100vh - 24px); background: var(--navy); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.auth .logo { width: min(280px, 70vw); border-radius: 8px; }
.auth .panel { width: 100%; max-width: 400px; margin-top: 10px; }
.auth input { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.22); }
.auth input::placeholder { color: rgba(255,255,255,.55); }
.auth label.field { color: #fff; }
.auth .btn { background: var(--gold); color: var(--navy); width: 100%; }
.auth .links { display: flex; justify-content: space-between; margin-top: 14px; font-size: .88rem; }
.auth .links a { color: var(--gold-2); }
.auth .d010 { color: rgba(255,255,255,.7); border-color: rgba(255,255,255,.15); max-width: 400px; text-align: center; }
.auth .alert.err { background: #3b1220; color: #ffd7d7; border-color: #6b2333; }
.auth .alert.ok { background: #10301f; color: #c9f0da; border-color: #24563c; }
.auth .alert.info { background: #0f2550; color: #d9e6ff; border-color: #29457d; }

/* intake */
.progress { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 14px; }
.progress span { font-size: .72rem; padding: 3px 8px; border-radius: 999px; background: #eceae4; color: #555; }
.progress span.on { background: var(--navy); color: var(--gold-2); }
.progress span.done { background: var(--ok-bg); color: var(--ok); }
.q { margin: 0 0 18px; }
.q .prompt { font-weight: 700; font-size: 1.04rem; margin-bottom: 6px; }
.q .help { color: var(--muted); font-size: .9rem; margin: -2px 0 8px; }
.opts { display: grid; gap: 8px; }
.opt { display: flex; gap: 10px; align-items: flex-start; background: #fff; border: 1px solid #d9d2c1; border-radius: 12px; padding: 11px 12px; cursor: pointer; }
.opt input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--navy); flex: none; }
.opt.sel { border-color: var(--navy); background: #f1f4fa; box-shadow: inset 0 0 0 1px var(--navy); }
.opt.special { border-style: dashed; }
.opt .other { margin-top: 6px; }
.scale { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.scale button { min-height: 44px; border: 1px solid #cfc7b4; background: #fff; border-radius: 8px; font: inherit; font-weight: 700; cursor: pointer; padding: 0; }
.scale button.sel { background: var(--navy); color: var(--gold-2); border-color: var(--navy); }
.anchors { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-top: 4px; gap: 10px; }
.anchors span:last-child { text-align: right; }
.stickybar { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 14px 0 8px; display: flex; gap: 10px; }
.listitem { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.listitem input[type=text] { flex: 1; }
.review-part { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.review-row { display: grid; grid-template-columns: 1fr; gap: 2px; padding: 6px 0; border-bottom: 1px dashed #ece6d8; }
.review-row .a { font-weight: 600; }
.addendum { background: var(--gold-soft); border-left: 4px solid var(--gold); padding: 8px 10px; border-radius: 8px; margin: 6px 0; font-size: .9rem; }

/* tabela do painel */
table.list { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.list th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px 8px; border-bottom: 1px solid #eee8db; vertical-align: top; }
table.list tr.click { cursor: pointer; } table.list tr.click:hover { background: #faf7f0; }
@media (max-width: 720px) {
  table.list.responsive thead { display: none; }
  table.list.responsive tr { display: block; background: #fff; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; padding: 6px 4px; }
  table.list.responsive td { display: flex; gap: 8px; border: 0; padding: 4px 8px; }
  table.list.responsive td::before { content: attr(data-l); color: var(--muted); font-size: .78rem; min-width: 96px; }
}

/* timeline e mensagens */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.tl li::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); border: 2px solid #fff; }
.tl .when { font-size: .78rem; color: var(--muted); }
.msg { max-width: 86%; padding: 10px 12px; border-radius: 14px; margin: 6px 0; font-size: .93rem; }
.msg.me { margin-left: auto; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .meta { font-size: .72rem; opacity: .75; margin-top: 4px; }
.action { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fff; }
.action h3 { margin-bottom: 6px; }
.empty { text-align: center; color: var(--muted); padding: 26px 12px; border: 1px dashed #d6cfbd; border-radius: 14px; background: #fbfaf6; }
.spinner { width: 28px; height: 28px; border: 3px solid #ddd; border-top-color: var(--navy); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 100; font-size: .9rem; box-shadow: var(--shadow); max-width: 90vw; }
dialog { border: 0; border-radius: 16px; padding: 20px; max-width: 460px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(4,18,47,.55); }
.codebox { font-family: ui-monospace, Menlo, monospace; font-size: 1.4rem; letter-spacing: .12em; background: var(--gold-soft); border: 1px dashed var(--gold); border-radius: 10px; padding: 12px; text-align: center; color: var(--navy); user-select: all; }
.qr { background: #fff; padding: 10px; display: inline-block; border-radius: 10px; }

@media print {
  .envbar, .topbar, .bottomnav, .tabs, .noprint, .stickybar { display: none !important; }
  body { background: #fff; } .card { box-shadow: none; break-inside: avoid; }
  .wrap { padding: 0; max-width: none; }
}
.wrap.narrow .stickybar { bottom: calc(62px + env(safe-area-inset-bottom)); }
@media (max-width: 420px) { .topbar { gap: 8px; padding: 8px 10px; } .topbar .who { font-size: .72rem; } .topbar img { height: 28px; } }

/* Linhas de cuidado (triagem e consulta) */
.ln .opts { display: grid; gap: 8px; margin: 6px 0 12px; }
.ln .opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; font-size: .95rem; min-width: 0; background: var(--card); }
.ln .opt input { margin-top: 4px; accent-color: var(--navy); flex: none; }
.ln .opt.on { border-color: var(--gold); background: var(--gold-soft); }
.ln .q { font-weight: 700; font-size: .95rem; margin-top: 8px; }
.ln .hint { font-size: .85rem; color: var(--muted); }
.ln label.f { display: grid; gap: 5px; font-weight: 600; font-size: .95rem; margin: 10px 0; }
.ln .nav { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; margin-top: 14px; }
.ln .prog { height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; margin-bottom: 12px; }
.ln .prog i { display: block; height: 100%; background: var(--gold); transition: width .25s; }
.ln .sem { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 700; }
.ln .sem.verde { background: var(--ok-bg); color: var(--ok); } .ln .sem.amarelo { background: var(--warn-bg); color: var(--warn); } .ln .sem.vermelho { background: var(--err-bg); color: var(--err); }
.ln .grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 6px 14px; }
.ln .ck { display: flex; gap: 8px; align-items: flex-start; font-size: .9rem; cursor: pointer; min-width: 0; }
.ln .ck input { margin-top: 4px; accent-color: var(--navy); }
.ln .ck.alert span { color: var(--err); }
.ln details.sec { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; }
.ln details.sec > summary { cursor: pointer; padding: 12px 14px; font-weight: 700; }
.ln details.sec .body { padding: 0 14px 12px; display: grid; gap: 10px; }
.ln .qq { background: var(--gold-soft); border-radius: 10px; padding: 10px 12px; display: grid; gap: 6px; }
.ln .qq textarea { min-height: 44px; }
.ln .sub { font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.ln .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.ln .acard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 6px; align-content: start; min-width: 0; }
.ln .acard.bloq { opacity: .62; }
.ln .acard h3 { margin: 0; }
.ln .acard p { margin: 0; font-size: .85rem; }
.ln .pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 700; }
.ln .p-ok { background: var(--ok-bg); color: var(--ok); } .ln .p-w { background: var(--warn-bg); color: var(--warn); } .ln .p-b { background: var(--err-bg); color: var(--err); } .ln .p-n { background: #eceff0; color: var(--muted); }
.ln .kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: .82rem; border-top: 1px solid var(--line); padding-top: 6px; margin: 0; }
.ln .kv dt { color: var(--muted); } .ln .kv dd { margin: 0; font-weight: 600; }
