:root {
  --brand-primary: #1e3a8a;
  --brand-secondary: #2563eb;
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  color-scheme: light;
}

html.dark {
  --bg-app: #0b0f19;
  --bg-card: #151d2e;
  --bg-subtle: #1e293b;
  --border-color: #27354f;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  color-scheme: dark;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  transition: background-color 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
}

/* Scrollbar estilizada */
.scrollbar-thin::-webkit-scrollbar,
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.scrollbar-thin::-webkit-scrollbar-track,
::-webkit-scrollbar-track {
  background: #f1f5f9;
}

html.dark .scrollbar-thin::-webkit-scrollbar-track,
html.dark ::-webkit-scrollbar-track {
  background: #0f172a;
}

.scrollbar-thin::-webkit-scrollbar-thumb,
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

html.dark .scrollbar-thin::-webkit-scrollbar-thumb,
html.dark ::-webkit-scrollbar-thumb {
  background: #334155;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.modal-backdrop {
  background-color: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
}

/* ============================================================
   TEMA ESCURO (DARK / NIGHT MODE) — OVERRIDES GLOBAIS
   ============================================================ */

html.dark body {
  background-color: #0b0f19 !important;
  color: #f1f5f9 !important;
}

/* Cartões e Contentores Brancos */
html.dark .bg-white {
  background-color: #151d2e !important;
  color: #f1f5f9 !important;
}

/* Fundos Secundários e Cabeçalhos de Tabelas */
html.dark .bg-slate-50,
html.dark .bg-slate-50\/70,
html.dark .bg-slate-50\/60,
html.dark .bg-slate-50\/40,
html.dark .bg-slate-100\/50,
html.dark .bg-slate-100 {
  background-color: #1a2337 !important;
}

html.dark .hover\:bg-slate-50:hover,
html.dark .hover\:bg-slate-100:hover,
html.dark .hover\:bg-slate-100\/80:hover {
  background-color: #22304a !important;
}

/* Bordas e Divisórias */
html.dark .border-slate-100,
html.dark .border-slate-200,
html.dark .divide-slate-100 > :not([hidden]) ~ :not([hidden]),
html.dark .divide-slate-200 > :not([hidden]) ~ :not([hidden]) {
  border-color: #27354f !important;
}

html.dark .border-slate-300 {
  border-color: #374b6e !important;
}

/* Cores de Texto */
html.dark .text-slate-900,
html.dark .text-slate-800 {
  color: #f8fafc !important;
}

html.dark .text-slate-700,
html.dark .text-slate-600 {
  color: #cbd5e1 !important;
}

html.dark .text-slate-500,
html.dark .text-slate-400 {
  color: #94a3b8 !important;
}

/* Inputs, Selects e Textareas */
html.dark input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
html.dark select,
html.dark textarea {
  background-color: #0d1424 !important;
  color: #f8fafc !important;
  border-color: #2d3e5e !important;
}

html.dark input:focus,
html.dark select:focus,
html.dark textarea:focus {
  border-color: #38bdf8 !important;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25) !important;
}

html.dark input::placeholder,
html.dark textarea::placeholder {
  color: #64748b !important;
}

/* Dropdowns e Menus Flutuantes (Comboboxes) */
html.dark .ws-combobox-wrap input {
  background-color: #0d1424 !important;
  color: #f8fafc !important;
}

html.dark [id^="ws-art-dropdown-"] {
  background-color: #151d2e !important;
  border-color: #2d3e5e !important;
}

html.dark .ws-art-option:hover {
  background-color: #1e2c46 !important;
}

/* Cabeçalho da Aplicação */
html.dark header {
  background-color: #111827 !important;
  border-color: #1f2937 !important;
}

html.dark header .bg-slate-50\/70 {
  background-color: #151d2e !important;
  border-color: #1f2937 !important;
}

html.dark header nav button:not(.bg-blue-900) {
  color: #94a3b8 !important;
}

html.dark header nav button:not(.bg-blue-900):hover {
  background-color: #1e293b !important;
  color: #f8fafc !important;
}

/* Modal */
html.dark #global-modal .bg-white {
  background-color: #151d2e !important;
  border-color: #27354f !important;
}

html.dark #global-modal .bg-slate-900 {
  background-color: #0d1424 !important;
  border-bottom: 1px solid #27354f !important;
}

/* Badges e Destaques em Dark Mode */
html.dark .badge.bg-blue-100 { background-color: #1e3a8a !important; color: #bfdbfe !important; }
html.dark .badge.bg-blue-200 { background-color: #1d4ed8 !important; color: #dbeafe !important; }
html.dark .badge.bg-indigo-100 { background-color: #312e81 !important; color: #c7d2fe !important; }
html.dark .badge.bg-emerald-100 { background-color: #064e3b !important; color: #a7f3d0 !important; }
html.dark .badge.bg-emerald-200 { background-color: #047857 !important; color: #d1fae5 !important; }
html.dark .badge.bg-amber-100 { background-color: #78350f !important; color: #fde68a !important; }
html.dark .badge.bg-amber-200 { background-color: #b45309 !important; color: #fef3c7 !important; }
html.dark .badge.bg-purple-100 { background-color: #581c87 !important; color: #e9d5ff !important; }
html.dark .badge.bg-slate-100,
html.dark .badge.bg-slate-200 { background-color: #334155 !important; color: #e2e8f0 !important; }

/* Paineis Especiais (Banner Sky, Indigo, Emerald) */
html.dark .bg-sky-50 {
  background-color: #082f49 !important;
  border-color: #0369a1 !important;
  color: #e0f2fe !important;
}
html.dark .bg-sky-50 .text-sky-950,
html.dark .bg-sky-50 .text-sky-900 {
  color: #f0f9ff !important;
}
html.dark .bg-sky-50 .text-sky-800 {
  color: #bae6fd !important;
}

html.dark .bg-indigo-50 {
  background-color: #1e1b4b !important;
  border-color: #3730a3 !important;
  color: #e0e7ff !important;
}

html.dark .bg-emerald-50,
html.dark .bg-emerald-50\/60,
html.dark .bg-emerald-50\/40 {
  background-color: #022c22 !important;
  color: #a7f3d0 !important;
}

/* ============================================================
   RESPONSIVIDADE (MOBILE & TABLETS)
   ============================================================ */

/* Suavização de Tabelas em Ecrãs Pequenos */
.table-responsive-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0.75rem;
}

/* Garantir alvos de toque adequados */
@media (max-width: 768px) {
  header nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  
  header nav button {
    white-space: nowrap;
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
  }

  main {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
    padding-top: 1rem !important;
  }

  .modal-backdrop > div {
    max-height: 92vh !important;
    margin: 0.5rem !important;
  }
}
