/* HourBank screens: flat, one border style, one radius, one spacing scale. Scoped so Perfex's own pages are not touched. */
.hourbank-page,
.hourbank-portal {
    --hb-border: #e2e8f0;
    --hb-radius: 6px;
    --hb-gap: 20px;
    --hb-pad: 24px;
}

.hourbank-page *,
.hourbank-portal * {
    box-shadow: none !important;
    text-shadow: none !important;
}

/* Perfex wraps tab content in its own panel; keep that flat too when it holds a HourBank tab. */
.panel_s:has(> .panel-body > .hourbank-page),
.panel_s:has(.hourbank-page) {
    box-shadow: none !important;
}

.hourbank-page .panel_s,
.hourbank-portal .panel_s {
    border: 1px solid var(--hb-border);
    border-radius: var(--hb-radius);
    background: #fff;
    margin-bottom: var(--hb-gap);
}

.hourbank-page .panel_s > .panel-body,
.hourbank-portal .panel_s > .panel-body {
    padding: var(--hb-pad);
}

.hourbank-page .panel-footer,
.hourbank-portal .panel-footer {
    border-top: 1px solid var(--hb-border);
    border-radius: 0 0 var(--hb-radius) var(--hb-radius);
    background: #f8fafc;
    padding: 16px var(--hb-pad);
}

.hourbank-page .btn,
.hourbank-portal .btn,
.hourbank-page .form-control,
.hourbank-portal .form-control,
.hourbank-page .bootstrap-select > .dropdown-toggle,
.hourbank-page .alert,
.hourbank-portal .alert {
    border-radius: var(--hb-radius);
}

.hourbank-page .btn,
.hourbank-portal .btn {
    border-width: 1px;
}

.hourbank-page .alert,
.hourbank-portal .alert {
    border: 1px solid var(--hb-border);
    border-inline-start-width: 4px;
}

.hourbank-page .progress,
.hourbank-portal .progress {
    border-radius: var(--hb-radius);
    border: 1px solid var(--hb-border);
    background: #f1f5f9;
}

.hourbank-page .nav-tabs,
.hourbank-portal .nav-tabs {
    border-bottom: 1px solid var(--hb-border);
}

.hourbank-page .table > thead > tr > th,
.hourbank-portal .table > thead > tr > th {
    border-bottom: 1px solid var(--hb-border);
    font-weight: 600;
}

.hourbank-page .table > tbody > tr > td,
.hourbank-portal .table > tbody > tr > td {
    border-top: 1px solid var(--hb-border);
}

.hourbank-page h4,
.hourbank-portal h4 {
    margin-top: 0;
}

.hourbank-page .dropdown-menu,
.hourbank-page .modal-content,
.hourbank-portal .dropdown-menu {
    border: 1px solid var(--hb-border);
    border-radius: var(--hb-radius);
}

@media (max-width: 480px) {
    .hourbank-portal .table > tbody > tr > td,
    .hourbank-portal .table > thead > tr > th {
        padding: 6px 4px;
        font-size: 13px;
    }
}


/* ------------------------------------------------------------------ spacing
   One rhythm for every HourBank screen: 8, 12, 16, 20, 24 px. The defaults use :where() so they have no weight of their own and
   a spacing class written on an element in a view (tw-mt-3 and so on) still wins. */
:where(.hourbank-page, .hourbank-portal) {
    --hb-text: #334155;
}

:where(.hourbank-page, .hourbank-portal) p {
    margin: 0 0 16px;
    line-height: 1.55;
}

:where(.hourbank-page, .hourbank-portal) p:last-child {
    margin-bottom: 0;
}

/* The title line of a panel */
.hourbank-page .panel_s > .panel-body > p.bold:first-child,
.hourbank-portal .panel_s > .panel-body > p.bold:first-child,
.hourbank-page .panel_s > .panel-body > h4:first-child,
.hourbank-portal .panel_s > .panel-body > h4:first-child {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
    margin: 0 0 16px;
    color: #1e293b;
}

/* Page heading and the buttons next to it */
.hourbank-page .tw-flex.tw-justify-between,
.hourbank-portal .tw-flex.tw-justify-between {
    gap: 16px;
    flex-wrap: wrap;
}

