:root {
  --bg: #EEF1F4;
  --card: #FFFFFF;
  --field: #DFE4EA;
  --text: #14181F;
  --muted: #6C7684;
  --line: #EEF1F4;
  --accent: #0E6E78;
  --accent-soft: #D8EBED;
  --on-accent: #FFFFFF;
  --green: #1B8A5A;
  --paid-bg: #CDEBDD;
  --paid-text: #0F4A30;
  --strong: #14181F;
  --on-strong: #FFFFFF;
  --danger: #C23B3B;
  --shade: rgba(10, 16, 22, .45);
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1418;
    --card: #1A2127;
    --field: #252E36;
    --text: #EEF1F4;
    --muted: #8E99A6;
    --line: #262F37;
    --accent: #2FA3AE;
    --accent-soft: #173A3F;
    --on-accent: #06181A;
    --green: #5CC896;
    --paid-bg: #1D4735;
    --paid-text: #CFF0DF;
    --strong: #EEF1F4;
    --on-strong: #14181F;
    --danger: #F07A7A;
    --shade: rgba(0, 0, 0, .6);
  }
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.35 -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior-y: none;
}

[hidden] { display: none !important; }

button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; touch-action: manipulation; }
input, textarea { -webkit-user-select: text; user-select: text; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.green { color: var(--green); }
.dim { color: var(--muted); }

.ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* ---------- customer list ---------- */

.list { min-height: 100%; padding: calc(var(--top) + 10px) 16px calc(var(--bottom) + 96px); max-width: 560px; margin: 0 auto; }

.topbar { display: flex; gap: 8px; align-items: center; position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 4px 0 10px; margin-top: -4px; }
.search { flex: 1; min-width: 0; height: 42px; border: 0; border-radius: 12px; background: var(--field); padding: 0 14px; font-size: 16px; }
.search::placeholder, .field input::placeholder, .field textarea::placeholder { color: var(--muted); }
.iconbtn { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: var(--accent); flex: 0 0 auto; position: relative; }
.iconbtn .dot { position: absolute; top: 7px; right: 7px; width: 9px; height: 9px; border-radius: 50%; background: #E0A020; }

.sum { background: #0E6E78; color: #fff; border-radius: 16px; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; }
.sum b { font-size: 22px; font-weight: 700; }

.sortbar { display: flex; justify-content: space-between; align-items: center; margin: 14px 4px 8px; font-size: 13px; color: var(--muted); }
.sortbar button { color: var(--accent); font-size: 13px; font-weight: 600; padding: 4px 0; }

.grp { background: var(--card); border-radius: 16px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--line); }
.av { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.row .n { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .n small { display: block; font-size: 12.5px; font-weight: 400; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; }
.row .num { font-size: 16px; font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 48px 24px; font-size: 15px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

.fab { position: fixed; right: max(18px, calc(50% - 262px)); bottom: calc(var(--bottom) + 22px); width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 18px rgba(14, 110, 120, .35); z-index: 3; }
.fab .ic { width: 28px; height: 28px; }

/* ---------- customer detail ---------- */

.detail { position: fixed; inset: 0; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; padding-top: var(--top); }
.hd { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 0; color: var(--accent); }
.hd button { display: flex; align-items: center; gap: 2px; height: 42px; padding: 0 8px; font-size: 16px; color: var(--accent); }
.hd .right { display: flex; }
.big { text-align: center; padding: 0 18px 10px; }
.big .nm { font-size: 17px; font-weight: 600; }
.big .v { font-size: 38px; font-weight: 800; letter-spacing: -1px; margin-top: 2px; line-height: 1.15; }
.big small { font-size: 13px; color: var(--muted); }
.contact { display: flex; justify-content: center; gap: 8px; padding: 0 18px 10px; }
.contact a { text-decoration: none; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 7px 16px; font-size: 14px; font-weight: 600; }
.cnote { text-align: center; font-size: 13px; color: var(--muted); padding: 0 24px 10px; white-space: pre-wrap; }

.chat { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 12px; }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
.bub { display: block; max-width: 78%; border-radius: 18px; padding: 10px 14px; font-size: 14.5px; line-height: 1.35; text-align: left; margin-bottom: 6px; overflow-wrap: anywhere; }
.bub b { display: block; font-size: 17px; margin-top: 2px; }
.bub small { display: block; font-size: 12px; opacity: .7; }
.bub.out { background: var(--card); border-bottom-left-radius: 5px; }
.bub.in { background: var(--paid-bg); color: var(--paid-text); margin-left: auto; border-bottom-right-radius: 5px; }

.two { display: flex; gap: 10px; padding: 10px 16px calc(var(--bottom) + 14px); }
.two button { flex: 1; padding: 16px 0; border-radius: 14px; font-size: 16px; font-weight: 600; }
.two .give { background: var(--strong); color: var(--on-strong); }
.two .take { background: var(--green); color: #fff; }
@media (prefers-color-scheme: dark) { .two .take { color: #062015; } }

/* ---------- bottom sheet ---------- */

#sheet { position: fixed; inset: 0; z-index: 10; background: var(--shade); display: flex; align-items: flex-end; justify-content: center; }
.panel { width: 100%; max-width: 560px; max-height: calc(100% - var(--top) - 20px); overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 8px 16px calc(var(--bottom) + 18px); animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }
.phead { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 12px; }
.phead h2 { font-size: 18px; font-weight: 700; }
.phead button { color: var(--accent); font-size: 16px; padding: 8px 4px; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin: 0 4px 5px; }
.field input, .field textarea { width: 100%; border: 0; border-radius: 12px; background: var(--card); padding: 13px 14px; font-size: 17px; -webkit-appearance: none; appearance: none; min-height: 48px; }
.field textarea { resize: none; min-height: 76px; }
.field input.amount { font-size: 24px; font-weight: 700; }
.split { display: flex; gap: 10px; }
.split .field { flex: 1; min-width: 0; }

.primary { width: 100%; padding: 16px 0; border-radius: 14px; background: var(--accent); color: var(--on-accent); font-size: 17px; font-weight: 600; margin-top: 4px; }
.primary:disabled { opacity: .55; }
.danger { width: 100%; padding: 14px 0; color: var(--danger); font-size: 16px; margin-top: 6px; }
.err { color: var(--danger); font-size: 14px; margin: 0 4px 10px; min-height: 1.2em; }

.menu { background: var(--card); border-radius: 16px; overflow: hidden; margin-bottom: 14px; }
.menu > * { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 15px 16px; font-size: 16px; text-align: left; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; }
.menu > *:last-child { border-bottom: 0; }
.menu .red { color: var(--danger); }
.switch { width: 50px; height: 30px; border-radius: 15px; background: var(--field); position: relative; flex: 0 0 auto; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(20px); }
.hint { font-size: 13px; color: var(--muted); margin: -6px 6px 14px; }

/* ---------- login and lock ---------- */

#gate { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 28px calc(var(--bottom) + 24px); }
#gate img { width: 92px; height: 92px; border-radius: 22px; }
#gate h1 { font-size: 28px; font-weight: 800; letter-spacing: -.5px; margin: 14px 0 22px; }
#gate form, #gate .box { width: 100%; max-width: 340px; }
#gate .link { display: block; margin: 14px auto 0; color: var(--accent); font-size: 15px; padding: 8px; }

/* ---------- toast ---------- */

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--bottom) + 92px); z-index: 30; max-width: 528px; margin: 0 auto; background: var(--strong); color: var(--on-strong); border-radius: 14px; padding: 13px 16px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; gap: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }
#toast button { color: inherit; font-weight: 700; text-decoration: underline; padding: 2px 4px; flex: 0 0 auto; }
