/* Secure Client Portal - visual system on top of Bootstrap 5.
   Brand color comes from /brand.css (admin setting). */

:root {
    --brand: #1f4e79;
    --brand-dark: #163856;
    --brand-rgb: 31, 78, 121;
    --ink: #17212b;
    --ink-soft: #4a5866;
    --line: #e2e7ec;
    --surface: #ffffff;
    --canvas: #f3f5f8;
    --radius: .6rem;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow: 0 2px 6px rgba(16, 24, 40, .06), 0 10px 24px -12px rgba(16, 24, 40, .12);
    --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --bs-body-color: var(--ink);
    --bs-border-color: var(--line);
}

body { color: var(--ink); font-size: .9375rem; }
h1, .h1 { font-size: 1.55rem; font-weight: 650; letter-spacing: -.01em; }
h2, .h2 { font-size: 1.15rem; font-weight: 650; }
h3, .h3 { font-size: 1rem; font-weight: 650; }
a { text-underline-offset: .15em; }
.skip-link { position: absolute; left: 1rem; top: .5rem; z-index: 2000; background: #fff; padding: .5rem 1rem; border-radius: .4rem; box-shadow: var(--shadow); }
:focus-visible { outline: 3px solid rgba(var(--brand-rgb), .45); outline-offset: 2px; }

.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-dark); --bs-btn-active-border-color: var(--brand-dark); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-bg: var(--brand-dark); --bs-btn-active-border-color: var(--brand-dark); }
.text-brand { color: var(--brand) !important; }
.bg-brand-subtle { background: rgba(var(--brand-rgb), .08) !important; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--brand-rgb), .6); box-shadow: 0 0 0 .2rem rgba(var(--brand-rgb), .18); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-label { font-weight: 550; font-size: .875rem; margin-bottom: .3rem; }
.form-text { font-size: .8rem; }
.required::after { content: " *"; color: #b42318; }

.brand-mark { display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: .5rem; background: var(--brand); color: #fff; font-size: 1rem; flex: 0 0 auto; }
.avatar { display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: rgba(var(--brand-rgb), .14); color: var(--brand); font-weight: 700; font-size: .75rem; margin-right: .35rem; }
.user-menu { display: inline-flex; align-items: center; border: 1px solid var(--line); }

/* ---------- Cards, tables, badges ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-header { background: transparent; border-bottom: 1px solid var(--line); padding: .85rem 1.1rem; font-weight: 650; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.card-header .h2, .card-header h2 { margin: 0; font-size: 1rem; }
.card-body { padding: 1.1rem; }
.table { --bs-table-hover-bg: rgba(var(--brand-rgb), .035); margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .6rem .75rem; vertical-align: middle; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); font-weight: 650; background: #f8fafb; border-bottom-color: var(--line); white-space: nowrap; }
.table-responsive { border-radius: 0 0 var(--radius) var(--radius); }
.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { color: var(--brand); }
.status-badge { font-weight: 600; font-size: .72rem; letter-spacing: .01em; padding: .35em .6em; }
.text-bg-warning { color: #5c3d00 !important; background-color: #fde9b3 !important; }
.text-bg-success { color: #0b4d2a !important; background-color: #c9efd8 !important; }
.text-bg-danger { color: #7a1610 !important; background-color: #fbd3cf !important; }
.text-bg-secondary { color: #3b4652 !important; background-color: #e3e8ee !important; }
.text-bg-info { color: #0b3f5c !important; background-color: #cfe9f7 !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.ref { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; font-weight: 600; letter-spacing: .02em; }
dl.kv { display: grid; grid-template-columns: minmax(8rem, 35%) 1fr; gap: .45rem 1rem; margin: 0; }
dl.kv dt { color: var(--ink-soft); font-weight: 500; font-size: .85rem; }
dl.kv dd { margin: 0; word-break: break-word; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--ink-soft); }
.empty-state i { font-size: 2rem; color: #a3afbb; display: block; margin-bottom: .5rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .lead-sub { color: var(--ink-soft); margin: .25rem 0 0; font-size: .9rem; }
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 10rem; }
.stat { display: flex; align-items: center; gap: .9rem; padding: 1rem 1.1rem; height: 100%; text-decoration: none; color: inherit; }
a.stat:hover { background: rgba(var(--brand-rgb), .03); }
.stat .stat-icon { width: 2.6rem; height: 2.6rem; border-radius: .6rem; display: grid; place-items: center; font-size: 1.2rem; background: rgba(var(--brand-rgb), .1); color: var(--brand); flex: 0 0 auto; }
.stat .stat-icon.warn { background: #fdf0cf; color: #8a5a00; }
.stat .stat-icon.danger { background: #fde1de; color: #a3241a; }
.stat .stat-value { font-size: 1.45rem; font-weight: 700; line-height: 1.1; }
.stat .stat-label { font-size: .8rem; color: var(--ink-soft); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 .9rem 1.4rem; border-left: 2px solid var(--line); margin-left: .4rem; }
.timeline li::before { content: ""; position: absolute; left: -.42rem; top: .25rem; width: .75rem; height: .75rem; border-radius: 50%; background: #fff; border: 2px solid var(--brand); }
.timeline li.failure::before, .timeline li.denied::before { border-color: #b42318; }
.timeline li:last-child { padding-bottom: 0; }
.steps { display: flex; gap: .5rem; flex-wrap: wrap; list-style: none; padding: 0; margin: 0 0 1rem; counter-reset: step; }
.steps li { flex: 1 1 9rem; padding: .6rem .75rem; border-radius: .5rem; background: #f1f4f7; font-size: .8rem; color: var(--ink-soft); border: 1px solid transparent; }
.steps li strong { display: block; color: var(--ink); font-size: .85rem; }
.steps li.done { background: #e4f5ea; color: #155a33; }
.steps li.current { background: #fff; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(var(--brand-rgb), .12); }
.steps li.failed { background: #fde8e6; color: #8a1c13; }
.callout { border-left: 4px solid var(--brand); background: rgba(var(--brand-rgb), .05); padding: .85rem 1rem; border-radius: 0 .5rem .5rem 0; }
.callout.warn { border-left-color: #d29a00; background: #fff8e6; }
.callout.danger { border-left-color: #b42318; background: #fff1ef; }
.code-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.05rem; }
.code-grid span { background: #f3f5f8; border: 1px dashed #c7d0d9; border-radius: .4rem; padding: .45rem; text-align: center; letter-spacing: .08em; }
.preview-frame { width: 100%; height: 75vh; min-height: 420px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.preview-img { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: var(--radius); display: block; margin: 0 auto; }
.qr { width: 200px; height: 200px; border: 1px solid var(--line); border-radius: .5rem; padding: .25rem; background: #fff; }
.perm-grid { columns: 2 18rem; column-gap: 2rem; }
.perm-grid .perm-group { break-inside: avoid; margin-bottom: 1rem; }
.small-muted { font-size: .8rem; color: var(--ink-soft); }
details.disclosure > summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.btn-group-actions { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ---------- Admin shell ---------- */
.admin-body { background: var(--canvas); }
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar { width: 264px; flex: 0 0 264px; background: #0f1d2b; color: #c9d4df; display: flex; flex-direction: column; }
@media (min-width: 992px) {
    .admin-sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; visibility: visible !important; transform: none !important; }
}
@media (max-width: 991.98px) {
    .admin-sidebar { --bs-offcanvas-width: 280px; --bs-offcanvas-bg: #0f1d2b; }
}
.sidebar-brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.1rem 1rem; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.sidebar-brand .brand-name { color: #fff; font-weight: 650; line-height: 1.2; }
.sidebar-brand .brand-sub { font-size: .75rem; color: #8ea0b2; }
.sidebar-nav { padding: .6rem .6rem 1.5rem; display: flex; flex-direction: column; gap: 1px; }
.sidebar-nav .nav-heading { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #74879a; padding: 1rem .7rem .35rem; font-weight: 650; }
.sidebar-nav .nav-item { display: flex; align-items: center; gap: .65rem; padding: .5rem .7rem; color: #c9d4df; text-decoration: none; border-radius: .45rem; font-size: .875rem; }
.sidebar-nav .nav-item i { font-size: 1rem; width: 1.1rem; text-align: center; color: #8ea0b2; }
.sidebar-nav .nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-nav .nav-item.active { background: var(--brand); color: #fff; }
.sidebar-nav .nav-item.active i { color: #fff; }
.admin-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.admin-topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: .75rem; padding: .65rem 1.5rem; background: rgba(255, 255, 255, .92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.topbar-search { align-items: center; gap: .5rem; position: relative; flex: 0 1 26rem; }
.topbar-search i { position: absolute; left: .65rem; color: #8a96a3; font-size: .85rem; }
.topbar-search input { padding-left: 2rem; background: #f3f5f8; border-color: transparent; }
.admin-content { padding: 1.5rem; flex: 1 1 auto; max-width: 1400px; width: 100%; }
.admin-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; padding: 1rem 1.5rem; font-size: .75rem; color: #7a8794; border-top: 1px solid var(--line); }
@media (max-width: 575.98px) { .admin-content { padding: 1rem; } .admin-topbar { padding: .6rem 1rem; } }

/* ---------- Client portal ---------- */
.portal-body { background: var(--canvas); display: flex; flex-direction: column; min-height: 100vh; }
.portal-header { background: #fff; border-bottom: 1px solid var(--line); }
.portal-header .navbar { padding: .65rem 0; }
.portal-brand { display: flex; align-items: center; gap: .6rem; font-weight: 650; font-size: 1.02rem; color: var(--ink); }
.portal-header .nav-link { color: var(--ink-soft); font-weight: 550; padding: .5rem .8rem !important; border-radius: .4rem; }
.portal-header .nav-link:hover { color: var(--brand); }
.portal-header .nav-link.active { color: var(--brand); background: rgba(var(--brand-rgb), .08); }
.portal-content { padding-top: 1.75rem; padding-bottom: 2.5rem; flex: 1 0 auto; }
.portal-footer { font-size: .8rem; color: #6b7785; padding: 1.25rem 0; border-top: 1px solid var(--line); background: #fff; }
.welcome { background: linear-gradient(120deg, var(--brand) 0%, var(--brand-dark) 100%); color: #fff; border-radius: var(--radius); padding: 1.4rem 1.5rem; box-shadow: var(--shadow); }
.welcome .profile-number { display: inline-flex; gap: .5rem; align-items: center; background: rgba(255, 255, 255, .14); border-radius: 2rem; padding: .25rem .8rem; font-size: .85rem; }
.doc-row { display: flex; align-items: center; gap: .9rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line); }
.doc-row:last-child { border-bottom: 0; }
.doc-row .doc-icon { font-size: 1.5rem; color: var(--brand); flex: 0 0 auto; }
.doc-row .doc-main { flex: 1 1 auto; min-width: 0; }
.doc-row .doc-title { font-weight: 600; color: var(--ink); text-decoration: none; display: block; overflow-wrap: anywhere; }
.doc-row .doc-title:hover { color: var(--brand); text-decoration: underline; }
.doc-row .doc-meta { font-size: .8rem; color: var(--ink-soft); }
.doc-row .doc-actions { display: flex; gap: .4rem; flex: 0 0 auto; }
@media (max-width: 575.98px) { .doc-row { flex-wrap: wrap; } .doc-row .doc-actions { width: 100%; justify-content: flex-end; } }

/* ---------- Guest pages ---------- */
.guest-body { background: radial-gradient(1200px 600px at 10% -10%, rgba(var(--brand-rgb), .18), transparent 60%), var(--canvas); min-height: 100vh; }
.guest-main { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem 1rem; }
.guest-card { width: 100%; max-width: 430px; background: #fff; border: 1px solid var(--line); border-radius: .8rem; box-shadow: var(--shadow); padding: 2rem; }
.guest-card-wide { max-width: 720px; }
.guest-brand { display: flex; align-items: center; gap: .65rem; font-weight: 650; font-size: 1.05rem; margin-bottom: 1.5rem; }
.guest-foot { font-size: .78rem; color: #6b7785; margin-top: 1.25rem; text-align: center; }
.error-code { font-size: 3rem; font-weight: 800; color: rgba(var(--brand-rgb), .25); line-height: 1; margin-bottom: .5rem; }
.pin-input { font-size: 1.6rem; letter-spacing: .5em; text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; max-width: 16rem; }

@media print {
    .admin-sidebar, .admin-topbar, .admin-footer, .portal-header, .portal-footer, .btn, form { display: none !important; }
    .admin-content, .portal-content { padding: 0; }
    .card { box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.mw-640 { max-width: 640px; }
.mw-760 { max-width: 760px; }
.settings-nav { top: 5rem; }
.text-pre { white-space: pre-line; }
/* Bootstrap makes .offcanvas-lg transparent at >= lg; keep the sidebar dark. */
.admin-sidebar.offcanvas-lg { background-color: #0f1d2b !important; color: #c9d4df; }
.ref { white-space: nowrap; }
@media (min-width: 992px) { .admin-shell { background: linear-gradient(to right, #0f1d2b 264px, transparent 264px); } }
.doc-row .doc-main { flex: 1 1 0; }
@media (max-width: 575.98px) { .doc-row .doc-actions { flex-basis: 100%; } }

/* ---------- Company logo ---------- */
.brand-logo { display: block; width: auto; height: auto; object-fit: contain; }
.brand-logo-chip { display: inline-flex; align-items: center; justify-content: center; background: #fff; border-radius: .45rem; padding: .3rem .45rem; flex: 0 0 auto; max-width: 9.5rem; }
.brand-logo-chip .brand-logo { max-height: 2.1rem; max-width: 100%; }
.brand-logo-portal { max-height: 2.25rem; max-width: 11rem; }
.brand-logo-guest { max-height: 3rem; max-width: 14rem; }
.guest-brand-logo-only { justify-content: center; }
.guest-brand-logo-only .brand-logo-guest { max-height: 4rem; max-width: 18rem; }
.logo-preview-wrap { display: flex; flex-direction: column; gap: .5rem; }
.logo-preview { display: flex; align-items: center; justify-content: center; width: 15rem; height: 5rem; border-radius: .5rem; border: 1px solid var(--line); padding: .6rem; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-preview-light { background: #fff; }
.logo-preview-dark { background: #0f1d2b; border-color: #0f1d2b; }
.logo-preview-dark img { background: #fff; border-radius: .35rem; padding: .25rem .35rem; }
.logo-preview-empty { flex-direction: column; gap: .3rem; color: #6b7785; font-size: .8rem; background: #f6f8fa; border-style: dashed; text-align: center; }
.logo-preview-empty i { font-size: 1.4rem; }
.logo-actions { min-width: 16rem; }
@media (max-width: 575.98px) { .logo-preview { width: 100%; } }

/* ---------- Invoicing ---------- */
.stat .stat-money { font-size: 1.15rem; }
.line-table .col-desc { min-width: 16rem; }
.line-table .col-qty { width: 7rem; }
.line-table .col-price { width: 9.5rem; }
.line-table .col-tax { width: 12rem; }
.line-table .col-amount { width: 8rem; }
.line-table .col-x { width: 2.75rem; }
.line-table textarea { resize: vertical; min-height: 2.1rem; }
.totals-preview td { padding: .15rem 0 .15rem 1.5rem; }
.invoice-sheet { background: #fff; }
.invoice-sheet .inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.invoice-sheet .inv-meta td { padding: .1rem .75rem .1rem 0; font-size: .85rem; }
.invoice-sheet .inv-meta td:first-child { color: var(--ink-soft); }
.invoice-totals { margin-left: auto; min-width: 18rem; }
.invoice-totals td { padding: .3rem .5rem; }
.invoice-totals .grand td { border-top: 2px solid var(--brand); font-weight: 700; font-size: 1.05rem; }
.balance-box { border-radius: var(--radius); padding: 1rem 1.25rem; background: rgba(var(--brand-rgb), .06); border: 1px solid rgba(var(--brand-rgb), .18); }
.balance-box .amount { font-size: 1.6rem; font-weight: 750; line-height: 1.1; }
.pay-option { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; background: #fff; }
.pay-option h3 { font-size: 1rem; margin: 0 0 .35rem; display: flex; align-items: center; gap: .5rem; }
.bank-details td { padding: .2rem .9rem .2rem 0; vertical-align: top; }
.bank-details td:first-child { color: var(--ink-soft); white-space: nowrap; }
.pay-ref { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.05rem; font-weight: 700; letter-spacing: .04em; }
.epc-qr { width: 9.5rem; height: 9.5rem; border: 1px solid var(--line); border-radius: .5rem; background: #fff; padding: .25rem; }
.outstanding-banner { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: center; }
.test-mode { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; }
@media (max-width: 575.98px) { .invoice-sheet .inv-parties { grid-template-columns: 1fr; } .invoice-totals { min-width: 0; width: 100%; } }
.bank-details .mono { font-size: .9rem; }
.cn-line { max-width: 60%; }
.ledger .ledger-head td { background: var(--bs-tertiary-bg); border-top: 2px solid var(--bs-border-color); }
/* Company manual */
.manual-toc { top: 5rem; max-height: calc(100vh - 6rem); overflow-y: auto; }
.manual-toc .list-group-item.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.manual-body { font-size: 1rem; line-height: 1.65; max-width: 52rem; }
.manual-body h2 { font-size: 1.45rem; margin: 2rem 0 .75rem; padding-top: .5rem; border-top: 1px solid var(--bs-border-color); scroll-margin-top: 5rem; }
.manual-section:first-of-type h2 { border-top: 0; margin-top: 0; padding-top: 0; }
.manual-body h3 { font-size: 1.1rem; margin-top: 1.5rem; }
.manual-body ul, .manual-body ol { padding-left: 1.4rem; }
.manual-body li { margin-bottom: .3rem; }
.manual-body code { font-size: .9em; }
.manual-table { font-size: .92rem; }
.manual-table th { background: var(--bs-tertiary-bg); }
.manual-figure { margin: 1.25rem 0; }
.manual-figure img { max-width: 100%; height: auto; border: 1px solid var(--bs-border-color); border-radius: .4rem; background: #fff; }
.manual-figure figcaption { font-size: .82rem; color: var(--bs-secondary-color); margin-top: .35rem; }
@media print { .manual-section { display: block !important; } .manual { border: 0; } .admin-sidebar, .admin-topbar, footer { display: none !important; } }
.designer-credit { color: inherit; opacity: .85; }
.designer-credit a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.guest-credit { margin-top: .25rem; }