.hourbank-page .content > .row > div > h4:first-child,
.hourbank-page .content > .row > div > .tw-flex:first-child {
    margin-bottom: 24px;
}

/* A row of buttons: never touching, wraps on a small screen */
.hb-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.hb-toolbar form {
    display: inline-block;
    margin: 0;
}

:where(.hourbank-page, .hourbank-portal) .btn + .btn,
:where(.hourbank-page, .hourbank-portal) .btn + form,
:where(.hourbank-page, .hourbank-portal) form + .btn,
:where(.hourbank-page, .hourbank-portal) form + form,
:where(.hourbank-page, .hourbank-portal) .btn + a.btn {
    margin-inline-start: 8px;
}

.hb-toolbar .btn + .btn,
.hb-toolbar .btn + form,
.hb-toolbar form + .btn {
    margin-inline-start: 0;
}

/* Tables */
:where(.hourbank-page, .hourbank-portal) .table {
    margin-bottom: 0;
}

:where(.hourbank-page, .hourbank-portal) .table-responsive {
    margin-bottom: 0;
    border: 0;
}

.hourbank-page .table > thead > tr > th,
.hourbank-page .table > tbody > tr > td,
.hourbank-portal .table > thead > tr > th,
.hourbank-portal .table > tbody > tr > td {
    padding: 12px 16px;
    vertical-align: middle;
    line-height: 1.5;
}

.hourbank-page .table > thead > tr > th:first-child,
.hourbank-page .table > tbody > tr > td:first-child,
.hourbank-portal .table > thead > tr > th:first-child,
.hourbank-portal .table > tbody > tr > td:first-child {
    padding-inline-start: 0;
}

.hourbank-page .table > thead > tr > th:last-child,
.hourbank-page .table > tbody > tr > td:last-child,
.hourbank-portal .table > thead > tr > th:last-child,
.hourbank-portal .table > tbody > tr > td:last-child {
    padding-inline-end: 0;
}

.hourbank-page .table > tbody > tr:first-child > td {
    border-top: 0;
}

/* Forms */
:where(.hourbank-page) .form-group {
    margin-bottom: 20px;
}

:where(.hourbank-page) .control-label,
:where(.hourbank-page) label {
    margin-bottom: 8px;
}

:where(.hourbank-page, .hourbank-portal) .checkbox,
:where(.hourbank-page, .hourbank-portal) .radio {
    margin: 12px 0;
}

:where(.hourbank-page) .checkbox + .checkbox,
:where(.hourbank-page) .radio + .radio {
    margin-top: 12px;
}

:where(.hourbank-page, .hourbank-portal) hr {
    margin: 24px 0;
    border-top: 1px solid var(--hb-border);
}

:where(.hourbank-page, .hourbank-portal) ul:not(.nav):not(.dropdown-menu) {
    padding-inline-start: 20px;
    margin: 0 0 12px;
}

:where(.hourbank-page, .hourbank-portal) ul:not(.nav):not(.dropdown-menu) > li {
    margin-bottom: 8px;
}

/* Tabs and what is under them */
.hourbank-page .nav-tabs {
    margin-bottom: 0;
}

.hourbank-page .nav-tabs > li > a {
    padding: 12px 18px;
    margin-inline-end: 4px;
}

.hourbank-page .tab-content.tw-mt-4,
.hourbank-page .tab-content {
    padding-top: 24px;
}

.hourbank-page .panel_s > .panel-body > .nav-tabs + .tab-content {
    margin-top: 0;
}

/* Input with a button joined to it */
.hourbank-page .input-group .form-control,
.hourbank-portal .input-group .form-control {
    height: 38px;
}

.hourbank-page .input-group-btn > .btn,
.hourbank-portal .input-group-btn > .btn {
    height: 38px;
    margin-inline-start: -1px;
    border-radius: 0 var(--hb-radius) var(--hb-radius) 0;
}

.hourbank-page .input-group .form-control:first-child,
.hourbank-portal .input-group .form-control:first-child {
    border-radius: var(--hb-radius) 0 0 var(--hb-radius);
}

/* Small helper text under a control */
.hourbank-page .help-block,
.hourbank-page p.text-muted {
    line-height: 1.5;
}

