/* Layout plataforma — complementa Bootstrap */
:root {
  /* Aberto: mais estreito. Recolhido: largo o suficiente para o avatar (4rem) + padding lateral */
  --app-sidebar-w: 14.25rem;
  --app-sidebar-w-icons: 5.75rem;
  --app-topbar-h: 3.5rem;
  --app-bg: #f1f5f9;
  /* Sidebar: azul bem escuro (distinto do azul primário claro do restante) */
  --app-sidebar-bg: #020b18;
  --app-sidebar-logo-bg: #0c2747;
  --app-sidebar-border: rgba(255, 255, 255, 0.1);
  --app-sidebar-text: #ffffff;
  --app-sidebar-hover: rgba(255, 255, 255, 0.1);
  --app-sidebar-active-bg: rgba(255, 255, 255, 0.12);
  --app-sidebar-active-border: #ffffff;
}

body.app-body {
  background-color: var(--app-bg);
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100%;
}

#appShell.app-shell {
  max-width: 100%;
  min-width: 0;
}

nav.app-sidebar {
  background-color: var(--app-sidebar-bg);
  color: var(--app-sidebar-text);
  border-bottom: 1px solid var(--app-sidebar-border);
}

@media (min-width: 992px) {
  nav.app-sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    width: var(--app-sidebar-w);
    max-width: 100%;
    border-right: 1px solid var(--app-sidebar-border);
    border-bottom: none;
    flex-shrink: 0;
    transition: width 0.2s ease;
  }

  .app-shell.sidebar-collapsed nav.app-sidebar {
    width: var(--app-sidebar-w-icons);
  }

  .app-shell.sidebar-collapsed .sidebar-user-name,
  .app-shell.sidebar-collapsed .sidebar-link-text,
  .app-shell.sidebar-collapsed .sidebar-footer-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .app-shell.sidebar-collapsed .sidebar-inner {
    padding-left: 0.65rem !important;
    padding-right: 0.65rem !important;
  }

  .app-shell.sidebar-collapsed .sidebar-user {
    margin-bottom: 1rem !important;
  }

  .app-shell.sidebar-collapsed .app-sidebar .nav-link {
    justify-content: center;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  .app-shell.sidebar-collapsed .app-sidebar .nav-link.active {
    border-left: none;
    padding-left: 0.65rem;
  }

  .app-shell.sidebar-collapsed .sidebar-footer-account .sidebar-footer-link {
    justify-content: center;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .app-shell.sidebar-collapsed .sidebar-footer-account form .sidebar-footer-link {
    justify-content: center;
  }
}

.sidebar-inner {
  min-height: 0;
}

.app-sidebar-user-trigger {
  cursor: pointer;
  line-height: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.app-sidebar-user-trigger:hover .app-sidebar-user-avatar {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.app-sidebar-user-trigger:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}

@media (min-width: 992px) {
  .app-sidebar-user-trigger:active {
    transform: scale(0.96);
  }
}

.app-sidebar-user-avatar {
  width: 4rem;
  height: 4rem;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  background: linear-gradient(145deg, var(--app-sidebar-logo-bg), #1e4976);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: box-shadow 0.15s ease;
  pointer-events: none;
}

.sidebar-user-name {
  max-width: 100%;
}

.sidebar-footer-account .sidebar-footer-link {
  transition: background-color 0.15s ease;
}

.sidebar-footer-account .sidebar-footer-link:hover {
  background: var(--app-sidebar-hover);
  color: #fff !important;
}

.sidebar-footer-account .sidebar-footer-link.text-danger:hover {
  background: rgba(220, 38, 38, 0.2);
  color: #fecaca !important;
}

.sidebar-footer-account button.sidebar-footer-link {
  background: transparent;
}

/* .nav-pills do Bootstrap aplica cor do tema — manter texto branco na sidebar */
.app-sidebar .nav-pills .nav-link {
  color: #ffffff !important;
  background-color: transparent !important;
}

.app-sidebar .nav-link {
  color: var(--app-sidebar-text) !important;
  border-radius: 0.5rem;
  padding: 0.6rem 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.app-sidebar .nav-link .bi {
  flex-shrink: 0;
  color: #ffffff;
}

.app-sidebar .nav-link:hover,
.app-sidebar .nav-link:focus {
  color: #ffffff;
  background: var(--app-sidebar-hover);
}

.app-sidebar .nav-link:hover .bi,
.app-sidebar .nav-link:focus .bi {
  color: #ffffff;
}

.app-sidebar .nav-pills .nav-link.active,
.app-sidebar .nav-link.active {
  color: #ffffff !important;
  background: var(--app-sidebar-active-bg) !important;
  border-left: 3px solid var(--app-sidebar-active-border);
  padding-left: calc(0.85rem - 3px);
  font-weight: 600;
}

.app-sidebar .nav-link.active .bi {
  color: #ffffff;
}

.app-sidebar .nav-link:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.app-brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.1rem;
}

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

.app-topbar {
  min-height: var(--app-topbar-h);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
}

.app-content {
  padding: 1.5rem;
  max-width: 100%;
  min-width: 0;
}

@media (min-width: 992px) {
  .app-content {
    padding: 1.75rem 2rem;
  }
}

.app-search .form-control {
  background: #f8fafc;
  border-color: #e2e8f0;
  max-width: 22rem;
}

.app-search .form-control:focus {
  background: #fff;
  border-color: #cbd5e1;
  box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.15);
}

.app-user-avatar {
  width: 2.25rem;
  height: 2.25rem;
  font-size: 0.85rem;
}

/* HTMX: indicadores de requisição */
.htmx-indicator {
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.htmx-indicator.htmx-request {
  opacity: 1;
}

/*
 * Botões padrão da plataforma: formato pill, primário azul, secundário branco.
 * Use sempre: btn btn-app btn-app-primary | btn-app-secondary | btn-app-danger (+ btn-sm quando menor).
 */
:root {
  --app-btn-pill-radius: 50rem;
  --app-btn-blue: #2563eb;
  --app-btn-blue-hover: #1d4ed8;
  --app-btn-blue-active: #1e40af;
  --app-btn-shadow-primary: 0 1px 3px rgba(37, 99, 235, 0.35);
  --app-btn-shadow-secondary: 0 1px 3px rgba(15, 23, 42, 0.08);
  --app-btn-shadow-secondary-hover: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.btn-app {
  border-radius: var(--app-btn-pill-radius) !important;
  font-weight: 700 !important;
  letter-spacing: -0.02em;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.35rem;
  line-height: 1.2;
  border: none;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease, transform 0.08s ease,
    border-color 0.15s ease;
}

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

.btn-app:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-app:disabled,
.btn-app.disabled {
  opacity: 0.55;
  pointer-events: none;
}

.btn-app.btn-sm,
.btn-app-sm {
  padding: 0.4rem 1rem !important;
  font-size: 0.875rem !important;
  gap: 0.4rem !important;
}

/* Primário: fundo azul, texto branco, ícone à esquerda do texto */
.btn-app-primary {
  background-color: var(--app-btn-blue) !important;
  color: #fff !important;
  box-shadow: var(--app-btn-shadow-primary);
  border: none !important;
}

.btn-app-primary:hover,
.btn-app-primary:focus {
  background-color: var(--app-btn-blue-hover) !important;
  color: #fff !important;
}

.btn-app-primary:active {
  background-color: var(--app-btn-blue-active) !important;
}

/* Secundário: branco, texto escuro, sombra leve */
.btn-app-secondary {
  background-color: #fff !important;
  color: #111827 !important;
  border: 1px solid rgba(15, 23, 42, 0.08) !important;
  box-shadow: var(--app-btn-shadow-secondary);
}

.btn-app-secondary:hover,
.btn-app-secondary:focus {
  background-color: #f8fafc !important;
  color: #111827 !important;
  box-shadow: var(--app-btn-shadow-secondary-hover);
}

/* Perigo (exclusão) */
.btn-app-danger {
  background-color: #dc2626 !important;
  color: #fff !important;
  box-shadow: 0 1px 3px rgba(220, 38, 38, 0.35);
  border: none !important;
}

.btn-app-danger:hover,
.btn-app-danger:focus {
  background-color: #b91c1c !important;
  color: #fff !important;
}

/* Sidebar escura: variante clara sobre azul */
.btn-app-sidebar {
  background-color: rgba(255, 255, 255, 0.1) !important;
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
  box-shadow: none;
}

.btn-app-sidebar:hover,
.btn-app-sidebar:focus {
  background-color: rgba(255, 255, 255, 0.16) !important;
  color: #fff !important;
}

/* Compat: código antigo que ainda usa só btn-rounded */
.btn-rounded:not(.btn-app) {
  border-radius: var(--app-btn-pill-radius) !important;
}

/* Skeleton (Bootstrap placeholder) */
.placeholder-glow .placeholder {
  min-height: 1em;
}

/* Modal de formulário (membros e similares): labels fortes, inputs destacados do fundo */
.app-modal-form__label,
.app-modal-form .form-label {
  font-weight: 700 !important;
  color: #0f172a !important;
  font-size: 0.8125rem;
  letter-spacing: 0.01em;
}

.app-modal-form .form-control,
.app-modal-form .form-select,
.app-modal-form input[type='file'].form-control {
  background-color: #ffffff !important;
  border: 1px solid #94a3b8 !important;
  color: #0f172a;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.07);
}

.app-modal-form .form-control::placeholder {
  color: #64748b;
  opacity: 1;
}

.app-modal-form .form-control:focus,
.app-modal-form .form-select:focus {
  background-color: #ffffff !important;
  border-color: var(--app-btn-blue) !important;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05), 0 0 0 0.2rem rgba(37, 99, 235, 0.2) !important;
  color: #0f172a;
}

.app-modal-form .form-text {
  color: #64748b !important;
  font-size: 0.8rem;
}

.app-modal-form .form-check-input:checked {
  background-color: var(--app-btn-blue);
  border-color: var(--app-btn-blue);
}

.app-modal-form__input-one-line {
  min-height: 2.5rem;
  resize: none;
  overflow: hidden;
  line-height: 1.4;
}

.autocomplete-dropdown {
  max-height: 14rem;
  overflow-y: auto;
}

/* Modal edição de seções (membro): título e rodapé fixos; só o corpo rola */
#app-modal-dialog.modal-dialog-scrollable
  #app-modal-content:has(> .membro-secao-modal-shell) {
  display: flex;
  flex-direction: column;
  max-height: 100%;
  overflow: hidden;
  min-height: 0;
}

.membro-secao-modal-shell {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  max-height: 100%;
}

.membro-secao-modal-shell form.membro-secao-form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.membro-secao-modal-shell form.membro-secao-form > .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* Modal “Novo membro”: um pouco mais largo que .modal-sm (~300px) */
#app-modal-dialog.app-modal-dialog--novo {
  max-width: min(26.5rem, calc(100% - 2rem));
}

/* Toasts — canto inferior direito */
#app-toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 1090;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-end;
  max-width: min(22rem, calc(100vw - 2rem));
  pointer-events: none;
}

