:root {
  --sidebar-width: 240px;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-contrast: #ffffff;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --border: #e5e7eb;
  --shadow: 0 6px 16px rgba(0,0,0,0.08);
  --radius: 12px;
}

.dark {
  --bg: #0f172a;
  --card: #0b1220;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #60a5fa;
  --primary-contrast: #0b1220;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --border: #1f2937;
  --shadow: 0 6px 16px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.dashboard {
  display: flex;
  min-height: 100vh;
}

/* Brand: logo 200x100 e título abaixo */
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 8px 0;
}

/* container .logo mantém espaço para o <img> ou emoji */
.brand .logo {
  width: 200px;
  height: 100px;
  overflow: hidden;
  border-radius: 6px;
  background: var(--card);
  
  display: flex;
  align-items: center;
  justify-content: center;
}

/* se houver <img> dentro de .logo, força 200x100 e object-fit */
.brand .logo img {
  width: 200px;
  height: 100px;
  object-fit: cover;
  display: block;
}

/* título sempre abaixo da logo */
.brand .title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  line-height: 2;
  max-width: 220px;
  word-wrap: break-word;
  margin: 0;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--card);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  padding: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: left 0.28s cubic-bezier(.2,.9,.2,1);
  z-index: 120;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  transition: background 0.18s ease, transform 0.08s ease;
  font-size: 14px;
}

.menu-item i { width: 18px; text-align: center; }

.menu-item:hover {
  background: var(--primary);
  color: var(--primary-contrast);
  transform: translateX(4px);
}

/* Botão hamburguer (mobile) */
.hamburger {
  display: none;
  font-size: 22px;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text);
}
/* Main content */
.main {
  flex: 1;
  padding: 24px;
  min-height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.header h1 {
  margin: 0 0 20px;
  font-size: 22px;
  font-weight: 700;
}

/* KPIs */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.card:hover { transform: translateY(-4px); box-shadow: 0 10px 24px rgba(0,0,0,0.08); }

.card-label {
  color: var(--muted);
  font-size: 13px;
}

.card-value {
  font-size: 20px;
  font-weight: 700;
}

/* Filtros */
.filters {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: end;
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field.checkbox { flex-direction: row; align-items: center; gap: 8px; }

.input-icon {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--card);
}

.input-icon input, select {
  border: none;
  outline: none;
  width: 100%;
  background: transparent;
  color: var(--text);
  font-size: 14px;
}

/* Tabela */
.table-wrapper {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

thead th {
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px;
  cursor: pointer;
  position: relative;
  user-select: none;
}

thead th.num { text-align: right; }

thead th .fa { margin-left: 6px; color: var(--muted); font-size: 12px; }

tbody tr:nth-child(even) { background: rgba(0,0,0,0.02); }

tbody td {
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}

tbody td.num { text-align: right; }

.actions-col { width: 140px; min-width: 100px; }

.row-actions { display: flex; gap: 8px; align-items: center; }

/* Low stock highlight */
.low-stock { background: rgba(239,68,68,0.06); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.14s ease;
  font-size: 14px;
}

.btn:hover { transform: translateY(-2px); background: rgba(37,99,235,0.06); }

.btn.primary {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: transparent;
}

.btn.primary:hover { background: #1d4ed8; }

.btn.danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}

.btn.danger:hover { background: #dc2626; }

.icon-btn { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; }

/* Modal base */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  background: rgba(0,0,0,0.38);
  z-index: 220;
}

.modal.show { display: flex; }

.modal-content {
  width: 100%;
  max-width: 760px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: fadeIn 0.26s ease;
}

.modal-content.small { max-width: 420px; }

.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }

.modal-body { padding: 16px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

/* Form grid (modal de produto) */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }

.form-field { display: flex; flex-direction: column; gap: 6px; }

.form-field input, .form-field select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  transition: border 0.16s ease;
}

.form-field input:focus, .form-field select:focus { border-color: var(--primary); outline: none; }

/* Modal de configurações (avatar e layout) */
.settings-grid { display: grid; grid-template-columns: 220px 1fr; gap: 16px; padding: 16px; }

