/* ===== TOKENS ===== */
:root {
    --bg:        #0a0a0f;
    --bg2:       #111118;
    --bg3:       #1a1a24;
    --border:    #1e1e2c;
    --border2:   #2a2a3a;
    --text:      #f0f0f0;
    --text2:     #c0c0d0;   /* was #888899 – higher contrast */
    --text3:     #a0a0b0;   /* was #444455 – now readable */
    --accent:    #e8ff6e;
    --accent-bg: rgba(232,255,110,0.08);
    --accent-dim:#b8cc50;
    --green:     #4ade80;
    --red:       #f87171;
    --blue:      #7b8cde;
    --purple:    #a78bfa;
    --radius:    12px;
    --radius-sm: 8px;
    --sidebar-w: 220px;
    --bnav-h:    68px;
    --font-ui:   'Syne', sans-serif;
    --font-mono: 'DM Mono', monospace;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
    height: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    font-size: 16px;  /* base size increased */
}

/* ===== LAYOUT ===== */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.main-wrap {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    padding-bottom: 40px;
}

/* ===== SIDEBAR ===== */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 28px 20px 24px;
    border-bottom: 1px solid var(--border);
}
.brand-mark {
    width: 32px; height: 32px;
    background: var(--accent);
    color: var(--bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
}
.brand-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text);
}
.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.snav-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text2);
    font-family: var(--font-ui);
    font-size: 14px;   /* was 14px – keep, but ensure contrast */
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-align: left;
}
.snav-btn:hover { background: var(--bg3); color: var(--text); }
.snav-btn.active { background: var(--accent-bg); color: var(--accent); }
.snav-btn svg { flex-shrink: 0; opacity: 0.7; }
.snav-btn.active svg { opacity: 1; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}
.sidebar-nw-label {
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text2);  /* was --text3 – now lighter */
    font-family: var(--font-mono);
    margin-bottom: 4px;
}
.sidebar-nw-val {
    font-size: 22px;
    font-weight: 800;
    color: var(--accent);
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
}

/* ===== PAGES ===== */
.page { display: none; padding: 28px 28px 20px; }
.page.active { display: block; }

/* ===== DASHBOARD HEADER ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
}
.page-date {
    font-size: 12px;      /* was 11px */
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text2);
    font-family: var(--font-mono);
    margin-bottom: 6px;
}
.page-nw {
    font-size: 44px;      /* was 40px */
    font-weight: 800;
    color: var(--accent);
    font-family: var(--font-mono);
    letter-spacing: -0.03em;
    line-height: 1;
}
.page-nw-change {
    font-size: 14px;      /* was 13px */
    font-family: var(--font-mono);
    margin-top: 6px;
    min-height: 18px;
}

/* ===== VIEW TABS ===== */
.view-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    flex-shrink: 0;
}
.vtab {
    background: none;
    border: none;
    padding: 6px 12px;
    border-radius: 7px;
    font-family: var(--font-ui);
    font-size: 13px;     /* was 12px */
    font-weight: 600;
    color: var(--text2);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.vtab:hover { color: var(--text); }
.vtab.active { background: var(--accent); color: var(--bg); }

/* ===== ACCOUNT CARDS ===== */
.overview-container { display: flex; flex-direction: column; gap: 12px; }

.account-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s;
    position: relative;
    overflow: hidden;
}
.account-card:hover {
    border-color: var(--border2);
    transform: translateY(-1px);
}
.account-card:active { transform: translateY(0); }

.ac-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.ac-name {
    font-size: 12px;      /* was 11px */
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text2);
    font-family: var(--font-mono);
}
.ac-type-pill {
    font-size: 11px;      /* was 10px */
    padding: 3px 8px;
    border-radius: 20px;
    font-family: var(--font-mono);
    font-weight: 500;
}
.ac-type-bank  { background: rgba(123,140,222,0.2); color: var(--text); }
.ac-type-invest { background: rgba(74,222,128,0.15); color: var(--text); }

.ac-mid {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 14px;
}
.ac-bal {
    font-size: 32px;      /* was 28px */
    font-weight: 800;
    color: var(--text);
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
    line-height: 1;
}
.ac-change {
    font-size: 14px;      /* was 13px */
    font-family: var(--font-mono);
    text-align: right;
}

.sparkline-wrap { height: 40px; position: relative; }
.sparkline-wrap canvas { width: 100% !important; height: 40px !important; }

/* ===== CHART VIEWS ===== */
.chart-view-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.chart-view-title {
    font-size: 12px;      /* was 11px */
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text2);
    font-family: var(--font-mono);
    margin-bottom: 16px;
}
.chart-view-card canvas { max-height: 320px; }

