:root {
  --bg:       #0c0c13;
  --bg2:      #13131e;
  --bg3:      #1a1a28;
  --border:   #252538;
  --border2:  #32324a;
  --text:     #ede9e1;
  --muted:    #55536a;
  --accent:   #f0d060;
  --teal:     #4ecdc4;
  --blue:     #60a5fa;
  --red:      #ff6b6b;
  --purple:   #a78bfa;
  --radius:   14px;
  --modal-r:  20px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { overflow-x: hidden; max-width: 100%; }
body { height: 100%; overflow-x: hidden; max-width: 100vw; background: var(--bg); color: var(--text); font-family: 'Noto Sans TC', sans-serif; font-size: 15px; }
::-webkit-scrollbar { width: 4px; } ::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

#app { min-height: 100vh; overflow-x: hidden; }
.page { max-width: 520px; margin: 0 auto; padding: 0 16px 100px; }

.serif { font-family: 'DM Serif Display', serif; }
.mono  { font-family: 'JetBrains Mono', monospace; }

.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 10px; transition: border-color .2s; }
.card:hover { border-color: var(--border2); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; border-radius: 10px; cursor: pointer; font-family: inherit; font-weight: 600; font-size: 14px; transition: all .15s; padding: 11px 20px; }
.btn-yellow { background: var(--accent); color: #111; }
.btn-yellow:hover { background: #e8c840; transform: translateY(-1px); }
.btn-ghost  { background: var(--bg3); color: var(--muted); border: 1px solid var(--border2); }
.btn-ghost:hover  { color: var(--text); border-color: var(--blue); }
.btn-danger { background: #2a1515; color: var(--red); border: none; border-radius: 8px; padding: 5px 10px; font-size: 12px; cursor: pointer; font-family: inherit; transition: all .15s; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-mini { background: var(--bg3); color: var(--muted); border: 1px solid var(--border); border-radius: 7px; padding: 4px 9px; font-size: 11px; cursor: pointer; font-family: inherit; transition: all .15s; }
.btn-mini:hover { border-color: var(--border2); color: var(--text); }
.btn-teal { background: #0f2a20; color: var(--teal); border: none; border-radius: 8px; padding: 5px 10px; font-size: 12px; cursor: pointer; font-family: inherit; }
.btn-teal:hover { background: var(--teal); color: #000; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

.inp { width: 100%; background: var(--bg3); border: 1px solid var(--border2); border-radius: 10px; padding: 10px 14px; color: var(--text); font-family: inherit; font-size: 14px; outline: none; transition: border-color .2s; }
.inp:focus { border-color: var(--accent); }
.inp-code { font-family: 'JetBrains Mono', monospace; font-size: 22px; letter-spacing: 6px; text-align: center; text-transform: uppercase; padding: 14px; }
select.inp option { background: var(--bg2); }
label.lbl { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; letter-spacing: .3px; }
.field { margin-bottom: 14px; }

.tabs { display: flex; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 10px 18px; font-family: inherit; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; transition: all .2s; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.seg { display: flex; background: var(--bg3); border: 1px solid var(--border2); border-radius: 10px; overflow: hidden; }
.seg-btn { flex: 1; background: none; border: none; padding: 9px; font-family: inherit; font-size: 13px; color: var(--muted); cursor: pointer; transition: all .15s; }
.seg-btn.active { background: #252540; color: var(--accent); font-weight: 700; }

.toggle-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--bg3); border: 1px solid transparent; border-radius: 10px; cursor: pointer; user-select: none; margin-bottom: 6px; transition: background .15s, border-color .15s; }
.toggle-row:has(input[type=checkbox]:checked) { background: #1a2a1e; border-color: var(--teal); }
.toggle-row input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; flex-shrink: 0; }

.av { border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #000; flex-shrink: 0; }

dialog#modal-dialog { border: none; background: transparent; padding: 0; margin: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; display: flex; align-items: flex-end; justify-content: center; overflow: hidden; }
dialog#modal-dialog::backdrop { background: rgba(0,0,0,.88); }
@media (min-height: 600px) { dialog#modal-dialog { align-items: center; padding: 16px; } }
.modal { background: var(--bg2); border: 1px solid var(--border2); border-radius: var(--modal-r) var(--modal-r) 0 0; padding: 28px 24px 40px; width: 100%; max-width: 480px; max-height: 88dvh; max-height: 88vh; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
@media (min-height: 600px) { .modal { border-radius: var(--modal-r); max-height: 85dvh; max-height: 85vh; } }

.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--bg3); border-radius: 20px; padding: 3px 9px; font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.tag { display: inline-block; border-radius: 5px; padding: 2px 6px; font-size: 10px; font-weight: 700; }

.status-bar { display: flex; align-items: center; gap: 8px; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 8px 14px; font-size: 12px; flex-wrap: wrap; margin-bottom: 10px; }

.topbar { padding: 20px 16px 0; max-width: 520px; margin: 0 auto; }

.trip-code { font-family: 'JetBrains Mono', monospace; font-size: 28px; font-weight: 700; letter-spacing: 8px; color: var(--accent); }

.empty { text-align: center; padding: 60px 24px; color: var(--muted); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }

.sec-lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin-bottom: 10px; opacity: .7; }

.bal-bar { height: 5px; background: var(--bg3); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bal-fill { height: 100%; border-radius: 4px; transition: width .5s; }

.receipt-drop { border: 2px dashed var(--border2); border-radius: 12px; padding: 24px; text-align: center; cursor: pointer; transition: all .2s; background: var(--bg); }
.receipt-drop:hover { border-color: var(--accent); background: #16160e; }
.receipt-thumb { width: 100%; border-radius: 10px; object-fit: cover; max-height: 160px; cursor: zoom-in; display: block; }
.ocr-box { background: #0d1f14; border: 1px solid #1d3a24; border-radius: 10px; padding: 12px; margin-top: 10px; }
.ocr-box.err { background: #1f0d0d; border-color: #3a1d1d; }
.item-tag { display: inline-block; background: var(--bg3); border-radius: 5px; padding: 2px 7px; font-size: 11px; color: var(--muted); margin: 2px; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--border2); font-size: 12px; margin: 20px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid #4ecdc433; border-top-color: var(--teal); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.sync-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.home-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; }
.home-inner { width: 100%; max-width: 400px; }
.home-logo { text-align: center; margin-bottom: 36px; }

.mode-badge { display: inline-flex; align-items: center; gap: 5px; background: var(--bg3); border: 1px solid var(--border2); border-radius: 20px; padding: 4px 10px; font-size: 11px; color: var(--muted); margin-top: 8px; }

#receipt-viewer { position: fixed; inset: 0; background: rgba(0,0,0,.95); z-index: 999; display: none; align-items: center; justify-content: center; padding: 20px; }
#receipt-viewer.show { display: flex; }
#receipt-viewer img { max-width: 100%; max-height: 90vh; border-radius: 12px; object-fit: contain; }
#rv-close { position: absolute; top: 16px; right: 16px; background: #333; color: #fff; border: none; border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 18px; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--border2); color: var(--text); border-radius: 30px; padding: 10px 20px; font-size: 13px; opacity: 0; transition: opacity .3s; z-index: 500; pointer-events: none; white-space: nowrap; }
#toast.show { opacity: 1; }

@keyframes fadeUp { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }
.card { animation: fadeUp .25s ease both; }
