/* =========================================================
   Agenda de Contatos Estratégicos — Estilos customizados
   Complementa Tailwind CDN
   ========================================================= */

/* =========================================================
   Tipografia — Google Fonts
   ========================================================= */

/* Body: Source Sans 3 para todo o texto geral */
body {
  font-family: 'Source Sans 3', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Headings: Montserrat para títulos e elementos de destaque */
h1, h2, h3, h4, h5, h6,
.font-heading {
  font-family: 'Montserrat', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Scroll suave */
html {
  scroll-behavior: smooth;
}

/* Esconder scrollbar em Chrome/Safari mas manter funcionalidade */
.hide-scrollbar::-webkit-scrollbar {
  display: none;
}
.hide-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Transição suave de opacidade para toasts */
#toasts > div {
  transition: opacity 0.35s ease;
  pointer-events: auto;
}

/* Badge hover */
.badge-hover:hover {
  filter: brightness(0.95);
  cursor: pointer;
}

/* Input focus ring customizado */
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Transição suave no foco */
input,
select,
textarea {
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Botão ativo nav */
[data-nav].active {
  color: #0f172a;
}

/* Card hover sutil */
.card-hover {
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.card-hover:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

/* Loading spinner */
.spinner {
  border: 3px solid #e2e8f0;
  border-top: 3px solid #0f172a;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Share popup */
.share-popup {
  animation: sharePopupIn 0.15s ease-out;
}

@keyframes sharePopupIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.share-btn:hover {
  transform: scale(1.1);
}

/* Avatar circular */
.contact-avatar {
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.contact-avatar-placeholder {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Upload de foto no formulário */
.photo-upload-area {
  position: relative;
  cursor: pointer;
  display: inline-block;
}

.photo-upload-area:hover .photo-upload-overlay {
  opacity: 1;
}

.photo-upload-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* =========================================================
   Image Crop Modal
   ========================================================= */

.crop-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: cropFadeIn 0.2s ease-out;
}

@keyframes cropFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.crop-viewport {
  position: relative;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.8);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.crop-viewport:active {
  cursor: grabbing;
}

.crop-viewport img {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  pointer-events: none;
  -webkit-user-drag: none;
  max-width: none;
}

.crop-instruction {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.8rem;
  margin-top: 1rem;
  text-align: center;
}

.crop-zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  outline: none;
  margin-top: 1rem;
}

.crop-zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.crop-zoom-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.crop-buttons {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.crop-btn {
  padding: 0.6rem 1.5rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s;
}

.crop-btn:hover { opacity: 0.85; }

.crop-btn-confirm {
  background: #0f172a;
  color: white;
}

.crop-btn-cancel {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

@media (max-width: 360px) {
  .crop-viewport {
    width: 240px;
    height: 240px;
  }
}

/* =========================================================
   Login Page
   ========================================================= */

.login-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1rem;
  padding: 2rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.login-card input:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

/* =========================================================
   User Dropdown
   ========================================================= */

.user-dropdown {
  animation: dropdownIn 0.15s ease-out;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   Admin Tables
   ========================================================= */

.admin-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.admin-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  color: #64748b;
  padding: 0.625rem 0.75rem;
  border-bottom: 2px solid #e2e8f0;
  background: #f8fafc;
}

.admin-table th:first-child { border-radius: 0.5rem 0 0 0; }
.admin-table th:last-child  { border-radius: 0 0.5rem 0 0; }

.admin-table td {
  padding: 0.75rem;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.875rem;
  vertical-align: middle;
  transition: background 0.15s ease;
}

.admin-table tbody tr:hover td {
  background: #f1f5f9;
}

.admin-table tbody tr {
  transition: background 0.15s ease;
}

/* Permission checkbox grid */
.perm-group {
  margin-bottom: 1rem;
}

.perm-group-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #475569;
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.25rem;
}

.perm-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-size: 0.8rem;
  color: #334155;
}

.perm-item input[type="checkbox"] {
  accent-color: #3b82f6;
}

/* =========================================================
   Mobile Bottom Navigation
   ========================================================= */

.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.06);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 6px 0 4px;
  font-size: 0.65rem;
  color: #94a3b8;
  text-decoration: none;
  transition: color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  border: none;
  background: none;
  cursor: pointer;
}

.mobile-nav-item.active {
  color: #0f172a;
}

.mobile-nav-item:hover {
  color: #475569;
}

.mobile-nav-icon {
  font-size: 1.25rem;
  line-height: 1;
  margin-bottom: 2px;
}

.mobile-nav-label {
  font-weight: 500;
  line-height: 1;
}

/* =========================================================
   Mobile "More" Bottom Sheet
   ========================================================= */

.mobile-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.mobile-sheet-overlay.hidden {
  display: none;
}

.mobile-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.mobile-sheet-overlay.open .mobile-sheet-backdrop {
  opacity: 1;
}

.mobile-sheet-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-radius: 1rem 1rem 0 0;
  padding: 0.5rem 1rem 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
}

.mobile-sheet-overlay.open .mobile-sheet-content {
  transform: translateY(0);
}

.mobile-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #cbd5e1;
  margin: 0 auto 0.75rem;
}

.mobile-sheet-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
  color: #475569;
  text-decoration: none;
  transition: background 0.15s ease;
}

.mobile-sheet-item:hover,
.mobile-sheet-item:active {
  background: #f1f5f9;
}

.mobile-sheet-item.active {
  color: #0f172a;
  background: #f1f5f9;
  font-weight: 600;
}

/* =========================================================
   Mobile UX — Touch Targets, Tipografia, Espaçamentos
   ========================================================= */

