:root {
    --ink: #172033;
    --muted: #67728a;
    --line: #dfe5ef;
    --surface: #ffffff;
    --canvas: #f5f7fb;
    --brand: #5a4fcf;
    --brand-dark: #4439b6;
    --accent: #e9e7ff;
    --success: #176b45;
    --success-bg: #e8f7ef;
    --danger: #9b2c2c;
    --danger-bg: #fff0f0;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(20, 30, 55, .08);
}
* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-height: 100vh; }
a { color: var(--brand); }
.topbar {
    min-height: 68px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10;
}
.brand { display: inline-flex; gap: 10px; align-items: center; text-decoration: none; color: var(--ink); font-size: 20px; font-weight: 800; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--brand); color: white; font-size: 14px; }
.main-nav { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.main-nav a { text-decoration: none; color: var(--ink); padding: 10px 12px; border-radius: 10px; font-weight: 650; }
.main-nav a:hover { background: var(--accent); color: var(--brand-dark); }
.menu-button { display: none; border: 0; background: transparent; font-size: 26px; }
.page-shell { width: min(1180px, calc(100% - 32px)); margin: 32px auto; }
.page-heading { margin-bottom: 24px; }
.page-heading h1 { margin: 0; font-size: clamp(28px, 5vw, 44px); letter-spacing: -.04em; }
.page-heading p { color: var(--muted); margin: 8px 0 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.card h2, .card h3 { margin-top: 0; }
.narrow { max-width: 680px; margin-inline: auto; }
.card-grid, .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.metric-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.metric-card span { display: block; color: var(--muted); font-weight: 650; }
.metric-card strong { display: block; font-size: 36px; margin-top: 8px; }
label { display: block; font-weight: 700; font-size: 14px; }
input, select, textarea {
    width: 100%; margin-top: 7px; padding: 12px 13px; border: 1px solid #cfd7e6; border-radius: 10px;
    background: white; color: var(--ink); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(90,79,207,.16); border-color: var(--brand); }
form > label { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.button {
    display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 10px;
    padding: 12px 16px; background: var(--brand); color: white; text-decoration: none; font-weight: 750; cursor: pointer;
}
.button:hover { background: var(--brand-dark); }
.button.secondary { background: var(--accent); color: var(--brand-dark); }
.button.small { padding: 9px 12px; font-size: 14px; }
.full-button { width: 100%; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.alert { padding: 14px 16px; border-radius: 11px; margin-bottom: 18px; font-weight: 650; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.section-title { margin: 32px 0 14px; }
.setting-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.setting-card p { color: var(--muted); }
.setting-card code { color: var(--muted); font-size: 12px; }
.inline-setting { min-width: 210px; display: flex; gap: 8px; align-items: end; }
.inline-setting input, .inline-setting select { margin: 0; }
.split-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.stacked-links { display: grid; gap: 5px; }
.stacked-links a { display: flex; justify-content: space-between; text-decoration: none; color: var(--ink); padding: 10px 12px; border-radius: 9px; }
.stacked-links a.active, .stacked-links a:hover { background: var(--accent); color: var(--brand-dark); }
.compact-form { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 20px; }
.compact-form input { margin-bottom: 10px; }
.inline-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-top: 18px; }
.inline-add input { margin: 0; }
.responsive-table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.link-button { border: 0; background: none; color: var(--brand); cursor: pointer; font-weight: 750; padding: 0; }
.permission-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.check-card { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-weight: 500; }
.check-card input { width: auto; margin: 3px 0 0; }
.check-card small { display: block; color: var(--muted); margin-top: 3px; }
.footer { text-align: center; color: var(--muted); padding: 28px; font-size: 13px; }

@media (max-width: 850px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .card-grid, .settings-grid { grid-template-columns: 1fr; }
    .split-layout { grid-template-columns: 1fr; }
    .menu-button { display: block; }
    .main-nav {
        display: none; position: absolute; left: 0; right: 0; top: 68px; background: white;
        padding: 14px; border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
    }
    .nav-open .main-nav { display: grid; }
}
@media (max-width: 600px) {
    .page-shell { width: min(100% - 20px, 1180px); margin-top: 20px; }
    .topbar { padding: 0 14px; }
    .card { padding: 18px; }
    .metric-grid, .form-grid, .permission-grid { grid-template-columns: 1fr; }
    .metric-card strong { font-size: 30px; }
    .setting-card { display: block; }
    .inline-setting { min-width: 0; margin-top: 16px; }
    .inline-add { grid-template-columns: 1fr; }
    .responsive-table thead { display: none; }
    .responsive-table tr { display: block; border-bottom: 1px solid var(--line); padding: 10px 0; }
    .responsive-table td { display: flex; justify-content: space-between; gap: 18px; border: 0; padding: 7px 0; }
    .responsive-table td::before { content: attr(data-label); color: var(--muted); font-weight: 700; }
}

/* ===== Engagement Management v0.4 ===== */

.section-heading-row{
    display:flex;
    justify-content:space-between;
    align-items:flex-start;
    gap:18px;
    margin-bottom:18px;
    flex-wrap:wrap;
}

.section-heading-row h2{
    margin-bottom:4px;
}

.section-heading-row p{
    margin:0;
    color:var(--muted);
}

.status-draft{background:#eef2f7;color:#425466;}
.status-active{background:#e7f7ef;color:#17633c;}
.status-on_hold{background:#fff4d6;color:#7a5200;}
.status-completed{background:#e7f0ff;color:#214f91;}
.status-cancelled{background:#fdeaea;color:#8d2424;}

@media(max-width:600px){
    .section-heading-row{
        display:block;
    }

    .section-heading-row .button{
        margin-top:14px;
        width:100%;
        text-align:center;
    }
}

/* Append this to /assets/style.css */
.section-heading-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.section-heading-row h2 { margin-bottom: 4px; }
.section-heading-row p { margin: 0; color: var(--muted); }
.contact-options {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.contact-options legend { font-weight: 700; padding: 0 6px; }
.contact-options label { display: flex; gap: 9px; align-items: center; font-weight: 600; }
.contact-options input { width: auto; }
.responsive-table td small { display: block; color: var(--muted); margin-top: 4px; }
.small-button { padding: 7px 10px; font-size: 13px; }
@media (max-width: 700px) {
    .contact-options { grid-template-columns: 1fr; }
    .section-heading-row .button { width: 100%; text-align: center; }
}

/* Append this to /assets/style.css */
.section-heading-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.section-heading-row h2 { margin-bottom: 4px; }
.section-heading-row p { margin: 0; color: var(--muted); }
.contact-options {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.contact-options legend { font-weight: 700; padding: 0 6px; }
.contact-options label { display: flex; gap: 9px; align-items: center; font-weight: 600; }
.contact-options input { width: auto; }
.responsive-table td small { display: block; color: var(--muted); margin-top: 4px; }
.small-button { padding: 7px 10px; font-size: 13px; }
@media (max-width: 700px) {
    .contact-options { grid-template-columns: 1fr; }
    .section-heading-row .button { width: 100%; text-align: center; }
}
/* Append this entire file to /assets/style.css */
.metric-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:16px;margin-bottom:20px}.metric-card{background:#fff;border:1px solid var(--line);border-radius:12px;padding:18px}.metric-card span{display:block;color:var(--muted);font-size:13px}.metric-card strong{display:block;font-size:25px;margin-top:6px}.timer-card{text-align:center;max-width:720px;margin:auto}.timer-display{font-size:52px;font-variant-numeric:tabular-nums;font-weight:800;margin:24px 0}.filter-grid{display:grid;grid-template-columns:repeat(4,minmax(150px,1fr));gap:12px;align-items:end}.filter-actions,.bulk-bar{display:flex;gap:8px;align-items:end}.bulk-bar{margin:0 0 12px}.filter-card{margin-bottom:18px}.row-deleted{opacity:.58;text-decoration:line-through}.button.danger{background:#b91c1c;color:#fff;border-color:#b91c1c}.status-rejected{background:#fee2e2;color:#991b1b}.status-submitted{background:#fef3c7;color:#92400e}.status-approved{background:#dcfce7;color:#166534}.floating-timer{position:fixed;right:18px;bottom:18px;z-index:1000;display:flex;align-items:center;gap:10px;background:#111827;color:#fff;text-decoration:none;border-radius:14px;padding:12px 16px;box-shadow:0 12px 30px rgba(0,0,0,.25);max-width:310px}.floating-timer strong{display:block;font-size:20px;font-variant-numeric:tabular-nums}.floating-timer small{display:block;color:#d1d5db;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:240px}.floating-timer-dot{width:10px;height:10px;border-radius:50%;background:#22c55e;box-shadow:0 0 0 5px rgba(34,197,94,.18)}
@media(max-width:900px){.filter-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.metric-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}@media(max-width:520px){.filter-grid,.metric-grid{grid-template-columns:1fr}.timer-display{font-size:38px}.floating-timer{left:12px;right:12px;bottom:12px}.filter-actions,.bulk-bar{align-items:stretch;flex-direction:column}}

/* =========================================================
   AuntBird blue/yellow responsive application shell
   Desktop: fixed sidebar
   Mobile/PWA: off-canvas drawer with sticky app bar
   ========================================================= */

:root {
    --ink: #263646;
    --muted: #64748b;
    --line: #d9e2ec;
    --surface: #ffffff;
    --canvas: #eef3f8;
    --brand: #174466;
    --brand-dark: #12314b;
    --brand-mid: #2b6ca3;
    --accent: #f4c542;
    --accent-soft: #fff8d8;
    --success: #176b45;
    --success-bg: #e8f7ef;
    --danger: #9b2c2c;
    --danger-bg: #fff0f0;
    --radius: 14px;
    --shadow: 0 8px 20px rgba(18, 49, 75, .09);
    --sidebar-width: 270px;
}

html,
body {
    min-height: 100%;
}

body {
    background: var(--canvas);
    color: var(--ink);
}

body.nav-open {
    overflow: hidden;
}

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

.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--brand-dark);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex: 0 0 var(--sidebar-width);
    box-shadow: 4px 0 22px rgba(0, 0, 0, .16);
    z-index: 1100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 24px 22px;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, .11);
}

.sidebar-brand .brand-mark,
.public-brand .brand-mark {
    width: 50px;
    height: 50px;
    border-radius: 14px;
    background: var(--brand-mid);
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 19px;
    font-weight: 900;
    flex: 0 0 auto;
}

.sidebar-brand strong {
    display: block;
    font-size: 20px;
    line-height: 1.1;
}

.sidebar-brand small {
    display: block;
    color: #b9c7d4;
    font-size: 12px;
    margin-top: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.nav-menu {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-section {
    margin: 17px 10px 5px;
    color: #7fa4c3;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.15px;
}

.nav-menu a {
    color: #fff;
    padding: 11px 13px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 11px;
    text-decoration: none;
    font-weight: 700;
    transition: background .18s ease, color .18s ease, transform .18s ease;
}

.nav-menu a:hover {
    background: var(--brand-mid);
    color: #fff;
    transform: translateX(2px);
}

.nav-menu a.active {
    background: var(--accent);
    color: #1f2937;
    box-shadow: 0 7px 18px rgba(244, 197, 66, .2);
}

.nav-icon {
    width: 22px;
    text-align: center;
    font-size: 17px;
    flex: 0 0 22px;
}

.sidebar-timer {
    margin: 8px 16px 16px;
    padding: 15px;
    color: #fff;
    text-decoration: none;
    border-radius: 14px;
    background: rgba(255, 255, 255, .08);
    border: 1px solid rgba(255, 255, 255, .13);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
}

.sidebar-timer:hover {
    background: rgba(43, 108, 163, .5);
}

.sidebar-timer-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #c8d6e3;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .75px;
    text-transform: uppercase;
}

.timer-status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, .16);
    flex: 0 0 auto;
}

.is-paused .timer-status-dot {
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(244, 197, 66, .16);
}

.sidebar-timer > strong {
    display: block;
    color: var(--accent);
    font-size: 28px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    margin: 13px 0 10px;
}

.sidebar-timer-client {
    display: block;
    color: #fff;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-timer small {
    display: block;
    color: #b9c7d4;
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-timer-open {
    display: block;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    margin-top: 12px;
}

.sidebar-footer {
    margin-top: auto;
    padding: 17px;
    border-top: 1px solid rgba(255, 255, 255, .1);
    padding-bottom: max(17px, env(safe-area-inset-bottom));
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 5px 5px 13px;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--brand-mid);
    color: #fff;
    font-weight: 900;
    flex: 0 0 auto;
}

.sidebar-user strong,
.sidebar-user small {
    display: block;
    max-width: 175px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user small {
    color: #b9c7d4;
    margin-top: 2px;
}

.signout-link {
    display: block;
    padding: 10px 12px;
    color: #fff;
    text-decoration: none;
    border-radius: 9px;
    font-weight: 700;
}

.signout-link:hover {
    background: var(--brand-mid);
}

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.mobile-topbar {
    display: none;
}

.content-wrap {
    width: 100%;
    max-width: 1500px;
    padding: 30px;
    margin: 0 auto;
    flex: 1;
}

.page-heading {
    margin-bottom: 23px;
}

.page-heading h1 {
    color: var(--brand);
    font-size: clamp(28px, 4vw, 42px);
    letter-spacing: -.035em;
}

.app-footer {
    padding: 16px 30px 22px;
    color: var(--muted);
    font-size: 13px;
    text-align: right;
}

.sidebar-overlay {
    display: none;
}

.card,
.metric-card,
.stat-card {
    box-shadow: var(--shadow);
}

.button {
    background: var(--brand);
}

.button:hover {
    background: var(--brand-mid);
}

.button.secondary {
    background: var(--accent-soft);
    color: #725a00;
    border: 1px solid #f0d771;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(43, 108, 163, .16);
    border-color: var(--brand-mid);
}

.public-topbar {
    min-height: 72px;
    padding: 0 22px;
    display: flex;
    align-items: center;
    background: var(--brand-dark);
}

.public-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    color: #fff;
    text-decoration: none;
    font-size: 20px;
    font-weight: 900;
}

.auth-page-shell {
    width: min(720px, calc(100% - 28px));
    margin: 30px auto;
}

/* Time module refinements */
.timer-card {
    text-align: left;
    max-width: 820px;
}

.timer-display {
    color: var(--brand);
    letter-spacing: -.04em;
}

.floating-timer {
    display: none !important;
}

/* Tablet and mobile app layout */
@media (max-width: 820px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(88vw, 330px);
        min-height: 100dvh;
        transform: translateX(-105%);
        transition: transform .24s ease;
        overflow-y: auto;
        box-shadow: 9px 0 30px rgba(0, 0, 0, .3);
    }

    body.nav-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        border: 0;
        padding: 0;
        background: rgba(10, 25, 40, .52);
        opacity: 0;
        visibility: hidden;
        transition: opacity .2s ease, visibility .2s ease;
        z-index: 1050;
    }

    body.nav-open .sidebar-overlay {
        opacity: 1;
        visibility: visible;
    }

    .mobile-topbar {
        min-height: 66px;
        padding:
            max(9px, env(safe-area-inset-top))
            13px
            9px;
        display: flex;
        align-items: center;
        gap: 11px;
        position: sticky;
        top: 0;
        z-index: 1000;
        background: #fff;
        border-bottom: 1px solid var(--line);
        box-shadow: 0 4px 12px rgba(18, 49, 75, .07);
    }

    .mobile-menu-button {
        width: 44px;
        height: 44px;
        border: 0;
        border-radius: 11px;
        background: var(--brand);
        color: #fff;
        font-size: 23px;
        display: inline-grid;
        place-items: center;
        cursor: pointer;
        flex: 0 0 auto;
    }

    .mobile-title {
        display: flex;
        align-items: center;
        gap: 9px;
        min-width: 0;
        flex: 1;
    }

    .mobile-brand-mark {
        width: 35px;
        height: 35px;
        border-radius: 10px;
        background: var(--brand-mid);
        color: #fff;
        display: grid;
        place-items: center;
        font-size: 12px;
        font-weight: 900;
        flex: 0 0 auto;
    }

    .mobile-title strong,
    .mobile-title small {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-title strong {
        color: var(--brand);
        font-size: 16px;
    }

    .mobile-title small {
        color: var(--muted);
        font-size: 11px;
        margin-top: 2px;
    }

    .mobile-timer-link {
        min-height: 40px;
        padding: 7px 10px;
        display: flex;
        align-items: center;
        gap: 7px;
        color: var(--brand);
        background: var(--accent-soft);
        border: 1px solid #f0d771;
        border-radius: 11px;
        text-decoration: none;
        flex: 0 0 auto;
    }

    .mobile-timer-link strong {
        font-size: 13px;
        font-variant-numeric: tabular-nums;
    }

    .content-wrap {
        padding: 17px;
    }

    .page-heading {
        margin-bottom: 18px;
    }

    .page-heading h1 {
        font-size: 29px;
    }

    .page-heading p {
        font-size: 13px;
    }

    .app-footer {
        padding: 12px 17px calc(16px + env(safe-area-inset-bottom));
        text-align: center;
    }

    .card,
    .metric-card,
    .stat-card {
        border-radius: 14px;
    }

    .button,
    button,
    input,
    select,
    textarea {
        min-height: 44px;
    }

    .button-row,
    .filter-actions,
    .bulk-bar {
        flex-wrap: wrap;
    }
}

@media (max-width: 560px) {
    .content-wrap {
        padding: 13px;
    }

    .page-heading h1 {
        font-size: 25px;
    }

    .mobile-title small,
    .page-heading p {
        display: none;
    }

    .mobile-timer-link {
        padding-inline: 8px;
    }

    .mobile-timer-link strong {
        font-size: 12px;
    }

    .form-grid,
    .card-grid,
    .settings-grid,
    .metric-grid,
    .filter-grid {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 17px;
    }

    .button-row,
    .filter-actions,
    .bulk-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .button-row > *,
    .filter-actions > *,
    .bulk-bar > *,
    .button-row form,
    .filter-actions form,
    .bulk-bar form {
        width: 100%;
    }

    .button-row .button,
    .button-row button,
    .filter-actions .button,
    .filter-actions button,
    .bulk-bar .button,
    .bulk-bar button {
        width: 100%;
    }

    .timer-display {
        font-size: 40px;
        text-align: center;
    }
}


<?php
declare(strict_types=1);

require_once __DIR__ . '/auth.php';

$timeHelpers = __DIR__ . '/time_helpers.php';
if (is_file($timeHelpers)) {
    require_once $timeHelpers;
}

if (!function_exists('auntbird_nav_active')) {
    function auntbird_nav_active(string $path): string
    {
        $requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?: '';
        $appPath = parse_url(app_url($path), PHP_URL_PATH) ?: '';

        if ($path === 'dashboard.php') {
            return basename($requestPath) === 'dashboard.php' ? ' active' : '';
        }

        $section = trim(dirname($appPath), '/');
        if ($section !== '' && strpos(trim($requestPath, '/'), $section . '/') !== false) {
            return ' active';
        }

        return $requestPath === $appPath ? ' active' : '';
    }
}

function page_header(string $title): void
{
    global $config;

    $user = current_user();
    $flashes = pull_flashes();
    $activeTimer = null;

    if (
        $user &&
        function_exists('active_timer') &&
        has_permission('time.view')
    ) {
        $activeTimer = active_timer();
    }

    $appName = (string) ($config['app_name'] ?? 'AuntBird');
    ?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta
        name="viewport"
        content="width=device-width, initial-scale=1, viewport-fit=cover"
    >
    <meta name="theme-color" content="#12314b">
    <title><?= e($title) ?> | <?= e($appName) ?></title>
    <link rel="stylesheet" href="<?= e(app_url('assets/style.css')) ?>?v=<?= e((string) (@filemtime(dirname(__DIR__) . '/assets/style.css') ?: time())) ?>">
</head>
<body class="<?= $user ? 'app-body' : 'auth-body' ?>">

<?php if (!$user): ?>
    <header class="public-topbar">
        <a class="public-brand" href="<?= e(app_url('login.php')) ?>">
            <span class="brand-mark">AB</span>
            <span><?= e($appName) ?></span>
        </a>
    </header>

    <main class="auth-page-shell">
        <?php foreach ($flashes as $flash): ?>
            <div class="alert alert-<?= e($flash['type']) ?>">
                <?= e($flash['message']) ?>
            </div>
        <?php endforeach; ?>

        <div class="page-heading">
            <h1><?= e($title) ?></h1>
        </div>
<?php return; endif; ?>

<div class="app-shell">
    <aside class="sidebar" id="auntbirdSidebar" aria-label="AuntBird navigation">
        <a class="sidebar-brand" href="<?= e(app_url('dashboard.php')) ?>">
            <span class="brand-mark">AB</span>
            <span>
                <strong><?= e($appName) ?></strong>
                <small><?= e($user['organization_name'] ?? 'Practice Management') ?></small>
            </span>
        </a>

        <nav class="nav-menu">
            <div class="nav-section">Overview</div>
            <a class="<?= auntbird_nav_active('dashboard.php') ?>" href="<?= e(app_url('dashboard.php')) ?>">
                <span class="nav-icon" aria-hidden="true">⌂</span>
                <span>Dashboard</span>
            </a>

            <?php if (has_permission('clients.view') || has_permission('engagements.view') || has_permission('time.view')): ?>
                <div class="nav-section">Practice</div>

                <?php if (has_permission('clients.view')): ?>
                    <a class="<?= auntbird_nav_active('clients/index.php') ?>" href="<?= e(app_url('clients/index.php')) ?>">
                        <span class="nav-icon" aria-hidden="true">◉</span>
                        <span>Clients</span>
                    </a>
                <?php endif; ?>

                <?php if (has_permission('engagements.view')): ?>
                    <a class="<?= auntbird_nav_active('engagements/index.php') ?>" href="<?= e(app_url('engagements/index.php')) ?>">
                        <span class="nav-icon" aria-hidden="true">▣</span>
                        <span>Engagements</span>
                    </a>
                <?php endif; ?>

                <?php if (has_permission('time.view')): ?>
                    <a class="<?= auntbird_nav_active('time/index.php') ?>" href="<?= e(app_url('time/index.php')) ?>">
                        <span class="nav-icon" aria-hidden="true">◷</span>
                        <span>Time</span>
                    </a>
                <?php endif; ?>

                <?php if (has_permission('billing.view')): ?>
                    <a class="<?= auntbird_nav_active('billing/index.php') ?>" href="<?= e(app_url('billing/index.php')) ?>">
                        <span class="nav-icon" aria-hidden="true">$</span>
                        <span>Billing</span>
                    </a>
                <?php endif; ?>
            <?php endif; ?>

            <?php if (
                has_permission('configuration.view') ||
                has_permission('lookups.view') ||
                has_permission('numbering.view') ||
                has_permission('configuration.manage')
            ): ?>
                <div class="nav-section">Administration</div>

                <?php if (has_permission('configuration.view')): ?>
                    <a class="<?= auntbird_nav_active('admin/settings.php') ?>" href="<?= e(app_url('admin/settings.php')) ?>">
                        <span class="nav-icon" aria-hidden="true">⚙</span>
                        <span>Settings</span>
                    </a>
                <?php endif; ?>

                <?php if (has_permission('lookups.view')): ?>
                    <a class="<?= auntbird_nav_active('admin/lookups.php') ?>" href="<?= e(app_url('admin/lookups.php')) ?>">
                        <span class="nav-icon" aria-hidden="true">☷</span>
                        <span>Lookups</span>
                    </a>
                <?php endif; ?>

                <?php if (has_permission('numbering.view')): ?>
                    <a class="<?= auntbird_nav_active('admin/numbering.php') ?>" href="<?= e(app_url('admin/numbering.php')) ?>">
                        <span class="nav-icon" aria-hidden="true">#</span>
                        <span>Numbering</span>
                    </a>
                <?php endif; ?>

                <?php if (has_permission('configuration.manage')): ?>
                    <a class="<?= auntbird_nav_active('admin/users.php') ?>" href="<?= e(app_url('admin/users.php')) ?>">
                        <span class="nav-icon" aria-hidden="true">♙</span>
                        <span>Users</span>
                    </a>

                    <a class="<?= auntbird_nav_active('admin/roles.php') ?>" href="<?= e(app_url('admin/roles.php')) ?>">
                        <span class="nav-icon" aria-hidden="true">◇</span>
                        <span>Roles</span>
                    </a>
                <?php endif; ?>
            <?php endif; ?>
        </nav>

        <?php if ($activeTimer): ?>
            <a
                class="sidebar-timer <?= $activeTimer['status'] === 'running' ? 'is-running' : 'is-paused' ?>"
                href="<?= e(app_url('time/timer.php')) ?>"
            >
                <span class="sidebar-timer-label">
                    <span class="timer-status-dot"></span>
                    <?= $activeTimer['status'] === 'running' ? 'Active timer' : 'Timer paused' ?>
                </span>

                <strong
                    class="js-live-timer"
                    data-seconds="<?= timer_elapsed_seconds($activeTimer) ?>"
                    data-running="<?= $activeTimer['status'] === 'running' ? '1' : '0' ?>"
                >
                    <?= gmdate('H:i:s', timer_elapsed_seconds($activeTimer)) ?>
                </strong>

                <span class="sidebar-timer-client">
                    <?= e($activeTimer['client_name']) ?>
                </span>

                <small><?= e($activeTimer['engagement_name']) ?></small>
                <span class="sidebar-timer-open">Open timer →</span>
            </a>
        <?php endif; ?>

        <div class="sidebar-footer">
            <div class="sidebar-user">
                <span class="sidebar-user-avatar">
                    <?= e(strtoupper(substr((string) ($user['first_name'] ?? 'U'), 0, 1))) ?>
                </span>
                <span>
                    <strong><?= e(trim(($user['first_name'] ?? '') . ' ' . ($user['last_name'] ?? ''))) ?></strong>
                    <small><?= e($user['organization_name'] ?? '') ?></small>
                </span>
            </div>

            <a class="signout-link" href="<?= e(app_url('logout.php')) ?>">
                Sign out
            </a>
        </div>
    </aside>

    <button
        class="sidebar-overlay"
        id="sidebarOverlay"
        type="button"
        aria-label="Close navigation"
        tabindex="-1"
    ></button>

    <section class="main-content">
        <header class="mobile-topbar">
            <button
                class="mobile-menu-button"
                id="mobileMenuButton"
                type="button"
                aria-label="Open navigation"
                aria-controls="auntbirdSidebar"
                aria-expanded="false"
            >☰</button>

            <div class="mobile-title">
                <span class="mobile-brand-mark">AB</span>
                <span>
                    <strong><?= e($title) ?></strong>
                    <small><?= e($appName) ?></small>
                </span>
            </div>

            <?php if ($activeTimer): ?>
                <a
                    class="mobile-timer-link"
                    href="<?= e(app_url('time/timer.php')) ?>"
                    aria-label="Open active timer"
                >
                    <span class="timer-status-dot"></span>
                    <strong
                        class="js-live-timer"
                        data-seconds="<?= timer_elapsed_seconds($activeTimer) ?>"
                        data-running="<?= $activeTimer['status'] === 'running' ? '1' : '0' ?>"
                    >
                        <?= gmdate('H:i:s', timer_elapsed_seconds($activeTimer)) ?>
                    </strong>
                </a>
            <?php endif; ?>
        </header>

        <main class="content-wrap">
            <?php foreach ($flashes as $flash): ?>
                <div class="alert alert-<?= e($flash['type']) ?>">
                    <?= e($flash['message']) ?>
                </div>
            <?php endforeach; ?>

            <div class="page-heading">
                <h1><?= e($title) ?></h1>
                <p>
                    <?= e($user['organization_name']) ?>
                    ·
                    <?= e(trim($user['first_name'] . ' ' . $user['last_name'])) ?>
                </p>
            </div>
<?php
}

function page_footer(): void
{
    $user = current_user();
    ?>

<?php if (!$user): ?>
    </main>
<?php else: ?>
        </main>
        <footer class="app-footer">
            AuntBird Practice Management
        </footer>
    </section>
</div>
<?php endif; ?>

<script>
(function () {
    'use strict';

    function formatTimer(totalSeconds) {
        var hours = Math.floor(totalSeconds / 3600);
        var minutes = Math.floor((totalSeconds % 3600) / 60);
        var seconds = totalSeconds % 60;

        return String(hours).padStart(2, '0') + ':' +
            String(minutes).padStart(2, '0') + ':' +
            String(seconds).padStart(2, '0');
    }

    Array.prototype.forEach.call(
        document.querySelectorAll('.js-live-timer'),
        function (display) {
            var seconds = Number(display.getAttribute('data-seconds') || 0);
            display.textContent = formatTimer(seconds);

            if (display.getAttribute('data-running') === '1') {
                window.setInterval(function () {
                    seconds++;
                    display.textContent = formatTimer(seconds);
                }, 1000);
            }
        }
    );

    var body = document.body;
    var menuButton = document.getElementById('mobileMenuButton');
    var overlay = document.getElementById('sidebarOverlay');
    var sidebar = document.getElementById('auntbirdSidebar');

    function setMenu(open) {
        body.classList.toggle('nav-open', open);

        if (menuButton) {
            menuButton.setAttribute('aria-expanded', open ? 'true' : 'false');
            menuButton.setAttribute(
                'aria-label',
                open ? 'Close navigation' : 'Open navigation'
            );
        }
    }

    if (menuButton) {
        menuButton.addEventListener('click', function () {
            setMenu(!body.classList.contains('nav-open'));
        });
    }

    if (overlay) {
        overlay.addEventListener('click', function () {
            setMenu(false);
        });
    }

    if (sidebar) {
        Array.prototype.forEach.call(
            sidebar.querySelectorAll('a'),
            function (link) {
                link.addEventListener('click', function () {
                    if (window.innerWidth <= 820) {
                        setMenu(false);
                    }
                });
            }
        );
    }

    document.addEventListener('keydown', function (event) {
        if (event.key === 'Escape') {
            setMenu(false);
        }
    });

    window.addEventListener('resize', function () {
        if (window.innerWidth > 820) {
            setMenu(false);
        }
    });
}());
</script>
</body>
</html>
<?php
}

/* Billing Workbench v0.6.1: invoice editing, issue workflow, and print */
.invoice-screen-actions{align-items:center}
.invoice-screen-actions form{margin:0}
.invoice-document-heading{display:flex;align-items:flex-start;justify-content:space-between;gap:30px;padding-bottom:24px;border-bottom:2px solid #174466}
.invoice-firm-heading{display:flex;align-items:center;gap:12px}
.invoice-logo-mark{width:48px;height:48px;display:grid;place-items:center;border-radius:13px;background:#174466;color:#fff;font-weight:900}
.invoice-firm-heading strong,.invoice-firm-heading small{display:block}
.invoice-firm-heading strong{font-size:22px;color:#174466}
.invoice-firm-heading small{margin-top:3px;color:#64748b}
.invoice-number-heading{text-align:right}
.invoice-number-heading span{display:block;text-transform:uppercase;letter-spacing:1.2px;color:#64748b;font-size:12px;font-weight:800}
.invoice-number-heading strong{display:block;margin-top:5px;font-size:28px;color:#174466}
.invoice-address-date-grid{display:grid;grid-template-columns:minmax(0,1.3fr) minmax(300px,.7fr);gap:35px;margin:28px 0}
.invoice-bill-to{display:flex;flex-direction:column;align-items:flex-start;line-height:1.5}
.invoice-label{margin-bottom:8px;text-transform:uppercase;letter-spacing:1px;color:#64748b;font-size:12px;font-weight:900}
.invoice-bill-to h2{margin:2px 0 8px;color:#17283a;font-size:24px}
.invoice-bill-to address{display:flex;flex-direction:column;font-style:normal;font-size:17px;color:#263646;line-height:1.55}
.invoice-contact-line{display:block;margin-top:5px;color:#4b6175}
.missing-address{padding:12px;border-radius:9px;background:#fff8d8;color:#725a00}
.invoice-date-panel{display:grid;align-content:start;border:1px solid #d9e2ec;border-radius:13px;overflow:hidden}
.invoice-date-panel div{display:grid;grid-template-columns:120px 1fr;gap:14px;padding:12px 15px;border-bottom:1px solid #e7edf2}
.invoice-date-panel div:last-child{border-bottom:0}
.invoice-date-panel span{color:#64748b}
.invoice-date-panel strong{text-align:right;color:#263646}
.invoice-edit-card{max-width:1150px}
.invoice-edit-dates{display:grid;grid-template-columns:repeat(4,minmax(145px,1fr));gap:14px;margin-bottom:22px}
.invoice-edit-table input{width:100%}
.invoice-edit-table input[type=number]{min-width:105px}
.invoice-edit-actions{justify-content:flex-end;margin-top:20px}

@media(max-width:850px){
 .invoice-address-date-grid{grid-template-columns:1fr}
 .invoice-date-panel{max-width:none}
 .invoice-edit-dates{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media(max-width:560px){
 .invoice-document-heading{flex-direction:column}
 .invoice-number-heading{text-align:left}
 .invoice-date-panel div{grid-template-columns:1fr;gap:3px}
 .invoice-date-panel strong{text-align:left}
 .invoice-edit-dates{grid-template-columns:1fr}
}
@media print{
 @page{size:auto;margin:.55in}
 body{background:#fff!important;color:#111!important}
 .sidebar,.mobile-topbar,.app-footer,.page-heading,.alert,.no-print{display:none!important}
 .app-shell,.main-content,.content-wrap{display:block!important;width:100%!important;max-width:none!important;margin:0!important;padding:0!important}
 .invoice-preview{box-shadow:none!important;border:0!important;padding:0!important}
 .invoice-document-heading{border-color:#222!important}
 .invoice-line-table{font-size:12pt}
 .invoice-address-date-grid{grid-template-columns:1.2fr .8fr!important}
 .invoice-date-panel{break-inside:avoid}
 .invoice-total-box{break-inside:avoid}
 a{color:inherit!important;text-decoration:none!important}
}

/* AuntBird direct invoice amount editing v0.6.5 */
.invoice-basis-summary{
    display:block;
    color:var(--brand,#174466);
    font-weight:800;
    margin-bottom:4px;
}
.final-amount-field{
    display:flex;
    align-items:center;
    gap:6px;
    max-width:220px;
}
.final-amount-field>span{
    font-size:20px;
    font-weight:900;
    color:var(--brand,#174466);
}
.invoice-final-amount{
    width:100%;
    min-width:140px;
    text-align:right;
    font-size:18px;
    font-weight:800;
}
.invoice-final-total-preview{
    margin:22px 0 0 auto;
    width:min(360px,100%);
    padding:16px 18px;
    border-radius:13px;
    background:#f5f8fb;
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:20px;
}
.invoice-final-total-preview span{
    color:var(--muted,#64748b);
    font-weight:700;
}
.invoice-final-total-preview strong{
    color:var(--brand,#174466);
    font-size:22px;
}
@media(max-width:600px){
    .final-amount-field{
        max-width:none;
    }
}



/* AuntBird Invoice Branding and Global Defaults v0.7 */
.invoice-business-logo{
    display:block;
    width:auto;
    max-width:230px;
    max-height:90px;
    object-fit:contain;
}
.invoice-business-identity{
    display:flex;
    flex-direction:column;
    gap:5px;
}
.invoice-business-identity>strong{
    font-size:24px;
    line-height:1.15;
    color:var(--brand,#174466);
}
.invoice-firm-address{
    display:flex;
    flex-direction:column;
    gap:2px;
    margin:0;
    color:var(--muted,#64748b);
    font-style:normal;
    font-size:13px;
}
.source-time-link{
    color:var(--brand,#174466);
    font-weight:700;
    text-decoration:none;
}
.source-time-link:hover{
    text-decoration:underline;
}
.source-time-description{
    font-weight:500;
}
.invoice-branding-grid{
    display:grid;
    grid-template-columns:minmax(220px,300px) minmax(0,1fr);
    gap:24px;
    align-items:start;
}
.invoice-logo-setting,
.invoice-brand-fields{
    display:grid;
    gap:14px;
}
.invoice-logo-preview{
    min-height:140px;
    border:1px dashed var(--line,#d9e2ec);
    border-radius:14px;
    display:flex;
    align-items:center;
    justify-content:center;
    padding:18px;
    background:#f8fafc;
    color:var(--muted,#64748b);
}
.invoice-logo-preview img{
    display:block;
    max-width:100%;
    max-height:110px;
    object-fit:contain;
}
.invoice-logo-setting small{
    display:block;
    margin-top:5px;
    color:var(--muted,#64748b);
}
.checkbox-line{
    display:flex;
    align-items:center;
    gap:9px;
}
.checkbox-line input{
    width:auto;
}
.three-field-row{
    display:grid;
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:12px;
}
.invoice-branding-readonly{
    display:flex;
    align-items:center;
    gap:18px;
}
.invoice-branding-readonly img{
    max-width:200px;
    max-height:80px;
    object-fit:contain;
}
@media(max-width:760px){
    .invoice-branding-grid{
        grid-template-columns:1fr;
    }
    .three-field-row{
        grid-template-columns:1fr;
    }
}
@media print{
    .invoice-business-logo{
        max-width:220px;
        max-height:80px;
    }
    .invoice-business-identity>strong{
        color:#000;
    }
    .invoice-firm-address{
        color:#222;
    }
}
/* AuntBird Client 360 View v0.8 */
.client-financial-snapshot{
    display:grid;
    grid-template-columns:repeat(4,minmax(0,1fr));
    gap:16px;
    margin:18px 0;
}
.client-financial-snapshot.compact{
    margin-top:0;
}
.client-metric-card{
    display:flex;
    flex-direction:column;
    gap:5px;
    min-height:120px;
    padding:20px;
    border:1px solid var(--line,#d9e2ec);
    border-radius:16px;
    background:#fff;
    color:inherit;
    text-decoration:none;
    box-shadow:0 8px 24px rgba(15,23,42,.05);
}
.client-metric-card:hover{
    transform:translateY(-1px);
    box-shadow:0 10px 28px rgba(15,23,42,.09);
}
.client-metric-card>span{
    color:var(--muted,#64748b);
    font-size:13px;
    font-weight:800;
    letter-spacing:.03em;
    text-transform:uppercase;
}
.client-metric-card>strong{
    color:var(--brand,#174466);
    font-size:28px;
    line-height:1.1;
}
.client-metric-card>small{
    color:var(--muted,#64748b);
}
.client-metric-card.attention{
    border-color:#e8b844;
    background:#fff9e8;
}
.client-metric-card.attention>strong{
    color:#9a5b00;
}
.client-activity-card{
    overflow:hidden;
}
.client-payment-list{
    display:grid;
    gap:10px;
}
.client-payment-list article{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:16px;
    padding:12px 0;
    border-bottom:1px solid var(--line,#d9e2ec);
}
.client-payment-list article:last-child{
    border-bottom:0;
}
.client-payment-list article div{
    display:flex;
    flex-direction:column;
    gap:3px;
}
.client-payment-list article strong{
    color:var(--brand,#174466);
    font-size:18px;
}
.client-payment-list article small,
.client-payment-list article>span{
    color:var(--muted,#64748b);
}
@media(max-width:1050px){
    .client-financial-snapshot{
        grid-template-columns:repeat(2,minmax(0,1fr));
    }
}
@media(max-width:620px){
    .client-financial-snapshot{
        grid-template-columns:1fr;
    }
    .client-metric-card{
        min-height:auto;
    }
}
/* AuntBird Client View UI Standard v0.9
   This page establishes the visual pattern for future record-detail pages. */

.client-profile-header{
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap:28px;
    padding:26px;
    margin-bottom:16px;
    border:1px solid var(--line,#d9e2ec);
    border-radius:18px;
    background:
        linear-gradient(135deg,rgba(23,68,102,.055),rgba(255,255,255,0) 52%),
        #fff;
}
.client-profile-main{
    display:flex;
    align-items:flex-start;
    gap:18px;
    min-width:0;
}
.client-avatar{
    display:grid;
    place-items:center;
    flex:0 0 58px;
    width:58px;
    height:58px;
    border-radius:16px;
    background:var(--brand,#174466);
    color:#fff;
    font-size:26px;
    font-weight:900;
    box-shadow:0 8px 22px rgba(23,68,102,.18);
}
.client-profile-copy{
    min-width:0;
}
.client-profile-eyebrow{
    display:flex;
    align-items:center;
    flex-wrap:wrap;
    gap:10px;
    margin-bottom:5px;
    color:var(--muted,#64748b);
    font-size:13px;
    font-weight:800;
    letter-spacing:.035em;
    text-transform:uppercase;
}
.client-profile-copy h1{
    margin:0;
    color:var(--brand,#174466);
    font-size:clamp(27px,3vw,38px);
    line-height:1.08;
}
.client-dba{
    margin:6px 0 0;
    color:var(--muted,#64748b);
    font-size:15px;
}
.client-profile-meta{
    display:flex;
    flex-wrap:wrap;
    gap:8px 20px;
    margin-top:14px;
    color:#445568;
    font-size:13px;
}
.client-profile-meta span{
    display:inline-flex;
    gap:4px;
}
.client-header-actions{
    display:flex;
    flex-wrap:wrap;
    justify-content:flex-end;
    gap:9px;
    max-width:430px;
}
.client-header-actions form{
    margin:0;
}
.client-header-actions .button{
    min-height:40px;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    white-space:nowrap;
}

/* Prominent, consistent record navigation. */
.client-section-tabs{
    display:flex;
    gap:6px;
    overflow-x:auto;
    margin:0 0 20px;
    padding:7px;
    border:1px solid var(--line,#d9e2ec);
    border-radius:15px;
    background:#fff;
    box-shadow:0 6px 18px rgba(15,23,42,.04);
    scrollbar-width:thin;
}
.client-tab{
    display:flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    flex:0 0 auto;
    min-width:108px;
    min-height:48px;
    padding:9px 13px;
    border:1px solid transparent;
    border-radius:11px;
    color:#526274;
    font-weight:800;
    text-decoration:none;
    transition:background .15s ease,border-color .15s ease,color .15s ease;
}
.client-tab:hover{
    border-color:#cbd8e3;
    background:#f5f8fb;
    color:var(--brand,#174466);
}
.client-tab small{
    display:inline-grid;
    place-items:center;
    min-width:22px;
    height:22px;
    padding:0 6px;
    border-radius:999px;
    background:#edf2f6;
    color:#667788;
    font-size:11px;
    font-weight:900;
}
.client-tab.active{
    border-color:var(--brand,#174466);
    background:var(--brand,#174466);
    color:#fff;
    box-shadow:0 6px 16px rgba(23,68,102,.18);
}
.client-tab.active small{
    background:rgba(255,255,255,.18);
    color:#fff;
}
.client-workspace{
    display:block;
}

/* Financial snapshot cards. */
.client-financial-snapshot{
    display:grid;
    grid-template-columns:repeat(4,minmax(0,1fr));
    gap:14px;
    margin:0 0 18px;
}
.client-financial-snapshot.compact{
    margin-top:0;
}
.client-metric-card{
    position:relative;
    display:flex;
    flex-direction:column;
    gap:7px;
    min-height:128px;
    padding:20px;
    overflow:hidden;
    border:1px solid var(--line,#d9e2ec);
    border-radius:16px;
    background:#fff;
    color:inherit;
    text-decoration:none;
    box-shadow:0 7px 20px rgba(15,23,42,.045);
}
.client-metric-card::after{
    content:"";
    position:absolute;
    right:-20px;
    bottom:-28px;
    width:90px;
    height:90px;
    border-radius:50%;
    background:rgba(23,68,102,.045);
}
a.client-metric-card:hover{
    transform:translateY(-2px);
    border-color:#b9cbd9;
    box-shadow:0 12px 28px rgba(15,23,42,.08);
}
.client-metric-card>span{
    color:var(--muted,#64748b);
    font-size:12px;
    font-weight:900;
    letter-spacing:.055em;
    text-transform:uppercase;
}
.client-metric-card>strong{
    position:relative;
    z-index:1;
    color:var(--brand,#174466);
    font-size:29px;
    line-height:1.05;
}
.client-metric-card>small{
    position:relative;
    z-index:1;
    color:var(--muted,#64748b);
}
.client-metric-card.attention{
    border-color:#e9c45e;
    background:#fffaf0;
}
.client-metric-card.attention::after{
    background:rgba(205,135,0,.07);
}
.client-metric-card.attention>strong{
    color:#985c00;
}

/* Record detail cards. */
.client-workspace .card{
    border-radius:16px;
}
.client-workspace .detail-grid{
    gap:16px;
}
.client-workspace .card h2{
    color:var(--brand,#174466);
    font-size:19px;
}
.client-workspace .section-heading-row{
    gap:18px;
}
.client-workspace .section-heading-row p{
    margin-top:3px;
    color:var(--muted,#64748b);
}
.client-activity-card{
    overflow:hidden;
}
.client-payment-list{
    display:grid;
    gap:0;
}
.client-payment-list article{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:16px;
    padding:13px 0;
    border-bottom:1px solid var(--line,#d9e2ec);
}
.client-payment-list article:last-child{
    border-bottom:0;
}
.client-payment-list article div{
    display:flex;
    flex-direction:column;
    gap:3px;
}
.client-payment-list article strong{
    color:var(--brand,#174466);
    font-size:18px;
}
.client-payment-list article small,
.client-payment-list article>span{
    color:var(--muted,#64748b);
}

/* Tables on record pages. */
.client-workspace .responsive-table-wrap{
    border:1px solid var(--line,#d9e2ec);
    border-radius:13px;
    overflow:hidden;
}
.client-workspace .responsive-table{
    margin:0;
}
.client-workspace .responsive-table thead th{
    background:#f3f6f9;
    color:#506174;
    font-size:12px;
    letter-spacing:.035em;
    text-transform:uppercase;
}
.client-workspace .responsive-table tbody tr:hover{
    background:#f8fafc;
}
.client-workspace .record-link strong{
    color:var(--brand,#174466);
}

@media(max-width:1100px){
    .client-profile-header{
        flex-direction:column;
    }
    .client-header-actions{
        justify-content:flex-start;
        max-width:none;
    }
    .client-financial-snapshot{
        grid-template-columns:repeat(2,minmax(0,1fr));
    }
}
@media(max-width:700px){
    .client-profile-header{
        padding:19px;
    }
    .client-profile-main{
        align-items:flex-start;
    }
    .client-avatar{
        flex-basis:48px;
        width:48px;
        height:48px;
        border-radius:13px;
        font-size:21px;
    }
    .client-profile-meta{
        display:grid;
        gap:5px;
    }
    .client-header-actions{
        width:100%;
    }
    .client-header-actions .button,
    .client-header-actions form,
    .client-header-actions form .button{
        width:100%;
    }
    .client-section-tabs{
        margin-left:-2px;
        margin-right:-2px;
    }
    .client-tab{
        min-width:102px;
    }
    .client-financial-snapshot{
        grid-template-columns:1fr;
    }
    .client-metric-card{
        min-height:auto;
    }
}

/* AuntBird Activity Types manager v0.2 */

.activity-actions{
    display:flex;
    align-items:center;
    flex-wrap:wrap;
    gap:10px;
}
.activity-actions form{
    margin:0;
}
.activity-sort-input{
    width:86px;
    min-width:86px;
}
.activity-add-form{
    grid-template-columns:minmax(220px,1fr) 120px auto;
}
.status-inactive{
    background:#eef1f4;
    color:#64748b;
}
.danger-link{
    color:#a93232;
}
.danger-link:hover{
    color:#7d1d1d;
}
.muted-text{
    color:#7b8794;
    font-size:13px;
}
.section-heading-row p{
    margin:5px 0 0;
    color:#64748b;
}
@media(max-width:700px){
    .activity-add-form{
        grid-template-columns:1fr;
    }
    .activity-sort-input{
        width:100%;
    }
    .activity-actions{
        justify-content:flex-start;
    }
}
/* AuntBird Recurring Invoices v0.10 */
.compact-actions{display:flex;align-items:center;flex-wrap:wrap;gap:10px}
.compact-actions form{margin:0}
.status-inactive{background:#eef1f4;color:#64748b}
.toolbar h2{margin:0 0 4px}
.toolbar p{margin:0;color:#64748b}

/* AuntBird Invoice Add Line Items v0.10.3 */
.invoice-add-line-toolbar{
    display:flex;
    align-items:center;
    flex-wrap:wrap;
    gap:14px;
    margin:16px 0 24px;
}
.invoice-add-line-toolbar small{
    color:#64748b;
}
.new-invoice-line td{
    vertical-align:top;
    background:#fbfcfe;
}
.new-invoice-line select,
.new-invoice-line input{
    width:100%;
}
.new-line-engagement{
    margin-bottom:8px;
}
.new-line-basis-fields{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:10px;
}
.new-line-basis-fields label span{
    display:block;
    margin-bottom:4px;
    color:#64748b;
    font-size:12px;
    font-weight:700;
    text-transform:uppercase;
}
.remove-new-line{
    display:inline-block;
    margin-top:8px;
}
.danger-link{
    color:#a93232;
}
@media(max-width:700px){
    .new-line-basis-fields{
        grid-template-columns:1fr;
    }
}
/* AuntBird Invoice Totals & Balances v0.10.6 */
.invoice-financial-summary{
    width:min(440px,100%);
    margin:28px 0 0 auto;
    border:1px solid #d8e0ea;
    border-radius:14px;
    overflow:hidden;
    background:#fff;
}
.invoice-summary-row{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:24px;
    padding:12px 16px;
    border-bottom:1px solid #e7edf4;
}
.invoice-summary-row:last-child{
    border-bottom:0;
}
.invoice-summary-row span{
    color:#536579;
}
.invoice-summary-row strong{
    color:#10283f;
    white-space:nowrap;
}
.invoice-summary-total{
    background:#f5f8fb;
    font-size:1.05rem;
}
.invoice-summary-payment strong{
    color:#24714a;
}
.invoice-summary-current-due{
    font-size:1.08rem;
    background:#eef5fb;
}
.invoice-summary-past-due{
    background:#fff4f1;
}
.invoice-summary-past-due span,
.invoice-summary-past-due strong{
    color:#a3392d;
}
.invoice-summary-account-balance{
    background:#123a58;
    font-size:1.12rem;
}
.invoice-summary-account-balance span,
.invoice-summary-account-balance strong{
    color:#fff;
}
.invoice-balance-note{
    width:min(440px,100%);
    margin:10px 0 0 auto;
    color:#64748b;
    font-size:.9rem;
    line-height:1.45;
}
@media(max-width:700px){
    .invoice-financial-summary,
    .invoice-balance-note{
        width:100%;
    }
}
/* AuntBird Payments Module v0.11 */
.payment-allocation-summary{width:min(430px,100%);margin:24px 0 20px auto;border:1px solid #dbe3ec;border-radius:12px;overflow:hidden}
.payment-allocation-summary>div{display:flex;justify-content:space-between;padding:11px 15px;border-bottom:1px solid #e8edf3}
.payment-allocation-summary>div:last-child{border-bottom:0;background:#eef6fb}
.payment-receipt-amount{font-size:2rem;color:#123a58}
.status-voided,.status-reversed,.status-refunded{background:#f8e9e7;color:#9b3027}
.danger-button{background:#9b3027;border-color:#9b3027}
.payment-client-picker{margin:0}

/* AuntBird Payment Client Search v0.11.1 */
.payment-client-picker{
    margin:0;
}
.payment-client-picker>label{
    display:block;
    margin-bottom:8px;
    font-weight:700;
}
.client-picker-grid{
    display:grid;
    grid-template-columns:minmax(260px,1fr) minmax(280px,1fr) auto;
    align-items:start;
    gap:12px;
}
.client-search-field,
.client-select-field{
    min-width:0;
}
.client-search-field input,
.client-select-field select{
    width:100%;
}
.client-search-field small{
    display:block;
    margin-top:6px;
    color:#64748b;
}
.client-search-status{
    min-height:20px;
    margin-top:8px;
    color:#52677c;
    font-size:.9rem;
}
@media(max-width:800px){
    .client-picker-grid{
        grid-template-columns:1fr;
    }
    .client-picker-grid .button{
        width:100%;
    }
}
/* AuntBird Live Client Search v0.11.2 */
.client-autocomplete{
    position:relative;
    min-width:0;
}
.client-search-results{
    position:absolute;
    z-index:50;
    top:calc(100% - 22px);
    left:0;
    right:0;
    max-height:320px;
    overflow-y:auto;
    background:#fff;
    border:1px solid #cfd9e5;
    border-radius:10px;
    box-shadow:0 14px 30px rgba(15,39,61,.16);
}
.client-search-result{
    display:block;
    width:100%;
    padding:11px 14px;
    border:0;
    border-bottom:1px solid #edf1f5;
    background:#fff;
    color:#173a56;
    text-align:left;
    cursor:pointer;
}
.client-search-result:last-child{
    border-bottom:0;
}
.client-search-result:hover,
.client-search-result:focus{
    background:#eef6fb;
    outline:none;
}
/* AuntBird Employees & Rates v0.12 */
.rate-priority-note{
    margin:0 0 18px;
    padding:12px 14px;
    border-left:4px solid #2d79ae;
    background:#eef6fb;
    color:#24465f;
}
.employee-rate-form{
    margin-bottom:24px;
}
.employee-rate-form .filter-actions{
    align-self:end;
}
@media(max-width:800px){
    .employee-rate-form{
        grid-template-columns:1fr;
    }
}
/* AuntBird Clients Live Search v0.12.4 */
.client-live-search-form{
    flex:1;
}
.client-live-search{
    min-width:280px;
    flex:1;
}
.client-live-search input{
    width:100%;
}
.client-live-search small{
    display:block;
    min-height:18px;
    margin-top:5px;
    color:#64748b;
}
.client-search-row[hidden]{
    display:none;
}
.client-live-empty{
    margin-top:20px;
}
@media(max-width:800px){
    .client-live-search-form{
        width:100%;
    }
    .client-live-search{
        min-width:0;
        width:100%;
    }
}



/* AuntBird application branding */
.sidebar-brand .brand-mark,
.public-brand .brand-mark {
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(255, 255, 255, .24);
    box-shadow: 0 5px 14px rgba(0, 0, 0, .16);
}

.sidebar-brand .brand-mark img,
.public-brand .brand-mark img,
.mobile-brand-mark img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.mobile-brand-mark {
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    box-shadow: 0 3px 9px rgba(18, 49, 75, .12);
}

/* Stripe Connect and invoice collection */
.stripe-connect-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:1rem;margin:1rem 0}.stripe-status-item{padding:1rem;border:1px solid #d9dee7;border-radius:10px;background:#fff}.stripe-status-item span{display:block;color:#667085;font-size:.85rem;margin-bottom:.3rem}.stripe-connected{color:#18794e}.stripe-pending{color:#9a6700}.stripe-disconnected{color:#b42318}.stripe-payment-note{margin-top:.75rem;font-size:.92rem;color:#667085}


/* Platform superadmin firm impersonation */
.impersonation-banner{position:sticky;top:0;z-index:1000;display:flex;align-items:center;justify-content:space-between;gap:16px;padding:10px 20px;background:#fff4cc;border-bottom:1px solid #d8a900;color:#563f00;box-shadow:0 2px 8px rgba(18,49,75,.12)}
.impersonation-banner form{margin:0;flex:0 0 auto}.impersonation-banner button{border:0;border-radius:8px;background:#12314b;color:#fff;font:inherit;font-weight:800;padding:8px 13px;cursor:pointer}.impersonation-banner button:hover{background:#0b253b}
@media(max-width:700px){.impersonation-banner{align-items:stretch;flex-direction:column;padding:10px 12px}.impersonation-banner button{width:100%}}
