:root {
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Palette - Dark Mode Premium */
  --bg-dark: #0B0F19;
  --bg-surface: #111827;
  --bg-card: #172033;
  --bg-card-hover: #1E293B;
  --bg-input: #0D1322;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.3);

  /* Brand Accents */
  --primary: #6366F1;
  --primary-hover: #4F46E5;
  --primary-light: rgba(99, 102, 241, 0.15);
  
  --success: #10B981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --warning: #F59E0B;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #EF4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --info: #3B82F6;
  --info-bg: rgba(59, 130, 246, 0.12);

  /* Text Colors */
  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  background: #0b1120;
}

/* Linha 1: Top Bar */
.header-top-bar {
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  height: 56px;
  width: 100%;
}

.header-top-inner {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
}

.header-brand-col {
  justify-self: start;
  display: flex;
  align-items: center;
}

.header-switcher-col {
  justify-self: center;
  display: flex;
  align-items: center;
}

.header-actions-col {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-user-btns {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding-left: 0.65rem;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
}

.header-user-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  user-select: none;
}

.header-user-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.header-btn-logout:hover {
  color: #f87171 !important;
  background: rgba(239, 68, 68, 0.15) !important;
  border-color: rgba(239, 68, 68, 0.35) !important;
}

/* Linha 2: Nav Bar */
.header-nav-bar {
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  height: 48px;
  width: 100%;
  overflow: hidden;
}

.header-nav-inner {
  max-width: 1550px;
  width: 100%;
  margin: 0 auto;
  padding: 0 0.75rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.header-nav-inner::-webkit-scrollbar {
  display: none;
}

/* Nav Menu Centralizado e Alinhado ("No Esquadro", Sem Cortar) */
.nav-menu {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: auto;
  padding: 3px 6px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

.nav-item {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.775rem;
  font-weight: 600;
  padding: 0.32rem 0.52rem;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  white-space: nowrap;
  transition: all 0.16s ease;
  user-select: none;
  letter-spacing: -0.01em;
}

.nav-item svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  flex-shrink: 0;
}

.nav-item:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

.nav-item.active {
  color: #ffffff;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  border-color: rgba(129, 140, 248, 0.4);
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.38);
  font-weight: 700;
}

/* Telas padrão / Laptops (1366px - 1440px) */
@media (max-width: 1440px) {
  .nav-item {
    padding: 0.3rem 0.48rem;
    font-size: 0.76rem;
    gap: 0.28rem;
  }
}

@media (max-width: 1366px) {
  .nav-item {
    padding: 0.28rem 0.44rem;
    font-size: 0.74rem;
    gap: 0.24rem;
  }
  .nav-menu {
    gap: 0.2rem;
    padding: 2px 4px;
  }
}

/* Telas menores (<= 1200px) */
@media (max-width: 1200px) {
  .nav-item {
    padding: 0.25rem 0.36rem;
    font-size: 0.71rem;
    gap: 0.2rem;
  }
  .nav-item svg {
    width: 12px;
    height: 12px;
  }
  .nav-menu {
    gap: 0.15rem;
  }
}

/* Tablets e Mobile (<= 1024px) */
@media (max-width: 1024px) {
  .header-top-bar {
    height: auto;
  }
  .header-top-inner {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
  }
  .header-switcher-col {
    order: 3;
    width: 100%;
    justify-content: center;
  }
  .header-nav-inner {
    justify-content: flex-start;
    padding: 0 0.5rem;
  }
  .nav-menu {
    margin: 0;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #6366F1 0%, #4338CA 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

.brand-logo svg {
  width: 18px;
  height: 18px;
  stroke: #ffffff;
}

.brand-title {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.brand-badge {
  font-size: 0.6rem;
  font-weight: 700;
  background: rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.4);
  padding: 0.1rem 0.4rem;
  border-radius: 9999px;
  text-transform: uppercase;
}

/* Status Badges */
.header-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.03);
}

.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #F59E0B;
  box-shadow: 0 0 6px #F59E0B;
}

.status-pill .dot.online {
  background: #10B981;
  box-shadow: 0 0 6px #10B981;
}

.status-pill.status-env {
  border-color: rgba(245, 158, 11, 0.3);
  color: #FCD34D;
}

.status-pill.status-env.production {
  border-color: rgba(16, 185, 129, 0.3);
  color: #6EE7B7;
}

