/* ==========================================================================
   Sallute ADM — Design System (v2, tema claro)
   Merge do design system anterior (dark) com o novo layout de sidebar.
   - As variáveis antigas (--accent, --text-muted, --bg-elevated...) foram
     mantidas como ALIASES da nova paleta: componentes antigos continuam
     funcionando sem alteração de classe.
   - Removidos: header/navbar/dropdown antigos (substituídos pela sidebar
     do novo base.html).
   ========================================================================== */

:root {
  /* ---------- Nova paleta ---------- */
  --ink:        #131C31;
  --ink-soft:   #4A566E;
  --ink-faint:  #7A86A0;
  --night-1:    #0E1730;
  --night-2:    #1D2C55;
  --night-line: rgba(255, 255, 255, 0.08);
  --bg:         #F3F5FA;
  --surface:    #FFFFFF;
  --surface-2:  #F7F9FD;
  --line:       #E2E7F1;
  --line-subtle:#EEF1F7;
  --primary:    #2C55E0;
  --primary-dk: #2143B8;
  --primary-bg: #EBF0FE;
  --amber:      #F5A524;

  /* Status */
  --ok-fg:      #0E7A57;  --ok-bg:      #E2F5EC;
  --warn-fg:    #935A00;  --warn-bg:    #FDF1DA;
  --bad-fg:     #B4232A;  --bad-bg:     #FCE8E9;
  --muted-fg:   #57627A;  --muted-bg:   #EDF0F6;

  /* Estrutura */
  --sidebar-w:  248px;
  --radius:     10px;
  --radius-sm:  7px;
  --shadow:     0 1px 2px rgba(19, 28, 49, 0.05), 0 4px 16px rgba(19, 28, 49, 0.06);

  --font-body:    'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;

  /* ---------- Aliases das variáveis antigas ----------
     Mantêm compatível qualquer regra ou estilo inline que
     ainda use os nomes do design system anterior. */
  --bg-elevated:    var(--surface);
  --bg-elevated-2:  var(--surface-2);
  --border:         var(--line);
  --border-subtle:  var(--line-subtle);
  --text:           var(--ink);
  --text-muted:     var(--ink-soft);
  --text-faint:     var(--ink-faint);
  --accent:         var(--primary);
  --accent-hover:   var(--primary-dk);
  --accent-bg:      var(--primary-bg);
  --success:        var(--ok-fg);
  --success-hover:  #0A6448;
  --danger:         var(--bad-fg);
  --danger-hover:   #98151C;
  --warning:        var(--warn-fg);
  --neutral:        var(--muted-fg);
  --neutral-hover:  #6B7690;
  --font:           var(--font-body);
}

/* ==========================================================================
   Reset e base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color-scheme: light;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0 0 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1rem 0 1.5rem;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background-color: #C9D1E0; border-radius: 10px; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ==========================================================================
   Layout: sidebar + conteúdo (novo base.html)
   ========================================================================== */

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(178deg, var(--night-1) 0%, var(--night-2) 100%);
  color: #C9D2E8;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--night-line);
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: radial-gradient(circle at 30% 30%, #3D63E8, #16255C);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-mark svg { display: block; }

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.2px;
  color: #FFFFFF;
  line-height: 1.15;
}

.brand-sub {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: #8B99BD;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 12px;
  overflow-y: auto;
}

.nav-group + .nav-group { margin-top: 18px; }

.nav-group-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: #7688B0;
  padding: 0 10px;
  margin-bottom: 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: #C9D2E8;
  font-weight: 500;
  position: relative;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #FFFFFF;
  text-decoration: none;
}

.nav-link.active {
  background: rgba(255, 255, 255, 0.10);
  color: #FFFFFF;
}

/* Marcador âmbar do item ativo */
.nav-link.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--amber);
}

.nav-link svg { flex-shrink: 0; opacity: 0.85; }

.nav-sub {
  display: block;
  padding: 6px 10px 6px 36px;
  border-radius: var(--radius-sm);
  color: #93A1C4;
  font-size: 13px;
}

.nav-sub:hover {
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--night-line);
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-block { position: relative; flex-shrink: 0; }

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #2C3D6E;
  color: #FFF;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.12);
}

.user-avatar-img {
  display: block;
  width: 38px;
  max-width: 38px;
  height: 38px;
  max-height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.12);
}

