:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --soft: #f7f8fa;
  --line: #eceef2;
  --text: #1c2230;
  --muted: #6b7280;
  --brand: #fcd242;      /* kuning Kuronoa */
  --brand-ink: #9a7419;  /* emas 'BAKERY' untuk teks/garis */
  --brand-soft: #fff6d6;
  --good: #11875d;
  --good-soft: #e8f6ef;
  --bad: #d23a3a;
  --bad-soft: #fdecec;
  --warn: #b7791f;
  --warn-soft: #fdf6e7;
  --c1: #2f7de1;          /* penjualan */
  --c2: #f0a43a;          /* bahan baku */
  --c3: #e2626b;          /* beban ops */
  --c4: #1c2230;          /* laba */
  --radius: 14px;
  --gap: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h3 { font-size: 15px; font-weight: 700; margin-bottom: 12px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }

/* ---------- Tombol ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: #e9bd24; color: var(--text); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  color: var(--text); display: inline-grid; place-items: center; cursor: pointer;
}
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.94);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) calc(16px + var(--safe-r)) 10px calc(16px + var(--safe-l));
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 38px; height: 38px; object-fit: contain; border-radius: 9px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 17px; }
.brand-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kuronoa-logo { height: 44px; width: auto; justify-self: center; object-fit: contain; }
.actions { display: flex; align-items: center; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 99px;
  background: var(--soft); border: 1px solid var(--line); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.chip.ok .dot { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.chip.warn .dot { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.chip.bad .dot { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

.banner {
  margin: 10px calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l));
  padding: 10px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: var(--warn-soft); color: #7a4f0e; border: 1px solid #f4e2bb;
  display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.banner.bad { background: var(--bad-soft); color: #8f1f1f; border-color: #f6caca; }
.banner .btn { height: 30px; }

/* ---------- Layout ---------- */
.wrap {
  width: 100%;
  padding: 14px calc(16px + var(--safe-r)) calc(28px + var(--safe-b)) calc(16px + var(--safe-l));
  display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr);
}
.wrap > * { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.grid2 { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .grid2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; min-width: 0; }
.toolbar > * { min-width: 0; }
.seg { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; max-width: 100%; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: none; height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line);
  background: #fff; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button[aria-selected="true"] { background: var(--text); color: #fff; border-color: var(--text); }

/* ---------- KPI ---------- */
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(165px, 100%), 1fr)); }
.kpi { min-width: 0; }
.kpi { border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; background: #fff; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent, var(--line)); }
.kpi .lbl { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .val { font-size: 21px; font-weight: 800; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .val.pos { color: var(--good); }
.kpi .val.neg { color: var(--bad); }
.delta { font-weight: 700; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

/* ---------- Grafik ---------- */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-size: 11px; fill: var(--muted); font-family: inherit; }
.chart .axis { stroke: var(--line); }
.chart .zero { stroke: #cfd4dc; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin: -4px 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.empty { padding: 26px 8px; text-align: center; color: var(--muted); font-size: 13px; }

/* Komposisi biaya */
.bar-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.bar-row:last-child { border-bottom: 0; }
.bar-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 8px; border-radius: 99px; background: var(--soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, #f6c42f, var(--brand)); }
.bar-row .amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.bar-row .amt small { display: block; color: var(--muted); font-weight: 500; }

/* Neraca ringkas */
.nr { display: grid; grid-template-columns: 1fr auto; gap: 0; font-size: 13px; }
.nr div { padding: 7px 0; border-bottom: 1px solid var(--line); }
.nr div:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.nr .hd { font-weight: 800; color: var(--text); background: transparent; }
.nr .tot { font-weight: 800; border-bottom: 2px solid var(--text); }
.nr .ind { padding-left: 14px; color: var(--muted); }

/* Tabel */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 760px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { text-align: right; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--soft); }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl td { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr.inactive td { color: #b4b9c2; }
.tbl tr.total td { font-weight: 800; border-top: 2px solid var(--text); border-bottom: 0; }
.tbl .pos { color: var(--good); font-weight: 700; }
.tbl .neg { color: var(--bad); font-weight: 700; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.pill.ok { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.mute { background: var(--soft); color: var(--muted); }

/* Status */
.status-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.st { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.st .ic { width: 26px; height: 26px; border-radius: 8px; flex: none; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.st.ok .ic { background: var(--good-soft); color: var(--good); }
.st.warn .ic { background: var(--warn-soft); color: var(--warn); }
.st.bad .ic { background: var(--bad-soft); color: var(--bad); }
.st.info .ic { background: var(--soft); color: var(--muted); }
.st b { display: block; font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.st span { font-size: 13px; font-weight: 600; word-break: break-word; }

/* Footer */
.foot { text-align: center; padding: 6px 0 0; }
.foot img { height: 64px; }
.credit { margin: 6px 0 0; font-weight: 700; color: var(--text); }
.foot .muted { margin: 2px 0 0; }

/* PDF header (hanya saat ekspor) */
.pdf-head { display: none; }

/* ---------- Kunci ---------- */
.lock { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: #fff; }
.lock-card { width: min(380px, 100%); text-align: center; }
.lock-logo { width: 84px; height: 84px; object-fit: contain; border-radius: 18px; }
.lock-card h1 { font-size: 26px; margin-top: 10px; }
.lock-card form { margin-top: 22px; display: grid; gap: 12px; }
.lock-card input[type=password], .lock-card input[type=url], .sheet input {
  width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--line); padding: 0 14px;
  font: inherit; font-size: 16px; background: #fff; color: var(--text); outline: none; text-align: center;
}
.lock-card input[type=password] { letter-spacing: .35em; font-size: 20px; }
.lock-card input:focus { border-color: var(--brand-ink); box-shadow: 0 0 0 3px var(--brand-soft); }
.check { display: flex; align-items: center; gap: 8px; justify-content: center; font-size: 13px; color: var(--muted); }
.msg { min-height: 18px; margin: 0; font-size: 13px; color: var(--bad); font-weight: 600; }
.adv { margin-top: 18px; text-align: left; font-size: 13px; color: var(--muted); }
.adv summary { cursor: pointer; text-align: center; }
.adv[open] { display: grid; gap: 8px; }
.adv input { text-align: left !important; font-size: 13px !important; }
.lock-brand { height: 72px; margin-top: 26px; opacity: .9; }

/* ---------- Dialog ---------- */
.sheet { border: 0; border-radius: 18px; padding: 18px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(16,24,40,.18); }
.sheet::backdrop { background: rgba(16,24,40,.35); }
.menu-list { display: grid; gap: 6px; margin: 14px 0; }
.menu-item { text-align: left; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.menu-item:hover { background: var(--soft); }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%) translateY(30px);
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.busy { position: fixed; inset: 0; background: rgba(255,255,255,.86); z-index: 60; display: grid; place-content: center; justify-items: center; gap: 10px; font-weight: 700; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand-ink); animation: spin .8s linear infinite; }

/* ---------- Responsif ---------- */
@media (max-width: 640px) {
  .topbar { grid-template-columns: auto auto; }
  .kuronoa-logo { display: none; }
  .actions { justify-self: end; }
  .btn#btnPdf span { display: none; }
  .btn#btnPdf { width: 38px; padding: 0; }
  .topbar { gap: 8px; }
  .brand-text span { display: none; }
  .chip span { max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
  .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .kpi .val { font-size: 18px; }
}
@media (max-width: 420px) {
  .chip { width: 30px; padding: 0; justify-content: center; }
  .chip span { display: none; }
  .actions { gap: 6px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { padding-top: calc(6px + var(--safe-t)); padding-bottom: 6px; }
  .kpis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* ---------- Mode ekspor PDF ---------- */
body.pdf-mode .topbar, body.pdf-mode .banner, body.pdf-mode .toolbar { display: none !important; }
body.pdf-mode #report { width: 1000px; padding: 0; gap: 12px; background: #fff; }
body.pdf-mode .pdf-head {
  display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 14px;
  padding: 0 0 12px; border-bottom: 2px solid var(--text);
}
body.pdf-mode .pdf-head img { width: 56px; height: 56px; object-fit: contain; }
body.pdf-mode .pdf-head img.right { width: auto; height: 46px; }
body.pdf-mode .pdf-head h2 { font-size: 22px; }
body.pdf-mode .grid2 { grid-template-columns: 1fr 1fr; }
body.pdf-mode .kpis { grid-template-columns: repeat(4, 1fr); }
body.pdf-mode .table-wrap { overflow: visible; }
body.pdf-mode .tbl { min-width: 0; font-size: 12px; }
body.pdf-mode .tbl th, body.pdf-mode .tbl td { padding: 6px 7px; }
body.pdf-mode .status-grid { grid-template-columns: repeat(3, 1fr); }
body.pdf-mode .foot { display: none; }
