:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --muted: #667085;
  --faint: #98a2b3;
  --primary: #059669;
  --primary-hover: #047857;
  --primary-soft: #e7f7f0;
  --primary-ink: #065f46;
  --on-primary: #ffffff;
  --danger: #d92d20;
  --danger-soft: #fef0ee;
  --warn: #b54708;
  --warn-soft: #fff4e5;
  --ring: rgba(5, 150, 105, .22);
  --scrim: rgba(16, 24, 40, .5);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14;
    --surface: #131a22;
    --surface-2: #1b242e;
    --border: #232e3a;
    --border-strong: #324050;
    --text: #e8edf3;
    --muted: #96a3b3;
    --faint: #667689;
    --primary: #10b981;
    --primary-hover: #34d399;
    --primary-soft: rgba(16, 185, 129, .13);
    --primary-ink: #6ee7b7;
    --on-primary: #04241a;
    --danger: #f97066;
    --danger-soft: rgba(249, 112, 102, .13);
    --warn: #fdb022;
    --warn-soft: rgba(253, 176, 34, .12);
    --ring: rgba(16, 185, 129, .3);
    --scrim: rgba(0, 0, 0, .62);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
h1, h2, p { margin: 0; }

.grow { flex: 1; min-width: 0; }

.i {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}


/* ---------- Layout ---------- */

.wrap {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 28px;
}

.page {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
}

.page.active { display: flex; }

.page-form {
  display: flex;
  flex-direction: column;
}

.stack > * + * { margin-top: 10px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: var(--safe-top);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

@supports (background: color-mix(in srgb, red 50%, blue)) {
  .topbar {
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    -webkit-backdrop-filter: saturate(1.5) blur(14px);
    backdrop-filter: saturate(1.5) blur(14px);
  }
}

.topbar-in {
  max-width: 560px;
  margin: 0 auto;
  min-height: 60px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar h1 {
  font-size: 17px;
  font-weight: 650;
  line-height: 1.25;
}

.topbar .sub {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 42px;
  height: 42px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: transparent;
  display: grid;
  place-items: center;
  color: var(--text);
  transition: background .15s;
}

.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { background: var(--border); }

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  background: var(--primary);
  color: var(--on-primary);
  display: grid;
  place-items: center;
  margin-left: 4px;
}

.brand-mark.lg {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  margin: 0 auto 18px;
}

.brand-mark.lg .i { width: 30px; height: 30px; }


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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.list, .menu { overflow: hidden; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  text-align: left;
  transition: background .12s;
}

.row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); }
.row:active { background: var(--border); }

.row-main { flex: 1; min-width: 0; }

.row-title {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  min-width: 0;
}

.row-sub > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sub .sep {
  flex: none;
  width: 1px;
  height: 11px;
  background: var(--border-strong);
}

.row-side { flex: none; text-align: right; }

.stock {
  display: block;
  font-weight: 700;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.stock-unit { display: block; font-size: 11.5px; color: var(--faint); }

.row.zero .stock { color: var(--danger); }

.list-note {
  margin-top: 12px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.empty .em-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--faint);
  display: grid;
  place-items: center;
}

.empty b { display: block; color: var(--text); font-weight: 600; margin-bottom: 2px; }
.empty .btn { margin-top: 14px; }


/* ---------- Beranda ---------- */

.search { position: relative; }

.search > .i {
  position: absolute;
  left: 14px;
  top: 14px;
  color: var(--faint);
  pointer-events: none;
}

.search .input { padding-left: 42px; padding-right: 46px; }

.results { margin-top: 8px; max-height: 56vh; overflow-y: auto; border-radius: 16px; }
.results .card { overflow: hidden; }

.results-empty { padding: 18px 16px; text-align: center; color: var(--muted); }
.results-empty .btn { margin-top: 12px; }

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  transition: background .12s, border-color .12s;
}

.tile:hover { border-color: var(--border-strong); }
.tile:active { background: var(--surface-2); }

.tile-icon {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary-ink);
}

.tile-icon.amber { background: var(--warn-soft); color: var(--warn); }

.tile-title { font-weight: 650; margin-top: 2px; }
.tile-meta { font-size: 12.5px; color: var(--muted); margin-top: -8px; }

.badge {
  position: absolute;
  top: 12px;
  right: 12px;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 12.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.menu { margin-top: 16px; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  text-align: left;
  transition: background .12s;
}

.menu-item:first-child { border-top: 0; }
.menu-item:hover { background: var(--surface-2); }
.menu-item:active { background: var(--border); }

.mi-icon {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  display: grid;
  place-items: center;
}

.mi-text { flex: 1; min-width: 0; }
.mi-title { display: block; font-weight: 600; }
.mi-sub { display: block; font-size: 12.5px; color: var(--muted); }
.chev { color: var(--faint); width: 18px; height: 18px; }

.offline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 16px 8px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12.5px;
  text-align: center;
}

.offline .i { width: 16px; height: 16px; }


/* ---------- Pasang aplikasi ---------- */

.install-card {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--primary-soft);
}

.ic-icon {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  background: var(--surface);
  color: var(--primary-ink);
  display: grid;
  place-items: center;
}

.ic-body { flex: 1; min-width: 0; }
.ic-title { font-weight: 650; }
.ic-text { font-size: 13px; color: var(--muted); margin-top: 2px; }
.ic-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.login .install-card { margin-top: 20px; }


