/* Resume Builder - scoped styles (namespaced under .rb to avoid leaking into the rest of the site) */
.rb {
    --rb-accent: #e60023;
    --rb-accent-ink: #ffffff;
    --rb-ink: #1f2d3d;
    --rb-muted: #6b7280;
    --rb-placeholder: #7b8490;
    --rb-border: #e5e7eb;
    --rb-bg-soft: #f7f8fa;
    --rb-radius: 12px;
    --rb-radius-sm: 8px;
    --rb-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 8px rgba(16, 24, 40, .06);
    --rb-input-h: 44px;

    font-family: 'vazirmatn', Tahoma, sans-serif;
    color: var(--text-color, var(--rb-ink));
    max-width: 1320px;
    margin: 0 auto;
    padding: 20px 16px 64px;
}

[data-theme="dark"] .rb {
    --rb-placeholder: #aeb6c2;
    --rb-border: rgba(255, 255, 255, .12);
    --rb-bg-soft: rgba(255, 255, 255, .04);
    --rb-shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 2px 10px rgba(0, 0, 0, .3);
}

.rb * { box-sizing: border-box; }

/* ---------- Page header ---------- */
.rb-page-head { margin-bottom: 20px; text-align: center; }
.rb-page-head h1 { font-size: 24px; font-weight: 800; margin: 0 0 6px; color: var(--text-color, var(--rb-ink)); }
.rb-page-head p { font-size: 14px; color: var(--text2-color, var(--rb-muted)); margin: 0; }

/* ---------- Layout: form + preview ---------- */
.rb-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 24px;
    align-items: start;
}

@media (max-width: 991px) {
    .rb-layout { grid-template-columns: 1fr; }
    .rb-preview-col { display: none; }
}

/* ---------- Stepper ---------- */
.rb-stepper {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    background: var(--bg-color2, #fff);
    border: 1px solid var(--rb-border);
    border-radius: var(--rb-radius);
    padding: 10px;
    margin-bottom: 20px;
    box-shadow: var(--rb-shadow);
    -webkit-overflow-scrolling: touch;
}

.rb-step-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 0 auto;
    padding: 8px 12px;
    border: none;
    background: transparent;
    border-radius: var(--rb-radius-sm);
    cursor: pointer;
    white-space: nowrap;
    color: var(--text2-color, var(--rb-muted));
    font-family: inherit;
    font-size: 13px;
    transition: background-color .15s ease, color .15s ease;
}

.rb-step-tab:hover { background: var(--rb-bg-soft); }

.rb-step-tab__num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    background: var(--rb-bg-soft);
    color: var(--text2-color, var(--rb-muted));
    flex-shrink: 0;
}

