:root {
    --primary: #059669;
    --primary-hover: #047857;
    --primary-light: #d1fae5;
    --bg: #f3f4f6;
    --card: #ffffff;
    --text: #111827;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --info: #3b82f6;
    --info-light: #dbeafe;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

[x-cloak] { display: none !important; }

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ---- Login ---- */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-card h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    color: var(--primary);
}

.login-card .subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

/* ---- Input with toggle ---- */
.input-with-toggle {
    position: relative;
}

.input-with-toggle input {
    padding-right: 5.5rem;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    font-size: 1.0625rem;
}

.toggle-visibility {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary);
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.toggle-visibility:hover {
    background: var(--primary-light);
}

/* ---- Forms ---- */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.2s;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

textarea { resize: vertical; min-height: 60px; }

label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.form-group {
    margin-bottom: 1rem;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    font-family: inherit;
    text-decoration: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-secondary:hover { background: #d1d5db; }

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover { background: var(--danger-hover); }

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-block {
    width: 100%;
    margin-top: 0.5rem;
}

.btn-ghost {
    background: transparent;
    color: var(--primary);
    padding: 0.375rem 0.5rem;
}

.btn-ghost:hover { background: var(--primary-light); }

/* ---- Layout ---- */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 2rem;
}

header {
    background: var(--primary);
    color: #fff;
    padding: 0.875rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.125rem;
    font-weight: 700;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-right button {
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    padding: 0.375rem 0.625rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    cursor: pointer;
    font-family: inherit;
    position: relative;
}

.header-right button:hover {
    background: rgba(255,255,255,0.3);
}

.badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

main {
    padding: 1rem;
}

/* ---- Cards ---- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
}

.card-clickable {
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.1s;
}

.card-clickable:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.dashboard-balance {
    font-size: 0.9375rem;
    font-weight: 700;
    white-space: nowrap;
}

.dashboard-settlement {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.app-download {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.group-actions {
    display: flex;
    gap: 0.5rem;
}

.group-actions .btn {
    flex: 1;
}

.card h3 {
    font-size: 1rem;
    margin-bottom: 0.125rem;
}

.card .meta {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* ---- Section Header ---- */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-size: 1.125rem;
}

.back-link {
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.875rem;
    background: none;
    border: none;
    font-family: inherit;
}

.back-link:hover { text-decoration: underline; }

/* ---- Tabs ---- */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1rem;
    gap: 0;
}

.tab {
    flex: 1;
    text-align: center;
    padding: 0.625rem 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}

.tab:hover { color: var(--text); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ---- Balance ---- */
.balance-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.balance-item:last-child { border-bottom: none; }

.balance-item-highlight {
    font-size: 1rem;
    color: var(--text);
    padding: 0.625rem 0;
}

.balance-item-highlight .balance-name {
    font-weight: 700;
}

.balance-hint {
    font-size: 0.75rem;
    color: var(--warning-dark, #b45309);
    font-weight: 600;
    margin-top: 0.125rem;
}

.balance-positive { color: var(--primary); font-weight: 700; }
.balance-negative { color: var(--danger); font-weight: 700; }
.balance-zero { color: var(--text-secondary); }

.settlement-suggestion {
    background: var(--info-light);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
}

.settlement-suggestion .amount {
    font-weight: 700;
    color: var(--info);
}

/* ---- Expense List / Journal ---- */
.expense-item {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.875rem 1rem;
    margin-bottom: 0.5rem;
}

.expense-item.settlement {
    border-left: 3px solid var(--info);
}

.expense-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.expense-title {
    font-weight: 600;
    font-size: 0.9375rem;
}

.expense-amount {
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
    margin-left: 0.5rem;
}

.expense-meta {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.expense-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

/* ---- Notifications Panel ---- */
.notifications-panel {
    background: var(--card);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow-md);
    max-height: 60vh;
    overflow-y: auto;
    margin: 0 1rem;
}

.notification-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.notification-item:last-child { border-bottom: none; }

.notification-item.unread {
    background: var(--primary-light);
}

.notification-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.notification-actions {
    display: flex;
    justify-content: flex-end;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--border);
}

/* ---- Members / Chips ---- */
.member-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.5rem;
}

.chip {
    background: var(--primary-light);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
}

/* ---- Checkbox list ---- */
.checkbox-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.25rem;
    font-size: 0.9375rem;
    cursor: pointer;
}

.checkbox-item:hover {
    background: var(--bg);
    border-radius: 4px;
}

.checkbox-item input[type="checkbox"] {
    width: auto;
    accent-color: var(--primary);
}

/* ---- Split Options ---- */
.split-inputs {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.split-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.split-row .name {
    flex: 1;
    font-size: 0.875rem;
}

.split-row input {
    width: 80px;
}

.split-input-wrap {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.split-abs {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 0.25rem;
}

.split-suffix {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    min-width: 1.75rem;
}

.split-total {
    text-align: right;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    padding-top: 0.25rem;
    border-top: 1px solid var(--border);
}

.split-total-ok {
    color: var(--primary);
    font-weight: 600;
}

.split-total-warn {
    color: var(--danger);
    font-weight: 600;
}

/* ---- Error ---- */
.error-msg {
    background: var(--danger-light);
    color: var(--danger);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
}

.empty-state p {
    margin-bottom: 1rem;
}

/* ---- Utility ---- */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-center { text-align: center; }
.text-sm { font-size: 0.8125rem; }
.text-muted { color: var(--text-secondary); }
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ---- Responsive ---- */
@media (min-width: 640px) {
    main { padding: 1.5rem; }
    header { padding: 1rem 1.5rem; }
}
