:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3fb;
  --text: #172033;
  --muted: #68738a;
  --line: #dfe6f1;
  --primary: #2357d9;
  --primary-dark: #173a93;
  --success: #0f8a5f;
  --warning: #b56a00;
  --danger: #b42318;
  --radius: 18px;
  --shadow: 0 20px 50px rgba(23, 32, 51, 0.08);
  --focus: 0 0 0 4px rgba(35, 87, 217, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--primary);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  z-index: 20;
}

.skip-link:focus {
  top: 1rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1.5rem;
  background: #101827;
  color: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.brand__icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--primary);
}

.brand small,
.metric-card small,
.debtor-card small {
  display: block;
  color: var(--muted);
}

.sidebar .brand small,
.sidebar p {
  color: #b9c3d7;
}

.menu {
  display: grid;
  gap: 0.45rem;
}

.menu__item {
  text-decoration: none;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  color: #d8e0ef;
}

.menu__item:hover,
.menu__item:focus-visible,
.menu__item--active {
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

.security-card {
  margin-top: auto;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
}

.security-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.security-card p {
  margin: 0;
  font-size: 0.9rem;
}

.main-content {
  padding: 2rem;
  display: grid;
  gap: 1.5rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.topbar h1,
.section-heading h2 {
  margin: 0;
}

.topbar__actions,
.form-actions,
.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--primary);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.grid,
.layout-two-columns,
.security-grid {
  display: grid;
  gap: 1rem;
}

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

.layout-two-columns {
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 1.2rem;
  border-top: 4px solid var(--primary);
}

.metric-card--success {
  border-top-color: var(--success);
}

.metric-card--warning {
  border-top-color: var(--warning);
}

.metric-card--danger {
  border-top-color: var(--danger);
}

.metric-card__label {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
}

.metric-card strong {
  display: block;
  margin: 0.35rem 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.panel {
  padding: 1.4rem;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.badge,
.chip,
.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
  font-weight: 700;
}

.badge {
  background: #e8efff;
  color: var(--primary-dark);
}

.badge--muted {
  background: var(--surface-soft);
  color: var(--muted);
}

.button {
  border: 0;
  border-radius: 12px;
  padding: 0.78rem 1rem;
  color: white;
  background: var(--primary);
  font-weight: 800;
}

.button:hover,
.button:focus-visible {
  background: var(--primary-dark);
  outline: none;
  box-shadow: var(--focus);
}

.button--ghost {
  color: var(--primary-dark);
  background: #e8efff;
}

.form {
  display: grid;
  gap: 1rem;
}

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

.form-grid--four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 0.4rem;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.78rem 0.85rem;
  color: var(--text);
  background: white;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: var(--focus);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

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

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tr:last-child td {
  border-bottom: 0;
}

.status--ok {
  color: #05603a;
  background: #d1fadf;
}

.status--open {
  color: #1849a9;
  background: #dbeafe;
}

.status--late {
  color: #912018;
  background: #fee4e2;
}

.debtor-list {
  display: grid;
  gap: 0.75rem;
}

.debtor-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfcff;
}

.debtor-card span {
  font-weight: 900;
  color: var(--primary-dark);
}

.chip {
  border: 1px solid var(--line);
  color: var(--muted);
  background: white;
}

.chip--active,
.chip:hover,
.chip:focus-visible {
  color: white;
  background: var(--primary);
  outline: none;
}

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

.security-grid article {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfcff;
}

.security-grid h3 {
  margin: 0 0 0.5rem;
}

.security-grid p {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .cards-grid,
  .security-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layout-two-columns,
  .form-grid--four {
    grid-template-columns: 1fr;
  }
}

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

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

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

  .main-content {
    padding: 1rem;
  }

  .topbar,
  .section-heading {
    flex-direction: column;
  }

  .cards-grid,
  .form-grid,
  .security-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .sidebar,
  .panel {
    padding: 1rem;
  }

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

  .topbar__actions,
  .form-actions,
  .filter-group {
    width: 100%;
  }

  .button,
  .chip {
    width: 100%;
  }
}

/* ==========================================
   Modais e Elementos Dinâmicos Adicionais (MVP)
   ========================================== */

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(16, 24, 39, 0.4);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop--active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 90%;
  max-width: 500px;
  padding: 1.8rem;
  transform: translateY(20px);
  transition: transform 0.25s ease;
}

.modal-backdrop--active .modal-content {
  transform: translateY(0);
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text);
}

.modal-close {
  background: none;
  border: 0;
  font-size: 1.5rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--danger);
}

