/* HTML e Body - altura mínima para viewport */
html {
  height: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Landing page - html sem scroll vertical, apenas body com scroll */
html.website-page-html {
  overflow-y: hidden !important;
  height: 100%;
}

body.website-page {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  height: 100vh;
  max-height: 100vh;
}

body.website-page main {
  overflow: visible !important;
  flex: 1;
  width: 100%;
}

body.website-page main > * {
  overflow: visible !important;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.dark ::-webkit-scrollbar-track {
  background: #1f2937;
}

::-webkit-scrollbar-thumb {
  background: #16a34a;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #15803d;
}

.dark ::-webkit-scrollbar-thumb {
  background: #22c55e;
}

.dark ::-webkit-scrollbar-thumb:hover {
  background: #16a34a;
}

/* Inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
textarea,
select {
  @apply w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg;
  @apply bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100;
  @apply focus:ring-2 focus:ring-primary-500 focus:border-transparent;
  @apply transition-colors;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
}

/* Selects */
select option {
  @apply bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100;
}

/* Tables */
table {
  @apply w-full;
}

thead {
  @apply bg-gray-50 dark:bg-gray-900;
}

th {
  @apply px-4 sm:px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider;
}

td {
  @apply px-4 sm:px-6 py-4 text-sm text-gray-900 dark:text-gray-100;
}

tbody tr {
  @apply border-b border-gray-200 dark:border-gray-700;
  @apply hover:bg-gray-50 dark:hover:bg-gray-800/50;
  @apply transition-colors;
}

/* Cards */
.card {
  @apply bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700;
  @apply transition-colors;
}

/* Buttons */
.btn {
  @apply px-4 py-2 rounded-lg font-semibold transition-colors;
  @apply focus:outline-none focus:ring-2 focus:ring-offset-2;
}

.btn-primary {
  @apply bg-primary-600 text-white hover:bg-primary-700;
  @apply focus:ring-primary-500;
  @apply shadow-sm hover:shadow-md;
}

.btn-secondary {
  @apply bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300;
  @apply hover:bg-gray-300 dark:hover:bg-gray-600;
}

.btn-danger {
  @apply bg-red-600 text-white hover:bg-red-700;
  @apply focus:ring-red-500;
}

/* Badges */
.badge {
  @apply inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium;
}

.badge-success {
  @apply bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-300;
}

.badge-danger {
  @apply bg-red-100 dark:bg-red-900/30 text-red-800 dark:text-red-300;
}

.badge-warning {
  @apply bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-300;
}

.badge-info {
  @apply bg-blue-100 dark:bg-blue-900/30 text-blue-800 dark:text-blue-300;
}

.badge-gray {
  @apply bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-300;
}

/* Custom Dropdown - Estilos diretos para garantir funcionamento no dark theme */
.custom-dropdown {
  position: relative;
}

.custom-dropdown button {
  width: 100%;
  padding: 0.625rem 1rem;
  text-align: left;
  background-color: white;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.dark .custom-dropdown button {
  background-color: #374151;
  border-color: #4b5563;
}

.custom-dropdown button:hover {
  border-color: #9ca3af;
}

.dark .custom-dropdown button:hover {
  border-color: #6b7280;
}

.custom-dropdown button:focus {
  outline: none;
  ring: 2px;
  ring-color: #16a34a;
  border-color: #16a34a;
}

.custom-dropdown button span {
  color: #374151;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dark .custom-dropdown button span {
  color: #d1d5db;
}

.custom-dropdown button i.fa-chevron-down {
  color: #9ca3af;
  margin-left: 0.5rem;
  transition: transform 0.2s;
}

.dark .custom-dropdown button i.fa-chevron-down {
  color: #6b7280;
}

.custom-dropdown button i.fa-chevron-down.rotate-180 {
  transform: rotate(180deg);
}

/* Menu dropdown */
.custom-dropdown > div[id$="-menu"] {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  background-color: white;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  z-index: 50;
  max-height: 24rem;
  overflow: hidden;
}

.dark .custom-dropdown > div[id$="-menu"] {
  background-color: #1f2937;
  border-color: #4b5563;
}

.custom-dropdown > div[id$="-menu"]:not(.hidden) {
  display: block;
  animation: slideDown 0.2s ease-out;
}

/* Container de busca */
.custom-dropdown .p-3 {
  padding: 0.75rem;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  background-color: white;
  z-index: 10;
}

.dark .custom-dropdown .p-3 {
  border-bottom-color: #374151;
  background-color: #1f2937;
}

.custom-dropdown input[type="text"] {
  width: 100%;
  padding-left: 2.5rem;
  padding-right: 1rem;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  background-color: white;
  color: #111827;
  font-size: 0.875rem;
}

.dark .custom-dropdown input[type="text"] {
  border-color: #4b5563;
  background-color: #374151;
  color: #f3f4f6;
}

.custom-dropdown input[type="text"]:focus {
  outline: none;
  ring: 2px;
  ring-color: #16a34a;
  border-color: transparent;
}

.custom-dropdown .fa-search {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
}

.dark .custom-dropdown .fa-search {
  color: #6b7280;
}

/* Grupos */
.custom-dropdown .dropdown-group {
  border-bottom: 1px solid #e5e7eb;
}

.dark .custom-dropdown .dropdown-group {
  border-bottom-color: #374151;
}

.custom-dropdown .dropdown-group > div:first-child {
  padding: 0.5rem 1rem;
  background-color: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 10;
}

.dark .custom-dropdown .dropdown-group > div:first-child {
  background-color: rgba(55, 65, 81, 0.5);
  border-bottom-color: #374151;
}

.custom-dropdown .dropdown-group > div:first-child span {
  font-size: 0.75rem;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dark .custom-dropdown .dropdown-group > div:first-child span {
  color: #d1d5db;
}

/* Opções */
.custom-dropdown .dropdown-option {
  width: 100%;
  padding: 0.625rem 1rem;
  text-align: left;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: #111827;
  background-color: transparent;
}

.dark .custom-dropdown .dropdown-option {
  color: #f3f4f6;
}

.custom-dropdown .dropdown-option:hover {
  background-color: #f0fdf4;
  color: #15803d;
}

.dark .custom-dropdown .dropdown-option:hover {
  background-color: #374151;
  color: #4ade80;
}

.custom-dropdown .dropdown-option span {
  font-weight: 500;
  font-size: 0.875rem;
  color: #111827;
}

.dark .custom-dropdown .dropdown-option span {
  color: #f3f4f6;
}

.custom-dropdown .dropdown-option:hover span {
  color: #15803d;
}

.dark .custom-dropdown .dropdown-option:hover span {
  color: #4ade80;
}

.custom-dropdown .dropdown-option.bg-primary-50 {
  background-color: #f0fdf4;
  color: #15803d;
}

.dark .custom-dropdown .dropdown-option.bg-primary-50 {
  background-color: #374151;
  color: #4ade80;
}

.custom-dropdown .dropdown-option .fa-check {
  color: #16a34a;
  margin-left: 0.5rem;
}

.dark .custom-dropdown .dropdown-option .fa-check {
  color: #4ade80;
}

/* Sem resultados */
.custom-dropdown #no-results {
  padding: 2rem 1rem;
  text-align: center;
}

.custom-dropdown #no-results i {
  color: #d1d5db;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.dark .custom-dropdown #no-results i {
  color: #4b5563;
}

.custom-dropdown #no-results p {
  font-size: 0.875rem;
  color: #6b7280;
}

.dark .custom-dropdown #no-results p {
  color: #9ca3af;
}

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

