/* ============================================
   PTW (Permit To Work) App Styles
   Ported from SHEQhub design system
   ============================================ */

:root {
    --color-primary: #003369;
    --color-primary-dark: #002244;
    --color-primary-light: #1a5096;
    --color-secondary: #9c270d;
    --color-teal: #1a9e9e;
    --color-teal-light: #e0f4f4;
    --color-teal-bg: #f0fafa;
    --color-error: #E31717;
    --color-success: #28a745;
    --color-warning: #f0ad4e;
    --color-text: #222222;
    --color-text-light: #444444;
    --color-bg: #f5f5f5;
    --color-white: #ffffff;
    --color-border: #ddd;
    --font-family: Arial, Helvetica, sans-serif;
    --radius: 8px;
    --radius-lg: 24px;
    --cyan-bright: #00D4FF;
    --cyan-glow: #00E5FF;
}

/* --- Base --- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    margin: 0;
    padding: 0;
    background: var(--color-bg);
}

h1 { color: #2a5a8a; margin-top: 0; font-size: 24px; }
h2 { color: #1e4d7a; margin-top: 0; font-size: 20px; }
h3 { color: #16406e; margin-top: 0; font-size: 18px; }
h1:focus { outline: none; }

a { color: var(--color-primary); font-weight: 700; font-size: 16px; }
a:hover { color: var(--color-primary-light); }

/* --- Utilities --- */
.d-flex { display: flex; }
.d-inline-flex { display: inline-flex; }
.flex-grow-1 { flex-grow: 1; }
.align-items-center { align-items: center; }
.justify-content-center { justify-content: center; }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-light); }

.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.gap-lg { gap: 24px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 24px; }
.ms-md { margin-left: 16px; }
.p-4 { padding: 32px; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* --- App Shell --- */
.app-shell {
    min-height: 100vh;
}

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background: var(--color-white);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    padding: 0 24px;
    height: 56px;
}

.app-header__left {
    display: flex;
    align-items: center;
}

.app-header__logo {
    display: flex;
    align-items: baseline;
    gap: 8px;
    text-decoration: none;
    color: var(--color-primary);
}

.app-header__title {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 1px;
}

.app-header__subtitle {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-light);
}

.app-header__nav {
    display: flex;
    gap: 24px;
    margin-left: 48px;
}

.app-header__link {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    text-decoration: none;
    padding: 4px 0;
    border-bottom: 2px solid transparent;
    transition: border-color 0.15s, color 0.15s;
}

.app-header__link:hover {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.app-main {
    margin-top: 56px;
    padding: 24px;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header__title {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-primary);
    margin: 0;
}

.page-header__actions {
    display: flex;
    gap: 12px;
}

/* --- Container --- */
.container__body {
    background: var(--color-white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* --- Cards --- */
.app-card {
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: 32px;
    max-width: 480px;
    margin: 60px auto;
}

/* --- Page narrow (centered narrow layout) --- */
.page--narrow {
    max-width: 480px;
    margin: 0 auto;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 600;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.4;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--cyan-bright), var(--cyan-glow));
    color: var(--color-primary-dark);
    border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.4);
}

.btn-outline {
    background: transparent;
    color: var(--color-primary);
    border-color: var(--color-border);
}

.btn-outline:hover:not(:disabled) {
    background: var(--color-primary);
    color: var(--color-white);
    border-color: var(--color-primary);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.btn-wide {
    width: 100%;
}

.btn--armed {
    color: var(--color-error);
    background: #fef2f2;
    border-color: var(--color-error);
}

.btn--armed:hover {
    color: var(--color-white);
    background: var(--color-error);
}

/* --- Forms --- */
.form-field {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    background: #f4f7f8;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    outline: none;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.form-control:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary);
}

.form-control--inline {
    background: transparent;
    border: 1px solid transparent;
    padding: 4px 8px;
    border-radius: 4px;
}

.form-control--inline:hover {
    border-color: var(--color-border);
}

.form-control--inline:focus {
    background: #f4f7f8;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary);
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-section-heading {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-primary);
    padding-bottom: 8px;
    border-bottom: 2px solid var(--color-primary);
    margin-bottom: 16px;
    margin-top: 24px;
}

.form-hint {
    font-size: 12px;
    color: var(--color-text-light);
    margin-top: 4px;
}

/* --- Data Table --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead {
    background: #e8eef4;
    color: #1a2a3a;
}

.data-table th {
    padding: 10px 14px;
    font-weight: 600;
    text-align: left;
    font-size: 14px;
    border-bottom: 2px solid #c5d3e0;
}

.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
}

.data-table tbody tr:hover {
    background: #f8f9fa;
}

.data-table tbody tr {
    cursor: pointer;
}

/* --- Alert --- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 16px;
}

.alert-danger {
    background: #fef2f2;
    color: var(--color-error);
    border: 1px solid #fca5a5;
}

.alert-success {
    background: #f0fdf4;
    color: var(--color-success);
    border: 1px solid #86efac;
}

/* --- Upload Zone --- */
.upload-zone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    position: relative;
    transition: border-color 0.15s, background 0.15s;
    position: relative;
}

