:root {
  --font-primary: 'Inter', system-ui, -apple-system, sans-serif;
  --verde-primario: #2E7D32;
  --verde-secundario: #66BB6A;
  --azul-tec: #1976D2;
  --amarelo-prod: #FBC02D;
  --cinza-escuro: #37474F;
  
  /* Mapeamento para variáveis funcionais */
  --primary-color: var(--verde-primario);
  --secondary-color: var(--cinza-escuro);
  --bg-light: #f8f9fa;
  --card-shadow: 0 4px 18px rgba(24, 65, 40, 0.08);
  --card-radius: 16px;
  --surface: #ffffff;
  --surface-muted: #f3f6f4;
  --border-color: #dfe8e2;
  --text-muted: #647168;
  --tap-size: 44px;
}

html {
  font-size: 16px;
  position: relative;
  min-height: 100%;
}

body {
  font-family: var(--font-primary);
  background-color: #f4f6f8;
  color: #333;
  margin-bottom: 0;
  min-width: 320px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
a,
input,
select,
textarea {
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid rgba(25, 118, 210, 0.45);
  outline-offset: 2px;
}

h1, .h1 { font-size: clamp(1.65rem, 4vw, 2.5rem); letter-spacing: -0.035em; }
h2, .h2 { font-size: clamp(1.4rem, 3vw, 2rem); letter-spacing: -0.025em; }
h3, .h3 { font-size: clamp(1.2rem, 2.5vw, 1.6rem); }

.text-muted {
  color: var(--text-muted) !important;
}

/* Modern Card Style */
.card {
  background: var(--surface);
  border: 1px solid rgba(223, 232, 226, 0.9);
  border: none;
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Navbar Modernization */
.navbar {
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  background-color: #fff !important;
}

.navbar-brand {
  font-weight: 700;
  letter-spacing: -0.5px;
}

/* Buttons */
.btn {
  border-radius: 8px;
  font-weight: 500;
  padding: 0.5rem 1rem;
  transition: all 0.2s;
  min-height: var(--tap-size);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .25rem;
}

.btn-sm {
  min-height: 40px;
  padding: .45rem .75rem;
}

.form-control,
.form-select {
  min-height: 48px;
  border-radius: 12px;
  border-color: #ccd8d0;
  font-size: 1rem;
}

textarea.form-control {
  min-height: 112px;
}

.form-check-input {
  width: 1.25rem;
  height: 1.25rem;
}

.dropdown-item {
  min-height: 44px;
  display: flex;
  align-items: center;
}

.btn-primary {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
  box-shadow: 0 2px 4px rgba(46, 125, 50, 0.2);
}

.btn-primary:hover {
  background-color: #1b5e20;
  border-color: #1b5e20;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem rgba(46, 125, 50, 0.25);
}

.text-primary {
  color: var(--primary-color) !important;
}

.bg-primary {
  background-color: var(--primary-color) !important;
}

.border-primary {
  border-color: var(--primary-color) !important;
}

.btn-outline-primary {
  color: var(--primary-color);
  border-color: var(--primary-color);
}

.btn-outline-primary:hover {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

/* --- Sidebar Layout --- */
#wrapper {
    display: flex;
    width: 100%;
    align-items: stretch;
    min-height: 100vh;
}

#sidebar-wrapper {
    min-width: 260px;
    max-width: 260px;
    background-color: #fff;
    border-right: 1px solid #e9ecef;
    transition: all 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

/* Estado collapsed para desktop */
@media (min-width: 769px) {
    #sidebar-wrapper.collapsed {
        min-width: 70px;
        max-width: 70px;
    }
    
    #sidebar-wrapper.collapsed .sidebar-heading {
        padding: 1.5rem 0.5rem;
        justify-content: center;
    }
    
    #sidebar-wrapper.collapsed .sidebar-heading span {
        display: none;
    }
    
    #sidebar-wrapper.collapsed .logo-text,
    #sidebar-wrapper.collapsed .list-group-item span,
    #sidebar-wrapper.collapsed .user-info span,
    #sidebar-wrapper.collapsed .user-info small {
        display: none;
    }
    
    #sidebar-wrapper.collapsed .list-group-item {
        justify-content: center;
        padding: 0.75rem 0.5rem;
    }
    
    #sidebar-wrapper.collapsed .list-group-item i {
        margin-right: 0;
        font-size: 1.25rem;
    }
    
    #sidebar-wrapper.collapsed .user-info {
        align-items: center;
        padding: 1rem 0.5rem;
    }
    
    #sidebar-wrapper.collapsed .user-photo {
        margin-right: 0;
        margin-bottom: 0;
    }
    
    #sidebar-wrapper.collapsed .sidebar-submenu {
        display: none;
    }
    
    #sidebar-wrapper.collapsed .dropdown-toggle::after {
        display: none;
    }
    
    #sidebar-wrapper.collapsed .p-3.border-top {
        width: 70px !important;
    }
    
    #sidebar-wrapper.collapsed .p-3.border-top > a > div > div:nth-child(2),
    #sidebar-wrapper.collapsed .p-3.border-top form button span {
        display: none;
    }
    
    #sidebar-wrapper.collapsed .p-3.border-top form button {
        padding: 0.5rem;
    }
}

