:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2c5aa0;
  --primary-hover: #1e4276;
  --success: #16a34a;
  --success-hover: #128038;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f7f8fa;
  color: var(--fg);
  line-height: 1.4;
}

button, input, select, textarea { font-family: inherit; font-size: 1em; }

/* Mobile-first: uma coluna, alvos de toque grandes o suficiente para o
   celular (min 44px de altura), sem grid multi-coluna em nenhum lugar. */
.wrap { padding: 16px; max-width: 480px; margin: 0 auto; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.topbar h1 { font-size: 1.3em; color: var(--primary); margin: 0; }
.subtitulo { color: var(--muted); margin: 0 0 16px; font-size: 0.9em; }

.btn {
  border: none; border-radius: 8px; padding: 10px 16px; font-weight: 600; cursor: pointer; color: #fff;
  min-height: 44px;
}
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--muted); }
.btn-grande { width: 100%; font-size: 1.05em; margin-top: 6px; }
.btn-sm { padding: 6px 12px; font-size: 0.82em; min-height: 0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Tela de login (motorista e admin) ---- */
.tela-login {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px;
}
.cartao-login {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px 24px; width: 100%; max-width: 360px; text-align: center;
}
.cartao-login h1 { font-size: 1.3em; color: var(--primary); margin: 0 0 4px; }
.form-login { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; text-align: left; }
.form-login label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85em; color: var(--muted); }
.form-login input {
  padding: 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 1.1em;
  letter-spacing: 0.03em;
}
.checkbox-label { display: flex; flex-direction: row; align-items: center; gap: 8px; font-size: 0.9em; }
.checkbox-label input { width: 18px; height: 18px; }
.checkbox-label[hidden] { display: none; }
.mensagem-erro { background: #fee2e2; color: #991b1b; padding: 8px 12px; border-radius: 8px; font-size: 0.9em; }
.ajuda { margin-top: 18px; font-size: 0.8em; color: var(--muted); }

/* ---- Lista de viagens / despesas (cards, sem tabela) ---- */
.instrucao { color: var(--muted); font-size: 0.9em; }
.lista-viagens, .lista-motoristas { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }

.card-viagem, .card-motorista {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer;
  display: block; text-decoration: none; color: inherit;
}
.card-viagem:active, .card-motorista:active { background: #f0f4fa; }
.card-viagem-top { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.card-viagem-sub { color: var(--muted); font-size: 0.85em; margin-top: 2px; }

.badge { display: inline-flex; padding: 3px 10px; border-radius: 999px; font-size: 0.75em; font-weight: 600; }
.badge-status-1 { background: #e0e7ff; color: #3730a3; }
.badge-status-2 { background: #fef3c7; color: #92400e; }
.badge-status-3 { background: #dcfce7; color: #166534; }
.badge-warn { background: #fef3c7; color: #92400e; }

.muted { color: var(--muted); font-size: 0.9em; }

.paginacao { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 0; }
.paginacao-info { color: var(--muted); font-size: 0.85em; }

/* ---- Formulario de despesa ---- */
.form-despesa { display: flex; flex-direction: column; gap: 14px; margin: 14px 0 24px; }
.form-despesa[hidden] { display: none; }
.block-label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85em; color: var(--muted); }
.block-label[hidden] { display: none; }
.block-label input, .block-label select, .block-label textarea {
  padding: 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--fg); font-size: 1em;
}
.valor-label input { font-weight: 700; font-size: 1.2em; }

.tipo-fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.tipo-fieldset legend { padding: 0 6px; color: var(--muted); font-size: 0.85em; }
.radio-label { display: flex; align-items: center; gap: 8px; padding: 8px 2px; font-size: 0.95em; }

#titulo-viagem-selecionada { color: var(--primary); font-size: 1.1em; margin: 12px 0 4px; }

.subtabs-mobile { display: flex; gap: 4px; margin: 10px 0 14px; border-bottom: 1px solid var(--border); }
.subtab-btn-mobile {
  flex: 1; border: none; background: transparent; padding: 10px 0; cursor: pointer; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent; min-height: 44px;
}
.subtab-btn-mobile.active { color: var(--primary); border-bottom-color: var(--primary); }

.lista-despesas { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.item-despesa {
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px; font-size: 0.9em; cursor: pointer;
}
.item-despesa:active { background: #f0f4fa; }
.item-despesa-linha { display: flex; justify-content: space-between; align-items: center; }
.item-despesa-tipo { color: var(--muted); font-size: 0.85em; }
.item-despesa-valor { font-weight: 700; }
.item-despesa-nota { display: flex; align-items: center; gap: 8px; }

/* ---- Modal de detalhe (despesa/entrada) ---- */
/* Overlay rola como uma pagina normal (sem flex align-items:flex-end/center) -
   quando o conteudo do card e mais alto que a tela, um container flex com
   align-items diferente de flex-start "esconde" o excesso do lado de inicio
   e ele fica inacessivel mesmo com overflow:auto (bug conhecido de
   flexbox+overflow). Scroll de documento normal nao tem essa armadilha. */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  overflow-y: auto; -webkit-overflow-scrolling: touch; z-index: 20;
}
.modal-overlay[hidden] { display: none; }
.modal-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 480px; margin: 40px auto; padding: 18px 20px 24px;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header h3 { margin: 0; color: var(--primary); font-size: 1.05em; }
.detalhe-lista { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.detalhe-lista dt { font-size: 0.78em; color: var(--muted); }
.detalhe-lista dd { margin: 2px 0 0; font-size: 1em; }
.modal-acoes:not(:empty) { margin-top: 16px; }

.painel { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
#busca-motorista { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 12px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #14171c; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 0.9em; z-index: 10;
}
.toast.erro { background: var(--danger); }

/* ---- Instalar App (PWA) ---- */
.btn-instalar-app {
  position: fixed; right: 16px; bottom: 16px; z-index: 20;
  background: var(--primary); color: #fff; border: none; border-radius: 999px;
  padding: 12px 18px; font-weight: 600; font-size: 0.95em; cursor: pointer;
  box-shadow: var(--shadow);
}
.btn-instalar-app:hover { background: var(--primary-hover); }
.btn-instalar-app[hidden] { display: none; }

.instalar-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 30;
}
.instalar-caixa {
  background: #fff; border-radius: var(--radius); padding: 20px; max-width: 320px; width: 100%;
  box-shadow: var(--shadow);
}
.instalar-caixa p { margin: 0 0 10px; font-size: 0.95em; }
.instalar-caixa button { width: 100%; margin-top: 4px; }
