/* ==============================================================================
   📐 DESIGN SYSTEM OFICIAL — MYAPPSHUB
   Padrão de Qualidade & Refinamento Autentic Sovereign
   Suporte a Tema Claro / Escuro (Dark Mode Persistente)
   Referência Normativa: MD MyAppshub/DS-MyAppsHub.md
   ============================================================================== */

:root {
  /* 1. Cores Primárias (Brand Oficial) */
  --color-brand:        #e11d2a;                 /* Vermelho Primário MyAppsHub */
  --color-brand-light:  #ff3b46;                 /* Hover de botões primários */
  --color-brand-dark:   #b3121c;                 /* Estados de erro e ênfases escuras */
  --color-brand-10:     rgba(225, 29, 42, 0.10); /* Fundos de tags, ícones ativos e badges */
  --color-brand-05:     rgba(225, 29, 42, 0.05); /* Gradientes sutis */
  --color-brand-scroll: rgba(185, 28, 28, 0.40); /* Barra de rolagem em repouso */

  /* 2. Cores Neutras — Modo Claro (Default) */
  --color-ink:          #0a0a0a;                 /* Texto principal (100%) */
  --color-ink-70:       rgba(10, 10, 10, 0.70);  /* Botões secundários e tabelas (70%) */
  --color-ink-60:       rgba(10, 10, 10, 0.60);  /* Textos auxiliares e parágrafos (60%) */
  --color-ink-50:       rgba(10, 10, 10, 0.50);  /* Placeholders e textos inativos (50%) */
  --color-ink-40:       rgba(10, 10, 10, 0.40);  /* Labels em caixa alta (40%) */

  --color-paper:        #f8f9fa;                 /* Background geral da aplicação */
  --color-surface:      #ffffff;                 /* Superfície de cards, modais e inputs */
  --color-surface-hover:#f1f3f5;
  --color-border:       #e2e8f0;                 /* Bordas de separação estrutural */
  --color-modal-head:   linear-gradient(180deg, rgba(225, 29, 42, 0.04) 0%, rgba(255, 255, 255, 0) 100%);
  --color-input-bg:     #ffffff;
}

/* ==============================================================================
   MODO ESCURO OFICIAL (DARK THEME)
   ============================================================================== */
html.dark,
[data-theme="dark"] {
  --color-ink:          #f8fafc;                 /* Texto principal no modo escuro */
  --color-ink-70:       rgba(248, 250, 252, 0.75);
  --color-ink-60:       rgba(248, 250, 252, 0.60);
  --color-ink-50:       rgba(248, 250, 252, 0.45);
  --color-ink-40:       rgba(248, 250, 252, 0.32);

  --color-paper:        #090a0d;                 /* Fundo ultra dark elegante */
  --color-surface:      #11141c;                 /* Superfície de cards e modais */
  --color-surface-hover:#181d28;
  --color-border:       #1f2430;                 /* Bordas sutis no escuro */
  --color-brand-10:     rgba(225, 29, 42, 0.18);
  --color-brand-05:     rgba(225, 29, 42, 0.08);
  --color-brand-scroll: rgba(225, 29, 42, 0.50);
  --color-modal-head:   linear-gradient(180deg, rgba(225, 29, 42, 0.08) 0%, rgba(17, 20, 28, 0) 100%);
  --color-input-bg:     #0d0f15;
}

/* ==============================================================================
   RESET & TIPOGRAFIA MONTSERRAT
   ============================================================================== */

* {
  box-sizing: border-box;
}

body {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--color-paper);
  color: var(--color-ink);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.text-ink       { color: var(--color-ink); }
.text-ink-70    { color: var(--color-ink-70); }
.text-ink-60    { color: var(--color-ink-60); }
.text-ink-50    { color: var(--color-ink-50); }
.text-ink-40    { color: var(--color-ink-40); }

/* ==============================================================================
   SCROLLBAR BRAND OFICIAL (Regra de Ouro do Scroll)
   ============================================================================== */