#sidebar-wrapper .sidebar-heading {
    padding: 1.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#sidebar-wrapper .list-group {
    width: 100%;
    padding: 1rem 0;
}

#sidebar-wrapper .list-group-item {
    border: none;
    padding: 0.75rem 1.25rem;
    min-height: 48px;
    font-weight: 500;
    color: #495057;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

#sidebar-wrapper .list-group-item i {
    width: 24px;
    margin-right: 0.5rem;
    text-align: center;
    color: #adb5bd;
    transition: color 0.2s;
}

#sidebar-wrapper .list-group-item:hover {
    background-color: #f8f9fa;
    color: var(--primary-color);
}

#sidebar-wrapper .list-group-item:hover i {
    color: var(--primary-color);
}

#sidebar-wrapper .list-group-item.active {
    background-color: rgba(13, 110, 253, 0.1);
    color: var(--primary-color);
    border-left: 4px solid var(--primary-color);
}

#sidebar-wrapper .list-group-item.active i {
    color: var(--primary-color);
}

/* Submenu styles */
.sidebar-submenu {
    font-size: 0.9rem;
    padding-left: 1rem;
}

.sidebar-submenu .list-group-item {
    padding: 0.5rem 1.5rem 0.5rem 2.5rem;
}

#page-content-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    margin-left: 260px;
    transition: margin-left 0.3s ease-in-out;
}

#sidebar-close {
  min-width: 44px;
  min-height: 44px;
}

/* Quando sidebar está collapsed, ajusta margem */
#page-content-wrapper.sidebar-collapsed {
    margin-left: 70px;
}

/* Toggled State */
#wrapper.toggled #sidebar-wrapper {
    margin-left: -260px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #sidebar-wrapper {
        margin-left: -260px;
        position: fixed;
        height: 100%;
        z-index: 1000;
        box-shadow: 0 0 15px rgba(0,0,0,0.1);
    }

    #wrapper.toggled #sidebar-wrapper {
        margin-left: 0;
    }
    
    #page-content-wrapper {
        min-width: 100vw;
        margin-left: 0 !important;
    }
}

/* Overlay for mobile when sidebar is open */
#sidebar-overlay {
    display: none;
    position: fixed;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

#wrapper.toggled #sidebar-overlay {
    display: block;
}

@media (min-width: 769px) {
    #sidebar-overlay {
        display: none !important;
    }
}

/* Navbar in Content */
.navbar-content {
    padding: 0.75rem 1.5rem;
    min-height: 100px;
    background: #fff;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-bar-button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 14px;
}

/* Main Content Area */
.main-content {
    padding: 2rem;
    flex: 1;
    background-color: #f4f6f8;
}

.main-content > .container-fluid {
  max-width: 1600px;
  margin-inline: auto;
}

/* Footer */
.footer-content {
    padding: 1rem 2rem;
    background: #fff;
    border-top: 1px solid #e9ecef;
    text-align: center;
    font-size: 0.875rem;
    color: #6c757d;
}

.offline-status {
  position: sticky;
  top: 0;
  z-index: 10050;
  padding: calc(.65rem + env(safe-area-inset-top)) 1rem .65rem;
  text-align: center;
  color: #3f3100;
  background: #fff3cd;
  border-bottom: 1px solid #e8d58c;
  font-weight: 600;
}

.offline-status[hidden] {
  display: none;
}

.table-responsive {
  border-radius: var(--card-radius);
}

.table {
  --bs-table-striped-bg: #f7faf8;
}

.table > :not(caption) > * > * {
  padding: .85rem .75rem;
}

.pagination .page-link {
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
}

