/* === Custom Properties === */
:root {
    --bg: #fff;
    --surface: rgba(0,0,0,0.03);
    --surface-hover: rgba(0,0,0,0.06);
    --border: rgba(0,0,0,0.08);
    --text: #111;
    --text-secondary: #666;
    --text-muted: #999;
    --income: #1a7a2f;
    --expense: #b91c1c;
    --btn-bg: rgba(0,0,0,0.05);
    --btn-hover: rgba(0,0,0,0.10);
    --glass: rgba(255,255,255,0.6);
    --glass-border: rgba(0,0,0,0.06);
    --blur: blur(20px);
    --qr-dark: #111;
    --qr-light: #fff;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000;
        --surface: rgba(255,255,255,0.04);
        --surface-hover: rgba(255,255,255,0.08);
        --border: rgba(255,255,255,0.08);
        --text: #eee;
        --text-secondary: #888;
        --text-muted: #555;
        --income: #4ade80;
        --expense: #f87171;
        --btn-bg: rgba(255,255,255,0.06);
        --btn-hover: rgba(255,255,255,0.12);
        --glass: rgba(255,255,255,0.05);
        --glass-border: rgba(255,255,255,0.08);
        --qr-dark: #eee;
        --qr-light: #000;
    }
}

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

/* === Base === */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--text); }

