/* ── Design Tokens ───────────────────────────────────────────────────────── */
:root {
    --brand:    #4F46E5;
    --brand-bg: #EEF2FF;
    --ink1:     #0F172A;
    --ink2:     #334155;
    --ink3:     #64748B;
    --canvas:   #F8FAFC;
    --surface:  #FFFFFF;
    --border:   #E2E8F0;
    --positive: #059669;
    --negative: #DC2626;

    --acct-a-color: #2563EB; --acct-a-bg: #EFF6FF;
    --acct-l-color: #EA580C; --acct-l-bg: #FFF7ED;
    --acct-e-color: #7C3AED; --acct-e-bg: #F5F3FF;
    --acct-r-color: #059669; --acct-r-bg: #F0FDF4;
    --acct-x-color: #E11D48; --acct-x-bg: #FFF1F2;
}

/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; overflow: hidden; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    color: var(--ink1);
    background: var(--canvas);
    -webkit-font-smoothing: antialiased;
}
input, select, button, textarea { font-family: inherit; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink3); }

/* ── App Shell ───────────────────────────────────────────────────────────── */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}
.main-content {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
    background: var(--canvas);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    flex-shrink: 0;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px 14px;
    border-bottom: 1px solid var(--border);
}
.logo-icon {
    width: 28px; height: 28px;
    border-radius: 7px;
    background: var(--brand);
    color: #fff;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.logo-name { font-size: 14px; font-weight: 700; color: var(--ink1); letter-spacing: -0.02em; line-height: 1.2; }
.logo-sub  { font-size: 10px; color: var(--ink3); }
.sidebar-nav {
    flex: 1;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow-y: auto;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 400;
    color: var(--ink2);
    text-decoration: none;
    transition: background 0.1s;
}
.sidebar-nav a:hover { background: var(--canvas); color: var(--ink1); }
.sidebar-nav a.active {
    background: var(--brand-bg);
    color: var(--brand);
    font-weight: 600;
}
.nav-icon { font-size: 15px; width: 16px; text-align: center; opacity: 0.6; flex-shrink: 0; }
.sidebar-nav a.active .nav-icon { opacity: 1; }
.sidebar-bottom {
    padding: 12px;
    border-top: 1px solid var(--border);
}
.btn-new-tx {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 7px 14px;
    border-radius: 6px;
    background: var(--brand);
    color: #fff;
    font-size: 13px; font-weight: 500;
    border: none; cursor: pointer;
    text-decoration: none;
    transition: background 0.12s;
}
.btn-new-tx:hover { background: #4338CA; color: #fff; }
.nav-user { margin-top: 8px; display: flex; flex-direction: column; gap: 1px; }
.nav-link-btn {
    display: flex; align-items: center; gap: 9px;
    padding: 7px 10px; border-radius: 6px;
    font-size: 13px; font-weight: 400; color: var(--ink2);
    background: none; border: none; cursor: pointer; width: 100%; text-align: left;
    transition: background 0.1s;
}
.nav-link-btn:hover { background: var(--canvas); color: var(--ink1); }

/* ── Page content ────────────────────────────────────────────────────────── */
.page-body { padding: 28px 32px; }
.page-title {
    font-size: 20px; font-weight: 700; color: var(--ink1);
    letter-spacing: -0.01em; margin: 0 0 20px;
}
.page-title-row {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 20px;
}
.page-title-row .page-title { margin-bottom: 0; }

/* ── LC Card ─────────────────────────────────────────────────────────────── */
.lc-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.lc-card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.lc-card-header-title { font-size: 13px; font-weight: 600; color: var(--ink1); }
.lc-card-body { padding: 20px 24px; }

/* ── Balance Cards ───────────────────────────────────────────────────────── */
.balance-cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.balance-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    display: flex; flex-direction: column; gap: 6px;
}
.balance-card-label {
    display: flex; align-items: center; justify-content: space-between;
}
.balance-card-label span:first-child {
    font-size: 12px; font-weight: 500; color: var(--ink3); letter-spacing: 0.02em;
}
.balance-card-code {
    font-size: 10px; font-weight: 700;
    border-radius: 4px; padding: 1px 5px; color: #fff;
}
.balance-card-value {
    font-family: 'JetBrains Mono', monospace;
    font-variant-numeric: tabular-nums;
    font-size: 20px; font-weight: 600;
    color: var(--ink1); letter-spacing: -0.03em;
}

/* ── Net Worth Hero ──────────────────────────────────────────────────────── */
.networth-hero {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 28px 32px;
    margin-bottom: 20px;
}
.networth-label {
    font-size: 12px; font-weight: 500; color: var(--ink3);
    letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 6px;
}
.networth-value {
    font-family: 'JetBrains Mono', monospace;
    font-variant-numeric: tabular-nums;
    font-size: 42px; font-weight: 700;
    color: var(--ink1); letter-spacing: -0.04em; line-height: 1;
}
.networth-delta {
    margin-top: 8px;
    font-size: 14px; font-weight: 600;
}
.networth-delta.positive { color: var(--positive); }
.networth-delta.negative { color: var(--negative); }

/* ── LC Table ────────────────────────────────────────────────────────────── */
.lc-table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.lc-table {
    width: 100%;
    border-collapse: collapse;
}
.lc-table th {
    font-size: 11px; font-weight: 600; color: var(--ink3);
    letter-spacing: 0.05em; text-transform: uppercase;
    padding: 9px 16px;
    background: var(--canvas);
    border-bottom: 1px solid var(--border);
    text-align: left; white-space: nowrap;
}
.lc-table th.right { text-align: right; }
.lc-table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--ink1); font-size: 13px;
    vertical-align: middle;
}
.lc-table tbody tr:last-child td { border-bottom: none; }
.lc-table tbody tr { cursor: default; transition: background 0.1s; }
.lc-table tbody tr:hover { background: var(--canvas); }
.lc-table td.right { text-align: right; }
.lc-table td.mono {
    font-family: 'JetBrains Mono', monospace;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
}
.lc-table .text-muted2 { font-size: 11px; color: var(--ink3); }

