/* Recruitment Flow - Public Registration Form Styles */
/* Mobile-first, responsive */

/* ============================================================
   CSS Custom Properties
   ============================================================ */
.rf-form {
    --rf-primary:       #005cb9;
    --rf-primary-dark:  #004a95;
    --rf-primary-light: rgba(0, 92, 185, 0.08);
    --rf-primary-ring:  rgba(0, 92, 185, 0.18);
    --rf-danger:        #c0392b;
    --rf-danger-bg:     #fef5f5;
    --rf-danger-border: #f5a0a0;
    --rf-border:        #d0d5dd;
    --rf-text:          #1a1a1a;
    --rf-text-label:    #101828;
    --rf-text-muted:    #667085;
    --rf-bg-white:      #ffffff;
    --rf-bg-field:      #fdfdfd;
    --rf-radius:        8px;
    --rf-radius-sm:     5px;
    --rf-shadow:        0 1px 4px rgba(16, 24, 40, 0.08);
    --rf-shadow-md:     0 4px 12px rgba(16, 24, 40, 0.10);
}

/* ============================================================
   Reset & Base
   ============================================================ */
.rf-form * {
    box-sizing: border-box;
}

.rf-form {
    max-width: 980px;
    width: 100%;
    margin: 0 auto;
    padding: 0 12px 32px;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.6;
    color: var(--rf-text);
}

/* ============================================================
   Typography
   ============================================================ */
.rf-form h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--rf-text-label);
    margin: 0 0 20px 0;
    padding: 0;
    border: none;
}

.rf-form h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--rf-primary);
    margin: 0 0 18px 0;
    padding: 0 0 10px 0;
    border-bottom: 1px solid #e4eaf3;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.rf-form h4 {
    font-size: 13px;
    font-weight: 700;
    color: var(--rf-text-muted);
    margin: 20px 0 12px 0;
    padding: 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: none;
}

.rf-form .icon {
    font-size: 15px;
    line-height: 1;
}

.rf-form .section-divider {
    display: none;
}

/* ============================================================
   Section Cards
   ============================================================ */
.rf-form .rf-section {
    background: var(--rf-bg-white);
    margin-bottom: 16px;
    padding: 20px 20px 10px;
    border: 1px solid #e4eaf3;
    border-left: 4px solid var(--rf-primary);
    border-radius: var(--rf-radius);
    box-shadow: var(--rf-shadow);
}

/* PDPA Consent Section */
.rf-form .rf-consent-section {
    background: #fffef0;
    border-color: #e6cc00;
    border-left-color: #b8960a;
}

.rf-form .rf-consent-box {
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
}

.rf-form .rf-consent-label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.7;
}

.rf-form .rf-consent-checkbox {
    width: 18px !important;
    height: 18px !important;
    min-width: 18px !important;
    margin: 4px 0 0 0 !important;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--rf-primary);
}

.rf-form .rf-consent-text {
    flex: 1;
    color: #333;
}

.rf-form .rf-consent-error {
    background: var(--rf-danger-bg);
    border: 1px solid var(--rf-danger-border);
    color: var(--rf-danger);
    padding: 10px 14px;
    border-radius: var(--rf-radius-sm);
    margin-top: 12px;
    font-size: 13px;
}

.rf-form .rf-consent-info {
    display: inline-block;
    margin-left: 4px;
    cursor: help;
    color: var(--rf-primary);
    font-size: 13px;
}

/* ============================================================
   Form Table (label + field rows)
   Mobile: stacked column | Desktop: side-by-side
   ============================================================ */
.rf-form .form-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0;
    border: none !important;
}

.rf-form .form-table tr {
    display: block;
    margin-bottom: 14px;
    border: none !important;
    background: transparent !important;
}

.rf-form .form-table th {
    display: block;
    width: 100%;
    padding: 0 0 5px 0;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--rf-text-label);
    line-height: 1.4;
    background: transparent !important;
    border: none !important;
}

.rf-form .form-table td {
    display: block;
    width: 100%;
    padding: 0;
    background: transparent;
    border: none !important;
}

/* English Caption */
.rf-form .en-caption {
    display: block;
    font-size: 11px;
    color: var(--rf-text-muted);
    font-weight: 400;
    margin-top: 1px;
    letter-spacing: 0.01em;
}

