:root {
  --bg: #f1f4f8;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #64748b;
  --border: #e4e9f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff4ff;
  --ok: #16a34a;
  --warn: #ea580c;
  --danger: #dc2626;
  --gray: #6b7280;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 2px 8px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------------- Topbar ---------------- */

.topbar {
  background: #fff;
  color: var(--text);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .brand { display: flex; align-items: center; margin-right: 24px; }
.topbar .brand img { height: 34px; display: block; }

.topbar-nav { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; }
.topbar-nav a {
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
}
.topbar-nav a:hover { color: var(--primary); background: var(--primary-light); text-decoration: none; }
.topbar-nav a.active { color: var(--primary); background: var(--primary-light); font-weight: 600; }
.topbar-nav a.hub-crumb { color: var(--muted); font-weight: 500; padding-right: 4px; }
.topbar-nav a.hub-crumb:hover { background: none; text-decoration: underline; }
.topbar-nav a.module-crumb { font-weight: 700; color: var(--text); }
.topbar-nav a.module-crumb:hover { color: var(--primary); }
.topbar-nav .crumb-sep { color: var(--border); margin: 0 2px; font-size: 0.9rem; }

.topbar .user {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  padding-left: 16px;
  margin-left: 8px;
  border-left: 1px solid var(--border);
}
.topbar .user a { color: var(--muted); }
.topbar .user a:hover { color: var(--primary); text-decoration: none; }
.topbar .user-name { color: var(--text); font-weight: 600; }
.topbar form { display: inline; }
.topbar button.link {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 0.85rem; padding: 0; font-family: inherit;
}
.topbar button.link:hover { color: var(--primary); text-decoration: underline; }

/* ---------------- Layout ---------------- */

.container { max-width: 1140px; margin: 0 auto; padding: 28px 24px 48px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  text-align: left;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  container-type: inline-size;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; }
/* Números curtos (contagens) ficam grandes; números longos (valores em R$)
   encolhem pra caber sem quebrar o card — daí o container query abaixo.
   white-space+ellipsis é o fallback pra navegador sem suporte a cqw: nunca
   estoura o card, na pior hipótese trunca (raro, e ainda assim melhor que
   quebrar o layout). */
.stat-card .num {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@supports (font-size: 1cqw) {
  .stat-card .num { font-size: clamp(1.05rem, 11cqw, 2rem); }
}
.stat-card .label { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
.stat-card.vencido .num { color: var(--danger); }
.stat-card.vencendo .num { color: var(--warn); }
.stat-card.ok .num { color: var(--ok); }
.stat-card.sem_calibracao .num { color: var(--gray); }
.stat-card.vencida .num { color: var(--danger); }
.stat-card.perto_vencer .num { color: var(--warn); }
.stat-card.pago .num { color: var(--ok); }

/* ---------------- Tables ---------------- */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 8px;
}
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
th { color: var(--muted); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; background: #fafbfd; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
/* Colunas de valor (class="num" nas células) — alinhadas à direita, nunca
   quebram linha, e usam algarismos de largura fixa pra alinhar visualmente. */
th.num, td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table { table-layout: auto; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.vencendo { background: #ffedd5; color: #c2410c; }
.badge.vencido { background: #fee2e2; color: #b91c1c; }
.badge.sem_calibracao { background: #f1f5f9; color: #475569; }
.badge.fora_de_uso { background: #e5e7eb; color: #4b5563; }
.badge.cancelado { background: #e5e7eb; color: #4b5563; }
.badge.aprovado { background: #dcfce7; color: #15803d; }
.badge.reprovado { background: #fee2e2; color: #b91c1c; }
.badge.aprovado_com_restricao { background: #fef9c3; color: #92400e; }
.badge.pago { background: #dcfce7; color: #15803d; }
.badge.vencida { background: #fee2e2; color: #b91c1c; }
.badge.perto_vencer { background: #ffedd5; color: #c2410c; }
.badge.pendente { background: #f1f5f9; color: #475569; }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.12s ease, box-shadow 0.12s ease;
  font-family: inherit;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; box-shadow: var(--shadow-md); }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn.secondary:hover { background: #f8fafc; box-shadow: none; }
.btn.danger { background: var(--danger); }

/* ---------------- Page structure ---------------- */

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { margin: 0; font-size: 1.5rem; font-weight: 700; }

form.filters { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
form.filters input, form.filters select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem; font-family: inherit; background: #fff;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.field { display: block; }
.field label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.92rem; font-family: inherit; background: #fff;
  transition: border-color 0.12s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.field textarea { resize: vertical; min-height: 60px; }
.field.checkline { display: flex; align-items: center; gap: 8px; }
.field.checkline input[type="checkbox"] { width: auto; }

/* Lista de módulos liberados (cadastro/edição de usuário): checkbox + nome alinhados, data opcional ao lado */
.modulos-lista { display: grid; gap: 4px; margin-top: 6px; }
.modulo-linha { display: grid; grid-template-columns: 240px 1fr; align-items: center; gap: 16px; min-height: 44px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.modulo-linha:last-child { border-bottom: none; }
.modulos-lista label.modulo-nome { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 0.92rem; font-weight: 500; color: inherit; cursor: pointer; }
.modulos-lista input[type="checkbox"] { width: 18px; height: 18px; margin: 0; padding: 0; flex: none; accent-color: var(--primary); }
.modulos-lista label.modulo-data { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 0.85rem; font-weight: normal; color: var(--muted); }
.modulos-lista input[type="date"] { width: 170px; }
.modulos-lista .dica { font-size: 0.8rem; }
@media (max-width: 640px) { .modulo-linha { grid-template-columns: 1fr; gap: 6px; } }

.alert-box {
  padding: 11px 15px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem;
}
.alert-box.error { background: #fee2e2; color: #b91c1c; }
.alert-box.info { background: #dbeafe; color: #1d4ed8; }
.alert-box.success { background: #dcfce7; color: #15803d; }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg);
}
.login-card { width: 340px; box-shadow: var(--shadow-md); }
.login-card h1 { font-size: 1.25rem; margin-bottom: 20px; font-weight: 700; }
.login-card .field { margin-bottom: 14px; }

.section-title { font-size: 1.05rem; font-weight: 700; margin: 30px 0 14px; }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 20px; margin-bottom: 8px; }
.meta-grid .k { color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; }
.meta-grid .v { font-size: 0.95rem; margin-top: 2px; }

.empty-state { color: var(--muted); padding: 36px 10px; text-align: center; background: var(--card); border: 1px dashed var(--border); border-radius: 12px; }

.blocked-banner {
  background: #fee2e2; color: #991b1b; padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-weight: 600;
}

/* ---------------- Impressão ---------------- */
/* .no-print marca qualquer elemento (botões, filtros, coluna de ações) que
   não deve sair no papel — cada tela decide o que usar essa classe. */
@media print {
  .topbar, .no-print { display: none !important; }
  .print-only { display: block !important; margin-bottom: 12px; font-size: 0.85rem; color: #444; }
  body { background: #fff; }
  .container { max-width: 100%; padding: 0; margin: 0; }
  .card { box-shadow: none; border: none; padding: 0; }
  table { font-size: 0.85rem; }
}
