/* ==============================================================================
   🏛️ EXALT HUB — ESTILOS DE AUTENTICAÇÃO, CONTROLE DE ACESSO E ADMINISTRAÇÃO
   ============================================================================== */

:root {
  /* Tokens oficiais do DESIGN.md v2.1 */
  --color-primary: #2B3C32;
  --color-primary-hover: #1F2C25;
  --color-secondary: #7D3818;
  --color-secondary-hover: #642B10;
  --color-secondary-light: #B65627;
  --color-text-primary: #2B3C32;
  --color-text-muted: #537160;
  --color-text-inverse: #FFFFFF;
  --color-bg: #FAFAF9;
  --color-surface: #FFFFFF;
  --color-bg-subtle: #F0F3F0;
  --color-border-light: #DDE3DD;
  --color-border-control: #7D8D82;
  --color-focus: #7D3818;
  --color-selection: #E8EEE9;
  --color-error: #9E1B1B;
  --color-error-bg: #FBEFEE;
  --color-success: #2B593D;
  --color-success-bg: #EDF4EE;
  --color-warning: #77511B;
  --color-warning-bg: #FAF3E6;

  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --radius-sm: 4px;
  --radius-card: 4px;
  --radius-btn: 4px;
  --radius-pill: 999px;

  /* Aliases para compatibilidade de componentes internos */
  --exalt-green: var(--color-primary);
  --exalt-green-dark: var(--color-primary-hover);
  --exalt-green-light: var(--color-text-muted);
  --exalt-gold: var(--color-secondary);
  --exalt-gold-light: var(--color-secondary-light);
  --exalt-gold-dark: var(--color-secondary-hover);
  --exalt-cream: var(--color-bg);
  --exalt-text-dark: var(--color-text-primary);
  --exalt-text-muted: var(--color-text-muted);
  --exalt-border: var(--color-border-light);
  --exalt-danger: var(--color-error);
  --exalt-success: var(--color-success);
  --exalt-warning: var(--color-warning);
}

/* --- TELA DE LOGIN --- */
body.login-page {
  background-color: #1E2B24;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(43, 60, 50, 0.7) 0%, transparent 60%),
    radial-gradient(circle at 85% 85%, rgba(31, 44, 37, 0.85) 0%, transparent 60%);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  color: var(--color-text-primary);
  margin: 0;
  padding: clamp(1rem, 3vw, 2rem);
  box-sizing: border-box;
}

.login-shell {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  box-sizing: border-box;
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-decoration: none;
  margin-bottom: 0.25rem;
}

.login-brand img {
  height: 34px;
  width: auto;
  max-width: min(244px, 72vw);
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  padding: 2.25rem 2rem;
  box-shadow: 0 12px 32px rgba(43, 60, 50, 0.10);
  border: 1px solid var(--color-border-light);
  position: relative;
  box-sizing: border-box;
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color-primary);
  border-top-left-radius: var(--radius-card);
  border-top-right-radius: var(--radius-card);
}

.login-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.625rem;
  line-height: 1.25;
  color: var(--color-primary);
  margin: 0 0 0.5rem 0;
  letter-spacing: -0.015em;
}

.login-subtitle {
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  margin: 0;
}

.alert-container {
  min-height: 0;
  transition: min-height 0.2s ease;
}

.alert-box {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  line-height: 1.45;
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  margin-bottom: 1.25rem;
  box-sizing: border-box;
  animation: alertFadeIn 0.2s ease-out;
}

@keyframes alertFadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.alert-icon {
  flex-shrink: 0;
  margin-top: 2px;
}

.alert-content {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.alert-danger {
  background-color: var(--color-error-bg);
  border: 1px solid rgba(158, 27, 27, 0.25);
  color: var(--color-error);
}

.alert-success {
  background-color: var(--color-success-bg);
  border: 1px solid rgba(43, 89, 61, 0.25);
  color: var(--color-success);
}

.alert-retry-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: background-color 0.15s ease;
  margin-top: 0.25rem;
}

.alert-retry-btn:hover {
  background: rgba(158, 27, 27, 0.08);
}

.alert-retry-btn:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-label {
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-primary);
  text-transform: none;
  letter-spacing: normal;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.form-input {
  width: 100%;
  min-height: 44px;
  padding: 0.625rem 0.875rem;
  padding-right: 2.75rem;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.4;
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface);
  color: var(--color-text-primary);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  box-sizing: border-box;
}

.input-wrapper:not(:has(.input-toggle-btn)) .form-input {
  padding-right: 0.875rem;
}

.form-input::placeholder {
  color: #8C9990;
  opacity: 1;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-focus);
  box-shadow: 0 0 0 2px var(--color-focus);
}

.form-input:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-color: var(--color-focus);
  box-shadow: none;
}

.form-input[aria-invalid="true"] {
  border-color: var(--color-error);
  background-color: var(--color-error-bg);
}

.form-input[aria-invalid="true"]:focus-visible {
  outline-color: var(--color-error);
  border-color: var(--color-error);
}

.field-error-msg {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  color: var(--color-error);
  font-weight: 500;
  line-height: 1.35;
  margin-top: 0.25rem;
  animation: alertFadeIn 0.15s ease-out;
}

.input-toggle-btn {
  position: absolute;
  right: 0;
  top: 0;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease;
}

.input-toggle-btn:hover {
  color: var(--color-primary);
}

.input-toggle-btn:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: -2px;
}

