:root {
  --menu-active-bg: rgba(13, 110, 253, 0.1);
  --menu-active-border: #0d6efd;
  --menu-active-color: #0d6efd;
  --color-primary-dark: #1b5e3f;
  --color-primary-mid: #4a9b6f;
  --color-primary-soft: rgba(45, 106, 79, 0.12);
  --color-bg-app: #f5f5f5;
  --color-bg-card: #ffffff;
  --color-text-main: #1a1a1a;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-success: #1b5e3f;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  --color-neutral: #9ca3af;
  --color-success-soft: rgba(27, 94, 63, 0.12);
  --color-warning-soft: rgba(245, 158, 11, 0.14);
  --color-error-soft: rgba(239, 68, 68, 0.12);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius-card: 8px;
  --sidebar-width: 250px;
  --sidebar-collapsed-width: 60px;
}

html[data-bs-theme="dark"] {
  --menu-active-bg: rgba(13, 110, 253, 0.15);
  --menu-active-border: #3b82f6;
  --menu-active-color: #ffffff;
  --color-primary-dark: #2e8b57;
  --color-primary-mid: #3cb371;
  --color-bg-app: #121212;
  --color-bg-card: #1e1e1e;
  --color-text-main: #e0e0e0;
  --color-text-muted: #a0aabf;
  --color-border: #333333;
  --color-warning: #fbbf24;
  --color-error: #f87171;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.3);
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

.wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bs-body-bg);
  border-right: 1px solid var(--bs-border-color);
  transition:
    transform 0.3s ease,
    width 0.3s ease;
  height: 100%;
  position: fixed;
  z-index: 1000;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed:not(.temp-expanded) .sidebar-search {
  display: none;
}

.sidebar.collapsed .nav-link span {
  display: none;
}

.sidebar.collapsed .nav-link {
  text-align: center;
  padding: 0.5rem;
}

.sidebar.collapsed .nav-link i {
  margin: 0;
  font-size: 1.2rem;
}

.sidebar.collapsed:not(.temp-expanded) .collapse {
  display: none !important;
}

.sidebar.collapsed .nav-link[data-bs-toggle="collapse"] .bi-chevron-down {
  display: none;
}

.sidebar.collapsed .nav-link[data-bs-toggle="collapse"] {
  position: relative;
}

.sidebar.collapsed .nav-link[data-bs-toggle="collapse"]::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid var(--bs-body-color);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  opacity: 0.6;
}

/* Estilo para a pasta pai do item ativo quando o menu está recolhido */
.sidebar.collapsed:not(.temp-expanded) .nav-link.active-parent {
  background-color: var(--menu-active-bg);
  color: var(--menu-active-color);
  position: relative;
}

.sidebar.collapsed:not(.temp-expanded) .nav-link.active-parent::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background-color: var(--menu-active-border);
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

.sidebar.collapsed:not(.temp-expanded) .nav-link.active-parent i {
  color: var(--menu-active-color);
}

.sidebar.temp-expanded {
  width: 250px !important;
  z-index: 1001;
}

.sidebar.temp-expanded .nav-link span {
  display: inline !important;
}

.sidebar.temp-expanded .nav-link[data-bs-toggle="collapse"] .bi-chevron-down {
  display: inline !important;
}

.sidebar.temp-expanded .nav-link[data-bs-toggle="collapse"]::after {
  display: none;
}

.sidebar-sticky {
  height: 100%;
  overflow-y: auto;
  padding: 1rem;
}

.sidebar-search .input-group-text,
.sidebar-search .form-control {
  border-color: var(--color-border);
}

.sidebar-search .form-control {
  min-height: 36px;
}

.sidebar-search .form-control:focus {
  box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.18);
}

.sidebar-search-empty {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
}

.sidebar-filter-hidden {
  display: none !important;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  transition: all 0.3s;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-content.expanded {
  margin-left: var(--sidebar-collapsed-width);
}

.content-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  background-color: var(--color-bg-app);
}

.app-topbar {
  background-color: var(--bs-body-bg);
  gap: 0.75rem;
  min-height: 64px;
}

.app-topbar-title {
  min-width: 0;
}