.avatar-settings-btn {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--primary);
  color: #FFF;
  border: 2px solid var(--night-1);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.15s ease;
}

.avatar-settings-btn:hover { background: var(--primary-dk); transform: scale(1.08); }
.avatar-settings-btn svg { flex-shrink: 0; }

.user-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.user-name { color: #FFF; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-form { margin: 0; }

.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #C9D2E8;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-logout svg { flex-shrink: 0; }

.btn-logout:hover {
  background: rgba(226, 62, 62, 0.16);
  color: #FFD9D9;
  border-color: rgba(226, 62, 62, 0.35);
  text-decoration: none;
}

.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;
}

/* ---------- Modal: foto de perfil ---------- */

.avatar-modal {
  position: fixed;
  margin: auto;
  inset: 0;
  width: 100%;
  max-width: 320px;
  max-height: calc(100vh - 4rem);
  padding: 1.5rem;
  background: var(--surface);
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 24px 60px -18px rgba(6, 10, 26, 0.5);
  color: var(--ink);
}

.avatar-modal::backdrop {
  background: rgba(9, 15, 34, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

@media (prefers-reduced-motion: no-preference) {
  .avatar-modal[open]          { animation: avatar-modal-in 0.18s ease-out; }
  .avatar-modal[open]::backdrop { animation: avatar-modal-backdrop-in 0.18s ease-out; }
}

@keyframes avatar-modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes avatar-modal-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.avatar-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease;
}

.avatar-modal-close:hover { background: var(--line); color: var(--ink); }

.avatar-modal-title {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
}

.avatar-modal-preview {
  width: 96px;
  height: 96px;
  margin: 0 auto 1.25rem;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}

.avatar-modal-preview-img {
  display: block;
  width: 96px;
  max-width: 96px;
  height: 96px;
  max-height: 96px;
  object-fit: cover;
}

.avatar-modal-preview-placeholder {
  font-size: 30px;
  font-weight: 700;
  color: var(--ink-faint);
}

.avatar-modal-form { margin: 0; }

.avatar-modal-form label {
  margin-top: 0;
  font-size: 0.85rem;
}

.avatar-modal-form input[type="file"] { font-size: 12.5px; }

.avatar-modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 1.25rem;
}

.avatar-modal-actions .btn-primary { margin-left: auto; }

/* ==========================================================================
   Login
   ========================================================================== */

.login-body {
  position: relative;
  overflow: hidden;
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(120% 120% at 15% 0%, var(--night-2) 0%, var(--night-1) 55%, #090F22 100%);
  color-scheme: dark;
  font-family: var(--font-body);
}

.login-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  pointer-events: none;
  z-index: 0;
}

.login-glow-1 {
  width: 380px;
  height: 380px;
  top: -120px;
  right: -80px;
  background: radial-gradient(circle, rgba(245, 165, 36, 0.35), transparent 70%);
}

.login-glow-2 {
  width: 420px;
  height: 420px;
  bottom: -160px;
  left: -120px;
  background: radial-gradient(circle, rgba(44, 85, 224, 0.45), transparent 70%);
}

.login-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse at center, black, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at center, black, transparent 75%);
  pointer-events: none;
  z-index: 0;
}

.login-wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
  padding: 1.5rem;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 1.5rem;
  color: #FFF;
}

.login-brand .brand-name { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; }
.login-brand .brand-sub { font-size: 0.78rem; color: #8B99BD; }

.brand-mark-lg {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  position: relative;
  box-shadow: 0 0 0 1px rgba(245, 165, 36, 0.25), 0 8px 24px -8px rgba(245, 165, 36, 0.55);
}

.brand-mark-lg svg { position: relative; z-index: 1; }

.brand-mark-ring {
  position: absolute;
  inset: -6px;
  border-radius: 16px;
  border: 1px solid rgba(245, 165, 36, 0.35);
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .brand-mark-ring { animation: login-ring-pulse 2.6s ease-in-out infinite; }
}

@keyframes login-ring-pulse {
  0%, 100% { transform: scale(1);    opacity: 0.55; }
  50%      { transform: scale(1.08); opacity: 0.15; }
}

.login-card {
  max-width: none;
  position: relative;
  padding-top: 2rem;
  box-shadow: 0 24px 60px -20px rgba(6, 10, 26, 0.55), 0 2px 6px rgba(6, 10, 26, 0.08);
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 1.5rem;
  right: 1.5rem;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: linear-gradient(90deg, var(--amber), var(--primary));
}

.login-title { margin: 0 0 0.35rem; text-align: left; }

.login-subtitle {
  margin: 0 0 1.5rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.field-icon { position: relative; }

.field-icon input { padding-left: 2.5rem; }

.field-icon::before {
  content: "";
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0.5;
  pointer-events: none;
}

.field-icon-user::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%234A566E' stroke-width='1.4'%3E%3Ccircle cx='8' cy='5.2' r='2.6'/%3E%3Cpath d='M2.8 13.2c0-2.6 2.3-4.2 5.2-4.2s5.2 1.6 5.2 4.2'/%3E%3C/svg%3E");
}

.field-icon-lock::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%234A566E' stroke-width='1.4'%3E%3Crect x='3.2' y='7.2' width='9.6' height='6.4' rx='1.2'/%3E%3Cpath d='M5.2 7.2V5a2.8 2.8 0 0 1 5.6 0v2.2'/%3E%3C/svg%3E");
}