/* Status labels */
.hourbank-page .label,
.hourbank-portal .label {
    display: inline-block;
    padding: 4px 10px;
    border-radius: var(--hb-radius);
    line-height: 1.3;
}

/* On a phone: the same rhythm with less padding, buttons never run together */
@media (max-width: 767px) {
    .hourbank-page,
    .hourbank-portal {
        --hb-pad: 16px;
        --hb-gap: 16px;
    }

    .hourbank-page .btn,
    .hourbank-portal .btn {
        margin-bottom: 8px;
    }

    .hourbank-page .table > thead > tr > th,
    .hourbank-page .table > tbody > tr > td {
        padding: 10px 12px;
    }
}


/* ------------------------------------------------------------------ polish, round two */

/* Tables that sit straight under a panel title start at the title's spacing, and end at the panel's padding */
.hourbank-page .panel-body > .table-responsive:first-child > .table > thead > tr:first-child > th,
.hourbank-page .panel-body > .table:first-child > thead > tr:first-child > th,
.hourbank-portal .panel-body > .table-responsive:first-child > .table > thead > tr:first-child > th {
    padding-top: 0;
}

.hourbank-page .panel-body > .table-responsive > .table > tbody > tr:last-child > td,
.hourbank-page .panel-body > .table > tbody > tr:last-child > td,
.hourbank-portal .panel-body > .table-responsive > .table > tbody > tr:last-child > td {
    padding-bottom: 0;
}

.hourbank-page .panel-body > p.bold:first-child + .table-responsive > .table > tbody > tr:first-child > td,
.hourbank-page .panel-body > p.bold:first-child + .table > tbody > tr:first-child > td,
.hourbank-portal .panel-body > p.bold:first-child + .table-responsive > .table > tbody > tr:first-child > td {
    padding-top: 0;
}

/* Perfex's own list tables (DataTables) keep a full-width layout with roomy first and last cells */
.hourbank-page .panel-table-full .table > thead > tr > th,
.hourbank-page .panel-table-full .table > tbody > tr > td {
    vertical-align: middle;
}

.hourbank-page .panel-table-full .table > thead > tr > th:first-child,
.hourbank-page .panel-table-full .table > tbody > tr > td:first-child {
    padding-inline-start: 16px;
}

.hourbank-page .panel-table-full .table > thead > tr > th:last-child,
.hourbank-page .panel-table-full .table > tbody > tr > td:last-child {
    padding-inline-end: 16px;
}

.hourbank-page .panel-table-full .row-options {
    margin-top: 4px;
}

.hourbank-page .panel-table-full .dataTables_wrapper .row,
.hourbank-page .panel-table-full .row.tw-mb-3 {
    margin-bottom: 16px;
}

/* Panel footer: buttons in one row, never touching */
.hourbank-page .panel-footer.text-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.hourbank-page .panel-footer .checkbox {
    margin: 0 8px 0 0;
}

/* A label with its Yes / No choices: the label on its own line, the choices under it */
.hourbank-page .form-group > .control-label {
    display: block;
}

.hourbank-page .radio-inline,
.hourbank-page .checkbox-inline {
    display: inline-block;
    margin: 0 24px 0 0;
    padding-top: 4px;
}

/* Stat blocks (hours left, billing cycle, price) stack with a gap on a phone */
.hb-stat {
    margin-bottom: 20px;
}

@media (min-width: 768px) {
    .hb-stat {
        margin-bottom: 0;
    }
}

/* Tabs scroll sideways on a phone instead of wrapping into rows */
@media (max-width: 767px) {
    .hourbank-page .nav-tabs {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    .hourbank-page .nav-tabs > li {
        float: none;
        flex: 0 0 auto;
    }
}

/* The summary text of a statement wraps instead of running off a narrow screen */
.hb-summary {
    display: block;
    white-space: normal;
    word-break: break-word;
    margin-top: 4px;
}

/* Work categories: one grid for the heading, every row and the add row */
.hb-cat-grid {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(220px, 3fr) 64px 150px;
    gap: 12px 16px;
    align-items: center;
    margin: 0 0 12px;
}

.hb-cat-head {
    font-weight: 600;
    margin-bottom: 12px;
}

.hb-cat-grid .checkbox {
    margin: 0;
}

.hb-cat-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.hb-cat-actions .btn {
    margin: 0;
}

@media (max-width: 767px) {
    .hb-cat-grid {
        grid-template-columns: 1fr;
        padding-bottom: 16px;
        border-bottom: 1px solid var(--hb-border);
    }

    .hb-cat-head {
        display: none;
    }

    .hb-cat-actions {
        justify-content: flex-start;
    }
}

/* Perfex's settings page: when it shows a HourBank group the whole page is flat, like the rest of HourBank */
#wrapper:has(.hourbank-page) .panel_s {
    box-shadow: none !important;
}

