/* Permit Document Renderer Styles */

/* Requirements Profile editor: keep the requirement text readable next to many criteria columns */
.profile-req-table td:nth-child(2),
.profile-req-table th:nth-child(2) {
    min-width: 420px;
}

.profile-edit-section:has(.profile-req-table) {
    overflow-x: auto;
}

/* PTW Templates */
.page-intro {
    font-size: 14px;
    font-weight: 500;
    color: #222;
    margin: 0 0 16px;
    max-width: 900px;
}

.ptw-template-list__desc {
    font-size: 13px;
    font-weight: 500;
    color: #444;
    margin-top: 2px;
}

.ptw-template-list__sections {
    margin: 0;
    padding-left: 18px;
    font-size: 14px;
    font-weight: 500;
    color: #222;
}

.ptw-template-list__actions {
    white-space: nowrap;
}

.ptw-template-list__actions .btn + .btn {
    margin-left: 6px;
}

.ptw-template-builder__save-state {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-success, #16a34a);
}

.ptw-template-builder__roles {
    margin-top: 10px;
}

.ptw-template-builder__profile-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 16px;
    font-weight: 700;
    color: var(--color-primary, #003369);
}

.ptw-template-builder__profile-link:hover {
    text-decoration: underline;
}

/* Signatory Profiles: numbered signature roles */
.sig-role-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    background: var(--color-primary, #003369);
    color: #fff;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.sig-profile-list__num {
    width: 48px;
    text-align: center;
    font-weight: 700;
}

.sig-profile-list__roles {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sig-profile-list__roles li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #222;
}

.sig-roles-table {
    margin-bottom: 12px;
}

.sig-roles-table__num {
    width: 64px;
    text-align: center;
}

.sig-roles-table__new {
    font-size: 13px;
    font-weight: 600;
    color: #444;
}

.sig-roles-table__person {
    min-width: 280px;
}

.sig-roles-table__cancel {
    margin-top: 6px;
}

.sig-roles-table__add {
    margin-top: 4px;
}

/* Signatures panel on the permit page (SHEQhub signature requests) */
.sig-requests {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 16px;
    margin: 16px auto 0;
    max-width: 1200px;
}

.sig-requests__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.sig-requests__title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--color-primary, #003369);
}

.sig-requests__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.sig-requests__table {
    margin-top: 10px;
}

.sig-requests__num {
    width: 56px;
    text-align: center;
}

.sig-requests__action {
    width: 140px;
    white-space: nowrap;
}

.sig-requests__email,
.sig-requests__when {
    font-size: 13px;
    font-weight: 500;
    color: #444;
    margin-top: 2px;
}

.sig-requests__msg {
    border-radius: 6px;
    padding: 10px 12px;
    margin-top: 8px;
    font-size: 14px;
    font-weight: 600;
    border-left: 4px solid;
}

.sig-requests__msg--ok {
    background: #ecfdf3;
    color: #14532d;
    border-color: var(--color-success, #16a34a);
}

.sig-requests__msg--error {
    background: #fef2f2;
    color: #9b1c1c;
    border-color: var(--color-error, #c62828);
}

@media (max-width: 700px) {
    .sig-requests__action {
        width: auto;
    }
}

/* Person picker (wizard, Signatory Profiles) */
.wizard-result {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    background: #e8f5e9;
    border-radius: 6px;
    margin-top: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #222;
}

/* Safety file found by its reference number (New Permit wizard) */
.wizard-safetyfile {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 10px 12px;
    background: #e8f5e9;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #222;
}

.wizard-safetyfile__row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.wizard-safetyfile .btn {
    margin-top: 6px;
}

.wizard-search-results {
    display: flex;
    flex-direction: column;
    gap: 2px;
    border: 1px solid #ddd;
    border-radius: 6px;
    max-height: 180px;
    overflow-y: auto;
    background: #fff;
    margin-top: 6px;
}

.wizard-search-result {
    display: flex;
    flex-direction: column;
    padding: 8px 10px;
    cursor: pointer;
    font-size: 14px;
    color: #222;
}

.wizard-search-result:hover {
    background: #f0f4ff;
}

.wizard-search-result strong {
    font-weight: 600;
}

.wizard-search-result span {
    font-size: 13px;
    color: #444;
}

/* Requirements page – tab action buttons */
.requirements-tab-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin: 16px 0 8px;
}

/* Shared lookup helpers (used by the create wizard, profile editor and permit builder) */
.wizard-search {
    display: flex;
    gap: 8px;
    align-items: center;
}

.wizard-search .form-control {
    flex: 1;
}

.wizard-loading,
.wizard-empty {
    font-size: 14px;
    font-weight: 500;
    color: #444;
    padding: 4px 0;
}

.permit-document {
    background: #fff;
    max-width: 1200px;   /* permits are wide forms (requirements + criteria columns) */
    margin: 0 auto;
    padding: 24px;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

/* Sections */
.permit-document__section {
    margin-bottom: 0;
    border-bottom: 1px solid #eee;
}

.permit-document__section:last-child {
    border-bottom: none;
}

.permit-document__section-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-primary, #003369);
    padding: 12px 0 8px;
    border-bottom: 1px solid #ddd;
    margin-bottom: 8px;
}

.permit-document__excel {
    overflow-x: auto;
}

/* Values captured on the permit, shown in a read-only (finalised / printed) permit */
.excel-cell--captured {
    font-weight: 600;
    color: #111;
}

/* Signature Slots */
.permit-document__signatures-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
    padding: 12px 0;
}