.login-submit {
  width: 100%;
  margin-top: 1.5rem;
  position: relative;
  touch-action: manipulation;
  box-shadow: 0 8px 20px -6px rgba(44, 85, 224, 0.55);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.login-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px -6px rgba(44, 85, 224, 0.65);
}

.login-submit:active { transform: translateY(0); }

.login-submit.is-loading { cursor: default; opacity: 0.9; }

.login-submit.is-loading::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #FFF;
  animation: login-spin 0.7s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .login-submit.is-loading::after { animation: none; }
}

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

.content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  padding: 28px 32px 40px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

.app-footer {
  padding: 16px 32px;
  color: var(--ink-faint);
  font-size: 12.5px;
  text-align: center;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

/* ==========================================================================
   Cabeçalho de página
   ========================================================================== */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.2px;
  margin: 0 0 0.25rem;
  text-align: left;
}

.page-subtitle {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 13.5px;
}

.result-count { font-weight: 600; color: var(--ink); }

/* ==========================================================================
   Botões
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  line-height: 1.2;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover { text-decoration: none; }

.btn-primary { background: var(--primary); color: #FFF; }
.btn-primary:hover { background: var(--primary-dk); }

.btn-secondary {
  background: var(--surface);
  color: var(--ink-soft);
  border-color: var(--line);
}
.btn-secondary:hover { border-color: #C6CFE0; color: var(--ink); }

.btn-danger { background: var(--danger); color: #FFF; }
.btn-danger:hover { background: var(--danger-hover); }

.btn-success { background: var(--success); color: #FFF; }
.btn-success:hover { background: var(--success-hover); }

.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-bg); }

.btn-sm { padding: 6px 11px; font-size: 12.5px; }

.btn:disabled, .btn.disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

/* Botões de submit SEM classe .btn (form.as_p das páginas de cadastro).
   O :not(.btn) evita que esta regra sobrescreva .btn-secondary/.btn-danger
   nos botões de submit que já usam o sistema de botões. */
form button[type="submit"]:not(.btn) {
  background-color: var(--primary);
  color: #fff;
  border: none;
  padding: 0.65rem 1.4rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
form button[type="submit"]:not(.btn):hover {
  background-color: var(--primary-dk);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.75rem;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.toolbar-start { justify-content: flex-start; }

/* ==========================================================================
   Campos de formulário (globais — usados pelas páginas de cadastro)
   ========================================================================== */

label {
  display: block;
  margin-top: 1rem;
  margin-bottom: 0.35rem;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

label:first-of-type { margin-top: 0; }

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background-color: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder { color: var(--ink-faint); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(44, 85, 224, 0.14);
}

input[readonly] {
  color: var(--ink-soft);
  background-color: var(--surface-2);
  cursor: default;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  vertical-align: middle;
  cursor: pointer;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  margin-top: 1rem;
}

/* ==========================================================================
   Cartões, detalhe e formulários (páginas de cadastro/visualização)
   ========================================================================== */

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

.card + .card { margin-top: 1.5rem; }

.detail-card {
  max-width: 760px;
  margin: 0 auto;
}

.detail-card h3.form-section-title:first-of-type { margin-top: 1.5rem; }

.detail-card dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.6rem 1.25rem;
  margin: 0;
}

.detail-card dt { color: var(--ink-soft); font-weight: 500; }
.detail-card dd { margin: 0; color: var(--ink); }

.form-card {
  max-width: 560px;
  margin: 0 auto;
}

.form-card form p { margin: 0 0 1rem; }

.form-card ul.errorlist {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  color: var(--danger);
  font-size: 0.85rem;
}

.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.field-hint {
  color: var(--ink-faint);
  font-size: 0.82rem;
  margin: 0.4rem 0 0;
  line-height: 1.4;
}

.dependente-block {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background-color: var(--surface-2);
  padding: 1.1rem 1.25rem 1.25rem;
  margin-bottom: 1rem;
}

.dependente-block label:first-of-type { margin-top: 0; }
.dependente-block .btn-remove-dependente { margin-top: 1rem; }

#add-dependente-btn { margin-bottom: 0.5rem; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.cancel-link {
  display: block;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.9rem;
  text-align: center;
  margin-top: 1rem;
}

.cancel-link:hover {
  color: var(--ink);
  text-decoration: underline;
}

.form-section-title {
  font-size: 1rem;
  color: var(--ink);
  margin: 2rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}

.form-section-title:first-child { margin-top: 0; }

.field-with-spinner { position: relative; }

.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--primary);
  border-top: 2px solid transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  position: absolute;
  right: 0.75rem;
  top: 0.6rem;
}

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

