/**
 * CENOM - CSS Fixes & Corrections
 * Correções de layout e compatibilidade
 */

/* ═══════════════════════════════════════════
   SKIP LINK - Acessibilidade (Keyboard)
   ═══════════════════════════════════════════ */

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 10000;
  font-weight: var(--font-weight-semibold);
  border-radius: 0 4px 4px 0;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 0;
  outline: 3px solid var(--color-secondary);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════
   GLOBAL FIXES
   ═══════════════════════════════════════════ */

html,
body {
  width: 100%;
  height: auto;
  overflow-x: hidden;
}

body {
  font-family: var(--font-family-base);
  font-size: var(--text-body);
  line-height: var(--line-height-normal);
  color: var(--color-gray-dark);
  background-color: var(--color-white);
}

/* ═══════════════════════════════════════════
   IMAGE FIXES
   ═══════════════════════════════════════════ */

img {
  max-width: 100%;
  height: auto;
  display: block;
  font-style: italic;
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
}

picture {
  display: block;
}

svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ═══════════════════════════════════════════
   FORM FIXES
   ═══════════════════════════════════════════ */

input,
textarea,
select,
button {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
  min-height: 44px;  /* Touch target mínimo WCAG */
}

input,
textarea,
select {
  padding: var(--spacing-sm);
  border: 1px solid var(--color-gray-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-white);
  transition: var(--transition-fast);
  min-height: 44px;  /* Toque fácil em mobile */
}

@media (max-width: 768px) {
  input,
  textarea,
  select {
    font-size: 16px;  /* Previne zoom automático em iOS */
    padding: var(--spacing-md);  /* Mais padding */
  }
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0, 82, 163, 0.1);
}

textarea {
  resize: vertical;
  min-height: 120px;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ═══════════════════════════════════════════
   MEDIA OBJECT FIX (common layout pattern)
   ═══════════════════════════════════════════ */

.media {
  display: flex;
  gap: var(--spacing-lg);
}

.media-img {
  flex-shrink: 0;
}

.media-body {
  flex: 1;
  min-width: 0;
}

@media (max-width: 640px) {
  .media {
    flex-direction: column;
  }
}

/* ═══════════════════════════════════════════
   TABLE FIXES
   ═══════════════════════════════════════════ */

table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  margin-bottom: var(--spacing-lg);
}

thead {
  background-color: var(--color-gray-light);
}

th,
td {
  padding: var(--spacing-sm);
  text-align: left;
  border-bottom: 1px solid var(--color-gray-border);
}

th {
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-dark);
}

tbody tr:hover {
  background-color: var(--color-gray-light);
}

/* ═══════════════════════════════════════════
   MARGIN COLLAPSE FIX (adjacent margins)
   ═══════════════════════════════════════════ */

h1 + p,
h2 + p,
h3 + p {
  margin-top: calc(var(--spacing-lg) * -0.5);
}

/* ═══════════════════════════════════════════
   UTILITY HELPERS
   ═══════════════════════════════════════════ */

.clearfix::after {
  content: '';
  display: block;
  clear: both;
}

.no-wrap {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.truncate-1 {
  -webkit-line-clamp: 1;
}

.truncate-3 {
  -webkit-line-clamp: 3;
}

/* ═══════════════════════════════════════════
   FOCUS VISIBLE (keyboard navigation)
   ═══════════════════════════════════════════ */

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

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════
   SELECTION STYLES
   ═══════════════════════════════════════════ */

::selection {
  background-color: var(--color-primary);
  color: var(--color-white);
}

::-moz-selection {
  background-color: var(--color-primary);
  color: var(--color-white);
}

/* ═══════════════════════════════════════════
   SCROLLBAR STYLING (webkit browsers)
   ═══════════════════════════════════════════ */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--color-gray-light);
}

::-webkit-scrollbar-thumb {
  background: var(--color-gray-border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-gray-medium);
}

/* ═══════════════════════════════════════════
   PLACEHOLDER TEXT FIXES
   ═══════════════════════════════════════════ */

::placeholder {
  color: var(--color-gray-medium);
  opacity: 0.7;
}

::-webkit-input-placeholder {
  color: var(--color-gray-medium);
  opacity: 0.7;
}

::-moz-placeholder {
  color: var(--color-gray-medium);
  opacity: 0.7;
}

:-ms-input-placeholder {
  color: var(--color-gray-medium);
  opacity: 0.7;
}

/* ═══════════════════════════════════════════
   ANIMATION PERFORMANCE FIX
   ═══════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ═══════════════════════════════════════════
   PRINT MEDIA FIXES
   ═══════════════════════════════════════════ */

@media print {
  body {
    background: white;
    color: black;
  }

  a {
    text-decoration: underline;
  }

  a[href]::after {
    content: ' (' attr(href) ')';
  }

  img,
  figure {
    page-break-inside: avoid;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    page-break-after: avoid;
  }

  p {
    page-break-inside: avoid;
  }

  button,
  a.btn {
    display: none;
  }
}

/* ═══════════════════════════════════════════
   VENDOR PREFIXES & COMPATIBILITY
   ═══════════════════════════════════════════ */

/* Smooth scrolling fallback */
@supports not (scroll-behavior: smooth) {
  html {
    scroll-behavior: auto;
  }
}

/* Flexbox gap fallback (IE11) */
.flex > * + * {
  margin-left: var(--gap, var(--spacing-md));
}

/* Grid gap fallback (IE11) */
.grid {
  gap: var(--gap, var(--spacing-lg));
}

/* ═══════════════════════════════════════════
   BACK TO TOP BUTTON
   ═══════════════════════════════════════════ */

.back-to-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  background: var(--color-primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: var(--font-weight-bold);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
  z-index: 50;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 61, 122, 0.2);
  cursor: pointer;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

@media (hover: hover) {
  .back-to-top:hover {
    background: var(--color-primary-dark);
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 61, 122, 0.3);
  }
}

.back-to-top:focus-visible {
  outline: 3px solid var(--color-secondary);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .back-to-top {
    bottom: 16px;
    right: 16px;
  }
}

/* Esconder em orientação landscape com height < 500px */
@media (max-height: 500px) and (orientation: landscape) {
  .back-to-top {
    display: none;
  }
}