/* Required asterisk */
.rf-form .req {
    color: var(--rf-danger);
    font-weight: 700;
    margin-left: 1px;
}

/* Muted/secondary text inline */
.rf-form .text-muted {
    color: var(--rf-text-muted);
    font-weight: normal;
}

/* Experience / Education table column widths — only applied when
   the table is in desktop layout (1024px+). */
@media (min-width: 1024px) {
    #experience-table th:nth-child(1),
    #experience-table td:nth-child(1) { min-width: 160px; }
    #experience-table th:nth-child(2),
    #experience-table td:nth-child(2) { min-width: 180px; }
    #experience-table th:nth-child(3),
    #experience-table th:nth-child(4),
    #experience-table td:nth-child(3),
    #experience-table td:nth-child(4) { min-width: 120px; }
    #experience-table th:nth-child(5),
    #experience-table td:nth-child(5) { min-width: 110px; }

    #education-table th:nth-child(1),
    #education-table td:nth-child(1) { min-width: 160px; }
    #education-table th:nth-child(2),
    #education-table td:nth-child(2) { min-width: 140px; }
    #education-table th:nth-child(3),
    #education-table td:nth-child(3) { min-width: 140px; }
    #education-table th:nth-child(4),
    #education-table td:nth-child(4) { min-width: 100px; }
    #education-table th:nth-child(5),
    #education-table td:nth-child(5) { min-width: 80px; }
}

/* cv-notification container spacing */
#rf-cv-notification {
    margin-top: 8px;
}

/* CV upload loading animation */
@keyframes rf-spin {
    to { transform: rotate(360deg); }
}
.rf-cv-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    color: #555;
    font-size: 14px;
}
.rf-cv-loading__spinner {
    width: 22px;
    height: 22px;
    border: 3px solid #ddd;
    border-top-color: #0073aa;
    border-radius: 50%;
    animation: rf-spin 0.75s linear infinite;
    flex-shrink: 0;
}

/* Field helper text */
.rf-form .description {
    font-size: 11px;
    color: var(--rf-text-muted);
    margin: 4px 0 0 0;
    display: block;
}

/* Inline validation error message */
.rf-field-error-msg {
    display: block;
    font-size: 12px;
    color: var(--rf-danger);
    margin-top: 4px;
    font-weight: 500;
    min-height: 0;
}

/* ============================================================
   Input Fields
   ============================================================ */
.rf-form input[type="text"],
.rf-form input[type="tel"],
.rf-form input[type="email"],
.rf-form select,
.rf-form textarea {
    width: 100%;
    padding: 9px 12px;
    font-size: 15px;
    line-height: 1.5;
    border: 1px solid var(--rf-border);
    border-radius: var(--rf-radius-sm);
    background: var(--rf-bg-field);
    color: var(--rf-text);
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.rf-form input[type="text"]:focus,
.rf-form input[type="tel"]:focus,
.rf-form input[type="email"]:focus,
.rf-form select:focus,
.rf-form textarea:focus {
    outline: none;
    border-color: var(--rf-primary);
    box-shadow: 0 0 0 3px var(--rf-primary-ring);
    background: var(--rf-bg-white);
}

.rf-form textarea {
    min-height: 76px;
    resize: vertical;
}

/* Select arrow */
.rf-form select {
    background-color: var(--rf-bg-field);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23667085' d='M5 6L0 0h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    padding-right: 32px;
    cursor: pointer;
}

.rf-form input[type="file"] {
    font-size: 14px;
    padding: 8px 0;
    width: 100%;
    background: transparent;
    border: none;
}

/* ============================================================
   Error State
   ============================================================ */
.rf-form .rf-date-error,
.rf-form input.rf-date-error,
.rf-form input.rf-date-error:focus {
    border-color: var(--rf-danger) !important;
    background-color: var(--rf-danger-bg) !important;
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.12) !important;
}

/* ============================================================
   Select2 Overrides
   ============================================================ */
.rf-form .select2-container {
    font-size: 15px;
}

.rf-form .select2-container--default .select2-selection--single {
    height: auto !important;
    padding: 8px 12px !important;
    border: 1px solid var(--rf-border) !important;
    border-radius: var(--rf-radius-sm) !important;
    background: var(--rf-bg-field) !important;
}

.rf-form .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 1.5 !important;
    padding: 0 !important;
    padding-right: 24px !important;
    color: var(--rf-text) !important;
    font-size: 15px;
}