.field-with-action {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.field-with-action input {
  flex: 1;
  min-width: 0;
}

.field-with-action .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* ==========================================================================
   Barra de busca + painel de filtros (lista de clientes)
   ========================================================================== */

.toolbar-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}

.search-bar {
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  margin: 0;
}

.search-field {
  flex: 1;
  position: relative;
  min-width: 200px;
}

.search-field svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-faint);
  pointer-events: none;
}

.search-field input {
  width: 100%;
  padding-left: 36px;
}

.filter-panel {
  display: none;
  margin: 0;
  padding: 16px;
  border-top: 1px dashed var(--line);
  background: var(--surface-2);
}

.filter-panel.open { display: block; }

.filter-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px 14px;
  margin-bottom: 14px;
}

.filter-fields label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-fields select,
.filter-fields input { width: 100%; }

.filter-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ==========================================================================
   Ações em lote
   ========================================================================== */

.lote-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.lote-toolbar span {
  color: var(--ink-soft);
  font-size: 13px;
}

.lote-count { font-size: 13px; color: var(--ink-soft); }
.lote-count strong { color: var(--ink); font-weight: 700; }

.lote-todos-filtrados {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}

.lote-todos-filtrados input { width: auto; accent-color: var(--primary); }

.lote-spacer { flex: 1; }

.lote-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.lote-actions[hidden] { display: none; }

/* ==========================================================================
   Tabelas
   ========================================================================== */

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

/* Quando a tabela vem logo após a barra de lote, elas se emendam */
.lote-toolbar + .table-wrap {
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--surface);
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  padding: 11px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--ink-soft);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-subtle);
  vertical-align: middle;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover { background-color: var(--surface-2); }

tr.clickable-row { cursor: pointer; transition: background 0.12s; }
tr.clickable-row:hover { background: var(--primary-bg); }

.select-col { width: 40px; text-align: center; }
.select-col input { width: 16px; height: 16px; }

/* Célula do cliente: avatar com iniciais + nome + doc/e-mail */
.cliente-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
}

.cliente-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-bg);
  color: var(--primary-dk);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.cliente-nome { font-weight: 600; color: var(--ink); }
.cliente-doc {
  font-size: 12px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.cliente-dependente-match {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.valor {
  font-family: var(--font-display);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}

td.muted { color: var(--ink-faint); }

td.empty-state, th.empty-state {
  text-align: center;
  padding: 48px 16px !important;
  color: var(--ink-faint);
  white-space: normal;
}

.empty-state strong {
  display: block;
  color: var(--ink-soft);
  font-size: 15px;
  margin-bottom: 4px;
}

.row-actions a {
  color: var(--ink-soft);
  text-decoration: none;
  margin-right: 0.5rem;
}
.row-actions a:hover { color: var(--primary); }

/* ==========================================================================
   Badges de status
   Nomes JÁ USADOS no projeto (is-active, status-aguardando...) + sinônimos
   ========================================================================== */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--muted-bg);
  color: var(--muted-fg);
}

