/* admin/css/preview-modal.css */

/* Update modal positioning */
#record-preview-modal {
    position: fixed !important;
    top: 32px !important; /* Account for WP admin bar */
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.7) !important;
    z-index: 999999 !important;
    overflow-y: auto !important;
    padding: 20px;
}

/* Ensure modal content is centered */
#record-preview-modal .modal-content {
    margin: 20px auto !important;
    position: relative !important;
    max-width: 800px !important;
    width: 100% !important;
    background: #fff !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
}

/* Import custom elements */
@import url('custom-elements.css');

/* Modal Container */
.pillar-modal {
    position: fixed !important;
    top: 32px !important; /* Account for WP admin bar */
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    z-index: 999999 !important;
    display: none;
    justify-content: center !important;
    align-items: center !important;
    padding: 20px !important;
}

.pillar-modal.show {
    display: flex !important;
}

/* Modal Content */
.pillar-modal .modal-content {
    margin: 20px auto !important;
    position: relative !important;
    max-width: 800px !important;
    width: 90% !important;
    background: #fff !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
    max-height: calc(100vh - 84px) !important; /* Account for admin bar + padding */
    overflow-y: auto !important;
}

/* Modal Header */
.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.modal-header h2 {
    margin: 0;
    color: #1d2327;
    font-size: 1.5em;
}

.close-modal {
    font-size: 24px;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
    transition: color 0.2s ease;
}

.close-modal:hover {
    color: #1d2327;
}

/* Modal Body */
.modal-body {
    padding: 20px;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

/* Tabs */
.preview-tabs {
    display: flex;
    gap: 0;
    padding: 0;
    border-bottom: 1px solid #e5e5e5;
    margin-bottom: 20px;
    background: #f8f9fa;
    border-radius: 4px 4px 0 0;
}

.tab-button {
    padding: 12px 24px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab-button .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
}

.tab-button:hover {
    color: #2271b1;
    background: #f0f0f1;
}

.tab-button.active {
    color: #2271b1;
    border-bottom-color: #2271b1;
    font-weight: 500;
    background: #fff;
}

/* Details Tab */
.details-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    padding: 10px 0;
}

.detail-row {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 4px;
}

.detail-row label {
    display: block !important;
    font-weight: 600 !important;
    margin-bottom: 5px !important;
    color: #666 !important;
    font-size: 0.9em !important;
}

.detail-row span {
    display: block !important;
    color: #1d2327 !important;
    font-size: 1.05em !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: pre-wrap !important;
}

/* Long text fields span full width */
.detail-row:has(.care-notes),
.detail-row:has(.manual-reason) {
    grid-column: 1 / -1 !important;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.preview-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 4px;
}

.preview-item label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    color: #666;
    font-size: 0.9em;
}

.preview-item span {
    color: #1d2327;
    font-size: 1.1em;
}

.preview-item.full-width {
    grid-column: 1 / -1;
}

/* Tasks Tab */
#record-preview-modal .task-section {
    margin-bottom: 30px !important;
    background: #fff !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 8px !important;
    padding: 20px !important;
}

#record-preview-modal .task-items {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    gap: 15px !important;
}

#record-preview-modal .task-item {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 12px 16px !important;
    background: #f8f9fa !important;
    border-radius: 6px !important;
    border: 1px solid #e5e7eb !important;
    transition: all 0.2s ease !important;
}

#record-preview-modal .task-value {
    font-weight: 500 !important;
    color: #1d2327 !important;
}

#record-preview-modal .task-value[data-completed="true"] {
    color: #00a32a !important;
}

#record-preview-modal .task-value[data-completed="true"]::after {
    content: "✓" !important;
}

#record-preview-modal .task-value[data-completed="false"]::after {
    content: "✗" !important;
    color: #dc2626 !important;
}

/* Update the task category headers */
#record-preview-modal .task-section h3 {
    color: #1d2327 !important;
    font-size: 1.2em !important;
    margin: 0 0 15px 0 !important;
    padding-bottom: 8px !important;
    border-bottom: 2px solid #e5e5e5 !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
}

