:root {
  --red: #ef0038;
  --red-dark: #c9002f;
  --orange: #ff6a00;
  --yellow: #ffc400;
  --black: #202020;
  --sidebar: #101722;
  --sidebar-2: #0b111a;
  --gray-900: #262626;
  --gray-700: #52525b;
  --gray-500: #71717a;
  --gray-300: #d4d4d8;
  --gray-200: #e4e4e7;
  --gray-100: #f4f4f5;
  --white: #ffffff;
  --background: #fff9f4;
  --border: #f0e2d6;
  --success: #047857;
  --danger: #dc2626;
  --warning: #b45309;
  --shadow: 0 18px 45px rgba(32, 32, 32, .08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--black);
  font-family: Inter, Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 106, 0, .10), transparent 28%),
    radial-gradient(circle at 88% 0%, rgba(239, 0, 56, .08), transparent 30%),
    linear-gradient(180deg, #fff 0%, var(--background) 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(480px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 26px;
  background: rgba(255, 255, 255, .97);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 7px;
  background: linear-gradient(90deg, var(--red), var(--orange), var(--yellow));
}

.auth-brand {
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--white);
}

.auth-brand img {
  max-width: 220px;
  max-height: 80px;
  object-fit: contain;
}

.auth-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.auth-heading h1,
.auth-heading p {
  margin: 0;
}

.auth-heading h1 {
  font-size: 24px;
}

.auth-heading p {
  margin-top: 4px;
  color: var(--gray-500);
}

.icon-box {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #fff0f3, #fff3e6);
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--gray-700);
  font-size: 13px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 11px 13px;
  color: var(--black);
  border: 1px solid #ead9cc;
  border-radius: 13px;
  outline: none;
  background: #fffdfb;
  transition: .18s ease;
}

input:focus,
select:focus {
  border-color: var(--orange);
  background: var(--white);
  box-shadow: 0 0 0 4px rgba(255, 106, 0, .13);
}

.btn {
  min-height: 40px;
  padding: 9px 14px;
  border: 0;
  border-radius: 12px;
  color: var(--white);
  font-size: 13px;
  font-weight: 900;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  box-shadow: 0 10px 22px rgba(239, 0, 56, .20);
}

.btn-secondary {
  background: var(--black);
}

.btn-outline {
  color: var(--black);
  border: 1px solid var(--border);
  background: var(--white);
}

.btn-warning {
  color: #2a1a00;
  background: linear-gradient(135deg, var(--orange), var(--yellow));
}

.btn-danger {
  background: var(--danger);
}

.btn-success {
  background: var(--success);
}

.btn-small {
  min-height: 32px;
  padding: 6px 9px;
  border-radius: 9px;
  font-size: 11px;
  box-shadow: none;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.form-message {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.5;
}

.form-message.success {
  color: var(--success);
}

.form-message.error {
  color: var(--danger);
}

.app-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  height: 100vh;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  color: var(--white);
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  box-shadow: 12px 0 32px rgba(16, 23, 34, .18);
  overflow-y: auto;
}

.sidebar-logo {
  min-height: 94px;
  display: grid;
  place-items: center;
  padding: 14px;
  margin-bottom: 18px;
  border-radius: 22px;
  background: var(--white);
}

.sidebar-logo img {
  max-width: 210px;
  max-height: 80px;
  object-fit: contain;
}

.nav-section {
  margin: 22px 8px 10px;
  color: var(--yellow);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.nav-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  margin-bottom: 7px;
  color: var(--white);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 13px;
  background: transparent;
  font-weight: 800;
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  border-color: transparent;
  background: linear-gradient(135deg, var(--red), var(--orange));
  box-shadow: 0 12px 24px rgba(239, 0, 56, .20);
}

.sidebar-footer {
  padding-top: 18px;
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, .12);
}

.main-area {
  min-width: 0;
}

.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 28px;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, .95);
  box-shadow: 0 10px 30px rgba(32, 32, 32, .05);
  backdrop-filter: blur(10px);
}

.topbar h1,
.topbar p {
  margin: 0;
}

.topbar h1 {
  font-size: 28px;
}

.topbar p {
  margin-top: 4px;
  color: var(--gray-500);
  font-weight: 700;
}

.topbar-user {
  color: var(--gray-700);
  font-size: 13px;
  font-weight: 800;
}

.brand-line {
  height: 5px;
  background: linear-gradient(90deg, var(--red), var(--orange), var(--yellow));
}

.content {
  width: min(1450px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 54px;
}

.toolbar,
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.toolbar {
  margin-bottom: 18px;
}

.toolbar h2,
.toolbar p,
.card-header h3,
.card-header p {
  margin: 0;
}

.toolbar p,
.card-header p {
  margin-top: 4px;
  color: var(--gray-500);
}

.toolbar-actions,
.upload-row {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.inline-field {
  min-width: 170px;
  margin: 0;
}

.card {
  padding: 22px;
  margin-bottom: 22px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: rgba(255, 255, 255, .97);
  box-shadow: var(--shadow);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 15px;
  margin-bottom: 22px;
}

.metric-card {
  min-height: 140px;
  padding: 20px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: linear-gradient(135deg, var(--white), #fff7f0);
  box-shadow: 0 12px 30px rgba(32, 32, 32, .05);
}

.metric-card::after {
  content: "";
  width: 90px;
  height: 90px;
  position: absolute;
  top: -30px;
  right: -30px;
  border-radius: 50%;
  background: rgba(239, 0, 56, .07);
}

.metric-label {
  color: var(--gray-500);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.metric-value {
  display: block;
  margin-top: 10px;
  color: var(--red);
  font-size: 28px;
  font-weight: 900;
}

.metric-help {
  display: block;
  margin-top: 8px;
  color: var(--gray-500);
  font-size: 12px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 20px;
}

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

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--gray-700);
  font-size: 12px;
  font-weight: 800;
}

.bar-track {
  height: 11px;
  border-radius: 999px;
  background: var(--gray-100);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--orange), var(--yellow));
}

