:root {
  --bg: #eef0f0;
  --card: #ffffff;
  --text: #262626;
  --muted: #6b6b6b;
  --primary: #8a1b2b;
  --primary-dark: #6b1520;
  --border: #d9d9d9;
  --error-bg: #fbdede;
  --error-text: #8a1b2b;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 2rem 1rem;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.container.wide {
  max-width: 1100px;
}

.container.narrow {
  max-width: 380px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.85rem 1.5rem;
  margin: -2rem -2rem 1.5rem -2rem;
  background: var(--primary);
  border-radius: 12px 12px 0 0;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.nav-logo {
  height: 20px;
  width: auto;
  margin-right: 0.5rem;
}

.login-brand {
  background: var(--primary);
  margin: -2rem -2rem 1.5rem -2rem;
  padding: 1rem 2rem;
  border-radius: 12px 12px 0 0;
  display: flex;
  justify-content: center;
}

.login-logo {
  height: 28px;
  width: auto;
}

.nav a {
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  opacity: 0.9;
}

.nav a:hover {
  opacity: 1;
  text-decoration: underline;
}

.nav-spacer {
  flex: 1;
}

.nav-user {
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.85rem;
}

h1 {
  margin-top: 0;
  font-size: 1.5rem;
}

.subtitle {
  color: var(--muted);
  margin-top: -0.5rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

legend {
  font-weight: 600;
  padding: 0 0.5rem;
}

.field {
  margin-bottom: 0.9rem;
}

.field-row {
  display: flex;
  gap: 0.75rem;
}

.field.grow { flex: 2; }
.field.small { flex: 1; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--muted);
}

input, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: #fff;
  color: var(--text);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.hint {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.hint.error { color: var(--error-text); }
.hint.ok { color: #15803d; }

.exam-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}

.exam-table th, .exam-table td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.sel-input { width: 18px; height: 18px; }
.valor-input { width: 100px; }

.valor-input.input-error {
  border-color: var(--error-text);
  background: var(--error-bg);
}

.field-error {
  display: block;
  font-size: 0.75rem;
  color: var(--error-text);
  margin-top: 0.25rem;
  white-space: normal;
}

button, .button {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.7rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
}

button:hover, .button:hover { background: var(--primary-dark); }

.button-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  display: inline-block;
}

.button-secondary:hover { background: var(--bg); }

.button-danger {
  background: #fff;
  color: var(--error-text);
  border: 1px solid var(--error-text);
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.button-danger:hover { background: var(--error-bg); }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  font-size: inherit;
  font-family: inherit;
}

.link-btn:hover {
  color: var(--text);
  text-decoration-thickness: 2px;
}

.bulk-actions {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.summary p { margin: 0.4rem 0; }

.table-wrap {
  overflow-x: auto;
}

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

th, td {
  text-align: left;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  white-space: nowrap;
}

.actions-cell {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.actions-cell form {
  margin: 0;
}

.inline-form {
  display: flex;
  gap: 0.4rem;
}

.inline-form input {
  width: 140px;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.perm-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text);
}

.perm-check input {
  width: 16px;
  height: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-backdrop[hidden] { display: none; }

body.modal-open { overflow: hidden; }

.modal {
  background: var(--card);
  border-radius: 12px;
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
}

.modal-body {
  padding: 1.25rem 1.5rem;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.detail-item.detail-full {
  grid-column: 1 / -1;
}

.detail-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.detail-value {
  font-size: 0.95rem;
  color: var(--text);
  white-space: pre-wrap;
}

.modal-footer {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.modal-footer form {
  margin: 0;
}

.detail-nf-section {
  margin: 0 1.5rem 1rem;
  padding: 1rem;
  background: var(--bg);
  border-radius: 8px;
}

.detail-nf-section .field-row {
  align-items: flex-end;
  margin-top: 0.6rem;
}

.nf-save-wrap {
  display: flex;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-ok {
  background: #dcfce7;
  color: #15803d;
}

.badge-pending {
  background: #ececec;
  color: var(--muted);
}

tr.row-nf-criada > td {
  background: #dcfce7;
}

@media print {
  body * {
    visibility: hidden;
  }

  #detail-backdrop,
  #detail-backdrop * {
    visibility: visible;
  }

  #detail-backdrop {
    position: absolute;
    inset: 0;
    background: #fff;
    padding: 0;
  }

  .modal {
    box-shadow: none;
    max-height: none;
    max-width: none;
  }

  .modal-footer,
  .detail-nf-section {
    display: none;
  }
}
