/* ============================================================
   style.css — Design System — Controle de Estoque
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ----------------------------------------------------------------
   1. Variáveis CSS (Design Tokens)
   ---------------------------------------------------------------- */
:root {
  /* Cores principais */
  --primary:        #3b82f6;
  --primary-dark:   #2563eb;
  --primary-light:  #eff6ff;

  /* Sidebar */
  --sidebar-bg:     #0f172a;
  --sidebar-hover:  #1e293b;
  --sidebar-active: #1d4ed8;
  --sidebar-text:   #94a3b8;
  --sidebar-active-text: #fff;
  --sidebar-width:  260px;

  /* Superfícies */
  --bg:             #f1f5f9;
  --surface:        #ffffff;
  --surface-2:      #f8fafc;
  --surface-alt:    #f8fafc;   /* alias — hover de itens dropdown */
  --border:         #e2e8f0;
  --border-focus:   #3b82f6;

  /* Texto */
  --text-primary:   #0f172a;
  --text-secondary: #64748b;
  --text-muted:     #94a3b8;

  /* Semânticas */
  --success:        #10b981;
  --success-bg:     #ecfdf5;
  --success-border: #6ee7b7;
  --warning:        #f59e0b;
  --warning-bg:     #fffbeb;
  --warning-border: #fcd34d;
  --danger:         #ef4444;
  --danger-bg:      #fef2f2;
  --danger-border:  #fca5a5;
  --info:           #06b6d4;
  --info-bg:        #ecfeff;
  --info-border:    #67e8f9;

  /* Tipografia */
  --font:           'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --text-xs:        0.75rem;
  --text-sm:        0.875rem;
  --text-base:      1rem;
  --text-lg:        1.125rem;
  --text-xl:        1.25rem;
  --text-2xl:       1.5rem;
  --text-3xl:       1.875rem;

  /* Espaçamento */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Bordas */
  --radius:     0.5rem;      /* alias de radius-md — usado em componentes novos */
  --radius-sm:  0.375rem;
  --radius-md:  0.5rem;
  --radius-lg:  0.75rem;
  --radius-xl:  1rem;
  --radius-full: 9999px;

  /* Sombras */
  --shadow-sm:  0 1px 2px 0 rgb(0 0 0 / .05);
  --shadow-md:  0 4px 6px -1px rgb(0 0 0 / .07), 0 2px 4px -2px rgb(0 0 0 / .05);
  --shadow-lg:  0 10px 15px -3px rgb(0 0 0 / .08), 0 4px 6px -4px rgb(0 0 0 / .05);

  /* Transições */
  --transition: 150ms ease;
  --transition-slow: 250ms ease;
}

/* ----------------------------------------------------------------
   2. Reset & Base
   ---------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover { color: var(--primary-dark); }

img { max-width: 100%; height: auto; }

ul, ol { list-style: none; }

/* ----------------------------------------------------------------
   3. Layout Principal
   ---------------------------------------------------------------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 1000;
  overflow-y: auto;
  transition: transform var(--transition-slow);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6);
  border-bottom: 1px solid rgba(255,255,255,.06);
  color: #fff;
}

.sidebar-brand-icon {
  width: 38px; height: 38px;
  background: var(--primary);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-lg);
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: .01em;
  line-height: 1.3;
}

.sidebar-brand-sub {
  font-size: var(--text-xs);
  color: var(--sidebar-text);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-4) 0;
}

.sidebar-section {
  padding: var(--space-4) var(--space-6) var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--sidebar-text);
  opacity: .6;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  color: var(--sidebar-text);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all var(--transition);
  border-left: 3px solid transparent;
  cursor: pointer;
}

.sidebar-link i {
  width: 18px;
  text-align: center;
  font-size: var(--text-sm);
  opacity: .8;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
  border-left-color: var(--primary);
}

.sidebar-link.active {
  background: rgba(59, 130, 246, .15);
  color: #fff;
  border-left-color: var(--primary);
}

.sidebar-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid rgba(255,255,255,.06);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--sidebar-text);
  font-size: var(--text-sm);
}

.sidebar-user-avatar {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: var(--text-sm);
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; overflow: hidden; }
.sidebar-user-name {
  color: #e2e8f0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.sidebar-user-role {
  font-size: var(--text-xs);
  display: block;
}

/* --- Área principal --- */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-4) var(--space-8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-width: 0;   /* permite que page-title aplique text-overflow */
  flex: 1;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: var(--text-xl);
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.hamburger:hover { background: var(--bg); }

.page-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;  /* impede que o lado direito encolha */
}