.app-topbar-title h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.card {
  border-color: var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.table {
  --bs-table-bg: var(--color-bg-card);
}

.table thead th {
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  vertical-align: middle;
}

.sys-page-header {
  align-items: flex-start;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 1rem;
}

.sys-page-header h1 {
  color: var(--color-text-main);
  font-weight: 700;
}

.sys-page-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.sys-filter-card,
.sys-results-card {
  overflow: hidden;
}

.sys-filter-header {
  background-color: var(--color-bg-card);
  border-bottom-color: var(--color-border);
  padding: 0.85rem 1rem;
}

.sys-filter-header h5 {
  color: var(--color-text-main);
  font-size: 0.98rem;
  font-weight: 700;
}

.sys-filter-header .btn-link {
  align-items: center;
  color: var(--color-text-muted);
  display: inline-flex;
  justify-content: center;
  min-height: 34px;
  padding: 0.25rem 0.5rem;
  text-decoration: none;
}

.sys-filter-body {
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.8), transparent);
}

.sys-filter-body .form-label {
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.sys-filter-body .form-control,
.sys-filter-body .form-select {
  min-height: 38px;
}

.sys-filter-body .form-check {
  background-color: rgba(255, 255, 255, 0.68);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.62rem 0.75rem 0.62rem 2.65rem;
  width: 100%;
}

.sys-filter-actions .btn {
  align-items: center;
  display: inline-flex;
  gap: 0.4rem;
  justify-content: center;
}

.sys-table-shell {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  max-height: 68vh;
}

.sys-value-positive,
.pos {
  color: var(--color-success) !important;
}

.sys-value-negative,
.neg {
  color: var(--color-warning) !important;
}

.sys-value-error,
.err-color {
  color: var(--color-error) !important;
}

.sys-empty-state {
  color: var(--color-text-muted);
  background-color: rgba(255, 255, 255, 0.62);
  border: 1px dashed var(--color-border);
  border-radius: 8px;
  padding: 3rem 1rem;
  text-align: center;
}

.sys-empty-state .bi {
  display: block;
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.sys-kpi-card {
  background-color: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 1rem;
}

.sys-kpi-label {
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sys-kpi-value {
  font-size: 1.22rem;
  font-weight: 700;
  line-height: 1.25;
  margin-top: 0.35rem;
  overflow-wrap: anywhere;
}

.sys-data-table {
  width: 100%;
}

.sys-data-table thead th {
  background-color: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 2;
}

.sys-data-table tbody td {
  border-color: var(--color-border);
}

.sys-data-table tfoot td {
  background-color: rgba(248, 250, 252, 0.92);
  bottom: 0;
  position: sticky;
  z-index: 1;
}

.sys-data-table .ssagro-historico-cell {
  max-width: 560px;
  min-width: 320px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  line-height: 1.35;
}

.sys-summary-section {
  border-top: 1px solid var(--color-border);
  padding-top: 1.25rem;
}

.sys-summary-section h5 {
  color: var(--color-text-main);
  font-size: 1rem;
  font-weight: 700;
}

.sysbase-auth-page {
  min-height: calc(100vh - 11rem);
  align-items: center;
  display: flex;
  justify-content: center;
}

.sysbase-auth-page > .row {
  width: 100%;
}

.sidebar-overlay {
  background-color: rgba(0, 0, 0, 0.35);
  inset: 0;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  transition: opacity 0.2s ease;
  z-index: 999;
}

.sidebar-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.footer {
  background-color: var(--bs-body-bg);
  border-top: 1px solid var(--bs-border-color);
  padding: 0.5rem 0;
  position: relative;
  z-index: 1000;
}

.footer span {
  overflow-wrap: anywhere;
}

.navbar-toggler {
  padding: 0.25rem 0.75rem;
  font-size: 1.25rem;
  line-height: 1;
  background-color: transparent;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  color: var(--bs-body-color);
  text-decoration: none;
  transition: all 0.3s;
}

.nav-link:hover {
  background-color: var(--bs-gray-200);
}

.sidebar .nav-link.active,
.sidebar .nav-link[aria-current="page"] {
  background-color: var(--menu-active-bg);
  color: var(--menu-active-color);
  font-weight: 500;
  position: relative;
}

.sidebar .nav-link.active::before,
.sidebar .nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background-color: var(--menu-active-border);
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

.sidebar .nav-link.active i,
.sidebar .nav-link[aria-current="page"] i {
  color: var(--menu-active-color);
}

.nav-link i {
  margin-right: 0.5rem;
  font-size: 1.2rem;
}

.nav-link .bi-chevron-down {
  margin-right: 0;
  transition: transform 0.3s;
}

.mobile-header-toggle {
  display: none;
}

.mobile-header-title {
  display: none;
}

.nav-link[aria-expanded="true"] .bi-chevron-down {
  transform: rotate(180deg);
}

#baseSubmenu {
  background-color: var(--bs-gray-100);
  border-radius: 0.25rem;
  margin: 0.25rem 0;
}

#baseSubmenu .nav-link {
  padding-left: 2.5rem;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.show {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .main-content.expanded {
    margin-left: 0;
  }

  .mobile-header-toggle {
    display: inline-flex;
  }

  .mobile-header-title {
    display: block;
  }

  button,
  a.btn,
  .nav-link,
  input[type="checkbox"],
  input[type="radio"] {
    min-height: 44px;
  }

  .content-wrapper {
    padding: 0.75rem;
  }

  .app-topbar {
    align-items: flex-start !important;
    padding: 0.75rem !important;
  }

  .app-topbar-title,
  .app-topbar-actions {
    width: 100%;
  }

  .app-topbar-title {
    justify-content: space-between;
  }

  .app-topbar-actions {
    justify-content: flex-start;
  }

  .app-topbar-actions .btn {
    flex: 0 0 auto;
  }

  .container-fluid {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .card-header {
    gap: 0.65rem;
  }

  .sys-page-header {
    padding-bottom: 0.75rem;
  }

  .sys-filter-actions {
    flex-direction: column;
  }

  .sys-filter-actions .btn {
    width: 100%;
  }

  .sys-table-shell {
    max-height: none;
  }
}

html[data-bs-theme="dark"] {
  color-scheme: dark;
}

html[data-bs-theme="dark"] .sidebar {
  background-color: #1a1c1e !important;
  border-right: 1px solid #2d3135;
}

html[data-bs-theme="dark"] .sidebar-sticky {
  background-color: transparent !important;
}

html[data-bs-theme="dark"] .nav-link:hover {
  background-color: #2d3135 !important;
}

html[data-bs-theme="dark"] #baseSubmenu,
html[data-bs-theme="dark"] #baseSubmenu .nav-link {
  background-color: #1a1c1e !important;
  color: #fff !important;
}

html[data-bs-theme="dark"] #baseSubmenu .nav-link.active,
html[data-bs-theme="dark"] #baseSubmenu .nav-link[aria-current="page"],
html[data-bs-theme="dark"] #baseSubmenu .nav-link:active,
html[data-bs-theme="dark"] #baseSubmenu .nav-link:focus {
  background-color: var(--menu-active-bg) !important;
  color: var(--menu-active-color) !important;
}

html[data-bs-theme="dark"] #baseSubmenu .nav-link:hover {
  background-color: #3d444b !important;
  color: #fff !important;
}

