/* ========================================
   RESPONSIVE DESIGN SYSTEM
   Portal UrbIA - Sistema Legislativo
   ======================================== */

/* ===== VARIÁVEIS CSS ===== */
:root {
  --primary-color: #3B82F6;
  --secondary-color: #1E40AF;
  --accent-color: #F59E0B;
  --success-color: #10B981;
  --warning-color: #F59E0B;
  --danger-color: #EF4444;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;

  /* Breakpoints */
  --mobile: 640px;
  --tablet: 768px;
  --laptop: 1024px;
  --desktop: 1280px;
  --wide: 1536px;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Typography */
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

  /* Border radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;
  --radius-2xl: 1rem;
  --radius-full: 9999px;
}

/* ===== RESET E BASE ===== */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  color: var(--gray-800);
  background-color: var(--gray-50);
  overflow-x: hidden;
}

/* ===== GLOBAL TEXT CONTRAST RULES ===== */
/* Ensure text is always visible with proper contrast */

/* Default: black text for light backgrounds */
body,
main,
article,
section,
div,
p,
span,
h1,
h2,
h3,
h4,
h5,
h6,
label,
li,
td,
th {
  color: inherit;
}

/* Light background elements - force black text */
.bg-white,
.bg-gray-50,
.bg-gray-100,
.bg-gray-200,
[class*="bg-white"],
[style*="background: #fff"],
[style*="background: white"],
[style*="background-color: #fff"],
[style*="background-color: white"],
.card,
.modal,
.dropdown-menu,
.bg-light {
  color: #0f172a !important;
}

.bg-white *,
.bg-gray-50 *,
.bg-gray-100 *,
.bg-gray-200 *,
.card *,
.modal *,
.dropdown-menu * {
  color: inherit;
}

/* Dark background elements - force white text */
.bg-dark,
.bg-gray-800,
.bg-gray-900,
[class*="bg-dark"],
[class*="bg-slate-800"],
[class*="bg-slate-900"],
[class*="bg-gray-800"],
[class*="bg-gray-900"],
.dark-card {
  color: #f8fafc !important;
}

.bg-dark *,
.bg-gray-800 *,
.bg-gray-900 * {
  color: inherit;
}

/* Form elements - always black text on white background */
input,
select,
textarea,
.form-control,
.form-input,
.form-select,
.doc-filter-input,
[type="text"],
[type="email"],
[type="password"],
[type="number"],
[type="date"],
[type="time"],
[type="datetime-local"],
[type="search"],
[type="tel"],
[type="url"] {
  color: #0f172a !important;
  -webkit-text-fill-color: #0f172a !important;
  background-color: #ffffff !important;
}

select option,
datalist option {
  color: #0f172a !important;
  background-color: #ffffff !important;
}

::-moz-placeholder {
  color: #6b7280 !important;
  -webkit-text-fill-color: #6b7280 !important;
  opacity: 1 !important;
}

::placeholder {
  color: #6b7280 !important;
  -webkit-text-fill-color: #6b7280 !important;
  opacity: 1 !important;
}

/* Content areas with light backgrounds */
.prose,
.doc-content,
.content,
.text-content,
.document-content,
[class*="content"] {
  color: #1f2937 !important;
}

.prose *,
.doc-content *,
.content *,
.text-content * {
  color: inherit !important;
}

/* Specific fix for document preview/content areas */
.doc-preview-surface,
.doc-editor-surface,
#viewConteudo,
#preview,
#editor {
  color: #0f172a !important;
  background-color: #ffffff;
}

.doc-preview-surface *,
.doc-editor-surface *,
#viewConteudo *,
#preview *,
#editor * {
  color: inherit !important;
}

/* Cards and modals on light backgrounds */
.doc-filter-card,
.doc-modal,
.doc-modal__body {
  color: #0f172a !important;
}

.doc-filter-card *,
.doc-modal *,
.doc-modal__body * {
  color: inherit;
}

/* Override for specific elements that should NOT inherit */
.doc-filter-card .doc-primary-btn,
.doc-modal .doc-primary-btn,
.btn-primary,
[class*="btn-primary"] {
  color: #ffffff !important;
}

