:root {
  --sidebar-bg: #0f172a;
  --sidebar-bg-2: #111827;
  --sidebar-border: #1f2937;
  --sidebar-fg: #cbd5e1;
  --sidebar-fg-muted: #64748b;
  --sidebar-active: #2563eb;
  --sidebar-hover: #1e293b;
  --topbar-bg: #ffffff;
  --content-bg: #f5f7fb;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  --radius: 10px;
  --sidebar-w: 260px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--content-bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }

/* ---------- Layout ---------- */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  z-index: 1030;
  transition: width .2s ease, transform .2s ease;
}

.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid var(--sidebar-border);
  color: #fff;
  font-weight: 700;
  letter-spacing: .3px;
  font-size: 16px;
}
.sidebar-brand .logo-mark {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: grid; place-items: center;
  color: #fff; font-weight: 800;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px 24px;
  scrollbar-width: thin;
}
.sidebar-scroll::-webkit-scrollbar { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: #1e293b; border-radius: 4px; }

.nav-section {
  padding: 14px 14px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--sidebar-fg-muted);
}

.nav-item { list-style: none; }
.nav-menu { list-style: none; padding: 0; margin: 0; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-fg);
  cursor: pointer;
  position: relative;
  transition: background .15s ease, color .15s ease;
  font-size: 13.5px;
}
.nav-link i.bi { font-size: 16px; opacity: .9; width: 18px; text-align: center; }
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active {
  background: rgba(37,99,235,.15);
  color: #fff;
}
.nav-link.active::before {
  content: "";
  position: absolute;
  left: -10px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0;
  background: var(--sidebar-active);
}
.nav-link .chev {
  margin-left: auto;
  transition: transform .2s ease;
  font-size: 12px;
  opacity: .7;
}
.nav-link[aria-expanded="true"] .chev { transform: rotate(90deg); }

.submenu { list-style: none; padding: 4px 0 4px 34px; margin: 0; }
.submenu .nav-link {
  padding: 7px 10px;
  font-size: 13px;
  color: #94a3b8;
}
.submenu .nav-link::before { display: none; }
.submenu .nav-link.active { background: transparent; color: #fff; }
.submenu .nav-link.active::after {
  content: "";
  position: absolute; left: -14px; top: 50%;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--sidebar-active); transform: translateY(-50%);
}
.submenu .submenu { padding-left: 20px; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
  display: flex; align-items: center; gap: 10px;
  color: #94a3b8;
  font-size: 12.5px;
}
.sidebar-footer .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg,#6366f1,#8b5cf6);
  color: #fff; display: grid; place-items: center; font-weight: 700;
}

/* Main */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex; flex-direction: column;
  transition: margin-left .2s ease;
}

.topbar {
  height: var(--topbar-h);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky; top: 0; z-index: 1020;
}
.topbar .search {
  position: relative;
  max-width: 380px; width: 100%;
}
.topbar .search i {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 14px;
}
.topbar .search input {
  width: 100%;
  border: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 8px;
  padding: 8px 12px 8px 34px;
  font-size: 13.5px;
  outline: none;
}
.topbar .search input:focus { border-color: var(--primary); background: #fff; }

.topbar .spacer { flex: 1; }
.topbar .icon-btn {
  width: 38px; height: 38px; border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text); background: transparent;
  border: 1px solid transparent; cursor: pointer;
  position: relative;
}
.topbar .icon-btn:hover { background: #f1f5f9; }
.topbar .icon-btn .badge-dot {
  position: absolute; top: 8px; right: 9px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); border: 2px solid #fff;
}

.topbar .user {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 4px 4px; border-radius: 30px;
  cursor: pointer;
}
.topbar .user:hover { background: #f1f5f9; }
.topbar .user .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg,#f59e0b,#ef4444);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.topbar .user .name { font-weight: 600; font-size: 13.5px; }
.topbar .user .role { font-size: 11.5px; color: var(--text-muted); }

.content {
  padding: 24px;
  flex: 1;
}

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1 {
  font-size: 20px; margin: 0 0 4px; font-weight: 700;
}
.page-head .crumbs {
  font-size: 12.5px; color: var(--text-muted);
}
.page-head .crumbs a { color: var(--text-muted); }
.page-head .crumbs a:hover { color: var(--primary); }

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(15,23,42,.03);
}
.card-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: transparent;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-header h5 { margin: 0; font-size: 15px; font-weight: 600; }
.card-body { padding: 18px; }

