:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1f294f;
  --muted: #66708e;
  --line: #dde3f0;
  --blue: #2f3b7c;
  --blue-strong: #243067;
  --red: #e32620;
  --red-strong: #bc1f1b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 4px solid var(--blue);
  box-shadow: 0 2px 10px rgba(31, 41, 79, 0.08);
}

.brand {
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
}

.brand img {
  display: block;
  width: 220px;
  height: 58px;
  object-fit: contain;
  object-position: left center;
}

nav {
  display: flex;
  gap: 14px;
}

nav a,
.button {
  color: var(--blue-strong);
  text-decoration: none;
}

.user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto;
}

.page.page-wide {
  width: min(1440px, calc(100% - 32px));
}

.auth {
  min-height: calc(100vh - 160px);
  display: grid;
  place-items: center;
}

.panel,
.toolbar,
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 28px;
}

.auth .panel {
  box-sizing: border-box;
  width: min(100%, 440px);
}

.auth .panel button {
  width: 100%;
}

h1 {
  margin: 0 0 22px;
  font-size: 28px;
  color: var(--blue-strong);
}

h2 {
  margin: 0;
  font-size: 18px;
  color: var(--blue-strong);
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

label {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 14px;
}

input,
select,
button,
.button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  font: inherit;
}

input,
select {
  background: #fff;
  color: var(--text);
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.danger,
.button.danger,
button.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.primary:hover,
.button:hover,
button:hover {
  border-color: var(--red);
}

.toolbar {
  display: grid;
  gap: 16px;
  padding: 16px;
  margin-bottom: 18px;
}

.dashboard-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.dashboard-heading h1 {
  margin: 0;
}

.metric-grid,
.dashboard-grid,
.suggestion-grid {
  display: grid;
  gap: 16px;
}

.metric-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metric {
  min-height: 108px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--red);
  border-radius: 8px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  color: var(--blue-strong);
  font-size: 26px;
}

.dashboard-grid {
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.8fr);
  margin-bottom: 18px;
}

.chart-panel {
  display: grid;
  gap: 22px;
}

.bar-chart {
  display: grid;
  gap: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: 72px minmax(120px, 1fr) 140px;
  align-items: center;
  gap: 12px;
}

.bar-label {
  color: var(--muted);
  font-weight: 700;
}

.bar-track {
  height: 16px;
  overflow: hidden;
  background: #eef2ff;
  border-radius: 999px;
}

.bar-fill {
  min-width: 3px;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--red));
  border-radius: 999px;
}

.bar-row strong {
  color: var(--blue-strong);
  text-align: right;
}

.section-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.section-title h1 {
  margin: 0;
}

.section-title span {
  color: var(--red);
  font-weight: 700;
}

.inline-form,
.actions,
.actions form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.table-wrap {
  overflow-x: auto;
  margin-bottom: 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--blue);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.right {
  text-align: right;
}

.compact-table th,
.compact-table td {
  white-space: normal;
}

.expand-table > tbody > tr > td {
  padding: 0;
}

details {
  background: var(--surface);
}

summary {
  display: grid;
  grid-template-columns: 160px minmax(160px, 1fr) 140px;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  padding: 0 16px;
  cursor: pointer;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::before {
  content: "+";
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  grid-column: 1;
  justify-self: start;
  color: #fff;
  background: var(--blue);
  border-radius: 50%;
  font-weight: 700;
}

summary span {
  grid-column: 1;
  padding-left: 36px;
  color: var(--blue-strong);
  font-weight: 700;
}

details[open] summary::before {
  content: "-";
  background: var(--red);
}

summary strong {
  color: var(--blue-strong);
}

summary em {
  color: var(--muted);
  font-style: normal;
  text-align: right;
}

.detail-table {
  padding: 0 16px 16px;
  background: #fbfcff;
}

.detail-table table th {
  background: #eef2ff;
  color: var(--blue-strong);
}

.visual-suggestions {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.suggestion-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.suggestion-grid article {
  display: grid;
  gap: 8px;
  padding: 16px;
  background: #fbfcff;
  border: 1px solid var(--line);
  border-top: 4px solid var(--blue);
  border-radius: 8px;
}

.suggestion-grid strong {
  color: var(--blue-strong);
}

.suggestion-grid span {
  color: var(--muted);
  line-height: 1.4;
}

.flash {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #eef2ff;
  border: 1px solid #c7cfee;
}

.flash.error {
  background: #fdecea;
  border-color: #f2b8b5;
  color: var(--red-strong);
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 16px;
  }

  .user {
    margin-left: 0;
  }

  input,
  select,
  button,
  .button {
    width: 100%;
  }

  .metric-grid,
  .dashboard-grid,
  .suggestion-grid {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 1fr;
  }

  .bar-row strong {
    text-align: left;
  }

  summary {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 12px 14px;
  }

  summary span {
    grid-column: 1;
  }

  summary em {
    text-align: left;
  }
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 12px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--blue-strong);
  border: 2px solid var(--red);
  border-radius: 6px;
}

.skip-link:focus {
  left: 12px;
}

:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: 2px;
}

