/* ============================================
   DILIFLOW Custom Styles
   Usa tokens de tokens.css para consistência
   ============================================ */

/* Smooth sidebar transitions */
.sidebar-transition {
  transition: transform var(--df-transition-slow), width var(--df-transition-slow);
}

/* Prevent pull-to-refresh on PWA */
body {
  overscroll-behavior-y: contain;
  font-family: var(--df-font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Headings use display font */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--df-font-display);
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--df-surface);
}
::-webkit-scrollbar-thumb {
  background: var(--df-border-hover);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--df-text-muted);
}

/* Global focus states — accent */
select:focus,
input:focus,
textarea:focus {
  border-color: var(--df-border-focus) !important;
  outline: none;
  box-shadow: 0 0 0 2px var(--df-accent-muted);
}

/* Form inputs dark theme */
select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
textarea {
  background-color: var(--df-bg);
  color: var(--df-text-primary);
  border: 1px solid var(--df-border);
  border-radius: var(--df-radius-md);
  padding: var(--df-space-2) var(--df-space-3);
  font-size: var(--df-text-sm);
  font-family: inherit;
  width: 100%;
  transition: border-color var(--df-transition-fast), box-shadow var(--df-transition-fast);
}

select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2394A3B8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 16px;
  padding-right: 32px;
  -webkit-appearance: none;
  appearance: none;
}

/* Checkbox dark theme */
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--df-accent);
}

/* Table row hover — subtle glow */
table tbody tr:hover {
  background-color: var(--df-row-hover) !important;
}

/* Touch targets — minimum 44px for mobile */
@media (max-width: 767px) {
  .touch-target {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .table-scroll {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
  }

  .table-scroll-wrapper {
    position: relative;
  }
  .table-scroll-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--df-scroll-fade));
    pointer-events: none;
    z-index: 1;
  }
}

/* Pagination touch-friendly */
@media (max-width: 767px) {
  .pagination a,
  .pagination span {
    min-height: 40px;
    min-width: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* Chart.js tooltip — theme-aware */
.chartjs-tooltip {
  background-color: var(--df-tooltip-bg) !important;
  backdrop-filter: blur(12px);
  border: 1px solid var(--df-border) !important;
  border-radius: var(--df-radius-md) !important;
  color: var(--df-text-primary) !important;
}

/* Disabled state */
button:disabled,
input:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Text selection — accent */
::selection {
  background-color: var(--df-accent);
  color: var(--df-bg);
}

/* Page content fade-in */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
main {
  animation: fadeIn 0.3s ease-out;
}

/* HTMX loading states */
.htmx-request .htmx-indicator {
  display: inline-block;
}
.htmx-request.opacity-on-load {
  opacity: 0.5;
  transition: opacity 0.2s ease;
}

/* HTMX skeleton loading — apply to containers */
.htmx-request .htmx-skeleton {
  display: block;
}
.htmx-skeleton {
  display: none;
}

/* Accent button glow */
.btn-accent {
  transition: all var(--df-transition-fast);
}
.btn-accent:hover {
  box-shadow: var(--df-shadow-glow);
}

/* Card hover lift — legacy alias */
.card-hover {
  transition: transform var(--df-transition-slow), box-shadow var(--df-transition-slow), border-color var(--df-transition-slow);
}
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--df-shadow-lg);
}

/* Badge pulse for alerts */
@keyframes badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}
.badge-pulse {
  animation: badge-pulse 2s ease-in-out infinite;
}

/* Smooth link underline on hover */
.link-underline {
  position: relative;
}
.link-underline::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 0;
  height: 1px;
  background-color: var(--df-accent);
  transition: width var(--df-transition-fast);
}
.link-underline:hover::after {
  width: 100%;
}

/* KPI value sizing */
.kpi-value {
  font-family: var(--df-font-display);
  font-size: var(--df-text-3xl);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

/* ── Phase 4: UX Polish ── */

/* HTMX swap transitions — fade content in/out */
.htmx-swapping {
  opacity: 0.4;
  transition: opacity 0.15s ease-out;
}
.htmx-settling {
  opacity: 1;
  transition: opacity 0.2s ease-in;
}

/* HTMX added content animation */
.htmx-added {
  animation: fadeSlideIn 0.3s ease-out;
}
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Loading button state — used with HTMX requests */
.btn.htmx-request {
  pointer-events: none;
  opacity: 0.6;
}
.btn.htmx-request::after {
  content: '';
  display: inline-block;
  width: 0.875rem;
  height: 0.875rem;
  border: 2px solid var(--df-spinner-track);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 0.5rem;
}

/* HTMX skeleton auto-show during requests */
.htmx-request .skeleton-placeholder {
  display: block !important;
}
.htmx-request .skeleton-content {
  display: none !important;
}
.skeleton-placeholder {
  display: none;
}

/* Smooth scroll behavior */
html {
  scroll-behavior: smooth;
}

/* Table container scroll shadow (both sides) */
.table-scroll-wrapper {
  position: relative;
}
.table-scroll-wrapper::before,
.table-scroll-wrapper::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.3s;
}
.table-scroll-wrapper::before {
  left: 0;
  background: linear-gradient(to left, transparent, var(--df-scroll-fade));
}
.table-scroll-wrapper::after {
  right: 0;
  background: linear-gradient(to right, transparent, var(--df-scroll-fade));
}
.table-scroll-wrapper.has-scroll-right::after { opacity: 1; }
.table-scroll-wrapper.has-scroll-left::before { opacity: 1; }