.rb-step-tab.is-active { color: var(--rb-ink); }
[data-theme="dark"] .rb-step-tab.is-active { color: #fff; }
.rb-step-tab.is-active .rb-step-tab__num { background: var(--rb-accent); color: var(--rb-accent-ink); }

.rb-step-tab.is-done .rb-step-tab__num { background: #16a34a; color: #fff; }
.rb-step-tab.is-done .rb-step-tab__num::before { content: "\2713"; }

.rb-step-tab.has-error .rb-step-tab__num { background: #dc2626; color: #fff; }

/* ---------- Cards / sections ---------- */
.rb-card {
    background: var(--bg-color2, #fff);
    border: 1px solid var(--rb-border);
    border-radius: var(--rb-radius);
    box-shadow: var(--rb-shadow);
    padding: 22px;
    margin-bottom: 18px;
}

.rb-card__title { font-size: 16px; font-weight: 700; margin: 0 0 4px; color: var(--text-color, var(--rb-ink)); }
.rb-card__hint { font-size: 12.5px; color: var(--text2-color, var(--rb-muted)); margin: 0 0 16px; }

.rb-step { }
.rb-step[hidden] { display: none !important; }

.rb-step-heading { margin-bottom: 16px; }
.rb-step-heading h2 { font-size: 19px; font-weight: 800; margin: 0 0 4px; color: var(--text-color, var(--rb-ink)); }
.rb-step-heading p { font-size: 13px; color: var(--text2-color, var(--rb-muted)); margin: 0; }

/* ---------- Form grid & controls ---------- */
.rb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.rb-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 640px) {
    .rb-grid, .rb-grid.cols-2 { grid-template-columns: 1fr; }
}

.rb-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.rb-field:last-child { margin-bottom: 0; }
.rb-field.span-2 { grid-column: span 2; }
@media (max-width: 640px) { .rb-field.span-2 { grid-column: span 1; } }

.rb-label { font-size: 13px; font-weight: 600; color: var(--text-color, var(--rb-ink)); }
.rb-label .req { color: var(--rb-accent); margin-inline-start: 2px; }
.rb-label .opt { font-weight: 400; color: var(--text2-color, var(--rb-muted)); font-size: 11.5px; }

.rb-input, .rb-textarea, .rb-select {
    width: 100%;
    min-height: var(--rb-input-h);
    padding: 9px 12px;
    border: 1px solid var(--rb-border);
    border-radius: var(--rb-radius-sm);
    background: var(--bg-color2, #fff);
    color: var(--text-color, #1f2937);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.rb-textarea { min-height: 96px; resize: vertical; line-height: 1.6; }

.rb-input::placeholder,
.rb-textarea::placeholder {
    color: var(--rb-placeholder);
    opacity: 1;
}

.rb-input:focus, .rb-textarea:focus, .rb-select:focus {
    border-color: var(--rb-accent);
    box-shadow: 0 0 0 3px rgba(210, 0, 0, .12);
}

.rb-input.is-invalid, .rb-textarea.is-invalid, .rb-select.is-invalid {
    border-color: #dc2626;
}

.rb-input:disabled, .rb-textarea:disabled, .rb-select:disabled {
    background: var(--rb-bg-soft);
    color: var(--text2-color, var(--rb-muted));
    cursor: not-allowed;
}

.rb-field-error { font-size: 12px; color: #dc2626; }

.rb-checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-color, var(--rb-ink)); }
.rb-checkbox-row input { width: 16px; height: 16px; accent-color: var(--rb-accent); }

/* ---------- Profile image uploader ---------- */
.rb-avatar-uploader { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

.rb-avatar-preview {
    width: 84px;
    height: 84px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--rb-ink);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    font-weight: 700;
    flex-shrink: 0;
    border: 3px solid var(--rb-bg-soft);
}

.rb-avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

.rb-avatar-actions { display: flex; flex-direction: column; gap: 6px; }
.rb-avatar-actions .rb-btn { align-self: flex-start; }
.rb-avatar-hint { font-size: 11.5px; color: var(--text2-color, var(--rb-muted)); margin: 0; }

/* ---------- Dynamic list cards ---------- */
.rb-list-empty {
    border: 1.5px dashed var(--rb-border);
    border-radius: var(--rb-radius);
    padding: 22px;
    text-align: center;
    color: var(--text2-color, var(--rb-muted));
    font-size: 13px;
    margin-bottom: 14px;
}

.rb-item-card {
    border: 1px solid var(--rb-border);
    border-radius: var(--rb-radius);
    padding: 16px 18px;
    margin-bottom: 12px;
    position: relative;
    background: var(--bg-color2, #fff);
}

.rb-item-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.rb-item-card__label { font-size: 12.5px; font-weight: 700; color: var(--text2-color, var(--rb-muted)); }

.rb-item-remove {
    border: none;
    background: transparent;
    color: #dc2626;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    min-height: 32px;
}

.rb-item-remove:hover { background: rgba(220, 38, 38, .08); }

.rb-add-btn {
    width: 100%;
    border: 1.5px dashed var(--rb-accent);
    color: var(--rb-accent);
    background: transparent;
    border-radius: var(--rb-radius);
    padding: 12px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    font-family: inherit;
    transition: background-color .15s ease;
}

.rb-add-btn:hover { background: rgba(210, 0, 0, .06); }
.rb-add-btn .plus { width: 20px; height: 20px; border-radius: 50%; background: var(--rb-accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; line-height: 1; }

/* ---------- Footer nav ---------- */
.rb-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    gap: 10px;
}

.rb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 22px;
    border-radius: var(--rb-radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: opacity .15s ease, background-color .15s ease;
}

.rb-btn:disabled { opacity: .6; cursor: not-allowed; }
.rb-btn-primary { background: var(--rb-accent); color: #fff; }
.rb-btn-primary:hover:not(:disabled) { opacity: .92; }
.rb-btn-accent { background: var(--rb-accent); color: #fff; }
.rb-btn-accent:hover:not(:disabled) { opacity: .92; }
.rb-btn-ghost { background: transparent; color: var(--text-color, var(--rb-ink)); border-color: var(--rb-border); }
.rb-btn-ghost:hover:not(:disabled) { background: var(--rb-bg-soft); }
.rb-btn.is-loading .rb-btn-label { visibility: hidden; }
.rb-btn.is-loading { position: relative; }
.rb-btn.is-loading::after {
    content: "";
    position: absolute;
    width: 18px; height: 18px;
    border-radius: 50%;
    border: 2.5px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    animation: rb-spin .7s linear infinite;
}

@keyframes rb-spin { to { transform: rotate(360deg); } }

.rb-nav-spacer { flex: 1; }

/* ---------- Preview (desktop sidebar + mobile modal) ---------- */
.rb-preview-col { position: sticky; top: 16px; }

.rb-preview-shell {
    background: var(--bg-color2, #fff);
    border: 1px solid var(--rb-border);
    border-radius: var(--rb-radius);
    box-shadow: var(--rb-shadow);
    overflow: hidden;
}

.rb-preview-shell__label {
    padding: 10px 14px;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text2-color, var(--rb-muted));
    border-bottom: 1px solid var(--rb-border);
}

/*
 * The live preview is the exact same resume-template.blade.php document
 * Browsershot renders for the final PDF, loaded into an iframe via srcdoc -
 * not a hand-built approximation. It's authored at a fixed A4 pixel size
 * (794x1123, matching 210mm/297mm at 96dpi) so it's pixel-identical to the
 * PDF; JS scales the iframe element itself down to fit its container.
 */
.rb-preview-frame-wrap {
    width: 100%;
    aspect-ratio: 210 / 297;
    overflow-y: auto;
    overflow-x: hidden;
    background: #fff;
}

.rb-preview-frame {
    width: 794px;
    height: 1123px;
    border: 0;
    display: block;
    transform-origin: top right;
    background: #fff;
}

.rb-preview-empty { padding: 40px 20px; text-align: center; color: #9aa2ad; font-size: 11.5px; }

/* Mobile preview trigger + modal */
.rb-preview-fab {
    display: none;
}

@media (max-width: 991px) {
    .rb-preview-fab {
        display: flex;
        position: fixed;
        inset-inline-end: 18px;
        bottom: 18px;
        z-index: 60;
        align-items: center;
        gap: 8px;
        padding: 12px 18px;
        border-radius: 999px;
        background: var(--rb-accent);
        color: #fff;
        border: none;
        box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
        font-family: inherit;
        font-size: 13px;
        font-weight: 700;
        cursor: pointer;
    }
}

.rb-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(15, 18, 24, .55);
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.rb-preview-modal.is-open { display: flex; }

.rb-preview-modal__sheet {
    width: 100%;
    max-width: 480px;
    max-height: 88vh;
    background: var(--bg-color2, #fff);
    border-radius: 16px 16px 0 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.rb-preview-modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--rb-border);
}

.rb-preview-modal__head strong { font-size: 14px; }

.rb-preview-modal__close {
    border: none;
    background: var(--rb-bg-soft);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-color, var(--rb-ink));
}

.rb-preview-modal .rb-preview-frame-wrap { aspect-ratio: auto; max-height: 70vh; border-radius: 0; }

/* ---------- Final step ---------- */
.rb-final-card { text-align: center; padding: 34px 22px; }
.rb-final-card .rb-icon { width: 56px; height: 56px; border-radius: 50%; background: rgba(210,0,0,.1); color: var(--rb-accent); display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; font-size: 26px; }
.rb-final-card h2 { font-size: 19px; margin: 0 0 6px; }
.rb-final-card p { font-size: 13.5px; color: var(--text2-color, var(--rb-muted)); margin: 0 0 20px; }

.rb-summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 0 0 24px; text-align: center; }
@media (max-width: 640px) { .rb-summary-grid { grid-template-columns: repeat(2, 1fr); } }
.rb-summary-tile { border: 1px solid var(--rb-border); border-radius: var(--rb-radius-sm); padding: 12px 8px; }
.rb-summary-tile strong { display: block; font-size: 18px; color: var(--rb-ink); }
[data-theme="dark"] .rb-summary-tile strong { color: #fff; }
.rb-summary-tile span { font-size: 11.5px; color: var(--text2-color, var(--rb-muted)); }

.rb-toast {
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2d3d;
    color: #fff;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 13px;
    z-index: 300;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}

.rb-toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Mobile layout ---------- */
.rb-main-col,
.rb-main-col form,
.rb-step,
.rb-card,
.rb-field,
.rb-item-card {
    min-width: 0;
}

.rb-input,
.rb-textarea,
.rb-select {
    max-width: 100%;
}

@media (max-width: 640px) {
    .rb {
        width: 100%;
        max-width: 100%;
        padding: 14px 10px 110px;
        overflow-x: clip;
    }

    .rb-page-head {
        margin-bottom: 14px;
        padding-inline: 4px;
    }

    .rb-page-head h1 {
        font-size: 20px;
        line-height: 1.5;
    }

    .rb-page-head p {
        font-size: 12.5px;
        line-height: 1.8;
    }

    .rb-stepper {
        width: 100%;
        gap: 6px;
        padding: 7px;
        margin-bottom: 16px;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
    }

    .rb-stepper::-webkit-scrollbar {
        display: none;
    }

    .rb-step-tab {
        flex: 0 0 auto;
        min-width: 38px;
        min-height: 40px;
        padding: 7px;
        justify-content: center;
        scroll-snap-align: center;
    }

    .rb-step-tab > span:last-child {
        display: none;
    }

    .rb-step-tab.is-active {
        padding-inline: 10px;
    }

    .rb-step-tab.is-active > span:last-child {
        display: inline;
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .rb-card {
        padding: 14px;
        margin-bottom: 14px;
    }

    .rb-step-heading {
        margin-bottom: 12px;
    }

    .rb-step-heading h2 {
        font-size: 17px;
        line-height: 1.5;
    }

    .rb-step-heading p,
    .rb-card__hint {
        line-height: 1.75;
    }

    .rb-grid,
    .rb-grid.cols-2 {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
    }

    .rb-field,
    .rb-field.span-2 {
        grid-column: 1 / -1;
        width: 100%;
        margin-bottom: 13px;
    }

    .rb-input,
    .rb-textarea,
    .rb-select {
        font-size: 16px;
    }

    .rb-avatar-uploader {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .rb-avatar-preview {
        margin-inline: auto;
    }

    .rb-avatar-actions {
        width: 100%;
        align-items: stretch;
    }

    .rb-avatar-actions .rb-btn {
        width: 100%;
        align-self: stretch;
    }

    .rb-item-card {
        padding: 12px;
    }

    .rb-item-card__head {
        gap: 8px;
        flex-wrap: wrap;
    }

    .rb-list-empty {
        padding: 18px 12px;
        line-height: 1.8;
    }

    .rb-add-btn {
        padding-inline: 10px;
        line-height: 1.6;
    }

    .rb-nav {
        position: sticky;
        bottom: 0;
        z-index: 40;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
        padding: 10px 0;
        margin-top: 14px;
        background: var(--bg-color, #fff);
        border-top: 1px solid var(--rb-border);
    }

    .rb-nav-spacer {
        display: none;
    }

    .rb-nav .rb-btn {
        width: 100%;
        min-width: 0;
        padding-inline: 10px;
    }

    .rb-final-card {
        padding: 24px 14px;
    }

    #rb-submit {
        width: 100%;
        min-width: 0 !important;
    }

    .rb-preview-fab {
        inset-inline-end: 12px;
        bottom: 76px;
        max-width: calc(100vw - 24px);
        padding: 11px 15px;
        box-shadow: 0 5px 16px rgba(0, 0, 0, .22);
    }

    .rb-preview-modal__sheet {
        max-width: 100%;
        max-height: 92dvh;
        border-radius: 14px 14px 0 0;
    }

    .rb-preview-modal .rb-preview-frame-wrap {
        width: 100%;
        max-height: calc(92dvh - 57px);
    }

    .rb-toast {
        width: calc(100% - 24px);
        max-width: 420px;
        bottom: 12px;
        text-align: center;
    }
}

@media (max-width: 359px) {
    .rb-summary-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .rb-btn {
        font-size: 12.5px;
    }
}
