/* ============ Tema (CSS variables) — default: Putih Bersih ============ */
:root, [data-theme="putih"] {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e4e7ec;
  --text: #1c2430;
  --text-muted: #6b7684;
  --accent: #b08d3e;          /* emas lembut */
  --accent-soft: #f6efdf;
  --accent-text: #7a6020;
  --ok: #1f7a4d;
  --ok-soft: #e3f2ea;
  --warn: #b05c12;
  --warn-soft: #f9ecdd;
  --danger: #b3364f;
  --danger-soft: #f9e3e8;
  --info: #2c6285;
  --info-soft: #e4eef5;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);
  --radius: 10px;
}

[data-theme="gelap"] {
  --bg: #12161c;
  --surface: #1a2029;
  --surface-2: #141a22;
  --border: #2a3341;
  --text: #e6e9ee;
  --text-muted: #93a0b0;
  --accent: #d4af5e;
  --accent-soft: #33291455;
  --accent-text: #d4af5e;
  --ok: #4fbf85;
  --ok-soft: #16281d;
  --warn: #e09a52;
  --warn-soft: #2e2013;
  --danger: #e07a90;
  --danger-soft: #2c1820;
  --info: #7fb2d0;
  --info-soft: #1b2a35;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 6px 20px rgba(0,0,0,.35);
}

[data-theme="krem"] {
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #efe9dd;
  --border: #e2d9c8;
  --text: #2b2519;
  --text-muted: #7d735f;
  --accent: #9a742c;
  --accent-soft: #f1e6cd;
  --accent-text: #715419;
  --shadow: 0 1px 2px rgba(60,50,20,.06), 0 4px 16px rgba(60,50,20,.07);
}

[data-theme="hijau"] {
  --bg: #f3f7f4;
  --surface: #ffffff;
  --surface-2: #e9f0eb;
  --border: #d9e4dc;
  --text: #1c2b22;
  --text-muted: #63756a;
  --accent: #2e6e4e;
  --accent-soft: #e2efe7;
  --accent-text: #245a40;
}

[data-theme="biru"] {
  --bg: #f4f7fa;
  --surface: #ffffff;
  --surface-2: #eaf0f5;
  --border: #dbe3ec;
  --text: #1a2633;
  --text-muted: #64748b;
  --accent: #2f5f83;
  --accent-soft: #e3edf5;
  --accent-text: #274e6b;
}

/* ============ Dasar ============ */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Plus Jakarta Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

.app-shell { display: flex; min-height: 100vh; }

/* ============ Sidebar ============ */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .brand-title {
  font-family: Cinzel, Georgia, serif;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .04em;
  color: var(--accent-text);
}
.sidebar-brand .brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.sidebar-nav { padding: 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }

/* ============ Topbar & konten ============ */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar h1 { font-size: 15px; font-weight: 600; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.content { padding: 22px; flex: 1; }

/* ============ Komponen ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .12s, background .12s;
  background: var(--surface-2);
  color: var(--text);
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }

.input, select.input, textarea.input {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field { margin-bottom: 13px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface-2);
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-2); }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ============ Kanban ============ */
.kanban {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 14px;
  align-items: flex-start;
}
.kanban-col {
  min-width: 268px;
  width: 268px;
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 180px);
}
.kanban-col-head {
  padding: 11px 14px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.kanban-col-head .count {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 8px;
  color: var(--text-muted);
}
.kanban-list { padding: 10px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; flex: 1; min-height: 60px; }
.kanban-list.drag-over { outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: 8px; background: var(--accent-soft); }

.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 12px;
  box-shadow: var(--shadow);
}
.kanban-card .spk { font-weight: 700; font-size: 13px; }
.kanban-card .cust { color: var(--text-muted); font-size: 12px; margin-top: 1px; }
.kanban-card .deadline { font-size: 11px; margin-top: 5px; color: var(--warn); }
.manifest-item {
  margin-top: 7px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  cursor: grab;
}
.manifest-item:active { cursor: grabbing; }
.manifest-item.dragging { opacity: .45; }
/* Sudah ada Hasil material terikat -> penanda halus, bukan warna mencolok. */
.manifest-item-ada-hasil { background: var(--ok-soft); border-color: var(--ok); border-left: 3px solid var(--ok); }
.manifest-item .m-content { min-width: 0; }
.manifest-item .m-spk { font-weight: 700; font-size: 12px; }
.manifest-item .m-craft { color: var(--text-muted); font-size: 11px; }
.manifest-item .m-item { color: var(--accent-text); font-size: 11px; font-weight: 700; }
.manifest-item .m-ukuran { color: var(--text-muted); font-size: 11px; }
.drag-handle { color: var(--text-muted); flex-shrink: 0; }

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 28, .45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px 16px;
  z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal-lg { max-width: 760px; }
.modal-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 18px; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 9px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); line-height: 1; }

/* ============ Util ============ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-3 { margin-bottom: 12px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.w-full { width: 100%; }
.hidden { display: none !important; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }

/* ============ Panel stok inventaris di papan produksi ============ */
.invent-panel {
  width: 242px;
  flex-shrink: 0;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
}
.invent-lot {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  font-size: 12px;
  cursor: grab;
}
.invent-lot:active { cursor: grabbing; }
.invent-lot .lot-title { font-weight: 700; }
.invent-lot .lot-sub { color: var(--text-muted); margin-top: 2px; }
.lot-drop-over { outline: 2px dashed var(--accent); outline-offset: 2px; background: var(--accent-soft) !important; border-radius: 8px; }
@media (max-width: 860px) { .invent-panel { display: none; } }

.toast-wrap { position: fixed; bottom: 18px; right: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease;
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -240px; transition: left .18s; z-index: 60; }
  .sidebar.open { left: 0; }
  .grid-2 { grid-template-columns: 1fr; }
}

.tree, .tree ul { list-style: none; margin: 0; padding-left: 18px; }
.tree { padding: 10px 4px; }
.tree li { position: relative; padding: 3px 0 3px 16px; }
.tree li::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 50%;
  width: 10px; border-left: 1px solid var(--border, #d8dee6); border-bottom: 1px solid var(--border, #d8dee6);
}
.tree > li::before { display: none; }
.tree li:last-child::after {
  content: ''; position: absolute; left: 0; top: 50%; bottom: 0;
  width: 1px; background: var(--surface);
}

/* Explorer stock (Inventaris): lot hasil Split/Konversi/Merge ditumpuk sebagai anak collapsible. */
.tree-toggle {
  border: none; background: none; cursor: pointer; padding: 0 2px; font-size: 10px;
  color: var(--text-muted); width: 16px; display: inline-block;
}
.tree-toggle:hover { color: var(--accent-text); }
.tree-leaf { color: var(--text-muted); display: inline-block; width: 16px; text-align: center; }
tr.tree-child { background: var(--surface-2); }
tr.tree-child td { color: var(--text-muted); }