.topbar-logout {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.topbar-logout:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Notificação de validade de lotes */
.notif-bell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(239, 68, 68, .1);
  color: var(--danger);
  text-decoration: none;
  transition: background var(--transition);
  animation: bell-shake 3s infinite;
  flex-shrink: 0;
}

.notif-bell:hover {
  background: rgba(239, 68, 68, .2);
}

.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--surface);
  letter-spacing: 0;
}

@keyframes bell-shake {
  0%, 75%, 100% { transform: rotate(0deg); }
  80%  { transform: rotate(-12deg); }
  87%  { transform: rotate(12deg); }
  93%  { transform: rotate(-6deg); }
  97%  { transform: rotate(4deg); }
}

/* Badge de status (Vencido, Crítico, Atenção) */
.badge-danger  { background: rgba(239,68,68,.15);  color: var(--danger);  border: 1px solid rgba(239,68,68,.3);  }
.badge-warning { background: rgba(245,158,11,.15); color: var(--warning); border: 1px solid rgba(245,158,11,.3); }
.badge-info    { background: rgba(59,130,246,.15);  color: #3b82f6;       border: 1px solid rgba(59,130,246,.3); }

/* ----------------------------------------------------------------
   Imagem de Produto — upload zone, thumbnail e preview
   ---------------------------------------------------------------- */
.img-upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  background: var(--surface-2);
}

.img-upload-zone:hover {
  border-color: var(--primary);
  background: rgba(var(--primary-rgb, 99,102,241), .04);
}

/* Thumbnail na listagem */
.product-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.product-thumb-ph {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: .85rem;
  flex-shrink: 0;
}

/* Layout do produto com imagem atual no editar */
.img-current-wrap {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
  padding: 1rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.img-current {
  width: 120px;
  height: 120px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.img-current-actions {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.content {
  flex: 1;
  padding: var(--space-8);
}

/* ----------------------------------------------------------------
   4. Cards / KPI
   ---------------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-6);
  margin-bottom: var(--space-8);
}

.kpi-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  transition: box-shadow var(--transition), transform var(--transition);
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.kpi-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xl);
  flex-shrink: 0;
}

.kpi-icon-blue   { background: var(--primary-light); color: var(--primary); }
.kpi-icon-green  { background: var(--success-bg);    color: var(--success); }
.kpi-icon-yellow { background: var(--warning-bg);    color: var(--warning); }
.kpi-icon-red    { background: var(--danger-bg);     color: var(--danger);  }

.kpi-body {}
.kpi-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: 500;
}

.kpi-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin: var(--space-1) 0;
}

.kpi-sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ----------------------------------------------------------------
   5. Cards de Conteúdo
   ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: var(--space-6);
}

.card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}

.card-title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.card-title i { color: var(--primary); }

.card-body {
  padding: var(--space-6);
}

.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ----------------------------------------------------------------
   6. Tabelas
   ---------------------------------------------------------------- */
/* Tabelas com scroll horizontal em mobile */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-xl);
}

/* Alias para tabela com overflow (tabela de dados) */
.data-table {
  min-width: 540px; /* garante que colunas não colem em mobile */
}

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead th {
  background: var(--surface-2);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }

tbody tr:hover { background: var(--surface-2); }

tbody td {
  padding: var(--space-4);
  color: var(--text-primary);
  vertical-align: middle;
}

.td-muted { color: var(--text-muted); }
.td-center { text-align: center; }

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: var(--space-4);
  display: block;
  opacity: .4;
}

.empty-state p { font-size: var(--text-lg); }

