/* ============================================================================
   ISAUTO DESIGN SYSTEM — TOKENS SEMÂNTICOS (CLARO / ESCURO) & COMPONENTES BASE
   ============================================================================ */

:root,
html.dark {
  --bg-app: #121316;
  --bg-surface: #1a1c20;
  --bg-elevated: #22252a;
  --bg-subtle: #16181c;
  --bg-input: #141518;
  --bg-hover: rgba(155, 167, 191, 0.08);
  --bg-header: rgba(26, 28, 32, 0.92);
  --bg-sidebar: #16181c;

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #9ba7bf;

  --border-subtle: rgba(155, 167, 191, 0.14);
  --border-strong: rgba(155, 167, 191, 0.28);

  --accent-primary: #ee2824;
  --accent-crimson: #a51e22;
  --accent-soft: rgba(238, 40, 36, 0.16);
  --accent-border: rgba(238, 40, 36, 0.45);
  --focus-ring: #f1d53c;

  --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.26);
  --shadow-popover: 0 14px 36px rgba(0, 0, 0, 0.5);
  --scroll-track: #141517;
  --scroll-thumb: #3a3d42;
}

html.light {
  --bg-app: #f4f6f9;
  --bg-surface: #ffffff;
  --bg-elevated: #eef2f6;
  --bg-subtle: #f8fafc;
  --bg-input: #ffffff;
  --bg-hover: rgba(40, 41, 41, 0.05);
  --bg-header: rgba(255, 255, 255, 0.94);
  --bg-sidebar: #ffffff;

  --text-primary: #18191c;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --border-subtle: #e2e6ee;
  --border-strong: #cbd5e1;

  --accent-primary: #ee2824;
  --accent-crimson: #a51e22;
  --accent-soft: rgba(238, 40, 36, 0.1);
  --accent-border: rgba(238, 40, 36, 0.35);
  --focus-ring: #a51e22;

  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-popover: 0 12px 32px rgba(15, 23, 42, 0.14);
  --scroll-track: #e9edf3;
  --scroll-thumb: #cbd5e1;
}

@layer base {
  html, body {
    max-width: 100%;
    overflow-x: clip;
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: 'Montserrat', sans-serif;
    -webkit-tap-highlight-color: rgba(238, 40, 36, 0.18);
    transition: background-color 180ms cubic-bezier(0.4, 0, 0.2, 1), color 180ms cubic-bezier(0.4, 0, 0.2, 1);
  }
}

