* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #2563eb; --primary-dark: #1d4ed8;
  --bg: #f8fafc; --card: #fff; --text: #1e293b;
  --muted: #64748b; --border: #e2e8f0;
  --green: #10b981; --red: #ef4444; --orange: #f59e0b;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; }
#app { flex: 1; display: flex; flex-direction: column; max-width: 480px; margin: 0 auto; width: 100%; }
header { padding: 1rem; background: var(--card); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 10; }
header h1 { font-size: 1.25rem; font-weight: 700; }
main { flex: 1; overflow-y: auto; padding: 1rem; padding-bottom: 100px; }
.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
h2 { margin-bottom: 1rem; font-size: 1.1rem; }
input, select { width: 100%; padding: 0.75rem; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; background: var(--card); margin-bottom: 0.75rem; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
label { font-size: 0.875rem; font-weight: 500; margin-bottom: 0.25rem; display: block; }
.btn { padding: 0.75rem 1.5rem; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: background 0.15s; }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:active { background: var(--primary-dark); }
.btn.secondary { background: var(--border); color: var(--text); }
.btn.secondary:active { background: #cbd5e1; }
.btn.danger { background: var(--card); color: var(--red); border: 1px solid var(--red); margin-top: 0.75rem; }
.btn.danger:active { background: #fef2f2; }
.btn.full { width: 100%; }
.btn.small { padding: 0.5rem 0.9rem; font-size: 0.8rem; }
.btn-row { display: flex; gap: 0.5rem; margin-top: 1rem; }
.btn-row .btn { flex: 1; }
.hidden { display: none !important; }
.badge { background: var(--green); color: white; padding: 0.25rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.screen-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem; }
#members-list { margin: 0.5rem 0; }
.member-input { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.member-input input { flex: 1; margin-bottom: 0; }
.member-input button { padding: 0.75rem; background: var(--border); border: none; border-radius: 8px; cursor: pointer; }
.balances { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; margin-bottom: 1rem; }
.balance-card { background: var(--card); padding: 0.75rem; border-radius: 8px; border: 1px solid var(--border); text-align: center; }
.balance-name { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.25rem; }
.balance-amount { font-size: 1.1rem; font-weight: 700; }
.balance-amount.positive { color: var(--green); }
.balance-amount.negative { color: var(--red); }
.balance-amount.zero { color: var(--muted); }
.table-wrapper { overflow-x: auto; margin-top: 0.5rem; }
#expenses-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
#expenses-table th, #expenses-table td { padding: 0.75rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border); }
#expenses-table th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }
#expenses-table th:last-child, #expenses-table td:nth-child(5) { text-align: right; }
#expenses-table td { background: var(--card); }
#expenses-table tr:last-child td { border-bottom: none; }
#expenses-table td:first-child { color: var(--muted); font-size: 0.75rem; }
#expenses-table td:nth-child(2) { white-space: nowrap; }
#expenses-table td:nth-child(5) { font-weight: 600; color: var(--red); text-align: right; }
#expenses-table tbody tr:hover td { background: var(--bg); }
#expenses-table tbody tr:empty { display: none; }
#expenses-table .empty-state { text-align: center; color: var(--muted); padding: 2rem; }
#expenses-table td:nth-child(6) { text-align: right; padding-left: 0; padding-right: 0.5rem; }
.row-delete { background: none; border: none; color: var(--muted); font-size: 1rem; line-height: 1; cursor: pointer; padding: 0.25rem 0.4rem; border-radius: 6px; flex-shrink: 0; }
.row-delete:hover { color: var(--red); background: var(--bg); }
.payment-entry .payment-right { display: flex; align-items: center; gap: 0.5rem; }
.split-member { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0; }
.split-member input[type="checkbox"] { width: 1.25rem; height: 1.25rem; accent-color: var(--primary); margin-bottom: 0; }
.settle-diagram { width: 100%; min-height: 280px; margin: 1rem 0; }
.settle-diagram svg { width: 100%; height: 280px; display: block; }
.state-node { cursor: default; }
.state-node circle { fill: var(--card); stroke: var(--primary); stroke-width: 2; transition: fill 0.2s; }
.state-node text { font-size: 0.75rem; font-weight: 600; fill: var(--text); pointer-events: none; }
.state-node .balance { font-size: 0.65rem; fill: var(--muted); }
.state-node.positive circle { fill: #ecfdf5; stroke: var(--green); }
.state-node.negative circle { fill: #fef2f2; stroke: var(--red); }
.state-node.zero circle { fill: var(--bg); stroke: var(--muted); }
.arrow { fill: none; stroke: var(--primary); stroke-width: 2; marker-end: url(#arrowhead); transition: stroke 0.2s; }
.arrow:hover { stroke: var(--primary-dark); stroke-width: 3; }
.arrow-label { font-size: 0.7rem; fill: var(--primary); font-weight: 600; pointer-events: none; }
.settle-diagram .empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.settlements-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; }
.settlement { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; }
.settlement-from { font-weight: 600; color: var(--red); }
.settlement-to { font-weight: 600; color: var(--green); margin-top: 0.25rem; }
.settlement-amount { font-size: 1.1rem; font-weight: 700; margin-top: 0.25rem; }
.settlement-mark-paid { white-space: nowrap; }
.payments-history { margin-top: 1.5rem; }
.payments-history h3 { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; margin-bottom: 0.5rem; }
.payment-entry { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 0.65rem 0.75rem; margin-bottom: 0.5rem; font-size: 0.875rem; }
.payment-entry .payment-amount { font-weight: 700; color: var(--green); }
.payment-entry .payment-date { color: var(--muted); font-size: 0.75rem; margin-left: 0.5rem; }
.muted { color: var(--muted); font-size: 0.875rem; margin-bottom: 0.75rem; }
.switch-link { text-align: center; font-size: 0.875rem; color: var(--muted); margin-top: 0.75rem; }
.switch-link a { color: var(--primary); font-weight: 600; text-decoration: none; }
.error-text { color: var(--red); font-size: 0.875rem; margin: -0.25rem 0 0.75rem; }
.copy-row { display: flex; gap: 0.5rem; }
.copy-row input { flex: 1; }
.copy-row .btn { margin-bottom: 0.75rem; }
.share-panel { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
.share-panel .hint { font-size: 0.8rem; color: var(--muted); margin: -0.5rem 0 0.75rem; }
#bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; max-width: 480px; margin: 0 auto; background: var(--card); border-top: 1px solid var(--border); display: flex; padding: 0.5rem 0; z-index: 20; }
.nav-btn { flex: 1; background: none; border: none; padding: 0.5rem; font-size: 0.75rem; color: var(--muted); cursor: pointer; }
.nav-btn.active { color: var(--primary); font-weight: 600; }
@media (max-width: 480px) {
  #app { max-width: 100%; }
  .table-wrapper { overflow-x: visible; }
  #expenses-table { table-layout: fixed; font-size: 0.68rem; }
  #expenses-table th, #expenses-table td { padding: 0.5rem 0.2rem; word-break: break-word; }
  #expenses-table th { font-size: 0.6rem; }
  #expenses-table td:nth-child(2) { white-space: normal; }
  #expenses-table th:nth-child(1), #expenses-table td:nth-child(1) { width: 6%; }
  #expenses-table th:nth-child(2), #expenses-table td:nth-child(2) { width: 17%; }
  #expenses-table th:nth-child(3), #expenses-table td:nth-child(3) { width: 15%; }
  #expenses-table th:nth-child(4), #expenses-table td:nth-child(4) { width: 30%; }
  #expenses-table th:nth-child(5), #expenses-table td:nth-child(5) { width: 22%; padding-right: 0.3rem; }
  #expenses-table th:nth-child(6), #expenses-table td:nth-child(6) { width: 10%; padding: 0.5rem 0; }
  #expenses-table .row-delete { font-size: 0.8rem; padding: 0.15rem; }
}