.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Nomes usados pelo projeto (status_css_class) */
.status-badge.is-active,
.status-badge.status-implantado { background: var(--ok-bg);    color: var(--ok-fg); }
.status-badge.status-aguardando { background: var(--warn-bg);  color: var(--warn-fg); }
.status-badge.status-declinada  { background: var(--bad-bg);   color: var(--bad-fg); }
.status-badge.is-inactive,
.status-badge.status-desistencia{ background: var(--muted-bg); color: var(--muted-fg); }

/* Sinônimos genéricos (compatibilidade com templates novos) */
.status-badge.status-ativo      { background: var(--ok-bg);    color: var(--ok-fg); }
.status-badge.status-pendente   { background: var(--warn-bg);  color: var(--warn-fg); }
.status-badge.status-cancelado  { background: var(--bad-bg);   color: var(--bad-fg); }
.status-badge.status-inativo    { background: var(--muted-bg); color: var(--muted-fg); }

/* Indicador de visualização (bolinha abaixo do status de assinatura):
   verde quando o cliente já abriu/assinou/recusou o documento, vermelho
   enquanto ainda não abriu (ver AssinaturaZapSign.visualizado). A bolinha
   só reflete o que já foi consultado na ZapSign — ver management command
   consultar_assinaturas_pendentes. */
.indicador-visualizacao {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.indicador-visualizacao::before {
  content: "";
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bad-fg);
}
.indicador-visualizacao.visto::before {
  background: var(--ok-fg);
}

/* ==========================================================================
   Utilitários de texto
   ========================================================================== */

.text-muted { color: var(--ink-soft); }
.text-danger { color: var(--danger); }
.text-pre-line { white-space: pre-line; }

.total-geral {
  font-size: 1.1rem;
  margin-top: 1.25rem;
  color: var(--ok-fg);
  text-align: right;
  font-weight: 600;
}

/* ==========================================================================
   Paginação
   ========================================================================== */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.pagination a,
.pagination .current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 7px 11px;
  text-align: center;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.pagination a {
  color: var(--ink-soft);
  border: 1px solid var(--line);
  background: var(--surface);
}

.pagination a:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}

.pagination .current {
  background: var(--primary);
  color: #FFF;
  border: 1px solid var(--primary);
}

/* ==========================================================================
   Confirmação de exclusão
   ========================================================================== */

.confirm-card {
  max-width: 480px;
  margin: 3rem auto;
  text-align: center;
}

.confirm-card h2 { color: var(--danger); }

.confirm-card p {
  color: var(--ink-soft);
  margin-bottom: 1.75rem;
}

