/* =========================================================================
   P81 — Hospital São Rafael — Automação SND
   app.css — Estilo compartilhado, mobile-first
   ========================================================================= */

:root {
  --azul:        #1a4d80;
  --azul-escuro: #143a60;
  --verde:       #2e7d32;
  --verde-escuro:#1b5e20;
  --vermelho:    #c62828;
  --vermelho-esc:#a31515;
  --amarelo:     #f9a825;
  --cinza-bg:    #f4f6f8;
  --cinza-borda: #e2e6ea;
  --cinza-txt:   #5b6470;
  --texto:       #2b2f36;
  --branco:      #ffffff;
  --raio:        10px;
  --sombra:      0 2px 10px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--cinza-bg);
  color: var(--texto);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--azul);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--sombra);
}
.topbar .logo-chip { height: 32px; width: auto; background: #fff; border-radius: 7px; padding: 3px 5px; flex: 0 0 auto; }
.topbar .marca { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52%; }
.topbar .marca small { display: block; font-weight: 400; font-size: 11px; opacity: .8; }
.topbar .espaco { flex: 1; }
.topbar .usuario { font-size: 13px; opacity: .95; text-align: right; }
.topbar .usuario small { display: block; opacity: .75; }
.menu-btn {
  background: transparent; border: 0; color: #fff;
  font-size: 24px; cursor: pointer; padding: 0 6px; line-height: 1;
}

/* ---------- Navegação ---------- */
.nav {
  background: var(--azul-escuro);
  display: none;
  flex-direction: column;
}
.nav.aberto { display: flex; }
.nav a {
  color: #dce6f2;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-size: 14px;
}
.nav a:hover, .nav a.ativo { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }

/* ---------- Layout ---------- */
.conteudo { padding: 14px; max-width: 1100px; margin: 0 auto; }
h1 { font-size: 20px; color: var(--azul); margin: 4px 0 14px; }
h2 { font-size: 17px; color: var(--azul); margin: 18px 0 10px; }

/* ---------- Cards ---------- */
.card {
  background: var(--branco);
  border-radius: var(--raio);
  box-shadow: var(--sombra);
  padding: 16px;
  margin-bottom: 14px;
}
.grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 12px; }