.kpi {
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px;
}
.kpi .label { color: var(--text-muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; }
.kpi .value { font-size: 26px; font-weight: 700; }
.kpi .foot { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.kpi .delta { font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.kpi .delta.up { color: var(--success); }
.kpi .delta.down { color: var(--danger); }
.kpi .icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: grid; place-items: center; font-size: 20px;
  background: rgba(37,99,235,.1); color: var(--primary);
}
.kpi.k2 .icon { background: rgba(245,158,11,.12); color: var(--warning); }
.kpi.k3 .icon { background: rgba(16,185,129,.12); color: var(--success); }
.kpi.k4 .icon { background: rgba(139,92,246,.12); color: #8b5cf6; }

.kpi-top { display: flex; justify-content: space-between; align-items: flex-start; }

/* Tables */
table.dataTable thead th {
  background: #f8fafc;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border) !important;
}
table.table tbody td { vertical-align: middle; font-size: 13.5px; }
table.table tbody tr:hover { background: #f8fafc; }

/* Badges */
.badge-soft {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
}
.badge-soft.success { background: rgba(16,185,129,.12); color: #047857; }
.badge-soft.warning { background: rgba(245,158,11,.14); color: #b45309; }
.badge-soft.danger { background: rgba(239,68,68,.12); color: #b91c1c; }
.badge-soft.info { background: rgba(6,182,212,.12); color: #0e7490; }
.badge-soft.gray { background: #f1f5f9; color: #475569; }
.badge-soft.primary { background: rgba(37,99,235,.12); color: #1d4ed8; }

/* Buttons */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-600); border-color: var(--primary-600); }
.btn-icon {
  width: 32px; height: 32px; padding: 0;
  display: inline-grid; place-items: center;
  border-radius: 6px;
}
.btn-soft {
  background: #f1f5f9; color: var(--text); border: none;
}
.btn-soft:hover { background: #e2e8f0; }

/* Forms */
.form-label { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.form-control, .form-select {
  border-radius: 8px;
  border-color: var(--border);
  font-size: 13.5px;
  padding: 8px 12px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-section { margin-bottom: 20px; }
.form-section .card-header h5 i { color: var(--primary); margin-right: 6px; }

/* Repeater */
.repeater-row {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
  background: #f8fafc;
}
.repeater-row .row-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.repeater-row .row-head .title { font-weight: 600; font-size: 13px; color: var(--text-muted); }

/* Image upload preview */
.image-drop {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.image-drop:hover { background: #f8fafc; border-color: var(--primary); color: var(--primary); }
.image-preview-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px; margin-top: 12px;
}
.image-preview-grid .thumb {
  aspect-ratio: 1;
  border-radius: 8px;
  background-size: cover; background-position: center;
  border: 1px solid var(--border);
  position: relative;
}

/* Form footer */
.form-footer {
  position: sticky; bottom: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex; justify-content: flex-end; gap: 8px;
  margin: 24px -24px -24px;
}

/* Category tree */
.tree { list-style: none; padding-left: 0; margin: 0; }
.tree ul { list-style: none; padding-left: 22px; border-left: 1px dashed var(--border); margin-left: 8px; }
.tree li { padding: 4px 0; }
.tree .node {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 6px;
}
.tree .node:hover { background: #f1f5f9; }
.tree .toggle { cursor: pointer; color: var(--text-muted); width: 16px; text-align: center; }
.tree .name { flex: 1; font-weight: 500; }
.tree .count { color: var(--text-muted); font-size: 12px; }

/* Warehouse cards */
.wh-card { padding: 18px; }
.wh-card .top { display: flex; justify-content: space-between; align-items: flex-start; }
.wh-card .icon {
  width: 42px; height: 42px; border-radius: 10px;
  background: rgba(37,99,235,.1); color: var(--primary);
  display: grid; place-items: center; font-size: 20px;
}
.wh-card h6 { margin: 12px 0 4px; font-size: 15px; font-weight: 600; }
.wh-card .addr { color: var(--text-muted); font-size: 12.5px; margin-bottom: 12px; }
.wh-card .bar { height: 8px; background: #f1f5f9; border-radius: 999px; overflow: hidden; }
.wh-card .bar > span { display: block; height: 100%; background: linear-gradient(90deg,#3b82f6,#6366f1); border-radius: 999px; }
.wh-card .meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* Chart container */
.chart-box { position: relative; height: 300px; }
.chart-sm { position: relative; height: 60px; }

/* Utilities */
.text-muted { color: var(--text-muted) !important; }
.hstack-gap { display: flex; align-items: center; gap: 8px; }

/* Sidebar collapsed */
.sidebar-collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
}
.sidebar-collapsed .sidebar .label,
.sidebar-collapsed .sidebar .nav-section,
.sidebar-collapsed .sidebar .chev,
.sidebar-collapsed .sidebar .submenu,
.sidebar-collapsed .sidebar-brand span,
.sidebar-collapsed .sidebar-footer .who { display: none; }
.sidebar-collapsed .main { margin-left: var(--sidebar-w-collapsed); }
.sidebar-collapsed .sidebar .nav-link { justify-content: center; }

/* Responsive */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .main { margin-left: 0; }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-open::after {
    content: ""; position: fixed; inset: 0;
    background: rgba(15,23,42,.4); z-index: 1025;
  }
}

/* Datatables tweaks */
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
  border-radius: 6px !important;
  border: 1px solid var(--border) !important;
  padding: 6px 10px !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
}

/* Product cell */
.product-cell { display: flex; align-items: center; gap: 10px; }
.product-cell .ph {
  width: 36px; height: 36px; border-radius: 6px;
  background: linear-gradient(135deg,#e0e7ff,#c7d2fe);
  display: grid; place-items: center; color: #4338ca; font-weight: 700;
}
.product-cell .info .name { font-weight: 600; font-size: 13.5px; }
.product-cell .info .sku { font-size: 11.5px; color: var(--text-muted); }

.activity-list { list-style: none; padding: 0; margin: 0; }
.activity-list li {
  display: flex; gap: 12px; padding: 12px 0;
  border-bottom: 1px dashed var(--border);
}
.activity-list li:last-child { border-bottom: 0; }
.activity-list .dot {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; flex-shrink: 0;
  background: var(--primary);
}
.activity-list .dot.warn { background: var(--warning); }
.activity-list .dot.ok { background: var(--success); }
.activity-list .dot.err { background: var(--danger); }
.activity-list .body { font-size: 13px; }
.activity-list .body .t { color: var(--text-muted); font-size: 11.5px; }
