:root {
  --bg: #1a1512;
  --surface: #241d19;
  --surface-2: #2f2620;
  --border: #423630;
  --primary: #d9591f;
  --primary-hover: #b8481a;
  --texto: #f5f1ee;
  --texto-secundario: #bdb0a8;
  --neutro: #555555;
  --neutro-hover: #444444;
  --sucesso: #2e7d32;
  --sucesso-hover: #1b5e20;
  --sucesso-texto: #6fd374;
  --alerta: #e0a800;
  --alerta-hover: #b38600;
  --perigo: #a62c2b;
  --perigo-hover: #7d2020;
  --perigo-texto: #ff6b6b;
  --info: #8a5a2e;
  --info-hover: #6b451f;
  --sem-dados: #8a8a8a;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--texto);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { overflow-x: hidden; }

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  font-weight: 600;
  transition: background 0.15s ease;
}
button:active { background: var(--primary-hover); }
button:disabled { opacity: 0.55; cursor: default; }

button.secundario { background: var(--neutro); }
button.secundario:active { background: var(--neutro-hover); }
button.perigo { background: var(--perigo); }
button.perigo:active { background: var(--perigo-hover); }
button.sucesso { background: var(--sucesso); }
button.sucesso:active { background: var(--sucesso-hover); }
button.info { background: var(--info); }
button.info:active { background: var(--info-hover); }
button.bloco { width: 100%; display: block; }

input, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--texto);
  border-radius: 10px;
  padding: 11px 12px;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}
input::placeholder { color: var(--texto-secundario); }

label {
  display: block;
  font-size: 13px;
  color: var(--texto-secundario);
  margin: 12px 0 4px;
}

.campo { margin-bottom: 6px; }

/* ---------- App shell ---------- */

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + var(--safe-top)) 14px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  background: transparent;
  color: var(--texto);
  padding: 8px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.icon-btn:active { background: var(--surface-2); }

main#conteudo {
  flex: 1;
  padding: 16px 14px calc(28px + var(--safe-bottom));
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

h2.titulo-tela {
  font-size: 21px;
  margin: 4px 0 14px;
}

p.subtitulo {
  color: var(--texto-secundario);
  font-size: 14px;
  margin-top: -8px;
  margin-bottom: 16px;
}

/* ---------- Drawer nav ---------- */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.drawer-overlay.aberto { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 82%;
  max-width: 300px;
  background: var(--surface);
  z-index: 31;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  box-shadow: 2px 0 18px rgba(0,0,0,0.4);
}
.drawer.aberto { transform: translateX(0); }

