/* ==========================================================================
   PT Solusi Gizi Nusantara - tampilan aplikasi
   Warna diambil dari logo: navy #1F4E68 dan hijau daun #2E9E3C.
   Disusun mobile-first karena tim penjualan dan gudang memakainya dari HP.
   ========================================================================== */

:root {
  --navy: #1f4e68;
  --navy-dark: #163a4f;
  --navy-soft: #eaf1f5;
  --green: #2e9e3c;
  --green-dark: #24802f;
  --green-soft: #e8f6ea;
  --bg: #f2f5f7;
  --card: #ffffff;
  --text: #1d2b33;
  --muted: #6b7c86;
  --line: #e2e9ed;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warn: #c47d0a;
  --warn-soft: #fdf3e0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(31, 78, 104, .08), 0 6px 18px rgba(31, 78, 104, .06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

h1, h2, h3, p { margin: 0; }
button { font-family: inherit; }

/* ---------- Layar login --------------------------------------------------- */

#screen-login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 0%, #2b6486 0%, var(--navy) 45%, var(--navy-dark) 100%);
}
.login-wrap { width: 100%; max-width: 360px; text-align: center; }
.login-logo {
  width: 108px; height: 108px; object-fit: contain;
  background: #fff; border-radius: 50%; padding: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.login-title { color: #fff; font-size: 19px; font-weight: 700; margin-top: 16px; letter-spacing: .2px; }
.login-sub { color: #b9d3e2; font-size: 13px; margin-top: 3px; }
.login-card { background: #fff; border-radius: 16px; padding: 20px 18px 18px; margin-top: 22px; text-align: left; box-shadow: 0 14px 40px rgba(0, 0, 0, .22); }
.login-footer { color: #9dc0d3; font-size: 11.5px; margin-top: 18px; line-height: 1.6; }
.login-hint { background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18); border-radius: 10px; padding: 9px 12px; margin-top: 14px; color: #cfe4ef; font-size: 11.5px; line-height: 1.7; text-align: left; }
.login-hint b { color: #fff; }

/* ---------- Elemen dasar -------------------------------------------------- */

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; font-size: 15px; font-family: inherit; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(31, 78, 104, .1); }
input[readonly] { background: #f7f9fa; color: var(--muted); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7c86' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%; padding: 12px 16px; font-size: 15px; font-weight: 600;
  border: 0; border-radius: 11px; cursor: pointer; transition: filter .15s, opacity .15s;
}
.btn:active { filter: brightness(.93); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-ghost { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { width: auto; padding: 8px 14px; font-size: 13px; border-radius: 9px; }
.btn-row { display: flex; gap: 9px; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.pill-green { background: var(--green-soft); color: var(--green-dark); }
.pill-navy { background: var(--navy-soft); color: var(--navy); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-grey { background: #eef1f3; color: var(--muted); }

.muted { color: var(--muted); }
.rp { font-variant-numeric: tabular-nums; }
.center { text-align: center; }

/* ---------- Kerangka aplikasi --------------------------------------------- */

#app { display: none; min-height: 100dvh; padding-bottom: calc(74px + var(--safe-bottom)); }
#app.tampil { display: block; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy); color: #fff;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  display: flex; align-items: center; gap: 11px;
}
.topbar img { width: 34px; height: 34px; background: #fff; border-radius: 50%; padding: 2px; object-fit: contain; }
.topbar .judul { flex: 1; min-width: 0; }
.topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.topbar .sub { font-size: 11.5px; color: #a9c9da; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .keluar { background: rgba(255, 255, 255, .13); color: #fff; border: 0; padding: 7px 12px; border-radius: 9px; font-size: 12.5px; font-weight: 600; cursor: pointer; }

#view { padding: 14px 14px 20px; max-width: 780px; margin: 0 auto; }

.seg { display: flex; gap: 5px; background: #e7ecef; padding: 4px; border-radius: 11px; margin-bottom: 14px; overflow-x: auto; }
.seg button { flex: 1; min-width: 74px; border: 0; background: transparent; padding: 8px 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); border-radius: 8px; cursor: pointer; white-space: nowrap; }
.seg button.aktif { background: #fff; color: var(--navy); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); margin: 18px 0 9px; }
.section-label:first-child { margin-top: 2px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 0 9px; }
.section-head .section-label { margin: 0; }
.section-head a { font-size: 12.5px; color: var(--navy); font-weight: 600; text-decoration: none; }

/* ---------- Kartu & daftar ------------------------------------------------ */

.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card { margin-top: 10px; }

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi {
  background: var(--card); border-radius: var(--radius); padding: 13px 14px;
  box-shadow: var(--shadow); border-left: 3px solid var(--navy);
}
button.kpi { width: 100%; text-align: left; font-family: inherit; border-top: 0; border-right: 0; border-bottom: 0; cursor: pointer; }
.kpi.bisa-klik:active { background: #f7f9fa; transform: scale(.985); }
.kpi .lbl .panah { float: right; color: #b6c3cb; font-size: 17px; line-height: 1; margin-top: -1px; }
.kpi.hijau { border-left-color: var(--green); }
.kpi.merah { border-left-color: var(--danger); }
.kpi.kuning { border-left-color: var(--warn); }
.kpi .lbl { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 19px; font-weight: 800; color: var(--navy); margin-top: 3px; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.kpi .val.kecil { font-size: 16px; }
.kpi .ket { font-size: 11px; color: var(--muted); margin-top: 2px; }

.row-list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 11px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left; font-family: inherit; font-size: 15px; color: var(--text);
}
.row:last-child { border-bottom: 0; }
.row:active { background: #f7f9fa; }
.row.statis { cursor: default; }
.row .isi { flex: 1; min-width: 0; }
.row .nm { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 12px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .kanan { text-align: right; flex-shrink: 0; }
.row .nilai { font-weight: 700; font-size: 14.5px; font-variant-numeric: tabular-nums; }
.row .nilai.merah { color: var(--danger); }
.avatar {
  width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; background: var(--navy-soft); color: var(--navy);
}
.avatar.hijau { background: var(--green-soft); color: var(--green-dark); }
.avatar.merah { background: var(--danger-soft); color: var(--danger); }
.avatar.kuning { background: var(--warn-soft); color: var(--warn); }

.kosong { background: var(--card); border-radius: var(--radius); padding: 26px 18px; text-align: center; box-shadow: var(--shadow); }
.kosong .jdl { font-weight: 700; color: var(--navy); }
.kosong .ket { font-size: 13px; color: var(--muted); margin-top: 4px; }

.memuat { text-align: center; padding: 34px 0; color: var(--muted); font-size: 13.5px; }
.memuat::before {
  content: ''; display: block; width: 22px; height: 22px; margin: 0 auto 10px;
  border: 2.5px solid var(--line); border-top-color: var(--navy); border-radius: 50%;
  animation: putar .7s linear infinite;
}
@keyframes putar { to { transform: rotate(360deg); } }

/* ---------- Grafik batang sederhana --------------------------------------- */

.chart { display: flex; align-items: flex-end; gap: 3px; height: 78px; margin-top: 10px; }
.chart .bar { flex: 1; background: var(--navy-soft); border-radius: 3px 3px 0 0; min-height: 3px; position: relative; }
.chart .bar.puncak { background: var(--green); }
.chart-kaki { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); margin-top: 5px; }

/* ---------- Ringkasan umur piutang ---------------------------------------- */

.aging { display: grid; gap: 8px; }
.aging-row { display: flex; align-items: center; gap: 10px; }
.aging-row .nm { font-size: 12.5px; width: 132px; flex-shrink: 0; color: var(--muted); }
.aging-row .bar-wrap { flex: 1; height: 8px; background: #eef1f3; border-radius: 6px; overflow: hidden; }
.aging-row .bar { height: 100%; border-radius: 6px; background: var(--navy); }
.aging-row .bar.b1 { background: #8fb8cc; }
.aging-row .bar.b2 { background: var(--warn); }
.aging-row .bar.b3 { background: #e07b39; }
.aging-row .bar.b4 { background: var(--danger); }
.aging-row .val { font-size: 12px; font-weight: 700; width: 82px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Item form penjualan/pembelian --------------------------------- */

.item-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 9px; }
.item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.item-top .no { font-size: 12px; font-weight: 700; color: var(--navy); }
.item-top .hapus { background: none; border: 0; color: var(--danger); font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 2px 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.grid2 .field, .grid3 .field { margin-bottom: 0; }
.item-sub { font-size: 12px; color: var(--muted); margin-top: 8px; display: flex; justify-content: space-between; }
.item-sub b { color: var(--navy); font-size: 13px; }

.diskon-info:empty { display: none; }
.diskon-info { margin-top: 7px; font-size: 11.5px; }
.diskon-aktif { display: block; background: var(--green-soft); color: var(--green-dark); border-radius: 8px; padding: 6px 9px; font-weight: 600; }
.diskon-nanti { display: block; background: #f5f8fa; color: var(--muted); border-radius: 8px; padding: 6px 9px; }

/* Baris tingkat diskon di layar pengaturan */
.tier-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tier-row input { width: 100%; }
.tier-row .lbl { font-size: 12px; color: var(--muted); white-space: nowrap; }
.tier-row .buang { background: none; border: 0; color: var(--danger); font-size: 18px; cursor: pointer; padding: 0 4px; line-height: 1; }
.tier-chip { display: inline-block; background: var(--green-soft); color: var(--green-dark); border-radius: 20px; padding: 3px 9px; font-size: 11px; font-weight: 700; margin: 2px 4px 2px 0; }

.total-strip {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--navy); color: #fff; border-radius: 12px; padding: 13px 16px; margin: 14px 0;
}
.total-strip .lbl { font-size: 13px; color: #b9d3e2; }
.total-strip .val { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

.pesan { border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 11px; display: none; }
.pesan.tampil { display: block; }
.pesan.error { background: var(--danger-soft); color: var(--danger); }
.pesan.sukses { background: var(--green-soft); color: var(--green-dark); }

/* ---------- Tabel ringkas ------------------------------------------------- */

.tabel-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table.rapi { width: 100%; border-collapse: collapse; font-size: 13px; }
table.rapi th { background: #f6f9fa; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; text-align: left; padding: 9px 12px; font-weight: 700; white-space: nowrap; }
table.rapi td { padding: 9px 12px; border-top: 1px solid var(--line); white-space: nowrap; }
table.rapi td.r, table.rapi th.r { text-align: right; }
table.rapi td.nowrap-off { white-space: normal; min-width: 150px; }

/* ---------- Navigasi bawah ------------------------------------------------ */

.navbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  display: flex; padding: 6px 4px calc(6px + var(--safe-bottom));
  box-shadow: 0 -2px 14px rgba(31, 78, 104, .07);
}
.navbar button {
  flex: 1; background: none; border: 0; padding: 5px 2px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 600; color: var(--muted);
}
.navbar button svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.navbar button.aktif { color: var(--navy); }
.navbar button.aktif svg { stroke: var(--navy); }
.navbar .titik { position: absolute; top: 2px; right: 50%; margin-right: -16px; width: 7px; height: 7px; background: var(--danger); border-radius: 50%; }
.navbar button { position: relative; }

.fab {
  position: fixed; right: 16px; bottom: calc(84px + var(--safe-bottom)); z-index: 25;
  background: var(--green); color: #fff; border: 0; border-radius: 30px;
  padding: 13px 20px; font-size: 14.5px; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 18px rgba(46, 158, 60, .38);
  display: flex; align-items: center; gap: 7px;
}

/* ---------- Panel geser (detail & form) ----------------------------------- */

.overlay { position: fixed; inset: 0; background: rgba(16, 36, 48, .48); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .22s; }
.overlay.tampil { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--bg); border-radius: 18px 18px 0 0;
  max-height: 92dvh; display: flex; flex-direction: column;
  transform: translateY(102%); transition: transform .26s cubic-bezier(.3, .8, .4, 1);
}
.sheet.tampil { transform: translateY(0); }
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: #fff;
  border-radius: 18px 18px 0 0;
}
.sheet-head .jdl { flex: 1; font-weight: 700; font-size: 16px; color: var(--navy); }
.sheet-head .tutup { background: #f0f3f5; border: 0; width: 30px; height: 30px; border-radius: 50%; font-size: 19px; line-height: 1; color: var(--muted); cursor: pointer; }
.sheet-body { padding: 14px 16px calc(20px + var(--safe-bottom)); overflow-y: auto; -webkit-overflow-scrolling: touch; }

.detail-baris { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 13.5px; border-bottom: 1px dashed var(--line); }
.detail-baris:last-child { border-bottom: 0; }
.detail-baris .k { color: var(--muted); }
.detail-baris .v { font-weight: 600; text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%) translateY(14px);
  background: #16323f; color: #fff; padding: 11px 18px; border-radius: 24px; font-size: 13.5px;
  z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 88vw; text-align: center;
}
.toast.tampil { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

@media (min-width: 760px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .sheet { left: 50%; right: auto; width: 720px; transform: translate(-50%, 102%); border-radius: 18px 18px 0 0; }
  .sheet.tampil { transform: translate(-50%, 0); }
}