/* --- Mobile Responsive Table (Cards) --- */
@media (max-width: 767.98px) {
  body {
    background: var(--surface-muted);
    overflow-x: hidden;
  }

  .main-content {
    padding: 1rem .75rem calc(1.5rem + env(safe-area-inset-bottom));
  }

  .main-content > .container-fluid {
    padding-inline: 0;
  }

  .navbar-content {
    min-height: calc(68px + env(safe-area-inset-top));
    padding: calc(.65rem + env(safe-area-inset-top)) .75rem .65rem;
  }

  .app-bar-logo img {
    width: 44px !important;
    height: 44px !important;
    object-fit: contain;
  }

  .navbar-content .dropdown-toggle {
    width: 44px;
    overflow: hidden;
    white-space: nowrap;
    color: transparent;
    padding-inline: 0;
    gap: 0;
  }

  .navbar-content .dropdown-toggle i {
    color: var(--secondary-color) !important;
    margin: 0 !important;
    width: 100%;
  }

  .navbar-content .dropdown-toggle::after {
    display: none;
  }

  .pwa-install-button span {
    display: none;
  }

  .pwa-install-button {
    width: 44px;
    padding: 0;
  }

  .pwa-install-button i {
    margin: 0 !important;
  }

  #sidebar-wrapper {
    width: min(86vw, 320px);
    min-width: min(86vw, 320px);
    max-width: min(86vw, 320px);
    margin-left: min(-86vw, -320px);
    height: 100dvh !important;
    padding-top: env(safe-area-inset-top);
    z-index: 1040;
  }

  #sidebar-wrapper .list-group {
    padding-top: .25rem;
  }

  #sidebar-wrapper .list-group-item {
    min-height: 52px;
    margin-inline: .5rem;
    width: calc(100% - 1rem);
    border-radius: 12px;
  }

  #sidebar-wrapper .p-3.border-top {
    width: min(86vw, 320px) !important;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
  }

  #sidebar-overlay {
    z-index: 1035;
    backdrop-filter: blur(3px);
  }

  main > .d-flex.justify-content-between,
  main > .d-flex.align-items-center.justify-content-between,
  main > div > .d-flex.justify-content-between {
    align-items: stretch !important;
    flex-direction: column;
    gap: .75rem;
  }

  main > .d-flex.justify-content-between > .btn,
  main > .d-flex.align-items-center.justify-content-between > .btn {
    width: 100%;
  }

  .card {
    border-radius: 18px;
  }

  .card-body {
    padding: 1rem;
  }

  .row.g-3,
  .row.g-4 {
    --bs-gutter-x: .85rem;
    --bs-gutter-y: .85rem;
  }

  .display-5 {
    font-size: 1.75rem;
  }

  .lead {
    font-size: 1rem;
  }

  .table-responsive {
    overflow: visible;
    background: transparent;
    border-radius: 0;
  }

  .table-mobile-cards {
    border: 0;
    background: transparent;
    margin: 0;
  }

  .table-mobile-cards thead {
    display: none;
  }

  .table-mobile-cards tbody tr {
    display: block;
    background: #fff;
    margin-bottom: 1rem;
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    padding: .45rem 1rem;
    position: relative;
  }

  .table-mobile-cards tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .75rem 0;
    border: none;
    border-bottom: 1px solid #eee;
    text-align: right;
    min-height: 44px;
    overflow-wrap: anywhere;
  }

  .table-mobile-cards tbody td:last-child {
    border-bottom: none;
    justify-content: center;
    padding-top: 1rem;
    margin-top: 0.5rem;
    gap: 0.5rem;
  }

  /* Label for the data */
  .table-mobile-cards tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6c757d;
    text-align: left;
    margin-right: 1rem;
    flex-shrink: 0;
  }

  /* Special styling for Actions column */
  .table-mobile-cards tbody td.actions-cell {
    display: flex;
    width: 100%;
    justify-content: stretch;
    gap: 8px;
  }
  
  .table-mobile-cards tbody td.actions-cell .btn {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .table-mobile-cards tbody td.actions-cell::before {
    display: none;
  }

  .table-mobile-cards tbody td.actions-cell,
  .table-mobile-cards tbody td.actions-cell > div,
  .table-mobile-cards tbody td.actions-cell > .btn-group {
    flex-wrap: wrap;
  }

  .table-mobile-cards tbody td.actions-cell .btn,
  .table-mobile-cards tbody td.actions-cell form {
    min-width: 44px;
  }

  .table-mobile-cards tbody tr:only-child td[colspan] {
    display: block;
    text-align: center;
    border: 0;
    padding: 1.5rem .5rem;
  }

  .table-mobile-cards tbody tr:only-child td[colspan]::before {
    display: none;
  }

  .btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
  }

  .btn-group > .btn {
    border-radius: 10px !important;
  }

  .footer-content,
  body > footer {
    display: none;
  }

  .login-bg {
    min-height: calc(100dvh - 84px) !important;
    margin-inline: -.75rem;
    padding: 1rem;
    align-items: flex-start !important;
  }

  .login-card {
    margin-top: max(.5rem, env(safe-area-inset-top));
  }

  body > header .navbar-brand img {
    width: 44px !important;
    height: 44px !important;
    object-fit: contain;
  }

  body > header .navbar-brand {
    font-size: 1.05rem;
    white-space: nowrap;
  }

  body > header .navbar-collapse {
    padding-block: .75rem;
  }

  body > header .navbar-nav {
    gap: .5rem;
  }

  body > header .nav-item {
    margin-left: 0 !important;
  }

  body > header .nav-link,
  body > header .btn {
    min-height: 48px;
    display: flex;
    align-items: center;
    padding-inline: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (display-mode: standalone) {
  body {
    overscroll-behavior-y: none;
  }

  .navbar-content {
    padding-top: calc(.75rem + env(safe-area-inset-top));
  }
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}