.activity-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.activity-item {
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fffdfb;
}

.activity-item strong,
.activity-item span {
  display: block;
}

.activity-item span {
  margin-top: 4px;
  color: var(--gray-500);
  font-size: 12px;
}

.filter-grid {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.filter-grid label {
  margin: 0;
}

.header-search {
  width: min(340px, 100%);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0 8px;
}

th {
  padding: 7px 9px;
  color: var(--gray-500);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .04em;
  text-align: left;
  text-transform: uppercase;
}

td {
  padding: 12px 9px;
  vertical-align: middle;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #fffdfb;
}

td:first-child {
  border-left: 1px solid var(--border);
  border-radius: 13px 0 0 13px;
}

td:last-child {
  border-right: 1px solid var(--border);
  border-radius: 0 13px 13px 0;
}

.table-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
}

.badge-success {
  color: #166534;
  background: #dcfce7;
}

.badge-danger {
  color: #991b1b;
  background: #fee2e2;
}

.badge-warning {
  color: #92400e;
  background: #ffedd5;
}

.badge-info {
  color: #1e40af;
  background: #dbeafe;
}

.pager {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  margin-top: 14px;
}

.pager-info {
  margin-right: auto;
  color: var(--gray-500);
  font-size: 12px;
  font-weight: 800;
}

.pager-button {
  min-width: 34px;
  height: 34px;
  padding: 0 9px;
  color: var(--black);
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--white);
  font-size: 12px;
  font-weight: 900;
}

.pager-button.active {
  color: var(--white);
  border-color: transparent;
  background: linear-gradient(135deg, var(--red), var(--orange));
}

.pager-button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 23, .65);
  backdrop-filter: blur(4px);
}

.modal {
  width: min(720px, 100%);
  max-height: calc(100vh - 40px);
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 22px;
  background: var(--white);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .30);
}

.modal-header,
.modal-footer {
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-color: var(--border);
}

.modal-header {
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.modal-header h2,
.modal-header p {
  margin: 0;
}

.modal-header p {
  margin-top: 4px;
  color: var(--gray-500);
}

.modal-body {
  padding: 22px;
  overflow-y: auto;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.modal-grid .full {
  grid-column: 1 / -1;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 11px;
  color: var(--gray-700);
  background: var(--gray-100);
}

.toast-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1200;
  display: grid;
  gap: 10px;
}

.toast {
  min-width: 280px;
  max-width: 420px;
  padding: 14px 16px;
  color: var(--white);
  border-radius: 14px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .22);
  animation: toast-in .18s ease;
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--danger);
}

.toast.info {
  background: var(--black);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.empty-state {
  padding: 24px;
  color: var(--gray-500);
  text-align: center;
}

@media (max-width: 1100px) {
  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }

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

@media (max-width: 950px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    position: relative;
  }

  .sidebar-footer {
    margin-top: 20px;
  }

  .filter-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .content {
    width: min(100% - 20px, 1450px);
  }

  .topbar {
    padding: 16px;
    align-items: flex-start;
    flex-direction: column;
  }

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

  .toolbar,
  .card-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-actions,
  .upload-row {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }
}

/* Fase 2C - Importacao e exportacao */
.import-actions {
  display: grid;
  gap: 14px;
}

.download-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.export-status {
  color: var(--gray-500);
  font-size: 12px;
  font-weight: 800;
}

@media (max-width: 640px) {
  .download-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .download-actions .btn,
  .download-actions .link-button {
    width: 100%;
  }
}

/* Fase 2D - Auditoria, perfis e fechamento */
.closing-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 14px;
}

.closing-summary {
  margin-top: 18px;
}

.closing-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.closing-summary-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fffdfb;
}

.closing-summary-card span,
.closing-summary-card strong {
  display: block;
}

.closing-summary-card span {
  color: var(--gray-500);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.closing-summary-card strong {
  margin-top: 7px;
  color: var(--red);
  font-size: 22px;
}

.audit-filters {
  display: grid;
  grid-template-columns: 1.2fr 1.4fr 1fr 1fr auto;
  gap: 12px;
  margin-bottom: 18px;
}

.profile-admin {
  color: #991b1b;
  background: #fee2e2;
}

.profile-gestor {
  color: #7c2d12;
  background: #ffedd5;
}

.profile-financeiro {
  color: #1e40af;
  background: #dbeafe;
}

.profile-operador {
  color: #166534;
  background: #dcfce7;
}

.profile-consulta {
  color: #52525b;
  background: #e4e4e7;
}

@media (max-width: 1100px) {
  .audit-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .closing-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .audit-filters,
  .closing-summary-grid {
    grid-template-columns: 1fr;
  }

  .closing-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
