/*
 * Shared page components (2026-09 UX audit, phase 1).
 * Built from the Open Invoices redesign so every page can use the same pieces:
 *   page header with actions, link-style secondary action, KPI tile row,
 *   pinned action bar, empty state, status badge.
 * Loaded after custom.css. Everything is opt-in by class name, so a page only
 * changes when it is moved onto these classes on purpose.
 */

:root {
    --hb-brand: #F07024;
    --hb-ink: #2f2b3d;
    --hb-muted: #6f6b7d;
    --hb-border: #e6e3eb;
    --hb-surface: #fff;
    --hb-danger: #EA5455;
    --hb-success: #28C76F;
    --hb-warning: #FF9F43;
    --hb-info: #00CFE8;
    --hb-shadow-raised: 0 6px 24px rgba(47, 43, 61, 0.18);
}

/* ---- Keyboard focus: visible on every button and link (was removed site-wide) ---- */
.btn:focus-visible,
a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
.form-check-input:focus-visible {
    outline: 2px solid var(--hb-brand);
    outline-offset: 2px;
}

/* ---- Page header: title on the left, secondary actions on the right ---- */
.hb-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

/* Same look as the older .headingh4 so migrated and unmigrated pages match. */
.hb-page-title {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 600;
    color: #272727;
}

.hb-page-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

/* ---- Link-style secondary action (a real <button> or <a>) ---- */
.hb-link {
    border: 0;
    background: none;
    padding: 0;
    color: var(--hb-brand);
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    text-decoration: none;
}

    .hb-link:hover {
        color: var(--hb-brand);
        text-decoration: underline;
    }

/* ---- KPI tile row: a few numbers that answer "where do I stand" ---- */
.hb-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.hb-kpi {
    padding: 14px 18px;
}

/* A tile that is also a link to the screen where the user acts on it. */
a.hb-kpi {
    color: inherit;
    text-decoration: none;
    transition: box-shadow .15s ease, border-color .15s ease;
    border: 1px solid transparent;
}

    a.hb-kpi:hover {
        border-color: var(--hb-brand);
        box-shadow: var(--hb-shadow-raised);
    }

.hb-kpi-label {
    font-size: 13px;
    color: var(--hb-muted);
}

.hb-kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--hb-ink);
    font-variant-numeric: tabular-nums;
}

    .hb-kpi-value.is-alert {
        color: var(--hb-danger);
    }

.hb-kpi-sub {
    font-size: 12px;
    color: var(--hb-muted);
}

/* Compact one-line tile (Home dashboard): icon beside the number, label under it, a chevron
   when the tile opens another screen. .card is a column flexbox in the theme, so force a row. */
.hb-kpi--icon {
    flex-direction: row;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    min-height: 0;
}

.hb-kpi-icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff4ec;
    color: var(--hb-brand);
    font-size: 22px;
}

.hb-kpi-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.hb-kpi .hb-kpi-label {
    margin: 0;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.3;
    color: var(--hb-muted);
}

.hb-kpi--icon .hb-kpi-value {
    order: -1; /* number first, label under it (the label stays first in the markup for screen readers) */
    font-size: 22px;
    line-height: 1.2;
}

.hb-kpi--icon .hb-kpi-sub {
    line-height: 1.3;
}

.hb-kpi-chevron {
    flex: 0 0 auto;
    color: var(--hb-muted);
    font-size: 18px;
    transition: transform .15s ease, color .15s ease;
}

    a.hb-kpi:hover .hb-kpi-chevron {
        color: var(--hb-brand);
        transform: translateX(2px);
    }

/* ---- Pinned action bar: the one primary action, stuck to the bottom of the screen ---- */
.hb-action-bar {
    position: sticky;
    bottom: 16px;
    z-index: 999; /* below page loaders (1000+) so the bar can't be clicked while one is up */
    margin-top: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px 24px;
    padding: 14px 20px;
    background: var(--hb-surface);
    border: 1px solid var(--hb-brand);
    border-left-width: 5px;
    border-radius: 8px;
    box-shadow: var(--hb-shadow-raised);
}

    .hb-action-bar [hidden] {
        display: none !important;
    }

.hb-action-bar-hint {
    font-size: 15px;
    color: var(--hb-muted);
}

.hb-action-bar-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

    .hb-action-bar-actions form {
        margin: 0;
    }

/* ---- Empty state: one sentence and, if there is one, the next step ---- */
.hb-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--hb-muted);
}

.hb-empty-icon {
    font-size: 32px;
    color: var(--hb-brand);
    opacity: .7;
}