::-webkit-scrollbar,
.main-content-scroll::-webkit-scrollbar,
.table-body-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track,
.main-content-scroll::-webkit-scrollbar-track,
.table-body-container::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb,
.main-content-scroll::-webkit-scrollbar-thumb,
.table-body-container::-webkit-scrollbar-thumb {
  background-color: var(--color-brand-scroll);
  border-radius: 10px;
  transition: background-color 0.25s ease;
}

::-webkit-scrollbar-thumb:hover,
.main-content-scroll::-webkit-scrollbar-thumb:hover,
.table-body-container::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-brand);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-brand-scroll) transparent;
}

/* ==============================================================================
   LAYOUT B: ARQUITETURA EM DUAS DIVS
   ============================================================================== */

.app-layout {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background-color: var(--color-paper);
}

.topbar-fixed,
.topbar-myappshub {
  flex-shrink: 0;
  width: 100%;
  height: 80px;
  z-index: 50;
  overflow: hidden;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 2px 15px rgba(0, 0, 0, 0.03);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.main-content-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 32px 36px;
  background: var(--color-paper);
}

/* ==============================================================================
   CARDS DE APLICATIVOS (PADRÃO AUTENTIC REFINADO)
   ============================================================================== */

.app-card {
  transition: all 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 20px;
  position: relative;
  overflow: hidden;
}

.app-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  transition: background 0.2s ease;
}

.app-card:hover {
  transform: translateY(-5px);
  border-color: rgba(225, 29, 42, 0.40);
  box-shadow: 0 20px 35px -10px rgba(225, 29, 42, 0.15), 0 4px 14px -2px rgba(0, 0, 0, 0.05);
}

.app-card:hover::before {
  background: linear-gradient(90deg, var(--color-brand), var(--color-brand-light));
}

.app-card:active {
  transform: translateY(-2px);
}

.app-icon-squircle {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: all 0.2s ease;
  background: var(--color-brand-10);
  border: 1px solid rgba(225, 29, 42, 0.20);
  color: var(--color-brand);
}

.app-card:hover .app-icon-squircle {
  transform: scale(1.06);
  background: rgba(225, 29, 42, 0.18);
  border-color: rgba(225, 29, 42, 0.35);
}

/* KPI Cards com Elevação Autentic */
.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
  transition: all 0.2s ease;
}

.kpi-card:hover {
  border-color: rgba(225, 29, 42, 0.30);
  box-shadow: 0 8px 24px -6px rgba(0, 0, 0, 0.06);
}

/* ==============================================================================
   INPUTS & BOTÕES BRAND
   ============================================================================== */

.brand-input {
  width: 100%;
  padding: 11px 16px;
  font-size: 13px;
  font-family: 'Montserrat', sans-serif;
  color: var(--color-ink);
  background-color: var(--color-input-bg);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  transition: all 0.2s ease;
  outline: none;
}

.brand-input:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px var(--color-brand-10);
}

.brand-input::placeholder {
  color: var(--color-ink-50);
}

.btn-brand-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-brand);
  color: #ffffff;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 22px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 16px 0 rgba(225, 29, 42, 0.25);
}

.btn-brand-primary:hover {
  background-color: var(--color-brand-light);
  transform: translateY(-1px);
  box-shadow: 0 6px 22px 0 rgba(225, 29, 42, 0.35);
}

.btn-brand-primary:active {
  background-color: var(--color-brand-dark);
  transform: translateY(0);
}

/* ==============================================================================
   DUAL-DIV EM TABELAS
   ============================================================================== */

.table-head-container {
  width: 100%;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding-right: 8px; /* Compensa a scrollbar lateral à direita */
  flex-shrink: 0;
}

.table-body-container {
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--color-surface);
}

/* ==============================================================================
   MODAIS & TOASTS CENTRALIZADOS
   ============================================================================== */