.drawer-cabecalho {
  padding: 22px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.drawer-cabecalho .marca { font-size: 22px; font-weight: 800; letter-spacing: 1px; }
.drawer-cabecalho .nome { font-weight: 700; margin-top: 10px; }
.drawer-cabecalho .papel { color: var(--texto-secundario); font-size: 13px; }

.drawer-menu {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--texto);
  padding: 13px 18px;
  border-radius: 0;
  font-weight: 600;
  font-size: 15px;
}
.drawer-item.ativo { background: var(--surface-2); color: #fff; }
.drawer-item:active { background: var(--surface-2); }

.drawer-rodape { padding: 14px 18px; border-top: 1px solid var(--border); }

/* ---------- Login ---------- */

.tela-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.cartao-login {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 20px;
  padding: 36px 26px;
  text-align: center;
}
.cartao-login h1 { font-size: 27px; margin: 0 0 4px; letter-spacing: 1px; }
.logo-login { width: 120px; height: 120px; border-radius: 50%; margin: 0 auto 10px; display: block; background: #fff; }
.logo-topbar { width: 28px; height: 28px; border-radius: 50%; background: #fff; }
.logo-drawer { width: 56px; height: 56px; border-radius: 50%; background: #fff; margin-bottom: 8px; }
.cartao-login p.slogan { color: var(--texto-secundario); margin: 0 0 22px; }
.cartao-login form { text-align: left; }
.cartao-login .status { min-height: 18px; font-size: 13px; margin: 8px 0 2px; text-align: center; }

/* ---------- Cards / listas ---------- */

.grid-indicadores {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.grid-indicadores.tres { grid-template-columns: repeat(3, 1fr); }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card-indicador {
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 10px;
  text-align: center;
}
.card-indicador .titulo { font-size: 10.5px; font-weight: 700; color: var(--texto-secundario); letter-spacing: 0.4px; }
.card-indicador .valor { font-size: 19px; font-weight: 800; margin-top: 4px; }

.linha-turno {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 9px 12px;
  margin: 8px 0;
}
.linha-turno .cabeca { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.linha-turno .detalhe { font-size: 12px; color: var(--texto-secundario); margin-top: 3px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.3px;
}
.badge.ok { background: rgba(46,125,50,0.25); color: var(--sucesso-texto); }
.badge.alerta { background: rgba(224,168,0,0.2); color: var(--alerta); }
.badge.perigo { background: rgba(166,44,43,0.25); color: var(--perigo-texto); }
.badge.neutro { background: rgba(138,138,138,0.2); color: var(--sem-dados); }

/* ---------- Registro (lista tipo "cartão" no lugar de tabela) ---------- */

.lista-registros { display: flex; flex-direction: column; gap: 10px; }

.registro {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 13px 14px;
  border: 1px solid transparent;
}
.registro.selecionado { border-color: var(--primary); }
.registro .linha1 { display: flex; justify-content: space-between; font-weight: 700; gap: 8px; }
.registro .linha2 { display: flex; justify-content: space-between; color: var(--texto-secundario); font-size: 13px; margin-top: 4px; gap: 8px; }
.registro .total { font-size: 18px; font-weight: 800; margin-top: 8px; }
.registro .acoes { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.registro .acoes button { flex: 1; padding: 9px; font-size: 13px; min-width: 100px; }

/* ---------- Resultado / totais ---------- */

.resultado-total {
  background: var(--surface);
  border-radius: var(--radius);
  text-align: center;
  padding: 16px;
  margin: 14px 0;
}
.resultado-total .rotulo { font-size: 12px; color: var(--texto-secundario); font-weight: 700; letter-spacing: 0.5px; }
.resultado-total .valor { font-size: 32px; font-weight: 800; margin-top: 4px; }

.linha-campos { display: flex; gap: 10px; }
.linha-campos > * { flex: 1; }

.acoes-fixas {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.acoes-fixas button { flex: 1; }

/* ---------- Filtros ---------- */

.filtros { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.filtros .linha { display: flex; gap: 8px; }
.filtros .linha > * { flex: 1; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button { padding: 7px 12px; font-size: 12.5px; background: var(--surface-2); }
.chips button.ativo { background: var(--primary); }

/* ---------- Modal / folha inferior ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 40;
  display: flex;
  align-items: flex-end;
}
.modal-folha {
  background: var(--bg);
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(24px + var(--safe-bottom));
  animation: subir 0.18s ease;
  position: relative;
}
@keyframes subir { from { transform: translateY(24px); opacity: 0.4; } to { transform: translateY(0); opacity: 1; } }
.modal-folha h2 { margin-top: 0; font-size: 19px; padding-right: 30px; }
.modal-fechar { position: absolute; top: 14px; right: 14px; }

/* ---------- Toast ---------- */

#toast-area {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(18px + var(--safe-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}
.toast.sucesso { border-color: var(--sucesso); }
.toast.erro { border-color: var(--perigo); }
.toast.aviso { border-color: var(--alerta); }

/* ---------- Estado vazio / carregando ---------- */

.estado-vazio {
  text-align: center;
  color: var(--texto-secundario);
  padding: 30px 10px;
}

.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: girar 0.7s linear infinite;
  margin: 0 auto;
}
@keyframes girar { to { transform: rotate(360deg); } }

.offline-aviso {
  background: var(--alerta);
  color: #1a1400;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
  padding: 7px;
}

.texto-secundario { color: var(--texto-secundario); }
.mt-0 { margin-top: 0; }
.oculto { display: none !important; }