.permit-document__signature-slot {
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 12px;
    cursor: default;
    transition: border-color 0.15s;
}

.permit-document__signature-slot--pending {
    border-style: dashed;
    border-color: #ccc;
}

.permit-document__signature-slot--signed {
    border-color: var(--color-success, #16a34a);
    background: #f0fdf4;
}

.permit-document__signature-slot:hover {
    border-color: var(--color-primary, #003369);
}

.permit-document__signature-slot-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.permit-document__signature-slot-number {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary, #003369);
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.permit-document__signature-slot-label {
    font-size: 14px;
    font-weight: 600;
    color: #222;
}

.permit-document__signature-slot-person {
    font-size: 14px;
    font-weight: 500;
    color: #222;
    margin-bottom: 8px;
}

.permit-document__signature-slot-empnr {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #444;
    overflow-wrap: anywhere;
}

.permit-document__signature-slot-area {
    min-height: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.permit-document__signature-img {
    max-width: 180px;
    max-height: 48px;
    object-fit: contain;
}

.permit-document__signature-date {
    font-size: 12px;
    font-weight: 500;
    color: #444;
    margin-top: 4px;
}

.permit-document__signature-pending-text {
    font-size: 14px;
    font-weight: 500;
    color: #444;
}

/* Sign Modal */
.sign-modal {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sign-modal__info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px;
    background: #f4f7f8;
    border-radius: 8px;
}

.sign-modal__info-row {
    display: flex;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #222;
}

.sign-modal__label {
    font-weight: 700;
    min-width: 100px;
}

.sign-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

.sign-modal__stored-sig {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sign-modal__sig-preview {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    background: #fff;
}

.sign-modal__sig-preview img {
    max-width: 240px;
    max-height: 80px;
    object-fit: contain;
}

.sign-modal__notice {
    font-size: 14px;
    font-weight: 500;
    color: #444;
    margin: 0;
}

.sign-modal__draw {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Full-size signing pad inside the sign modal (SignatureField defaults to a 36px table-cell pad) */
.sign-modal__draw .ptw-signature canvas {
    height: 160px;
    background: #fff;
    border: 2px dashed var(--color-border, #ccc);
    border-radius: 8px;
    touch-action: none;
    cursor: crosshair;
}

.sign-modal__draw .ptw-signature img {
    max-height: 160px;
    border: 2px solid var(--color-border, #ccc);
    border-radius: 8px;
    background: #fff;
}

/* SHEQhub check results (criteria columns checked against the safety file) */
.permit-document__sheqhub-pass {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: #dcfce7;
    color: #166534;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
}

.permit-document__sheqhub-fail {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: #fef2f2;
    color: #991b1b;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
}

/* A very wide requirements table scrolls inside its own section, not the whole page */
.requirements-section-editor {
    overflow-x: auto;
}

/* Requirements table: keep the requirement itself readable when many criteria columns are present */
.requirements-section-editor .data-table td:nth-child(2),
.requirements-section-editor .data-table th:nth-child(2) {
    min-width: 260px;
}

/* Criteria column widths (Narrow / Medium / Wide / Extra Wide as configured on the criteria profile) */
.crit-col--narrow { min-width: 100px; }
.crit-col--medium { min-width: 130px; }
.crit-col--wide { min-width: 180px; }
.crit-col--extrawide { min-width: 280px; }

.requirements-section-editor td .form-control {
    min-width: 0;
    width: 100%;
}

.req-text {
    font-size: 14px;
    font-weight: 500;
    color: #222;
    line-height: 1.35;
}

.req-signature-img {
    max-height: 34px;
    max-width: 160px;
}

/* Requirement text (an added requirement is typed in place) */
.req-text-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.req-text-cell .form-control {
    flex: 1;
    min-width: 160px;
}

.permit-document__sheqhub-pass,
.permit-document__sheqhub-fail,
.permit-document__sheqhub-pending {
    white-space: nowrap;
}

.permit-document__sheqhub-pending {
    display: inline-block;
    padding: 2px 8px;
    border: 1px dashed #64748b;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    color: #333;
}

/* "SHEQhub check" tag under the header of a column that is checked automatically */
.crit-col__source {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    opacity: 0.9;
}

/* Under the checklist: what each SHEQhub column was checked against, the result and when */
.req-sheqhub-notes {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.req-sheqhub-note {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    color: #222;
}

/* Requirements Profile editor: a SHEQhub column has no default value */
.profile-req-table__auto {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary, #003369);
}

/* Criteria Profile editor: the SHEQhub criterion a column is checked against */
.criteria-edit__sheqhub {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #222;
}

.criteria-edit__sheqhub--missing {
    color: var(--color-error, #c0392b);
    font-weight: 600;
}

.criteria-edit__intro {
    margin: 0 0 12px;
    font-size: 14px;
    font-weight: 500;
    color: #222;
}

/* Print page actions */
.permit-print__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 0;
}

/* Clickable data table rows */
.data-table__row--clickable {
    cursor: pointer;
}

.data-table__row--clickable:hover {
    background: #f0f4ff;
}

/* Page header meta */
.page-header__meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #222;
}

/* Print styles */
@media print {
    body * {
        visibility: hidden;
    }

    .permit-document,
    .permit-document * {
        visibility: visible;
    }

    .permit-document {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        margin: 0;
        padding: 16px;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    .page-header,
    .ptw-actions,
    .ptw-info-banner,
    .ptw-readonly-banner,
    .permit-print__actions,
    nav,
    .sidebar,
    .app-shell__sidebar {
        display: none !important;
    }

    .permit-document__signature-slot--pending {
        border-style: dashed;
    }

    .permit-document__signature-pending-text {
        color: #444;
    }

    /* Export / print: the whole permit must fit the page width - nothing may be cut off.
       On screen wide tables scroll sideways; on paper they are shrunk to fit instead. */
    @page {
        size: A4;
        margin: 10mm;
    }

    html,
    body,
    body *:not(.permit-document):not(.permit-document *) {
        background: transparent !important;
        box-shadow: none !important;
        border-color: transparent !important;
    }

    .permit-document__excel,
    .requirements-section-editor {
        overflow: visible !important;
    }

    /* Requirements table: always exactly the permit width, like the form sections around it.
       Fixed layout + the percentage <colgroup> means the content can never push the table wider;
       long values wrap inside their cell instead. */
    .requirements-section-editor .data-table {
        display: table !important;
        width: 100% !important;
        max-width: 100%;
        table-layout: fixed;
        font-size: 11px;
    }

    .requirements-section-editor .data-table th,
    .requirements-section-editor .data-table td {
        min-width: 0 !important;
        padding: 4px 5px;
        font-size: 11px;
        white-space: normal !important;
        overflow-wrap: anywhere;
        word-break: break-word;
        hyphens: auto;
    }

    .requirements-section-editor .data-table td:nth-child(2),
    .requirements-section-editor .data-table th:nth-child(2) {
        min-width: 0 !important;
    }

    .crit-col--narrow,
    .crit-col--medium,
    .crit-col--wide,
    .crit-col--extrawide {
        min-width: 0 !important;
    }

    .req-text,
    .permit-document__sheqhub-pass,
    .permit-document__sheqhub-fail,
    .permit-document__sheqhub-pending {
        font-size: 11px;
        white-space: normal;
    }

    .crit-col__source {
        font-size: 10px;
    }

    /* Printing straight from the permit page: inputs shrink with their column */
    .requirements-section-editor .data-table .form-control,
    .req-text-cell .form-control {
        min-width: 0 !important;
        width: 100%;
        padding: 2px 4px;
        font-size: 11px;
    }

    .req-signature-img {
        max-width: 100%;
        max-height: 28px;
    }

    /* Many criteria columns: denser text so the columns stay readable (never below 10px) */
    .req-table--dense th,
    .req-table--dense td,
    .req-table--dense .req-text,
    .req-table--very-dense th,
    .req-table--very-dense td,
    .req-table--very-dense .req-text {
        font-size: 10px !important;
    }

    .req-table--very-dense th,
    .req-table--very-dense td {
        padding: 3px 3px;
    }

    .requirements-section-editor tr,
    .permit-document__signature-slot {
        break-inside: avoid;
    }

    .permit-document__section-title {
        break-after: avoid;
    }

    /* A form section is never split over two pages (it moves to the next page instead) */
    .permit-document__excel {
        break-inside: avoid;
    }
}

/* Requirements table: number and action columns */
.req-col-num {
    width: 50px;
    text-align: center;
    font-weight: 500;
    color: #444;
}

.req-col-action {
    width: 60px;
    text-align: center;
}

/* Requirements / Criteria Profile editors */
.profile-edit-grid__row > .profile-edit-grid__main { flex: 2; }

.profile-edit-grid__row > .profile-edit-grid__check {
    flex: 1;
    display: flex;
    align-items: flex-end;
}

.empty-state--compact { padding: 24px; }

.requirements-list__actions { width: 180px; }

.criteria-edit__type { width: 260px; }
.criteria-edit__width { width: 130px; }
.criteria-edit__required { width: 100px; text-align: center; }

.criteria-edit__marker { margin-right: 6px; }

.criteria-edit__muted {
    font-weight: 500;
    color: #444;
}

.criteria-edit__name { display: inline-block; }
.criteria-edit__name--group { width: calc(100% - 26px); }
.criteria-edit__name--child { width: calc(100% - 40px); }

.criteria-edit__child-cell { padding-left: 32px; }

.permit-print__hint {
    font-size: 14px;
    font-weight: 500;
    color: #222;
    margin-right: auto;
    align-self: center;
}

/* Fill-in boxes of a form section (yellow cells) */
td.excel-cell--input { padding: 0 !important; }

.excel-cell__input {
    width: 100%;
    height: 100%;
    border: none;
    padding: 3px 5px;
    box-sizing: border-box;
    background: rgba(255, 255, 200, 0.3);
    font-size: inherit;
    font-family: inherit;
    font-weight: 600;
    color: #111;
}

.excel-section-viewer__empty {
    font-size: 14px;
    font-weight: 500;
    color: #444;
}

/* The section name is already the heading of every section on the permit: the workbook's own
   sheet title would repeat it, so it is not shown on the permit or in the PTW Template preview. */
.permit-document .ptw-sheet-title,
.ptw-template-builder .ptw-sheet-title,
.permit-builder__sections .ptw-sheet-title {
    display: none;
}

/* Signature boxes placed inside the form */
td.excel-sig {
    text-align: center;
    vertical-align: middle;
}

.excel-sig__img {
    display: block;
    max-width: 100%;
    max-height: 44px;
    margin: 0 auto;
    object-fit: contain;
}

.excel-sig__meta {
    font-size: 10px;
    font-weight: 600;
    color: #222;
    line-height: 1.2;
}

.excel-sig__btn {
    width: 100%;
    min-height: 34px;
    border: 2px dashed var(--color-primary, #003369);
    border-radius: 6px;
    background: #eef3fb;
    color: var(--color-primary, #003369);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    padding: 4px 6px;
}

.excel-sig__btn:hover {
    background: var(--color-primary, #003369);
    color: #fff;
}

.excel-sig__text {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-primary, #003369);
}

td.excel-sig--placeholder {
    outline: 2px dashed var(--color-primary, #003369);
    outline-offset: -3px;
}

/* PTW Template builder - signature boxes panel */
.ptw-template-builder__sig {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--color-border, #ddd);
    border-radius: 8px;
    background: #f8fafc;
}

.ptw-template-builder__sig-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.ptw-template-builder__sig-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--color-primary, #003369);
    margin: 0;
}

.ptw-template-builder__sig-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    border-top: 1px solid #e5e7eb;
    font-size: 14px;
    font-weight: 500;
    color: #222;
}

.ptw-template-builder__sig-cell { flex: 1; }
.ptw-template-builder__sig-role { white-space: nowrap; }

.excel-sig__who {
    display: block;
    font-size: 10px;
    font-weight: 600;
}

/* PTW Template builder: questions of a requirements section */
.req-col-required {
    width: 96px;
    text-align: center;
    line-height: 1.2;
}

.req-required-check {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.tpl-questions {
    margin: 12px 0 16px;
    padding: 12px;
    border: 1px solid var(--color-border, #d0d7de);
    border-radius: 8px;
    background: var(--color-white, #fff);
}

.tpl-questions__table {
    margin-top: 8px;
}

.tpl-questions__table .req-col-action {
    width: 100px;
    white-space: nowrap;
}

.tpl-questions__text {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text, #222);
}

.tpl-questions__from {
    width: 120px;
    text-align: center;
}

.tpl-questions__badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text, #222);
    background: #e8ecef;
}

.tpl-questions__badge--required {
    color: #fff;
    background: var(--color-primary, #003369);
}

.tpl-questions__badge--extra {
    color: #0b4f4a;
    background: var(--color-teal-bg, #e0f2f1);
}

.tpl-questions__lock {
    font-size: 15px;
    color: var(--color-primary, #003369);
}

.tpl-questions__row--removed .tpl-questions__text {
    text-decoration: line-through;
    color: #444;
}

.tpl-questions__add {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 10px;
}

.tpl-questions__add .form-control {
    flex: 1;
}

.tpl-questions__preview-title {
    margin-top: 12px;
    margin-bottom: 6px;
}

@media (max-width: 700px) {
    .tpl-questions__from { width: auto; }
    .tpl-questions__add { flex-direction: column; align-items: stretch; }
}