.toggle-eye-icon {
  pointer-events: none;
}

.btn-primary {
  width: 100%;
  min-height: 44px;
  padding: 0.625rem 1.125rem;
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: normal;
  border: none;
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-primary:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 3px;
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn-spinner-content {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.spinner-icon {
  animation: spin 0.9s linear infinite;
}

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

.login-support {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--color-border-light);
  text-align: center;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.support-text {
  color: var(--color-text-muted);
}

.support-link {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}

.support-link:hover {
  color: var(--color-secondary);
  text-decoration: underline;
}

.support-link:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.dev-helper {
  margin-top: 0.75rem;
  text-align: center;
}

.dev-btn {
  background: transparent;
  border: 1px dashed var(--color-border-control);
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: 0.75rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.dev-btn:hover {
  background: var(--color-bg-subtle);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.dev-btn:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .alert-box,
  .field-error-msg,
  .spinner-icon,
  .btn-primary,
  .form-input {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 480px) {
  body.login-page {
    padding: 1rem;
  }

  .login-card {
    padding: 1.75rem 1.25rem;
  }

  .login-title {
    font-size: 1.45rem;
  }

  .form-input {
    font-size: 1rem;
  }
}

/* --- CABEÇALHO DO USUÁRIO NO HUB --- */
.user-menu-wrapper {
  position: relative;
  display: inline-block;
}

.user-profile-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #FFFFFF;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

.user-profile-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--exalt-gold);
  color: #1A1A1A;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
}

.user-dropdown {
  position: absolute;
  top: 110%;
  right: 0;
  width: 240px;
  background: #FFFFFF;
  border: 1px solid var(--exalt-border);
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.25);
  padding: 0.5rem 0;
  z-index: 1000;
  display: none;
}

.user-dropdown.show {
  display: block;
}

.user-dropdown-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--exalt-border);
}

.user-dropdown-name {
  font-weight: 700;
  color: var(--exalt-green);
  font-size: 0.9rem;
}

.user-dropdown-role {
  font-size: 0.75rem;
  color: var(--exalt-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  color: var(--exalt-text-dark);
  text-decoration: none;
  font-size: 0.875rem;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.user-dropdown-item:hover {
  background: #F3F4F6;
  color: var(--exalt-green);
}

.user-dropdown-item.logout {
  color: var(--exalt-danger);
  border-top: 1px solid var(--exalt-border);
}

.user-dropdown-item.logout:hover {
  background: #FEF2F2;
}

/* --- BADGES DE PAPEL E STATUS --- */
.badge-role {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: inline-block;
}

.badge-role-admin { background: #FEE2E2; color: #991B1B; }
.badge-role-gestor { background: #FEF3C7; color: #92400E; }
.badge-role-colaborador, .badge-role-corretor { background: #E0E7FF; color: #3730A3; }
.badge-role-leitor { background: #F3F4F6; color: #374151; }

.badge-status-ativo { background: #D1FAE5; color: #065F46; }
.badge-status-suspenso { background: #FEE2E2; color: #991B1B; }
.badge-status-pendente { background: #DBEAFE; color: #1E40AF; }
.badge-status-desativado { background: #F3F4F6; color: #6B7280; }

/* --- PAINEL ADMINISTRATIVO --- */
.admin-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  font-family: var(--font-body);
}

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

.admin-title {
  font-family: var(--font-display);
  font-size: 1.85rem;
  color: var(--exalt-green);
  margin: 0;
}

.admin-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--exalt-border);
}

.admin-tab-btn {
  padding: 0.75rem 1.25rem;
  background: none;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--exalt-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.admin-tab-btn.active {
  color: var(--exalt-green);
  border-bottom-color: var(--exalt-green);
}

.admin-table-container {
  background: #FFFFFF;
  border-radius: var(--radius-card);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--exalt-border);
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.admin-table th {
  background: #F9FAFB;
  padding: 0.85rem 1rem;
  font-weight: 700;
  color: var(--exalt-green-dark);
  border-bottom: 1px solid var(--exalt-border);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.admin-table td {
  padding: 1rem;
  border-bottom: 1px solid #F3F4F6;
  color: var(--exalt-text-dark);
}

.admin-table tr:hover {
  background-color: #F9FAFB;
}

.admin-actions-cell {
  display: flex;
  gap: 0.5rem;
}

.btn-icon {
  background: #F3F4F6;
  border: 1px solid #E5E7EB;
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  color: var(--exalt-text-dark);
  font-size: 0.8rem;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: #E5E7EB;
  color: var(--exalt-green);
}

.btn-icon.danger:hover {
  background: #FEE2E2;
  color: var(--exalt-danger);
  border-color: #FCA5A5;
}

/* Troca opcional de senha; dialog nativo mantém foco e suporta Escape. */
.password-dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  margin: auto;
  padding: 28px;
  border: 1px solid var(--border-color, #d5dbd7);
  border-radius: var(--radius-card, 4px);
  background: var(--bg-card, #fff);
  color: var(--text-primary, #24362b);
}
.password-dialog::backdrop { background: rgb(16 30 22 / 55%); }
.password-dialog h2 { margin: 0 0 12px; }
.password-dialog p { margin: 12px 0; line-height: 1.5; }
.password-dialog .form-label { display: block; margin: 16px 0 6px; }
.password-dialog .form-input { width: 100%; }
.password-dialog-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 20px; }
.password-dialog-actions button { width: auto; min-height: 44px; padding: 10px 16px; }