/* Cartões de métrica do dashboard */
.metricas { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.metrica {
  background: var(--branco); border-radius: var(--raio);
  box-shadow: var(--sombra); padding: 16px; text-align: center;
}
.metrica .num { font-size: 26px; font-weight: 700; color: var(--azul); }
.metrica .rotulo { font-size: 12px; color: var(--cinza-txt); margin-top: 4px; }

/* ---------- Lista em cartões (mobile-first, sem rolagem horizontal) ---------- */
.lista-cards { display: grid; grid-template-columns: 1fr; gap: 12px; }
.lcard { background: var(--branco); border-radius: 14px; box-shadow: var(--sombra); padding: 14px; display: flex; flex-direction: column; gap: 8px; border-left: 4px solid var(--azul); }
.lcard.alerta-borda { border-left-color: var(--amarelo); }
.lcard .lc-topo { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lcard .lc-quarto { font-size: 20px; font-weight: 800; color: var(--azul); }
.lcard .lc-pac { font-size: 15px; font-weight: 600; }
.lcard .lc-info { font-size: 13px; color: var(--cinza-txt); }
.lcard .campo { margin-bottom: 6px; }
.lcard .lc-acoes { display: flex; gap: 8px; margin-top: 4px; }
.lcard .lc-acoes form { flex: 1; margin: 0; }
.lcard .lc-acoes > button { flex: 1; }
.btn-bloco { width: 100%; justify-content: center; }
@media (min-width: 600px)  { .lista-cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .lista-cards { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--azul); color: #fff; border: 0;
  padding: 10px 16px; border-radius: 8px; font-size: 14px;
  cursor: pointer; text-decoration: none; transition: background .15s;
}
.btn:hover { background: var(--azul-escuro); text-decoration: none; }
.btn-verde   { background: var(--verde); }
.btn-verde:hover { background: var(--verde-escuro); }
.btn-perigo  { background: var(--vermelho); }
.btn-perigo:hover { background: var(--vermelho-esc); }
.btn-claro   { background: #eef2f6; color: var(--azul); }
.btn-claro:hover { background: #e0e8f0; }
.btn-pequeno { padding: 6px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Formulários ---------- */
.campo { margin-bottom: 12px; }
.campo label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.campo input, .campo select, .campo textarea {
  width: 100%; padding: 10px; border: 1px solid var(--cinza-borda);
  border-radius: 8px; font-size: 15px; background: #fff; color: var(--texto);
}
.campo textarea { min-height: 70px; resize: vertical; }
.campo .ajuda { font-size: 12px; color: var(--cinza-txt); margin-top: 4px; }
.linha-campos { display: grid; grid-template-columns: 1fr; gap: 12px; }
.acoes-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.inline { display: inline; }

/* ---------- Tabelas (viram cartões no mobile) ---------- */
.tabela-wrap { overflow-x: auto; }
table.lista { width: 100%; border-collapse: collapse; }
table.lista th, table.lista td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--cinza-borda); font-size: 14px; }
table.lista th { background: var(--azul); color: #fff; font-weight: 600; }
table.lista tr:hover td { background: #f6f9fc; }
.vazio { text-align: center; padding: 26px; color: var(--cinza-txt); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-verde   { background: #e6f4ea; color: var(--verde-escuro); }
.badge-azul    { background: #e3f0fb; color: var(--azul); }
.badge-amarelo { background: #fff6e0; color: #8a6100; }
.badge-vermelho{ background: #fdecea; color: var(--vermelho-esc); }
.badge-cinza   { background: #eceff2; color: var(--cinza-txt); }

/* ---------- Alertas / flash ---------- */
.alerta { padding: 11px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; border: 1px solid transparent; }
.alerta-sucesso { background: #e6f4ea; border-color: #b6dcc0; color: var(--verde-escuro); }
.alerta-erro    { background: #fdecea; border-color: #f3c0bc; color: var(--vermelho-esc); }
.alerta-info    { background: #e3f0fb; border-color: #b9d6f2; color: var(--azul-escuro); }

/* ---------- Miniatura de foto ---------- */
.foto-thumb { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; border: 1px solid var(--cinza-borda); }

/* ---------- Desktop ---------- */
@media (min-width: 768px) {
  body { font-size: 15px; }
  .menu-btn { display: none; }
  .nav { display: flex !important; flex-direction: row; flex-wrap: wrap; }
  .nav a { border-bottom: 0; }
  .conteudo { padding: 22px; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .metricas { grid-template-columns: repeat(4, 1fr); }
  .linha-campos.duas { grid-template-columns: 1fr 1fr; }
  .linha-campos.tres { grid-template-columns: 1fr 1fr 1fr; }
}

/* ---------- Tabelas viram cartões no celular (sem rolagem horizontal) ---------- */
@media (max-width: 640px) {
  .tabela-wrap { overflow: visible; }
  table.lista thead { display: none; }
  table.lista, table.lista tbody, table.lista tr, table.lista td { display: block; width: auto; }
  table.lista tr { background: var(--branco); border-radius: 12px; box-shadow: var(--sombra); margin-bottom: 12px; padding: 4px 12px; border-left: 4px solid var(--azul); }
  table.lista tr:hover td { background: transparent; }
  table.lista td { border: 0; border-bottom: 1px solid #eef1f4; padding: 9px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
  table.lista td:last-child { border-bottom: 0; }
  table.lista td::before { content: attr(data-label); font-weight: 700; color: var(--cinza-txt); font-size: 11px; text-transform: uppercase; letter-spacing: .3px; text-align: left; flex: 0 0 38%; }
  table.lista td[colspan] { justify-content: center; text-align: center; padding: 18px 0; color: var(--cinza-txt); }
  table.lista td[colspan]::before { content: ""; display: none; }
}