/* ----------------------------------------------------------------
   7. Formulários
   ---------------------------------------------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-5);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-group.full-width {
  grid-column: 1 / -1;
}

label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
}

label .required {
  color: var(--danger);
  margin-left: var(--space-1);
}

.form-control {
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  width: 100%;
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
}

.form-control::placeholder { color: var(--text-muted); }

textarea.form-control {
  resize: vertical;
  min-height: 90px;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-10);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: calc(-1 * var(--space-1));
}

.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.form-check input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ----------------------------------------------------------------
   8. Botões
   ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font);
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-success:hover:not(:disabled) {
  background: #059669;
  border-color: #059669;
  color: #fff;
}

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

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

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

.btn-outline:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

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

.btn-outline-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 0.6rem var(--space-4);
  font-size: var(--text-sm);
}

.btn-lg {
  padding: var(--space-4) var(--space-8);
  font-size: var(--text-base);
}

.btn-icon {
  padding: var(--space-2);
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
}

.btn-group {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ----------------------------------------------------------------
   9. Badges
   ---------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
}

.badge-success { background: var(--success-bg); color: #065f46; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger  { background: var(--danger-bg);  color: #991b1b; }
.badge-info    { background: var(--info-bg);    color: #155e75; }
.badge-default { background: var(--border);     color: var(--text-secondary); }

/* ----------------------------------------------------------------
   10. Alertas / Flash Messages
   ---------------------------------------------------------------- */
.alerts-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 420px;
  width: 100%;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid;
  box-shadow: var(--shadow-lg);
  animation: slideInRight .25s ease;
  position: relative;
}

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

.alert i { margin-top: 2px; flex-shrink: 0; }

.alert-sucesso {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: #065f46;
}

.alert-erro {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: #991b1b;
}

.alert-aviso {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: #92400e;
}

.alert-info {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: #155e75;
}

.alert-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--text-lg);
  line-height: 1;
  opacity: .5;
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  transition: opacity var(--transition);
}

.alert-close:hover { opacity: 1; }

/* Alertas inline (dentro do conteúdo) */
.content .alert {
  position: relative;
  box-shadow: none;
  animation: none;
  margin-bottom: var(--space-4);
}

/* ----------------------------------------------------------------
   11. Filtros de Busca
   ---------------------------------------------------------------- */
.search-bar {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  align-items: flex-end;
}

.search-bar .form-group {
  flex: 1;
  min-width: 200px;
}

.search-bar .btn {
  flex-shrink: 0;
  align-self: flex-end;
}

.search-input-wrap {
  position: relative;
}

.search-input-wrap i {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input-wrap .form-control {
  padding-left: calc(var(--space-3) + 1.2rem + var(--space-2));
}

/* ----------------------------------------------------------------
   12. Paginação
   ---------------------------------------------------------------- */
.paginacao {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  justify-content: center;
  margin-top: var(--space-6);
}

.btn-pag {
  padding: var(--space-2) var(--space-4);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition);
}

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

.btn-pag.disabled {
  opacity: .4;
  pointer-events: none;
  cursor: default;
}

.pag-info {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ----------------------------------------------------------------
   13. Itens de Entrada (tabela dinâmica)
   ---------------------------------------------------------------- */
.itens-table {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.itens-table thead th {
  padding: var(--space-3) var(--space-4);
}

.itens-table .item-row td {
  padding: var(--space-2) var(--space-3);
}

.btn-remove-item {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-base);
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

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

/* ----------------------------------------------------------------
   14. Página de Login
   ---------------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: var(--space-10) var(--space-8);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / .4);
}

.login-header {
  text-align: center;
  margin-bottom: var(--space-8);
}

.login-logo {
  width: 60px; height: 60px;
  background: var(--primary);
  border-radius: var(--radius-xl);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-2xl);
  color: #fff;
  margin-bottom: var(--space-4);
}

.login-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.login-sub {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.login-form .form-group { margin-bottom: var(--space-5); }

.login-btn {
  width: 100%;
  justify-content: center;
  padding: var(--space-4);
  font-size: var(--text-base);
  border-radius: var(--radius-lg);
}

/* ----------------------------------------------------------------
   15. Dashboard — Gráfico e Alertas
   ---------------------------------------------------------------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: var(--space-6);
  align-items: start;
}

.chart-container {
  position: relative;
  height: 300px;
}

.alert-list { list-style: none; }

.alert-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}

.alert-item:last-child { border-bottom: none; }

.alert-item-dot {
  width: 8px; height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.dot-red    { background: var(--danger); }
.dot-yellow { background: var(--warning); }

/* ----------------------------------------------------------------
   16. Estoque — Badge dinâmico
   ---------------------------------------------------------------- */
.saldo-positivo { color: var(--success); font-weight: 600; }
.saldo-minimo   { color: var(--warning); font-weight: 600; }
.saldo-zerado   { color: var(--danger);  font-weight: 600; }

/* ----------------------------------------------------------------
   17. Responsividade
   ---------------------------------------------------------------- */

/* Tablet: sidebar compacta */
@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* Mobile */
@media (max-width: 768px) {
  :root { --sidebar-width: 260px; }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,.4);
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-slow);
  }

  .sidebar-overlay.open {
    opacity: 1;
    pointer-events: all;
  }

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

  .hamburger { display: flex; }

  .content {
    padding: var(--space-4);
  }

  .topbar {
    padding: var(--space-4);
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
  }

  .kpi-value { font-size: var(--text-2xl); }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .btn-group { width: 100%; }
  .btn-group .btn { flex: 1; justify-content: center; }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .search-bar {
    flex-direction: column;
  }

  .search-bar .form-group { min-width: 100%; }

  .alerts-container {
    top: auto;
    bottom: var(--space-4);
    right: var(--space-4);
    left: var(--space-4);
    max-width: none;
  }

  /* Tabelas: garantir scroll horizontal */
  .table-responsive, .table-wrapper {
    border-radius: var(--radius-xl);
  }

  /* Itens de entrada: scroll em mobile */
  .itens-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Permissões: scroll */
  .permissoes-table { min-width: 600px; }

  /* Seletor de estoque: gap menor */
  .topbar-right { gap: var(--space-2); }

  /* Chevron do seletor: menor em mobile */
  .estoque-chevron { display: none; }
}