/* ===== SIMPLE PAGE HEADER ===== */
.page-header-simple {
    margin-bottom: 24px;
}
.page-title {
    font-size: 28px;      /* was 24px */
    font-weight: 800;
    color: var(--text);
}
.account-detail-header {
    display: flex;
    align-items: center;
    gap: 14px;
}
.back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text2);
    font-family: var(--font-ui);
    font-size: 14px;      /* was 13px */
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.back-btn:hover { border-color: var(--border2); color: var(--text); }

/* ===== FORM CARD ===== */
.form-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 560px;
}
.field-group { margin-bottom: 18px; }
.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.field-label {
    display: block;
    font-size: 12px;      /* was 11px */
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text2);
    font-family: var(--font-mono);
    margin-bottom: 8px;
}
.field-input {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 16px;      /* was 14px – prevents zoom on mobile */
    outline: none;
    transition: border-color 0.15s;
    -webkit-appearance: none;
    appearance: none;
}
.field-input:focus { border-color: var(--accent); }
.field-input::placeholder { color: var(--text2); opacity: 0.8; }
select.field-input { cursor: pointer; }
input[type="date"].field-input { color-scheme: dark; }

/* ===== TYPE PICKER ===== */
.type-picker {
    display: flex;
    gap: 8px;
}
.type-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text2);
    font-family: var(--font-ui);
    font-size: 14px;      /* was 13px */
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.type-btn:hover { border-color: var(--border2); color: var(--text); }
.type-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.type-icon { font-size: 24px; }   /* was 22px */

/* ===== PRIMARY BUTTON ===== */
.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 16px;      /* was 15px */
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    letter-spacing: 0.01em;
    margin-top: 4px;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.99); }

/* ===== NUMPAD ===== */
.numpad-display {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-family: var(--font-mono);
    font-size: 32px;      /* was 28px */
    font-weight: 500;
    color: var(--accent);
    letter-spacing: -0.02em;
    margin-bottom: 12px;
    min-height: 56px;
    word-break: break-all;
}
.numpad-display::before {
    content: '£';
    font-size: 22px;
    opacity: 0.7;
    vertical-align: middle;
    margin-right: 4px;
    color: var(--text2);
}
.numpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 4px;
}
.nk {
    padding: 16px 0;      /* was 14px */
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 24px;      /* was 18px */
    font-weight: 500;
    cursor: pointer;
    transition: background 0.1s, transform 0.1s;
    text-align: center;
}
.nk:active { background: var(--bg2); transform: scale(0.96); }
.nk-accent { color: var(--text2); font-size: 20px; }

/* ===== ACCOUNT INFO STRIP ===== */
.account-info-strip {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
    background: var(--bg3);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 18px;
}
.info-label {
    font-size: 11px;      /* was 10px – keep small but legible */
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text2);
    font-family: var(--font-mono);
}
.info-val {
    font-size: 14px;      /* was 13px */
    font-family: var(--font-mono);
    color: var(--text);
    font-weight: 500;
}

/* ===== DATA ACTIONS ===== */
.data-hint {
    font-size: 14px;      /* was 13px */
    color: var(--text2);
    line-height: 1.6;
    margin-bottom: 20px;
}
.data-actions { display: flex; flex-direction: column; gap: 10px; }
.data-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg3);
    font-family: var(--font-ui);
    font-size: 15px;      /* was 14px */
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
    text-align: left;
    color: var(--text2);
}
.data-btn:hover { border-color: var(--border2); color: var(--text); }
.data-btn-export { color: var(--green); border-color: rgba(74,222,128,0.2); }
.data-btn-export:hover { border-color: rgba(74,222,128,0.4); }
.data-btn-import { color: var(--blue); border-color: rgba(123,140,222,0.2); }
.data-btn-import:hover { border-color: rgba(123,140,222,0.4); }
.data-btn-clear { color: var(--red); border-color: rgba(248,113,113,0.2); }
.data-btn-clear:hover { border-color: rgba(248,113,113,0.4); }

/* ===== STATS STRIP ===== */
.stats-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}
.stat-item {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}
.stat-label {
    font-size: 11px;      /* was 10px */
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text2);
    font-family: var(--font-mono);
    margin-bottom: 6px;
}
.stat-val {
    font-size: 18px;      /* was 15px */
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
    letter-spacing: -0.01em;
}

/* ===== CHART CARD ===== */
.chart-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.chart-card canvas { max-height: 280px; }

/* ===== HISTORY ===== */
.history-section {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.history-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.history-title {
    font-size: 12px;      /* was 11px */
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text2);
    font-family: var(--font-mono);
}
.history-row {
    display: flex;
    align-items: center;
    padding: 13px 18px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}