/* Tab active indicator animation */
.tab-active {
  position: relative;
}
.tab-active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--df-accent);
  border-radius: var(--df-radius-full);
  animation: tabSlide 0.25s ease-out;
}
@keyframes tabSlide {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* ── Phase 5: Accessibility ── */

/* Skip to content link */
.skip-link {
  position: absolute;
  top: -9999px;
  left: 0;
  right: 0;
  z-index: 9999;
  padding: 0.75rem 1rem;
  text-align: center;
  font-weight: 600;
  color: #fff;  /* always white on accent bg */
  background: var(--df-accent);
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0;
  outline: none;
}

/* Prefers-reduced-motion — disable animations */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .hover-elevate:hover {
    transform: none;
  }
  main {
    animation: none;
  }
}

/* High contrast mode — improve borders */
@media (prefers-contrast: high) {
  .glass-card {
    border-color: var(--df-border-hover);
  }
  .df-table td {
    border-bottom-color: var(--df-border);
  }
  .badge-status {
    border-color: currentColor;
  }
}

/* Focus ring for interactive cards/links */
a.glass-card:focus-visible,
button.glass-card:focus-visible {
  outline: 2px solid var(--df-accent);
  outline-offset: 2px;
}

/* ── Mobile enhancements ── */
@media (max-width: 767px) {
  /* Larger page title on mobile */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  /* Full-width buttons on mobile */
  .page-header .btn {
    width: 100%;
    justify-content: center;
  }

  /* KPI values slightly smaller on mobile */
  .kpi-value {
    font-size: 1.75rem;
  }

  /* KPI card text sizes */
  .glass-card h3.text-3xl {
    font-size: 1.75rem;
  }

  /* Stack search + button on mobile */
  .glass-card form.flex {
    flex-wrap: wrap;
  }

  /* Cards grid adjustments */
  .glass-card .grid.grid-cols-2 {
    gap: 0.5rem;
  }

  /* Better table text sizing */
  .df-table td {
    font-size: 12px;
    padding: 0.625rem 0.75rem;
  }
  .df-table th {
    padding: 0.625rem 0.75rem;
    font-size: 10px;
  }

  /* Glass card padding reduction */
  .glass-card {
    padding: 1rem;
  }
  .glass-card.p-6 {
    padding: 1rem;
  }

  /* Supplier cards: single column */
  .grid.lg\:grid-cols-3 {
    grid-template-columns: 1fr;
  }

  /* Period selector compact */
  #period-selector {
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Sidebar overlay for mobile */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: var(--df-overlay-bg);
    backdrop-filter: blur(4px);
    z-index: 40;
  }

  /* Bottom safe area for PWA */
  main {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Full-width search on mobile */
  input[type="text"],
  input[type="search"] {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  /* Navbar compact on mobile */
  .navbar-search {
    display: none;
  }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 1023px) {
  .glass-card h3.text-3xl {
    font-size: 1.875rem;
  }
}

/* Landscape phone optimization */
@media (max-height: 500px) and (orientation: landscape) {
  .page-header {
    margin-bottom: 0.75rem;
  }
  .glass-card {
    padding: 0.75rem;
  }
}

/* ── Sprint 3: Micro-animations & Polish ── */

/* Staggered fade-in for grid children (cards, KPIs) */
@keyframes staggerFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.stagger-in > * {
  animation: staggerFadeIn 0.4s ease-out both;
}
.stagger-in > *:nth-child(1) { animation-delay: 0ms; }
.stagger-in > *:nth-child(2) { animation-delay: 60ms; }
.stagger-in > *:nth-child(3) { animation-delay: 120ms; }
.stagger-in > *:nth-child(4) { animation-delay: 180ms; }
.stagger-in > *:nth-child(5) { animation-delay: 240ms; }
.stagger-in > *:nth-child(6) { animation-delay: 300ms; }

/* Number count-up effect placeholder */
.count-up {
  font-variant-numeric: tabular-nums;
}

/* Smooth progress bar fill */
@keyframes progressFill {
  from { width: 0%; }
}
.animate-progress {
  animation: progressFill 0.8s ease-out;
}

/* Subtle pulse for live indicators */
@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.live-indicator {
  animation: livePulse 2s ease-in-out infinite;
}

/* Row hover slide-right effect for table actions */
.df-table tbody tr .row-action {
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.df-table tbody tr:hover .row-action {
  opacity: 1;
  transform: translateX(0);
}

/* Glass card border shimmer on hover */
@keyframes borderShimmer {
  0% { border-color: var(--df-border-subtle); }
  50% { border-color: var(--df-accent-muted); }
  100% { border-color: var(--df-border-subtle); }
}
.shimmer-border:hover {
  animation: borderShimmer 2s ease-in-out;
}

/* Smooth accordion expand */
.accordion-content {
  overflow: hidden;
  transition: max-height 0.3s ease-out, opacity 0.2s ease;
}

/* Tooltip fade */
.tooltip-fade {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}
.group:hover .tooltip-fade,
*:hover > .tooltip-fade {
  opacity: 1;
  transform: translateY(0);
}
