:root {
    --black: #0d0d0d;
    --black-soft: #171717;
    --panel: #1c1c1c;
    --gold: #d4af37;
    --gold-light: #f0d879;
    --gold-dark: #a9822b;
    --white: #f5f5f0;
    --muted: #b3aa96;
    --danger: #c0392b;
    --success: #2e8b57;
    --border: #3a331f;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--black);
    color: var(--white);
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    min-height: 100vh;
}

a { color: var(--gold-light); text-decoration: none; }
a:hover { color: var(--gold); text-decoration: underline; }

/* ===================== App shell (sidebar + main area) ===================== */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #141414 0%, #0d0d0d 100%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px;
    border-bottom: 1px solid var(--border);
}
.sidebar-logo { height: 44px; width: 44px; border-radius: 50%; flex-shrink: 0; }
.sidebar-title { color: var(--gold); font-weight: 700; font-size: 15px; line-height: 1.3; }
.sidebar-subtitle { color: var(--muted); font-size: 11px; margin-top: 2px; }

.sidebar-nav { padding: 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-section {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
    padding: 14px 10px 6px;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--white);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.12s;
}
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--muted); }
.sidebar-link:hover { background: rgba(212,175,55,0.08); text-decoration: none; }
.sidebar-link.active { background: rgba(212,175,55,0.14); color: var(--gold); font-weight: 700; }
.sidebar-link.active svg { color: var(--gold); }