.doc-action-card,
.doc-action-card * {
  color: #f8fafc !important;
}

/* Header elements on dark backgrounds */
.header-gamified,
.header-gamified *,
.sidebar-desktop,
.nav-desktop {
  color: #f8fafc;
}

/* Ensure links have proper contrast */
a {
  color: inherit;
}

/* Badge and label overrides */
.badge,
.doc-badge {
  color: inherit;
}

/* ===== CONTAINERS RESPONSIVOS ===== */
.container {
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

@media (min-width: 640px) {
  .container {
    max-width: 640px;
    padding: 0 var(--space-lg);
  }
}

@media (min-width: 768px) {
  .container {
    max-width: 768px;
    padding: 0 var(--space-xl);
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 1024px;
    padding: 0 var(--space-xl);
  }
}

@media (min-width: 1280px) {
  .container {
    max-width: 1280px;
    padding: 0 var(--space-2xl);
  }
}

@media (min-width: 1536px) {
  .container {
    max-width: 1536px;
    padding: 0 var(--space-2xl);
  }
}

/* ===== NAVEGAÇÃO RESPONSIVA ===== */
.navbar {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.navbar-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-md);
  max-width: 1280px;
  margin: 0 auto;
}

.navbar-logo {
  display: flex;
  align-items: center;
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--primary-color);
  text-decoration: none;
}

.navbar-logo img {
  height: 3.5rem;
  width: auto;
  margin-right: var(--space-sm);
}

@media (min-width: 640px) {
  .navbar-logo img {
    height: 5rem;
  }
}

.navbar-menu {
  display: none;
  align-items: center;
  gap: var(--space-lg);
}

.navbar-menu.active {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid var(--gray-200);
  padding: var(--space-lg);
  box-shadow: var(--shadow-lg);
}

@media (min-width: 768px) {
  .navbar-menu {
    display: flex;
    flex-direction: row;
    position: static;
    background: none;
    border: none;
    padding: 0;
    box-shadow: none;
  }
}