.modal-backdrop {
  backdrop-filter: blur(8px);
  background: rgba(10, 10, 10, 0.65);
  animation: modalFadeIn 0.2s ease-out forwards;
}

.modal-content-anim {
  animation: modalScaleUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  background: var(--color-surface);
  border-color: var(--color-border);
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalScaleUp {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* TOAST CENTRALIZADO NA PARTE INFERIOR (SOVEREIGN TOAST) */
.toast-container {
  position: fixed !important;
  bottom: 32px !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  z-index: 9999999 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  gap: 10px !important;
  pointer-events: none !important;
  width: auto !important;
  max-width: 90vw !important;
  margin: 0 !important;
}

.toast-item {
  pointer-events: auto;
  animation: toastSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes toastSlideUp {
  0% {
    opacity: 0;
    transform: translateY(24px) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ==============================================================================
   IFRAME WORKSPACE
   ============================================================================== */

.iframe-container {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
}

/* Toggle Switch do Tema */
.theme-toggle-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-ink-70);
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
  color: var(--color-brand);
  border-color: var(--color-brand);
  transform: scale(1.05);
}

/* ==============================================================================
   CORREÇÃO DE AUTOFILL NATIVO DO NAVEGADOR
   ============================================================================== */

input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-text-fill-color: var(--color-ink) !important;
  -webkit-box-shadow: 0 0 0px 1000px var(--color-input-bg) inset !important;
  box-shadow: 0 0 0px 1000px var(--color-input-bg) inset !important;
  transition: background-color 5000s ease-in-out 0s;
}

/* ==============================================================================
   SIDEBAR LATERAL FINA (ICON RAIL) — ESTILO MINIMALISTA EXECUTIVO
   ============================================================================== */

.app-container-sidebar {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background-color: var(--color-paper);
}

.sidebar-rail {
  width: 68px;
  height: 100vh;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  background-color: var(--color-surface);
  border-right: 1px solid var(--color-border);
  z-index: 40;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.rail-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-ink-60);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

.rail-btn:hover {
  color: var(--color-brand);
  background: var(--color-brand-10);
  border-color: rgba(225, 29, 42, 0.25);
  transform: scale(1.05);
}

.rail-btn.active {
  color: #ffffff;
  background: var(--color-brand);
  border-color: var(--color-brand);
  box-shadow: 0 4px 14px rgba(225, 29, 42, 0.35);
}

/* ==============================================================================
   BARRA DE ABAS SUPERIOR MULTI-IFRAME WORKSPACE
   ============================================================================== */

.top-tab-bar {
  height: 48px;
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 10px;
  flex-shrink: 0;
  position: relative;
  z-index: 50;
  overflow: visible;
}

.tabs-scroll-area {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs-scroll-area::-webkit-scrollbar {
  display: none;
}

.tab-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-ink-60);
  background: var(--color-paper);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
  user-select: none;
}

.tab-pill:hover {
  color: var(--color-ink);
  border-color: rgba(225, 29, 42, 0.3);
  background: var(--color-surface);
}

.tab-pill.active {
  color: var(--color-brand);
  background: var(--color-surface);
  border-color: var(--color-brand);
  box-shadow: 0 2px 8px rgba(225, 29, 42, 0.15);
}

.top-bar-logo-btn {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0 4px;
  user-select: none;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.top-bar-logo-btn:hover {
  transform: scale(1.10);
}

.top-bar-logo-btn:active {
  transform: scale(0.95);
}

.top-bar-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-ink-60);
  background: var(--color-paper);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: all 0.18s ease;
  user-select: none;
}

.top-bar-icon-btn:hover {
  color: var(--color-brand);
  border-color: rgba(225, 29, 42, 0.3);
  background: var(--color-surface);
  transform: translateY(-1px);
}

.top-bar-icon-btn:active {
  transform: translateY(0);
}

.settings-menu-dropdown {
  position: fixed;
  top: 54px;
  right: 16px;
  width: 240px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
  z-index: 9999999;
  display: none;
  animation: dropdownFade 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  overflow: hidden;
}