#app-toast-container .app-toast {
  pointer-events: auto;
  width: 100%;
  border-radius: 0.65rem;
  opacity: 0;
  transform: translateX(0.75rem);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.app-toast--show {
  opacity: 1 !important;
  transform: translateX(0) !important;
}

.app-toast--leave {
  opacity: 0 !important;
  transform: translateX(0.5rem) !important;
}

.app-toast__inner {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.75rem 0.75rem 0.75rem 1rem;
}

.app-toast__body {
  flex: 1;
  min-width: 0;
  font-size: 0.875rem;
  line-height: 1.4;
  padding-top: 0.1rem;
}

.app-toast__icon {
  font-size: 1.1rem;
  margin-top: 0.05rem;
}

.app-toast__close {
  flex-shrink: 0;
  opacity: 0.55;
  padding: 0.35rem;
  font-size: 0.65rem;
}

.app-toast__close:hover {
  opacity: 1;
}

.app-toast--success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.app-toast--success .app-toast__icon {
  color: #059669;
}

.app-toast--danger {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.app-toast--danger .app-toast__icon {
  color: #dc2626;
}

.app-toast--warning {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

.app-toast--warning .app-toast__icon {
  color: #d97706;
}

.app-toast--info {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.app-toast--info .app-toast__icon {
  color: #2563eb;
}

/* ClearableFileInput: evita nome/path longo estourar o layout */
.app-file-input-initial-row {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
  max-width: 100%;
}

.app-file-input-initial-prefix {
  flex-shrink: 0;
}

.app-file-input-current-link {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Página de login (fora do shell principal) */
body.auth-login-body {
  background: linear-gradient(165deg, var(--app-sidebar-bg) 0%, var(--app-sidebar-logo-bg) 38%, var(--app-bg) 38%);
}

.auth-login-card {
  max-width: 26rem;
  border-radius: 1rem;
}