/* Mobile pequeno (até 480px) — ajustes finos */
@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  /* Topbar: esconde texto do estoque, mantém dot colorido */
  .estoque-nome {
    display: none;
  }

  /* Topbar: esconde texto "Sair" */
  .topbar-logout span {
    display: none;
  }

  /* Título da página menor */
  .page-title {
    font-size: var(--text-base);
    max-width: 140px;
  }

  /* Seletor de estoque compacto */
  .estoque-btn {
    padding: .4rem .5rem;
  }

  /* Dropdown de estoque: expandir para esquerda em telas pequenas */
  .estoque-dropdown {
    right: auto;
    left: 0;
    min-width: 190px;
  }
}

/* Telas muito pequenas (até 360px) */
@media (max-width: 360px) {
  .topbar {
    padding: var(--space-3) var(--space-3);
  }
  .content {
    padding: var(--space-3);
  }
  .page-title {
    max-width: 100px;
  }
}

/* ----------------------------------------------------------------
   18. Utilitários
   ---------------------------------------------------------------- */
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }

.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-muted   { color: var(--text-muted); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-sm      { font-size: var(--text-sm); }
.font-bold    { font-weight: 700; }
.font-semibold { font-weight: 600; }

.d-flex   { display: flex; }
.gap-2    { gap: var(--space-2); }
.gap-3    { gap: var(--space-3); }
.gap-4    { gap: var(--space-4); }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.w-full { width: 100%; }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

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

/* Divider */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-6) 0;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-6);
}

.breadcrumb a { color: var(--primary); }
.breadcrumb .sep { opacity: .5; }
.breadcrumb .current { color: var(--text-primary); font-weight: 600; }