.filter-form fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.filter-form legend {
  padding: 0;
  margin-bottom: 12px;
  color: var(--blue-strong);
  font-size: 18px;
  font-weight: 700;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  margin: 0;
  color: var(--blue-strong);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.results-summary {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.results-summary strong {
  color: var(--blue-strong);
}

.nfes-table td small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.responsive-table .cell-value {
  min-width: 0;
}

.nfes-table .nfe-key-cell {
  min-width: 260px;
  white-space: normal;
}

.nfe-key-block {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.nfe-key {
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: normal;
}

.nfe-key-block .copy-key-button {
  flex: 0 0 auto;
  width: auto;
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
}

.agendamentos-table .nfe-reference-cell {
  min-width: 310px;
  white-space: normal;
}

.agendamentos-table td:nth-child(4),
.agendamentos-table td:nth-child(5) {
  min-width: 190px;
  white-space: normal;
}

.nfe-reference > strong {
  display: block;
  margin-bottom: 6px;
}

.nfes-table td:nth-child(4),
.nfes-table td:nth-child(5) {
  min-width: 190px;
  white-space: normal;
}

.badge {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--blue-strong);
  font-size: 13px;
  font-weight: 700;
  white-space: normal;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 16px 0;
}

.pagination .button,
.pagination .page-current {
  min-width: 40px;
  min-height: 40px;
  padding: 0 10px;
}

.page-current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

.pagination-gap {
  color: var(--muted);
  padding: 0 4px;
}

.empty-state {
  text-align: center;
}

.empty-state p {
  margin: 4px 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.nfe-summary h1 {
  margin-bottom: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin: 0 0 20px;
}

.summary-grid > div {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcff;
}

.summary-grid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.summary-grid dd {
  margin: 5px 0 0;
  color: var(--blue-strong);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.summary-grid dd small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.mono {
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.schedule-form h2 {
  margin-bottom: 14px;
}

.field textarea {
  width: 100%;
  min-height: 100px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  resize: vertical;
}

.field small {
  color: var(--muted);
  font-size: 12px;
}

.flash a {
  color: var(--blue-strong);
  font-weight: 700;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.status-badge {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.status-ativo {
  background: #e8f6ee;
  color: #17603a;
}

.status-cancelado {
  background: #fdecea;
  color: var(--red-strong);
}

.agendamento-cancelado td {
  color: var(--muted);
}

.agendamentos-table td small,
.history-table td small,
.acessos-table td small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.status-revogado {
  background: #eef2ff;
  color: var(--muted);
}

.revoked-row td {
  color: var(--muted);
}

.assignment-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.assignment-user {
  padding: 0 12px;
  background: #fbfcff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.assignment-user summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0;
  color: var(--blue-strong);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.assignment-user summary::-webkit-details-marker {
  display: none;
}

.assignment-user summary::before {
  content: "+";
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  background: var(--blue);
  border-radius: 50%;
  font-size: 14px;
}

.assignment-user[open] summary::before {
  content: "-";
  background: var(--red);
}

.assignment-user .role-form {
  padding-bottom: 14px;
  align-items: end;
}

.assignment-user .role-form .field {
  min-width: 180px;
  flex: 1;
}

.assignment-user .role-form .field input,
.assignment-user .role-form .field select {
  width: 100%;
}

.page-actions {
  margin-bottom: 16px;
}

.items-header {
  margin: 20px 0 10px;
}

.items-header h3 {
  margin: 0;
  color: var(--blue-strong);
}

.items-table td {
  white-space: normal;
}

.items-table td small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.nfe-dialog {
  width: min(1100px, calc(100% - 24px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.35);
}

.nfe-dialog::backdrop {
  background: rgba(15, 23, 42, 0.58);
}

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 0;
}

.dialog-content {
  max-height: calc(100vh - 150px);
  padding: 20px;
  overflow: auto;
}

.nfe-detail h2 {
  margin-bottom: 14px;
}

@media (max-width: 720px) {
  .dialog-header {
    align-items: flex-start;
    padding: 14px 16px;
  }

  .dialog-header .button {
    width: auto;
  }

  .dialog-content {
    max-height: calc(100vh - 170px);
    padding: 14px;
  }
}

.flash ul {
  margin: 0;
  padding-left: 20px;
}

@media (max-width: 720px) {
  .results-summary {
    font-size: 13px;
  }
}

@media (max-width: 900px) {
  .responsive-table {
    display: block;
    width: 100%;
  }

  .responsive-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  .responsive-table tbody {
    display: grid;
    gap: 12px;
    padding: 12px;
  }

  .responsive-table tr {
    display: grid;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
  }

  .responsive-table td,
  .responsive-table td:nth-child(4),
  .responsive-table td:nth-child(5),
  .responsive-table .nfe-key-cell,
  .responsive-table .nfe-reference-cell {
    display: grid;
    grid-template-columns: minmax(100px, 0.35fr) minmax(0, 1fr);
    gap: 12px;
    min-width: 0;
    padding: 10px 12px;
    white-space: normal;
  }

  .responsive-table td::before {
    content: attr(data-label);
    color: var(--blue-strong);
    font-size: 12px;
    font-weight: 700;
  }

  .responsive-table td:last-child {
    border-bottom: 0;
  }

  .responsive-table td.right {
    text-align: left;
  }

  .responsive-table .actions {
    align-items: stretch;
  }

  .table-wrap:has(.responsive-table) {
    overflow-x: visible;
  }
}