.history-row:last-child { border-bottom: none; }
.history-row:hover { background: var(--bg3); }
.history-date {
    font-size: 13px;      /* was 12px */
    color: var(--text2);
    font-family: var(--font-mono);
    width: 90px;
    flex-shrink: 0;
}
.history-bal {
    font-size: 15px;      /* was 14px */
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--text);
    flex: 1;
}
.history-change {
    font-size: 13px;      /* was 12px */
    font-family: var(--font-mono);
    width: 80px;
    text-align: right;
    flex-shrink: 0;
}
.history-del {
    width: 28px;
    height: 28px;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text3);
    font-size: 14px;
    cursor: pointer;
    margin-left: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s;
}
.history-del:hover { border-color: var(--red); color: var(--red); }

/* ===== COLOURS ===== */
.pos { color: var(--green); }
.neg { color: var(--red); }
.neu { color: var(--text2); }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text3);
}
.empty-icon { font-size: 48px; margin-bottom: 14px; }
.empty-title { font-size: 18px; font-weight: 700; color: var(--text2); margin-bottom: 6px; }
.empty-sub { font-size: 14px; line-height: 1.6; color: var(--text2); }

/* ===== BOTTOM NAV (mobile only) ===== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--bnav-h);
    background: var(--bg2);
    border-top: 1px solid var(--border);
    z-index: 200;
    padding: 0 8px;
    align-items: center;
    justify-content: space-around;
}
.bnav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text3);
    font-family: var(--font-ui);
    font-size: 11px;      /* was 10px */
    font-weight: 600;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 10px;
    transition: color 0.15s;
    min-width: 52px;
}
.bnav-btn:hover { color: var(--text2); }
.bnav-btn.active { color: var(--accent); }
.bnav-btn svg { transition: stroke 0.15s; }

.bnav-fab {
    width: 52px;
    height: 52px;
    border-radius: 50% !important;
    background: var(--accent) !important;
    color: var(--bg) !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    box-shadow: 0 4px 20px rgba(232,255,110,0.3);
    min-width: unset;
    gap: 0 !important;
}
.bnav-fab span { display: none; }

/* ===== TOAST ===== */
.toast-area {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 500;
    animation: toastIn 0.25s ease;
    pointer-events: auto;
}
.toast-success { background: rgba(74,222,128,0.15); border: 1px solid rgba(74,222,128,0.3); color: var(--green); }
.toast-error   { background: rgba(248,113,113,0.15); border: 1px solid rgba(248,113,113,0.3); color: var(--red); }
@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-wrap {
        margin-left: 0;
        padding-bottom: calc(var(--bnav-h) + 12px);
    }
    .bottom-nav { display: flex; }

    .page { padding: 20px 16px 12px; }

    .page-nw { font-size: 36px; }

    .view-tabs {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .vtab { padding: 6px 10px; font-size: 12px; }

    .stats-strip { grid-template-columns: repeat(2, 1fr); }

    .field-row { grid-template-columns: 1fr; gap: 0; }

    .form-card { padding: 18px; }

    .ac-bal { font-size: 28px; }

    .toast-area { top: auto; bottom: calc(var(--bnav-h) + 12px); right: 12px; left: 12px; }
    .toast { text-align: center; }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .chart-view-card canvas { max-height: 260px; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* Account card enhancements */
.account-card {
    transition: all 0.2s ease;
}
.account-card:hover {
    transform: translateY(-2px);
    filter: brightness(1.02);
}

/* Colour dot + name alignment */
.ac-top div {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Tinted balance numbers (already set inline, but fallback) */
.ac-bal {
    font-weight: 800;
    text-shadow: 0 0 2px rgba(0,0,0,0.3);
}

/* Make type pills slightly softer */
.ac-type-pill {
    backdrop-filter: blur(2px);
}

/* Allow chart canvas to scroll horizontally if legend is too wide */
.chart-view-card {
    overflow-x: auto;
}

/* Custom legend scroll behaviour */
.custom-legend {
    scrollbar-width: thin;
    scrollbar-color: var(--border2) var(--bg3);
}
.custom-legend::-webkit-scrollbar {
    height: 4px;
    width: 4px;
}
.custom-legend::-webkit-scrollbar-track {
    background: var(--bg3);
}
.custom-legend::-webkit-scrollbar-thumb {
    background: var(--border2);
    border-radius: 4px;
}

/* Vertical scroll legend for distribution chart */
#distLegend {
    scrollbar-width: thin;
    scrollbar-color: var(--border2) var(--bg3);
}
#distLegend::-webkit-scrollbar {
    width: 4px;
}
#distLegend::-webkit-scrollbar-track {
    background: var(--bg3);
    border-radius: 4px;
}
#distLegend::-webkit-scrollbar-thumb {
    background: var(--border2);
    border-radius: 4px;
}