/* ---------- Form ---------- */

.field { margin-bottom: 16px; }

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13.5px;
  font-weight: 600;
}

.input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.input::placeholder { color: var(--faint); }

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--ring);
}

.input.invalid { border-color: var(--danger); }

input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

.affix { position: relative; }

.affix .pre, .affix .suf {
  position: absolute;
  top: 0;
  height: 48px;
  display: flex;
  align-items: center;
  color: var(--faint);
  pointer-events: none;
}

.affix .pre { left: 14px; }
.affix .suf { right: 14px; }
.affix .txt { font-size: 14px; font-weight: 600; color: var(--muted); }

.input.has-pre { padding-left: 42px; }
.input.has-suf { padding-right: 46px; }
.input.has-pre-txt { padding-left: 42px; }
.input.has-suf-txt { padding-right: 46px; }

.suf-btn {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
}

.suf-btn:hover { background: var(--surface-2); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

@media (max-width: 400px) {
  .grid-2 { grid-template-columns: 1fr; gap: 0; }
}

.item-info { padding: 14px 16px; margin-bottom: 18px; }
.ii-name { font-size: 17px; font-weight: 650; line-height: 1.3; }
.ii-sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

.ii-stock {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.ii-stock b { color: var(--text); font-variant-numeric: tabular-nums; }

.notice {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 18px;
  border-radius: 12px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.45;
}

.notice .i { width: 18px; height: 18px; margin-top: 1px; }

.form-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
}

.bottombar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + var(--safe-bottom));
}

.bottombar-in { max-width: 560px; margin: 0 auto; }


/* ---------- Tombol ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  transition: background .15s, transform .06s;
}

.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; pointer-events: none; }

.btn-block { width: 100%; }
.btn-sm { height: 38px; padding: 0 14px; font-size: 14px; border-radius: 10px; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-soft { background: var(--surface-2); color: var(--text); }
.btn-soft:hover { background: var(--border); }

.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }


/* ---------- Draft ---------- */

.draft-item { padding: 14px; }

.di-head { display: flex; align-items: flex-start; gap: 12px; }
.di-main { flex: 1; min-width: 0; }

.di-title { font-weight: 600; line-height: 1.3; word-break: break-word; }
.di-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; word-break: break-word; }

.qty {
  flex: none;
  text-align: right;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.qty small { display: block; font-size: 11.5px; font-weight: 500; color: var(--faint); margin-top: 2px; }

.di-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--muted);
}

.di-meta b { color: var(--text); font-variant-numeric: tabular-nums; }

.di-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 11.5px;
  font-weight: 600;
  vertical-align: 1px;
}


/* ---------- Overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--scrim);
  animation: fade .15s ease-out;
}

.overlay.center { align-items: center; padding: 20px; }

.sheet {
  width: 100%;
  max-width: 520px;
  padding: 8px 20px calc(20px + var(--safe-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  animation: rise .22s ease-out;
}

@media (min-width: 600px) {
  .overlay { align-items: center; padding: 20px; }
  .sheet { border-radius: 22px; padding-bottom: 20px; }
}

.grabber {
  width: 38px;
  height: 4px;
  margin: 4px auto 18px;
  border-radius: 99px;
  background: var(--border-strong);
}

.sheet-title { font-size: 19px; font-weight: 700; line-height: 1.3; word-break: break-word; }
.sheet-sub { color: var(--muted); margin-top: 2px; word-break: break-word; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.stat { padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.stat.wide { grid-column: span 2; }
.stat .k { font-size: 12.5px; color: var(--muted); }
.stat .v { margin-top: 2px; font-size: 18px; font-weight: 700; word-break: break-word; font-variant-numeric: tabular-nums; }

.dialog-actions { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; }

.dialog {
  width: 100%;
  max-width: 380px;
  padding: 20px;
  border-radius: 20px;
  background: var(--surface);
  animation: rise .2s ease-out;
}

.dialog h2 { font-size: 17px; font-weight: 700; }
.dialog p { margin: 6px 0 20px; color: var(--muted); }
.dialog .dialog-actions { grid-template-columns: 1fr 1fr; }

.loading { z-index: 100; background: rgba(16, 24, 40, .35); }

.loading-box {
  min-width: 180px;
  padding: 22px 26px;
  border-radius: 18px;
  background: var(--surface);
  text-align: center;
  font-weight: 600;
  font-size: 14px;
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 12px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.toast {
  position: fixed;
  z-index: 120;
  top: calc(12px + var(--safe-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.toast-box {
  max-width: 460px;
  padding: 11px 16px;
  border-radius: 12px;
  background: #182230;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .25);
  animation: drop .2s ease-out;
}

.toast-box.success { background: #067647; }
.toast-box.error { background: #b42318; }


/* ---------- Masuk ---------- */

.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}

.login-card { width: 100%; max-width: 400px; margin: 0 auto; }
.login-head { text-align: center; margin-bottom: 24px; }
.login-head h1 { font-size: 24px; font-weight: 700; }
.login-head p { color: var(--muted); margin-top: 4px; }
.login-form { padding: 20px; }
.login-form .btn { margin-top: 4px; }


/* ---------- Animasi ---------- */

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
