:root {
  --bg: #f3f1ec;
  --card: #ffffff;
  --ink: #1d1f22;
  --ink-2: #555a61;
  --ink-3: #8a8f96;
  --line: #e3e0d8;
  --side: #1f2328;
  --side-ink: #c9ccd1;
  --accent: #e8a317;
  --in: #1f7a4d;
  --in-bg: #e6f3ec;
  --out: #2f5fa8;
  --out-bg: #e7eef9;
  --red: #c62828;
  --red-bg: #fdecea;
  --red-line: #f3b9b4;
  --radius: 10px;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; background: var(--bg); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 22px; }
.brand-mark { width: 38px; height: 38px; flex-shrink: 0; display: block; }
.brand-name { color: #fff; font-weight: 600; }
.brand-sub { font-size: 12px; color: #8b9097; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 10px;
  background: none; border: 0; border-radius: 8px; color: var(--side-ink); cursor: pointer; text-align: left;
}
.nav-item:hover { background: #2a2f35; color: #fff; }
.nav-item.active { background: #343a41; color: #fff; }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.nav-icon {
  width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.nav-icon.in { background: #24533b; color: #9fe0bc; }
.nav-icon.out { background: #263f66; color: #a9c6f2; }
.nav-icon.stock { background: #5a4518; color: #f5cf7a; }
.nav-badge {
  margin-left: auto; background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 10px;
}

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.clock { padding: 12px 10px; border-top: 1px solid #343a41; margin-bottom: 4px; }
.clock-time { color: #fff; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.clock-date { font-size: 12px; color: #8b9097; }
.btn-ghost {
  background: none; border: 1px solid #3a4047; color: var(--side-ink); border-radius: 8px;
  padding: 8px 10px; cursor: pointer; text-align: left;
}
.btn-ghost:hover { border-color: #5a616a; color: #fff; }
.btn-ghost:disabled { opacity: .5; cursor: wait; }
.sync { font-size: 11px; color: #7d828a; padding: 4px 2px 0; }

/* ---------- Main ---------- */
.main { flex: 1; overflow-y: auto; padding: 26px 30px 40px; }
.page { display: none; }
.page.active { display: block; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 20px; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -.01em; }
.page-head p { margin: 0; color: var(--ink-2); max-width: 560px; }
.stats { display: flex; gap: 10px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 16px; min-width: 130px;
}
.stat span { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat label { font-size: 12px; color: var(--ink-3); }
.stat.danger span { color: var(--red); }

.banner {
  background: var(--red-bg); border: 1px solid var(--red-line); color: #7f1d1d;
  padding: 12px 14px; border-radius: var(--radius); margin-bottom: 18px; white-space: pre-line;
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.split { display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: start; }

/* ---------- Form ---------- */
.form { padding: 18px; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 0; }
.form h2, .report h2 { margin: 0; font-size: 15px; }
.auto-time {
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  background: #faf8f3; border: 1px dashed #d9d4c7; border-radius: 8px; padding: 8px 12px;
}
.auto-time label { grid-column: 1 / -1; font-size: 12px; color: var(--ink-3); }
.auto-time-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.auto-time small {
  font-size: 11px; color: #8a6a12; background: #fbefd2; padding: 2px 8px; border-radius: 10px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field input, .field select, .filters input, .search-big {
  border: 1px solid #d6d2c8; border-radius: 8px; padding: 9px 11px; background: #fff; min-width: 0;
}
.field input:focus, .field select:focus, .filters input:focus, .search-big:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px #e8a31733;
}
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.field input, .field select { width: 100%; }
.total-line {
  display: flex; justify-content: space-between; align-items: baseline;
  border-top: 1px solid var(--line); padding-top: 10px; color: var(--ink-2);
}
.total-line strong { font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }
.hint { font-size: 12px; color: var(--ink-3); min-height: 0; }
.hint.warn { color: var(--red); }
.stock-pill {
  font-size: 13px; padding: 8px 12px; border-radius: 8px; background: var(--in-bg); color: var(--in);
}
.stock-pill.low { background: var(--red-bg); color: var(--red); }
.btn-primary {
  margin-top: 4px; border: 0; border-radius: 8px; padding: 11px; font-weight: 600; cursor: pointer;
  background: var(--in); color: #fff;
}
.btn-primary.out { background: var(--out); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-primary:focus-visible { outline: 3px solid #e8a31799; outline-offset: 2px; }

/* ---------- Laporan ---------- */
.report { padding: 18px; min-height: 400px; }
.report-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 6px; }
.filters input[type=search] { width: 220px; }
.report-sum { font-size: 12px; color: var(--ink-3); margin: 10px 0 6px; }
.day { margin-top: 14px; }
.day-head {
  display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .04em; padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.entry {
  display: grid; grid-template-columns: 62px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid #f0ede6;
}
.entry-time { font-variant-numeric: tabular-nums; color: var(--ink-3); font-size: 13px; }
.entry-name { font-weight: 600; }
.entry-meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #f1eee6; color: var(--ink-2); margin-right: 6px; }
.entry-qty { text-align: right; font-variant-numeric: tabular-nums; }
.entry-qty b { font-size: 15px; }
.entry-qty.in b { color: var(--in); }
.entry-qty.out b { color: var(--out); }
.entry-qty small { display: block; font-size: 12px; color: var(--ink-3); }
.more { display: block; margin: 14px auto 0; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.more:hover { border-color: var(--ink-3); }
.empty { text-align: center; color: var(--ink-3); padding: 40px 0; }

/* ---------- Stok ---------- */
.stock-tools { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.search-big { font-size: 16px; padding: 12px 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid #d6d2c8; background: #fff; border-radius: 16px; padding: 5px 12px; cursor: pointer; font-size: 13px;
}
.chip:hover { border-color: var(--ink-3); }
.chip.active { background: var(--side); border-color: var(--side); color: #fff; }
.chip .n { color: var(--ink-3); margin-left: 4px; }
.chip.active .n { color: #aab0b7; }

.table-wrap { overflow: hidden; }
.stock-table { width: 100%; border-collapse: collapse; }
.stock-table th {
  position: sticky; top: 0; background: #faf8f3; text-align: left; font-size: 12px; color: var(--ink-2);
  font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.stock-table td { padding: 9px 14px; border-bottom: 1px solid #f0ede6; }
.stock-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.stock-table tbody tr.item { cursor: pointer; }
.stock-table tbody tr.item:hover td { background: #faf8f3; }
.stock-table tbody tr.item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.group td {
  background: #f6f4ee; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-2); padding: 8px 14px;
}
.group.alert td { background: var(--red); color: #fff; }
tr.low td { background: var(--red-bg); color: var(--red); border-bottom-color: var(--red-line); }
tr.low:hover td { background: #fadad6 !important; }
tr.low .name { font-weight: 700; }
.status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.status.ok { background: var(--in-bg); color: var(--in); }
.status.low { background: var(--red); color: #fff; }
.status.none { background: #f1eee6; color: var(--ink-3); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: #11141899; display: grid; place-items: center; z-index: 20; padding: 24px;
}
.modal-box {
  position: relative; background: var(--card); border-radius: 14px; width: min(920px, 100%);
  max-height: 100%; overflow: auto; display: grid; grid-template-columns: 1.1fr 1fr;
}
.modal-close {
  position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: #f1eee6; font-size: 20px; cursor: pointer; z-index: 1;
}
.modal-close:hover { background: #e5e1d6; }
.modal-img {
  background: #f1eee6; min-height: 380px; display: grid; place-items: center; color: var(--ink-3);
  border-radius: 14px 0 0 14px; overflow: hidden; padding: 16px; text-align: center;
}
.modal-img img { max-width: 100%; max-height: 520px; object-fit: contain; }
.modal-info { padding: 26px 24px; }
.d-kat { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.modal-info h2 { margin: 4px 0 12px; font-size: 20px; padding-right: 30px; }
.d-stok { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.d-stok small { font-size: 14px; font-weight: 500; color: var(--ink-3); }
.d-stok.low { color: var(--red); }
.d-lok {
  display: inline-block; margin-top: 8px; padding: 3px 10px; border-radius: 8px;
  background: var(--accent); color: var(--ink); font-size: 13px; font-weight: 700; letter-spacing: .02em;
}
.d-lok.empty-lok { background: #f1eee6; color: var(--ink-3); font-weight: 500; }
.stock-table td.lok { white-space: nowrap; font-weight: 600; color: var(--ink-2); }
.muted { color: var(--ink-3); font-weight: 400; }
.d-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 14px; margin: 14px 0; }
.d-grid .d-sec {
  grid-column: 1 / -1; padding-top: 8px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2);
}
.d-grid div.d-sec { border-top: 0; }
.d-grid .wide { grid-column: 1 / -1; }
.d-grid .wide dd { font-weight: 500; }
.d-grid div { border-top: 1px solid var(--line); padding-top: 6px; }
.d-grid dt { font-size: 12px; color: var(--ink-3); }
.d-grid dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.modal-info h3 { font-size: 13px; margin: 18px 0 6px; }
.d-moves { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.d-moves li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid #f0ede6; }
.d-moves .q-in { color: var(--in); font-weight: 600; }
.d-moves .q-out { color: var(--out); font-weight: 600; }
.d-moves span:first-child { color: var(--ink-2); }

/* ---------- Tambah barang baru ---------- */
.tools-row { display: flex; justify-content: flex-end; }
.btn-add {
  border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; cursor: pointer;
  background: var(--in); color: #fff;
}
.btn-add:hover { filter: brightness(1.08); }
.link-add { background: none; border: 0; padding: 0; color: var(--in); font-weight: 700; cursor: pointer; text-decoration: underline; font-size: 12px; }
.modal-box.form-baru {
  display: flex; flex-direction: column; gap: 12px; width: min(520px, 100%); padding: 24px 24px 22px;
}
.form-baru h2 { margin: 0; font-size: 19px; padding-right: 40px; }
.form-baru .hint { margin: -4px 0 2px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--side); color: #fff;
  padding: 11px 18px; border-radius: 8px; z-index: 30; box-shadow: 0 6px 24px #0003;
}
.toast.err { background: var(--red); }

@media (max-width: 1180px) {
  .split { grid-template-columns: 1fr; }
  .form { position: static; }
  .modal-box { grid-template-columns: 1fr; }
  .modal-img { border-radius: 14px 14px 0 0; min-height: 260px; }
}
