:root {
    --primary:       #4f46e5;
    --primary-dark:  #4338ca;
    --primary-light: #eef2ff;
    --danger:        #ef4444;
    --success:       #22c55e;
    --text:          #1e293b;
    --muted:         #64748b;
    --border:        #e2e8f0;
    --bg:            #f8fafc;
    --white:         #ffffff;
    --radius:        10px;
    --shadow:        0 1px 3px rgba(0,0,0,.08);
    --shadow-md:     0 4px 12px rgba(0,0,0,.10);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Landing ── */
.landing {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
}

.landing-card {
    background: var(--white);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    padding: 40px 36px;
    width: 100%;
    max-width: 400px;
}

.logo {
    text-align: center;
    margin-bottom: 32px;
}
.logo h1 {
    font-size: 30px;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -.5px;
}
.logo p {
    color: var(--muted);
    font-size: 14px;
    margin-top: 4px;
}

.form-section h2 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: 10px;
}
.form-section input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    margin-bottom: 10px;
    background: var(--white);
}
.form-section input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

.divider {
    text-align: center;
    margin: 24px 0;
    position: relative;
}
.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0; right: 0;
    height: 1px;
    background: var(--border);
}
.divider span {
    position: relative;
    background: var(--white);
    padding: 0 12px;
    color: var(--muted);
    font-size: 13px;
}

.landing-footer {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 12px;
    color: #c0c8d8;
    letter-spacing: .04em;
}
.landing-footer-author {
    font-weight: 700;
    color: #a5b0c8;
    letter-spacing: .12em;
}

.alert {
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    margin-bottom: 16px;
}
.alert-error { background: #fef2f2; color: var(--danger); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background .15s, opacity .15s;
    white-space: nowrap;
    text-decoration: none;
}
.btn-primary  { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline  { background: var(--white); color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-ghost    { background: none; color: var(--muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-full     { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* ── App header ── */
.app-header {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.header-inner {
    max-width: 700px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.logo-link {
    font-size: 18px;
    font-weight: 800;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: -.3px;
    flex-shrink: 0;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.group-name {
    font-weight: 600;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.code-badge {
    background: var(--primary-light);
    color: var(--primary);
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 13px;
    font-weight: 700;
    font-family: ui-monospace, monospace;
    letter-spacing: .08em;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s;
}
.code-badge:hover { background: #c7d2fe; }

/* ── Main ── */
.app-main {
    max-width: 700px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 2px;
    padding: 14px 0 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 24px;
}
.tab {
    padding: 8px 18px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: color .15s, border-color .15s;
    border-radius: 6px 6px 0 0;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Panel header ── */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.panel-header h2 {
    font-size: 18px;
    font-weight: 700;
}

/* ── Expense items ── */
.expense-item {
    background: var(--white);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.expense-body { flex: 1; min-width: 0; }
.expense-desc {
    font-weight: 600;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.expense-meta {
    font-size: 13px;
    color: var(--muted);
    margin-top: 3px;
    line-height: 1.4;
}
.expense-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
}
.expense-amount {
    font-size: 17px;
    font-weight: 700;
}
.btn-delete {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color .15s, background .15s;
}
.btn-delete:hover { color: var(--danger); background: #fef2f2; }

/* ── Members ── */
.add-member-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.add-member-row input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.add-member-row input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

.member-item {
    background: var(--white);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
}
.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: var(--white);
    flex-shrink: 0;
}
.member-name { font-weight: 500; }

/* ── Balances ── */
.balance-item {
    background: var(--white);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
}
.balance-info { flex: 1; }
.balance-name { font-weight: 600; }
.balance-label { font-size: 13px; color: var(--muted); }
.balance-amount { font-size: 17px; font-weight: 700; }
.positive { color: var(--success); }
.negative { color: var(--danger); }
.neutral  { color: var(--muted); }

.settle-section { margin-top: 28px; }
.settle-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin-bottom: 12px;
}
.settle-item {
    background: var(--white);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    flex-wrap: wrap;
}
.settle-arrow { color: var(--muted); font-size: 16px; }
.settle-amount { margin-left: auto; font-weight: 700; font-size: 15px; }

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.45);
    z-index: 50;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}
.modal-overlay.open { display: flex; }
@media (min-width: 640px) {
    .modal-overlay { align-items: center; padding: 24px; }
}
.modal {
    background: var(--white);
    border-radius: 16px 16px 0 0;
    padding: 24px 20px 32px;
    width: 100%;
    max-width: 480px;
    max-height: 92vh;
    overflow-y: auto;
}
@media (min-width: 640px) {
    .modal { border-radius: 16px; padding: 28px; }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
    background: var(--bg);
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background .15s;
}
.modal-close:hover { background: var(--border); }

/* ── Form ── */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: 7px;
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    outline: none;
    background: var(--white);
    transition: border-color .15s, box-shadow .15s;
    appearance: auto;
}
.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    transition: all .15s;
    background: var(--white);
    color: var(--text);
}
.chip.selected {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* ── Split mode toggle ── */
.split-mode-toggle {
    display: flex;
    gap: 0;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    width: fit-content;
}
.split-mode-btn {
    padding: 7px 20px;
    font-size: 13px;
    font-weight: 600;
    background: var(--white);
    color: var(--muted);
    border: none;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.split-mode-btn + .split-mode-btn {
    border-left: 1.5px solid var(--border);
}
.split-mode-btn.active {
    background: var(--primary);
    color: var(--white);
}

/* ── Custom split ── */
.custom-split-list { display: flex; flex-direction: column; gap: 8px; }

.custom-split-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.custom-split-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.custom-split-input-wrap {
    display: flex;
    align-items: center;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}
.custom-amount-input {
    width: 80px;
    padding: 7px 10px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    outline: none;
    text-align: right;
    background: var(--white);
}
.custom-input-suffix {
    padding: 0 10px 0 4px;
    font-size: 13px;
    color: var(--muted);
    background: var(--bg);
    align-self: stretch;
    display: flex;
    align-items: center;
    border-left: 1.5px solid var(--border);
}

.custom-split-total {
    margin-top: 10px;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 7px;
    min-height: 34px;
    display: flex;
    align-items: center;
}
.custom-split-total.ok    { background: #f0fdf4; color: var(--success); }
.custom-split-total.error { background: #fef2f2; color: var(--danger); }

.split-preview {
    background: var(--bg);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 18px;
    min-height: 38px;
    display: flex;
    align-items: center;
}

/* ── States ── */
.empty-state {
    text-align: center;
    padding: 52px 16px;
    color: var(--muted);
}
.empty-state p { font-size: 15px; line-height: 1.6; }

.skeleton-list {
    height: 80px;
    background: linear-gradient(90deg, var(--border) 25%, #f1f5f9 50%, var(--border) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: var(--radius);
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #1e293b;
    color: var(--white);
    padding: 10px 22px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: transform .28s cubic-bezier(.34,1.56,.64,1);
    z-index: 200;
    pointer-events: none;
    white-space: nowrap;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