html[data-bs-theme="dark"]
  .sidebar.collapsed
  .nav-link[data-bs-toggle="collapse"]::after {
  border-left-color: #fff;
}

/* Melhoria para caixas de seleção (checkbox) e preenchimentos automáticos */
html[data-bs-theme="dark"] .form-check-input:checked {
  background-color: #3b82f6;
  border-color: #3b82f6;
}

html[data-bs-theme="dark"] .form-control:focus,
html[data-bs-theme="dark"] .form-select:focus {
  background-color: #1a1c1e;
  color: #fff;
  border-color: #3b82f6;
  box-shadow: 0 0 0 0.25rem rgba(59, 130, 246, 0.25);
}

html[data-bs-theme="dark"] .form-control,
html[data-bs-theme="dark"] .form-select {
  color-scheme: dark;
}

html[data-bs-theme="dark"] .sys-filter-body {
  background: linear-gradient(180deg, rgba(30, 30, 30, 0.95), transparent);
}

html[data-bs-theme="dark"] .sys-filter-body .form-check,
html[data-bs-theme="dark"] .sys-empty-state {
  background-color: rgba(30, 30, 30, 0.72);
}

html[data-bs-theme="dark"] .sys-data-table thead th,
html[data-bs-theme="dark"] .sys-data-table tfoot td {
  background-color: #1e1e1e;
}

.alert-important {
  border-width: 2px !important;
  border-left-width: 6px !important;
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.075);
}

.alert-danger.alert-important {
  border-left-color: #dc3545 !important;
}

.alert-warning.alert-important {
  border-left-color: #ffc107 !important;
}

html[data-bs-theme="dark"] .alert-danger.alert-important {
  background-color: rgba(220, 53, 69, 0.15) !important;
  color: #f8d7da !important;
  border-color: rgba(220, 53, 69, 0.35) !important;
}

html[data-bs-theme="dark"] .alert-warning.alert-important {
  background-color: rgba(255, 193, 7, 0.15) !important;
  color: #fff3cd !important;
  border-color: rgba(255, 193, 7, 0.35) !important;
}
