:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #111113;
  --muted: #62626a;
  --line: #d9d9de;
  --in: #1d6b35;
  --out: #a52a22;
  --warn: #7a4a00;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f4f4f6;
    --muted: #a1a1aa;
    --line: #36363a;
    --in: #66d184;
    --out: #ff8a80;
    --warn: #ffc766;
  }
}

* { box-sizing: border-box; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 440px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

h1 { font-size: clamp(24px, 8vw, 30px); line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
h2 { font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

button, input, select { font: inherit; color: inherit; }

button {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}

button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #3b82f6; outline-offset: 2px; }
button.primary { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 600; }
button.danger { color: var(--out); }
button.link { background: none; border: 0; padding: 8px 0; font-weight: 600; }
button.wide { width: 100%; }
button.add { flex: none; font-size: 14px; font-weight: 600; }

[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Tombol utama menempel di bawah; main diberi ruang supaya isi terakhir tidak tertutup. */
main:has(.dock) { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px max(16px, calc((100% - 408px) / 2)) calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.dock button { min-height: 52px; border-radius: 16px; }

.segments { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 14px; }
.segments label { flex: 1; position: relative; }
.segments input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.segments span { display: grid; place-items: center; height: 100%; min-height: 44px; padding: 4px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--text); text-align: center; }
.segments input:checked + span { background: var(--text); color: var(--bg); }
.segments input:focus-visible + span { outline: 3px solid #3b82f6; outline-offset: 2px; }

.chips { border: 0; padding: 0; min-width: 0; }
.chips legend { padding: 0; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.chips > div { display: flex; flex-wrap: wrap; gap: 10px; padding: 3px; }
.chips label { position: relative; max-width: 100%; }
.chips input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.chips span { display: block; min-height: 44px; padding: 10px 16px; border: 1px solid rgb(128 128 128 / 0.5); border-radius: 12px; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips input:checked + span { outline: 3px solid var(--text); outline-offset: 2px; }
.chips input:focus-visible + span { outline: 3px solid #3b82f6; outline-offset: 2px; }

.reminder { display: flex; align-items: center; gap: 4px 16px; padding: 0 12px; border: 1px solid var(--warn); border-radius: 12px; background: var(--surface); }
.reminder p { flex: 1; min-width: 0; padding: 6px 0; }
.reminder button { flex: none; font-size: 14px; }
.reminder button.quiet { font-weight: 400; color: var(--muted); }

.month { display: flex; flex-wrap: wrap; column-gap: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* Cincin fokus digambar di bagian kartu yang tidak tertutup kartu berikutnya. */
.stack .card:focus-visible { outline: none; }
.stack .card:focus-visible::after { content: ""; position: absolute; top: 6px; left: 6px; right: 6px; height: 52px; border: 3px solid currentcolor; border-radius: 12px; pointer-events: none; }

.order { display: flex; flex-direction: column; gap: 8px; padding: 0; list-style: none; }
.order li { display: flex; align-items: center; gap: 8px; }
.order-name { flex: 1; min-width: 0; padding: 10px 14px; border-radius: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order button { flex: none; font-size: 14px; }

.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.actions button { padding-inline: 4px; font-size: 15px; font-weight: 600; }

.card {
  display: block;
  width: 100%;
  height: 188px;
  flex: none;
  padding: 18px;
  border: 1px solid rgb(255 255 255 / 0.25);
  border-radius: 18px;
  box-shadow: 0 -3px 14px rgb(0 0 0 / 0.22);
  text-align: left;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 18px;
  font-weight: 600;
}

.card-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.card-balance { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Tumpukan: tiap kartu menutupi kartu sebelumnya, menyisakan baris nama dan saldo. */
.stack { display: flex; flex-direction: column; }
.stack .card { position: relative; align-self: stretch; display: flex; flex-direction: column; transition: transform 0.18s ease; }
.stack .card + .card { margin-top: -122px; }

@media (hover: hover) { .stack .card:hover { transform: translateY(-8px); } }
.stack .card:active { transform: translateY(-8px); }
@media (prefers-reduced-motion: reduce) { .stack .card { transition: none; } }

.empty {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 28px 20px;
  background: var(--surface);
  border-radius: 18px;
}

.center { text-align: center; }
.greeting { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-title { font-size: 20px; }
.login-title { margin-top: 8dvh; text-align: center; }

.panel { display: flex; flex-direction: column; gap: 12px; padding: 16px; background: var(--surface); border-radius: 18px; }
.panel p { overflow-wrap: anywhere; }
.panel input { background: var(--bg); }

button:disabled { cursor: default; opacity: 0.45; }
button[type="submit"]:disabled { cursor: progress; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.summary > div { background: var(--surface); border-radius: 12px; padding: 10px 12px; min-width: 0; overflow-wrap: anywhere; }

.history { list-style: none; padding: 0; background: var(--surface); border-radius: 14px; overflow: hidden; margin-top: -8px; }
.history li + li { border-top: 1px solid var(--line); }
.tx { display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 12px; border: 0; border-radius: 0; text-align: left; padding: 12px; }
.tx-main { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.tx .amount { white-space: nowrap; }
.in { color: var(--in); }
.out { color: var(--out); }

dialog {
  width: min(440px, 100%);
  max-width: 100%;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--bg);
  color: var(--text);
  overflow-y: auto;
}

dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog > * + * { margin-top: 14px; }
form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 4px; }
label > span, .label { font-size: 13px; color: var(--muted); }

form.panel button.primary { min-height: 48px; }

input:not([type="range"], [type="radio"]), select {
  width: 100%;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

/* Pratinjau tetap terlihat saat memilih warna di bawahnya. */
.preview { position: sticky; top: -20px; z-index: 1; margin: -20px 0 -8px; padding: 20px 0 8px; background: var(--bg); }
.preview .card { height: 84px; overflow: hidden; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; align-items: center; }
.swatch { width: 38px; min-height: 38px; height: 38px; padding: 0; border-radius: 50%; }
.swatch[aria-pressed="true"] { outline: 3px solid var(--text); outline-offset: 2px; }
.picker { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }

.sv {
  position: relative;
  height: 160px;
  margin: 0 2px;
  border-radius: 12px;
  background-image: linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent);
  touch-action: none;
  cursor: crosshair;
}

.sv:focus-visible { outline: 3px solid #3b82f6; outline-offset: 2px; }

.knob {
  position: absolute;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000;
  pointer-events: none;
}

input.hue {
  -webkit-appearance: none;
  appearance: none;
  min-height: 28px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}

input.hue::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; border: 3px solid #fff; border-radius: 50%; background: transparent; box-shadow: 0 0 0 1px #000; }
input.hue::-moz-range-thumb { width: 22px; height: 22px; border: 3px solid #fff; border-radius: 50%; background: transparent; box-shadow: 0 0 0 1px #000; }

.error { color: var(--out); font-size: 14px; }
.warning { color: var(--warn); font-size: 14px; font-weight: 600; }
.error:empty, .warning:empty { display: none; }

#sheet { padding-bottom: 0; scroll-padding-bottom: 130px; }
#sheet:has(.preview) { scroll-padding-top: 120px; }
#sheet form { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.form-actions { position: sticky; bottom: 0; z-index: 2; display: flex; flex-direction: column; gap: 8px; padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); background: var(--bg); }
.more { margin-top: 12px; }

#toast {
  position: fixed;
  left: 16px;
  right: 16px;
  top: calc(16px + env(safe-area-inset-top));
  max-width: 408px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#toast.show { opacity: 1; }