/* Category Icons */
.task-category[data-category="Nutrition"] h3 .dashicons::before {
    content: "\f480"; /* food icon */
}

.task-category[data-category="Transferring"] h3 .dashicons::before {
    content: "\f237"; /* move icon */
}

.task-category[data-category="Dressing"] h3 .dashicons::before {
    content: "\f330"; /* shirt icon */
}

.task-category[data-category="Personal Care"] h3 .dashicons::before {
    content: "\f338"; /* heart icon */
}

.task-category[data-category="Toileting"] h3 .dashicons::before {
    content: "\f522"; /* building icon */
}

.task-category[data-category="Housekeeping"] h3 .dashicons::before {
    content: "\f481"; /* home icon */
}

.task-category[data-category="Other"] h3 .dashicons::before {
    content: "\f111"; /* plus icon */
}

/* Empty state styling */
.no-tasks-message {
    text-align: center;
    padding: 40px 20px;
    background: #f8f9fa;
    border-radius: 8px;
    color: #666;
}

.no-tasks-message .dashicons {
    font-size: 48px;
    width: 48px;
    height: 48px;
    color: #c3c4c7;
    margin-bottom: 16px;
}

/* Details tab enhancements */
.preview-item.has-details {
    border-left: 4px solid #2271b1;
}