.settings-menu-dropdown.open {
  display: block !important;
}

.settings-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-ink-70);
  background: transparent;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.settings-menu-item:hover {
  background-color: var(--color-brand-10);
  color: var(--color-brand);
}

.tab-pill-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
  padding-left: 6px;
  border-left: 1px solid var(--color-border);
}

.tab-action-btn,
.tab-close-btn {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--color-ink-50);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
}

.tab-action-btn:hover,
.tab-close-btn:hover {
  background: rgba(225, 29, 42, 0.15);
  color: var(--color-brand);
}

/* ==============================================================================
   DROPDOWN CUSTOMIZADO DESIGN SYSTEM (ZERO MENU NATIVO AZUL)
   ============================================================================== */

.ds-dropdown {
  position: relative;
  width: 100%;
}

.ds-dropdown-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  font-size: 13px;
  font-family: 'Montserrat', sans-serif;
  color: var(--color-ink);
  background-color: var(--color-input-bg);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.ds-dropdown-trigger:hover,
.ds-dropdown.open .ds-dropdown-trigger {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px var(--color-brand-10);
}

.ds-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 16px 36px -8px rgba(0, 0, 0, 0.45);
  z-index: 999999;
  display: none;
  max-height: 240px;
  overflow-y: auto;
  animation: dropdownFade 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.ds-dropdown.open .ds-dropdown-menu {
  display: block;
}

@keyframes dropdownFade {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.ds-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-ink-70);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ds-dropdown-item:hover {
  background-color: var(--color-brand-10);
  color: var(--color-brand);
}

.ds-dropdown-item.selected {
  background-color: var(--color-brand-10);
  color: var(--color-brand);
  font-weight: 700;
}

/* ==============================================================================
   BOTÕES DE AÇÃO NA TABELA (EDITAR & EXCLUIR COM ÍCONES)
   ============================================================================== */

.action-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn-edit {
  color: #3b82f6;
  background: rgba(59, 130, 246, 0.10);
  border-color: rgba(59, 130, 246, 0.20);
}

.action-btn-edit:hover {
  background: #3b82f6;
  color: #ffffff;
  transform: scale(1.10);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}

.action-btn-delete {
  color: #e11d2a;
  background: rgba(225, 29, 42, 0.10);
  border-color: rgba(225, 29, 42, 0.20);
}

.action-btn-delete:hover {
  background: #e11d2a;
  color: #ffffff;
  transform: scale(1.10);
  box-shadow: 0 4px 12px rgba(225, 29, 42, 0.35);
}

/* ==============================================================================
   TELA DE LOGIN EXECUTIVA & MODERNA (REDESIGN PREMIUM)
   ============================================================================== */

.login-canvas {
  min-height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, rgba(225, 29, 42, 0.14) 0%, transparent 65%), var(--color-paper);
}

.login-glass-card {
  width: 100%;
  max-width: 440px;
  border-radius: 28px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: 0 35px 70px -15px rgba(0, 0, 0, 0.40), 0 0 0 1px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(24px);
  padding: 40px 36px;
  position: relative;
  z-index: 10;
  animation: modalScaleUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.login-glow-aura {
  position: absolute;
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, rgba(225, 29, 42, 0.20) 0%, rgba(225, 29, 42, 0) 70%);
  filter: blur(60px);
  pointer-events: none;
  z-index: 1;
}

/* ==============================================================================
   SEÇÃO RECOLHÍVEL DE CARDS (COLLAPSIBLE CATEGORIES)
   ============================================================================== */

.category-accordion-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.2s ease;
}

.category-accordion-btn:hover {
  opacity: 0.85;
}

.category-chevron {
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: inline-block;
  font-size: 11px;
}

.category-chevron.collapsed {
  transform: rotate(-90deg);
}

.category-grid-wrapper {
  transition: all 0.25s ease;
}

.category-grid-wrapper.collapsed {
  display: none;
}