/* Smooth transitions */
* {
  transition-property: background-color, border-color, color, fill, stroke;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  transition-duration: 150ms;
}

/* Container principal - altura fixa sem scroll (apenas para admin panel) */
body:not(.website-page) .flex.flex-col.pt-16 {
  height: calc(100vh - 4rem); /* viewport - header (altura fixa) */
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Evita scroll no container principal */
}

/* Container do conteúdo (sidebar + main) - altura para sidebar se estender (apenas para admin panel) */
body:not(.website-page) .flex.flex-col.pt-16 > .flex.flex-1 {
  flex: 1;
  display: flex;
  align-items: stretch;
  min-height: 0;
}

/* Main content - scroll apenas quando necessário (apenas para admin panel) */
body:not(.website-page) .flex.flex-col.pt-16 > .flex.flex-1 > main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0; /* Permite scroll quando necessário */
}

/* Sidebar se estende até o rodapé (apenas para admin panel) */
@media (min-width: 1024px) {
  body:not(.website-page) aside#sidebar {
    align-self: stretch;
    height: 100%; /* Altura 100% do container pai */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Evita scroll no sidebar */
  }
  
  /* Scroll apenas no nav interno quando necessário */
  body:not(.website-page) aside#sidebar > nav {
    flex: 1;
    overflow-y: auto; /* Scroll apenas quando menu ultrapassar */
    overflow-x: hidden;
    min-height: 0;
  }
}

/* Footer sempre visível no final */
footer {
  flex-shrink: 0;
  margin-top: auto;
}