.preview-item .details-text {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e5e7eb;
    font-size: 0.9em;
    color: #666;
}
/* Signatures Tab */
.signature-preview {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.signature-preview h3 {
    color: #1d2327;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.signature-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.signature-timestamp {
    margin-top: 10px;
    color: #666;
    font-size: 0.9em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.signature-timestamp .date,
.signature-timestamp .time {
    background: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #e5e7eb;
}

.signatures-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.signature-box {
    border: 1px solid #ddd;
    padding: 10px;
    margin: 10px 0;
    min-height: 100px;
}

/* Modal Footer */
.modal-footer {
    padding: 20px;
    border-top: 1px solid #e5e5e5;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background-color: #f8f9fa;
    border-radius: 0 0 8px 8px;
}

/* Buttons */
.modal-footer .button,
.modal-footer .action-btn,
.modal-footer .close-modal {
    padding: 8px 16px;
    font-size: 13px;
    min-width: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.modal-footer .close-modal {
    background: #f8f9fa !important;
    border: 1px solid #d1d5db !important;
    color: #6b7280 !important;
    border-radius: 6px;
    cursor: pointer;
}

.modal-footer .close-modal:hover {
    background: #e9ecef !important;
    color: #374151 !important;
}

.modal-footer .export-pdf {
    background: #2271b1;
    color: white;
    border-color: #2271b1;
}

.modal-footer .export-pdf:hover {
    background: #135e96;
    border-color: #135e96;
}

/* Responsive Design */
@media screen and (max-width: 782px) {
    .modal-content {
        margin: 0;
        width: 95%;
        max-height: 90vh;
    }

    .signatures-container {
        grid-template-columns: 1fr;
    }

    .preview-grid {
        grid-template-columns: 1fr;
    }

    .preview-tabs {
        overflow-x: auto;
    }

    .tab-button {
        padding: 10px 16px;
        white-space: nowrap;
    }

    .task-item {
        padding: 10px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .task-category {
        padding: 15px;
    }

    .task-times {
        width: 100%;
    }

    .tab-button .dashicons {
        margin-right: 0;
    }

    .tab-button span:not(.dashicons) {
        display: none;
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-footer .button,
    .modal-footer .action-btn {
        width: 100%;
        margin: 5px 0;
        justify-content: center;
    }

    .signature-timestamp {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
}

/* Print Styles */
@media print {
    .modal {
        position: relative;
        background: none;
        padding: 0;
    }

    .modal-content {
        box-shadow: none;
        margin: 0;
    }

    .preview-tabs,
    .modal-footer,
    .close-modal {
        display: none;
    }

    .tab-content {
        display: block !important;
    }

    .signature-preview {
        break-inside: avoid;
    }

    /* Add page breaks */
    .task-category {
        break-inside: avoid;
    }

    /* Ensure signatures are visible */
    .signature-box {
        border: 1px solid #000;
    }

    /* Force background colors */
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* Add animation class */
.modal.show {
    animation: modalFadeIn 0.3s ease-out;
}

/* Update animation */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Add missing task status icons */
.task-item.completed .dashicons::before {
    content: "\f147"; /* checkmark */
}

.task-item:not(.completed) .dashicons::before {
    content: "\f460"; /* minus */
}

/* Tab Content */
.tab-content {
    display: none !important;
}

.tab-content.active {
    display: block !important;
}

/* Record Type Specific Content */
.evv-only,
.timesheet-only {
    display: none !important;
}

/* These will be overridden by JavaScript when needed */
.record-type-evv .evv-only,
.record-type-timesheet .timesheet-only {
    display: block !important;
}

/* Inside the details grid, wrappers must be transparent so children are grid items */
.record-type-timesheet .details-grid > .timesheet-only,
.record-type-evv .details-grid > .evv-only {
    display: contents !important;
}


/* Make sure modal content is properly contained */
.modal-content {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

/* Task Items */
.task-item {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 12px 16px !important;
    background: #f8f9fa !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 6px !important;
    margin-bottom: 8px !important;
}

.task-value {
    font-weight: 500 !important;
    color: #1d2327 !important;
}

/* Task Sections */
.task-section {
    margin-bottom: 24px !important;
}

.task-section h3 {
    margin-bottom: 16px !important;
    padding-bottom: 8px !important;
    border-bottom: 1px solid #e5e7eb !important;
}

/* Make sure task sections are visible when active — except custom tasks which is JS-controlled */
#tasks-tab.active .task-section:not(#custom-tasks) {
    display: block !important;
}
#tasks-tab.active #custom-tasks.has-tasks {
    display: block !important;
}
#tasks-tab.active #custom-tasks:not(.has-tasks) {
    display: none !important;
}

/* Task Details */
.task-details {
    margin-top: 8px !important;
    padding-left: 16px !important;
    color: #666 !important;
    font-size: 0.9em !important;
}

/*
 * An "Other Details" row with nothing in it is noise, and .hide() cannot remove
 * it: the .task-item rules above carry `display: flex !important`, which beats
 * the inline style jQuery writes. The JS toggles this class instead.
 */
#record-preview-modal .task-item.task-details.is-empty {
    display: none !important;
}

/*
 * Match the Details tab's card treatment. Tasks previously used a heavier box —
 * a border, a wider radius, a full-size label — nested inside the already
 * bordered .task-section, which is what made this tab look coarser than the
 * neatly rendered details beside it.
 */
#record-preview-modal .task-item {
    padding: 15px !important;
    border-radius: 4px !important;
    border: 0 !important;
    margin-bottom: 0 !important; /* .task-items is a grid; gap handles spacing */
    gap: 12px !important;
}

#record-preview-modal .task-item label {
    font-weight: 600 !important;
    font-size: 0.9em !important;
    color: #666 !important;
    margin: 0 !important;
}

/*
 * Tick for performed, X for not — the same convention as the timesheet PDF the
 * agency files, so the screen and the paperwork agree. Colour is the only
 * addition: the two glyphs were identical in weight and colour, which made a
 * completed task and a skipped one hard to tell apart at a glance.
 */
#record-preview-modal .task-item .task-value {
    flex: 0 0 auto !important;
    font-size: 1.05em !important;
    font-weight: 700 !important;
    line-height: 1 !important;
}

#record-preview-modal .task-item .task-value[data-completed="true"]::after {
    content: "\2713" !important; /* ✓ */
    color: #15803d !important;
}

#record-preview-modal .task-item .task-value[data-completed="false"]::after {
    content: "X" !important;
    color: #9ca3af !important;
}

/*
 * The Other Details row carries free text rather than a mark, so it stacks like
 * a details card and spans the grid instead of being squeezed into one column.
 */
#record-preview-modal .task-item.task-details {
    grid-column: 1 / -1 !important;
    display: block !important;
    padding-left: 15px !important;
    margin-top: 0 !important; /* the grid gap already spaces it */
    font-size: 1em !important;
    color: #1d2327 !important;
}