/* Print */
@media print {
  .sidebar, .topbar, .btn, .btn-group { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
  .content { padding: 0 !important; }
}

/* ----------------------------------------------------------------
   Modal de Confirmação Global
   ---------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  transition: opacity 220ms ease;
  padding: 1rem;
}

.modal-overlay.modal-aberto {
  display: flex !important;
  opacity: 1;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / .35);
  padding: 2rem 2rem 1.75rem;
  width: 100%;
  max-width: 420px;
  text-align: center;
  transform: scale(.88) translateY(16px);
  transition: transform 250ms cubic-bezier(.34,1.56,.64,1);
  position: relative;
}

.modal-overlay.modal-aberto .modal-box {
  transform: scale(1) translateY(0);
}

/* Ícone circular */
.modal-icone {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
  font-size: 1.75rem;
  flex-shrink: 0;
}

.modal-icone.tipo-salvar   { background: #eff6ff; color: var(--primary); }
.modal-icone.tipo-excluir  { background: var(--danger-bg); color: var(--danger); }
.modal-icone.tipo-entrada  { background: var(--success-bg); color: var(--success); }
.modal-icone.tipo-saida    { background: var(--warning-bg); color: var(--warning); }
.modal-icone.tipo-acao     { background: #f0fdf4; color: #16a34a; }

/* Textos */
.modal-titulo {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: .5rem;
}

.modal-msg {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 1.75rem;
}

/* Botões */
.modal-acoes {
  display: flex;
  gap: .75rem;
  justify-content: center;
}

.modal-acoes .btn {
  flex: 1;
  max-width: 160px;
  justify-content: center;
}

.btn-modal-confirmar { }
.btn-modal-cancelar  { }

/* Animação de fechar */
.modal-overlay.modal-saindo {
  opacity: 0;
}
.modal-overlay.modal-saindo .modal-box {
  transform: scale(.92) translateY(8px);
}

/* Garante que ícones internos não bloqueiem eventos de clique */
.btn-icon i,
.btn i,
.btn-remove-item i {
  pointer-events: none;
}


@media (max-width: 480px) {
  .modal-box { padding: 1.5rem 1.25rem 1.25rem; }
  .modal-acoes { flex-direction: column; }
  .modal-acoes .btn { max-width: 100%; }
}

/* ================================================================
   SELETOR DE ESTOQUE (Topbar)
   ================================================================ */
.estoque-selector {
  position: relative;
}
.estoque-btn {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem .85rem;
  background: rgba(99,102,241,.1);
  border: 1.5px solid rgba(99,102,241,.25);
  border-radius: 999px;
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.estoque-btn:hover {
  background: rgba(99,102,241,.18);
  border-color: #6366f1;
}
.estoque-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.estoque-chevron {
  font-size: .7rem;
  color: var(--text-secondary);
  transition: transform .2s;
}
.estoque-dropdown.open + * .estoque-chevron,
#estoqueDropdown.open ~ .estoque-btn .estoque-chevron {
  transform: rotate(180deg);
}
.estoque-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + .5rem);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 10px 40px rgba(0,0,0,.12);
  min-width: 220px;
  overflow: hidden;
  z-index: 9999;
  animation: dropIn .18s ease;
}
.estoque-dropdown.open { display: block; }
@keyframes dropIn {
  from { opacity:0; transform: translateY(-6px); }
  to   { opacity:1; transform: translateY(0); }
}
.estoque-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .7rem 1rem;
  font-size: var(--text-sm);
  color: var(--text-primary);
  text-decoration: none;
  transition: background .15s;
  cursor: pointer;
}
.estoque-item:hover { background: var(--surface-alt); }
.estoque-item.ativo { background: rgba(99,102,241,.08); font-weight: 600; }
.estoque-item.estoque-novo { color: #6366f1; font-weight: 600; }
.estoque-divider {
  height: 1px;
  background: var(--border);
  margin: .25rem 0;
}

/* ================================================================
   PÁGINAS DE ESTOQUES (CRUD)
   ================================================================ */
.estoques-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-top: 1.5rem;
}
.estoque-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.25rem 1.5rem;
  position: relative;
  transition: box-shadow .2s;
}
.estoque-card:hover { box-shadow: var(--shadow-md); }
.estoque-card-header {
  display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem;
}
.estoque-cor-badge {
  width: 16px; height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}
.estoque-card-nome {
  font-size: var(--text-base); font-weight: 700;
  color: var(--text-primary);
}
.estoque-card-desc {
  font-size: var(--text-sm); color: var(--text-secondary);
  margin-bottom: .75rem;
}
.estoque-card-acoes { display: flex; gap: .5rem; }
.cor-picker-wrap {
  display: flex; align-items: center; gap: .75rem;
}
.cor-preview {
  width: 36px; height: 36px; border-radius: 50%;
  border: 2px solid var(--border); flex-shrink: 0;
}

/* ================================================================
   PAINEL DE PERMISSÕES
   ================================================================ */
.permissoes-table th, .permissoes-table td { vertical-align: middle; }
.permissoes-toggle {
  display: flex; gap: .5rem; flex-wrap: wrap;
}
.permissoes-toggle label {
  display: flex; align-items: center; gap: .35rem;
  font-size: var(--text-sm); cursor: pointer;
  padding: .25rem .6rem; border-radius: 20px;
  border: 1.5px solid var(--border);
  transition: all .15s;
}
.permissoes-toggle input[type=checkbox] { accent-color: #6366f1; }
.permissoes-toggle label:has(input:checked) {
  background: rgba(99,102,241,.12); border-color: #6366f1;
}