/* Controladores de Exibição das Abas (SPA) */
.section-wrapper {
  display: none !important;
}

.section-wrapper--active {
  display: grid !important;
}

/* Seções simples (card panel) usam display block */
section.panel.section-wrapper--active {
  display: block !important;
}

/* Indicadores de Status e Estados da UI */
.loading-indicator,
.empty-state,
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  margin: 1rem 0;
}

.empty-state__icon {
  font-size: 2.8rem;
  margin-bottom: 0.8rem;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4.5px solid var(--surface-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 0.8rem;
}

.error-state {
  border-color: var(--danger);
  color: var(--danger);
}

.error-state__icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Botões utilitários de tabelas */
.button-action {
  background: none;
  border: 0;
  color: var(--primary);
  cursor: pointer;
  font-weight: bold;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  font-size: 0.8rem;
  transition: background-color 0.2s;
}

.button-action:hover {
  background: var(--surface-soft);
}

.button-action--danger {
  color: var(--danger);
}

.button-action--danger:hover {
  background: #fee4e2;
}

.button-action--success {
  color: var(--success);
}

.button-action--success:hover {
  background: #d1fadf;
}

/* Elementos de Ações Rápidas na Tabela */
.td-actions {
  display: flex;
  gap: 0.4rem;
}

/* Topbar Ajustada */
.topbar__actions {
  align-items: center;
}

.topbar__month-select {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  font-weight: 700;
  color: var(--text);
}

/* ==========================================
   SISTEMA DE TOASTS E NOTIFICAÇÕES (PREMIUM)
   ========================================== */
#toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  display: grid;
  gap: 0.75rem;
  z-index: 10000;
  max-width: 400px;
  width: calc(100vw - 3rem);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(23, 32, 51, 0.12);
  border: 1px solid var(--line);
  color: var(--text);
  pointer-events: auto;
  transform: translateX(120%);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.35s ease;
}

.toast--visible {
  transform: translateX(0);
  opacity: 1;
}

.toast--exit {
  transform: translateX(120%);
  opacity: 0;
}

.toast--success {
  border-left: 5px solid var(--success);
}

.toast--error {
  border-left: 5px solid var(--danger);
}

.toast--warning {
  border-left: 5px solid var(--warning);
}

.toast__icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.toast__message {
  font-size: 0.9rem;
  font-weight: 500;
  flex-grow: 1;
}

.toast__close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.2rem;
  line-height: 1;
  transition: color 0.2s;
}

.toast__close:hover {
  color: var(--text);
}

/* ==========================================
   MODAL DE CONFIRMAÇÃO
   ========================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(16, 24, 39, 0.4);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 0;
  animation: fadeIn 0.25s forwards;
}

.modal-overlay--exit {
  animation: fadeOut 0.25s forwards;
}

.modal-confirm {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 90%;
  max-width: 440px;
  padding: 1.6rem;
  transform: scale(0.9);
  opacity: 0;
  animation: modalScaleIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-confirm--exit {
  animation: modalScaleOut 0.25s forwards;
}

.modal-confirm__header h3 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--text);
}

.modal-confirm__body {
  margin: 1rem 0 1.5rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.modal-confirm__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

@keyframes fadeIn {
  to { opacity: 1; }
}

@keyframes fadeOut {
  to { opacity: 0; }
}

@keyframes modalScaleIn {
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes modalScaleOut {
  to {
    transform: scale(0.9);
    opacity: 0;
  }
}

/* ==========================================
   SPINNER E LOADINGS
   ========================================== */
.button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.button .spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
  margin-bottom: 0;
  margin-right: 0.5rem;
  display: inline-block;
  vertical-align: middle;
}

/* ==========================================
   RESPONSIVIDADE MOBILE
   ========================================== */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    min-height: auto;
    z-index: 1000;
    flex-direction: row;
    justify-content: space-around;
    padding: 0.75rem;
    gap: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .sidebar .brand,
  .sidebar .security-card {
    display: none;
  }

  .sidebar .menu {
    grid-template-columns: repeat(6, 1fr);
    width: 100%;
    gap: 0.25rem;
  }

  .sidebar .menu__item {
    padding: 0.5rem 0.2rem;
    font-size: 0.7rem;
    text-align: center;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
  }

  .main-content {
    padding: 1rem;
    padding-bottom: 5.5rem; /* Margem para o menu bottom */
  }

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

  .layout-two-columns {
    grid-template-columns: 1fr;
  }

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

  .topbar__actions {
    margin-top: 0.5rem;
    justify-content: space-between;
  }
}

@media (max-width: 480px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }
}


