:root {
  --azul: #1b4f8f;          /* azul institucional */
  --azul-2: #2a6fb8;
  --agua: #16a3a0;          /* verde-água */
  --agua-claro: #e3f5f4;
  --bg: #f4f7fa;
  --branco: #ffffff;
  --linha: #dfe5ec;
  --linha-forte: #c9d3de;
  --texto: #1d2a38;
  --muted: #6b7a8a;
  --erro: #c43d3d;
  --row-h: 28px;
  --col-w: 170px;
  --time-w: 58px;
  --radius: 8px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--texto);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; }
:focus-visible { outline: 2px solid var(--agua); outline-offset: 1px; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.erro { color: var(--erro); min-height: 1.2em; margin: 6px 0 0; }

/* ---------- Botões ---------- */
.btn { border: 1px solid var(--linha-forte); background: var(--branco); border-radius: 6px; padding: 6px 12px; cursor: pointer; transition: background .15s, border-color .15s, transform .08s; }
.btn:hover { border-color: var(--azul-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.icon { padding: 2px 9px; font-size: 16px; line-height: 1; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn.primary { background: var(--azul); border-color: var(--azul); color: #fff; }
.btn.primary:hover { background: var(--azul-2); }
.btn.danger { color: var(--erro); border-color: #efc4c4; }
.btn.ghost { background: transparent; border-color: transparent; color: inherit; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--agua-claro); color: #0c6f6c; font-size: 12px; font-weight: 600; }
.pill.lock { background: #fdeede; color: #9a5a12; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--azul) 0%, var(--agua) 100%); padding: 16px; }
.login-card { background: #fff; width: min(360px, 100%); padding: 28px; border-radius: 14px; box-shadow: 0 20px 40px rgba(0,0,0,.18); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 6px 0 0; color: var(--azul); }
.login-card p { margin: 0; }
.login-card label, .card label, dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select { border: 1px solid var(--linha-forte); border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--texto); }
input:focus, select:focus { outline: 2px solid var(--agua); outline-offset: 0; border-color: var(--agua); }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, var(--azul), var(--agua)); color: #fff; font-weight: 700; display: grid; place-items: center; letter-spacing: .5px; }
.brand-mark.sm { width: 30px; height: 30px; border-radius: 8px; font-size: 12px; }

/* ---------- Topo ---------- */
.topbar { display: flex; align-items: center; gap: 12px; background: var(--azul); color: #fff; padding: 3px 12px; position: sticky; top: 0; z-index: 30; min-height: 38px; }
.topbar .brand-mark.sm { width: 24px; height: 24px; border-radius: 6px; font-size: 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand small { font-weight: 400; opacity: .8; margin-left: 4px; }
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tabs button { background: transparent; border: 0; color: #d7e6f7; padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.tabs button.active, .tabs button:hover { background: rgba(255,255,255,.14); color: #fff; }
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user .pill { background: rgba(255,255,255,.18); color: #fff; }
.user .btn.ghost { color: #fff; }

/* ---------- Barra de ferramentas ---------- */
/* Tela cheia: a grade ocupa todo o espaço que sobra (mais linhas visíveis) */
#view-app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
#view-app > .tab { flex: 1; min-height: 0; }
#tab-agenda { display: flex; flex-direction: column; }
#tab-auditoria, #tab-cadastros { overflow: auto; }
.tab { padding: 6px 10px 4px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-bottom: 6px; }
.toolbar .sm, .toolbar select, .toolbar input { height: 28px; padding: 2px 6px; font-size: 13px; }
.toolbar select { max-width: 170px; }
/* Sala e Especialidade com metade da largura: filtros cabem numa linha no computador */
.toolbar #f-sala, .toolbar #f-esp { width: 85px; max-width: 85px; text-overflow: ellipsis; }
.group.mes { margin-left: auto; }
#f-busca { width: 230px; }
#f-busca:not(:placeholder-shown) { border-color: var(--agua); background: var(--agua-claro); }
.group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.group label { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
#nav-titulo { margin-left: 6px; color: var(--azul); font-size: 14px; white-space: nowrap; }
#nav-titulo::first-letter { text-transform: uppercase; }
.seg { background: #fff; border: 1px solid var(--linha-forte); border-radius: 8px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 3px 10px; border-radius: 6px; cursor: pointer; }
.seg button.active { background: var(--azul); color: #fff; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: #fff; border: 1px solid var(--linha); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); min-width: 150px; }
.filters label.grow { flex: 1; min-width: 220px; }
.filters label.check, label.check { flex-direction: row; align-items: center; gap: 6px; min-width: 0; }
.ac { position: relative; display: flex; gap: 4px; }
.ac input { flex: 1; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--linha-forte); border-radius: 6px; margin: 2px 0 0; padding: 4px 0; list-style: none; z-index: 50; max-height: 240px; overflow: auto; box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.ac-list li { padding: 6px 10px; cursor: pointer; color: var(--texto); font-size: 13px; }
.ac-list li:hover, .ac-list li.sel { background: var(--agua-claro); }
.ac-list li small { color: var(--muted); }

.rodape { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; padding: 4px 2px 0; font-size: 11.5px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.legend .st { padding: 0 6px; border-radius: 3px; font-size: 11px; border-left: 3px solid; }
.legend .chegou-leg { background: #dff3e4; border-color: #2e9e57; }
.atalhos kbd { font: 600 10.5px/1 system-ui, sans-serif; background: #fff; border: 1px solid var(--linha-forte); border-bottom-width: 2px; border-radius: 4px; padding: 1px 4px; color: var(--texto); margin-left: 6px; }
#resumo { margin-left: auto; font-variant-numeric: tabular-nums; }

.progress { position: relative; height: 20px; flex: none; background: #fff; border: 1px solid var(--linha); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
.progress .bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--azul-2), var(--agua)); transition: width .3s; }
.progress span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 600; }

/* ---------- Status ---------- */
.st.AGENDADA { background: #e9f1fb; border-color: #2a6fb8; }
.st.CONFIRMADA { background: #e1f5f0; border-color: #16a37f; }
.st.EM_ATENDIMENTO { background: #fff3dd; border-color: #e0962a; }
.st.FINALIZADA { background: #eceff3; border-color: #7d8896; }
.st.CANCELADA { background: #fcebeb; border-color: #cf5656; }

/* ---------- Grade estilo planilha ---------- */
.grid-wrap { background: #fff; border: 1px solid var(--linha); border-radius: var(--radius); overflow: auto; flex: 1; min-height: 0; }
.grid { display: grid; position: relative; min-width: max-content; }
.gh { position: sticky; top: 0; z-index: 10; background: #f0f4f8; border-bottom: 1px solid var(--linha-forte); border-right: 1px solid var(--linha); padding: 6px 8px; font-weight: 600; font-size: 13px; text-align: center; color: var(--azul); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gh.corner { left: 0; z-index: 12; }
.gh.today { background: var(--agua-claro); color: #0c6f6c; }
.gh small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.gt { position: sticky; left: 0; z-index: 5; background: #f7f9fb; border-right: 1px solid var(--linha-forte); font-size: 11px; color: var(--muted); text-align: right; padding: 0 6px; height: var(--row-h); line-height: var(--row-h); }
.gt.hour { color: var(--texto); font-weight: 600; }
.gc { border-right: 1px solid var(--linha); border-bottom: 1px solid #edf1f5; height: var(--row-h); }
.gc.hour { border-bottom-color: var(--linha); }
.gc.admin:hover { background: #f3fafa; cursor: cell; }
.gc.drop { background: #d7f0ef !important; outline: 2px dashed var(--agua); outline-offset: -2px; }
.col-layer { position: relative; pointer-events: none; }
.appt { position: absolute; pointer-events: auto; border-radius: 5px; border-left: 4px solid; padding: 2px 6px; font-size: 12px; line-height: 1.25; overflow: hidden; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.appt[draggable="true"] { cursor: grab; }
.appt.dragging { opacity: .45; }
.appt .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .m { color: #4a5868; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt.CANCELADA .n { text-decoration: line-through; }
.appt .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.appt.hl { outline: 2px solid var(--azul); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Tabelas / cartões ---------- */
.table-wrap { background: #fff; border: 1px solid var(--linha); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 170px); }
.table { border-collapse: collapse; width: 100%; font-size: 13px; }
.table th { position: sticky; top: 0; background: #f0f4f8; color: var(--azul); text-align: left; padding: 8px; border-bottom: 1px solid var(--linha-forte); }
.table td { padding: 6px 8px; border-bottom: 1px solid #edf1f5; vertical-align: top; }
.table td.json { font-family: Consolas, monospace; font-size: 11.5px; color: #4a5868; max-width: 260px; word-break: break-word; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card { background: #fff; border: 1px solid var(--linha); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.card h3 { margin: 0; color: var(--azul); }
.card .row { display: flex; gap: 8px; align-items: flex-end; }
.card .row label { flex: 1; }
.mini { list-style: none; padding: 0; margin: 6px 0 0; max-height: 180px; overflow: auto; font-size: 12.5px; border-top: 1px solid var(--linha); }
.mini li { padding: 4px 0; border-bottom: 1px solid #f0f3f6; display: flex; justify-content: space-between; gap: 8px; }

/* ---------- Diálogos ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 24px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,35,55,.45); }
dialog form { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
dialog h2 { margin: 0; color: var(--azul); font-size: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.grid2 .span2 { grid-column: span 2; }
.pac-box { background: var(--agua-claro); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.pac-box:empty { display: none; }
.pac-box b { color: var(--azul); }
.pac-box .sens { margin-top: 4px; padding-top: 4px; border-top: 1px dashed #9fd6d4; }
.pac-pick { display: flex; gap: 8px; align-items: flex-end; }
.pac-pick label { flex: 1; }
.info { font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.spacer { flex: 1; }

.toast { display: flex; align-items: center; gap: 12px; position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--texto); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }
.toast.erro { background: var(--erro); color: #fff; }

@media (max-width: 760px) {
  :root { --col-w: 140px; }
  .topbar { flex-wrap: wrap; }
  .tabs { margin-left: 0; }
  .user { margin-left: 0; width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  .grid2 .span2 { grid-column: auto; }
}
@media print {
  .topbar, .toolbar, .filters, .legend { display: none; }
  .grid-wrap { max-height: none; overflow: visible; border: 0; }
}

.appt .cod { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .5px; padding: 0 3px; border-radius: 3px; background: #1f2d3d; color: #fff; vertical-align: 1px; }
.ac-list li.fp { line-height: 1.35; border-bottom: 1px solid var(--linha); }
.ac-list li.fp:last-child { border-bottom: 0; }
#dlg-pac-lista { max-height: 320px; }
.linha-edit { position: absolute; left: 2px; right: 2px; z-index: 30; display: flex; align-items: center; gap: 4px; padding: 0 4px;
  background: #fffbe6; border: 2px solid var(--agua); border-radius: 3px; pointer-events: auto; box-sizing: border-box; }
.linha-edit input.hora { width: 44px; font-size: 12px; font-weight: 700; color: #1f2d3d; text-align: center; border-right: 1px solid var(--linha-forte); cursor: text; }
.linha-edit input.hora:focus { background: #fff; }
.linha-edit .grow { flex: 1; position: relative; }
.linha-edit input { border: 0; outline: 0; background: transparent; font-size: 13px; padding: 3px 2px; height: 24px; box-shadow: none; }
.linha-edit #rap-nome { width: 100%; text-transform: uppercase; }
.linha-edit #rap-cod { width: 42px; text-align: center; letter-spacing: 1px; text-transform: uppercase; border-left: 1px solid var(--linha-forte); }
.linha-edit .ac-list { min-width: 320px; }
.linha-erro { position: absolute; top: 100%; left: 0; right: 0; margin-top: 2px; background: #fdecec; color: #b42318; font-size: 12px; padding: 4px 6px; border-radius: 3px; }
.appt .add { position: absolute; top: 1px; right: 2px; width: 18px; height: 18px; line-height: 16px; padding: 0; border: 0; border-radius: 4px; background: rgba(255,255,255,.85); color: #1f2d3d; font-weight: 700; cursor: pointer; display: none; }
.appt:hover .add { display: block; }

/* ---------- Planilha (uma linha por paciente) ---------- */
#grid.planilha { display: flex; gap: 0; align-items: flex-start; width: 100%; }
.pl-col { flex: 1 1 0; min-width: 180px; max-width: 420px; border-right: 1px solid var(--linha); }
.pl-col:last-child { border-right: 0; }
.pl-head { position: sticky; top: 0; z-index: 5; background: #f4f7fa; border-bottom: 1px solid var(--linha); padding: 3px 8px; display: flex; flex-direction: column; }
.pl-head b { color: var(--azul); font-size: 14px; }
.pl-head small { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-col.today .pl-head { background: #e3f4f3; }
.pl-row { position: relative; display: grid; grid-template-columns: 46px 1fr 34px 24px; column-gap: 4px; align-items: center; min-height: 25px; border-bottom: 1px solid #edf1f5;
  border-left: 4px solid transparent; font-size: 13px; cursor: pointer; }
.pl-row:hover { background: #f3fafa; }
.pl-row .h { font-weight: 700; color: #1f2d3d; padding-left: 6px; font-variant-numeric: tabular-nums; }
.pl-row .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 4px; }
.pl-row .c { font-size: 11px; font-weight: 700; letter-spacing: .5px; color: #1f2d3d; text-align: center; }
.pl-row .pend { display: inline-block; width: 14px; height: 14px; line-height: 14px; text-align: center; border-radius: 50%; background: #f5b400; color: #fff; font-size: 10px; }
.pl-row.livre .h { color: #9aa8b6; font-weight: 600; }
.pl-row.livre .n { color: #b3bfcb; font-style: italic; font-size: 12px; }
.pl-row.livre:hover .n { color: var(--agua); }
.pl-row.st.AGENDADA { border-left-color: #2f6fb2; }
.pl-row.st.CONFIRMADA { border-left-color: #1a9c7a; }
.pl-row.st.EM_ATENDIMENTO { border-left-color: #e09a1a; background: #fff8ea; }
.pl-row.st.FINALIZADA { border-left-color: #7d8a99; color: #6b7785; }
.pl-row.st.CANCELADA { border-left-color: #d64545; color: #a0a9b3; text-decoration: line-through; }
.pl-row.hl { background: #e7f0fb; }
.pl-row .add { position: absolute; left: 48px; bottom: -9px; z-index: 3; width: 18px; height: 18px; line-height: 16px; padding: 0; border: 1px solid var(--linha-forte); border-radius: 4px; background: #fff; font-weight: 700; cursor: pointer; display: none; }
.pl-row:hover .add, .pl-row:focus .add { display: block; }
.pl-row .add:hover { background: var(--agua); border-color: var(--agua); color: #fff; }
.pl-row:focus { outline: 2px solid var(--agua); outline-offset: -2px; background: #eef9f8; z-index: 2; }
.pl-row .k { display: flex; justify-content: center; }
.pl-row .chk { width: 15px; height: 15px; margin: 0; cursor: pointer; accent-color: #2e9e57; }
.pl-row .chk:disabled { cursor: default; }
.pl-row.chegou { background: #eef9f1; }
.pl-row.chegou .n { font-weight: 600; }
.pl-row .avulso { font-style: normal; font-size: 10px; font-weight: 700; color: #9a5a12; background: #fdeede; border-radius: 3px; padding: 0 3px; margin-left: 4px; }
.pl-vazio { padding: 10px; color: var(--muted); font-size: 12px; font-style: italic; }
.appt .ok { color: #2e9e57; font-weight: 800; }
.pl-row.editando { display: block; cursor: default; background: #fffbe6; }
.pl-row.editando > span, .pl-row.editando > .add { display: none; }
.linha-edit.in-row { position: relative; left: 0; right: 0; top: 0; border-radius: 0; border-width: 2px; }
#grid-wrap.carregando { opacity: .55; transition: opacity .15s; pointer-events: none; }

/* Diálogo: rodapé sempre visível */
dialog form { max-height: calc(100vh - 48px); overflow: auto; }
dialog .actions { position: sticky; bottom: -18px; background: #fff; padding: 10px 0 6px; border-top: 1px solid var(--linha); }

/* ---------- Repetir toda semana / ações extras / escolha de escopo ---------- */
.serie { border: 1px solid var(--linha); border-radius: 8px; padding: 8px 10px; background: #fafcfd; }
.serie-dias { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; margin: 8px 0; }
.serie-dias .sd { display: flex; align-items: center; gap: 6px; }
.serie-dias .sd label { min-width: 52px; color: var(--texto); }
.serie-dias input[type=time] { padding: 2px 4px; width: 92px; min-width: 0; }
#dlg-appt { width: min(620px, calc(100vw - 32px)); }
@media (max-width: 620px) { .serie-dias { grid-template-columns: 1fr; } }
.serie label select { margin-top: 2px; }
.acoes-extra { display: flex; flex-wrap: wrap; gap: 6px; }
.escolha { gap: 8px; }
.escolha .opcao { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; border: 1px solid var(--linha-forte); background: #fff; border-radius: 8px; padding: 10px 12px; cursor: pointer; transition: border-color .15s, background .15s; }
.escolha .opcao:hover, .escolha .opcao:focus-visible { border-color: var(--agua); background: var(--agua-claro); }
.escolha .opcao.destaque { border-color: var(--azul-2); }
.escolha .opcao b { color: var(--azul); }
.escolha .opcao small { color: var(--muted); }
.res-lista { margin: 0; padding-left: 18px; max-height: 260px; overflow: auto; font-size: 13px; }
.res-lista li { margin: 2px 0; }
@media (max-width: 760px) { #f-busca { width: 100%; } .group.mes { margin-left: 0; } .atalhos { display: none; } }

/* Cadastros: vínculo do profissional com o Slack */
#l-prof li { align-items: center; gap: 8px; }
#l-prof input.slack-id { width: 120px; height: 24px; padding: 1px 6px; font-size: 12px; font-family: monospace; }
