@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
    --ink-navy:    #101E33;
    --ink-navy-2:  #1B3157;
    --paper:       #F1F5EE;      /* pale sage — classic accounting-ledger paper */
    --paper-line:  #C9D6C0;      /* ruled-line green */
    --card:        #FFFFFF;
    --ledger-red:  #A5332A;
    --brass:       #A9822E;
    --text-dark:   #1D2A22;
    --text-muted:  #63705F;
    --shadow:      0 8px 24px rgba(16, 30, 51, 0.10);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background: #b9fe8554;
    color: #0e3b1f;
    -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: 'Fraunces', serif; margin: 0; }

/* ---------------- Login ---------------- */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: var(--ink-navy);
}
.login-card {
    background: var(--card); padding: 48px 40px; border-radius: 4px;
    width: 320px; text-align: center; box-shadow: var(--shadow);
    border-top: 4px solid var(--brass);
}
.login-mark { font-family: 'Fraunces', serif; font-size: 32px; font-weight: 700; letter-spacing: 2px; color: var(--ink-navy); }
.login-sub { font-family: 'IBM Plex Mono', monospace; letter-spacing: 6px; font-size: 12px; color: var(--brass); margin-top: 2px; }
.login-tag { color: var(--text-muted); font-size: 13px; margin: 14px 0 28px; }
.login-form label { display: block; text-align: left; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.login-form input {
    width: 100%; padding: 12px 14px; border: 1px solid var(--paper-line); border-radius: 4px;
    font-size: 16px; margin-bottom: 16px; font-family: 'IBM Plex Mono', monospace; letter-spacing: 4px;
}
.login-form button {
    width: 100%; padding: 12px; border: none; border-radius: 4px; background: var(--ink-navy);
    color: #fff; font-weight: 600; font-size: 14px; cursor: pointer; transition: background .15s;
}
.login-form button:hover { background: var(--ink-navy-2); }
.login-error { background: #FBE9E7; color: var(--ledger-red); font-size: 13px; padding: 8px 12px; border-radius: 4px; margin-bottom: 16px; }

/* ---------------- Shell / Sidebar ---------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px; background: var(--ink-navy); color: #fff; flex-shrink: 0;
    display: flex; flex-direction: column; padding: 28px 0;
}
.sidebar-brand { padding: 0 24px 24px; border-bottom: 1px solid rgba(255,255,255,0.08); margin-bottom: 18px; }
.brand-mark { font-family: 'Fraunces', serif; font-weight: 700; font-size: 22px; letter-spacing: 1px; display: block; }
.brand-sub { font-family: 'IBM Plex Mono', monospace; font-size: 11px; letter-spacing: 4px; color: var(--brass); }

.sidebar-nav { flex: 1; padding: 0 12px; }
.nav-group { margin-bottom: 22px; }
.nav-group-label {
    font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: rgba(255,255,255,0.4);
    padding: 0 12px 8px;
}
.nav-tab {
    display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,0.78);
    text-decoration: none; padding: 10px 12px; border-radius: 6px 2px 2px 6px;
    font-size: 14px; margin-bottom: 2px; position: relative; transition: background .15s, color .15s;
}
.tab-dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,0.35); flex-shrink: 0; }
.nav-tab:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-tab.active { background: var(--paper); color: var(--ink-navy); font-weight: 600; }
.nav-tab.active .tab-dot { background: var(--brass); }

.sidebar-logout {
    margin: 12px 24px 0; color: rgba(255,255,255,0.5); font-size: 13px; text-decoration: none;
    border-top: 1px solid rgba(255,255,255,0.08); padding-top: 16px;
}
.sidebar-logout:hover { color: #fff; }

/* ---------------- Main content ---------------- */
.main { flex: 1; padding: 36px 44px; max-width: 1160px; }
.main-topbar { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 26px; flex-wrap: wrap; gap: 16px; }
.crumb { font-size: 12px; color: #0f2b07; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 4px; }
.main h1 { font-size: 28px; color: var(--ink-navy); }
.topbar-right { display: flex; align-items: center; gap: 20px; }

.total-box { text-align: right; }
.total-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.total-value { font-family: 'IBM Plex Mono', monospace; font-size: 20px; font-weight: 600; color: var(--brass); }

.btn-add {
    background: var(--ink-navy); color: #fff; border: none; padding: 10px 20px; border-radius: 4px;
    font-weight: 600; font-size: 14px; cursor: pointer; transition: background .15s;
}
.btn-add:hover { background: var(--ink-navy-2); }

/* ---------------- Ledger table ---------------- */
.table-wrap { background: #00000036; border-radius: 6px; box-shadow: var(--shadow); overflow-x: auto; }
.ledger-table { width: 100%; border-collapse: collapse; }
.ledger-table thead th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted);
    padding: 14px 18px; border-bottom: 2px solid var(--ink-navy);
}
.ledger-table tbody td {
    padding: 13px 18px; border-bottom: 1px solid var(--paper-line); font-size: 14px; vertical-align: top;
}
.ledger-table tbody tr:last-child td { border-bottom: none; }
.ledger-table tbody tr:hover { background: #FAFBF8; cursor: pointer; }
.ledger-table .num-cell { font-family: 'IBM Plex Mono', monospace; text-align: right; font-weight: 500; }
.ledger-table .actions-cell { text-align: right; white-space: nowrap; }
.loading-row, .empty-row { padding: 24px !important; text-align: center; color: var(--text-muted); font-style: italic; }

.row-edit-btn {
    background: none; border: 1px solid var(--paper-line); color: var(--text-muted); font-size: 12px;
    padding: 5px 10px; border-radius: 4px; cursor: pointer; margin-left: 6px;
}
.row-edit-btn:hover { border-color: var(--ink-navy); color: var(--ink-navy); }

/* ---------------- Dashboard cards ---------------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 32px; }
.dash-card {
    background: #9bf4aa99; border-radius: 6px; padding: 18px 20px; box-shadow: var(--shadow);
    text-decoration: none; color: var(--text-dark); border-left: 3px solid var(--brass); transition: transform .12s;
}
.dash-card:hover { transform: translateY(-2px); }
.dash-card-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.dash-card-available { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-top: 6px; }
.dash-card-value { font-family: 'IBM Plex Mono', monospace; font-size: 22px; font-weight: 600; margin: 6px 0 4px; color: var(--ink-navy); }
.dash-card-count { font-size: 12px; color: var(--text-muted); }

.dash-lower { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.dash-panel { background: #b7c5fd9c; border-radius: 6px; padding: 20px 22px; box-shadow: var(--shadow); }
.dash-panel h2 { font-size: 17px; margin-bottom: 12px; color: var(--ink-navy); }
.dash-list { list-style: none; padding: 0; margin: 0; }
.dash-list li { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--paper-line); font-size: 14px; }
.dash-list li:last-child { border-bottom: none; }
.dash-list-time { font-family: 'IBM Plex Mono', monospace; color: #012525; }
.empty-note { color: var(--text-muted); font-style: italic; font-size: 14px; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(16, 30, 51, 0.45);
    align-items: center; justify-content: center; z-index: 100;
}
.modal-backdrop.open { display: flex; }
.modal { background: #fff; width: 460px; max-width: 92vw; border-radius: 8px; box-shadow: var(--shadow); max-height: 88vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--paper-line); }
.modal-head h2 { font-size: 19px; }
.Bmodal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.form-fields { padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--paper-line); border-radius: 4px; font-size: 14px;
    font-family: 'Inter', sans-serif;
}
.field textarea { min-height: 64px; resize: vertical; }
.modal-actions { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; border-top: 1px solid var(--paper-line); }
.modal-actions-right { display: flex; gap: 10px; }
.btn-cancel { background: none; border: 1px solid var(--paper-line); padding: 9px 16px; border-radius: 4px; cursor: pointer; font-size: 14px; }
.btn-save { background: var(--ink-navy); color: #fff; border: none; padding: 9px 18px; border-radius: 4px; cursor: pointer; font-weight: 600; font-size: 14px; }
.btn-delete { background: none; color: var(--ledger-red); border: 1px solid #EAC7C3; padding: 9px 16px; border-radius: 4px; cursor: pointer; font-size: 14px; }
.btn-delete:hover { background: #FBEEEC; }

/* ---------------- Mobile menu toggle / overlay (hidden on desktop) ---------------- */
.mobile-menu-toggle {
    display: none;
    position: fixed; top: 14px; left: 14px; z-index: 120;
    background: var(--ink-navy); color: #fff; border: none;
    width: 40px; height: 40px; border-radius: 6px;
    font-size: 20px; line-height: 1; cursor: pointer;
}
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0; background: rgba(16, 30, 51, 0.5); z-index: 90;
}
.sidebar-overlay.open { display: block; }

@media (max-width: 760px) {
    .mobile-menu-toggle { display: block; }
    .app-shell { flex-direction: column; }
    .sidebar {
        position: fixed; top: 0; left: 0; z-index: 110;
        width: 240px; height: 100vh;
        transform: translateX(-100%);
        transition: transform .2s ease;
        padding: 64px 0 16px;
        overflow-y: auto;
    }
    .sidebar.open { transform: translateX(0); }
    .main { padding: 20px; padding-top: 70px; max-width: 100%; }
    .main-topbar { flex-direction: column; align-items: flex-start; gap: 12px; }
    .main h1 { font-size: 22px; }

    .topbar-right {
        width: 100%;
        justify-content: flex-start;   /* was space-between */
        flex-wrap: wrap;
        gap: 14px;
    }
    .search-box {
        flex: 1 1 100%;
        order: -1;          /* search bar sits on its own row, above total/add */
    }
    .search-box input {
        width: 100%;
    }
    .search-box input:focus {
        width: 100%;         /* prevent the desktop focus-expand from overflowing */
    }

    .dash-lower { grid-template-columns: 1fr; }
    /* Scroll wide tables horizontally instead of squashing columns */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .ledger-table { min-width: 640px; }
    .ledger-table { width: 100%; border-collapse: collapse; min-width: 720px; }
    .loan-schedule-card { padding: 1rem; }
    .loan-schedule-table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    .loan-schedule-head { flex-direction: column; align-items: flex-start; }
    /* Full-screen modal on small devices */
    .modal-backdrop.open { align-items: stretch; justify-content: stretch; }
    .modal { width: 100%; max-width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
}

.login-links { margin-top: 16px; text-align: center; font-size: 0.85rem; }
.login-links a { color: #555; text-decoration: underline; }
.login-links span { margin: 0 6px; color: #ccc; }
.login-success { background: #e6f7ec; color: #1a7f4b; padding: 10px 14px; border-radius: 8px; font-size: 0.85rem; margin-bottom: 12px; }

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}
.search-box .search-icon {
    position: absolute;
    left: 10px;
    color: #999;
    pointer-events: none;
}
.search-box input {
    padding: 8px 12px 8px 32px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    width: 220px;
    outline: none;
    transition: border-color 0.15s, width 0.15s;
}
.search-box input:focus {
    border-color: #999;
    width: 260px;
}



.module-chart-card{background:#fff;border:1px solid #eee;border-radius:12px;padding:1.25rem 1.5rem;margin-bottom:1rem;}
.module-chart-head{display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:8px;margin-bottom:1rem;}
.module-chart-head strong{font-size:15px;}
.module-chart-head span{font-size:13px;color:#555;}
#module-chart-wrap{
    height:220px;
    max-width:520px;
    margin:0 auto;
}


.period-controls{display:flex;align-items:center;gap:8px;}
.period-filter{padding:8px 12px;border:1px solid #ddd;border-radius:8px;font-size:13px;background:#fff;cursor:pointer;}
.period-filter:disabled{opacity:0.5;cursor:not-allowed;}
.period-filter-alltime{padding:8px 14px;border:1px solid #ddd;border-radius:8px;font-size:13px;background:#fff;cursor:pointer;}
.period-filter-alltime.active{background:#333;color:#fff;border-color:#333;}
.dash-card-period{font-size:11px;color:#999;font-weight:400;}
