/* Estilos customizados para o Concursos App */

* {
  box-sizing: border-box;
}

/* ✅ v213: Prevenir pull-to-refresh nativo do Chrome/Android/Safari */
html, body {
  overscroll-behavior-y: contain;
}

/* ===== iOS Safari Gradient Fallback ===== */
/* Tailwind CDN arbitrary values like from-[#122D6A] may not work on all iOS Safari versions.
   These inline styles and CSS fallbacks ensure gradients always render. */
.bg-gradient-to-r.from-\[\#122D6A\].to-\[\#2A4A9F\] {
  background: linear-gradient(to right, #122D6A, #2A4A9F) !important;
}
.bg-gradient-to-br.from-\[\#122D6A\].to-\[\#2A4A9F\] {
  background: linear-gradient(to bottom right, #122D6A, #2A4A9F) !important;
}
.bg-gradient-to-br.from-\[\#0D1F4D\].via-\[\#122D6A\].to-\[\#1A3A7F\] {
  background: linear-gradient(to bottom right, #0D1F4D, #122D6A, #1A3A7F) !important;
}
.bg-gradient-to-br.from-\[\#1A3A7F\].to-\[\#2A4A9F\] {
  background: linear-gradient(to bottom right, #1A3A7F, #2A4A9F) !important;
}

/* ===== CRITICAL: Force blue header on ALL platforms ===== */
/* This ensures the sticky header is ALWAYS blue with white text,
   even if Tailwind CDN fails or iOS Safari has rendering issues. */
header.sticky.top-0.z-50 {
  background-color: #122D6A !important;
  background-image: linear-gradient(to right, #122D6A, #2A4A9F) !important;
  color: #ffffff !important;
}
/* White text for direct header UI (buttons, labels) EXCEPT dropdown menus.
   Dropdowns (#userMenu, #helpMenu, #configMenu) use inline styles for correct colors.
   Strategy: Only force white on header's own buttons, not dropdown buttons. */
header.sticky.top-0.z-50 > div > div > div > button,
header.sticky.top-0.z-50 > div > div > div > a,
header.sticky.top-0.z-50 > div > div > button,
header.sticky.top-0.z-50 > div > div > a,
header.sticky.top-0.z-50 > div > button,
header.sticky.top-0.z-50 h1,
header.sticky.top-0.z-50 h2,
header.sticky.top-0.z-50 span:not(#userMenu span):not(#helpMenu span):not(#configMenu span) {
  color: #ffffff;
}
header.sticky.top-0.z-50 i.fas,
header.sticky.top-0.z-50 i.far,
header.sticky.top-0.z-50 i.fab {
  color: #ffffff !important;
}
/* Dropdown elements use their OWN colors (inline styles) - override header white */
header.sticky.top-0.z-50 #userMenu,
header.sticky.top-0.z-50 #userMenu *,
header.sticky.top-0.z-50 #helpMenu,
header.sticky.top-0.z-50 #helpMenu *,
header.sticky.top-0.z-50 #configMenu,
header.sticky.top-0.z-50 #configMenu * {
  color: unset;
}
header.sticky.top-0.z-50 #userMenu i.fas,
header.sticky.top-0.z-50 #userMenu i.far,
header.sticky.top-0.z-50 #helpMenu i.fas,
header.sticky.top-0.z-50 #helpMenu i.far,
header.sticky.top-0.z-50 #configMenu i.fas,
header.sticky.top-0.z-50 #configMenu i.far {
  color: unset !important;
}
header.sticky.top-0.z-50 .text-\[#7BC4FF\] {
  color: #7BC4FF !important;
}

/* ===== CRITICAL: Dark mode auto-contrast for text-[#122D6A] ===== */
/* Many elements use text-[#122D6A] (dark blue) which is invisible in dark mode.
   This rule automatically converts them to light blue when dark mode is active.
   Exceptions: elements inside the blue header (handled above) and elements with
   explicit bg that provides sufficient contrast (bg-[#E8EDF5], bg-[#D0D9EB]). */
html.dark .text-\[\#122D6A\] {
  color: #7BC4FF !important;
}
/* Also handle text-[#1A3A7F] and text-[#2A4A9F] and text-[#0D1F4D] variants */
html.dark .text-\[\#1A3A7F\] {
  color: #7BC4FF !important;
}
html.dark .text-\[\#2A4A9F\] {
  color: #93C5FD !important;
}
html.dark .text-\[\#0D1F4D\] {
  color: #7BC4FF !important;
}
/* Exceptions: Elements with explicit light backgrounds that ensure contrast.
   Flashcards, badges, and modals that keep a white/light bg in dark mode. */
html.dark .bg-white .text-\[\#122D6A\],
html.dark .bg-white.text-\[\#122D6A\],
html.dark .bg-\[\#E8EDF5\] .text-\[\#122D6A\],
html.dark .bg-\[\#D0D9EB\] .text-\[\#122D6A\],
html.dark .bg-\[\#D6E4F5\] .text-\[\#122D6A\],
html.dark .bg-blue-50 .text-\[\#122D6A\],
html.dark .bg-blue-100 .text-\[\#122D6A\] {
  color: #122D6A !important;
}
/* Override: header icons MUST stay white (header has blue bg) */
header.sticky .text-\[\#122D6A\] {
  color: #122D6A;
}
html.dark header.sticky .text-\[\#122D6A\] {
  color: #ffffff !important;
}

/* ===== iOS/Safari Critical Fixes ===== */
html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Safe areas: top is handled by sticky headers via CSS.
     --sat is a JS-set CSS variable for Android standalone fallback. */
  padding-top: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* iOS button reset - prevents iOS from adding its own styles */
/* IMPORTANT: Exclude checkbox and radio from appearance reset */
button,
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: 0;
}

/* Ensure checkboxes and radios keep native appearance */
input[type="checkbox"],
input[type="radio"] {
  -webkit-appearance: checkbox;
  -moz-appearance: checkbox;
  appearance: checkbox;
  width: 20px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: #10B981;
}

input[type="radio"] {
  -webkit-appearance: radio;
  -moz-appearance: radio;
  appearance: radio;
}

/* Re-apply border-radius after reset */
button {
  border-radius: inherit;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
select,
textarea {
  border-radius: 8px;
}

/* iOS touch targets - minimum 44x44px for tappable elements */
.touch-target {
  min-width: 44px;
  min-height: 44px;
}

/* Header buttons minimum tap area on mobile */
@media (max-width: 640px) {
  header.sticky button,
  nav.fixed button {
    min-width: 36px;
    min-height: 36px;
  }
}

/* iOS tap highlight */
a, button, [onclick] {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  touch-action: manipulation;
}

/* Prevent iOS zoom on input focus (font-size must be >= 16px) */
@supports (-webkit-touch-callout: none) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* iOS overflow scrolling */
.overflow-y-auto,
.overflow-x-auto,
[style*="overflow"] {
  -webkit-overflow-scrolling: touch;
}

/* Line clamp support (iOS Safari) */
.line-clamp-1 {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Grid children min-width fix (prevents overflow on iOS) */
.grid > * {
  min-width: 0;
}

/* ===== Mobile-first KPI fixes ===== */
/* Force 4-column grid on all screen sizes for KPI cards */
.kpi-grid-4 {
  display: grid !important;
  grid-template-columns: repeat(4, 1fr) !important;
  gap: 6px !important;
}

/* KPI card consistent sizing */
.kpi-card {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  padding: 6px 4px !important;
  min-height: 56px !important;
  border-radius: 8px !important;
}

/* v130: KPI icon - minimalista acima do valor */
.kpi-card .kpi-icon {
  font-size: 10px !important;
  line-height: 1 !important;
  margin-bottom: 2px !important;
  opacity: 0.7;
}

.kpi-card .kpi-value {
  font-size: 16px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  white-space: nowrap !important;
}

.kpi-card .kpi-label {
  font-size: 9px !important;
  line-height: 1.2 !important;
  margin-top: 2px !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

@media (min-width: 640px) {
  .kpi-grid-4 {
    gap: 12px !important;
  }
  .kpi-card {
    padding: 10px 8px !important;
    min-height: 64px !important;
  }
  .kpi-card .kpi-icon {
    font-size: 12px !important;
    margin-bottom: 3px !important;
  }
  .kpi-card .kpi-value {
    font-size: 20px !important;
  }
  .kpi-card .kpi-label {
    font-size: 10px !important;
  }
}

/* ===== Meta card button grid fix ===== */
.meta-btn-grid {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 4px !important;
}

.meta-btn-grid > button {
  font-size: 10px !important;
  line-height: 1.2 !important;
  padding: 6px 2px !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  min-height: 32px !important;
  border-radius: 6px !important;
}

@media (min-width: 640px) {
  .meta-btn-grid {
    gap: 6px !important;
  }
  .meta-btn-grid > button {
    font-size: 11px !important;
    padding: 8px 4px !important;
    min-height: 36px !important;
  }
}

/* ===== Meta cards grid - always 2 columns on mobile ===== */
.meta-cards-grid {
  display: grid !important;
  grid-template-columns: repeat(1, 1fr) !important;
  gap: 8px !important;
}

@media (min-width: 480px) {
  .meta-cards-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media (min-width: 1024px) {
  .meta-cards-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

@media (min-width: 1280px) {
  .meta-cards-grid {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

/* ===== Animacoes suaves ===== */
.transition-all {
  transition: all 0.3s ease;
}

/* Efeito de hover nos cards */
.hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

/* Progress bar animada */
@keyframes progress {
  from {
    width: 0%;
  }
}

.progress-bar {
  animation: progress 1s ease-in-out;
}

/* Fade in animation */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.5s ease-in-out;
}

/* Loading spinner */
.spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #3498db;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

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

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

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

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Barras listradas para semanas futuras */
.bg-stripes {
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 5px,
    rgba(255, 255, 255, 0.1) 5px,
    rgba(255, 255, 255, 0.1) 10px
  );
}

/* Dark mode para barras listradas */
.dark .bg-stripes {
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 5px,
    rgba(255, 255, 255, 0.05) 5px,
    rgba(255, 255, 255, 0.05) 10px
  );
}

/* ===== Week calendar header fix ===== */
.week-header-label {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  flex-wrap: nowrap !important;
}

.week-header-label .week-number {
  font-size: 14px !important;
  font-weight: 700 !important;
  white-space: nowrap !important;
}

.week-header-label .week-dates {
  font-size: 11px !important;
  white-space: nowrap !important;
  opacity: 0.7;
}

/* ===== Day tabs fix ===== */
.dia-tab {
  min-width: 0 !important;
  padding: 8px 2px !important;
  font-size: 12px !important;
}

/* ===== Safe Area - Status Bar Protection (iOS + Android) ===== */
/* With viewport-fit=cover, the viewport extends behind the status bar.
   We MUST add padding-top to sticky/fixed headers so they don't overlap
   with system UI (notch, Dynamic Island, Android status bar).
   
   env(safe-area-inset-top) returns:
   - iPhone with notch/Dynamic Island: ~47-59px in standalone
   - iPhone SE/older: ~20px in standalone
   - Android in standalone/TWA: varies (usually 24-48px)
   - Any device in browser: 0px (browser chrome handles it)
   - Desktop: 0px
   
   --sat is a JS-set CSS variable for Android standalone fallback
   where env(safe-area-inset-top) returns 0. */

/* ALL sticky headers at top get safe-area padding */
header.sticky.top-0,
div.sticky.top-0 {
  padding-top: env(safe-area-inset-top, var(--sat, 0px)) !important;
}

/* Override: when env() IS supported, use it directly (ignores --sat) */
@supports (padding-top: env(safe-area-inset-top)) {
  header.sticky.top-0,
  div.sticky.top-0 {
    padding-top: env(safe-area-inset-top, 0px) !important;
  }
  
  /* For Android standalone where env returns 0 but --sat is set */
  html[data-android-standalone] header.sticky.top-0,
  html[data-android-standalone] div.sticky.top-0 {
    padding-top: max(env(safe-area-inset-top, 0px), var(--sat, 0px)) !important;
  }
}

/* Pages WITHOUT a sticky/fixed header that need explicit safe-area top spacing */
.ios-safe-top {
  padding-top: env(safe-area-inset-top, 0px);
}

/* ===== Concursos screen - mobile fixes ===== */

/* ===== iOS Calendar grid fix ===== */
/* On iOS Safari, Tailwind CDN's grid-cols-7 class may not be applied or may fail.
   Force 7-column grid layout with inline-equivalent CSS for all iOS devices.
   This ONLY affects iOS (via @supports -webkit-touch-callout) - Android is untouched. */
@supports (-webkit-touch-callout: none) {
  /* Force 7-column grid on iOS - the core fix */
  .grid.grid-cols-7 {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  .grid.grid-cols-7 > div {
    min-width: 0 !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  /* Force calendar day cells to have proper background rendering on iOS */
  .grid.grid-cols-7 > div[style*="background-color"] {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
}
.concursos-summary-cards {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 6px !important;
}

.concursos-summary-cards > div {
  padding: 8px 4px !important;
  border-radius: 10px !important;
  text-align: center !important;
}

.concursos-summary-cards .concursos-number {
  font-size: 20px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
}

.concursos-summary-cards .concursos-label {
  font-size: 9px !important;
  margin-top: 1px !important;
  text-transform: uppercase !important;
  letter-spacing: 0.3px !important;
}

@media (min-width: 640px) {
  .concursos-summary-cards {
    gap: 12px !important;
  }
  .concursos-summary-cards > div {
    padding: 14px 8px !important;
  }
  .concursos-summary-cards .concursos-number {
    font-size: 28px !important;
  }
  .concursos-summary-cards .concursos-label {
    font-size: 11px !important;
  }
}

/* Concursos filter bar - mobile friendly */
.concursos-filters {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  align-items: center !important;
}

.concursos-filters select,
.concursos-filters input[type="text"] {
  flex: 1 1 100% !important;
  min-width: 0 !important;
}

@media (min-width: 480px) {
  .concursos-filters select,
  .concursos-filters input[type="text"] {
    flex: 1 1 auto !important;
    min-width: 140px !important;
  }
}

/* Concursos tab buttons - prevent truncation */
.concursos-tab-group {
  display: flex !important;
  flex-shrink: 0 !important;
}

.concursos-tab-group > button {
  padding: 6px 10px !important;
  font-size: 11px !important;
  white-space: nowrap !important;
}

@media (min-width: 640px) {
  .concursos-tab-group > button {
    padding: 8px 12px !important;
    font-size: 12px !important;
  }
}

/* ===== Universal compact KPI grid (same as homepage kpi-grid-4) ===== */
/* All screens now use kpi-grid-4 with kpi-card for consistent look */

/* ===== Simulados - status card ===== */
.status-card-meta {
  padding: 12px !important;
  border-radius: 12px !important;
}

.status-card-meta .status-icon {
  width: 36px !important;
  height: 36px !important;
  flex-shrink: 0 !important;
}

.status-card-meta .status-icon i {
  font-size: 14px !important;
}

.status-card-meta h3 {
  font-size: 14px !important;
  line-height: 1.3 !important;
}

@media (min-width: 640px) {
  .status-card-meta {
    padding: 20px !important;
  }
  .status-card-meta .status-icon {
    width: 48px !important;
    height: 48px !important;
  }
  .status-card-meta .status-icon i {
    font-size: 20px !important;
  }
  .status-card-meta h3 {
    font-size: 18px !important;
  }
}

/* ===== Reduce top spacing for inner pages ===== */
.page-content-compact {
  padding-top: 12px !important;
  padding-bottom: env(safe-area-inset-bottom, 12px) !important;
}

@media (min-width: 640px) {
  .page-content-compact {
    padding-top: 24px !important;
  }
}

/* Animação do sino de notificação */
@keyframes bellShake {
  0% { transform: rotate(0); }
  15% { transform: rotate(12deg); }
  30% { transform: rotate(-10deg); }
  45% { transform: rotate(8deg); }
  60% { transform: rotate(-6deg); }
  75% { transform: rotate(3deg); }
  100% { transform: rotate(0); }
}

/* ===== v200: Pull-to-refresh para iOS/PWA ===== */
#pull-to-refresh-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 0;
  overflow: hidden;
  transition: height 0.2s ease;
  background: linear-gradient(135deg, #122D6A, #2A4A9F);
  color: white;
  font-size: 13px;
  font-weight: 600;
}

#pull-to-refresh-indicator.active {
  height: 48px;
}

#pull-to-refresh-indicator .ptr-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== v200: Responsividade nomes longos disciplina/topico ===== */
/* Cards de meta - text overflow */
.meta-cards-grid .truncate,
.meta-cards-grid [class*="truncate"] {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  max-width: 100% !important;
}

.meta-cards-grid .line-clamp-2 {
  display: -webkit-box !important;
  -webkit-line-clamp: 2 !important;
  -webkit-box-orient: vertical !important;
  overflow: hidden !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
}

/* Force card to not overflow on mobile */
.meta-cards-grid > div {
  min-width: 0 !important;
  overflow: hidden !important;
}

.meta-cards-grid > div > div {
  min-width: 0 !important;
}

/* Discipline name in card header */
.meta-cards-grid > div .text-xs.font-bold,
.meta-cards-grid > div .text-sm.font-bold {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  max-width: calc(100% - 60px) !important;
}

/* Topic name under discipline */
.meta-cards-grid > div p[title] {
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  hyphens: auto !important;
}

/* ===== v200: Meta button grid - accommodate SVG dot content ===== */
.meta-btn-grid > button span {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

.meta-btn-grid > button svg {
  flex-shrink: 0 !important;
}