#record-preview-modal .task-item.task-details label {
    display: block !important;
    margin-bottom: 5px !important;
}

#record-preview-modal .task-item.task-details .task-value {
    display: block !important;
    color: #1d2327 !important;
    font-weight: 400 !important;
    font-size: 1.05em !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: pre-wrap !important;
}

/* Tab Navigation */
.tab-nav {
    display: flex !important;
    gap: 0 !important;
    border-bottom: 1px solid #e5e5e5 !important;
    background: #f8f9fa !important;
    margin: 0 !important;
    padding: 0 !important;
}

.tab-button {
    flex: 1 !important;
    padding: 12px 24px !important;
    background: none !important;
    border: none !important;
    border-bottom: 2px solid transparent !important;
    cursor: pointer !important;
    font-size: 14px !important;
    color: #666 !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
}

.tab-button:hover {
    color: #2271b1 !important;
    background: #f0f0f1 !important;
}

.tab-button.active {
    color: #2271b1 !important;
    border-bottom-color: #2271b1 !important;
    font-weight: 500 !important;
    background: #fff !important;
}

/* Tab Content */
.tab-content {
    display: none !important;
    padding: 20px !important;
}

.tab-content.active {
    display: block !important;
}

/* Show when parent has evv class — lower specificity fallback */
.pillar-modal[data-record-type="evv"] .evv-only {
    display: block;
}

.rejection-notice {
    background-color: #fff3cd;
    border: 1px solid #ffeeba;
    border-radius: 4px;
    margin-bottom: 20px;
    padding: 15px;
}

.rejection-notice .notice-header {
    display: flex;
    align-items: center;
    margin-bottom: 0;
    padding: 10px;
    position: relative;
}

.rejection-notice .notice-header i {
    color: #856404;
    margin-right: 10px;
}

.rejection-notice .notice-header h3 {
    color: #856404;
    margin: 0;
}

.rejection-notice .notice-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    opacity: 0;
}

.rejection-notice .notice-content.expanded {
    max-height: 1000px;
    opacity: 1;
    padding: 15px;
}

.rejection-entry {
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 4px;
    transition: opacity 0.3s ease;
}

.rejection-entry.current {
    background-color: #fff3cd;
    border: 1px solid #ffeeba;
}

.rejection-entry.historical {
    background-color: #f8f9fa;
    border: 1px solid #e5e7eb;
}

.resubmission-notice {
    background-color: #e8f5e9;
    border: 1px solid #c8e6c9;
    border-radius: 4px;
    margin: 10px 0;
    padding: 15px;
}

.resubmission-notice .notice-header {
    display: flex;
    align-items: center;
    margin-bottom: 0;
    padding: 10px;
    position: relative;
}

.resubmission-notice .notice-header i {
    color: #2e7d32;
    margin-right: 10px;
}

.resubmission-notice .notice-header h3 {
    color: #2e7d32;
    margin: 0;
}

.previous-rejection {
    background-color: #f8f9fa;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 10px;
    margin-top: 10px;
}

.toggle-history {
    margin-left: auto;
    background: none;
    border: none;
    padding: 5px;
    cursor: pointer;
    color: inherit;
}

.toggle-history:hover {
    opacity: 0.8;
}

.toggle-history .dashicons {
    transition: transform 0.3s ease;
}

.toggle-history[aria-expanded="false"] .dashicons {
    transform: rotate(180deg);
}

/* Add hover effect for the toggle button */
.toggle-history:hover {
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
}

/* Notice content transitions */
.notice-content {
    max-height: 0 !important;
    overflow: hidden !important;
    opacity: 0 !important;
    transition: all 0.3s ease-in-out !important;
    padding: 0 15px !important;
}

.notice-content.expanded {
    max-height: 1000px !important;
    opacity: 1 !important;
    padding: 15px !important;
}

/* Remove duplicate/conflicting styles */
.resubmission-notice .notice-content {
    /* Remove these as they're now handled by the base .notice-content class */
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    opacity: 0;
}

