:root {
  /* Warna brand Al-Hafizh: hijau tua, emas, krem (diambil dari logo) */
  --brand: #124020; --brand-2: #1d5a30; --gold: #a59c46; --gold-dark: #736b37; --cream: #eee8d8;
  --bg: #f6f4ec; --card: #fff; --text: #17251b; --muted: #66705f; --line: #e3dfcf;
  --primary: #124020; --primary-ink: #fff; --primary-soft: #f1eedb;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #8a6d1c; --warn-soft: #f6efcf; --bad: #b91c1c; --bad-soft: #fee2e2;
  --shopee: #ee4d2d; --instan: #c2410c;
  --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.2; }
h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); font-size: .88em; }
.error { color: var(--bad); min-height: 1em; margin: .4rem 0 0; }
.empty { color: var(--muted); text-align: center; padding: 1rem; margin: 0; }
.right { text-align: right; white-space: nowrap; }

/* login */
.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 24px 16px; background: var(--brand); }
.login-logo { width: min(240px, 60vw); height: auto; }
.login-card h1 { color: var(--brand); font-size: 1.3rem; margin: 0; }
.login-card p { margin: 0; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: .8rem; }

/* layout */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; background: var(--brand); color: var(--cream); border-bottom: 3px solid var(--gold); }
.topbar a { color: var(--gold); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; font-family: Georgia, "Times New Roman", serif; font-style: italic; }
.brand small { font-family: system-ui, sans-serif; font-style: normal; font-weight: 600; font-size: .75rem; color: var(--gold); letter-spacing: 1px; text-transform: uppercase; margin-left: 4px; }
.brand-logo { height: 34px; width: auto; }
.me { font-size: .9rem; }
main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 80px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.hint { background: var(--primary-soft); border-color: var(--gold); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px 14px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* pipeline */
.pipeline { display: flex; align-items: center; gap: 4px; overflow-x: auto; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.pipeline i { color: var(--muted); font-style: normal; }
.step { flex: 1 0 auto; min-width: 92px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 6px 10px; cursor: pointer; text-align: left; color: var(--text); font: inherit; }
.step b { display: block; font-size: 1.3rem; }
.step span { font-size: .78rem; color: var(--muted); }
.step.has { border-color: var(--gold); background: var(--primary-soft); }
.step.has b { color: var(--brand); }

/* tabs */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px 0; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.tabs button { position: relative; border: 0; background: none; padding: 10px 12px; font: inherit; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-color: var(--primary); }
.tabs button[data-count]:not([data-count=""])::after { content: attr(data-count); margin-left: 6px; background: var(--bad); color: #fff; border-radius: 999px; padding: 0 7px; font-size: .75rem; }
.tab { display: none; } .tab.active { display: block; }

/* forms */
label { display: grid; gap: 4px; font-size: .88rem; color: var(--muted); }
.lbl { display: block; font-size: .88rem; color: var(--muted); margin: 8px 0 4px; }
input, select, textarea { font: inherit; color: var(--text); padding: 9px 10px; border: 1px solid #d4cfba; border-radius: 8px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--gold); border-color: var(--brand); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .95rem; margin: 8px 0; }
label.check input { width: 20px; height: 20px; flex: none; }
.seg { display: flex; border: 1px solid #d4cfba; border-radius: 8px; overflow: hidden; }
.seg label { flex: 1; display: block; color: var(--text); position: relative; }
.seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg span { display: block; text-align: center; padding: 9px; cursor: pointer; font-weight: 600; }
.seg input:checked + span { background: var(--primary); color: #fff; }
.item-row { display: grid; grid-template-columns: 1fr 80px auto; gap: 6px; margin-bottom: 6px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters label { flex: 1 1 150px; }
.scan { display: flex; gap: 8px; margin-bottom: 10px; }
.scan input { font-size: 1.1rem; font-family: ui-monospace, monospace; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 9px 14px; border-radius: 8px; border: 1px solid #d4cfba; background: #fff; color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--brand-2); filter: none; }
.btn.danger { color: var(--bad); border-color: #fca5a5; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.big { padding: 12px 18px; font-size: 1rem; }

/* badges */
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--text); vertical-align: middle; }
.badge.mp-shopee { background: #fde4dd; color: var(--shopee); }
.badge.mp-tokopedia { background: #dcf5dd; color: #027a0a; }
.badge.instan { background: var(--instan); color: #fff; }
.badge.reguler { background: #e7e5e4; }
.badge.st-baru { background: #e0e7ff; color: #3730a3; }
.badge.st-dicek { background: var(--warn-soft); color: var(--warn); }
.badge.st-siap_pickup { background: #cffafe; color: #0e7490; }
.badge.st-selesai { background: var(--ok-soft); color: var(--ok); }
.badge.st-batal { background: var(--bad-soft); color: var(--bad); }

/* kartu order */
.card-order.instan { border-left: 5px solid var(--instan); }
.ono { font-weight: 700; font-family: ui-monospace, monospace; }
.items { margin: 8px 0; padding: 0; list-style: none; }
.items li { padding: 6px 10px; background: var(--bg); border-radius: 8px; margin-bottom: 4px; font-size: 1.02rem; }
.items .size { background: var(--cream); color: var(--gold-dark); padding: 1px 6px; border-radius: 5px; font-weight: 700; }
.items .qty { float: right; font-weight: 800; font-size: 1.1rem; }
.note { background: #faf8ee; border: 1px dashed var(--gold); border-radius: 8px; padding: 6px 10px; margin: 6px 0; }
.note.danger { background: var(--bad-soft); border-color: #fca5a5; }
.resi, .resi-big { font-family: ui-monospace, monospace; font-weight: 700; letter-spacing: .5px; }
.resi-big { font-size: 1.25rem; text-align: center; padding: 8px; border: 2px dashed var(--line); border-radius: 8px; margin: 8px 0; word-break: break-all; }
.resi.small { font-size: .85rem; }
.group-title { margin: 18px 4px 8px; }
.pick-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.pick-info { flex: 1 1 240px; min-width: 0; }
.pick-btns { display: flex; gap: 6px; }

.totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.total { display: flex; align-items: center; gap: 10px; background: var(--primary-soft); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.total b { font-size: 1.6rem; color: var(--brand); }
.total small { color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.kpi b { display: block; font-size: 1.8rem; }
.kpi span { color: var(--muted); font-size: .85rem; }
.kpi.ok b { color: var(--ok); } .kpi.warn b { color: var(--warn); } .kpi.bad b { color: var(--bad); }

/* tabel */
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: .78rem; text-transform: uppercase; color: var(--muted); letter-spacing: .3px; }
.tbl tr.off { opacity: .5; }
.card > .tbl, .card > div > .tbl { display: block; overflow-x: auto; }
@media (min-width: 700px) { .card > .tbl, .card > div > .tbl { display: table; } }

dialog { border: 0; border-radius: var(--radius); padding: 18px; width: min(560px, calc(100vw - 32px)); max-height: 90vh; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.timeline { padding-left: 1.2rem; } .timeline li { margin-bottom: 6px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(120px); background: #1f1a14; color: #fff; padding: 10px 16px; border-radius: 10px; transition: transform .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--bad); }

@media (max-width: 560px) {
  .topbar .me { font-size: .8rem; }
  .items .qty { float: none; margin-left: 6px; }
  .scan { flex-direction: column; }
}
@media print { .topbar, .tabs, .pipeline, .filters { display: none; } }

/* --- toko, gudang, keuangan --- */
.me { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.wh-select { width: auto; padding: 4px 8px; font-size: .85rem; background: var(--brand-2); color: var(--cream); border-color: var(--gold-dark); }
.badge.wh { background: var(--cream); color: var(--gold-dark); }
.badge.mp-tiktokshop { background: #e7e5e4; color: #111; }
.badge.mp-lazada { background: #e0e7ff; color: #1e3a8a; }
.badge.mp-lainnya { background: var(--line); }
.kpi small { display: block; color: var(--muted); font-size: .78rem; margin-top: 2px; }
.kpi.ok b { color: var(--ok); }
.kpis-sm .kpi { border: 0; background: var(--bg); padding: 10px; }
.kpis-sm .kpi b { font-size: 1.25rem; }
.progress { height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 6px 0 12px; }
.progress i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.note-warn { background: var(--warn-soft); border-color: var(--gold); line-height: 1.7; }
.fin-tabs { flex: 1 1 100%; }
.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11px; }
.chart .bar path { fill: var(--brand); }
.chart .bar .hit { fill: transparent; }
.chart .bar.on path { fill: var(--brand-2); }
.chart .bar.on .hit { fill: rgba(18, 64, 32, .06); }
.chart-tip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: .82rem; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; }
details summary { cursor: pointer; color: var(--brand); margin-top: 8px; }
.fin-orders input.money { min-width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.fin-orders tr.saved td { background: var(--ok-soft); transition: background .2s; }
.hist { white-space: nowrap; }
.linkbtn { border: 0; background: none; color: var(--bad); cursor: pointer; font: inherit; padding: 0 4px; }
.hpp-form { display: grid; gap: 10px; }
.kpi b { white-space: nowrap; }
@media (max-width: 560px) {
  .kpi b { font-size: 1.3rem; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-wrap { overflow-x: auto; }
  .chart { min-width: 560px; }
}

/* --- grafik garis / batang --- */
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .85rem; color: var(--text); margin: 4px 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; flex: none; }
.legend .sw { margin-right: 0; }
.chart .grid.zero { stroke: #c9c3ad; }
.chart .ax.hl { fill: var(--text); font-weight: 700; }
.chart .band { fill: var(--primary-soft); }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--card); stroke-width: 2; }
.chart .lead { stroke-width: 1; opacity: .6; }
.chart .dl { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart .hit { fill: transparent; }
.chart .xh { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; }
.chart g.on .xh { opacity: .7; }
.chart.bars g.on .hit { fill: rgba(18, 64, 32, .05); }
.chart-tip .sw { width: 9px; height: 9px; }
.year-nav { display: flex; align-items: center; gap: 10px; }
.year-nav h2 { margin: 0; }
.btn:disabled { opacity: .4; cursor: default; }
.chart-note { margin: 4px 0 0; font-size: .8rem; }

/* --- laporan unduh (PDF lewat cetak) --- */
.rep-form { display: grid; gap: 8px; }
.rep-form .seg span { font-size: .9rem; }
.print-area { display: none; }
@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body.printing { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; font-size: 11pt; }
  body.printing > *:not(.print-area) { display: none !important; }
  body.printing .print-area { display: block; color: var(--text); }
  .print-area section { break-inside: avoid; margin: 0 0 14px; }
  .print-area h3 { color: var(--brand); border-bottom: 2px solid var(--gold); padding-bottom: 4px; margin: 12px 0 8px; font-size: 12pt; }
  .print-area .kpis { grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 14px; }
  .print-area .kpi { border: 1px solid var(--line); padding: 8px 10px; break-inside: avoid; }
  .print-area .kpi b { font-size: 14pt; white-space: nowrap; }
  .print-area .chart { min-width: 0; width: 100%; }
  .print-area .chart-wrap { overflow: visible; }
  .print-area .tbl { display: table; font-size: 9.5pt; }
  .print-area .tbl th, .print-area .tbl td { padding: 4px 6px; }
  .print-area .progress { height: 10px; }
  .rep-head { display: flex; align-items: center; gap: 12px; padding-bottom: 10px; border-bottom: 3px solid var(--brand); margin-bottom: 6px; }
  .rep-head img { height: 46px; }
  .rep-brand { font-family: Georgia, serif; font-style: italic; font-weight: 700; font-size: 18pt; color: var(--brand); }
  .rep-tag { color: var(--gold-dark); font-size: 9pt; letter-spacing: .5px; }
  .rep-meta { margin-left: auto; text-align: right; font-size: 9.5pt; color: var(--muted); }
  .rep-meta b { color: var(--text); font-size: 12pt; }
  .rep-foot { margin-top: 12px; padding-top: 6px; border-top: 1px solid var(--line); font-size: 8.5pt; color: var(--muted); }
}

/* --- agen / reseller / offline --- */
.inline { display: flex; gap: 6px; }
.inline select { flex: 1; }
.item-row.sale { grid-template-columns: 1fr 70px 120px auto; }
.price-in { text-align: right; }
.sale-box { border: 1px dashed var(--gold); border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; background: #fcfbf5; }
.sale-total { margin-top: 8px; line-height: 1.6; }
.sale-total .big { font-size: 1.05rem; }
.stamp { display: inline-block; border: 2px solid var(--ok); color: var(--ok); font-weight: 800; padding: 2px 10px; border-radius: 6px; letter-spacing: 2px; }
@media (max-width: 560px) { .item-row.sale { grid-template-columns: 1fr 56px; } .item-row.sale .price-in { grid-column: 1; } }
@media print {
  .print-area .inv-to { margin: 10px 0; line-height: 1.5; }
  .print-area .tbl.inv td, .print-area .tbl.inv th { padding: 6px; }
  .print-area .r { text-align: right; }
  .print-area .inv-sum { margin: 8px 0 0 auto; border-collapse: collapse; min-width: 50%; font-size: 10.5pt; }
  .print-area .inv-sum td { padding: 4px 8px; text-align: right; }
  .print-area .inv-sum td:first-child { text-align: left; color: var(--muted); }
  .print-area .inv-sum tr.tot td { font-weight: 800; color: var(--text); border-top: 1.5px solid var(--text); font-size: 12pt; }
  .print-area .inv-pay { border: 1px dashed var(--gold); padding: 8px 10px; border-radius: 6px; }
}

.fin-orders.no-hpp .hpp-col { display: none; }
.pipeline.readonly .step { cursor: default; }
