/* ==================================================================
 * Bright Energy Billing - staff interface
 * Brand: navy #1F3B73, green #4A9E3F, amber #F2A71B
 * ================================================================== */

:root {
    --navy: #1F3B73;
    --navy-dark: #152a54;
    --navy-soft: #e8eef8;
    --green: #4A9E3F;
    --green-dark: #3a8231;
    --green-soft: #e7f4e4;
    --amber: #F2A71B;
    --amber-soft: #fff4dc;
    --bg: #f3f6fa;
    --card: #ffffff;
    --line: #e2e8f0;
    --text: #1b2433;
    --muted: #667085;
    --danger: #b42318;
    --danger-soft: #fef3f2;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { margin: 0 0 12px; font-size: 15px; color: var(--navy); }

/* --- Top bar ------------------------------------------------------ */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 20px;
    min-height: 58px;
    background: var(--navy);
    color: #e6ecf7;
    border-bottom: 3px solid var(--green);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { background: #fff; border-radius: 50%; padding: 2px; width: 34px; height: auto; }
.brand small { font-weight: 400; color: var(--amber); }

.menu { display: flex; align-items: center; flex: 1; gap: 12px; }
.nav { display: flex; flex-wrap: wrap; gap: 2px; margin-right: auto; }
.nav a { padding: 7px 11px; border-radius: 7px; color: #cfd9ee; font-size: 13.5px; }
.nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; text-decoration: none; }
.nav a.active { background: #fff; color: var(--navy); font-weight: 600; }

.user-box { display: flex; align-items: center; gap: 10px; font-size: 13px; white-space: nowrap; }
.link-btn { background: none; border: 0; padding: 0; color: #cfd9ee; font: inherit; cursor: pointer; }
.link-btn:hover { color: #fff; text-decoration: underline; }

.nav-toggle { display: none; }
.nav-burger { display: none; }

.role {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 7px;
    border-radius: 20px;
    font-size: 10.5px;
    font-style: normal;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.role-admin { background: var(--amber); color: #3d2a00; }
.role-staff { background: var(--green); color: #fff; }

@media (max-width: 1100px) {
    .topbar { flex-wrap: wrap; padding: 8px 14px; }
    .nav-burger { display: flex; flex-direction: column; gap: 4px; margin-left: auto; padding: 10px; cursor: pointer; }
    .nav-burger span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; }
    .menu { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding: 6px 0 10px; }
    .nav-toggle:checked ~ .menu { display: flex; }
    .nav { flex-direction: column; margin: 0; }
    .nav a { padding: 10px 12px; font-size: 15px; }
    .user-box { justify-content: space-between; padding: 10px 12px 0; border-top: 1px solid rgba(255, 255, 255, .15); }
}

/* --- Layout ------------------------------------------------------- */

.wrap { max-width: 1240px; margin: 0 auto; padding: 22px 20px; }
.foot { padding: 16px 20px 36px; color: var(--muted); font-size: 12px; text-align: center; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-title { margin: 0; font-size: 22px; color: var(--text); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.page-title .count { color: var(--muted); font-size: 13px; font-weight: 400; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.head-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.head-tools select { width: auto; max-width: 320px; margin: 0; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
}
.card.narrow { max-width: 620px; }
.narrow-form { max-width: 820px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.two-col { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; align-items: start; }
.two-col.even { grid-template-columns: 1fr 1fr; }
.two-col > .card { margin-bottom: 16px; }
@media (max-width: 960px) { .two-col, .two-col.even { grid-template-columns: 1fr; gap: 0; } }

.action-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
.danger-zone { border-color: #fecdca; }
.danger-zone h2 { color: var(--danger); }

/* --- Stats -------------------------------------------------------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 16px;
    background: var(--card);
    border: 1px solid var(--line);
    border-left: 4px solid var(--navy);
    border-radius: var(--radius);
    color: var(--text);
}
a.stat:hover { text-decoration: none; box-shadow: 0 2px 10px rgba(31, 59, 115, .1); }
.stat-warn { border-left-color: var(--amber); }
.stat-ok { border-left-color: var(--green); }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 12.5px; }

.aging-bars { width: 100%; border-collapse: collapse; }
.aging-bars th { text-align: left; font-weight: 500; color: var(--muted); padding: 6px 10px 6px 0; white-space: nowrap; width: 110px; }
.aging-bars td { padding: 6px 0; }
.aging-bars .bar-cell { width: 60%; padding-right: 12px; }
.bar { display: block; height: 12px; border-radius: 6px; background: var(--green); }
.bar-d1_30 { background: var(--amber); }
.bar-d31_60 { background: #e8830c; }
.bar-d61_90, .bar-d90_plus { background: var(--danger); }
.aging-bars .total-row th, .aging-bars .total-row td { border-top: 1px solid var(--line); font-weight: 700; color: var(--text); padding-top: 9px; }

/* --- Tables ------------------------------------------------------- */

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid thead th { background: #f7f9fc; font-size: 11.5px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); white-space: nowrap; }
.grid tfoot th { background: #f7f9fc; font-size: 13px; }
.grid tbody tr:hover { background: #fafbfd; }
.grid .r, .r { text-align: right; }
.strong { font-weight: 700; }
.big { font-size: 18px; }
.grid .empty, .empty { text-align: center; color: var(--muted); padding: 24px; }
.mono { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-line; }
.danger-text { color: var(--danger); }
.r-float { float: right; }
.row-void td { color: #98a2b3; }
.row-void td a { color: #98a2b3; text-decoration: line-through; }
.row-inactive { opacity: .6; }
.actions-col { white-space: nowrap; text-align: right; }
.actions-col .btn, .actions-col form { margin-left: 4px; }
.inline { display: inline; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
    white-space: nowrap;
    vertical-align: middle;
    background: #eef1f5;
    color: #475467;
}
.badge-draft { background: #eef1f5; color: #475467; }
.badge-sent, .badge-issued { background: var(--navy-soft); color: var(--navy); }
.badge-accepted, .badge-paid, .badge-valid, .badge-converted { background: var(--green-soft); color: #25611d; }
.badge-partially_paid { background: var(--amber-soft); color: #8a5a00; }
.badge-overdue, .badge-rejected, .badge-void { background: var(--danger-soft); color: var(--danger); }
.badge-expired { background: #f2f4f7; color: #667085; }

.kv { border-collapse: collapse; width: 100%; }
.kv th { text-align: left; padding: 6px 16px 6px 0; color: var(--muted); font-weight: 500; vertical-align: top; white-space: nowrap; width: 1%; }
.kv td { padding: 6px 0; vertical-align: top; }

.doc-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .doc-summary { grid-template-columns: 1fr; } }

/* --- Buttons ------------------------------------------------------ */

.btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid #d0d7e2;
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 13.5px;
    line-height: 1.3;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}
.btn:hover { background: #f4f6fa; text-decoration: none; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-xs { padding: 3px 8px; font-size: 12px; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); }
.btn-ok { background: var(--green); border-color: var(--green); color: #fff; }
.btn-ok:hover { background: var(--green-dark); }
.btn-danger { border-color: #fecdca; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }

/* --- Forms -------------------------------------------------------- */

label { display: block; margin-bottom: 12px; font-size: 13px; color: #344054; font-weight: 500; }
label small { display: block; margin-top: 3px; color: var(--muted); font-weight: 400; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=email], input[type=tel], input[type=file], select, textarea {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid #d0d7e2;
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 14px;
}
input[type=file] { padding: 6px; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(31, 59, 115, .15); border-color: var(--navy); }
input[readonly] { background: #f4f6fa; color: var(--muted); }
textarea { resize: vertical; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: auto; margin: 0; }

.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 16px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid .wide { grid-column: span 2; }
@media (max-width: 900px) { .form-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .form-grid, .form-grid.cols-2 { grid-template-columns: 1fr; } .form-grid .wide { grid-column: auto; } }

.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.sticky-actions { position: sticky; bottom: 0; z-index: 5; padding: 12px 0; background: linear-gradient(to top, var(--bg) 70%, rgba(243, 246, 250, 0)); }

.filters { display: flex; flex-wrap: wrap; gap: 0 14px; align-items: flex-end; }
.filters label { flex: 1 1 160px; }
.filters label.grow { flex: 1 1 320px; }
.filter-actions { display: flex; gap: 8px; margin-bottom: 12px; }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px; }
.flash ul { margin: 6px 0 0 18px; padding: 0; }
.flash-success { background: var(--green-soft); color: #1f5319; border: 1px solid #b7deb0; }
.flash-error { background: var(--danger-soft); color: #7a271a; border: 1px solid #fecdca; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }
.warn-text { background: var(--amber-soft); border: 1px solid #f7d58b; color: #6b4600; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.denied-title { color: var(--danger); margin-top: 0; }

/* --- Document editor ---------------------------------------------- */

.items-table td { vertical-align: top; }
.items-table input, .items-table textarea { margin-top: 0; }
.items-table .line-no { padding-top: 16px; color: var(--muted); }
.items-table .line-no::after { content: attr(data-n); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.col-item { width: 36px; }
.col-qty { width: 80px; }
.col-unit { width: 84px; }
.col-num { width: 120px; }
.col-x { width: 34px; }
.line-total { display: inline-block; padding-top: 9px; font-weight: 700; font-variant-numeric: tabular-nums; }
.row-remove {
    width: 28px;
    height: 28px;
    margin-top: 5px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--danger);
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}
.row-remove:hover { background: var(--danger-soft); }

@media (max-width: 760px) {
    .items-table thead { display: none; }
    .items-table, .items-table tbody, .items-table tr, .items-table td { display: block; width: 100%; }
    .items-table tr.item-row { position: relative; border: 1px solid var(--line); border-radius: 8px; padding: 10px 10px 4px; margin-bottom: 10px; }
    .items-table td { border: 0; padding: 3px 0; }
    .items-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11.5px; color: var(--muted); }
    .items-table td.line-no { display: none; }
    .items-table td.col-x { position: absolute; top: 4px; right: 6px; width: auto; }
    .items-table td.r { text-align: left; }
}

.totals-card { display: flex; gap: 24px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.words-box { flex: 1 1 380px; }
.words {
    display: block;
    margin-top: 4px;
    padding: 9px 11px;
    border: 1px dashed #c9d3e3;
    border-radius: 8px;
    background: #f8fafd;
    font-weight: 600;
    letter-spacing: .2px;
}
.totals { border-collapse: collapse; min-width: 260px; }
.totals.full { width: 100%; }
.totals th { text-align: right; padding: 7px 12px; color: var(--muted); font-weight: 500; }
.totals td { text-align: right; padding: 7px 12px; border-bottom: 1px solid var(--line); min-width: 120px; font-variant-numeric: tabular-nums; }
.totals tr.grand th, .totals tr.grand td { font-size: 17px; font-weight: 700; color: var(--navy); }
.totals tr.balance th, .totals tr.balance td { color: var(--green-dark); }

.alloc-cell { display: flex; gap: 6px; align-items: center; min-width: 170px; }
.alloc-cell input { margin: 0; }

.logo-row { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.logo-preview { width: 90px; height: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; }

/* --- Feeds, logs, reports ----------------------------------------- */

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; overflow: hidden; }
.feed li:last-child { border-bottom: 0; }
.feed-action { font-weight: 600; text-transform: capitalize; }
.feed-ref { color: var(--navy); margin-left: 6px; }
.feed-meta { display: block; color: var(--muted); font-size: 12px; }

.logs td { font-size: 13px; }
.act { display: inline-block; padding: 2px 8px; border-radius: 20px; background: #eef1f5; color: #344054; font-size: 11.5px; text-transform: capitalize; white-space: nowrap; }
.act-invoice_created, .act-quote_created, .act-payment_recorded, .act-invoice_issued, .act-customer_created { background: var(--green-soft); color: #1f5319; }
.act-invoice_updated, .act-quote_updated, .act-customer_updated, .act-settings_updated, .act-user_updated { background: var(--navy-soft); color: var(--navy); }
.act-invoice_voided, .act-payment_voided, .act-invoice_deleted, .act-quote_deleted, .act-access_denied, .act-login_failed, .act-login_blocked { background: var(--danger-soft); color: var(--danger); }
.changes { list-style: none; margin: 0; padding: 0; }
.changes li { padding: 2px 0; font-size: 12.5px; }
.fname { font-weight: 600; }
.from { color: #b42318; text-decoration: line-through; }
.arrow { color: var(--muted); margin: 0 5px; }
.to { color: #25611d; font-weight: 600; }
.details { max-width: 520px; word-break: break-word; }

.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin: 14px 0 4px; color: var(--muted); font-size: 13px; }

.legend { font-size: 12px; color: var(--muted); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 10px; vertical-align: middle; }
.sw-inv, .hbar-inv { background: var(--navy); }
.sw-col, .hbar-col { background: var(--green); }
.bars-col { width: 45%; min-width: 140px; }
.hbar { display: block; height: 7px; border-radius: 4px; margin: 3px 0; }

.doc-copies { list-style: none; margin: 0; padding: 0; }
.doc-copies li { padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.doc-copies li:last-child { border-bottom: 0; }

/* --- Sign in / install -------------------------------------------- */

.login-bg {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, var(--navy) 0%, #24497f 55%, var(--green) 140%);
}
.login-card {
    width: 100%;
    max-width: 380px;
    padding: 30px 28px;
    background: #fff;
    border-radius: 14px;
    border-top: 4px solid var(--amber);
    box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.install-card { max-width: 480px; }
.login-logo { display: block; margin: 0 auto 10px; }
.login-card h1 { margin: 0 0 4px; font-size: 19px; text-align: center; color: var(--navy); }
.login-card .sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; text-align: center; }
.login-card .ok { color: var(--green-dark); margin: 5px 0; }
code { background: #f1f4f9; padding: 1px 6px; border-radius: 4px; font-family: Consolas, monospace; }