.sidebar-date-widget {
    margin: 10px 12px 16px;
    padding: 12px 14px;
    background: #1a1a1a;
    border: 1px solid var(--gold-dark);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-date-widget svg { width: 20px; height: 20px; color: var(--gold); flex-shrink: 0; }
.sidebar-date-label { color: var(--gold); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.sidebar-date-value { color: var(--white); font-weight: 700; font-size: 14px; margin-top: 2px; }
.sidebar-date-day { color: var(--muted); font-size: 11px; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 99; }
.sidebar-backdrop.open { display: block; }
.sidebar-toggle { display: none; background: none; border: none; color: var(--gold); cursor: pointer; padding: 6px; }
.sidebar-toggle svg { width: 24px; height: 24px; }

.main-area { flex: 1; margin-left: 260px; display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }

.app-topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 14px 28px;
    background: #141414;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.topbar-spacer { flex: 1; }
.topbar-date, .topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-date svg, .topbar-user svg { width: 20px; height: 20px; color: var(--gold); }
.topbar-date-value, .topbar-user-name { font-size: 13px; font-weight: 600; color: var(--white); }
.topbar-date-day, .topbar-user-role { font-size: 11px; color: var(--muted); }
.topbar-divider { width: 1px; height: 32px; background: var(--border); }

.content { max-width: 1200px; margin: 0 auto; padding: 30px 28px 60px; width: 100%; }

.app-footer {
    text-align: center;
    color: var(--muted);
    padding: 18px;
    border-top: 1px solid var(--border);
    font-size: 13px;
}
.app-footer a { color: var(--gold-light); }

.btn-logout {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--gold);
    color: var(--black) !important;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 13px;
}
.btn-logout svg { width: 16px; height: 16px; }
.btn-logout:hover { background: var(--gold-light); text-decoration: none; }

h1, h2, h3 { color: var(--gold); }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 24px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border-radius: 8px;
    overflow: hidden;
}
thead { background: #262016; }
th, td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
th { color: var(--gold); text-transform: uppercase; font-size: 12px; letter-spacing: 0.5px; }
tbody tr:hover { background: #232016; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
}
.badge-active { background: rgba(46,139,87,0.2); color: #6fcf97; border: 1px solid var(--success); }
.badge-inactive { background: rgba(192,57,43,0.2); color: #e57368; border: 1px solid var(--danger); }
.badge-admin { background: rgba(212,175,55,0.15); color: var(--gold); border: 1px solid var(--gold-dark); }
.badge-staff { background: rgba(179,170,150,0.15); color: var(--muted); border: 1px solid var(--border); }
.badge-accounts { background: rgba(179,170,150,0.15); color: var(--muted); border: 1px solid var(--border); }
.badge-warning { background: rgba(212,175,55,0.15); color: var(--gold-light); border: 1px solid var(--gold-dark); }
.badge-expired { background: rgba(192,57,43,0.25); color: #ff8a80; border: 1px solid var(--danger); }
.badge-income { background: rgba(46,139,87,0.2); color: #6fcf97; border: 1px solid var(--success); }
.badge-expense { background: rgba(192,57,43,0.2); color: #e57368; border: 1px solid var(--danger); }
.badge-transfer { background: rgba(212,175,55,0.15); color: var(--gold-light); border: 1px solid var(--gold-dark); }

.actions a, .actions button {
    margin-right: 8px;
    font-size: 13px;
}

.btn {
    display: inline-block;
    background: var(--gold);
    color: var(--black);
    border: none;
    padding: 9px 18px;
    border-radius: 5px;
    font-weight: 700;
    cursor: pointer;
    font-size: 14px;
}
.btn:hover { background: var(--gold-light); }
.btn-secondary {
    background: transparent;
    color: var(--gold);
    border: 1px solid var(--gold-dark);
}
.btn-secondary:hover { background: rgba(212,175,55,0.1); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { background: #e05a4a; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 4px; }

form.inline { display: inline; }

.form-group { margin-bottom: 16px; }
label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 14px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=date], select {
    width: 100%;
    padding: 10px 12px;
    background: #141414;
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--white);
    font-size: 14px;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(212,175,55,0.18);
}

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }

.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 18px;
    font-size: 14px;
}
.alert-success { background: rgba(46,139,87,0.15); border: 1px solid var(--success); color: #6fcf97; }
.alert-error { background: rgba(192,57,43,0.15); border: 1px solid var(--danger); color: #e57368; }

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, #1a1a1a 0%, #0d0d0d 70%);
}
.login-box {
    background: var(--panel);
    border: 1px solid var(--gold-dark);
    border-radius: 10px;
    padding: 36px;
    width: 100%;
    max-width: 380px;
    text-align: center;
    box-shadow: 0 0 40px rgba(212,175,55,0.08);
}
.login-box .logo { height: 90px; width: 90px; margin-bottom: 14px; border-radius: 50%; }
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box .tagline { color: var(--muted); font-size: 13px; margin-bottom: 24px; letter-spacing: 1px; }
.login-box .btn { width: 100%; padding: 11px; margin-top: 6px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

/* Modal dialog (used by the Ledger module and any future "create" popups) */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.72);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal-backdrop.open { display: flex; }

.modal-card {
    background: #141414;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 26px 28px 28px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 50px rgba(0,0,0,0.5);
}
.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
}
.modal-head h2 { margin: 0; font-size: 19px; color: var(--white); }
.modal-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
}
.modal-close:hover { color: var(--white); }
.required-mark { color: var(--gold); margin-left: 2px; }
.field-hint {
    font-size: 12px;
    color: var(--muted);
    margin: -12px 0 16px;
}
.modal-card .btn { width: 100%; padding: 11px; margin-top: 4px; }

.page-subtitle { color: var(--muted); margin: -14px 0 24px; font-size: 14px; }

.txn-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 26px;
}
.txn-tab {
    background: #141414;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 12px;
    text-align: center;
    cursor: pointer;
    color: var(--muted);
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    user-select: none;
}
.txn-tab svg { width: 22px; height: 22px; margin-bottom: 8px; }
.txn-tab-label { font-weight: 600; font-size: 14px; }
.txn-tab:hover { border-color: var(--gold-dark); }
.txn-tab.active.tab-income { background: rgba(46,139,87,0.12); border-color: var(--success); color: #6fcf97; }
.txn-tab.active.tab-expense { background: rgba(192,57,43,0.12); border-color: var(--danger); color: #e57368; }
.txn-tab.active.tab-transfer { background: rgba(212,175,55,0.12); border-color: var(--gold-dark); color: var(--gold-light); }

.btn svg { width: 16px; height: 16px; vertical-align: -3px; margin-right: 6px; }

.amount-income { color: #6fcf97; font-weight: 600; }
.amount-expense { color: #e57368; font-weight: 600; }
.amount-transfer { color: var(--gold-light); font-weight: 600; }

/* ===================== Dashboard ===================== */

.section-label {
    color: var(--gold);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin: 28px 0 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.section-label:first-of-type { margin-top: 10px; }

.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 8px;
}
.overview-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 22px 18px;
    text-align: center;
}
.overview-icon {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
}
.overview-icon svg { width: 24px; height: 24px; }
.overview-icon-gold { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.06); }
.overview-icon-green { background: var(--success); color: #fff; }
.overview-icon-red { background: var(--danger); color: #fff; }

.overview-title { font-size: 13px; font-weight: 700; color: var(--white); text-transform: uppercase; letter-spacing: 0.3px; }
.overview-subtitle { font-size: 12px; color: var(--muted); margin-top: 3px; }
.overview-divider { width: 40px; height: 1px; background: var(--border); margin: 14px auto; }
.overview-value { font-size: 26px; font-weight: 800; }
.overview-value-gold { color: var(--gold); }
.overview-value-green { color: #6fcf97; }
.overview-value-red { color: #ff8a80; }
.overview-unit { font-size: 11px; color: var(--muted); margin-top: 2px; }

.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 8px;
}
.quick-action {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    color: var(--white);
    text-decoration: none;
    transition: border-color 0.15s;
}
.quick-action:hover { border-color: var(--gold-dark); text-decoration: none; }
.quick-action-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: rgba(212,175,55,0.12);
    color: var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.quick-action-icon svg { width: 18px; height: 18px; }
.quick-action-label { flex: 1; font-size: 13px; font-weight: 600; }
.quick-action-chevron { color: var(--muted); font-size: 20px; }

/* ===================== Journal Entry ===================== */

table.journal-table { margin-top: 4px; }
.journal-table th, .journal-table td { padding: 8px 8px; }
.journal-table input, .journal-table select {
    padding: 8px 10px;
    font-size: 13px;
    min-width: 0;
}
.journal-table .jrow-ledger { min-width: 200px; }
.jrow-delete-cell { width: 36px; text-align: center; }
.jrow-delete {
    background: none;
    border: 1px solid var(--danger);
    color: #e57368;
    border-radius: 5px;
    width: 28px;
    height: 28px;
    line-height: 1;
    font-size: 16px;
    cursor: pointer;
}
.jrow-delete:hover { background: rgba(192,57,43,0.15); }

.journal-summary {
    display: flex;
    gap: 28px;
    justify-content: flex-end;
    align-items: center;
    margin: 18px 0;
    padding: 14px 18px;
    background: #141414;
    border-radius: 8px;
    border: 1px solid var(--border);
    flex-wrap: wrap;
}
.summary-item { text-align: right; }
.summary-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.summary-value { font-size: 19px; font-weight: 700; color: var(--white); }
.balance-ok { color: #6fcf97; }
.balance-error { color: #ff8a80; }

.journal-entry-details {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
}
.journal-entry-details summary {
    padding: 14px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    background: #171717;
    list-style: none;
}
.journal-entry-details summary::-webkit-details-marker { display: none; }
.journal-entry-details summary::marker { content: ""; }
.journal-entry-details[open] summary { border-bottom: 1px solid var(--border); }
.journal-entry-lines-table { margin: 0; border-radius: 0; }
.journal-entry-lines-table th, .journal-entry-lines-table td { padding: 9px 16px; }

/* ===================== Responsive ===================== */

@media (max-width: 768px) {
    .content { padding: 20px 14px 50px; }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-area { margin-left: 0; }
    .sidebar-toggle { display: block; }
}

@media (max-width: 640px) {
    .app-topbar { padding: 10px 14px; gap: 10px; }
    .topbar-date { display: none; } /* saves space on phones; business date is still visible at the top of the sidebar */
    .topbar-user-role { display: none; }
    .btn-logout { padding: 6px 12px; font-size: 12px; }
    .btn-logout span { display: none; } /* icon-only logout button on very small screens */

    .content { padding: 16px 10px 40px; }
    .card { padding: 16px; border-radius: 6px; }
    h1 { font-size: 22px; }
    .page-subtitle { margin-top: -10px; }
    .section-label { margin: 20px 0 10px; }

    table { font-size: 13px; }
    th, td { padding: 9px 10px; }
    .actions a, .actions button { display: inline-block; margin: 2px 6px 2px 0; }

    .txn-tabs { gap: 8px; }
    .txn-tab { padding: 12px 4px; border-radius: 8px; }
    .txn-tab svg { width: 18px; height: 18px; margin-bottom: 5px; }
    .txn-tab-label { font-size: 11px; }

    .form-row { grid-template-columns: 1fr; gap: 0; }
    .page-head { align-items: stretch; }
    .page-head form { flex-wrap: wrap; }
    .page-head form input[type=text] { min-width: 0; flex: 1 1 auto; }

    .modal-card { padding: 20px 16px 22px; max-width: 100%; }
    .login-box { padding: 24px 20px; }
    .login-box .logo { height: 70px; width: 70px; }

    .journal-table .jrow-ledger { min-width: 140px; }
    .journal-summary { justify-content: space-between; gap: 12px; padding: 12px; }
    .summary-value { font-size: 16px; }
    .journal-entry-details summary { padding: 12px; font-size: 13px; }

    .overview-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
    .overview-card { padding: 16px 12px; }
    .overview-icon { width: 42px; height: 42px; margin-bottom: 10px; }
    .overview-icon svg { width: 18px; height: 18px; }
    .overview-value { font-size: 20px; }
    .quick-actions { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 400px) {
    .txn-tab-label { font-size: 10px; }
    .overview-value { font-size: 17px; }
    .btn { padding: 9px 14px; font-size: 13px; }
}
