:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e2e5e9;
  --line-strong: #c9ced4;
  --head: #f3f4f6;
  --text: #1f2933;
  --muted: #6b7280;
  --accent: #1e7145;
  --accent-dark: #165a36;
  --accent-soft: #e8f3ec;
  --today: #fff8db;
  --ok-bg: #e6f4ea;   --ok: #1e6b3a;
  --warn-bg: #fff1d6; --warn: #8a4b00;
  --bad-bg: #fde8e8;  --bad: #a4161a;
  --none-bg: #f1f2f4; --none: #6b7280;
  --row-h: 34px;
  --radius: 8px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }

/* ---------- tombol & input ---------- */
.btn {
  height: 34px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--line-strong);
  background: var(--panel); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--head); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--head); color: var(--text); }
.btn.icon { width: 34px; padding: 0; font-size: 16px; }
.btn.block { width: 100%; height: 44px; font-size: 15px; }
.field {
  height: 34px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--panel);
}
.field:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field.search { width: 200px; }

/* ---------- login ---------- */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 32px 28px; text-align: center; box-shadow: 0 4px 24px rgba(15, 23, 42, .06);
}
.login-card h1 { margin: 14px 0 2px; font-size: 22px; }
.login-card p { margin: 0; }
.mark {
  display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px;
  border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; font-size: 22px;
}
.mark.sm { width: 32px; height: 32px; border-radius: 8px; font-size: 15px; }
.pin-label { display: block; margin: 26px 0 8px; color: var(--muted); font-size: 13px; }
.pin-input {
  width: 100%; height: 52px; margin-bottom: 14px; border: 1px solid var(--line-strong); border-radius: 10px;
  text-align: center; font-size: 26px; letter-spacing: 12px;
}
.pin-input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.login-msg { min-height: 20px; margin-top: 12px !important; color: var(--bad); font-size: 13px; }

/* ---------- kerangka aplikasi ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  flex: none; height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text span { color: var(--muted); font-size: 12px; }
.top-right { display: flex; align-items: center; gap: 8px; }
.save-state { font-size: 13px; color: var(--muted); }
.save-state.saving { color: var(--warn); }
.save-state.error { color: var(--bad); cursor: pointer; text-decoration: underline; }
.save-state.ok { color: var(--ok); }

.toolbar {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.toolbar .title { font-weight: 600; font-size: 15px; margin-right: 6px; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); }
.toolbar .grow { flex: 1; }
.toolbar label.inline { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.month-label { min-width: 130px; text-align: center; font-weight: 600; }
.legend { display: flex; gap: 12px; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
.legend .l-bad { background: var(--bad-bg); border: 1px solid #f3b4b4; }
.legend .l-warn { background: var(--warn-bg); border: 1px solid #f2cf8f; }
.legend .l-today { background: var(--today); border: 1px solid #ecd98a; }

.fbar {
  flex: none; display: flex; align-items: center; height: 32px; background: var(--panel);
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.fbar-ref {
  min-width: 170px; height: 100%; display: flex; align-items: center; padding: 0 12px;
  border-right: 1px solid var(--line); font-weight: 600; white-space: nowrap;
}
.fbar-fx { padding: 0 10px; color: var(--muted); font-style: italic; border-right: 1px solid var(--line); }
.fbar-val { padding: 0 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sheet { flex: 1; overflow: auto; background: var(--panel); outline: none; }
.sheet.pad { background: var(--bg); padding: 16px; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- tab sheet (seperti Excel) ---------- */
.tabs {
  flex: none; display: flex; gap: 2px; padding: 0 8px; overflow-x: auto; background: var(--head);
  border-top: 1px solid var(--line-strong);
}
.tab {
  flex: none; height: 36px; padding: 0 16px; border: 0; border-bottom: 3px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); background: #e9ebee; }
.tab.active { background: var(--panel); color: var(--accent); font-weight: 600; border-bottom-color: var(--accent); }
.tab.sep-left { margin-left: 10px; }