.rf-form .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 100% !important;
    top: 0 !important;
    right: 8px !important;
}

.rf-form .select2-container--default.select2-container--open .select2-selection--single,
.rf-form .select2-container--default.select2-container--focus .select2-selection--single {
    border-color: var(--rf-primary) !important;
    box-shadow: 0 0 0 3px var(--rf-primary-ring) !important;
    background: var(--rf-bg-white) !important;
}

.rf-form .select2-container--default .select2-selection--single .select2-selection__clear {
    display: none !important;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--rf-primary);
}

.select2-dropdown {
    border: 1px solid var(--rf-border);
    border-radius: var(--rf-radius-sm);
    box-shadow: var(--rf-shadow-md);
}

.select2-search--dropdown .select2-search__field {
    padding: 8px 12px;
    border: 1px solid var(--rf-border);
    border-radius: var(--rf-radius-sm);
    font-size: 14px;
}

.select2-search--dropdown .select2-search__field:focus {
    outline: none;
    border-color: var(--rf-primary);
}

/* ============================================================
   CV Upload Section
   ============================================================ */
.rf-upload-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

/* ============================================================
   Buttons
   ============================================================ */
.rf-form button[type="button"],
.rf-form button[type="submit"] {
    display: inline-block;
    width: 100%;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--rf-radius-sm);
    cursor: pointer;
    transition: background-color 0.15s, box-shadow 0.15s, transform 0.1s;
    line-height: 1.4;
    border: none;
}

/* Default / secondary button */
.rf-form button[type="button"] {
    background: #f0f2f5;
    color: #344054;
    border: 1px solid var(--rf-border);
}

.rf-form button[type="button"]:hover {
    background: #e4e7ec;
}

/* Primary blue - submit, upload, mockup, modal OK */
.rf-form button[type="submit"],
#rf-upload-cv-btn,
#rf-mockup-cv-btn,
.rf-modal__button {
    background: var(--rf-primary);
    color: #ffffff;
    border: none;
}

.rf-form button[type="submit"]:hover,
#rf-upload-cv-btn:hover,
#rf-mockup-cv-btn:hover,
.rf-modal__button:hover {
    background: var(--rf-primary-dark);
    box-shadow: 0 2px 8px rgba(0, 92, 185, 0.3);
}

/* Upload/Mockup: auto-width, slightly smaller */
#rf-upload-cv-btn,
#rf-mockup-cv-btn {
    width: auto;
    padding: 8px 16px;
    font-size: 13px;
}

.rf-form button:active,
#rf-upload-cv-btn:active,
#rf-mockup-cv-btn:active,
.rf-modal__button:active {
    transform: translateY(1px);
    box-shadow: none;
}

/* Add-row button: outlined primary */
.rf-add-row-btn {
    background: var(--rf-bg-white) !important;
    color: var(--rf-primary) !important;
    border: 1px solid var(--rf-primary) !important;
    font-size: 13px !important;
    padding: 7px 14px !important;
    width: auto !important;
    margin-top: 6px;
}

.rf-add-row-btn:hover {
    background: var(--rf-primary-light) !important;
}

/* Remove row button: outlined danger
   Use ID selectors (#experience-table / #education-table) for specificity
   to safely override any theme or cached rule. */
#experience-table button.remove-exp-row,
#education-table button.remove-edu-row,
.rf-form .remove-exp-row,
.rf-form .remove-edu-row {
    background: #ffffff !important;
    color: #c0392b !important;
    border: 1px solid #f5a0a0 !important;
    padding: 6px 12px !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    border-radius: 5px !important;
    width: 100% !important;
    cursor: pointer;
    transition: background-color 0.15s !important;
    box-shadow: none !important;
}

#experience-table button.remove-exp-row:hover,
#education-table button.remove-edu-row:hover,
.rf-form .remove-exp-row:hover,
.rf-form .remove-edu-row:hover {
    background: #fef5f5 !important;
    border-color: #c0392b !important;
}

/* Submit row */
.rf-submit-row {
    text-align: center;
    margin-top: 24px;
}

.rf-submit-row button[type="submit"] {
    width: auto;
    min-width: 200px;
    padding: 13px 36px;
    font-size: 16px;
}

/* ============================================================
   Experience & Education Tables
   Mobile: 2-col grid cards  |  Desktop: full table
   ============================================================ */

