:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --field: #f2f3f6;
  --text: #111418;
  --muted: #6b7280;
  --line: rgba(0, 0, 0, .08);
  --up: #15803d;
  --down: #dc2626;
  --accent: #2563eb;
  --c-crypto: #f97316;
  --c-stock: #3b82f6;
  --c-gold: #d4a514;
  --c-manual: #a855f7;
  --radius: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d10;
    --card: #16191e;
    --field: #1f232a;
    --text: #f3f4f6;
    --muted: #8b93a1;
    --line: rgba(255, 255, 255, .08);
    --up: #22c55e;
    --down: #f05252;
    --accent: #5b8cff;
    --c-gold: #eab308;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button { font: inherit; color: inherit; }

.num, .total, .r-value, .r-pl, .r-sub, .group-total { font-variant-numeric: tabular-nums; }

/* Header */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
}
.top h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--card);
  cursor: pointer;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 99px;
  background: var(--card);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live[data-state="on"] { color: var(--up); }
.live[data-state="on"] i { background: var(--up); animation: pulse 2s infinite; }
.live[data-state="wait"] i { background: #f59e0b; }
.live[data-state="off"] { color: var(--down); }
.live[data-state="off"] i { background: var(--down); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 60%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* Layout */
main {
  max-width: 560px;
  margin: 0 auto;
  padding: 4px 16px calc(110px + env(safe-area-inset-bottom));
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.label { font-size: 13px; color: var(--muted); }
.small { font-size: 13px; }
.up { color: var(--up); }
.down { color: var(--down); }

/* Summary */
.summary { padding: 18px 16px 16px; }
.total {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.15;
  margin: 2px 0 2px;
  overflow-wrap: anywhere;
  border-radius: 8px;
}
.note { font-size: 13px; color: #d97706; margin-top: 2px; }
.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.stats .num { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.stats .num.small { font-weight: 500; font-size: 13px; }

.alloc {
  display: flex;
  height: 8px;
  margin-top: 16px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--field);
  gap: 2px;
}
.alloc span { display: block; height: 100%; transition: width .4s ease; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* Chart */
.chart-card { padding: 14px 16px 12px; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.chart { color: var(--accent); }
.chart.up { color: var(--up); }
.chart.down { color: var(--down); }
.chart svg { display: block; width: 100%; height: 150px; }
.chart-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.chart-empty { display: grid; place-items: center; height: 110px; text-align: center; font-size: 14px; color: var(--muted); padding: 0 12px; }

/* Segmented control */
.seg {
  display: flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--field);
  gap: 2px;
}
.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.seg.small button { padding: 5px 8px; font-size: 12px; }

/* Holdings */
.group { margin-bottom: 16px; }
.group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.group-head > span:first-child { display: inline-flex; align-items: center; gap: 8px; }
.group-total { text-transform: none; letter-spacing: 0; }
.rows { overflow: hidden; }

.row {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--field); }
.r-main, .r-side { min-width: 0; }
.r-side { text-align: right; flex: none; max-width: 58%; }
.r-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-value { font-weight: 600; font-size: 16px; border-radius: 6px; padding: 0 4px; margin: 0 -4px; }
.r-pl { font-size: 13px; }
.r-day { font-size: 12px; }

.flash-up { animation: flashUp .9s ease-out; }
.flash-down { animation: flashDown .9s ease-out; }
@keyframes flashUp { from { background: color-mix(in srgb, var(--up) 35%, transparent); } to { background: transparent; } }
@keyframes flashDown { from { background: color-mix(in srgb, var(--down) 35%, transparent); } to { background: transparent; } }

/* Dividen */
.muted { color: var(--muted); }
.div-card { padding: 14px 16px 10px; }
.div-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.div-head h2 { margin: 0; font-size: 18px; }
.div-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.div-stats .num { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.sub-head { margin: 16px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.sub-head .muted { font-weight: 400; font-size: 12px; }
.estimates { font-size: 14px; }
.est-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); }
.est-row:last-child { border-bottom: 0; }
.est-row .muted { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.est-name { font-weight: 600; }
.est-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.rows.inset { margin: 0 -16px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.r-sub.due { color: #d97706; }
.pair2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.hint.calc { margin: -6px 0 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--field); border-radius: 99px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.chip:active { border-color: var(--accent); }
input[type="date"] { min-width: 0; }

.empty { text-align: center; color: var(--muted); padding: 24px 24px 0; }
.empty-icon { font-size: 40px; }
.empty p { margin: 6px 0; }
.empty b { color: var(--text); }

/* FAB */
.fab {
  position: fixed;
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 6;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  cursor: pointer;
}
.fab:active { transform: scale(.95); }

/* Sheets */
dialog.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--card);
  color: var(--text);
  overflow: hidden;
}
dialog.sheet[open] { animation: sheetUp .25s ease-out; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet-body {
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 20px; }

.link { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 16px; cursor: pointer; padding: 6px 0; }

.field { display: block; margin-bottom: 14px; }
.field[hidden] { display: none; }
.flabel { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.hint { display: block; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.about { margin-top: 18px; line-height: 1.5; }

input, select {
  width: 100%;
  min-height: 46px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 17px; /* >=16px agar iOS tidak auto-zoom */
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
input:focus, select:focus { border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; margin-bottom: 14px; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; padding: 0; accent-color: var(--accent); -webkit-appearance: checkbox; appearance: auto; }

.pair { display: grid; grid-template-columns: minmax(0, 1fr) 112px; gap: 8px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.btn {
  flex: 1 1 auto;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--field);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--down); }
.btn:disabled { opacity: .6; }

.trade { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; }
.trade .seg { margin-bottom: 10px; }

.form-error { color: var(--down); font-size: 14px; margin: 0 0 12px; }
.form-error:empty { display: none; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(20, 22, 26, .92);
  color: #fff;
  font-size: 14px;
  text-align: center;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Kunci PIN */
html.locked .top, html.locked main, html.locked .fab { visibility: hidden; }
html.locked body, body:has(.lock.show) { overflow: hidden; }
.lock {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  background: var(--bg);
}
html.locked .lock, .lock.show { display: flex; }
.lock-inner { width: 100%; max-width: 320px; text-align: center; }
.lock-logo { border-radius: 16px; margin-bottom: 14px; }
.lock h2 { margin: 0; font-size: 20px; }
.lock-msg { min-height: 20px; margin: 6px 0 18px; font-size: 14px; color: var(--muted); }
.lock-msg.err { color: var(--down); }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 34px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--muted); transition: background .1s; }
.pin-dots i.on { background: var(--text); border-color: var(--text); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 26px; justify-content: center; }
.keypad button {
  width: 76px;
  height: 76px;
  border: 0;
  border-radius: 50%;
  background: var(--card);
  font-size: 30px;
  font-weight: 400;
  cursor: pointer;
  touch-action: manipulation;
}
.keypad button:active { background: var(--field); }
.keypad .kp-text { background: transparent; font-size: 15px; font-weight: 600; color: var(--accent); }
.keypad [data-k="del"] { font-size: 24px; color: var(--text); }
.keypad:has(button:disabled) { opacity: .5; }
