* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.4; }
body { min-height: 100dvh; overscroll-behavior-y: contain; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
img { display: block; max-width: 100%; }

#app { min-height: 100dvh; }

/* Boot screen */
.boot { display: grid; place-items: center; gap: 16px; min-height: 100dvh; color: var(--text-3); }
.boot-logo { width: 64px; height: 64px; border-radius: 16px; background: var(--primary); color: var(--primary-text); font-weight: 700; font-size: 22px; display: grid; place-items: center; }

/* Layout */
.app-shell { padding-top: var(--safe-top); padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom)); min-height: 100dvh; }
.topbar {
    position: sticky; top: 0; z-index: 10;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 8px;
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; font-weight: 600; margin: 0; flex: 1; }
.topbar .icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; color: var(--text-2); }
.topbar .icon-btn:active { background: var(--surface-2); }

.content { padding: 16px 16px 8px; }

/* Tabbar */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0;
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: grid; grid-template-columns: repeat(5, 1fr);
    z-index: 20;
}
.tabbar a {
    display: grid; place-items: center; gap: 2px;
    color: var(--text-3); font-size: 11px; font-weight: 500;
    text-decoration: none; padding: 8px 4px;
}
.tabbar a.active { color: var(--primary); }
.tabbar .tab-icon { width: 24px; height: 24px; display: grid; place-items: center; }
.tabbar a.add { color: var(--primary-text); }
.tabbar a.add .tab-icon { width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: var(--primary-text); margin-top: -10px; box-shadow: var(--shadow-md); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px; margin-bottom: 10px; }
.card-row { display: flex; align-items: center; gap: 12px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.muted { color: var(--text-3); font-size: 13px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin: 16px 4px 8px; font-weight: 600; }

/* Forms */
.field { display: block; margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.input, .select, .textarea {
    display: block; width: 100%; min-height: 44px; padding: 10px 12px;
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    appearance: none; -webkit-appearance: none;
}
.select { background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 18px;
    background: var(--primary); color: var(--primary-text);
    border-radius: var(--radius-sm); font-weight: 600;
    transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn.full { width: 100%; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: white; }
.btn.ghost { background: transparent; color: var(--primary); }
.btn:disabled { opacity: .5; pointer-events: none; }

/* List items */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
    display: grid; grid-template-columns: 56px 1fr auto; gap: 12px;
    padding: 12px; align-items: center;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.list-item .thumb { width: 56px; height: 56px; border-radius: 8px; background: var(--surface-2); object-fit: cover; }
.list-item .meta { min-width: 0; }
.list-item .meta .title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta .sub { font-size: 13px; color: var(--text-3); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.list-item .amount { text-align: right; font-weight: 600; font-size: 15px; }
.list-item .amount .cur { font-size: 12px; color: var(--text-3); display: block; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.badge.allocated { background: var(--success-bg); color: var(--success); }
.badge.unallocated { background: var(--surface-3); color: var(--text-3); }
.badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.failed { background: var(--danger-bg); color: var(--danger); }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px; }
.tile .label { font-size: 12px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.tile .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.tile .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* Sheet / modal */
.sheet-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.4);
    display: flex; align-items: flex-end; justify-content: center;
    z-index: 100; opacity: 0; transition: opacity .2s;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
    background: var(--surface); width: 100%; max-width: 500px;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 18px 16px calc(18px + var(--safe-bottom));
    transform: translateY(100%); transition: transform .25s;
    max-height: 85dvh; overflow-y: auto;
}
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet-grabber { width: 40px; height: 4px; background: var(--surface-3); border-radius: 2px; margin: 0 auto 14px; }

/* Toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow-md); animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); color: white; }
.toast.success { background: var(--success); color: white; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Receipt detail */
.receipt-image { width: 100%; max-height: 50dvh; object-fit: contain; background: var(--surface-2); border-radius: var(--radius-md); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; align-items: center; }
.kv label { color: var(--text-3); font-size: 13px; }

/* Trip summary */
.curlist { display: flex; flex-direction: column; gap: 6px; }
.curlist > div { display: grid; grid-template-columns: 60px 1fr auto; gap: 10px; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius-sm); }

/* Charts */
canvas.chart { width: 100%; height: 200px; display: block; }

/* Desktop landing */
.desktop-page { min-height: 100dvh; display: grid; place-items: center; padding: 40px; text-align: center; }
.desktop-page .qr-box { background: var(--surface); padding: 24px; border-radius: var(--radius-lg); border: 1px solid var(--border); display: inline-block; margin-top: 24px; }
.desktop-page h1 { font-size: 28px; margin: 0 0 8px; }

/* Login page */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.auth h1 { font-size: 32px; margin: 0 0 8px; }
.auth p { color: var(--text-3); margin: 0 0 24px; }
.auth-toggle { text-align: center; margin-top: 16px; color: var(--text-3); font-size: 14px; }
.auth-toggle button { color: var(--primary); font-weight: 600; }

/* Install prompt */
.install-banner { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 14px; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow-md); z-index: 50; }
.install-banner .grow { flex: 1; }

/* Items editor */
.items { display: flex; flex-direction: column; gap: 8px; }
.item-row { display: grid; grid-template-columns: 1fr 60px 80px 80px 32px; gap: 6px; align-items: center; }
.item-row input { min-height: 36px; padding: 6px 8px; font-size: 14px; }
.item-row .remove { color: var(--danger); width: 32px; height: 36px; display: grid; place-items: center; }

/* Misc */
.empty { text-align: center; padding: 40px 16px; color: var(--text-3); }
.empty svg { opacity: .4; margin-bottom: 8px; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--surface-3); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-spinner { display: grid; place-items: center; padding: 60px; }

.divider { height: 1px; background: var(--border); margin: 12px 0; }

.icon { width: 20px; height: 20px; flex-shrink: 0; }
.icon-lg { width: 28px; height: 28px; }