.hb-empty-title {
    margin: 8px 0 4px;
    font-size: 15px;
    font-weight: 600;
    color: var(--hb-ink);
}

/* ---- Status badge: always carries text, never colour alone ---- */
.hb-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
    background: rgba(111, 107, 125, .12);
    color: var(--hb-ink);
}

.hb-badge--ok {
    background: rgba(40, 199, 111, .14);
    color: #1b7f47;
}

.hb-badge--warn {
    background: rgba(255, 159, 67, .18);
    color: #9a5a12;
}

.hb-badge--danger {
    background: rgba(234, 84, 85, .14);
    color: #b3282a;
}

.hb-badge--info {
    background: rgba(0, 207, 232, .14);
    color: #06707e;
}

@media (max-width: 575.98px) {
    .hb-page-actions {
        gap: 8px 16px;
    }

    .hb-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .hb-kpi {
        padding: 10px 12px;
    }

    .hb-kpi-value {
        font-size: 18px;
    }

    .hb-action-bar {
        padding: 12px;
        bottom: 8px;
    }

    .hb-action-bar-actions {
        width: 100%;
        flex-wrap: nowrap;
    }

        .hb-action-bar-actions form {
            flex: 1 1 0;
            min-width: 0;
        }

        .hb-action-bar-actions .btn {
            width: 100%;
            min-width: 0;
            padding-left: 8px;
            padding-right: 8px;
        }
}

/* ---- Message cards (bell conversation pop-up) and cleaned email bodies (emailBody.js) ---- */
.hb-msg-modal-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-right: 3rem;
}

.hb-msg-modal-titles {
    flex: 1;
    min-width: 0;
}

.hb-msg-modal-titles .modal-title {
    margin: 0;
}

#RecordNumberLabel {
    color: var(--hb-brand);
}

.hb-msg-scroll {
    max-height: 65vh;
    overflow-y: auto;
    padding-right: 4px;
}

.hb-msg-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.hb-msg {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--hb-border);
    border-radius: 10px;
    background: var(--hb-surface);
}

.hb-msg--staff {
    background: #fff8f3;
    border-color: #f6dccb;
}

.hb-msg-avatar {
    flex: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 600;
    background: #eef0f4;
    color: var(--hb-ink);
}

.hb-msg--staff .hb-msg-avatar {
    background: var(--hb-brand);
    color: #fff;
}

.hb-msg-main {
    flex: 1;
    min-width: 0;
}

.hb-msg-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.hb-msg-new {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2071ff;
}

.hb-msg-author {
    font-weight: 600;
    color: var(--hb-ink);
}

.hb-msg-role {
    font-size: 11px;
    font-weight: 600;
    color: var(--hb-brand);
    background: #fdebdf;
    border-radius: 999px;
    padding: 1px 8px;
}

.hb-msg-date {
    margin-left: auto;
    font-size: 12.5px;
    color: var(--hb-muted);
    white-space: nowrap;
}

.hb-msg-read-toggle {
    border: 0;
    background: none;
    color: var(--hb-muted);
    padding: 2px 4px;
    border-radius: 4px;
    line-height: 1;
}

.hb-msg-read-toggle:hover {
    color: var(--hb-brand);
}

.hb-msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin-top: 8px;
    font-size: 13px;
}

/* Email body text: mail-client styling is stripped, so give it one consistent look. */
.hb-msg-text {
    color: var(--hb-ink);
    font-size: 14px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.hb-msg-text p,
.hb-msg-text div {
    margin: 0;
}

.hb-msg-text p + p {
    margin-top: 0.6em;
}

.hb-msg-text img {
    max-width: 100%;
    height: auto;
}

.hb-msg-text table {
    max-width: 100%;
}

/* "···" toggle that reveals the folded signature / quoted earlier emails. */
.hb-msg-fold {
    margin-top: 6px;
}

.hb-msg-fold > summary {
    display: inline-block;
    list-style: none;
    cursor: pointer;
    padding: 0 8px;
    border: 1px solid var(--hb-border);
    border-radius: 999px;
    color: var(--hb-muted);
    font-size: 12px;
    line-height: 16px;
    letter-spacing: 1px;
}

.hb-msg-fold > summary::-webkit-details-marker {
    display: none;
}

.hb-msg-fold > summary:hover {
    color: var(--hb-brand);
    border-color: var(--hb-brand);
}

.hb-msg-folded {
    margin-top: 8px;
    color: var(--hb-muted);
    font-size: 13px;
}

.hb-msg-folded img {
    max-height: 80px;
    width: auto;
}