.settings-left { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.avatar { width: 160px; height: 160px; border-radius: 8px; border: 2px solid var(--border); background: var(--card); overflow: hidden; box-shadow: var(--shadow); }

.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.settings-right { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
/* Footer */
.footer { text-align: center; color: var(--muted); padding: 20px; font-size: 13px; }

/* Toasts */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(18px);
  transition: all 0.28s ease;
  z-index: 320;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-left: 4px solid var(--success); }
.toast.danger  { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Responsivo geral */
@media (max-width: 980px) {
  .sidebar { width: 200px; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
}

/* Mobile */
@media (max-width: 640px) {
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 200;
  }
  .sidebar.show { left: 0; }
  .hamburger { display: block; }
  .main { padding: 16px; }
  .header h1 { font-size: 18px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .filters { flex-direction: column; align-items: stretch; }
  .form-grid { grid-template-columns: 1fr; }
  .actions-col { width: 100px; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-right { grid-template-columns: 1fr; }
}

/* Overlay para mobile */
.sidebar-overlay { display: none; }
@media (max-width: 640px) {
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 190;
  }
  .sidebar.show + .sidebar-overlay { display: block; }
}

/* Pequenos ajustes */
thead th .fa-sort-up,
thead th .fa-sort-down { color: var(--primary); }

.input-icon .fa { color: var(--muted); }

.menu-item i { width: 18px; text-align: center; }

/* Ensure brand image responsive on very small widths */
@media (max-width: 420px) {
  .brand .logo { width: 160px; height: 80px; }
  .brand .logo img { width: 160px; height: 80px; }
  .brand .title { font-size: 13px; max-width: 180px; }
}

/* Dropdown */
.dropdown {
  position: relative;
}

.dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 100;
  min-width: 180px;
  padding: 6px 0;
}

.dropdown:hover .dropdown-content {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.dropdown-item:hover {
  background: rgba(37,99,235,0.08);
}
/* Rodapé da sidebar */
.sidebar-footer {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* Botão Sair com estilo diferenciado */
.sidebar-footer .exit-btn {
  /* background: rgba(239, 68, 68, 0.1) !important; */
  color: var(--danger) !important;
  /* border: 1px solid rgba(239, 68, 68, 0.2) !important; */
}

.sidebar-footer .exit-btn:hover {
  background: var(--danger) !important;
  color: white !important;
  transform: translateX(4px);
}

/* Versão compacta para mobile */
@media (max-width: 640px) {
  .sidebar-footer {
    padding-top: 16px;
    margin-top: auto;
  }
}
/* Mobile First Improvements */
@media (max-width: 768px) {
  .dashboard {
    flex-direction: column;
  }
  
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    width: 85%;
    max-width: 300px;
    z-index: 1000;
    transition: left 0.3s ease;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  }
  
  .sidebar.active {
    left: 0;
  }
  
  .main {
    padding: 16px;
    width: 100%;
  }
  
  .header {
    position: sticky;
    top: 0;
    background: var(--bg);
    padding: 12px 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
  }
  
  .header h1 {
    font-size: 18px;
    margin: 0;
  }
  
  .hamburger {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
  }
  
  .kpis {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin: 16px 0;
  }
  
  .card {
    padding: 12px;
    min-height: 80px;
  }
  
  .card-value {
    font-size: 18px;
  }
  
  .filters {
    flex-direction: column;
    gap: 12px;
  }
  
  .field {
    width: 100%;
  }
  
  .table-wrapper {
    border-radius: 8px;
    margin: 8px 0;
  }
  
  table {
    min-width: 700px;
  }
  
  /* Modal improvements for mobile */
  .modal-content {
    margin: 20px;
    width: calc(100% - 40px);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .settings-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .avatar {
    width: 120px;
    height: 120px;
    margin: 0 auto;
  }
  
  /* Touch-friendly buttons */
  .btn, .menu-item {
    min-height: 44px;
    padding: 12px 16px;
  }
  
  /* Improved dropdown for mobile */
  .dropdown-content {
    position: static;
    display: none;
    box-shadow: none;
    border: none;
    padding: 8px 0;
  }
  
  .dropdown.active .dropdown-content {
    display: block;
  }
}

@media (max-width: 480px) {
  .kpis {
    grid-template-columns: 1fr;
  }
  
  .card {
    text-align: center;
  }
  
  .main {
    padding: 12px;
  }
  
  .modal-content {
    margin: 10px;
    width: calc(100% - 20px);
    max-height: calc(100vh - 20px);
  }
  
  .row-actions {
    flex-direction: column;
    gap: 6px;
  }
  
  .row-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

/* Touch device improvements */
@media (hover: none) and (pointer: coarse) {
  .menu-item:hover {
    transform: none;
    background: transparent;
    color: var(--text);
  }
  
  .menu-item:active {
    background: var(--primary);
    color: var(--primary-contrast);
    transform: translateX(4px);
  }
  
  .btn:hover {
    transform: none;
  }
  
  .btn:active {
    transform: translateY(-2px);
  }
  
  .card:hover {
    transform: none;
  }
  
  .card:active {
    transform: translateY(-2px);
  }
}

/* Prevent zoom on input focus for iOS */
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* Swipe to close sidebar */
.sidebar {
  touch-action: pan-y;
}

/* Acessibilidade - Focus styles melhorados */
.menu-item:focus, 
.btn:focus, 
.dropdown-item:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Melhorar contraste para acessibilidade */
@media (prefers-contrast: high) {
  .card {
    border: 2px solid var(--border);
  }
  
  .btn {
    border-width: 2px;
  }
}

/* Suporte para reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .menu-item,
  .btn,
  .card {
    transition: none !important;
  }
}

/* Estilos para elementos inert (quando modal está aberto) */
.main[inert] {
  opacity: 0.6;
  pointer-events: none;
  user-select: none;
}

/* Melhorar visibilidade do foco para teclado */
.menu-item:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Garantir que modais tenham z-index adequado */
.modal {
  z-index: 1000;
}

.sidebar {
  z-index: 900;
}

/* Mobile improvements para acessibilidade */
@media (max-width: 768px) {
  /* Garantir que elementos interativos sejam tocáveis */
  .btn, 
  .menu-item,
  input[type="button"],
  input[type="submit"] {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Melhorar legibilidade em mobile */
  body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
}