/* Scroll container — prevents table from breaking page layout on
   narrow content areas (e.g. when a WP theme has a sidebar). */
.rf-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Visual hint that content can scroll horizontally */
    background:
        /* left shadow */
        linear-gradient(to right, #fff 30%, rgba(255,255,255,0)),
        linear-gradient(to left,  #fff 30%, rgba(255,255,255,0)) 100% 0,
        radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.06), transparent),
        radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.06), transparent) 100% 0;
    background-repeat: no-repeat;
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
}

.rf-form .exp-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0;
}

/* Mobile: hide thead, stack each row as a 2-column grid card */
.rf-form .exp-table thead {
    display: none;
}

.rf-form .exp-table tbody {
    display: block;
}

.rf-form .exp-table tr.experience-row,
.rf-form .exp-table tr.education-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 14px;
    margin-bottom: 12px;
    padding: 14px 14px 10px;
    border: 1px solid #e4eaf3;
    border-radius: 6px;
    background: #fafbfc;
}

/* Duration + Remove span full width */
.rf-form .exp-table tr.experience-row td:nth-child(5),
.rf-form .exp-table tr.experience-row td:nth-child(6),
.rf-form .exp-table tr.education-row td:nth-child(6) {
    grid-column: 1 / -1;
}

.rf-form .exp-table td {
    padding: 0 0 10px 0;
    border: none;
    background: transparent;
    display: block;
}

.rf-form .exp-table td:last-child {
    padding-bottom: 0;
}

.rf-form .exp-table input,
.rf-form .exp-table select {
    width: 100%;
}

/* Mobile labels via ::before (bilingual) */
#experience-table td:nth-child(1)::before { content: "Organization / บริษัท"; }
#experience-table td:nth-child(2)::before { content: "Position / ตำแหน่ง"; }
#experience-table td:nth-child(3)::before { content: "Date from / วันที่เริ่ม"; }
#experience-table td:nth-child(4)::before { content: "Date to / วันที่สิ้นสุด"; }
#experience-table td:nth-child(5)::before { content: "Duration / ระยะเวลา"; }

#education-table td:nth-child(1)::before { content: "Institution / สถาบัน"; }
#education-table td:nth-child(2)::before { content: "Level / ระดับ"; }
#education-table td:nth-child(3)::before { content: "Major / สาขา"; }
#education-table td:nth-child(4)::before { content: "Grad Year / ปีที่จบ"; }
#education-table td:nth-child(5)::before { content: "GPA"; }

#experience-table td:nth-child(1)::before,
#experience-table td:nth-child(2)::before,
#experience-table td:nth-child(3)::before,
#experience-table td:nth-child(4)::before,
#experience-table td:nth-child(5)::before,
#education-table td:nth-child(1)::before,
#education-table td:nth-child(2)::before,
#education-table td:nth-child(3)::before,
#education-table td:nth-child(4)::before,
#education-table td:nth-child(5)::before {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--rf-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

/* Experience duration display */
.rf-form .exp-duration {
    display: inline-block;
    padding: 8px 12px;
    font-size: 13px;
    border: 1px solid var(--rf-border);
    border-radius: var(--rf-radius-sm);
    background: #f5f6f8;
    color: #344054;
    min-width: 160px;
    font-weight: 500;
}

/* ============================================================
   Notifications
   ============================================================ */
.rf-notification {
    padding: 11px 15px;
    border-radius: var(--rf-radius-sm);
    margin-bottom: 8px;
    font-size: 13px;
    animation: rfSlideIn 0.2s ease-out;
}

.rf-notification.success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.rf-notification.error {
    background: var(--rf-danger-bg);
    color: #991b1b;
    border: 1px solid var(--rf-danger-border);
}

