/* ========================================================
   Permit to Work Form - Excel-replica styling
   ======================================================== */

/* Paper container */
.ptw-form {
    max-width: 210mm;
    margin: 0 auto;
    padding: 12px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.12);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10px;
    line-height: 1.3;
    color: #000;
}

/* Document-style tables (thin borders, no navy) */
.ptw-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 6px;
}

.ptw-table td,
.ptw-table th {
    border: 1px solid #000;
    padding: 3px 5px;
    vertical-align: middle;
    text-align: left;
}

/* Uploaded Excel sections: only the borders the workbook itself has (set per cell on import),
   so open areas stay open cells exactly like the original Excel permit */
.ptw-table.ptw-table--exact td,
.ptw-table.ptw-table--exact th {
    border: none;
}

/* Section headers - navy blue with white text */
.ptw-section-header {
    background: #003366;
    color: #fff;
    font-weight: 700;
    font-size: 11px;
    padding: 5px 8px !important;
    text-align: left;
}

.ptw-section-header--small {
    background: #003366;
    color: #fff;
    font-weight: 700;
    font-size: 10px;
    padding: 3px 6px !important;
}

/* Label cells - gray background */
.ptw-label {
    background: #D9D9D9;
    font-weight: 700;
    font-size: 9px;
    white-space: nowrap;
}

.ptw-label--wrap {
    background: #D9D9D9;
    font-weight: 700;
    font-size: 9px;
    white-space: normal;
}

/* Fillable yellow input cells */
.ptw-input-cell {
    background: #FFFFCC;
    min-width: 60px;
}

/* Transparent borderless inputs for yellow cells */
.ptw-input {
    width: 100%;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 10px;
    padding: 1px 2px;
    outline: none;
    color: #000;
    box-sizing: border-box;
}

.ptw-input:focus {
    background: #FFFF99;
}

.ptw-input--date {
    width: 100%;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 10px;
    padding: 1px 2px;
    outline: none;
    color: #000;
    max-width: 130px;
}

.ptw-input--time {
    width: 80px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 10px;
    padding: 1px 2px;
    outline: none;
    color: #000;
}

.ptw-select {
    width: 100%;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 10px;
    padding: 1px;
    outline: none;
    color: #000;
    cursor: pointer;
}

.ptw-textarea {
    width: 100%;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 10px;
    padding: 2px 4px;
    outline: none;
    color: #000;
    resize: vertical;
    min-height: 40px;
    box-sizing: border-box;
}

.ptw-textarea:focus {
    background: #FFFF99;
}