/* === Nav === */
nav {
    background: var(--glass);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border-bottom: 1px solid var(--glass-border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    margin-left: 1.5rem;
    font-size: 0.85rem;
}
.nav-links a:hover { color: var(--text); }

/* === Layout === */
main {
    max-width: 1200px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

h2 { margin-bottom: 1rem; color: var(--text); font-weight: 600; }
h3 { color: var(--text); font-weight: 600; }
.section-heading { margin-top: 2rem; margin-bottom: 0.75rem; }

/* === Glass Card === */
.glass {
    background: var(--glass);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
}

/* === Filters === */
.filters {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--glass);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
}
.filter-form {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}
.filter-form label { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-label { cursor: pointer; }

/* === Table === */
.table-container { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    background: transparent;
}
th, td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.balance { font-weight: 600; }

tr:hover { background: var(--surface-hover); }
tr.voided { opacity: 0.4; text-decoration: line-through; }
tr.income-row td.num { color: var(--income); }
tr.expense-row td.num { color: var(--expense); }
tr.voided td.num { color: var(--text-muted); }

td.empty { text-align: center; color: var(--text-muted); padding: 2rem; }

/* === Tags === */
.tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    margin-right: 0.25rem;
    font-weight: 500;
}

/* Light mode tag palette */
.tag-0  { background: #dcfce7; color: #166534; }
.tag-1  { background: #ede9fe; color: #5b21b6; }
.tag-2  { background: #ffedd5; color: #9a3412; }
.tag-3  { background: #dbeafe; color: #1e40af; }
.tag-4  { background: #fce7f3; color: #9d174d; }
.tag-5  { background: #fef9c3; color: #854d0e; }
.tag-6  { background: #cffafe; color: #155e75; }
.tag-7  { background: #fee2e2; color: #991b1b; }
.tag-8  { background: #fef3c7; color: #92400e; }
.tag-9  { background: #e0f2fe; color: #075985; }
.tag-10 { background: #fce7f3; color: #831843; }
.tag-11 { background: #ecfccb; color: #3f6212; }
.tag-12 { background: #f3e8ff; color: #6b21a8; }
.tag-13 { background: #fff7ed; color: #9a3412; }
.tag-14 { background: #e0f2fe; color: #0369a1; }
.tag-15 { background: #fff7ed; color: #b45309; }

@media (prefers-color-scheme: dark) {
    .tag-0  { background: rgba(74,222,128,0.15); color: #4ade80; }
    .tag-1  { background: rgba(167,139,250,0.15); color: #a78bfa; }
    .tag-2  { background: rgba(251,146,60,0.15); color: #fb923c; }
    .tag-3  { background: rgba(96,165,250,0.15); color: #60a5fa; }
    .tag-4  { background: rgba(244,114,182,0.15); color: #f472b6; }
    .tag-5  { background: rgba(250,204,21,0.15); color: #facc15; }
    .tag-6  { background: rgba(34,211,238,0.15); color: #22d3ee; }
    .tag-7  { background: rgba(248,113,113,0.15); color: #f87171; }
    .tag-8  { background: rgba(251,191,36,0.15); color: #fbbf24; }
    .tag-9  { background: rgba(125,211,252,0.15); color: #7dd3fc; }
    .tag-10 { background: rgba(232,121,249,0.15); color: #e879f9; }
    .tag-11 { background: rgba(163,230,53,0.15); color: #a3e635; }
    .tag-12 { background: rgba(196,181,253,0.15); color: #c4b5fd; }
    .tag-13 { background: rgba(253,186,116,0.15); color: #fdba74; }
    .tag-14 { background: rgba(125,211,252,0.15); color: #7dd3fc; }
    .tag-15 { background: rgba(251,191,36,0.15); color: #fbbf24; }
}

/* === Buttons === */
button, .btn-primary {
    background: var(--btn-bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.4rem 1rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    transition: background 0.15s;
    text-decoration: none;
}
button:hover, .btn-primary:hover { background: var(--btn-hover); }

.btn-small {
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
}
.btn-void {
    background: rgba(185,28,28,0.08);
    border-color: rgba(185,28,28,0.15);
    color: var(--expense);
}
.btn-void:hover { background: rgba(185,28,28,0.15); }
.btn-restore {
    background: var(--btn-bg);
    border-color: var(--border);
}
.btn-restore:hover { background: var(--btn-hover); }

.btn-full { width: 100%; text-align: center; padding: 0.6rem 1rem; font-size: 1rem; }
.btn-nostr { background: var(--btn-bg); border-color: var(--border); }
.btn-nostr:hover { background: var(--btn-hover); }

.btn-clear {
    background: var(--btn-bg);
    border-color: var(--border);
    text-decoration: none;
    color: var(--text);
    display: inline-block;
}
.btn-clear:hover { background: var(--btn-hover); }

.btn-invoice {
    text-decoration: none;
    display: inline-block;
    font-weight: 600;
}

.btn-secondary-action { background: var(--btn-bg); }
.btn-secondary-action:hover { background: var(--btn-hover); }

.btn-link {
    background: var(--btn-bg);
    border-color: var(--border);
    text-decoration: none;
    color: var(--text);
    display: inline-block;
}
.btn-link:hover { background: var(--btn-hover); }

.inline-form { display: inline; }

/* === Forms === */
.transaction-form, .export-form, .invoice-form {
    background: var(--glass);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 600px;
}
.invoice-form { margin-bottom: 1rem; }

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}
.form-row label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    flex: 1;
    color: var(--text-secondary);
    font-size: 0.85rem;
}
.button-row { gap: 0.5rem; }

input, select {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    font-size: 0.9rem;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--text-muted);
    box-shadow: 0 0 0 2px var(--surface-hover);
}

/* === Rate Preview === */
.rate-preview {
    margin-bottom: 1rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    min-height: 1.5rem;
}

/* === Login === */
.login-container {
    max-width: 320px;
    margin: 15vh auto;
    text-align: center;
}
.login-container h1 {
    margin-bottom: 1.5rem;
    color: var(--text);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.error { color: var(--expense); margin-bottom: 0.5rem; }
.success { color: var(--income); margin-bottom: 0.5rem; }

.login-section { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }

/* === Passkey Prompt === */
.passkey-prompt {
    max-width: 400px;
    margin: 10vh auto;
    text-align: center;
}
.passkey-prompt h2 { margin-bottom: 0.75rem; }
.passkey-prompt p { color: var(--text-secondary); margin-bottom: 1.5rem; line-height: 1.5; }
.prompt-actions { display: flex; flex-direction: column; gap: 0.75rem; }

/* === Actions === */
.actions { white-space: nowrap; }

/* === Filter Summary === */
.filter-summary {
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    font-size: 0.85rem;
    background: var(--glass);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--glass-border);
}
.filter-summary.balanced { border-color: rgba(26,122,47,0.2); }
.filter-summary.imbalanced { border-color: rgba(185,28,28,0.2); }

@media (prefers-color-scheme: dark) {
    .filter-summary.balanced { border-color: rgba(74,222,128,0.2); }
    .filter-summary.imbalanced { border-color: rgba(248,113,113,0.2); }
}

.summary-count { color: var(--text-muted); }
.summary-detail { color: var(--text-secondary); }
.summary-balance { font-weight: 600; margin-left: auto; }
.balanced .summary-balance { color: var(--income); }
.imbalanced .summary-balance { color: var(--expense); }

/* === Tag Filters === */
.tag-filters { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.tag-chip { cursor: pointer; display: inline-flex; align-items: center; }
.tag-chip input[type="checkbox"] { display: none; }
.tag-chip .tag { opacity: 0.4; transition: opacity 0.15s; }
.tag-chip.active .tag,
.tag-chip:hover .tag { opacity: 1; }
.tag-chip input:checked + .tag {
    opacity: 1;
    outline: 1px solid var(--text-muted);
    outline-offset: 1px;
}

a.tag { text-decoration: none; cursor: pointer; }
a.tag:hover { opacity: 0.7; }

/* === Invoice CTA === */
.invoice-cta {
    margin-bottom: 1rem;
    display: flex;
    justify-content: flex-end;
}

/* === Notice === */
.notice {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    color: var(--text-secondary);
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

@media (prefers-color-scheme: dark) {
    .modal-overlay { background: rgba(0,0,0,0.7); }
}

.modal-content {
    background: var(--glass);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    position: relative;
    text-align: center;
}
.modal-close {
    position: absolute;
    top: 0.5rem; right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
}
.modal-close:hover { color: var(--text); }
.modal-details { margin: 1rem 0; }
.modal-amount {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--income);
}
.modal-payee { color: var(--text-secondary); margin-top: 0.25rem; }

.qr-container {
    display: flex;
    justify-content: center;
    margin: 1.25rem 0;
}
.qr-container img { border-radius: 8px; }

.modal-link { margin: 0.75rem 0; }
.modal-link a {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.modal-copy {
    display: flex;
    gap: 0.5rem;
    margin: 0.75rem 0;
}
.modal-copy input {
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.modal-status { margin-top: 1rem; }

/* === Status Badges === */
.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.status-badge.pending { background: rgba(251,191,36,0.12); color: #b45309; }
.status-badge.settled { background: rgba(26,122,47,0.12); color: var(--income); }
.status-badge.expired { background: var(--surface); color: var(--text-muted); }

@media (prefers-color-scheme: dark) {
    .status-badge.pending { background: rgba(251,191,36,0.12); color: #fbbf24; }
    .status-badge.settled { background: rgba(74,222,128,0.12); color: #4ade80; }
}
