/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f7;
    color: #1d1d1f;
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: env(safe-area-inset-top);
}

/* === Container === */
.container { max-width: 480px; margin: 0 auto; padding: 16px; }
.home-container { padding-top: 40px; }

/* === Typography === */
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 600; margin-bottom: 16px; }
h3 { font-size: 18px; font-weight: 600; margin-bottom: 12px; }
.subtitle { color: #86868b; font-size: 16px; margin-top: 4px; }
.text-muted { color: #86868b; font-size: 14px; }
.dot { margin: 0 4px; color: #d2d2d7; }

/* === Hero === */
.hero { text-align: center; margin-bottom: 32px; }
.hero-icon { font-size: 64px; margin-bottom: 12px; }

/* === Card === */
.card {
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; font-size: 15px; color: #6e6e73; }
.form-group input[type="text"],
.form-group select {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid #d2d2d7;
    border-radius: 12px;
    font-size: 16px;
    background: #fff;
    -webkit-appearance: none;
    appearance: none;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #007aff;
    box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
}
.form-row { display: flex; gap: 12px; align-items: flex-end; }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

/* === Divider === */
.divider-text {
    text-align: center;
    margin: 20px 0;
    position: relative;
    color: #86868b;
    font-size: 14px;
}
.divider-text::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 50%;
    border-top: 1px solid #d2d2d7;
}
.divider-text span {
    background: #f5f5f7;
    padding: 0 16px;
    position: relative;
}

/* === Recent Trips === */
.recent-trip-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid #f5f5f7;
    text-decoration: none;
    color: #1d1d1f;
    min-height: 48px;
}
.recent-trip-item:last-child { border-bottom: none; }
.recent-name { font-weight: 500; font-size: 16px; }
.recent-arrow { color: #86868b; font-size: 18px; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    min-width: 44px;
    transition: opacity 0.15s;
    text-decoration: none;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: #007aff; color: #fff; }
.btn-secondary { background: #e5e5ea; color: #1d1d1f; }
.btn-success { background: #34c759; color: #fff; }
.btn-lg { padding: 16px 24px; font-size: 17px; }
.btn-sm { padding: 8px 16px; font-size: 14px; border-radius: 8px; min-height: 36px; }
.btn-block { width: 100%; }
.btn-icon {
    background: none; border: none; font-size: 20px;
    padding: 6px; cursor: pointer; min-width: 36px; min-height: 36px;
    display: flex; align-items: center; justify-content: center;
}
.btn-restore {
    margin-top: 8px;
    background: #007aff;
    color: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
}

/* === App Layout === */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
}
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #fff;
    border-bottom: 1px solid #e5e5ea;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 8px;
}
.header-left { flex: 1; min-width: 0; overflow: hidden; }
.header-left h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.badge {
    background: #e5e5ea;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}
.app-main {
    flex: 1;
    padding: 12px 16px;
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
    overflow-y: auto;
}

/* === Bottom Nav (5 tabs) === */
.bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    background: #fff;
    border-top: 1px solid #e5e5ea;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 200;
}
.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 0 4px;
    text-decoration: none;
    color: #86868b;
    font-size: 10px;
    min-height: 48px;
}
.nav-item.active { color: #007aff; }
.nav-icon { font-size: 20px; margin-bottom: 1px; }
.nav-label { font-weight: 500; }

/* === FAB === */
.fab {
    position: fixed;
    bottom: calc(66px + env(safe-area-inset-bottom));
    right: max(16px, calc((100vw - 480px) / 2 + 16px));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #007aff;
    color: #fff;
    font-size: 32px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,122,255,0.4);
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
}
.fab:active { transform: scale(0.9); }

/* === Expense Card === */
.expense-card {
    overflow: hidden;
    border-radius: 12px;
    margin-bottom: 8px;
    background: #ff3b30;
    position: relative;
}
.expense-card.dragging {
    opacity: 0.5;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    z-index: 50;
}
.expense-card-inner {
    display: flex;
    transition: transform 0.2s ease;
    background: #fff;
    position: relative;
    z-index: 1;
    align-items: stretch;
}
.drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    font-size: 16px;
    color: #c7c7cc;
    cursor: grab;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}
.drag-handle:active { cursor: grabbing; color: #007aff; }
.expense-card-content {
    flex: 1;
    padding: 14px 12px 14px 0;
    min-width: 0;
    cursor: pointer;
}
.expense-header {
    display: flex;
    align-items: center;
    gap: 8px;
}
.expense-category { font-size: 20px; }
.expense-location { flex: 1; font-weight: 500; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-amount { font-size: 17px; font-weight: 700; white-space: nowrap; }
.expense-meta { margin-top: 4px; font-size: 13px; color: #86868b; }

/* Expense amounts (dual display) */
.expense-amounts {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
}
.expense-base-amount {
    font-size: 12px;
    color: #86868b;
    font-weight: 500;
}

/* Header convert currency select */
.header-convert-select {
    padding: 6px 10px;
    border: 1.5px solid #007aff40;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    background: #f0f5ff;
    color: #007aff;
    min-height: 36px;
    cursor: pointer;
}

/* Swipe action (behind the card, right side) */
.expense-swipe-actions {
    position: absolute;
    right: 0; top: 0; bottom: 0;
    display: flex;
    align-items: stretch;
    z-index: 0;
    pointer-events: none;
}
.expense-card.swiped .expense-swipe-actions {
    pointer-events: auto;
}
.swipe-action-btn {
    width: 80px;
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.swipe-delete { background: #ff3b30; }

/* === Empty State === */
.empty-state { text-align: center; padding: 60px 20px; color: #86868b; }
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* === Loading === */
.loading { text-align: center; padding: 40px; color: #86868b; }

/* === Modal === */
.modal { display: none; position: fixed; inset: 0; z-index: 500; }
.modal.open { display: flex; flex-direction: column; justify-content: flex-end; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.modal-content {
    position: relative;
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    margin: 20px;
    max-width: 440px;
    align-self: center;
    width: calc(100% - 40px);
}
.modal-sheet {
    position: relative;
    background: #fff;
    border-radius: 16px 16px 0 0;
    padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
    max-height: 90vh;
    overflow-y: auto;
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
}
.modal-handle {
    width: 36px;
    height: 4px;
    background: #d2d2d7;
    border-radius: 2px;
    margin: 0 auto 16px;
}

/* === Share Link === */
.share-link-box { display: flex; gap: 8px; margin: 12px 0; }
.share-link-box input {
    flex: 1; padding: 12px; border: 1px solid #d2d2d7; border-radius: 8px;
    font-size: 14px; background: #f5f5f7;
}

/* === Member Management === */
.member-manage-list { display: flex; flex-direction: column; gap: 4px; }
.member-manage-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #f5f5f7;
    border-radius: 10px;
    min-height: 48px;
}
.member-manage-name { flex: 1; font-weight: 500; font-size: 16px; }
.member-manage-count { font-size: 13px; color: #86868b; }

/* === Category Grid === */
.category-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.category-btn {
    padding: 12px 8px;
    border: 2px solid #e5e5ea;
    border-radius: 12px;
    background: #fff;
    font-size: 13px;
    cursor: pointer;
    text-align: center;
    line-height: 1.4;
    min-height: 60px;
    transition: all 0.15s;
}
.category-btn.selected { border-color: #007aff; background: #f0f5ff; }

/* === Split Tabs === */
.split-tabs { display: flex; gap: 8px; }
.split-tab {
    flex: 1;
    padding: 10px 4px;
    border: 2px solid #e5e5ea;
    border-radius: 10px;
    background: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    min-height: 44px;
}
.split-tab.active { border-color: #007aff; background: #f0f5ff; color: #007aff; }

/* === Member Checklist === */
.member-check-list { display: flex; flex-direction: column; gap: 8px; }
.member-check {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; background: #f5f5f7; border-radius: 10px;
    font-size: 15px; cursor: pointer; min-height: 44px;
}
.member-check input[type="checkbox"] { width: 20px; height: 20px; accent-color: #007aff; }

.custom-split-row { padding: 8px 0; align-items: center; }
.split-total-hint { margin-top: 8px; font-size: 14px; color: #86868b; text-align: right; }

/* === Settle Page === */
.balance-list { display: flex; flex-direction: column; gap: 8px; }
.balance-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 0; border-bottom: 1px solid #f5f5f7;
}
.balance-name { font-weight: 600; font-size: 16px; }
.balance-detail { display: flex; gap: 12px; align-items: center; }
.balance-net { font-weight: 700; font-size: 16px; }
.balance-net.positive { color: #34c759; }
.balance-net.negative { color: #ff3b30; }

.transfer-list { display: flex; flex-direction: column; gap: 12px; }
.transfer-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px; background: #f5f5f7; border-radius: 12px; gap: 8px;
}
.transfer-row.settled { opacity: 0.5; }
.transfer-info { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: 1; }
.transfer-from { font-weight: 600; color: #ff3b30; }
.transfer-arrow { color: #86868b; font-size: 14px; }
.transfer-to { font-weight: 600; color: #34c759; }
.transfer-amounts { margin-left: auto; text-align: right; }
.transfer-amount { font-weight: 700; font-size: 16px; }
.transfer-alt { display: block; font-size: 12px; color: #86868b; font-weight: 500; }
.transfer-actions { flex-shrink: 0; }
.settled-badge { color: #34c759; font-weight: 600; font-size: 13px; }
.all-settled-msg { text-align: center; padding: 16px; font-size: 18px; font-weight: 600; color: #34c759; }

/* Card header row with copy button */
.card-header-row {
    display: flex; justify-content: space-between; align-items: center;
}
.btn-copy {
    font-size: 13px; font-weight: 600; color: #007aff;
    background: none; border: 1px solid #007aff;
    padding: 4px 12px; border-radius: 14px;
    cursor: pointer; white-space: nowrap;
    min-height: 28px;
    transition: background 0.15s, color 0.15s;
}
.btn-copy:active { background: #007aff; color: #fff; }

/* Settle member cards */
.settle-member-card { padding: 0; overflow: hidden; }
.settle-member-header {
    padding: 16px 20px;
    cursor: pointer;
    -webkit-user-select: none; user-select: none;
}
.settle-member-header:active { background: #f5f5f7; }
.settle-member-info {
    display: flex; justify-content: space-between; align-items: center;
}
.settle-member-name { font-size: 17px; font-weight: 700; }
.settle-member-summary {
    display: flex; gap: 12px; align-items: center; margin-top: 4px;
}
.settle-toggle { font-size: 12px; color: #86868b; margin-left: auto; }
.settle-member-detail {
    border-top: 1px solid #f0f0f0;
    padding: 0 16px 12px;
}
.settle-section-label {
    font-size: 12px; font-weight: 600; color: #86868b;
    padding: 10px 0 4px; text-transform: uppercase;
}
.settle-item {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 8px; border-radius: 8px; cursor: pointer;
    transition: opacity 0.2s, background 0.15s;
    min-height: 44px;
}
.settle-item:active { background: #f5f5f7; }
.settle-item-done {
    opacity: 0.4;
    text-decoration: line-through;
}
.settle-item-icon { font-size: 18px; flex-shrink: 0; }
.settle-item-name { flex: 1; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settle-item-amount { font-size: 15px; font-weight: 600; flex-shrink: 0; }
.settle-item-check { width: 20px; font-size: 14px; color: #34c759; font-weight: 700; text-align: center; flex-shrink: 0; }

/* Net label */
.settle-member-net { text-align: right; }
.settle-net-label {
    display: block; font-size: 11px; font-weight: 500; margin-top: 1px;
}
.settle-net-label.positive { color: #34c759; }
.settle-net-label.negative { color: #ff3b30; }
.settle-net-label:not(.positive):not(.negative) { color: #86868b; }

/* Progress badge */
.settle-progress {
    font-size: 12px; font-weight: 600; color: #86868b;
    background: #f0f0f0; padding: 2px 8px; border-radius: 10px;
}
.settle-progress.all-done {
    background: #d1f7e5; color: #00873c;
}

/* Remaining summary */
.settle-remaining {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 12px; margin: 8px 0 4px;
    background: #f5f5f7; border-radius: 10px;
}
.settle-remaining-label { font-size: 13px; font-weight: 600; color: #6e6e73; }
.settle-remaining-amount { font-size: 15px; font-weight: 700; }
.settle-remaining-amount.positive { color: #34c759; }
.settle-remaining-amount.negative { color: #ff3b30; }

/* === Stats Page === */
.stats-summary { text-align: center; padding: 24px; }
.stat-number { font-size: 36px; font-weight: 800; color: #007aff; }
.stat-label { font-size: 16px; color: #86868b; margin-top: 4px; }
.stat-sub { font-size: 14px; color: #aeaeb2; margin-top: 2px; }
.chart-container { position: relative; max-height: 280px; margin: 0 auto; }

/* Stats list */
.stats-list { margin-top: 16px; }
.stats-list-row {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 0; border-bottom: 1px solid #f0f0f0;
}
.stats-list-row:last-child { border-bottom: none; }
.stats-list-icon { font-size: 18px; flex-shrink: 0; width: 24px; text-align: center; }
.stats-list-rank {
    flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%;
    background: #f0f0f0; font-size: 12px; font-weight: 700; color: #86868b;
    display: flex; align-items: center; justify-content: center;
}
.stats-list-name { font-size: 14px; font-weight: 600; flex-shrink: 0; min-width: 36px; }
.stats-list-bar {
    flex: 1; height: 8px; background: #f0f0f0; border-radius: 4px; overflow: hidden;
}
.stats-list-fill { display: block; height: 100%; border-radius: 4px; transition: width 0.3s; }
.stats-list-amount { font-size: 14px; font-weight: 700; flex-shrink: 0; min-width: 50px; text-align: right; }
.stats-list-pct { font-size: 12px; color: #86868b; flex-shrink: 0; min-width: 32px; text-align: right; }

/* === Rate Page === */
.rate-main-card {
    text-align: center;
    background: linear-gradient(135deg, #007aff 0%, #5856d6 100%);
    color: #fff;
}
.rate-main-header { font-size: 13px; opacity: 0.8; margin-bottom: 4px; }
.rate-main-value { font-size: 20px; font-weight: 700; }
.rate-main-value strong { font-size: 24px; }
.rate-main-sub { font-size: 12px; opacity: 0.7; margin-top: 4px; }
.rate-flag { margin-right: 4px; }

.rate-highlight-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}
.rate-highlight-card {
    background: #fff;
    border-radius: 12px;
    padding: 14px 8px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.rate-highlight-flag { font-size: 24px; }
.rate-highlight-code { font-size: 14px; font-weight: 700; margin-top: 2px; }
.rate-highlight-value { font-size: 13px; color: #007aff; font-weight: 600; margin-top: 2px; }

.rate-table { display: flex; flex-direction: column; }
.rate-row {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 0; border-bottom: 1px solid #f5f5f7;
}
.rate-row:last-child { border-bottom: none; }
.rate-row-flag { font-size: 20px; width: 28px; text-align: center; }
.rate-row-code { font-weight: 700; font-size: 15px; width: 40px; }
.rate-row-name { flex: 1; font-size: 14px; color: #6e6e73; }
.rate-row-value { font-weight: 600; font-size: 15px; color: #007aff; }
.rate-row-highlight { background: #f0f5ff; border-radius: 8px; margin: 0 -8px; padding: 12px 8px; }
.rate-row-highlight .rate-row-code { color: #007aff; }
.rate-row-highlight .rate-row-value { font-size: 16px; font-weight: 800; }

/* Converter */
.converter-row { display: flex; flex-direction: column; gap: 8px; }
.converter-input-group { display: flex; align-items: center; gap: 10px; }
.converter-select {
    padding: 10px 12px; border: 1px solid #d2d2d7; border-radius: 10px;
    font-size: 15px; font-weight: 600; background: #f5f5f7;
    -webkit-appearance: none; appearance: none; width: 90px;
}
.converter-input {
    flex: 1; padding: 12px 14px; border: 1px solid #d2d2d7; border-radius: 10px;
    font-size: 18px; font-weight: 600; background: #fff;
}
.converter-input:focus { outline: none; border-color: #007aff; box-shadow: 0 0 0 3px rgba(0,122,255,0.15); }
.converter-arrow { text-align: center; font-size: 18px; color: #86868b; }
.converter-base-label {
    padding: 10px 12px; background: #e5e5ea; border-radius: 10px;
    font-size: 15px; font-weight: 600; width: 90px; text-align: center;
}
.converter-result {
    flex: 1; padding: 12px 14px; font-size: 22px; font-weight: 800;
    color: #007aff; background: #f0f5ff; border-radius: 10px; text-align: right;
}

/* === Log Page === */
.log-item { padding: 14px 0; border-bottom: 1px solid #f5f5f7; }
.log-header { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.log-icon { font-size: 16px; }
.log-action {
    padding: 2px 8px; border-radius: 6px; font-size: 13px; font-weight: 600;
}
.action-create { background: #d1f7e5; color: #00873c; }
.action-update { background: #ffecd2; color: #c77b00; }
.action-delete { background: #ffdada; color: #c50000; }
.action-restore { background: #e0e7ff; color: #3b5adb; }
.log-user { font-weight: 600; font-size: 15px; }
.log-time { color: #86868b; font-size: 12px; margin-left: auto; }
.log-detail { margin-top: 4px; font-size: 14px; color: #6e6e73; }

/* === Error === */
.error { color: #ff3b30; text-align: center; padding: 20px; }