.status-pill.status-env.production .dot {
  background: #10B981;
  box-shadow: 0 0 6px #10B981;
}

/* Main Content */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.25s ease forwards;
}

.tab-pane.active {
  display: block;
}

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

/* Hero Banner (Compact & Sleek) */
.hero-banner {
  background: linear-gradient(135deg, #1E1B4B 0%, #172033 100%);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.5rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.hero-info h2 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 0.2rem;
}

.hero-info p {
  color: var(--text-secondary);
  max-width: 680px;
  font-size: 0.825rem;
  line-height: 1.35;
  margin-bottom: 0;
}

/* Page Title Row */
.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
}

.page-title-row h2 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.page-title-row p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Stats Grid (Compact & Responsive) */
.stats-grid, .kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card, .kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.9rem 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  transition: all 0.2s ease;
}

.stat-card:hover, .kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-highlight);
  box-shadow: var(--shadow-md);
}

.stat-card.stat-card-wide {
  grid-column: span 2;
}

@media (max-width: 900px) {
  .stat-card.stat-card-wide {
    grid-column: span 1;
  }
}

.stat-icon, .kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg, .kpi-icon svg {
  width: 22px;
  height: 22px;
  max-width: 22px;
  max-height: 22px;
}

.icon-blue { background: rgba(59, 130, 246, 0.15); color: #60A5FA; }
.icon-green { background: rgba(16, 185, 129, 0.15); color: #34D399; }
.icon-yellow { background: rgba(245, 158, 11, 0.15); color: #FBBF24; }
.icon-red { background: rgba(239, 68, 68, 0.15); color: #F87171; }
.icon-purple { background: rgba(168, 85, 247, 0.15); color: #C084FC; }

.stat-details, .kpi-content {
  display: flex;
  flex-direction: column;
}

.stat-label, .kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value, .kpi-value {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0.1rem 0;
}

.highlight-value {
  color: #A78BFA;
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Card */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.card-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.card-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.step-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 0.5rem;
}

/* Buttons */
.btn {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.btn svg {
  width: 16px;
  height: 16px;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: #DC2626;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 0.9rem 1.75rem;
  font-size: 1rem;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1.25rem;
}

.col-1 { grid-column: span 1; }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; }
.col-8 { grid-column: span 8; }
.col-9 { grid-column: span 9; }
.col-10 { grid-column: span 10; }
.col-11 { grid-column: span 11; }
.col-12 { grid-column: span 12; }

@media (max-width: 900px) {
  .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9 {
    grid-column: span 12;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select,
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.9rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.disabled-input {
  opacity: 0.7;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.02) !important;
}

.font-mono {
  font-family: var(--font-mono);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.input-with-button {
  display: flex;
  gap: 0.5rem;
}

.input-with-button input {
  flex: 1;
}

/* Item Card (for dynamic items in NF-e form) */
.item-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1rem;
  position: relative;
  transition: border-color 0.2s;
}

.item-card:hover {
  border-color: var(--border-highlight);
}

.item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.item-number-badge {
  font-size: 0.8rem;
  font-weight: 700;
  color: #A5B4FC;
  background: rgba(99, 102, 241, 0.2);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
}

.btn-remove-item {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.btn-remove-item:hover {
  background: var(--danger-bg);
}

/* Checkout Summary */
.checkout-summary {
  background: var(--bg-card);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-top: 1.75rem;
  box-shadow: var(--shadow-md);
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.summary-row.total-row {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  margin-top: 0.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.total-badge {
  font-size: 1.6rem;
  font-weight: 800;
  color: #34D399;
  letter-spacing: -0.02em;
}

.summary-actions {
  margin-top: 1.25rem;
  display: flex;
  justify-content: flex-end;
}

/* Data Tables */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.825rem;
}

.data-table th {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
  font-size: 0.8rem;
}

.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-success { background: var(--success-bg); color: #34D399; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-warning { background: var(--warning-bg); color: #FBBF24; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-danger { background: var(--danger-bg); color: #F87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.badge-info { background: var(--info-bg); color: #60A5FA; border: 1px solid rgba(59, 130, 246, 0.3); }
.badge-muted { background: rgba(255, 255, 255, 0.08); color: var(--text-muted); }

/* Table Action Buttons - Compact & Elegant */
.action-buttons {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  white-space: nowrap;
}

.data-table-compact {
  font-size: 0.78rem;
}
.data-table-compact th {
  padding: 0.4rem 0.5rem;
  font-size: 0.67rem;
}
.data-table-compact td {
  padding: 0.4rem 0.5rem;
  font-size: 0.78rem;
}
.btn-xs {
  padding: 2px 7px !important;
  font-size: 0.72rem !important;
  line-height: 1.4 !important;
  border-radius: 4px !important;
}

.btn-action,
.btn-icon {
  width: 28px !important;
  height: 28px !important;
  min-width: 28px !important;
  max-width: 28px !important;
  padding: 0 !important;
  border-radius: var(--radius-sm) !important;
  background: rgba(255, 255, 255, 0.04) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: var(--text-secondary) !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  transition: all 0.15s ease !important;
  box-sizing: border-box !important;
}

.btn-action svg,
.btn-icon svg {
  width: 14px !important;
  height: 14px !important;
  flex-shrink: 0;
}

.btn-action:hover,
.btn-icon:hover {
  background: var(--primary) !important;
  color: #ffffff !important;
  border-color: var(--primary) !important;
  transform: translateY(-1px);
}

.btn-action.text-danger:hover,
.btn-icon.text-danger:hover {
  background: var(--danger) !important;
  border-color: var(--danger) !important;
  color: #ffffff !important;
}

.btn-action.text-success,
.btn-icon.text-success {
  color: #34D399 !important;
  border-color: rgba(16, 185, 129, 0.3) !important;
}

#nfse-table, #notas-table {
  width: 100%;
  table-layout: auto;
}

#nfse-table th, #nfse-table td,
#notas-table th, #notas-table td {
  padding: 0.5rem 0.55rem;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.filter-group {
  flex: 1;
}

.filter-group.select-group {
  flex: 0 0 240px;
}

/* Sub-tabs */
.tabs-subnav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.subtab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.subtab-btn:hover {
  color: var(--text-primary);
}

.subtab-btn.active {
  background: rgba(99, 102, 241, 0.15);
  color: #A5B4FC;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.subtab-pane {
  display: none;
}

.subtab-pane.active {
  display: block;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  padding: 1.5rem;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.modal-backdrop.open .modal-card {
  transform: scale(1);
}

.modal-card.modal-lg {
  max-width: 660px;
}

.modal-card.modal-xl {
  max-width: 1050px;
}

.xml-dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  padding: 2.2rem 1.5rem;
  text-align: center;
  background: rgba(15, 23, 42, 0.5);
  cursor: pointer;
  transition: all 0.2s ease;
}

.xml-dropzone:hover, .xml-dropzone.dragover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.12);
  transform: translateY(-2px);
}

.modal-header {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.35rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 1.1rem 1.25rem;
  max-height: 75vh;
  overflow-y: auto;
}

.modal-body .form-grid {
  gap: 0.75rem;
}

.modal-body .form-group {
  gap: 0.3rem;
}

.modal-body input[type="text"],
.modal-body input[type="password"],
.modal-body input[type="email"],
.modal-body input[type="number"],
.modal-body select,
.modal-body textarea {
  padding: 0.5rem 0.75rem;
  font-size: 0.825rem;
}

.modal-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.85rem;
  line-height: 1.35;
}

.modal-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 2000;
}

.toast {
  min-width: 300px;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  animation: slideInRight 0.25s ease forwards;
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-error { border-left: 4px solid var(--danger); }
.toast.toast-info { border-left: 4px solid var(--primary); }

.toast-message {
  font-size: 0.875rem;
  color: var(--text-primary);
  flex: 1;
}

@media (max-width: 768px) {
  .header-container {
    height: auto;
    padding: 1rem;
    flex-direction: column;
    align-items: stretch;
  }
  .nav-menu {
    overflow-x: auto;
    padding-bottom: 0.5rem;
  }
  .hero-banner {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ==========================================================================
   Company Switcher & Portal do Contador
   ========================================================================== */
.company-switcher-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(99, 102, 241, 0.35);
  padding: 0.38rem 0.85rem;
  border-radius: 9px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: all 0.2s ease;
}

.company-switcher-box:hover {
  border-color: rgba(129, 140, 248, 0.6);
  background: rgba(30, 41, 59, 0.85);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.25);
}

.switcher-icon {
  font-size: 1.15rem;
}

.switcher-content {
  display: flex;
  flex-direction: column;
}

.switcher-label {
  font-size: 0.6rem;
  font-weight: 800;
  color: #818cf8;
  letter-spacing: 0.06em;
  line-height: 1.1;
}

.header-empresa-dropdown {
  background: transparent;
  border: none;
  color: #f8fafc;
  font-size: 0.825rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  max-width: 240px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-empresa-dropdown option {
  background: #0f172a;
  color: #f8fafc;
}

.btn-icon-add, .btn-icon-edit {
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon-add {
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #a5b4fc;
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-icon-add:hover {
  background: var(--primary);
  color: #fff;
}

.btn-icon-edit {
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
}

.btn-icon-edit:hover {
  background: #0284c7;
  color: #fff;
}

/* Faturamento & Mensalidades */
.faturamento-banner {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.98) 100%);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 1.75rem;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.faturamento-grid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  flex-wrap: wrap;
}

.faturamento-info {
  flex: 1;
  min-width: 280px;
}

.faturamento-info h3 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #f8fafc;
  margin: 0.5rem 0;
}

.faturamento-info p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0;
}

.faturamento-stats {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.fat-stat-box {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.fat-stat-box.highlight {
  border-color: rgba(16, 185, 129, 0.5);
  background: rgba(16, 185, 129, 0.08);
}

.fat-stat-box.highlight .fat-stat-val {
  color: #34d399;
}

.fat-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.fat-stat-val {
  font-size: 1.35rem;
  font-weight: 800;
  color: #f8fafc;
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #334155;
  transition: .3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--success);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* ============================================
   Login Screen & Logout Styles
   ============================================ */
.login-container {
  width: 100%;
  max-width: 440px;
  padding: 1.5rem;
  animation: fadeInDown 0.35s ease-out;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  backdrop-filter: blur(16px);
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  margin-bottom: 0.75rem;
  color: var(--primary);
}

.login-logo h1 {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  letter-spacing: -0.02em;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 2rem;
}

.login-card .form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.login-card .form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.login-card .form-group input {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 0.2s ease;
}

.login-card .form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.btn-block {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.75rem;
}

.login-error {
  margin-top: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  color: #fca5a5;
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.4;
  animation: fadeInDown 0.2s ease-out;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

/* Nav Logout Button */
.nav-logout {
  margin-left: auto;
  color: var(--text-muted);
  transition: all 0.2s ease;
  cursor: pointer;
}

.nav-logout:hover {
  color: var(--danger) !important;
  background: var(--danger-bg) !important;
}

/* --- Dual Environment Switcher & Keys Component --- */
.env-switcher-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.env-segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: rgba(15, 23, 42, 0.7);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.env-segment {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
}

.env-segment:hover {
  background: rgba(255, 255, 255, 0.04);
  color: #ffffff;
}

.env-segment-icon {
  font-size: 1.6rem;
  line-height: 1;
  filter: grayscale(0.6);
  transition: filter 0.2s;
}

.env-segment.active .env-segment-icon {
  filter: none;
}

.env-segment-text {
  display: flex;
  flex-direction: column;
}

.env-segment-text strong {
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.env-segment-text small {
  font-size: 0.75rem;
  opacity: 0.8;
  margin-top: 2px;
}

#btn-env-sandbox.active {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fbbf24;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.15);
}

#btn-env-production.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.15);
}

/* Env Banner */
.env-banner {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 18px;
  border-radius: 10px;
  transition: all 0.25s ease;
}

.banner-sandbox {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.banner-production {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.env-banner-icon {
  font-size: 1.8rem;
  line-height: 1;
}

/* Dual Keys Grid */
.dual-keys-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 860px) {
  .env-segmented-control {
    grid-template-columns: 1fr;
  }
  .dual-keys-grid {
    grid-template-columns: 1fr;
  }
}

.key-card {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.key-card.active-card {
  border-color: rgba(99, 102, 241, 0.4);
  background: rgba(23, 32, 51, 0.7);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.key-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

/* Interactive Topbar Status Pill */
.status-pill.status-env {
  cursor: pointer;
  transition: all 0.2s ease;
}

.status-pill.status-env:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}