/* Hints, notes and results below a heading or a field get room */
.hourbank-page .hourbank-triage .table {
    margin-top: 4px;
}

.hourbank-page .hourbank-triage .hb-pinpoint {
    margin-top: 24px;
}

.hourbank-page .text-warning,
.hourbank-page .text-danger {
    display: inline-block;
    margin-top: 4px;
}

/* The filter and bulk row above the agreements list */
.hb-filters {
    margin-bottom: 16px;
}

.hb-filters .form-group {
    margin-bottom: 0;
}

/* Perfex's top bar has a soft shadow; on HourBank pages it is a plain line like everything else */
body:has(.hourbank-page) #header,
body:has(.hourbank-portal) #header {
    box-shadow: none !important;
    border-bottom: 1px solid var(--hb-border, #e2e8f0);
}

/* A table right after the panel title: the title's own spacing is the only gap */
.hourbank-page .panel-body > p.bold:first-child + .table-responsive > .table > thead > tr:first-child > th,
.hourbank-portal .panel-body > p.bold:first-child + .table-responsive > .table > thead > tr:first-child > th,
.hourbank-page .panel-body > h4:first-child + .table-responsive > .table > thead > tr:first-child > th {
    padding-top: 0;
}

/* A list straight under the tabs starts at the tab spacing only */
.hourbank-page .tab-pane > .table-responsive:first-child > .table > thead > tr:first-child > th {
    padding-top: 0;
}

/* Row actions sit in their own column, buttons spaced like the toolbars */
.hourbank-page .hb-toolbar-end {
    justify-content: flex-end;
}

.hourbank-page td > .hb-toolbar form {
    margin: 0;
}

/* Perfex gives every table a 25px top margin; spacing here comes from the title above it */
.hourbank-page .table,
.hourbank-portal .table {
    margin-top: 0;
}

/* A toolbar inside a table cell: no outer margin, buttons stay on one line */
.hourbank-page td > .hb-toolbar {
    margin-bottom: 0;
    flex-wrap: nowrap;
    white-space: nowrap;
}

/* Right-to-left: spacing utilities follow the reading direction, charts keep their own left-to-right axis */
.hourbank-page .tw-mr-1,
.hourbank-portal .tw-mr-1 { margin-right: 0; margin-inline-end: 0.25rem; }
.hourbank-page .tw-mr-4,
.hourbank-portal .tw-mr-4 { margin-right: 0; margin-inline-end: 1rem; }
.hourbank-page .tw-ml-2,
.hourbank-portal .tw-ml-2 { margin-left: 0; margin-inline-start: 0.5rem; }
.hourbank-page .tw-ml-6,
.hourbank-portal .tw-ml-6 { margin-left: 0; margin-inline-start: 1.5rem; }

.hourbank-page svg,
.hourbank-portal svg {
    direction: ltr;
}

/* Mixed text and numbers (10 h, 30%) keep their own order inside a right-to-left page */
.hourbank-page :is(p, td, th, li, label, h1, h2, h3, h4, h5, h6, strong, small, .bold, .text-muted),
.hourbank-portal :is(p, td, th, li, label, h1, h2, h3, h4, h5, h6, strong, small, .bold, .text-muted) {
    unicode-bidi: plaintext;
}

/* A row of filters inside a tab: fields and buttons side by side, wrapping on a phone */
.hb-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.hb-filter-bar .hb-filter-field {
    flex: 0 1 220px;
    min-width: 150px;
}

.hb-filter-bar .form-control {
    width: 100%;
}
