:root {
  color-scheme: light;
  --ink: #193b2c;
  --muted: #6c806f;
  --line: #dce6dc;
  --canvas: #f4f7f3;
  --surface: #ffffff;
  --green: #1d7045;
  --green-dark: #155637;
  --green-soft: #e9f2e9;
  --amber: #a76a14;
  --amber-soft: #fff2dc;
  --red: #a43432;
  --red-soft: #fce9e7;
}

* { box-sizing: border-box; }

/* Estrutura e cabeçalho da auditoria */
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: "Trebuchet MS", Arial, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.audit-page { width: min(1600px, 100%); min-height: 100vh; margin: 0 auto; padding: 0 28px 32px; }
.topbar { display: flex; align-items: center; gap: 18px; min-height: 76px; border-bottom: 1px solid var(--line); }
.back-link, .icon-button { display: inline-grid; place-items: center; width: 38px; height: 38px; flex: 0 0 38px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); text-decoration: none; box-shadow: inset 0 1px 0 #fff, 0 3px 8px rgba(25,48,32,.08); transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease; }
.back-link:hover, .icon-button:hover { transform: translateY(-1px); border-color: #a9c3aa; background: var(--green-soft); box-shadow: 0 6px 12px rgba(25,48,32,.12); }
.module-switch-link { color: #267044; background: linear-gradient(145deg, #f7fff5, #e0efdc); }
.module-switch-link i, #sairBtn i { filter: drop-shadow(0 1px 1px rgba(25,70,37,.2)); }
.brand-lockup { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-logo { display: block; flex: 0 0 42px; width: 42px; height: 42px; object-fit: contain; }
.brand-lockup .eyebrow, .page-heading .eyebrow, .dialog-heading .eyebrow { margin: 0 0 3px; color: var(--muted); font-size: .62rem; font-weight: 800; }
.brand-lockup strong { font-size: .96rem; }
.user-tools { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-name { max-width: 260px; overflow: hidden; color: var(--muted); font-size: .82rem; text-overflow: ellipsis; white-space: nowrap; }
.audit-user-avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; flex: 0 0 34px; border: 1px solid rgba(226,255,190,.75); border-radius: 50%; color: #173b2b; background: radial-gradient(circle at 32% 24%, #d9f59a, #9bc74e 68%, #6d9d35); box-shadow: inset 0 2px 0 rgba(255,255,255,.55), inset 0 -3px 0 rgba(45,83,27,.2), 0 3px 8px rgba(0,0,0,.18); }
.audit-user-avatar i { filter: drop-shadow(0 1px 1px rgba(255,255,255,.35)); }
.audit-actions { display: flex; align-items: center; gap: 8px; }
.audit-actions .icon-button { display: inline-flex; width: auto; min-width: 38px; height: 38px; flex-basis: auto; gap: 8px; padding: 0 12px; font-size: .76rem; font-weight: 700; white-space: nowrap; }
.audit-actions .module-switch-link { border-color: rgba(67,132,79,.35); color: #267044; background: linear-gradient(145deg, #f7fff5, #e0efdc); }
.audit-actions .logout-link { border-color: rgba(164,52,50,.28); color: var(--red); background: linear-gradient(145deg, #fff8f7, #f5e1df); }
.audit-actions .logout-link:hover { border-color: #cf7772; background: var(--red-soft); }
.audit-actions .icon-button span { display: inline; }

/* Tela 1: título e ações */
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; padding: 27px 0 19px; }
.page-heading .eyebrow { margin-bottom: 5px; }
h1 { margin: 0; font-size: 1.55rem; }
.heading-actions { display: flex; gap: 8px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 8px 12px; border: 1px solid transparent; border-radius: 5px; font-size: .8rem; font-weight: 700; }
.button-primary { background: var(--green); color: #fff; }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { border-color: var(--line); background: var(--surface); color: var(--ink); }
.button-secondary:hover, .button-quiet:hover { background: var(--green-soft); }
.button-quiet { border-color: transparent; background: transparent; color: var(--muted); }

/* Tela 2: filtros */
.filter-bar { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.filter-field { display: grid; gap: 5px; min-width: 0; }
.filter-field > span { color: var(--muted); font-size: .68rem; font-weight: 700; }
.filter-field input, .filter-field select, .pagination-controls select { width: 100%; min-width: 0; height: 36px; padding: 7px 9px; border: 1px solid #cfdacf; border-radius: 4px; outline: 0; background: #fff; color: var(--ink); font-size: .78rem; }
.filter-field input:focus, .filter-field select:focus, .pagination-controls select:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(29, 112, 69, .12); }
.filter-search { grid-column: span 2; }
.filter-actions { display: flex; align-items: end; gap: 6px; }
.filter-actions .button { flex: 1; }

/* Tela 3: histórico, tabela e paginação */
.results-section { margin-top: 20px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.results-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px 15px 10px; }
.results-heading h2 { margin: 0; font-size: .95rem; }
.status-message { margin: 0; color: var(--muted); font-size: .74rem; }
.status-message.error { color: var(--red); }
.table-scroll { max-height: calc(100vh - 345px); min-height: 220px; overflow: auto; border-top: 1px solid var(--line); }
table { width: 100%; min-width: 1050px; border-collapse: collapse; font-size: .75rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid #e8eee8; text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; background: #edf3ed; color: #34543c; font-size: .65rem; font-weight: 800; text-transform: uppercase; }
tbody tr:nth-child(even) { background: #fafcf9; }
tbody tr:hover { background: #f0f6ef; }
td { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td:first-child { min-width: 145px; font-variant-numeric: tabular-nums; }
td:last-child { width: 94px; }
.empty-cell { height: 130px; max-width: none; color: var(--muted); text-align: center; white-space: normal; }
.badge { display: inline-flex; align-items: center; min-height: 22px; padding: 3px 7px; border-radius: 4px; font-size: .66rem; font-weight: 800; }
.badge-success { background: var(--green-soft); color: var(--green-dark); }
.badge-failure { background: var(--red-soft); color: var(--red); }
.details-button { padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--ink); font-size: .7rem; }
.details-button:hover { border-color: #a9c3aa; background: var(--green-soft); }
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; color: var(--muted); font-size: .74rem; }
.pagination-controls { display: flex; align-items: center; gap: 8px; }
.pagination-controls .icon-button { width: 30px; height: 30px; flex-basis: 30px; }
.pagination-controls .icon-button:disabled { opacity: .42; cursor: not-allowed; }
.pagination-controls select { width: 68px; height: 30px; padding: 4px 6px; }
.page-size-label { margin-left: 6px; }

/* Janela de detalhes do evento */
.details-dialog { width: min(620px, calc(100% - 28px)); max-height: 80vh; padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); box-shadow: 0 18px 55px rgba(15, 40, 25, .2); }

/* Ajustes responsivos */
.details-dialog::backdrop { background: rgba(15, 32, 20, .48); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin: 0; font-size: 1rem; }
.details-list { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 0; max-height: calc(80vh - 75px); margin: 0; padding: 12px 18px 18px; overflow: auto; }
.details-list dt, .details-list dd { margin: 0; padding: 8px 0; border-bottom: 1px solid #edf1ed; font-size: .78rem; }
.details-list dt { color: var(--muted); font-weight: 700; }
.details-list dd { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

@media (max-width: 900px) {
  .filter-bar { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
  .table-scroll { max-height: calc(100vh - 410px); }
}

@media (max-width: 620px) {
  .audit-page { padding: 0 14px 24px; }
  .topbar { min-height: 64px; gap: 10px; flex-wrap: wrap; padding: 10px 0; }
  .brand-logo { flex-basis: 34px; width: 34px; height: 34px; }
  .brand-lockup strong { font-size: .84rem; }
  .user-tools { width: 100%; justify-content: flex-end; gap: 8px; }
  .user-name { max-width: min(120px, 30vw); font-size: .72rem; }
  .audit-actions { margin-left: auto; }
  .audit-actions .icon-button { padding: 0 10px; }
  .page-heading { align-items: stretch; flex-direction: column; padding: 20px 0 14px; }
  .heading-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 11px; gap: 9px; }
  .filter-search { grid-column: span 2; }
  .filter-actions { grid-column: span 2; }
  .table-scroll { max-height: calc(100vh - 500px); min-height: 200px; }
  .results-heading { align-items: start; flex-direction: column; }
  .table-footer { align-items: start; flex-direction: column; }
  .pagination-controls { width: 100%; }
  .pagination-controls span { margin: 0 auto; }
  .details-list { grid-template-columns: 100px minmax(0, 1fr); padding-inline: 14px; }
}