/* ---------- grid ---------- */
table.grid { border-collapse: separate; border-spacing: 0; min-width: 100%; font-variant-numeric: tabular-nums; }
.grid th, .grid td {
  height: var(--row-h); padding: 0 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  white-space: nowrap; background: var(--panel);
}
.grid thead th {
  position: sticky; top: 0; z-index: 2; background: var(--head); font-weight: 600; font-size: 13px;
  color: #374151; text-align: left; border-bottom: 1px solid var(--line-strong);
}
.grid thead tr.letters th {
  height: 22px; font-size: 11px; font-weight: 400; color: #9aa1aa; text-align: center; border-bottom: 1px solid var(--line);
}
.grid thead tr.letters + tr th { top: 22px; }
.grid .rn { width: 44px; min-width: 44px; text-align: center; color: #9aa1aa; background: var(--head); font-size: 12px; }
.grid td.rn { position: sticky; left: 0; z-index: 1; }
.grid thead th.rn { left: 0; z-index: 3; }
.grid .stick1 { position: sticky; left: 44px; z-index: 1; }
.grid .stick2 { position: sticky; left: 164px; z-index: 1; box-shadow: 1px 0 0 var(--line-strong); }
.grid .c-sku { width: 120px; min-width: 120px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.grid .c-nama { min-width: 200px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.grid thead th.stick1, .grid thead th.stick2 { z-index: 3; }
.grid .num { text-align: right; }
.grid .center { text-align: center; }
.grid .dim { color: var(--muted); }
.grid tbody tr:hover td { background: #fafbfc; }
.grid tbody tr:hover td.rn { background: var(--head); }
.grid tr.group td {
  height: 30px; background: var(--accent-soft) !important; color: var(--accent-dark); font-weight: 600; font-size: 12px;
  letter-spacing: .4px; text-transform: uppercase;
}
.grid tr.group td span { position: sticky; left: 54px; }
.grid tr.total td { font-weight: 700; background: var(--head) !important; }

/* kolom tanggal */
.grid th.day { text-align: center; min-width: 76px; line-height: 1.1; }
.grid th.day small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.grid th.day.today, .grid td.today { background: var(--today); }
.grid th.day.today { color: #7a5b00; }
.grid td.future, .grid th.future { background: #fafafa; color: #c3c7cc; }
.grid td.edit { cursor: cell; text-align: right; min-width: 76px; }
.grid td.v-bad { background: var(--bad-bg) !important; color: var(--bad); font-weight: 600; }
.grid td.v-warn { background: var(--warn-bg) !important; color: var(--warn); font-weight: 600; }
.grid td.sel { outline: 2px solid var(--accent); outline-offset: -2px; position: relative; z-index: 1; }
.grid td.unsaved { box-shadow: inset 3px 0 0 var(--bad); }
.grid td.editing { padding: 0; outline: 2px solid var(--accent); outline-offset: -2px; }
.cell-input {
  width: 100%; height: calc(var(--row-h) - 2px); border: 0; padding: 0 9px; text-align: right;
  background: #fff; outline: none; font-variant-numeric: tabular-nums;
}
.grid td.min-col { background: #fbfcfd; }
.grid td.click { cursor: pointer; }
.grid td.toggle { text-align: center; cursor: pointer; color: var(--accent); font-weight: 700; }
.grid td.toggle.off { color: #d0d4d9; font-weight: 400; }
.grid tbody tr.link { cursor: pointer; }

/* status */
.pill {
  display: inline-block; min-width: 118px; padding: 3px 10px; border-radius: 999px; font-size: 12px;
  font-weight: 600; text-align: center;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.none { background: var(--none-bg); color: var(--none); }
.up { color: var(--ok); }
.down { color: var(--bad); }

/* ---------- dashboard ---------- */
.tiles { flex: none; display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  text-align: left; cursor: default;
}
.tile .k { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tile .v { font-size: clamp(18px, 1.7vw, 24px); font-weight: 700; font-variant-numeric: tabular-nums; }
.tile.filter { cursor: pointer; }
.tile.filter:hover { border-color: var(--line-strong); }
.tile.ok .v { color: var(--ok); }
.tile.warn .v { color: var(--warn); }
.tile.bad .v { color: var(--bad); }
.tile.none .v { color: var(--none); }
.tile.active { outline: 2px solid currentColor; }
.tile.ok.active { outline-color: var(--ok); }
.tile.warn.active { outline-color: var(--warn); }
.tile.bad.active { outline-color: var(--bad); }
.tile.none.active { outline-color: var(--none); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.card.fit { flex: 0 1 auto; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.card-head b { font-size: 14px; }
.card-scroll { overflow: auto; flex: 1 1 auto; min-height: 0; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.note { flex: none; margin: 10px 0 0; color: var(--muted); font-size: 12px; }

/* ---------- dialog ---------- */
.dialog { border: 0; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.dialog::backdrop { background: rgba(15, 23, 42, .35); }
.dialog form { padding: 22px; }
.dialog h2 { margin: 0 0 16px; font-size: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label, .gudang-pick label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid input, .form-grid select { height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--text); background: #fff; }
.gudang-pick { margin: 14px 0 0; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.gudang-pick legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.gudang-pick div { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 12px; }
.gudang-pick label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.form-msg { min-height: 18px; color: var(--bad); font-size: 13px; margin: 10px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- layar kecil ---------- */
@media (max-width: 1200px) {
  .grid .opt { display: none; }
}
@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile.wide { grid-column: span 2; }
  .field.search { width: 100%; order: 10; }
  .legend { display: none; }
  .fbar-ref { min-width: 120px; }
  .sheet.pad { display: block; overflow: auto; }
  .card-scroll { max-height: 70vh; }
}
@media (max-width: 600px) {
  .topbar { padding: 0 12px; }
  .hide-sm { display: none; }
  .tiles { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .tile { padding: 8px 10px; }
  .tile .k { font-size: 11px; }
  .tile .v { font-size: 18px; }
  .tile.wide { grid-column: span 3; }
  /* input di HP: SKU pindah ke baris rumus, nama dipersempit supaya kolom tanggal terlihat */
  .grid.input tr.letters { display: none; }
  .grid.input thead tr.letters + tr th { top: 0; }
  .grid.input .rn { width: 30px; min-width: 30px; padding: 0 4px; }
  .grid.input .stick1 { display: none; }
  .grid.input .stick2 { left: 30px; }
  .grid.input .c-nama { min-width: 120px; max-width: 140px; }
  .grid.input tr.group td span { left: 38px; }
  .fbar-ref { min-width: 0; }
  .toolbar { padding: 8px 12px; }
  .brand-text span { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .sheet.pad { padding: 12px; }
}
