/* White cards on soft gray, blue accent, large radius + diffuse shadow */
:root {
  --accent: #0A84FF;
  --accent-2: #0066FF;
  --accent-soft: #E8F2FF;
  --bg: #EEF1F5;
  --card: #FFFFFF;
  --field: #F4F6F9;
  --text: #111317;
  --muted: #8B919C;
  --line: #E6E9EE;
  --ink: #111317;
  --ok: #0A84FF;
  --danger: #FF453A;
  --r-lg: 24px;
  --r-md: 16px;
  --r-sm: 12px;
  --shadow: 0 12px 32px rgba(17, 30, 60, .07), 0 2px 6px rgba(17, 30, 60, .04);
  --shadow-blue: 0 14px 30px rgba(10, 112, 255, .32);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(110px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
/* 16px+ prevents iOS zoom on focus */
input, select, textarea { font-size: 17px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 12px;
  background: rgba(238, 241, 245, .85);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}
.top-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 30px; font-weight: 800; letter-spacing: -.5px; margin: 4px 0 12px; }
.icon-btn {
  width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 20px; color: var(--text); padding: 0;
}

/* hero summary card */
.summary {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px;
  padding: 18px 20px; border-radius: var(--r-lg);
  background: linear-gradient(135deg, #22A6FF 0%, var(--accent-2) 100%);
  color: #fff; box-shadow: var(--shadow-blue);
}
.summary div { display: flex; flex-direction: column; min-width: 0; }
.summary div:first-child { grid-column: 1 / -1; }
.summary .label { font-size: 13px; opacity: .8; }
.summary .val { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.summary div:first-child .val { font-size: 38px; font-weight: 800; letter-spacing: -1px; line-height: 1.15; }

/* segmented pills, black active like "1D" */
.tabs {
  position: relative; display: flex; margin-top: 14px; padding: 4px;
  background: var(--card); border-radius: 999px; box-shadow: var(--shadow);
}
.tab-ind {
  position: absolute; top: 4px; bottom: 4px; left: 0; border-radius: 999px;
  background: var(--ink); box-shadow: 0 4px 12px rgba(17, 19, 23, .25);
  transition: transform .38s cubic-bezier(.32,.72,0,1), width .38s cubic-bezier(.32,.72,0,1);
}
.tabs button {
  position: relative; flex: 1; border: 0; padding: 9px 0; border-radius: 999px;
  background: transparent; color: var(--muted); font-size: 15px; font-weight: 600;
  transition: color .25s ease, transform .12s ease;
}
.tabs button.active { color: #fff; }
.rate-line { font-size: 12px; color: var(--muted); margin-top: 10px; text-align: center; }
.sync-text:not(:empty)::before { content: "・"; }
.sync-text { transition: color .2s ease; }
.sync-text.busy { color: var(--accent); }
.sync-text.err { color: var(--danger); }

/* ---------- list ---------- */
.list { padding: 4px 16px 12px; display: flex; flex-direction: column; gap: 12px; }
.item {
  display: flex; gap: 14px; align-items: center;
  background: var(--card); border-radius: var(--r-lg); padding: 12px 14px 12px 12px;
  box-shadow: var(--shadow);
}
.item.done .name { text-decoration: line-through; color: var(--muted); }
.thumb {
  width: 64px; height: 64px; border-radius: var(--r-md); flex: none;
  object-fit: cover; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; font-size: 26px;
}
.item-main { flex: 1; min-width: 0; }
.name { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.amounts { font-size: 13px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.amounts .twd { color: var(--muted); }
.amounts .paid { color: var(--accent); font-weight: 700; }
.item.done .thumb { opacity: .55; }

/* swipe-to-delete row: red button sits behind the card */
.row { position: relative; border-radius: var(--r-lg); }
.row .item {
  position: relative; z-index: 1;
  touch-action: pan-y; -webkit-user-select: none; user-select: none;
}
.row-del {
  position: absolute; inset: 0; border: 0; border-radius: var(--r-lg);
  background: var(--danger); color: #fff; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: flex-end; padding: 0 26px 0 0;
  opacity: 0;
}
.row.reveal .row-del { opacity: 1; }

.empty { text-align: center; color: var(--muted); margin-top: 56px; }

.fab {
  position: fixed; right: 20px; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 20;
  width: 62px; height: 62px; border-radius: 22px; border: 0;
  background: linear-gradient(135deg, #22A6FF, var(--accent-2));
  color: #fff; font-size: 32px; line-height: 1;
  box-shadow: var(--shadow-blue);
}

/* ---------- sheets ---------- */
dialog.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; margin: auto auto 0;
  padding: 0; border: 0; border-radius: 28px 28px 0 0;
  background: var(--bg); color: var(--text);
  box-shadow: 0 -10px 40px rgba(17, 30, 60, .12);
}
dialog::backdrop { background: rgba(17, 19, 23, .35); }
.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 18px 20px 12px; background: var(--bg);
}
.sheet-head strong { font-size: 17px; font-weight: 700; }
.sheet-head > :first-child { justify-self: start; }
.sheet-head > :last-child { justify-self: end; }
.sheet-body { padding: 8px 16px calc(28px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.link { border: 0; background: transparent; color: var(--accent); font-size: 17px; padding: 0; }
.link.strong { font-weight: 700; }

.photo-box {
  width: 100%; border: 0; padding: 0;
  background: var(--card); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow);
  aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center;
}
.photo-box img { width: 100%; height: 100%; object-fit: contain; }
.photo-empty { color: var(--accent); font-size: 15px; font-weight: 600; line-height: 1.8; }
.photo-icon {
  display: inline-flex; width: 64px; height: 64px; border-radius: 20px;
  align-items: center; justify-content: center; font-size: 30px; background: var(--accent-soft);
}

/* action sheet */
dialog.action-sheet {
  width: 100%; max-width: 560px; margin: auto auto 0; border: 0; background: transparent;
  padding: 0 10px calc(10px + env(safe-area-inset-bottom));
}
.action-group {
  display: flex; flex-direction: column; border-radius: 22px; overflow: hidden;
  background: var(--card); margin-top: 8px; box-shadow: var(--shadow);
}
.action-group button {
  border: 0; background: transparent; padding: 18px; font-size: 18px; color: var(--accent);
}
.action-group button + button { border-top: 1px solid var(--line); }
.action-group .strong { font-weight: 700; color: var(--text); }
.action-group .danger-text { color: var(--danger); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: var(--r-md); padding: 15px 14px;
  background: var(--card); color: var(--accent); font-size: 16px; font-weight: 600;
  box-shadow: var(--shadow);
}
.btn.wide { width: 100%; }
.btn.danger { background: var(--danger); color: #fff; margin-top: 8px; box-shadow: none; }
.btn.primary {
  background: linear-gradient(135deg, #22A6FF, var(--accent-2)); color: #fff;
  margin-top: 4px; box-shadow: var(--shadow-blue);
}
.danger-text { color: var(--danger); }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 38px; height: 38px; flex: none; border: 0; border-radius: var(--r-sm);
  background: var(--accent-soft); color: var(--accent); font-size: 20px; font-weight: 600; padding: 0;
}
.field .stepper input { text-align: center; font-weight: 700; font-size: 20px; }

.buy-info {
  display: flex; gap: 14px; align-items: center;
  background: var(--card); border-radius: var(--r-lg); padding: 12px; box-shadow: var(--shadow);
}
.buy-info .thumb { width: 72px; height: 72px; }

.field {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--card); border-radius: var(--r-md); padding: 12px 16px;
  box-shadow: 0 1px 3px rgba(17, 30, 60, .04);
}
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .field textarea, .field select {
  border: 0; outline: 0; background: transparent; padding: 2px 0; width: 100%; resize: none;
}
.conv { color: var(--muted); font-size: 13px; min-height: 1em; }
.check {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: var(--r-md); padding: 14px 16px;
}
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

h2 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 14px 4px 0; }
.muted { color: var(--muted); margin: 0 4px; }
.small { font-size: 12px; }
select.full {
  width: 100%; border: 0; border-radius: var(--r-md); padding: 14px 16px; background: var(--card);
  box-shadow: 0 1px 3px rgba(17, 30, 60, .04);
}
.rate-row {
  display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center;
  background: var(--card); border-radius: var(--r-md); padding: 14px 16px; margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(17, 30, 60, .04);
}
.rate-row .code { font-weight: 700; }
.rate-row .auto { font-size: 13px; color: var(--muted); text-align: right; }
.rate-row input {
  grid-column: 1 / -1; border: 0; border-radius: var(--r-sm);
  padding: 10px 12px; background: var(--field); width: 100%; outline: 0;
}

dialog.viewer {
  width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: rgba(0, 0, 0, .92);
}
dialog.viewer[open] { display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

.toast {
  position: fixed; left: 50%; bottom: calc(104px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 16px) scale(.96); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 10px 28px rgba(17, 19, 23, .25); max-width: calc(100% - 32px);
  transition: opacity .22s ease, transform .35s cubic-bezier(.32,.72,0,1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
[hidden] { display: none !important; }

/* ================= motion ================= */
:root {
  --ease-out: cubic-bezier(.32,.72,0,1); /* iOS sheet curve */
  --ease-in: cubic-bezier(.4,0,1,1);
}

/* press feedback — :active is the only feedback on touch */
.item, .btn, .fab, .icon-btn, .photo-box, .stepper button, .link, .action-group button, .thumb {
  transition: transform .15s ease, background-color .15s ease, box-shadow .2s ease, opacity .15s ease;
}
.item:active { transform: scale(.98); }
.btn:active, .photo-box:active { transform: scale(.97); }
.fab:active { transform: scale(.9); box-shadow: 0 6px 16px rgba(10, 112, 255, .3); }
.icon-btn:active { transform: scale(.9) rotate(30deg); }
.tabs button:active { transform: scale(.95); }
.stepper button:active { transform: scale(.88); background: #D6E8FF; }
.link:active { opacity: .5; }
.action-group button:active { background: var(--field); }
.row-del:active { filter: brightness(.9); }
/* stepper value pops when it changes */
.field .stepper input { transition: transform .15s ease; }

/* list rows */
@keyframes row-in {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.row.enter {
  animation: row-in .45s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}
.row.leaving {
  height: 0 !important; margin-bottom: -12px; opacity: 0; overflow: hidden;
  transition: height .28s var(--ease-out) .08s, margin .28s var(--ease-out) .08s, opacity .25s ease;
}
.row.leaving .item {
  transform: translateX(var(--out)) !important;
  transition: transform .3s var(--ease-in) !important;
}
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.empty { animation: fade-up .4s var(--ease-out) both; }

/* bottom sheets */
@keyframes sheet-in  { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-out { from { transform: none; } to { transform: translateY(100%); } }
@keyframes fade-in   { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out  { from { opacity: 1; } to { opacity: 0; } }
dialog.sheet[open], dialog.action-sheet[open] { animation: sheet-in .45s var(--ease-out); }
dialog.sheet[open]::backdrop, dialog.action-sheet[open]::backdrop { animation: fade-in .3s ease; }
dialog[data-closing] { animation: sheet-out .22s var(--ease-in) forwards !important; }
dialog[data-closing]::backdrop { animation: fade-out .22s ease forwards !important; }

/* photo viewer: fade + zoom */
@keyframes zoom-in { from { opacity: 0; transform: scale(.88); } to { opacity: 1; transform: none; } }
dialog.viewer[open] { animation: fade-in .25s ease; }
dialog.viewer[open] img { animation: zoom-in .35s var(--ease-out); }
dialog.viewer[data-closing] { animation: fade-out .2s ease forwards !important; }

/* summary card + header entrance */
.summary { animation: row-in .5s var(--ease-out) both; }

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

#sync-on, #sync-off { display: flex; flex-direction: column; gap: 10px; }