/* Todos os inputs/selects/textareas mais altos no mobile */
@media (max-width: 640px) {
  .nav-fixed {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .login-card {
    padding: 1.5rem;
  }

  /* Inputs e selects — mínimo 2.75rem (44px) de altura */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="date"],
  input[type="number"],
  input[type="search"],
  input[type="url"],
  select,
  textarea {
    min-height: 2.75rem;
    font-size: 1rem; /* 16px evita zoom no iOS */
  }

  /* Botões — mínimo 2.75rem de altura */
  button, .btn, [role="button"] {
    min-height: 2.75rem;
  }

  /* Checkboxes e radios maiores */
  input[type="checkbox"],
  input[type="radio"] {
    width: 1.25rem;
    height: 1.25rem;
    min-width: 1.25rem;
  }

  /* Details/Summary touch-friendly */
  summary {
    min-height: 2.75rem;
    display: flex;
    align-items: center;
  }

  /* Admin table — melhor legibilidade mobile */
  .admin-table td {
    padding: 0.625rem 0.5rem;
    font-size: 0.8125rem;
  }
  .admin-table th {
    padding: 0.5rem;
    font-size: 0.6875rem;
  }

  /* Permission grid — mais espaço para toque */
  .perm-item {
    padding: 0.5rem 0;
    font-size: 0.875rem;
    min-height: 2.5rem;
  }
  .perm-grid {
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
    gap: 0.125rem;
  }

  /* Crop modal zoom slider responsivo */
  .crop-zoom-slider {
    width: min(12.5rem, 70vw);
  }
}

/* =========================================================
   Bottom Nav — Melhor tamanho e legibilidade
   ========================================================= */

.mobile-bottom-nav {
  padding-top: 0.375rem;
  padding-bottom: calc(0.25rem + env(safe-area-inset-bottom));
}

.mobile-nav-item {
  padding: 0.5rem 0 0.375rem;
  font-size: 0.6875rem;
  min-height: 3.25rem;
}

.mobile-nav-icon {
  font-size: 1.375rem;
  margin-bottom: 0.125rem;
}

.mobile-nav-label {
  font-size: 0.625rem;
  letter-spacing: 0.01em;
}

/* =========================================================
   Contraste — textos secundários mais legíveis
   ========================================================= */

/* Override global: text-slate-400 em contextos pequenos -> mais contraste */
.text-slate-400 {
  color: #78859b; /* entre slate-400 (#94a3b8) e slate-500 (#64748b) — ratio ~4.6:1 */
}

/* =========================================================
   Touch-friendly action buttons
   ========================================================= */

/* Botões de ação em cards (editar/excluir/ver) — área mínima de toque */
@media (max-width: 640px) {
  [data-edit-emp],
  [data-del-emp],
  [data-view-emp],
  [data-edit-role],
  [data-del-role],
  [data-trash-restore],
  [data-trash-perm-del] {
    min-height: 2.25rem;
    min-width: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.375rem 0.625rem;
  }

  /* Share buttons */
  .share-btn {
    min-height: 2.5rem;
    min-width: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Mais espaço entre botões de ação */
  [data-edit-emp] + [data-del-emp],
  [data-view-emp] + [data-edit-emp] {
    margin-left: 0.25rem;
  }
}

/* =========================================================
   Toast — centralizado no mobile
   ========================================================= */
@media (max-width: 640px) {
  #toasts {
    left: 1rem !important;
    right: 1rem !important;
    max-width: none !important;
  }
  #toasts > div {
    max-width: none;
  }
}

/* =========================================================
   Desktop UX — Hover States, Animações, Transições
   ========================================================= */

/* Animação de entrada para modais (overlay fade + content scale) */
@keyframes modalOverlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modalContentIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-overlay {
  animation: modalOverlayIn 0.2s ease-out;
}

.modal-overlay > div:first-child,
.modal-overlay > .bg-white {
  animation: modalContentIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Cards genéricos com transições (empresas, cargos, lixeira, logs) */
.emp-card,
.role-card {
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.emp-card:hover,
.role-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

/* Botões primários — transição suave */
button, .btn, [role="button"] {
  transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

/* Botões primários — feedback tátil no click */
button:active:not(:disabled),
.btn:active:not(:disabled) {
  transform: scale(0.98);
}

/* Botões de ação em cards — hover glow */
[data-view-emp]:hover,
[data-edit-emp]:hover,
[data-edit-role]:hover {
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}

[data-del-emp]:hover,
[data-del-role]:hover,
[data-trash-perm-del]:hover {
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}

[data-trash-restore]:hover {
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.2);
}

/* Details/Summary — animação de abertura */
details[open] > summary {
  margin-bottom: 0;
}

details {
  transition: border-color 0.2s ease;
}

details[open] {
  border-color: #cbd5e1;
}

/* Autocomplete dropdown items — transição */
[data-ac-id],
[data-emp-ac] {
  transition: background-color 0.1s ease;
}

/* Links — transição suave de cor */
a {
  transition: color 0.15s ease;
}

/* Badges — hover elegante */
.inline-block.rounded-full {
  transition: filter 0.15s ease, transform 0.15s ease;
}

/* Config tabs — transição de cor mais suave */
[data-cfg-tab] {
  transition: color 0.2s ease, border-color 0.2s ease;
}

/* Cadastros tabs — transição de cor */
[data-tab] {
  transition: color 0.2s ease, border-color 0.2s ease;
}

/* Scrollbar customizada (desktop) */
@media (min-width: 641px) {
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
  }
}