/* ── Account Type Badges ─────────────────────────────────────────────────── */
.acct-badge {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border-radius: 4px;
    font-size: 10px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.acct-badge-lg {
    width: 24px; height: 24px; font-size: 12px;
}
.acct-A { background: var(--acct-a-color); }
.acct-L { background: var(--acct-l-color); }
.acct-E { background: var(--acct-e-color); }
.acct-R { background: var(--acct-r-color); }
.acct-X { background: var(--acct-x-color); }

.type-row-A { background: var(--acct-a-bg) !important; }
.type-row-L { background: var(--acct-l-bg) !important; }
.type-row-E { background: var(--acct-e-bg) !important; }
.type-row-R { background: var(--acct-r-bg) !important; }
.type-row-X { background: var(--acct-x-bg) !important; }

/* ── Status Pills ────────────────────────────────────────────────────────── */
.pill {
    display: inline-block;
    padding: 2px 8px; border-radius: 99px;
    font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
    border: 1px solid; white-space: nowrap;
}
.pill-posted    { background: #F0FDF4; color: #059669; border-color: #BBF7D0; }
.pill-pending   { background: #FFFBEB; color: #D97706; border-color: #FDE68A; }
.pill-skipped   { background: var(--canvas); color: var(--ink3); border-color: var(--border); }
.pill-duplicate { background: #FFF1F2; color: #E11D48; border-color: #FECDD3; }
.pill-imported  { background: #EFF6FF; color: #2563EB; border-color: #BFDBFE; }
.pill-active    { background: #F0FDF4; color: #059669; border-color: #BBF7D0; }
.pill-inactive  { background: var(--canvas); color: var(--ink3); border-color: var(--border); }

/* ── Instrument Badge ────────────────────────────────────────────────────── */
.instrument-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px; font-weight: 600;
    color: var(--ink1); background: var(--canvas);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 1px 6px; letter-spacing: 0.05em;
}
.type-badge-fiat   { font-size: 11px; font-weight: 600; color: #2563EB; background: #2563EB18; padding: 2px 7px; border-radius: 4px; }
.type-badge-stock  { font-size: 11px; font-weight: 600; color: #7C3AED; background: #7C3AED18; padding: 2px 7px; border-radius: 4px; }
.type-badge-crypto { font-size: 11px; font-weight: 600; color: #EA580C; background: #EA580C18; padding: 2px 7px; border-radius: 4px; }

/* ── Money ───────────────────────────────────────────────────────────────── */
.money {
    font-family: 'JetBrains Mono', monospace;
    font-variant-numeric: tabular-nums;
    font-size: 13px; white-space: nowrap;
}
.money-positive { color: var(--positive); }
.money-negative { color: var(--negative); }
.money-neutral  { color: var(--ink2); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.lc-btn {
    display: inline-flex; align-items: center; gap: 6px;
    border-radius: 6px; font-family: 'Inter', sans-serif;
    font-weight: 500; cursor: pointer; border: none;
    transition: background 0.12s; white-space: nowrap;
    text-decoration: none;
}
.lc-btn-md { font-size: 13px; padding: 7px 14px; }
.lc-btn-sm { font-size: 12px; padding: 5px 10px; }
.lc-btn-primary { background: var(--brand); color: #fff; }
.lc-btn-primary:hover { background: #4338CA; color: #fff; }
.lc-btn-secondary {
    background: var(--surface); color: var(--ink2);
    border: 1px solid var(--border);
}
.lc-btn-secondary:hover { background: var(--canvas); color: var(--ink1); }
.lc-btn-ghost { background: transparent; color: var(--ink2); }
.lc-btn-ghost:hover { background: var(--canvas); color: var(--ink1); }
.lc-btn-danger { background: var(--negative); color: #fff; }
.lc-btn-danger:hover { background: #B91C1C; color: #fff; }
.lc-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Form controls ───────────────────────────────────────────────────────── */
.lc-input {
    font-family: 'Inter', sans-serif; font-size: 13px;
    padding: 7px 10px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--ink1);
    outline: none; width: 100%;
}
.lc-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,0.08); }
.lc-input.mono { font-family: 'JetBrains Mono', monospace; }
.lc-select {
    font-family: 'Inter', sans-serif; font-size: 13px;
    padding: 7px 10px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--ink1);
    outline: none; width: 100%; cursor: pointer;
}
.lc-select:focus { border-color: var(--brand); }
.lc-label {
    font-size: 11px; font-weight: 600; color: var(--ink3);
    letter-spacing: 0.05em; text-transform: uppercase;
    display: block; margin-bottom: 4px;
}

/* ── Posting rows ────────────────────────────────────────────────────────── */
.posting-header {
    display: grid;
    grid-template-columns: 1fr 110px 110px 110px;
    gap: 8px; padding: 6px 16px;
    background: #F0F4FF;
    border-bottom: 1px solid var(--border);
}
.posting-header span {
    font-size: 10px; font-weight: 600; color: var(--ink3);
    letter-spacing: 0.06em; text-transform: uppercase;
}
.posting-header span.right { text-align: right; }
.posting-row {
    display: grid;
    grid-template-columns: 1fr 110px 110px 110px;
    gap: 8px; padding: 7px 16px;
    background: #FAFBFC;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.posting-row:last-child { border-bottom: none; }
.posting-actions {
    display: flex; gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--canvas);
}
.acct-chip {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 12px;
}
.acct-chip-name { color: var(--ink2); font-weight: 500; }

/* ── Section header ──────────────────────────────────────────────────────── */
.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 12px;
}
.section-title { font-size: 13px; font-weight: 600; color: var(--ink1); }

/* ── Divider ─────────────────────────────────────────────────────────────── */
.lc-divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ── Error / Alert ───────────────────────────────────────────────────────── */
.lc-alert-error {
    background: #FFF1F2; border: 1px solid #FECDD3; color: #BE123C;
    border-radius: 8px; padding: 12px 16px; font-size: 13px;
    margin-bottom: 16px;
}

/* ── Loading / Empty ─────────────────────────────────────────────────────── */
.lc-loading, .lc-empty {
    padding: 40px 20px; text-align: center;
    font-size: 13px; color: var(--ink3);
}

/* ── Expand toggle ───────────────────────────────────────────────────────── */
.expand-toggle {
    font-size: 11px; color: var(--ink3);
    text-align: right; cursor: pointer; user-select: none;
}
.expand-toggle.open { color: var(--brand); }
.expanded-row-bg { background: #FAFBFF !important; }

/* ── Collapse toggle row ─────────────────────────────────────────────────── */
.type-group-row {
    cursor: pointer; transition: opacity 0.1s;
}
.type-group-row:hover { opacity: 0.85; }
.type-group-row td { font-weight: 600; padding: 9px 16px; }
.toggle-arrow { font-size: 11px; color: var(--ink3); margin-right: 6px; }

/* ── Blazor error + loading ──────────────────────────────────────────────── */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    box-sizing: border-box; display: none;
    left: 0; padding: .6rem 1.25rem .7rem 1.25rem;
    position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.loading-progress {
    position: absolute; display: block;
    width: 8rem; height: 8rem;
    inset: 20vh 0 auto 0; margin: 0 auto;
}
.loading-progress circle {
    fill: none; stroke: #e0e0e0; stroke-width: .6rem;
    transform-origin: 50% 50%; transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: var(--brand);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray .05s ease-in-out;
}
.loading-progress-text {
    position: absolute; text-align: center; font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto .2rem;
}
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }

/* ── Data sources cards ──────────────────────────────────────────────────── */
.source-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 20px;
    display: flex; align-items: center; gap: 16px;
    margin-bottom: 12px;
}
.source-icon {
    width: 40px; height: 40px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 13px;
    font-family: 'JetBrains Mono', monospace; flex-shrink: 0;
}
.source-info { flex: 1; min-width: 0; }
.source-name { font-size: 14px; font-weight: 600; color: var(--ink1); }
.source-meta { font-size: 12px; color: var(--ink3); margin-top: 2px; }
.source-status-connected {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 600;
    background: #F0FDF4; color: var(--positive); border: 1px solid #BBF7D0;
}
.source-status-manual {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 600;
    background: var(--canvas); color: var(--ink3); border: 1px solid var(--border);
}
.source-dashed {
    border: 2px dashed var(--border); border-radius: 10px;
    padding: 24px; text-align: center; cursor: pointer;
    background: var(--canvas); font-size: 13px; color: var(--ink3); font-weight: 500;
    transition: border-color 0.1s;
}
.source-dashed:hover { border-color: var(--brand); color: var(--brand); }

/* ── Auth pages ──────────────────────────────────────────────────────────── */
.auth-container {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--canvas); padding: 24px;
}
.auth-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 36px 40px;
    width: 100%; max-width: 400px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}
.auth-logo {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 24px;
}
.auth-card h2 {
    font-size: 20px; font-weight: 700; color: var(--ink1);
    margin: 0 0 20px; letter-spacing: -0.01em;
}
.form-group { margin-bottom: 14px; }
.form-group label {
    font-size: 11px; font-weight: 600; color: var(--ink3);
    letter-spacing: 0.05em; text-transform: uppercase;
    display: block; margin-bottom: 4px;
}
.form-control {
    font-family: 'Inter', sans-serif; font-size: 13px;
    padding: 8px 10px; width: 100%;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--ink1); outline: none;
}
.form-control:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,0.08); }
.auth-card .btn-primary {
    display: block; width: 100%; padding: 9px 14px; margin-top: 6px;
    background: var(--brand); color: #fff;
    font-size: 13px; font-weight: 600; border: none; border-radius: 6px;
    cursor: pointer; transition: background 0.12s;
}
.auth-card .btn-primary:hover { background: #4338CA; }
.auth-card .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-divider {
    text-align: center; font-size: 12px; color: var(--ink3);
    margin: 16px 0; position: relative;
}
.auth-divider::before, .auth-divider::after {
    content: ''; position: absolute; top: 50%; width: 44%; height: 1px;
    background: var(--border);
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }
.btn-social {
    display: flex; align-items: center; justify-content: center;
    width: 100%; padding: 8px 14px; margin-bottom: 8px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--ink2);
    font-size: 13px; font-weight: 500; text-decoration: none;
    transition: background 0.1s;
}
.btn-social:hover { background: var(--canvas); color: var(--ink1); }
.auth-footer { text-align: center; font-size: 12px; color: var(--ink3); margin-top: 16px; margin-bottom: 0; }
.auth-footer a { color: var(--brand); text-decoration: none; font-weight: 500; }
.alert { padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; }
.alert-error { background: #FFF1F2; border: 1px solid #FECDD3; color: #BE123C; }

/* ── Retrieve inline form ────────────────────────────────────────────────── */
.retrieve-form {
    background: var(--canvas); border-top: 1px solid var(--border);
    border-radius: 0 0 10px 10px;
    padding: 16px 20px; display: flex; align-items: flex-end; gap: 12px;
    flex-wrap: wrap;
}