.confirm-card form {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

/* ==========================================================================
   Mensagens (django.contrib.messages)
   ========================================================================== */

.messages {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 13.5px;
  font-weight: 500;
}

.message-success { background: var(--ok-bg);      color: var(--ok-fg);      border-color: #BCE6D3; }
.message-warning { background: var(--warn-bg);    color: var(--warn-fg);    border-color: #F3DCAE; }
.message-error   { background: var(--bad-bg);     color: var(--bad-fg);     border-color: #F3C2C5; }
.message-info    { background: var(--primary-bg); color: var(--primary-dk); border-color: #C8D6FA; }

/* ==========================================================================
   Documentos do cliente
   ========================================================================== */

.documento-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--line-subtle);
  flex-wrap: wrap;
}

.documento-row:last-child { border-bottom: none; }

.documento-info {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.documento-nome {
  font-weight: 600;
  color: var(--ink);
}

.documento-meta {
  font-size: 0.8rem;
  color: var(--ink-faint);
}

.documento-acoes {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.documento-acoes form {
  display: inline-flex;
  margin: 0;
}

.documento-gerar { position: relative; }

.documento-gerar summary {
  list-style: none;
  user-select: none;
}

.documento-gerar summary::-webkit-details-marker,
.documento-gerar summary::marker {
  display: none;
  content: "";
}

.documento-gerar[open] summary {
  border-color: var(--primary);
  color: var(--ink);
}

.documento-gerar form {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 20;
  margin: 0;
  padding: 0.5rem;
  background-color: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.pix-info {
  background-color: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  margin-bottom: 0.5rem;
}

.pix-info dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  margin: 0;
}

.pix-info dt {
  font-weight: 600;
  color: var(--ink-faint);
}

.pix-info dd {
  margin: 0;
  color: var(--ink);
}

.comprovante-upload-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.9rem 0;
}

/* ==========================================================================
   Dashboard
   ========================================================================== */

.dashboard-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.periodo-switch {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.periodo-switch a {
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
}
.periodo-switch a:hover { color: var(--ink); text-decoration: none; }
.periodo-switch a.active { background: var(--primary); color: #FFF; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}

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

.kpi-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.kpi-label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }

.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  background: var(--primary-bg);
  color: var(--primary);
  flex-shrink: 0;
}
.kpi-icon.is-ok    { background: var(--ok-bg);   color: var(--ok-fg); }
.kpi-icon.is-warn  { background: var(--warn-bg); color: var(--warn-fg); }
.kpi-icon.is-amber { background: #FDF1DA; color: #935A00; }

.kpi-value {
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.4px;
}

.kpi-delta { font-size: 12px; margin-top: 6px; font-weight: 600; }
.kpi-delta.is-up   { color: var(--ok-fg); }
.kpi-delta.is-down { color: var(--bad-fg); }
.kpi-delta .kpi-delta-sufixo { color: var(--ink-faint); font-weight: 400; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  align-items: start;
}

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

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

.dashboard-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 2px;
}

.dashboard-card-subtitle {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 16px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 180px;
  border-bottom: 1px solid var(--line-subtle);
}

.bar-chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  height: 100%;
}

.bar-chart-value { font-size: 12px; font-weight: 700; color: var(--ink-soft); }

.bar-chart-bar {
  width: 100%;
  max-width: 42px;
  background: var(--primary);
  border-radius: 6px 6px 2px 2px;
  transform-origin: bottom;
}

.bar-chart-labels {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.bar-chart-labels span {
  flex: 1;
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-faint);
  font-weight: 600;
}

.rank-list { display: flex; flex-direction: column; gap: 14px; }

.rank-row-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.rank-row-nome { font-weight: 600; color: var(--ink); }
.rank-row-valor { color: var(--ink-soft); font-weight: 600; }

.rank-bar-track {
  height: 7px;
  background: var(--line-subtle);
  border-radius: 99px;
  overflow: hidden;
}
.rank-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
}

.vendedor-rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-subtle);
}
.vendedor-rank-row:last-child { border-bottom: none; }

.vendedor-rank-pos {
  width: 20px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-faint);
  flex-shrink: 0;
}
.vendedor-rank-row:nth-child(1) .vendedor-rank-pos { color: #d97706; }
.vendedor-rank-row:nth-child(2) .vendedor-rank-pos { color: var(--ink-soft); }
.vendedor-rank-row:nth-child(3) .vendedor-rank-pos { color: #b45309; }

.vendedor-rank-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-bg);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12.5px;
  flex-shrink: 0;
}

.vendedor-rank-nome {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vendedor-rank-receita { font-size: 11.5px; color: var(--ink-faint); }
.vendedor-rank-vidas { font-size: 14px; font-weight: 800; color: var(--ink); }

.dashboard-empty { color: var(--ink-faint); font-size: 13px; padding: 24px 0; text-align: center; }

/* ==========================================================================
   Responsivo
   ========================================================================== */

@media (max-width: 900px) {
  .app { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    padding-right: 8px;
  }

  .brand { border-bottom: none; padding: 14px 16px; }

  .sidebar-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px;
    overflow-x: auto;
  }

  .nav-group { display: flex; gap: 4px; }
  .nav-group + .nav-group { margin: 0; }
  .nav-group-label, .nav-sub { display: none; }
  .nav-link.active::before { display: none; }
  .nav-link.active { box-shadow: inset 0 -2px 0 var(--amber); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }

  /* Avatar + Sair continuam acessíveis no mobile, de forma compacta */
  .sidebar-footer {
    padding: 8px 12px;
    border-top: none;
    margin-left: auto;
  }
  .sidebar-footer .user-name { display: none; }

  .avatar-modal { max-width: calc(100% - 2rem); }

  .main { padding: 18px 14px 32px; }
  .app-footer { padding: 14px; }

  .search-bar { flex-wrap: wrap; }
  .lote-actions { width: 100%; }
  .lote-actions .btn { flex: 1; justify-content: center; }

  .detail-card dl { grid-template-columns: 1fr; gap: 0.2rem 0; }
  .detail-card dt { margin-top: 0.6rem; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .nav-link, .clickable-row, .btn { transition: none; }
}