:root {
  --primary: #2563eb;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --surface: #ffffff;
  --bg: #f3f6fb;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

body {
  margin: 0;
  font-family: "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #0f172a;
  color: #cbd5e1;
  border-right: 1px solid #1e293b;
  padding: 14px 10px;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #111c30;
  border: 1px solid #1f2d48;
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}

.sidebar-brand h1 {
  margin: 0;
  font-size: 15px;
  color: #f1f5f9;
}

.sidebar-brand p {
  margin: 2px 0 0;
  font-size: 11px;
  color: #64748b;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
}

.menu-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #64748b;
  margin: 12px 6px 6px;
}

.nav-stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.nav-btn,
.subnav-btn {
  width: 100%;
  border: 0;
  text-align: left;
  background: transparent;
  color: #cbd5e1;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: 0.2s ease;
  font-weight: 500;
  text-decoration: none;
}

.nav-btn:hover,
.subnav-btn:hover {
  background: #1e293b;
}

.nav-btn.active,
.subnav-btn.active {
  background: rgba(37, 99, 235, 0.2);
  color: #93c5fd;
}

.module-group {
  margin: 6px 0;
}

.module-toggle {
  width: 100%;
  background: transparent;
  border: 0;
  color: #cbd5e1;
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.module-toggle:hover {
  background: #1e293b;
}

.module-items {
  display: none;
  margin: 4px 0 0 8px;
  border-left: 1px dashed #334155;
  padding-left: 8px;
}

.module-group.open .module-items {
  display: block;
}

.module-item-link {
  display: block;
  color: #94a3b8;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
}

.module-item-link:hover {
  background: #1e293b;
  color: #dbeafe;
}

.module-item-link.active {
  background: rgba(37, 99, 235, 0.2);
  color: #93c5fd;
}

.main-area {
  min-width: 0;
}

.topbar {
  margin: 12px 12px 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  top: 10px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-soft {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.subnav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 6px;
}

.subnav-btn {
  background: #fff;
  border: 1px solid var(--border);
  color: #334155;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 12px;
}

.kpi-card {
  padding: 14px;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  margin-top: 6px;
}

.table-modern thead th {
  background: #f8fafc;
  color: #475569;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.table-modern td {
  vertical-align: middle;
  font-size: 13px;
}

.table-modern tbody tr:hover td {
  background: #f8fbff;
}

.status-badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.status-ok {
  background: rgba(22, 163, 74, 0.16);
  color: var(--success);
}

.status-warn {
  background: rgba(245, 158, 11, 0.17);
  color: #b45309;
}

.status-danger {
  background: rgba(220, 38, 38, 0.16);
  color: var(--danger);
}

.btn-soft {
  border: 1px solid var(--border);
  background: #fff;
}

.btn-soft:hover {
  background: #f8fafc;
}

.workflow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.workflow-step {
  padding: 8px 12px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 600;
}

.ledger-type {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.warn-panel {
  border-left: 4px solid var(--danger);
  background: #fff5f5;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  color: var(--muted);
}

.notif-dot {
  font-size: 10px;
  position: absolute;
  top: -6px;
  right: -8px;
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
  padding: 10px 14px;
}

.product-drawer {
  width: min(760px, 100vw);
}

.product-drawer .offcanvas-body {
  background: var(--bg);
}

.unit-status-chip {
  display: inline-block;
  min-width: 130px;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

.unit-status-chip:hover {
  filter: brightness(0.97);
}

.unit-status-tone-none {
  background: #f1f5f9;
  color: #475569;
}

.unit-status-tone-material {
  background: rgba(34, 197, 94, 0.18);
  color: #166534;
}

.unit-status-tone-partial {
  background: rgba(245, 158, 11, 0.16);
  color: #b45309;
}

.unit-status-tone-inprocess {
  background: rgba(14, 165, 233, 0.16);
  color: #0c4a6e;
}

.unit-status-tone-inproduction {
  background: rgba(59, 130, 246, 0.16);
  color: #1e40af;
}

.unit-status-tone-semi {
  background: rgba(16, 185, 129, 0.15);
  color: #047857;
}

.unit-status-tone-finished {
  background: rgba(22, 163, 74, 0.16);
  color: #15803d;
}

.unit-status-tone-review {
  background: rgba(251, 191, 36, 0.2);
  color: #92400e;
}

.unit-status-tone-pass {
  background: rgba(34, 197, 94, 0.18);
  color: #166534;
}

.unit-status-tone-fail {
  background: rgba(220, 38, 38, 0.16);
  color: #b91c1c;
}

.unit-status-tone-default {
  background: #eef2ff;
  color: #3730a3;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.quick-actions .btn {
  text-align: left;
}

.skeleton {
  border-radius: 10px;
  background: linear-gradient(90deg, #edf2f7 25%, #f8fafc 50%, #edf2f7 75%);
  background-size: 200% 100%;
  animation: shimmer 1.1s linear infinite;
  height: 110px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.shortage {
  background: #fff7ed;
}

body.dark {
  --surface: #0f172a;
  --bg: #020617;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
}

body.dark .topbar,
body.dark .card-soft,
body.dark .btn-soft,
body.dark .modal-content,
body.dark .offcanvas,
body.dark .table-modern thead th {
  background: #0f172a !important;
  color: #e2e8f0;
}

body.dark .subnav-btn {
  background: #111827;
  color: #cbd5e1;
  border-color: #334155;
}

body.dark .subnav-btn.active {
  background: rgba(37, 99, 235, 0.2);
  color: #93c5fd;
}

body.dark .table,
body.dark .form-control,
body.dark .form-select,
body.dark .form-control:focus,
body.dark .form-select:focus {
  background: #111827;
  color: #e2e8f0;
  border-color: #334155;
}

@media (max-width: 992px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 270px;
    transform: translateX(-100%);
    transition: 0.25s ease;
    z-index: 30;
  }
  .sidebar.open {
    transform: translateX(0);
  }
}