/* Checkbox styling */
.ptw-checkbox {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

/* Signature areas */
.ptw-signature {
    min-height: 36px;
    min-width: 100px;
    cursor: pointer;
    position: relative;
}

.ptw-signature canvas {
    border-bottom: 1px dotted #999;
    display: block;
    width: 100%;
    height: 36px;
}

.ptw-signature img {
    max-height: 34px;
    max-width: 100%;
}

.ptw-signature__placeholder {
    color: #999;
    font-size: 8px;
    font-style: italic;
    text-align: center;
    padding-top: 10px;
}

/* Rotated text for "Contact" label */
.ptw-rotated {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-weight: 700;
    font-size: 8px;
    text-align: center;
    background: #D9D9D9;
    padding: 4px 2px;
    width: 18px;
}

/* Sub-section title row */
.ptw-subtitle {
    font-weight: 700;
    font-size: 10px;
    background: #E8E8E8;
    padding: 4px 6px !important;
}

/* Paragraph text inside tables */
.ptw-text {
    font-size: 9px;
    line-height: 1.4;
    padding: 4px 6px !important;
}

/* Signatures legend */
.ptw-legend {
    font-size: 8px;
    line-height: 1.4;
    padding: 4px 6px !important;
    background: #f0f0f0;
}

/* Status badge */
.ptw-status {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ptw-status--draft { background: #FFF3CD; color: #856404; }
.ptw-status--issued { background: #CCE5FF; color: #004085; }
.ptw-status--active { background: #D4EDDA; color: #155724; }
.ptw-status--suspended { background: #F8D7DA; color: #721C24; }
.ptw-status--completed { background: #D1ECF1; color: #0C5460; }
.ptw-status--revoked { background: #F5C6CB; color: #721C24; }
.ptw-status--cancelled { background: #E2E3E5; color: #383D41; }

/* Tab bar */
.ptw-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
    border-bottom: 2px solid #003366;
}

.ptw-tab {
    padding: 8px 20px;
    background: #E8E8E8;
    border: 1px solid #ccc;
    border-bottom: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #333;
    border-radius: 4px 4px 0 0;
    margin-right: 2px;
}

.ptw-tab:hover {
    background: #d0d0d0;
}

.ptw-tab--active {
    background: #003366;
    color: #fff;
    border-color: #003366;
}

/* Company logo in document header */
.ptw-company-logo {
    max-width: 100px;
    max-height: 50px;
    object-fit: contain;
}

/* Page title header */
.ptw-page-title {
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    margin: 0;
    padding: 6px;
    background: #003366;
    color: #fff;
}

/* Profile selection grid */
.ptw-profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    padding: 16px 0;
}

.ptw-profile-card {
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
}

.ptw-profile-card:hover {
    border-color: #003366;
    box-shadow: 0 2px 8px rgba(0,51,102,.15);
}

.ptw-profile-card--selected {
    border-color: #003366;
    background: #f0f5fa;
}

.ptw-profile-card__name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
    color: #003366;
}

.ptw-profile-card__desc {
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
}

.ptw-profile-card__meta {
    font-size: 11px;
    color: #888;
}

/* Action bar */
.ptw-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
    padding: 12px 0;
}

/* Two-column side-by-side tables */
.ptw-side-by-side {
    display: flex;
    gap: 6px;
}

.ptw-side-by-side > div {
    flex: 1;
}

/* Profile info bar */
.ptw-profile-info {
    background: #f0f5fa;
    border: 1px solid #003366;
    border-radius: 4px;
    padding: 8px 14px;
    margin-bottom: 12px;
    font-size: 13px;
}

/* Saved message */
.ptw-saved-msg {
    color: #155724;
    font-size: 13px;
    align-self: center;
}

/* Section 3 configuration bar */
.ptw-section3-config {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f0f5fa;
    border: 1px solid #003366;
    border-radius: 4px;
    padding: 8px 14px;
    margin-bottom: 6px;
}

.ptw-config-label {
    font-size: 13px;
    font-weight: 600;
    color: #003366;
    white-space: nowrap;
}

.ptw-config-select {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 12px;
    max-width: 400px;
}

/* Add requirement button row */
.ptw-add-row {
    margin: 4px 0 8px;
    text-align: right;
}

/* Remove requirement button */
.ptw-btn-remove {
    background: none;
    border: none;
    color: #c33;
    font-size: 14px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
    line-height: 1;
}

.ptw-btn-remove:hover {
    background: #fee;
    color: #a00;
}

/* Read-only mode (finalised permits) */
.ptw-form--readonly .ptw-input-cell {
    background: #F0F0F0;
    pointer-events: none;
}

.ptw-form--readonly .ptw-input,
.ptw-form--readonly .ptw-input--date,
.ptw-form--readonly .ptw-input--time,
.ptw-form--readonly .ptw-select,
.ptw-form--readonly .ptw-textarea,
.ptw-form--readonly .ptw-checkbox {
    pointer-events: none;
    color: #333;
    opacity: 1;
}

.ptw-form--readonly .ptw-signature {
    pointer-events: none;
}

/* Read-only banner */
.ptw-readonly-banner {
    background: #CCE5FF;
    border: 1px solid #004085;
    color: #004085;
    border-radius: 4px;
    padding: 10px 16px;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 600;
}

/* Status badge in page header */
.page-header__title .ptw-status {
    margin-left: 12px;
    vertical-align: middle;
    font-size: 11px;
}

/* Print styles */
@media print {
    .ptw-form {
        box-shadow: none;
        padding: 0;
        max-width: 100%;
    }

    .ptw-tabs,
    .ptw-actions,
    .page-header,
    .app-header {
        display: none !important;
    }

    .ptw-input-cell {
        background: #FFFFCC !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .ptw-section-header,
    .ptw-section-header--small {
        background: #003366 !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .ptw-label,
    .ptw-label--wrap {
        background: #D9D9D9 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
