:root {
  --bg:        #f1f5f9;
  --bg2:       #ffffff;
  --bg3:       #f8fafc;
  --border:    #e2e8f0;
  --border2:   #cbd5e1;
  --text:      #1e293b;
  --text-muted:#64748b;
  --primary:   #2563eb;
  --primary-dk:#1d4ed8;
  --success:   #16a34a;
  --warning:   #d97706;
  --danger:    #dc2626;
  --sidebar-w: 230px;
}

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

body {
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  border-bottom: 1px solid #e2e8f0;
}

.brand-icon { font-size: 1.5rem; }
.brand-name { font-size: 1rem; font-weight: 700; color: #1e293b; }

.nav-menu { list-style: none; padding: .5rem 0; flex: 1; overflow-y: auto; }

.nav-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1rem;
  color: #475569;
  text-decoration: none;
  border-radius: 8px;
  margin: 2px 8px;
  font-size: .875rem;
  transition: all .15s;
}

.nav-link:hover { background: #e2e8f0; color: #1e293b; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-icon { font-size: .95rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: .875rem 1rem;
  border-top: 1px solid #e2e8f0;
}

.user-info { margin-bottom: .5rem; }
.user-name { display: block; font-weight: 600; font-size: .85rem; color: #1e293b; }
.user-role { font-size: .72rem; color: #64748b; text-transform: uppercase; letter-spacing: .05em; }

.btn-logout {
  display: block;
  text-align: center;
  padding: .4rem;
  color: #64748b;
  text-decoration: none;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: .78rem;
  transition: all .15s;
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); }

/* ── Main ── */
.main-content { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }
.content-wrap { padding: 1.75rem 2rem; max-width: 1200px; }

/* ── Login ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 20px rgba(0,0,0,.10);
}

.login-logo { text-align: center; margin-bottom: 1.5rem; }
.brand-icon-lg { font-size: 2.5rem; }
.login-logo h1 { font-size: 1.4rem; font-weight: 700; color: var(--text); margin: .5rem 0 .2rem; }
.login-logo p { color: var(--text-muted); font-size: .85rem; }

/* ── Cards ── */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}

.card-header {
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg3);
}
.card-header h3 { font-size: .9rem; font-weight: 600; color: var(--text); }
.card-body { padding: 1.25rem; }
.card-body.p-0 { padding: 0; }
.card-footer { padding: .75rem 1.25rem; border-top: 1px solid var(--border); background: var(--bg3); }
.mt-4 { margin-top: 1.5rem; }
.mb-3 { margin-bottom: 1rem; }

/* ── Stat cards ── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card-stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.card-stat.card-alert  { border-left: 4px solid var(--danger); }
.card-stat.card-warning{ border-left: 4px solid var(--warning); }
.stat-icon  { font-size: 1.6rem; margin-bottom: .4rem; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text); }
.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }

/* ── Table ── */
.table { width: 100%; border-collapse: collapse; }

.table th {
  background: var(--bg3);
  padding: .6rem 1rem;
  text-align: left;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.table td {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }
.row-pending td  { background: #fffbeb !important; }
.row-divergente td { background: #fef2f2 !important; }
.row-zero td { opacity: .5; }

.text-center { text-align: center; }
.text-muted   { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger  { color: var(--danger); }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.badge-entrada, .badge-ok, .badge-processada {
  background: #dcfce7; color: #15803d;
}
.badge-saida, .badge-venda, .badge-faltando, .badge-cancelada {
  background: #fee2e2; color: #dc2626;
}
.badge-ajuste, .badge-aguardando_vinculo, .badge-sobrando {
  background: #fef3c7; color: #d97706;
}
.badge-devolucao, .badge-importada {
  background: #dbeafe; color: #2563eb;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem 1rem;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all .15s;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; }
.btn-outline {
  background: #fff;
  border: 1px solid var(--border2);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
.btn-sm { padding: .28rem .65rem; font-size: .775rem; }
.btn-block { width: 100%; justify-content: center; }
.ml-2 { margin-left: .5rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  margin-bottom: .35rem;
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.form-control {
  width: 100%;
  padding: .55rem .75rem;
  background: #fff;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  font-size: .9rem;
  transition: border .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }

/* ── Alerts ── */
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: .875rem;
  border-left: 4px solid transparent;
}
.alert-success { background: #f0fdf4; border-color: #16a34a; color: #15803d; }
.alert-danger   { background: #fef2f2; border-color: #dc2626; color: #dc2626; }
.alert-warning  { background: #fffbeb; border-color: #d97706; color: #92400e; }
.alert-info     { background: #eff6ff; border-color: #2563eb; color: #1d4ed8; }

/* ── Page header ── */
.page-title { font-size: 1.35rem; font-weight: 700; margin-bottom: 1.25rem; color: var(--text); }
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}
.page-header .page-title { margin-bottom: 0; }

/* ── Info grid ── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}
.info-grid div { display: flex; flex-direction: column; gap: .2rem; }
.info-grid label {
  font-size: .7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
}

/* ── Modal ── */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(2px);
}
.modal-dialog {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 90%; max-width: 500px;
  position: relative; z-index: 1;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
}
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg3);
  border-radius: 14px 14px 0 0;
}
.modal-header h3 { font-size: .95rem; font-weight: 700; }
.btn-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; }
.btn-close:hover { color: var(--danger); }
.modal-body { padding: 1.25rem; }
.form-actions { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1rem; }

/* ── Search ── */
.search-results {
  background: #fff;
  border: 1px solid var(--border2);
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
  margin-top: .25rem;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
}
.search-item {
  padding: .6rem .75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
  color: var(--text);
}
.search-item:hover { background: #eff6ff; color: var(--primary); }
.search-item:last-child { border-bottom: none; }

.produto-selecionado {
  background: #f0fdf4;
  border: 1px solid #86efac;
  padding: .6rem .75rem;
  border-radius: 8px;
  font-size: .85rem;
  color: #15803d;
}

/* ── Filter form ── */
.filter-form {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end;
}
.filter-form .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; gap: 1rem; }

/* ── Mobile top bar ── */
.mobile-topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  background: #1e293b; height: 52px;
  align-items: center; padding: 0 1rem; gap: .75rem;
}
.mobile-topbar .brand-name { color: #fff; font-size: .85rem; font-weight: 600; flex: 1; }
.hamburger { background: none; border: none; cursor: pointer; padding: 4px; display: flex; flex-direction: column; gap: 5px; }
.hamburger span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 150;
}
.sidebar-overlay.open { display: block; }

/* ── Responsive ── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .mobile-topbar { display: flex; }
  .sidebar {
    position: fixed; top: 0; left: -260px; width: 260px; height: 100vh;
    z-index: 160; transition: left .25s ease; display: flex;
  }
  .sidebar.open { left: 0; }
  .main-content { margin-left: 0; padding-top: 52px; }
  .content-wrap { padding: 1rem; }
  .cards-grid { grid-template-columns: 1fr 1fr; }
}
