@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --success-hover: #059669;
    --bg: #f9fafb;
    --surface: #ffffff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --radius: 16px;
    --radius-sm: 8px;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 600px;
    margin: 0 auto;
    background-color: var(--bg);
    min-height: 100vh;
    padding-bottom: 5rem;
}

header {
    background-color: var(--surface);
    color: var(--text);
    padding: 1.5rem 1rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
header h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

main {
    padding: 1.5rem 1rem;
}

/* Typography & General */
h2, h3, h4 {
    color: var(--text);
    font-weight: 600;
}
h2 { font-size: 1.5rem; margin-bottom: 1rem; }
h3 { font-size: 1.25rem; margin-bottom: 1rem; }

/* Cards & Lists */
ul { list-style: none; }

.category-list {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    scroll-snap-type: x mandatory;
}
.category-list::-webkit-scrollbar {
    height: 4px;
}
.category-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}
.contacts-modal-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.member-item, .contact-item, .tx-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}
.member-item:hover, .contact-item:hover, .tx-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}
.category-item {
    flex: 0 0 100px;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0.75rem 0.25rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    text-align: center;
}
.tx-item {
    flex-direction: column;
    align-items: stretch;
}

/* Forms & Inputs */
.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}
.form-row .form-group {
    flex: 1;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.form-group label {
    font-weight: 600;
    font-size: 0.9rem;
}
input, select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background-color: var(--surface);
    font-family: inherit;
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Buttons */
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    border: none;
    border-radius: var(--radius-sm);
    transition: transform 0.15s ease, opacity 0.2s ease, background-color 0.2s;
}
button:active:not(:disabled) {
    transform: scale(0.95);
}
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.primary-btn, .primary-btn-large, button[type="submit"] {
    background-color: var(--primary);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
}
button[type="submit"] {
    padding: 0.75rem;
}
.primary-btn-large {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    border-radius: var(--radius);
}
.danger-btn {
    background-color: var(--danger);
    color: white;
    padding: 0.75rem 1.25rem;
}
.secondary-btn, button[type="button"], .back-btn {
    background-color: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.75rem 1.25rem;
}

/* Icon Only Buttons inside Lists */
.icon-btn {
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    background-color: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.icon-btn:hover {
    background-color: var(--bg);
}
.icon-btn.danger-btn {
    color: var(--danger);
    background-color: #fef2f2;
    border-color: #fecaca;
}
.icon-btn.danger-btn:hover {
    background-color: #fee2e2;
}

/* Add Forms Inline */
.add-member-form, .add-form, #add-contact-form {
    display: flex;
    gap: 0.5rem;
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-top: 1rem;
}
.add-member-form input, .add-form input {
    flex: 1;
}

/* Specific Sections */
.transaction-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}
.wealth-summary, .member-header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding: 1.5rem;
    background-color: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.wealth-amount {
    font-size: 2rem;
    font-weight: 700;
}
.wealth-amount.positive { color: var(--success); }
.wealth-amount.negative { color: var(--danger); }
.wealth-amount.neutral { color: var(--text); }

/* Transactions */
.tx-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.tx-date { font-weight: 600; color: var(--text); }
.tx-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}
.tx-desc { font-weight: 600; font-size: 1.05rem; }
.tx-amount { font-size: 1.15rem; font-weight: 700; }
.tx-amount.positive { color: var(--success); }
.tx-amount.negative { color: var(--danger); }
.tx-notes { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.5rem; background: var(--bg); padding: 0.5rem; border-radius: var(--radius-sm); }

/* Modals */
.hidden { display: none !important; }
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(4px);
    display: flex; justify-content: center; align-items: center;
    z-index: 9999;
    padding: 1rem;
}
.modal-content {
    background-color: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}
.modal-actions {
    display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem;
}

/* FAB */
.fab {
    position: fixed;
    bottom: 2rem;
    right: max(2rem, calc(50vw - 280px));
    width: 56px;
    height: 56px;
    border-radius: 9999px;
    background-color: var(--primary);
    color: white;
    font-size: 1.5rem;
    box-shadow: var(--shadow);
    z-index: 1000;
}
.fab:hover { background-color: var(--primary-hover); transform: scale(1.05); }

/* Ledger Table */
.ledger-table-container {
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; text-align: right; }
th { text-align: right; padding: 0.75rem; color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; border-bottom: 2px solid var(--border); }
th:first-child { text-align: left; }
td { padding: 1rem 0.75rem; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
td:first-child { text-align: left; font-weight: 500; }

/* Filters */
.filters-container { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.filters-container input { flex: 2; }
.filters-container select { flex: 1; }

/* List texts */
.member-name, .contact-name {
    font-weight: 600;
    font-size: 1.05rem;
}
.category-name {
    font-weight: 600;
    font-size: 0.8rem;
    line-height: 1.2;
    word-break: break-word;
}
.category-balance {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.contact-info { display: flex; flex-direction: column; gap: 0.25rem; }
.category-info { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem; }
.contact-details { font-size: 0.85rem; color: var(--text-muted); }
.member-actions { display: flex; gap: 0.5rem; }
.category-actions { display: flex; gap: 0.2rem; margin-top: 0.4rem; }
.category-actions .icon-btn { padding: 0.25rem; }
.category-actions svg { width: 14px; height: 14px; }

/* Toasts */
.toast {
    padding: 1rem;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: var(--surface);
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.95rem;
    font-weight: 500;
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