@keyframes rfSlideIn {
    from { opacity: 0; transform: translateY(-5px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Resume Success Modal
   ============================================================ */
.rf-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
}

.rf-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.rf-modal__dialog {
    position: relative;
    width: calc(100% - 32px);
    max-width: 540px;
    margin: 10vh auto 0;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.rf-modal__header {
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    background: var(--rf-primary-light);
}

.rf-modal__title {
    font-size: 15px;
    font-weight: 700;
    color: var(--rf-primary);
    line-height: 1.4;
}

.rf-modal__body {
    padding: 18px 20px;
    color: #333;
    font-size: 14px;
    line-height: 1.7;
}

.rf-modal__body p {
    margin: 0 0 10px 0;
    text-align: left;
}

.rf-modal__body p:last-child {
    margin-bottom: 0;
}

.rf-modal__footer {
    padding: 12px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
}

.rf-modal__button {
    width: auto !important;
    padding: 9px 22px !important;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--rf-radius-sm);
    cursor: pointer;
    transition: background-color 0.15s, transform 0.1s;
}

/* ============================================================
   Form-level Success / Error messages
   ============================================================ */
.rf-success {
    background: #ecfdf5;
    border: 1px solid #6ee7b7;
    color: #065f46;
    padding: 16px 20px;
    border-radius: var(--rf-radius);
    margin-bottom: 24px;
    font-weight: 500;
}

.rf-error {
    background: var(--rf-danger-bg);
    border: 1px solid var(--rf-danger-border);
    color: #991b1b;
    padding: 16px 20px;
    border-radius: var(--rf-radius);
    margin-bottom: 24px;
}

/* ============================================================
   TABLET (768px+)
   ============================================================ */
@media (min-width: 768px) {
    .rf-form {
        padding: 0 0 40px;
        max-width: 980px;
    }

    .rf-form h2 {
        font-size: 26px;
    }

    .rf-form .rf-section {
        padding: 24px 28px 12px;
    }

    /* 2-column label + field layout */
    .rf-form .form-table tr {
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        margin-bottom: 10px;
    }

    .rf-form .form-table th {
        width: 210px;
        min-width: 210px;
        flex-shrink: 0;
        padding: 10px 16px 0 0;
        display: block;
    }

    .rf-form .form-table td {
        flex: 1;
        min-width: 0;
        display: block;
        padding: 4px 0 0;
    }

    /* Buttons: auto-width on tablet+ */
    .rf-form button[type="button"],
    .rf-form button[type="submit"] {
        width: auto;
    }

    .rf-submit-row {
        text-align: center;
    }

    .rf-submit-row button[type="submit"] {
        min-width: 220px;
    }
}

/* ============================================================
   DESKTOP (1024px+)
   exp/edu tables switch to full table layout here (not at 768px)
   so narrower content areas (e.g. WP themes with sidebars) still
   get card layout instead of horizontal overflow.
   ============================================================ */
@media (min-width: 1024px) {
    .rf-form {
        max-width: 1100px;
        padding: 0 0 48px;
    }

    .rf-form .rf-section {
        padding: 26px 32px 14px;
    }

    .rf-form .form-table th {
        width: 240px;
        min-width: 240px;
    }

    /* Hide mobile ::before labels */
    #experience-table td::before,
    #education-table td::before {
        display: none !important;
    }

    /* Revert exp/edu tables to proper <table> layout */
    .rf-form .exp-table {
        display: table;
    }

    .rf-form .exp-table thead {
        display: table-header-group;
    }

    .rf-form .exp-table tbody {
        display: table-row-group;
    }

    .rf-form .exp-table tr.experience-row,
    .rf-form .exp-table tr.education-row {
        display: table-row;
        grid-template-columns: none;
        gap: 0;
        margin-bottom: 0;
        padding: 0;
        border: none;
        border-radius: 0;
        background: transparent;
    }

    /* Reset grid-column span overrides (from mobile) */
    .rf-form .exp-table tr.experience-row td:nth-child(5),
    .rf-form .exp-table tr.experience-row td:nth-child(6),
    .rf-form .exp-table tr.education-row td:nth-child(6) {
        grid-column: auto;
    }

    .rf-form .exp-table th {
        display: table-cell;
        padding: 8px 10px;
        font-size: 12px;
        font-weight: 700;
        color: var(--rf-text-muted);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        border-bottom: 2px solid #e4eaf3;
        text-align: left;
        white-space: nowrap;
        background: transparent;
    }

    .rf-form .exp-table td {
        display: table-cell;
        padding: 8px 8px;
        border-bottom: 1px solid #f0f2f5;
        background: transparent;
        vertical-align: middle;
    }

    #experience-table button.remove-exp-row,
    #education-table button.remove-edu-row,
    .rf-form .remove-exp-row,
    .rf-form .remove-edu-row {
        width: auto !important;
        white-space: nowrap;
    }
}