.upload-zone:hover,
.upload-zone--active {
    border-color: var(--color-primary);
    background: #f0f4f8;
}

.upload-zone__content {
    pointer-events: none;
}

.upload-zone__icon {
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
}

.upload-zone__text {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 8px;
}

.upload-zone__hint {
    font-size: 14px;
    color: var(--color-text-light);
}

.upload-zone__input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    z-index: 10;
}

/* --- Preview --- */
.preview-container {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.preview-actions {
    padding: 12px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
}

.preview-frame {
    padding: 20px;
    overflow-x: auto;
    max-height: 70vh;
    overflow-y: auto;
}

/* --- Spinner --- */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Modal --- */
.app-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.app-modal {
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 90%;
    overflow: hidden;
}

.app-modal-header {
    background: var(--color-primary);
    color: var(--color-white);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-modal-header h3 {
    color: var(--color-white);
    margin: 0;
    font-size: 16px;
}

.app-modal-close {
    background: none;
    border: none;
    color: var(--color-white);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.app-modal-body {
    padding: 24px;
}

.app-modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* --- Status Badge --- */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
}

.status-badge--draft { background: #e0e7ff; color: #3730a3; }
.status-badge--issued { background: #dbeafe; color: #1d4ed8; }
.status-badge--active { background: #dcfce7; color: #166534; }
.status-badge--suspended { background: #fef3c7; color: #92400e; }
.status-badge--completed { background: #d1fae5; color: #065f46; }
.status-badge--cancelled { background: #fef2f2; color: #991b1b; }
.status-badge--revoked { background: #fce7f3; color: #9d174d; }

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--color-text-light);
    font-size: 16px;
}

/* --- Parsed Data Table --- */
.parsed-data .data-table .form-control--inline {
    width: 100%;
    min-width: 200px;
}

/* --- Blazor error boundary --- */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* --- Loading progress --- */
.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--color-primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Loading");
}

/* --- Profile Edit Page --- */
.profile-edit-section {
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}

.profile-edit-section__title {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-primary);
    margin: 0 0 16px 0;
}

.profile-edit-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.profile-edit-section__header .profile-edit-section__title {
    margin-bottom: 0;
}

.profile-edit-grid__row {
    display: flex;
    gap: 24px;
}

.profile-edit-grid__row > .form-field {
    flex: 1;
}

.profile-edit-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 16px 0;
}

/* Icon buttons (remove, etc.) */
.btn-icon {
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    transition: all 0.15s;
}

.btn-icon--danger {
    color: #c33;
}

.btn-icon--danger:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #a00;
}

/* Form checkbox */
.form-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.form-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Success banner */
.ptw-success-banner {
    background: #f0fdf4;
    border: 1px solid #86efac;
    color: #166534;
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 600;
}

/* --- Responsive --- */
@media (max-width: 1000px) {
    .app-main { padding: 16px; }
    .app-header__nav { gap: 16px; margin-left: 24px; }
}

@media (max-width: 700px) {
    .app-header { padding: 0 12px; }
    .app-header__nav { display: none; }
    .app-main { padding: 12px; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .container__body { padding: 16px; }
}

@media (max-width: 500px) {
    .data-table { display: block; overflow-x: auto; }
}

/* --- Print --- */
@media print {
    .app-header, .app-header__nav, .page-header__actions, .btn { display: none !important; }
    .app-main { margin-top: 0; padding: 0; }
    .container__body { box-shadow: none; }
    body { background: white; }
}

/* --- Sign-in with the SHEQhub login --- */
.app-header__session {
    margin-left: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
}

.app-header__company {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-primary);
}

.app-header__user {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-light);
}

.sign-in {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    gap: 12px;
}

.sign-in__card {
    max-width: 520px;
    width: 100%;
    background: var(--color-white);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    padding: 28px;
}

.sign-in__title {
    font-size: 22px;
    font-weight: 700;
    color: var(--color-primary);
    margin: 0 0 12px;
}

.sign-in__text {
    font-size: 15px;
    font-weight: 500;
    color: var(--color-text);
}

.sign-in__message {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-error);
}

.sign-in__actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

@media (max-width: 700px) {
    .app-header__user { display: none; }
    .sign-in__card { padding: 20px 16px; }
}