.resubmission-notice .notice-content.expanded {
    /* Remove these as they're now handled by the base .notice-content.expanded class */
    max-height: 1000px;
    opacity: 1;
    padding: 15px;
}

/* Remove redundant transition declaration */
.rejection-notice .notice-content,
.resubmission-notice .notice-content {
    /* Remove this as it's now handled by the base .notice-content class */
    transition: all 0.3s ease-in-out;
}

/* Mobile responsiveness */
@media screen and (max-width: 768px) {
    .pillar-modal {
        padding: 10px !important;
    }

    .modal-content {
        width: 100% !important;
        margin: 10px auto !important;
        max-height: calc(100vh - 60px) !important;
    }

    .modal-header {
        padding: 15px !important;
    }

    .modal-header h2 {
        font-size: 1.2em !important;
    }

    /* Adjust rejection and resubmission notices */
    .rejection-notice,
    .resubmission-notice {
        margin: 10px 0 !important;
        padding: 10px !important;
    }

    .notice-header {
        flex-wrap: wrap !important;
        gap: 5px !important;
    }

    .notice-header h3 {
        font-size: 1em !important;
        flex: 1 !important;
    }

    .rejection-entry,
    .previous-rejection {
        padding: 8px !important;
        margin-bottom: 8px !important;
    }

    /* Adjust collapse all button */
    .collapse-all-wrapper {
        padding: 5px !important;
    }

    .collapse-all-btn {
        font-size: 11px !important;
        padding: 4px 8px !important;
    }

    /* Adjust tabs for mobile */
    .tab-nav {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .tab-button {
        padding: 10px 15px !important;
        white-space: nowrap !important;
        font-size: 13px !important;
    }

    /* Make text more readable on mobile */
    .rejection-entry p,
    .previous-rejection p {
        font-size: 14px !important;
        margin: 4px 0 !important;
    }

    /* Ensure toggle buttons are easily tappable */
    .toggle-history {
        padding: 8px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* Additional adjustments for very small screens */
@media screen and (max-width: 480px) {
    .modal-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }

    .modal-header .close-modal {
        position: absolute !important;
        top: 10px !important;
        right: 10px !important;
    }

    .notice-header {
        padding: 8px !important;
    }

    .notice-content.expanded {
        padding: 10px !important;
    }

    /* Ensure text doesn't overflow on small screens */
    .rejection-entry p,
    .previous-rejection p {
        word-break: break-word !important;
    }
}

/* Restore collapse-all button styles */
.collapse-all-wrapper {
    display: flex !important;
    justify-content: flex-end !important;
    padding: 5px 10px !important;
    background: #f8f9fa !important;
    border-bottom: 1px solid #e5e7eb !important;
}

.collapse-all-btn {
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    padding: 5px 10px !important;
    background: none !important;
    border: 1px solid #ddd !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    font-size: 12px !important;
    color: #666 !important;
}

.collapse-all-btn:hover {
    background: #f0f0f1 !important;
}

/* Add initial states for toggle buttons */
.toggle-history[aria-expanded="true"] .dashicons {
    transform: rotate(0deg) !important;
}

.toggle-history[aria-expanded="false"] .dashicons {
    transform: rotate(180deg) !important;
}

/* Add fade effect for entries */
.rejection-entry, .previous-rejection {
    animation: fadeIn 0.3s ease-in-out !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Enhanced signature display in modal */
.signature-container {
    background: #fff !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 4px !important;
    padding: 15px !important;
    margin: 10px 0 !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05) !important;
}

.signature-label {
    font-weight: 600 !important;
    color: #333 !important;
    margin-bottom: 8px !important;
    display: block !important;
}

.signature-image {
    width: 100% !important;
    max-width: 400px !important;  /* Larger size in modal */
    height: auto !important;
    min-height: 100px !important;
    background: #fff !important;
    border: 1px solid #ddd !important;
    padding: 10px !important;
    image-rendering: -webkit-optimize-contrast !important;
    image-rendering: crisp-edges !important;
    opacity: 1 !important;
}

/* Signature timestamp and info */
.signature-info {
    font-size: 12px !important;
    color: #666 !important;
    margin-top: 5px !important;
    display: block !important;
}