main, header, section, aside, .fin-view {
  min-width: 0;
  max-width: 100%;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

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

input[type="file"] {
  max-width: 100%;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================================
   CAMADA TEMÁTICA DE COMPATIBILIDADE (GARANTE CLARO + ESCURO EM TODO O SISTEMA)
   ============================================================================ */
html.light body {
  background-color: var(--bg-app) !important;
  color: var(--text-primary) !important;
}

html.light .bg-slate-950,
html.light .bg-slate-950\/90,
html.light .bg-slate-950\/80,
html.light .bg-slate-950\/75,
html.light .bg-slate-950\/70,
html.light .bg-slate-950\/60,
html.light .bg-slate-950\/50 {
  background-color: var(--bg-subtle) !important;
}

html.light .bg-slate-900,
html.light .bg-slate-900\/95,
html.light .bg-slate-900\/90,
html.light .bg-slate-900\/80,
html.light .bg-slate-900\/70,
html.light .bg-slate-900\/60,
html.light .bg-slate-900\/50,
html.light .from-slate-900,
html.light .to-slate-950 {
  background-color: var(--bg-surface) !important;
  --tw-gradient-from: #ffffff !important;
  --tw-gradient-to: #f8fafc !important;
  box-shadow: var(--shadow-card);
}

@media (min-width: 768px) {
  html.light .md\:bg-slate-900 {
    background-color: var(--bg-surface) !important;
    box-shadow: var(--shadow-card);
  }
  html.light .md\:border-slate-800 {
    border-color: var(--border-subtle) !important;
  }
}

html.light .bg-slate-800,
html.light .bg-slate-800\/80,
html.light .bg-slate-800\/70,
html.light .bg-slate-800\/60,
html.light .bg-slate-800\/50,
html.light .bg-slate-800\/40,
html.light .bg-slate-800\/30,
html.light .bg-slate-700 {
  background-color: var(--bg-elevated) !important;
}

html.light .hover\:bg-slate-800:hover,
html.light .hover\:bg-slate-800\/50:hover,
html.light .hover\:bg-slate-800\/40:hover,
html.light .hover\:bg-slate-800\/30:hover,
html.light .hover\:bg-slate-700:hover {
  background-color: #e2e8f0 !important;
}

html.light .border-slate-800,
html.light .border-slate-800\/80,
html.light .border-slate-800\/70,
html.light .border-slate-800\/60,
html.light .border-slate-700,
html.light .border-slate-700\/80,
html.light .border-slate-600 {
  border-color: var(--border-subtle) !important;
}

html.light .divide-slate-800\/70 > :not([hidden]) ~ :not([hidden]),
html.light .divide-slate-800\/60 > :not([hidden]) ~ :not([hidden]) {
  border-color: var(--border-subtle) !important;
}

html.light .text-white:not(.btn-isauto-primary):not(.ds-btn-primary):not(.bg-red-600):not(.bg-blue-600):not(.bg-emerald-600):not(.bg-emerald-700):not(.bg-indigo-600):not(.bg-purple-600):not(.bg-amber-600):not(.bg-rose-600):not(.bg-\[\#ee2824\]):not(.active),
html.light .text-slate-100,
html.light .text-slate-200 {
  color: var(--text-primary) !important;
}

html.light .text-slate-300 {
  color: var(--text-secondary) !important;
}

html.light .text-slate-400,
html.light .text-slate-500 {
  color: var(--text-muted) !important;
}

html.light .hover\:text-white:hover,
html.light .hover\:text-slate-100:hover,
html.light .hover\:text-slate-200:hover {
  color: var(--text-primary) !important;
}

/* Cores semânticas em contraste alto para superfícies claras (WCAG AA/AAA) */
html.light .text-purple-300,
html.light .text-purple-400 { color: #5b21b6 !important; }
html.light .text-emerald-200 { color: #064e3b !important; }
html.light .text-emerald-300 { color: #065f46 !important; }
html.light .text-emerald-400 { color: #047857 !important; }
html.light .text-blue-200 { color: #1e3a8a !important; }
html.light .text-blue-300,
html.light .text-blue-400 { color: #1d4ed8 !important; }
html.light .text-amber-200 { color: #78350f !important; }
html.light .text-amber-300 { color: #92400e !important; }
html.light .text-amber-400 { color: #b45309 !important; }
html.light .text-indigo-200 { color: #312e81 !important; }
html.light .text-indigo-300,
html.light .text-indigo-400 { color: #4338ca !important; }
html.light .text-rose-200,
html.light .text-red-200 { color: #7f1d1d !important; }
html.light .text-rose-300,
html.light .text-red-300 { color: #991b1b !important; }
html.light .text-rose-400,
html.light .text-red-400 { color: #b91c1c !important; }

/* Alertas, toasts e seções semânticas (fundo escuro -> pastel claro legível) */
html.light .bg-amber-950,
html.light .bg-amber-950\/40,
html.light .bg-amber-950\/30,
html.light .bg-amber-950\/25 {
  background-color: #fef3c7 !important;
}
html.light .bg-emerald-950,
html.light .bg-emerald-950\/70,
html.light .bg-emerald-950\/40,
html.light .bg-emerald-950\/35,
html.light .bg-emerald-950\/30,
html.light .bg-emerald-950\/10,
html.light .bg-emerald-900 {
  background-color: #d1fae5 !important;
}
html.light .hover\:bg-emerald-900:hover {
  background-color: #a7f3d0 !important;
}
html.light .bg-blue-950\/40,
html.light .bg-blue-950\/30,
html.light .bg-blue-950\/10 {
  background-color: #dbeafe !important;
}
html.light .bg-indigo-950\/50,
html.light .bg-indigo-950\/40,
html.light .bg-indigo-950\/10 {
  background-color: #e0e7ff !important;
}
html.light .bg-red-950\/40,
html.light .bg-red-950\/35,
html.light .bg-red-950\/30,
html.light .bg-rose-950,
html.light .bg-rose-950\/70,
html.light .bg-rose-950\/60,
html.light .bg-rose-900 {
  background-color: #fee2e2 !important;
}
html.light .hover\:bg-rose-900:hover {
  background-color: #fecaca !important;
}

/* Badges /5..20 sobre fundo claro: bordas levemente mais definidas */
html.light .bg-amber-500\/20 { background-color: #fef3c7 !important; }
html.light .bg-emerald-500\/20 { background-color: #d1fae5 !important; }
html.light .bg-red-500\/20,
html.light .bg-red-500\/15 { background-color: #fee2e2 !important; }
html.light .bg-blue-500\/20 { background-color: #dbeafe !important; }
html.light .bg-purple-500\/20 { background-color: #ede9fe !important; }
html.light .bg-indigo-500\/20 { background-color: #e0e7ff !important; }

html.light input,
html.light select,
html.light textarea {
  color: var(--text-primary) !important;
}
html.light input::placeholder,
html.light textarea::placeholder {
  color: var(--text-muted) !important;
}
html.light select option {
  background-color: #ffffff;
  color: #18191c;
}
html.dark select option {
  background-color: #1a1c20;
  color: #f8fafc;
}

/* ============================================================================
   COMPONENTES BASE DO DESIGN SYSTEM (.ds-*)
   ============================================================================ */
.ds-header {
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
}

.ds-sidebar {
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
}

.ds-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 1rem;
  box-shadow: var(--shadow-card);
  transition: border-color 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.ds-subcard {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 0.75rem;
}

.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 38px;
  padding: 0 0.875rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  transition: all 180ms cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}
.ds-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ds-btn-primary,
.btn-isauto-primary {
  background: linear-gradient(135deg, #ee2824 0%, #a51e22 100%);
  color: #ffffff !important;
  box-shadow: 0 4px 12px -2px rgba(238, 40, 36, 0.35);
  transition: filter 180ms ease, transform 120ms ease;
}
.ds-btn-primary:hover,
.btn-isauto-primary:hover {
  filter: brightness(1.08);
}
.ds-btn-primary:active,
.btn-isauto-primary:active {
  transform: scale(0.985);
}

.ds-btn-secondary {
  background-color: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}
.ds-btn-secondary:hover {
  background-color: var(--bg-hover);
  border-color: var(--border-strong);
}

.ds-month-stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 0.75rem;
  padding: 0.25rem;
}

.ds-stepper-btn {
  padding: 0.35rem 0.55rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: background-color 180ms ease, color 180ms ease;
}
.ds-stepper-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-elevated);
}

/* Sidebar Desktop Navigation Items */
.ds-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  min-height: 38px;
  padding: 0.45rem 0.75rem;
  border-radius: 0.625rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: all 180ms cubic-bezier(0.4, 0, 0.2, 1);
  text-align: left;
}
.ds-nav-item:hover {
  color: var(--text-primary);
  background-color: var(--bg-hover);
}
.ds-nav-item.active {
  background-color: var(--accent-soft);
  color: var(--text-primary);
  border-color: var(--accent-border);
}
.ds-nav-item.active svg {
  color: var(--accent-primary);
}

/* Navegação Principal & Sub-abas Financeiro (Mobile & Tablet) */
.mod-tab-btn {
  color: var(--text-muted);
  background: transparent;
}
.mod-tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.mod-tab-btn.active {
  background: linear-gradient(135deg, #ee2824 0%, #a51e22 100%);
  color: #ffffff !important;
  box-shadow: 0 4px 16px -2px rgba(238, 40, 36, 0.4);
}

.mob-nav-btn {
  color: var(--text-muted);
  position: relative;
}
.mob-nav-btn.active {
  color: var(--text-primary);
}
.mob-nav-btn.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 18%;
  right: 18%;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(90deg, #ee2824, #a51e22);
}
.mob-nav-btn.active svg {
  color: #ee2824;
}

.fin-subtab {
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  transition: all 180ms ease;
}
.fin-subtab:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}
.fin-subtab.active {
  background: var(--accent-soft);
  color: var(--text-primary);
  border-color: var(--accent-border);
}

/* Mobile Bottom Nav tematica */
html.light #mobileBottomNav {
  background-color: rgba(255, 255, 255, 0.96) !important;
  border-top-color: var(--border-subtle) !important;
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08) !important;
}

/* Scrollbar */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scroll-track); }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-crimson); }

/* CRM Shell */
.crm-shell {
  height: calc(100dvh - 13.5rem);
  min-height: 460px;
  max-height: 760px;
}

@media (max-width: 1023px) {
  .crm-shell {
    height: calc(100dvh - 13.5rem);
    min-height: 440px;
    max-height: none;
  }
  .crm-shell[data-mobile-view="list"] #waChatSidebar { display: flex; }
  .crm-shell[data-mobile-view="list"] #waChatPane { display: none; }
  .crm-shell[data-mobile-view="chat"] #waChatSidebar { display: none; }
  .crm-shell[data-mobile-view="chat"] #waChatPane { display: flex; }
}

@media (min-width: 1121px) and (max-width: 1480px) {
  .isauto-table-compact th,
  .isauto-table-compact td {
    padding-left: 0.55rem;
    padding-right: 0.55rem;
  }
}

/* Mobile & Tablets (<= 1120px): Tabelas em cartões empilhados */
@media (max-width: 1120px) {
  .isauto-responsive-table,
  .isauto-responsive-table tbody {
    display: block;
    width: 100%;
  }
  .isauto-responsive-table thead {
    display: none;
  }
  .isauto-responsive-table tr {
    display: block;
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 1rem;
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-card);
  }
  .isauto-responsive-table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0.45rem 0 !important;
    border-bottom: 1px dashed var(--border-subtle);
    text-align: right !important;
    white-space: normal !important;
    word-break: break-word;
  }
  .isauto-responsive-table td > * {
    min-width: 0;
    max-width: 68%;
  }
  .isauto-responsive-table td::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
    padding-top: 2px;
  }
  .isauto-responsive-table td:last-child {
    border-bottom: none;
    padding-top: 0.7rem !important;
    justify-content: flex-end;
    align-items: center;
  }
  .isauto-responsive-table td:last-child::before {
    margin-right: auto;
  }
  .isauto-responsive-table td[colspan] {
    display: block !important;
    text-align: center !important;
    border-bottom: none !important;
  }
  .isauto-responsive-table td[colspan]::before {
    display: none;
  }
}

/* Smartphone & Tablet (< 1024px): Bottom Nav spacing & touch targets >= 44px */
@media (max-width: 1023px) {
  body {
    padding-bottom: 5.5rem;
  }
  #toastContainer {
    bottom: 5.25rem;
    left: 0.75rem;
    right: 0.75rem;
  }
  main button,
  header button,
  main select,
  label[for],
  label:has(input[type="checkbox"]),
  label:has(input[type="file"]),
  #modalOverlay button,
  #modalOverlay select,
  #modalOverlay input[type="date"],
  #modalOverlay input[type="text"],
  #modalOverlay input[type="number"] {
    min-height: 44px;
  }
  header select,
  .ds-month-stepper select {
    min-height: 34px;
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    line-height: 1.25;
  }
  .touch-compact {
    min-height: 36px !important;
  }
}

@media print {
  .no-print,
  #mobileBottomNav,
  #desktopSidebar {
    display: none !important;
  }
  body {
    background: #ffffff !important;
    color: #111827 !important;
    padding-bottom: 0 !important;
  }
  .bg-slate-900, .bg-slate-950, .ds-card, .ds-subcard {
    background: #ffffff !important;
    border-color: #d1d5db !important;
    color: #111827 !important;
  }
  .text-white, .text-slate-200, .text-slate-300 {
    color: #111827 !important;
  }
}
