/* Gestão de Cirurgias — tema da aplicação */
:root {
  --app-primary: #0f5c8c;
  --app-primary-600: #0b4a72;
  --app-primary-50: #e8f2f9;
  --app-accent: #0f9d8a;
  --app-bg: #f4f6f9;
  --app-surface: #ffffff;
  --app-border: #e3e8ef;
  --app-text: #1d2733;
  --app-muted: #6b7788;
  --sidebar-w: 248px;
  --bs-primary: #0f5c8c;
  --bs-primary-rgb: 15, 92, 140;
  --bs-link-color: #0f5c8c;
  --bs-link-color-rgb: 15, 92, 140;
  --bs-body-font-size: .925rem;
  --bs-body-color: #1d2733;
  --bs-border-color: #e3e8ef;
}

body { background: var(--app-bg); color: var(--app-text); }
.btn-primary { --bs-btn-bg: var(--app-primary); --bs-btn-border-color: var(--app-primary); --bs-btn-hover-bg: var(--app-primary-600); --bs-btn-hover-border-color: var(--app-primary-600); --bs-btn-active-bg: var(--app-primary-600); }
.btn-outline-primary { --bs-btn-color: var(--app-primary); --bs-btn-border-color: var(--app-primary); --bs-btn-hover-bg: var(--app-primary); --bs-btn-hover-border-color: var(--app-primary); }
.text-purple { color: #6f42c1 !important; }
.bg-purple { background-color: #6f42c1 !important; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
@media (min-width: 992px) {
  /* mantém a coluna da barra lateral preenchida em páginas longas */
  .app-shell { background: linear-gradient(to right, #0e2a3f var(--sidebar-w), transparent var(--sidebar-w)); }
}
@media (max-width: 575.98px) {
  .status-cards { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .status-card { padding: .5rem; }
  .status-card .status-badge { font-size: .6rem; padding: .2rem .4rem; }
  .status-card .count { font-size: 1.2rem; }
}
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: #0e2a3f; color: #c9d6e2;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 1rem .75rem; z-index: 1040;
}
.brand { display: flex; align-items: center; gap: .65rem; color: #fff; text-decoration: none; padding: .25rem .5rem 1.25rem; line-height: 1.1; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, #1a8fd1, #0f9d8a); display: grid; place-items: center; font-size: 1.25rem; }
.brand-text { font-size: .85rem; color: #cfe0ee; }
.brand-text strong { font-size: 1.05rem; color: #fff; }
.side-nav .nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #7f98ad; padding: 1rem .75rem .35rem; }
.side-nav .nav-link { color: #c9d6e2; border-radius: 8px; padding: .5rem .75rem; display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.side-nav .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-nav .nav-link.active { background: #1a8fd1; color: #fff; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 58px; background: var(--app-surface); border-bottom: 1px solid var(--app-border); display: flex; align-items: center; padding: 0 1.5rem; position: sticky; top: 0; z-index: 1030; }
.topbar-title { color: var(--app-muted); font-size: .9rem; }
.user-chip { display: flex; align-items: center; gap: .5rem; border: 1px solid var(--app-border); }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--app-primary); color: #fff; display: grid; place-items: center; font-size: .8rem; font-weight: 600; }
.content { padding: 1.5rem; max-width: 1480px; width: 100%; }

@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: calc(-1 * var(--sidebar-w)); transition: left .2s ease; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .content { padding: 1rem; }
}

/* Cabeçalhos de página */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.45rem; font-weight: 650; margin: 0; }
.page-header .subtitle { color: var(--app-muted); font-size: .9rem; margin-top: .15rem; }

/* Cartões */
.card { border: 1px solid var(--app-border); border-radius: 12px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--app-border); font-weight: 600; padding: .85rem 1.1rem; }
.card-body { padding: 1.1rem; }
.section-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--app-muted); margin-bottom: .75rem; display: flex; align-items: center; gap: .4rem; }
.section-title .step { width: 22px; height: 22px; border-radius: 50%; background: var(--app-primary-50); color: var(--app-primary); display: inline-grid; place-items: center; font-size: .75rem; }

/* Formulários */
.form-label { font-weight: 550; font-size: .85rem; margin-bottom: .3rem; color: #344255; }
.form-label.required::after { content: " *"; color: #d63a3a; }
.form-control, .form-select { border-color: #d5dde7; }
.form-control:focus, .form-select:focus { border-color: #5aa6d6; box-shadow: 0 0 0 .2rem rgba(26,143,209,.15); }
.has-error .form-control, .has-error .form-select, .has-error .ts-control { border-color: #d63a3a; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; padding-top: 1rem; border-top: 1px solid var(--app-border); margin-top: .5rem; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(244,246,249,.95); backdrop-filter: blur(4px); padding: .75rem 0; z-index: 5; }
.ts-wrapper.form-select, .ts-wrapper.form-control { padding: 0; border: 0; box-shadow: none; }
.ts-control { border-color: #d5dde7; border-radius: var(--bs-border-radius); min-height: 38px; font-size: var(--bs-body-font-size); }
.ts-control input, .ts-dropdown { font-size: var(--bs-body-font-size); }
.table-nowrap td, .table-nowrap th { white-space: nowrap; }
.table-nowrap td .wrap { white-space: normal; min-width: 180px; }
.ts-dropdown .option small { color: var(--app-muted); }
.ts-dropdown { z-index: 1060; }

/* Status */
.status-badge { display: inline-flex; align-items: center; gap: .35rem; padding: .28rem .6rem; border-radius: 999px; font-size: .72rem; font-weight: 700; letter-spacing: .03em; white-space: nowrap; border: 1px solid transparent; }
.status-badge.lg { font-size: .85rem; padding: .4rem .85rem; }
.status-solicitado { background: #e6f0fb; color: #1d5fa8; border-color: #c7dcf3; }
.status-negada { background: #fdecec; color: #b42323; border-color: #f6cccc; }
.status-autorizado { background: #e3f6f1; color: #0b7a66; border-color: #bfe8dd; }
.status-agendado { background: #efe9fb; color: #5b34b0; border-color: #dbcff5; }
.status-realizado { background: #e5f5e5; color: #1f7a2e; border-color: #c4e6c7; }
.status-cancelado { background: #eef0f3; color: #4d5866; border-color: #d9dee5; }

.status-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.status-card { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 12px; padding: .75rem .9rem; text-decoration: none; color: inherit; display: block; transition: border-color .15s, box-shadow .15s; }
.status-card:hover { border-color: #9cc5e3; box-shadow: 0 2px 8px rgba(15,92,140,.08); color: inherit; }
.status-card.active { border-color: var(--app-primary); box-shadow: 0 0 0 2px rgba(15,92,140,.15); }
.status-card .count { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }

/* Tabelas */
.table-app { margin: 0; }
.table-app thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--app-muted); font-weight: 650; background: #f8fafc; border-bottom: 1px solid var(--app-border); white-space: nowrap; padding: .65rem .75rem; }
.table-app td { padding: .65rem .75rem; vertical-align: middle; border-color: #eef1f5; }
.table-app tbody tr.row-link { cursor: pointer; }
.table-app tbody tr.row-link:hover td { background: #f5f9fd; }
.table-app thead th a { color: inherit; text-decoration: none; }
.table-app thead th a.sort-link { display: inline; }
.table-app thead th a.sort-link .bi { margin-left: .15rem; white-space: nowrap; }
.table-app thead th a.sort-link:hover, .table-app thead th a.sort-link.active { color: var(--app-primary); }
.table-app thead th .sort-idle { opacity: .35; font-size: .85em; }
.table-app thead th a.sort-link:hover .sort-idle { opacity: .8; }

/* Listagem de cirurgias: tabela densa, títulos quebram linha, cabeçalho fixo na rolagem */
.page-wide .content { max-width: none; }
.table-surgeries { font-size: .82rem; }
.table-surgeries thead th { white-space: normal; vertical-align: bottom; line-height: 1.25; padding: .5rem .4rem; font-size: .76rem; text-transform: none; letter-spacing: 0; }
.table-surgeries td { padding: .4rem .4rem; line-height: 1.3; }
.table-surgeries .col-num { white-space: nowrap; }
.table-surgeries td.col-wide { min-width: 8.5rem; }
.table-surgeries td.col-mid { min-width: 5.5rem; }
.table-surgeries td.col-status { min-width: 7rem; max-width: 10rem; }
.table-surgeries .status-badge { font-size: .64rem; padding: .2rem .45rem; }
.table-surgeries .expiry-badge { white-space: normal; border-radius: 8px; font-size: .68rem; line-height: 1.2; }
.table-surgeries .small-muted { font-size: .74rem; }
.table-scroll { overflow: auto; }
@media (min-width: 992px) {
  .table-scroll { max-height: calc(100vh - 170px); }
  .table-scroll thead th { position: sticky; top: 0; z-index: 2; box-shadow: inset 0 -1px 0 var(--app-border); }
}
/* Termos de Uso e Política de Privacidade */
.legal-public .content { max-width: 960px; }
.legal-draft { display: flex; gap: .6rem; align-items: flex-start; font-size: .88rem; max-width: 960px; }
.legal-doc { max-width: 960px; }
.legal-doc .card-body { padding: 1.5rem 1.75rem; }
.legal-doc section + section { margin-top: 1.4rem; }
.legal-doc h2 { font-size: 1rem; font-weight: 650; color: var(--app-text); margin-bottom: .55rem; }
.legal-doc p, .legal-doc li { line-height: 1.6; color: #344255; }
.legal-doc ul { padding-left: 1.2rem; margin-bottom: .5rem; }
.legal-doc li + li { margin-top: .3rem; }
.legal-doc .legal-table td:first-child { white-space: nowrap; font-weight: 600; }
.legal-fill { background: #fff5e0; color: #8a5a00; border-radius: 4px; padding: 0 .25rem; }
@media (max-width: 575.98px) { .legal-doc .card-body { padding: 1.1rem; } .legal-doc .legal-table td:first-child { white-space: normal; } }
.team-template-picker { background: var(--app-primary-50); border-radius: 10px; padding: .6rem .75rem; }
.team-template-picker .form-select { width: auto; min-width: 16rem; max-width: 100%; }
.pager .page-size-form .form-select { width: auto; padding-top: .15rem; padding-bottom: .15rem; }
.pager .pagination .page-link { min-width: 2rem; text-align: center; }
.surgery-number { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; color: var(--app-primary); }
.muted { color: var(--app-muted); }
.small-muted { color: var(--app-muted); font-size: .8rem; }

/* Filtros */
.filters .form-label { font-size: .75rem; }
.filters-toggle[aria-expanded="true"] .bi-chevron-down { transform: rotate(180deg); }

/* Detalhes */
.detail-hero { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 14px; padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.detail-hero .number { font-size: 1.6rem; font-weight: 750; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--app-primary); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .9rem 1.25rem; }
.kv dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--app-muted); font-weight: 650; margin-bottom: .15rem; }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.flow-steps { display: flex; gap: 0; align-items: center; margin-top: 1rem; overflow-x: auto; padding-bottom: .25rem; }
.flow-step { display: flex; align-items: center; gap: .45rem; font-size: .78rem; font-weight: 650; color: #9aa6b5; white-space: nowrap; }
.flow-step .dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #d3dae3; display: grid; place-items: center; background: #fff; font-size: .8rem; }
.flow-step.done { color: #0b7a66; }
.flow-step.done .dot { border-color: #0f9d8a; background: #0f9d8a; color: #fff; }
.flow-step.current { color: var(--app-primary); }
.flow-step.current .dot { border-color: var(--app-primary); background: var(--app-primary); color: #fff; box-shadow: 0 0 0 4px rgba(15,92,140,.15); }
.flow-step.failed .dot { border-color: #d63a3a; background: #d63a3a; color: #fff; }
.flow-step.failed { color: #b42323; }
.flow-line { flex: 1 1 24px; min-width: 24px; height: 2px; background: #d3dae3; margin: 0 .5rem; }
.flow-line.done { background: #0f9d8a; }

.nav-tabs-app { border-bottom: 1px solid var(--app-border); gap: .25rem; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
.nav-tabs-app .nav-link { border: 0; border-bottom: 2px solid transparent; color: var(--app-muted); font-weight: 600; padding: .6rem .9rem; white-space: nowrap; }
.nav-tabs-app .nav-link.active { color: var(--app-primary); border-bottom-color: var(--app-primary); background: transparent; }
.nav-tabs-app .nav-link .badge { font-weight: 600; }

.stage-col { border-radius: 10px; border: 1px solid var(--app-border); padding: .85rem; height: 100%; background: #fff; }
.stage-col h6 { font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 700; margin-bottom: .6rem; }
.stage-col.req h6 { color: #1d5fa8; }
.stage-col.aut h6 { color: #0b7a66; }
.stage-col.rea h6 { color: #1f7a2e; }
.team-list { list-style: none; padding: 0; margin: 0; }
.team-list li { display: flex; justify-content: space-between; gap: .75rem; padding: .35rem 0; border-bottom: 1px dashed #edf0f4; font-size: .88rem; }
.team-list li:last-child { border-bottom: 0; }
.team-list .role { color: var(--app-muted); font-size: .78rem; }
/* Editores de equipe: autorizada × realizada — visualmente distintos */
.team-editor { border-radius: 10px; border: 1px solid var(--app-border); border-left-width: 4px; padding: .5rem .85rem; background: #fff; }
.team-editor.aut { border-left-color: #0b7a66; }
.team-editor.rea { border-left-color: #1f7a2e; background: #fbfdfb; }
.team-editor-head, .team-editor-row { display: grid; grid-template-columns: 1fr; gap: .25rem .75rem; align-items: center; }
.team-editor-head { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 700; color: var(--app-muted); padding: .35rem 0; border-bottom: 1px solid #edf0f4; }
.team-editor-row { padding: .6rem 0; border-bottom: 1px dashed #edf0f4; }
.team-editor-row:last-child { border-bottom: 0; }
.team-editor-row .form-label { margin: 0; font-weight: 600; }
@media (min-width: 768px) {
  .team-editor-head, .team-editor-row { grid-template-columns: 11rem minmax(0, 1fr); }
}
.cmp-table td.diff { background: #fff8e6; }
.qty-pill { display: inline-block; min-width: 28px; text-align: center; padding: .1rem .45rem; border-radius: 6px; background: #eef3f8; font-weight: 700; font-size: .82rem; }
.qty-none { color: #b8c1cc; }
.principal-tag { font-size: .65rem; font-weight: 700; text-transform: uppercase; background: var(--app-primary-50); color: var(--app-primary); border-radius: 4px; padding: .05rem .35rem; margin-left: .35rem; vertical-align: middle; }

.attempt { border: 1px solid var(--app-border); border-radius: 12px; margin-bottom: 1rem; overflow: hidden; background: #fff; }
.attempt-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; padding: .75rem 1rem; background: #f8fafc; border-bottom: 1px solid var(--app-border); }
.attempt.denied .attempt-head { background: #fff5f5; }
.attempt.current { border-color: #7cc9b8; box-shadow: 0 0 0 2px rgba(15,157,138,.12); }

/* Timeline */
.timeline { position: relative; list-style: none; padding: 0 0 0 2.25rem; margin: 0; }
.timeline::before { content: ""; position: absolute; left: 14px; top: 6px; bottom: 6px; width: 2px; background: #e1e7ee; }
.timeline-item { position: relative; padding: 0 0 1.1rem; }
.timeline-icon { position: absolute; left: -2.25rem; top: 0; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: .9rem; background: #fff; border: 2px solid #d3dae3; color: var(--app-muted); }
.timeline-item.milestone .timeline-icon { color: #fff; border-color: transparent; }
.timeline-item.milestone.c-primary .timeline-icon { background: #1d5fa8; }
.timeline-item.milestone.c-success .timeline-icon { background: #0f9d8a; }
.timeline-item.milestone.c-danger .timeline-icon { background: #d63a3a; }
.timeline-item.milestone.c-purple .timeline-icon { background: #6f42c1; }
.timeline-item.milestone.c-dark .timeline-icon { background: #4d5866; }
.timeline-item.milestone.c-warning .timeline-icon { background: #e39b17; }
.timeline-card { background: #fff; border: 1px solid var(--app-border); border-radius: 10px; padding: .6rem .85rem; }
.timeline-item.milestone .timeline-card { border-left: 3px solid var(--app-primary); }
.timeline-title { font-weight: 700; font-size: .9rem; }
.timeline-meta { font-size: .78rem; color: var(--app-muted); }
.change-list { margin: .4rem 0 0; padding: 0; list-style: none; font-size: .8rem; }
.change-list li { padding: .12rem 0; }
.change-old { color: #b42323; text-decoration: line-through; text-decoration-color: rgba(180,35,35,.4); }
.change-new { color: #1f7a2e; font-weight: 600; }
.timeline.only-milestones .timeline-item:not(.milestone) { display: none; }

/* Procedimentos (editor) */
.proc-editor .proc-row { display: grid; grid-template-columns: 1fr 110px 110px 84px; gap: .5rem; align-items: center; padding: .5rem .6rem; border: 1px solid var(--app-border); border-radius: 10px; margin-bottom: .5rem; background: #fff; }
.proc-editor .proc-row.principal { border-color: #86b7da; background: #f4f9fd; }
.proc-editor .proc-row.replacing { border-color: var(--app-primary); box-shadow: 0 0 0 2px rgba(15,92,140,.15); }
.proc-editor .proc-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; color: var(--app-primary); }
.proc-editor .proc-desc { font-size: .85rem; color: #3c4a5c; }
.proc-editor .empty { border: 1px dashed #cdd6e1; border-radius: 10px; padding: .9rem; color: var(--app-muted); text-align: center; font-size: .88rem; }
@media (max-width: 575.98px) { .proc-editor .proc-row { grid-template-columns: 1fr 80px; } }
/* Procedimentos AUTORIZADOS: solicitado (referência) × autorizado (0 = não autorizado) + motivo da glosa */
.proc-editor .proc-row.auth { grid-template-columns: minmax(0, 1fr) 76px 96px 90px 84px; }
.proc-editor .proc-row.auth .proc-glosa { grid-column: 1 / -1; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .5rem; align-items: center; }
.proc-editor .proc-row.auth .proc-glosa label { margin: 0; white-space: nowrap; }
.proc-editor .proc-row.glosed { border-color: #f1c4c4; background: #fff8f8; }
.proc-editor .proc-row.glosed .proc-glosa-input { border-color: #e9a3a3; }
.proc-editor .proc-ref .qty-pill { background: #f1f4f8; color: #56637a; }
.glosa-tag { font-size: .65rem; font-weight: 700; text-transform: uppercase; background: #fdecec; color: #a12a2a; border-radius: 4px; padding: .05rem .35rem; margin-left: .35rem; vertical-align: middle; }
.qty-pill.qty-zero { background: #fdecec; color: #a12a2a; }
@media (max-width: 767.98px) {
  .proc-editor .proc-row.auth { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .proc-editor .proc-row.auth .proc-main { grid-column: 1 / -1; }
  .proc-editor .proc-row.auth .proc-glosa { grid-template-columns: 1fr; gap: .15rem; }
}
/* Card unificado da autorização: subseções no mesmo bloco visual */
/* (não usar .auth-card: é a classe do card de login, com max-width de 410px) */
.authz-card .auth-block { padding: .9rem 0; border-top: 1px dashed var(--app-border); }
.authz-card .auth-block:first-of-type { border-top: 0; padding-top: .25rem; }
.authz-card .auth-block-title { font-size: .82rem; font-weight: 600; color: var(--app-text); margin: 0 0 .6rem; display: flex; align-items: center; gap: .4rem; }
.authz-card .auth-block-title .bi { color: var(--app-primary); }
.authz-card .doc-section { border-top-style: dashed; }
.auth-proc-table tr.glosed td { background: #fff8f8; }
/* Validade da autorização (autorizadas ainda não agendadas) */
.expiry-badge { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 600; border-radius: 999px; padding: .12rem .5rem; border: 1px solid transparent; white-space: nowrap; text-decoration: none; }
.expiry-badge.due { background: #fff5e0; color: #8a5a00; border-color: #f5dfae; }
.expiry-badge.expired { background: #fdecec; color: #a12a2a; border-color: #f5c9c9; }
a.expiry-badge:hover { filter: brightness(.97); }
.expiry-summary { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; font-size: .85rem; padding: .55rem .8rem; border-radius: 10px; background: #fffaf0; border: 1px solid #f0d9a4; color: #6b4a00; }
.expiry-summary > .bi { color: #c98a00; }

.patient-found { border-left: 3px solid var(--app-accent); background: #effaf7; }
.doc-item { display: flex; align-items: center; gap: .75rem; padding: .55rem .25rem; border-bottom: 1px solid #eef1f5; }
.doc-item:last-child { border-bottom: 0; }
.doc-item > .bi { font-size: 1.3rem; color: var(--app-primary); }
.min-w-0 { min-width: 0; }
.doc-item.deleted { opacity: .6; }
.doc-item.deleted .name { text-decoration: line-through; }

.flash-stack .alert { border-radius: 10px; }
.empty-state { text-align: center; color: var(--app-muted); padding: 2.5rem 1rem; }
.empty-state .bi { font-size: 2.2rem; color: #b6c3d1; display: block; margin-bottom: .5rem; }

/* Login */
body.auth { background: linear-gradient(135deg, #0e2a3f 0%, #0f5c8c 55%, #0f9d8a 100%); min-height: 100vh; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 410px; border: 0; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth-card .brand-mark { width: 48px; height: 48px; font-size: 1.5rem; color: #fff; }
.auth-logo-wrap { text-align: center; margin-bottom: 1.75rem; }
.auth-logo { display: inline-block; width: 100%; max-width: 300px; height: auto; }

.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }

/* ---------------------------------------------------------------- Visualização de dados
   Paleta categórica validada (daltonismo/contraste): série 1 azul, série 2 laranja.
   Texto nunca usa a cor da série; marcas finas, grade recessiva. */
:root {
  --viz-s1: #2a78d6;
  --viz-s2: #eb6834;
  --viz-grid: #e9ecf1;
  --viz-axis: #c9d0d9;
  --viz-track: #eef2f7;
}

/* Indicadores (stat tiles) */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr)); gap: .75rem; }
.kpi { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 12px; padding: .85rem 1rem; }
.kpi-label { font-size: .78rem; font-weight: 600; color: var(--app-muted); }
.kpi-value { font-size: 1.6rem; font-weight: 700; line-height: 1.15; margin-top: .2rem; color: var(--app-text); }
.kpi-note { font-size: .72rem; color: var(--app-muted); margin-top: .15rem; }
.kpi-hero { grid-row: span 2; display: flex; flex-direction: column; justify-content: center; border-color: #c7dcf3; background: linear-gradient(180deg, #f5f9ff 0%, #fff 100%); }
.kpi-hero .kpi-value { font-size: 3rem; }
@media (max-width: 575.98px) { .kpi-hero { grid-row: auto; } .kpi-hero .kpi-value { font-size: 2.25rem; } }

/* Legenda (2+ séries) */
.viz-legend { font-size: .8rem; font-weight: 400; color: var(--app-muted); display: inline-flex; align-items: center; gap: .35rem; }
.viz-key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.viz-key.s1, .vbar.s1 { background: var(--viz-s1); }
.viz-key.s2, .vbar.s2 { background: var(--viz-s2); }

/* Barras horizontais (uma série, rótulo direto do valor) */
.hbar { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: .6rem; font-size: .85rem; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { display: block; height: 14px; background: var(--viz-track); border-radius: 0 4px 4px 0; }
.hbar-bar { display: block; height: 100%; min-width: 2px; background: var(--viz-s1); border-radius: 0 4px 4px 0; }
.hbar-bar.is-zero { display: none; }  /* valor zero: sem marca (o número continua escrito ao lado) */
.hbar-row.is-other .hbar-bar { background: var(--viz-axis); }
.hbar-value { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 2.5ch; text-align: right; }
.viz-rank td { vertical-align: middle; }
.viz-rank-bar-col { min-width: 140px; }
.rank-cell { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .5rem; }
.viz-desc { white-space: normal; min-width: 180px; }

/* Colunas agrupadas (um único eixo de contagem) */
.vchart { --plot-h: 210px; }
.vchart-plot { position: relative; height: var(--plot-h); margin-left: 2rem; border-bottom: 1px solid var(--viz-axis); }
.vchart-tick { position: absolute; left: 0; right: 0; border-top: 1px solid var(--viz-grid); }
.vchart-tick span { position: absolute; left: -2rem; width: 1.7rem; text-align: right; transform: translateY(-50%); font-size: .7rem; color: var(--app-muted); font-variant-numeric: tabular-nums; }
.vchart-bands { position: absolute; inset: 0; display: flex; }
.vchart-band { flex: 1 1 0; display: flex; justify-content: center; align-items: flex-end; gap: 2px; min-width: 0; }
.vchart-band:hover { background: rgba(15, 92, 140, .05); }
.vbar { width: 40%; max-width: 18px; min-height: 0; border-radius: 4px 4px 0 0; }
.vchart-x { display: flex; margin-left: 2rem; padding-top: .35rem; }
.vchart-x span { flex: 1 1 0; text-align: center; font-size: .7rem; color: var(--app-muted); white-space: nowrap; min-width: 0; overflow: hidden; }
.viz-table summary { font-size: .8rem; color: var(--app-muted); cursor: pointer; }
@media (max-width: 767.98px) {
  .vchart-x span:nth-child(even) { visibility: hidden; }  /* rótulos alternados em telas estreitas */
  .hbar-row { grid-template-columns: minmax(80px, 42%) 1fr auto; }
}

/* Calendário */
.cal-nav { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.cal-month { font-weight: 700; min-width: 11rem; text-align: center; }
.cal-legend { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.cal-card { overflow: hidden; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-weekday { padding: .5rem; font-size: .75rem; font-weight: 700; text-transform: uppercase; color: var(--app-muted); background: #f8fafc; border-bottom: 1px solid var(--app-border); text-align: center; }
.cal-day { min-height: 118px; padding: .35rem; border-right: 1px solid var(--app-border); border-bottom: 1px solid var(--app-border); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day.is-other { background: #fafbfc; }
.cal-day.is-other .cal-day-num { color: #b3bcc8; }
.cal-day-num { font-size: .8rem; font-weight: 600; color: var(--app-text); align-self: flex-end; width: 1.6rem; height: 1.6rem; display: grid; place-items: center; border-radius: 50%; }
.cal-day.is-today .cal-day-num { background: var(--app-primary); color: #fff; }
.cal-event { display: block; font-size: .72rem; line-height: 1.25; padding: .15rem .35rem; border-radius: 5px; border: 1px solid; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event:hover { filter: brightness(.96); }
.cal-event-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-more { font-size: .72rem; padding-left: .35rem; }
.cal-agenda-day + .cal-agenda-day { border-top: 1px solid var(--app-border); }
.cal-agenda-date { padding: .55rem 1rem; font-weight: 700; font-size: .85rem; background: #f8fafc; }
.cal-agenda-date.is-today { background: #eaf3fb; }
.cal-agenda-time { width: 4.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------- Nova solicitação: documentos e autopreenchimento */
.subsection-title { font-size: .8rem; font-weight: 600; color: var(--app-text); margin: 1.1rem 0 .6rem; display: flex; align-items: center; gap: .4rem; }
.subsection-title .bi { color: var(--app-primary); }
.card-body > .subsection-title:first-of-type { margin-top: .25rem; }
.doc-section { margin-top: 1rem; padding-top: .9rem; border-top: 1px dashed var(--app-border); }
.card-body > .doc-section:first-of-type:not(:first-child) { margin-top: 1rem; }
.doc-slot { border: 1px solid var(--app-border); border-radius: 10px; background: #fbfcfe; padding: .6rem .75rem; height: 100%; }
.doc-slot-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; }
.doc-slot-title { font-weight: 600; font-size: .86rem; }
.doc-add { white-space: nowrap; cursor: pointer; }
.doc-list { list-style: none; margin: .5rem 0 0; padding: 0; }
.doc-row { display: flex; align-items: center; gap: .55rem; padding: .35rem .15rem; border-top: 1px solid var(--app-border); font-size: .85rem; }
.doc-row > .bi { font-size: 1.1rem; color: var(--app-muted); }
.doc-empty { padding: .2rem 0; }
.doc-note { color: #8a5a00; }
.doc-status { display: inline-flex; align-items: center; white-space: nowrap; font-size: .72rem; font-weight: 600; border-radius: 999px; padding: .12rem .5rem; border: 1px solid transparent; }
.doc-status.s-wait { background: #f1f4f8; color: #56637a; border-color: #dfe5ee; }
.doc-status.s-proc { background: #eaf3fb; color: var(--app-primary); border-color: #cfe2f3; }
.doc-status.s-ok { background: #e8f6f1; color: #0b6b58; border-color: #c8ebdf; }
.doc-status.s-review { background: #fff5e0; color: #8a5a00; border-color: #f5dfae; }
.doc-status.s-error { background: #fdecec; color: #a12a2a; border-color: #f5c9c9; }
.doc-status.s-neutral { background: #f1f4f8; color: #56637a; }
.autofill-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-top: .75rem; }
.autofill-bar .btn { white-space: nowrap; }
.autofill-result { margin-top: .75rem; border: 1px solid #d7e6f3; background: #f6fafd; border-radius: 10px; padding: .65rem .8rem; }
.af-run { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .85rem; margin-bottom: .3rem; }
.af-items { list-style: none; margin: .35rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .15rem 1.25rem; }
.af-item { display: flex; gap: .4rem; align-items: baseline; font-size: .83rem; min-width: 0; }
.af-item-label { color: var(--app-muted); white-space: nowrap; }
.af-item-value { font-weight: 600; overflow-wrap: anywhere; white-space: pre-line; }
.af-item.st-found .bi { color: #0f9d8a; }
.af-item.st-review .bi, .af-item.st-conflict .bi, .af-item.st-unmatched .bi { color: #c98a00; }
.af-item.st-not_found .bi, .af-item.st-not_found .af-item-value { color: var(--app-muted); font-weight: 400; }
.af-note { font-size: .76rem; margin-top: .25rem; display: flex; gap: .3rem; align-items: baseline; }
.af-note.ok { color: #0b6b58; }
.af-note.review { color: #8a5a00; }
.af-note.muted { color: var(--app-muted); }
.af-sub { font-size: .74rem; color: var(--app-muted); margin-top: .1rem; }
.af-diverge { margin-top: .35rem; font-size: .8rem; border: 1px solid #f0d9a4; background: #fffaf0; border-radius: 8px; padding: .45rem .6rem; }
.af-diverge ul { padding-left: 1.1rem; }
.field-wrap.af-filled .form-control, .field-wrap.af-filled .form-select, .field-wrap.af-filled .ts-control { border-color: #7fcdb9; background-color: #f5fcf9; }
.field-wrap.af-review .form-control, .field-wrap.af-review .form-select, .field-wrap.af-review .ts-control { border-color: #e9c46a; background-color: #fffcf2; }
.doc-tags { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; margin: .15rem 0; }
.doc-type-tag { font-size: .7rem; font-weight: 600; line-height: 1.5; color: var(--app-primary); background: var(--app-primary-50); border-radius: 999px; padding: .05rem .5rem; }
.doc-status .bi { margin-right: .2rem; }
.allergy-flag { display: inline-block; font-size: .82rem; color: #a12a2a; background: #fdecec; border: 1px solid #f5c9c9; border-radius: 8px; padding: .15rem .55rem; }
@media (max-width: 575.98px) {
  .doc-slot-head { flex-direction: column; }
  .af-items { grid-template-columns: 1fr; }
}

/* Repositório de documentos (pastas em grade; documentos em lista, sem tabela, para ler bem no celular) */
.repo-filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.repo-filters .form-control { flex: 1 1 240px; }
.repo-filters .form-select { flex: 0 1 220px; }
.repo-folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .75rem; }
.repo-folders > .card { grid-column: 1 / -1; }
.repo-folder { display: flex; align-items: center; gap: .75rem; padding: .9rem 1rem; min-height: 64px; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 12px; text-decoration: none; color: inherit; }
.repo-folder:hover, .repo-folder:focus-visible { border-color: var(--app-primary); box-shadow: 0 2px 8px rgba(16,24,40,.08); }
.repo-folder > .bi, .repo-folder-icon { font-size: 1.6rem; color: #d9a420; }
.repo-folder-name { display: block; font-weight: 600; word-break: break-word; }
.repo-docs { list-style: none; margin: 0; padding: 0; }
.repo-doc { display: flex; align-items: flex-start; gap: .75rem; padding: .75rem 1rem; border-top: 1px solid var(--app-border); }
.repo-docs > .repo-doc:first-child { border-top: 0; }
.repo-doc.is-disabled { opacity: .6; }
.repo-doc-icon { font-size: 1.35rem; color: var(--app-muted); line-height: 1.2; }
.repo-doc-name { font-weight: 600; word-break: break-word; }
.repo-doc-meta { display: flex; flex-wrap: wrap; gap: .25rem .75rem; font-size: .8rem; color: var(--app-muted); margin-top: .15rem; }
.repo-doc-meta a { color: inherit; }
.repo-type { color: var(--app-text); font-weight: 600; }
.repo-usage.never { color: #1d7a46; }
.repo-usage.used { color: #9a5b00; font-weight: 600; }
.repo-doc-actions { display: flex; gap: .35rem; flex-shrink: 0; }
.repo-doc-actions form { display: inline; }
.repo-pick { width: 1.35rem; height: 1.35rem; margin-top: .1rem; flex-shrink: 0; }
.repo-picker-docs label { cursor: pointer; }
@media (max-width: 575.98px) {
  .repo-doc { flex-wrap: wrap; }
  .repo-doc > .min-w-0 { flex: 1 1 0; }  /* ícone/caixa continuam ao lado do nome; só as ações descem */
  .repo-picker-docs .repo-doc { flex-wrap: nowrap; }
  .repo-doc-actions { width: 100%; justify-content: flex-end; }
  .repo-doc-actions .btn { min-width: 44px; min-height: 40px; }
  .repo-filters .form-select { flex: 1 1 100%; }
}

@media print {
  .sidebar, .topbar, .btn, .nav-tabs-app, form { display: none !important; }
  .tab-pane { display: block !important; opacity: 1 !important; }
  .content { padding: 0; }
}