.navbar-link {
  color: var(--gray-600);
  text-decoration: none;
  font-weight: 500;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.navbar-link:hover,
.navbar-link.active {
  color: var(--primary-color);
  background-color: var(--gray-50);
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.navbar-toggle {
  display: block;
  background: none;
  border: none;
  padding: var(--space-sm);
  cursor: pointer;
  color: var(--gray-600);
}

@media (min-width: 768px) {
  .navbar-toggle {
    display: none;
  }
}

/* ===== GRID RESPONSIVO ===== */
.grid {
  display: grid;
  gap: var(--space-lg);
}

.grid-1 {
  grid-template-columns: 1fr;
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 639px) {

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 640px) and (max-width: 767px) {

  .grid-3,
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .grid-4 {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ===== CARDS RESPONSIVOS ===== */
.card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  overflow: hidden;
  transition: all 0.3s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--gray-200);
}

.card-body {
  padding: var(--space-lg);
}

.card-footer {
  padding: var(--space-lg);
  border-top: 1px solid var(--gray-200);
  background-color: var(--gray-50);
}

/* ===== BOTÕES RESPONSIVOS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-md);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: var(--font-size-sm);
  line-height: 1.5;
  min-height: 2.5rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-xs);
  min-height: 2rem;
}

.btn-lg {
  padding: var(--space-md) var(--space-xl);
  font-size: var(--font-size-lg);
  min-height: 3rem;
}

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

.btn-primary:hover {
  background-color: var(--secondary-color);
}

.btn-secondary {
  background-color: var(--gray-200);
  color: var(--gray-800);
}

.btn-secondary:hover {
  background-color: var(--gray-300);
}

.btn-success {
  background-color: var(--success-color);
  color: white;
}

.btn-success:hover {
  background-color: #059669;
}

.btn-group {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

@media (max-width: 639px) {
  .btn-group {
    flex-direction: column;
    width: 100%;
  }

  .btn-group .btn {
    width: 100%;
  }
}

/* ===== FORMULÁRIOS RESPONSIVOS ===== */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-label {
  display: block;
  margin-bottom: var(--space-xs);
  font-weight: 500;
  color: var(--gray-700);
  font-size: var(--font-size-sm);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  color: var(--gray-900);
  background-color: #ffffff;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ===== GLOBAL FORM INPUT TEXT COLOR FIX ===== */
/* Ensure text is visible (black) in all form elements */
input,
select,
textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="search"],
input[type="tel"],
input[type="url"] {
  color: #111827 !important;
  -webkit-text-fill-color: #111827;
}

select option {
  color: #111827 !important;
  background-color: #ffffff !important;
}

/* Placeholder color */
::-moz-placeholder {
  color: #6b7280 !important;
  opacity: 1;
}
::placeholder {
  color: #6b7280 !important;
  opacity: 1;
}

::-webkit-input-placeholder {
  color: #6b7280 !important;
}

::-moz-placeholder {
  color: #6b7280 !important;
}

:-ms-input-placeholder {
  color: #6b7280 !important;
}

/* Mobile specific overrides for better visibility */
@media (max-width: 767px) {

  input,
  select,
  textarea {
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
    background-color: #ffffff !important;
  }

  select option {
    color: #0f172a !important;
    background-color: #ffffff !important;
  }
}

.form-grid {
  display: grid;
  gap: var(--space-lg);
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

/* ===== TABELAS RESPONSIVAS ===== */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table th,
.table td {
  padding: var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

.table th {
  background-color: var(--gray-50);
  font-weight: 600;
  color: var(--gray-700);
  font-size: var(--font-size-sm);
}

.table tr:hover {
  background-color: var(--gray-50);
}

@media (max-width: 767px) {

  .table th,
  .table td {
    padding: var(--space-sm);
    font-size: var(--font-size-sm);
  }

  .table th:nth-child(n+3),
  .table td:nth-child(n+3) {
    display: none;
  }
}

/* ===== MODAIS RESPONSIVOS ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-md);
}

.modal-content {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
}

@media (min-width: 640px) {
  .modal-content {
    max-width: 500px;
  }
}

@media (min-width: 768px) {
  .modal-content {
    max-width: 600px;
  }
}

/* ===== UTILITÁRIOS RESPONSIVOS ===== */
.hidden-mobile {
  display: none;
}

@media (min-width: 640px) {
  .hidden-mobile {
    display: block;
  }
}

.hidden-tablet {
  display: block;
}

@media (min-width: 768px) {
  .hidden-tablet {
    display: none;
  }
}

.hidden-desktop {
  display: block;
}

@media (min-width: 1024px) {
  .hidden-desktop {
    display: none;
  }
}

.text-responsive {
  font-size: var(--font-size-sm);
}

@media (min-width: 640px) {
  .text-responsive {
    font-size: var(--font-size-base);
  }
}

@media (min-width: 768px) {
  .text-responsive {
    font-size: var(--font-size-lg);
  }
}

/* ===== ANIMAÇÕES ===== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(0);
  }
}

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

.animate-slide-in {
  animation: slideIn 0.3s ease-out;
}

/* ===== LOADING STATES ===== */
.loading {
  position: relative;
  overflow: hidden;
}

.loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,
      transparent,
      rgba(255, 255, 255, 0.6),
      transparent);
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% {
    left: -100%;
  }

  100% {
    left: 100%;
  }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --gray-50: #1F2937;
    --gray-100: #374151;
    --gray-200: #4B5563;
    --gray-300: #6B7280;
    --gray-400: #9CA3AF;
    --gray-500: #D1D5DB;
    --gray-600: #E5E7EB;
    --gray-700: #F3F4F6;
    --gray-800: #F9FAFB;
    --gray-900: #FFFFFF;
  }
}

/* ===== PRINT STYLES ===== */
@media print {

  .navbar,
  .btn,
  .modal {
    display: none !important;
  }

  .card {
    box-shadow: none;
    border: 1px solid var(--gray-300);
  }

  .grid {
    grid-template-columns: 1fr !important;
  }
}

/* ===== ACESSIBILIDADE ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus styles */
*:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* ===== CUSTOMIZAÇÕES ESPECÍFICAS DO PORTAL ===== */
.portal-header {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: white;
  padding: var(--space-2xl) 0;
  text-align: center;
}

.portal-header h1 {
  font-size: var(--font-size-4xl);
  font-weight: 700;
  margin-bottom: var(--space-md);
}

.portal-header p {
  font-size: var(--font-size-lg);
  opacity: 0.9;
}

@media (max-width: 639px) {
  .portal-header {
    padding: var(--space-xl) 0;
  }

  .portal-header h1 {
    font-size: var(--font-size-3xl);
  }

  .portal-header p {
    font-size: var(--font-size-base);
  }
}

.material-card {
  transition: all 0.3s ease;
  cursor: pointer;
}

.material-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.price-tag {
  background: var(--success-color);
  color: white;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: var(--font-size-sm);
}

.price-tag.free {
  background: var(--gray-500);
}

.price-tag.premium {
  background: var(--accent-color);
}

/* ===== RESPONSIVE FIXES ESPECÍFICOS ===== */
@media (max-width: 639px) {

  /* Ajustes para mobile */
  .flex-col-mobile {
    flex-direction: column;
  }

  .w-full-mobile {
    width: 100% !important;
  }

  .text-center-mobile {
    text-align: center;
  }

  .px-mobile {
    padding-left: var(--space-md);
    padding-right: var(--space-md);
  }

  .py-mobile {
    padding-top: var(--space-md);
    padding-bottom: var(--space-md);
  }
}

@media (min-width: 640px) and (max-width: 1023px) {

  /* Ajustes para tablet */
  .tablet-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  .tablet-flex-row {
    flex-direction: row;
  }
}

/* ===== FIXES PARA PROBLEMAS COMUNS ===== */
.overflow-hidden {
  overflow: hidden;
}

.overflow-x-auto {
  overflow-x: auto;
}

.overflow-y-auto {
  overflow-y: auto;
}

.min-h-screen {
  min-height: 100vh;
}

.w-full {
  width: 100%;
}

.h-full {
  height: 100%;
}

.flex-1 {
  flex: 1;
}

/* Garantir que imagens sejam responsivas */
img {
  max-width: 100%;
  height: auto;
}

/* Garantir que vídeos sejam responsivos */
video {
  max-width: 100%;
  height: auto;
}

/* Fix para elementos que podem quebrar o layout */
* {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ========================================
   DARK MODE TEXT VISIBILITY FIXES
   ======================================== */
html.dark .bg-white,
html.dark .bg-gray-50,
html.dark .bg-gray-100,
html.dark [class*="bg-white"] {
  color: inherit !important;
}

html.dark input,
html.dark select,
html.dark textarea {
  color: #f8fafc !important;
  background-color: #1e293b !important;
  border-color: #475569 !important;
}

html.dark option {
  background-color: #1e293b !important;
  color: #f8fafc !important;
}

/* ========================================
   PAGINATION FALLBACK (NON-TAILWIND)
   ======================================== */
nav[role="navigation"] {
    display: flex;
    justify-content: center;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
}

nav[role="navigation"] .relative.inline-flex {
    display: flex !important;
    gap: 0.25rem;
}

nav[role="navigation"] a, 
nav[role="navigation"] span[aria-current="page"] > span {
    padding: 0.5rem 0.75rem !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 0.375rem !important;
    font-size: 0.875rem !important;
    color: #374151 !important;
    background-color: #ffffff !important;
    text-decoration: none !important;
}

nav[role="navigation"] a:hover {
    background-color: #f3f4f6 !important;
}

nav[role="navigation"] span[aria-current="page"] > span {
    background-color: #0891b2 !important; /* cyan-600 */
    color: #ffffff !important;
    border-color: #0891b2 !important;
}

.dark nav[role="navigation"] a,
.dark nav[role="navigation"] span[aria-current="page"] > span {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #f1f5f9 !important;
}

.dark nav[role="navigation"] span[aria-current="page"] > span {
    background-color: #0891b2 !important;
    color: #ffffff !important;
}
