/* ===== GLOBAL ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Cairo', sans-serif;
    background: #f0f2f5;
    color: #333;
    direction: rtl;
}

/* ===== FORM PANEL ===== */
.form-panel {
    max-width: 960px;
    margin: 30px auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 20px rgba(0,0,0,0.08);
    overflow: hidden;
}
.form-header {
    background: #fff;
    color: #8b0000;
    text-align: center;
    padding: 22px 20px;
    border-bottom: 3px solid #8b0000;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}
.form-header img.form-logo { height: 55px; width: auto; }
.form-header h2 { font-size: 20px; font-weight: 700; color: #8b0000; }
.form-header p { font-size: 13px; color: #888; margin-top: 3px; }
.form-body { padding: 22px 28px; }
/* Accordion sections */
.form-section {
    margin-bottom: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    transition: box-shadow 0.2s;
}
.form-section:hover {
    box-shadow: 0 2px 10px rgba(139,0,0,0.08);
}
.section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    cursor: pointer;
    background: #fff;
    border: none;
    width: 100%;
    text-align: right;
    user-select: none;
    transition: background 0.2s;
}
.section-toggle:hover { background: #fdf5f5; }
.form-section.open .section-toggle { background: #fdf5f5; border-bottom: 2px solid #8b0000; }
.section-toggle-title {
    display: flex;
    align-items: center;
    gap: 10px;
}
.section-toggle-title .sec-icon {
    width: 32px; height: 32px;
    background: #8b0000;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 15px; flex-shrink: 0;
}
.section-toggle-title h3 {
    font-size: 14px; font-weight: 700; color: #222;
    margin: 0; padding: 0; border: none;
}
.section-toggle-title .sec-summary {
    font-size: 11px; color: #888; margin-top: 2px;
}
.section-arrow {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: #f0f0f0;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.3s, background 0.2s;
    flex-shrink: 0;
    font-size: 12px; color: #555;
}
.form-section.open .section-arrow {
    transform: rotate(180deg);
    background: #8b0000;
    color: #fff;
}
.section-body {
    padding: 16px 18px;
    display: none;
    background: #fafafa;
    border-top: 1px solid #f0f0f0;
    animation: slideDown 0.2s ease;
}
.form-section.open .section-body { display: block; }
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-field { display: flex; flex-direction: column; }
.form-field label { font-size: 12px; font-weight: 600; margin-bottom: 4px; color: #555; }
.form-field input, .form-field select, .form-field textarea {
    padding: 8px 10px;
    border: 1px solid #ddd; border-radius: 6px;
    font-family: 'Cairo', sans-serif; font-size: 13px;
    direction: rtl;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
    border-color: #8b0000; outline: none;
    box-shadow: 0 0 0 2px rgba(139,0,0,0.1);
}
.form-field textarea { resize: vertical; min-height: 60px; }
.hint { font-size: 11px; color: #888; margin-bottom: 8px; }

/* Optional service checkboxes in form */
.opt-check-grid { display: flex; flex-direction: column; gap: 8px; }
.opt-check-item {
    display: flex; align-items: center; gap: 10px;
    background: #fff; border: 1px solid #ddd; border-radius: 8px;
    padding: 10px 13px; cursor: pointer;
}
.opt-check-item:hover { border-color: #8b0000; background: #fff9f9; }
.opt-check-item input[type="checkbox"] {
    width: 17px; height: 17px; accent-color: #8b0000;
    flex-shrink: 0; cursor: pointer;
}
.opt-check-item .opt-name { font-size: 13px; font-weight: 700; color: #222; }
.opt-check-item .opt-desc { font-size: 11px; color: #777; margin-top: 2px; }

/* Price field inside optional item */
.opt-price-field {
    display: flex; flex-direction: column; align-items: flex-end;
    flex-shrink: 0; gap: 4px;
}
.opt-price-lbl { font-size: 10px; color: #888; white-space: nowrap; }
.opt-price-input-row {
    display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}
.opt-price-field input[type="number"] {
    width: 90px; padding: 5px 8px; border: 1.5px solid #8b0000;
    border-radius: 6px; font-family: 'Cairo', sans-serif;
    font-size: 13px; font-weight: 700; color: #8b0000;
    text-align: center; outline: none;
}
.opt-price-field input[type="number"]:focus { background: #fff5f5; }
.opt-price-field input[type="number"]:disabled { border-color: #ccc; color: #aaa; }

/* On-demand toggle */
.on-demand-toggle {
    display: flex; align-items: center; gap: 4px;
    font-size: 11px; color: #8b0000; cursor: pointer;
    font-family: 'Cairo', sans-serif; white-space: nowrap;
    user-select: none;
}
.on-demand-toggle input[type="checkbox"] {
    width: 13px; height: 13px; accent-color: #8b0000;
    cursor: pointer; pointer-events: none;
}

/* Grand total row in price table */
.grand-total-row td {
    background: #8b0000 !important; color: #fff !important;
    font-weight: 800; font-size: 13px; text-align: center;
}

.form-actions {
    display: flex; gap: 15px; justify-content: center;
    padding-top: 18px; border-top: 1px solid #eee;
}
.btn-preview {
    background: #8b0000; color: #fff; border: none; border-radius: 8px;
    padding: 12px 38px; cursor: pointer;
    font-family: 'Cairo', sans-serif; font-size: 15px; font-weight: 700;
}
.btn-preview:hover { background: #6b0000; }
.btn-print {
    background: #2980b9; color: #fff; border: none; border-radius: 8px;
    padding: 12px 38px; cursor: pointer;
    font-family: 'Cairo', sans-serif; font-size: 15px; font-weight: 700;
}
.btn-print:hover { background: #21618c; }

/* ===== PREVIEW PANEL ===== */
.preview-panel { max-width: 900px; margin: 30px auto; }
.preview-toolbar { display: flex; justify-content: space-between; margin-bottom: 18px; }
.btn-back {
    background: #555; color: #fff; border: none; border-radius: 8px;
    padding: 10px 26px; cursor: pointer;
    font-family: 'Cairo', sans-serif; font-size: 14px; font-weight: 600;
}
.btn-back:hover { background: #333; }

/* ===== QUOTE PAGE A4 ===== */
.quote-page {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto 20px;
    background-color: #fff;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: top left;
    position: relative;
    page-break-after: always;
    display: flex;
    flex-direction: column;
    direction: rtl;
    font-family: 'Cairo', sans-serif;
    overflow: hidden;
    padding-right: 8mm;
}

/* Header spacer - matches template header height ~11% of A4 */
.qh-spacer { height: 32mm; flex-shrink: 0; }
/* Footer spacer with page number inside */
.qf-spacer {
    height: 14mm;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
}

/* ===== INFO BAR ===== */
.q-infobar {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    margin: 10px 22px;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    direction: rtl;
}
.q-infobar-cell {
    padding: 7px 12px;
    border-left: 1px solid #ddd;
    text-align: center;
    background: #fff;
}
.q-infobar-cell:last-child { border-left: none; }
.q-infobar-cell .qi-label { font-size: 10px; color: #888; display: block; margin-bottom: 2px; }
.q-infobar-cell .qi-val { font-size: 13px; font-weight: 700; color: #222; }

/* ===== SECTION TITLE RED ===== */
.q-sec-title {
    font-size: 14px; font-weight: 700; color: #8b0000;
    margin: 10px 22px 6px;
    padding-bottom: 4px;
    border-bottom: 1.5px solid #8b0000;
    text-align: right;
}

/* ===== CLIENT TABLE ===== */
.q-client-table {
    margin: 0 22px 8px;
    width: calc(100% - 44px);
    border-collapse: collapse;
    font-size: 12px;
    direction: rtl;
}
.q-client-table td {
    padding: 5px 9px;
    border: 1px solid #e0e0e0;
    vertical-align: middle;
}
.q-client-table td.lbl {
    font-weight: 700; color: #555;
    white-space: nowrap; background: #fafafa;
    width: 120px;
}
.q-client-table td.val { color: #222; }

/* ===== SERVICE BOX ===== */
.q-service-box {
    margin: 0 22px 8px;
    display: grid;
    grid-template-columns: 185px 1fr;
    border: 1px solid #ddd;
    border-radius: 5px;
    overflow: hidden;
    direction: rtl;
}
.q-service-left {
    background: #8b0000; color: #fff;
    padding: 12px 10px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
}
.q-service-left .svc-label { font-size: 11px; font-weight: 600; margin-bottom: 3px; }
.q-service-left .svc-price { font-size: 28px; font-weight: 900; line-height: 1; display: flex; align-items: center; justify-content: center; gap: 4px; }
.q-service-left .svc-price svg { width: 26px; height: 28px; fill: currentColor; flex-shrink: 0; }
.q-service-left .svc-unit { font-size: 10px; margin-top: 2px; opacity: 0.9; }
.q-service-left .svc-note {
    font-size: 9px; margin-top: 8px; opacity: 0.85;
    line-height: 1.4; border-top: 1px solid rgba(255,255,255,0.3);
    padding-top: 6px;
}
.q-service-right { padding: 12px 16px; background: #fff; }
.q-service-right .svc-name { font-size: 20px; font-weight: 800; color: #222; margin-bottom: 4px; }
.q-service-right .svc-desc { font-size: 11px; color: #666; line-height: 1.5; margin-bottom: 9px; }
.q-service-mini-grid {
    display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 5px;
    direction: rtl;
}
.q-mini-card {
    border: 1px solid #e0e0e0; border-radius: 4px;
    padding: 5px 7px; text-align: center; background: #fafafa;
}
.q-mini-card .mc-lbl { font-size: 9px; color: #888; }
.q-mini-card .mc-val { font-size: 11px; font-weight: 700; color: #222; margin-top: 1px; }

/* ===== PRICE TABLE ===== */
.q-price-table {
    margin: 0 22px 8px;
    width: calc(100% - 44px);
    border-collapse: collapse;
    border-radius: 5px;
    overflow: hidden;
    direction: rtl;
}
.q-price-table thead tr { background: #8b0000; color: #fff; }
.q-price-table th { padding: 8px 10px; text-align: center; font-size: 11px; font-weight: 700; }
.q-price-table td { padding: 8px 10px; text-align: center; border: 1px solid #e0e0e0; font-size: 12px; }
.q-price-table tbody tr:nth-child(even) td { background: #fdf3f3; }

/* ===== INCLUDED SERVICES ===== */
.q-included-box {
    margin: 0 22px 6px;
    border: 1px solid #f0c0b0;
    border-radius: 5px;
    padding: 6px 10px;
    background: #fffaf9;
}
.q-included-title {
    font-size: 12px; font-weight: 800; color: #8b0000;
    margin-bottom: 3px; text-align: right;
}
.q-included-list { columns: 2; column-gap: 10px; list-style: none; padding: 0; }
.q-included-list li {
    font-size: 11px; color: #333; padding: 1px 11px 1px 0;
    position: relative; line-height: 1.4; break-inside: avoid;
}
.q-included-list li::before {
    content: "\2022"; color: #8b0000; font-weight: 700;
    position: absolute; right: 0;
}
.q-included-list li.red-item { color: #8b0000; font-weight: 600; }

/* ===== BOTTOM AREA (note + pagenum pushed to footer) ===== */
.q-bottom-area {
    margin-top: auto;
    margin-bottom: 4mm;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* ===== TAX NOTE ===== */
.q-tax-note {
    margin: 0 22px;
    font-size: 10px; color: #666; line-height: 1.6;
    background: #fffbf0; border: 1px solid #f0e0a0;
    border-radius: 4px; padding: 7px 10px;
    direction: rtl;
}

/* ===== PAGE NUMBER ===== */
.q-pagenum {
    text-align: right;
    padding: 0 22px;
    font-size: 11px; color: #555;
    font-weight: 600;
    width: 100%;
}

/* ===== PAGE 2 TERMS ===== */
.q-terms-main-title {
    font-size: 26px; font-weight: 800; color: #222;
    text-align: right; margin: 12px 22px 3px;
}
.q-terms-main-line {
    margin: 0 22px 10px; border: none;
    border-top: 2px solid #8b0000;
}

/* Optional cards on page 2 */
.q-opt-section-label {
    margin: 0 22px 3px; text-align: right;
}
.q-opt-section-label .osl-sub { font-size: 10px; color: #888; }
.q-opt-section-label .osl-title { font-size: 14px; font-weight: 800; color: #222; }

.q-opt-cards {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 8px; margin: 6px 22px 10px;
    direction: rtl;
}
.q-opt-card {
    border: 1px solid #e0e0e0; border-radius: 7px;
    padding: 9px 11px; background: #fff;
    display: flex; gap: 8px; align-items: flex-start;
}
.q-opt-card.selected { border-color: #8b0000; background: #fffaf9; }
.q-opt-radio {
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid #8b0000; flex-shrink: 0; margin-top: 2px;
    display: flex; align-items: center; justify-content: center;
    background: #fff;
}
.q-opt-card.selected .q-opt-radio { background: #8b0000; }
.q-opt-radio-inner {
    width: 7px; height: 7px; border-radius: 50%; background: #fff;
    display: none;
}
.q-opt-card.selected .q-opt-radio-inner { display: block; }
.q-opt-body { flex: 1; }
.q-opt-body .ob-name { font-size: 12px; font-weight: 700; color: #222; margin-bottom: 2px; }
.q-opt-body .ob-desc { font-size: 10px; color: #666; line-height: 1.5; }
.q-opt-price { font-size: 13px; font-weight: 800; color: #8b0000; white-space: nowrap; text-align: left; }

/* Terms content blocks */
.q-terms-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 22px 8px; direction: rtl; }
.q-terms-single { margin: 0 22px 8px; direction: rtl; }
.q-terms-block {
    background: #fffaf9; border: 1.5px solid #f0c0b0;
    border-radius: 5px; padding: 9px 12px;
}
.q-terms-block-title {
    font-size: 12px; font-weight: 700; color: #8b0000;
    margin-bottom: 6px; text-align: right;
}
.q-terms-block ul { list-style: none; padding: 0; }
.q-terms-block ul li {
    font-size: 10px; color: #444; padding: 2px 12px 2px 0;
    position: relative; line-height: 1.6;
}
.q-terms-block ul li::before {
    content: "\2022"; color: #8b0000; position: absolute; right: 0;
}
.q-terms-block p { font-size: 10px; color: #444; line-height: 1.6; }

/* Approval + signatures */
.q-approval-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 22px 8px; direction: rtl; }
.q-approval-block {
    background: #fffaf9; border: 1.5px solid #f0c0b0;
    border-radius: 5px; padding: 10px 12px;
}
.q-approval-block .ab-title { font-size: 12px; font-weight: 700; color: #8b0000; margin-bottom: 5px; }
.q-approval-block p { font-size: 10px; color: #444; line-height: 1.7; }
.q-approval-block .ab-sig {
    margin-top: 22px; border-top: 1px solid #ccc;
    padding-top: 3px; font-size: 10px; color: #888; text-align: center;
}

/* Company signature block centered */
.q-company-sig-wrap { display: flex; justify-content: center; margin: 10px 22px 6px; }
.q-company-sig-box {
    width: 240px; text-align: center;
    background: #fffaf9; border: 1.5px solid #f0c0b0;
    border-radius: 5px; padding: 10px 16px 8px;
}
.csb-title { font-size: 11px; font-weight: 700; color: #8b0000; margin-bottom: 6px; }
.csb-sig-img {
    height: 44px; display: flex; align-items: center; justify-content: center;
    margin: 2px 0; overflow: hidden;
}
.csb-sig-img img {
    width: 120px; height: 44px;
    object-fit: contain; object-position: center; display: block;
}
.csb-hint { font-size: 10px; color: #888; border-top: 1px solid #ccc; padding-top: 3px; margin-top: 4px; }

/* Grand total row */
.grand-total-row td {
    background: #8b0000 !important; color: #fff !important;
    font-weight: 800; font-size: 13px; text-align: center;
}
.q-closing {
    margin: 0 22px 6px; font-size: 11px; color: #555;
    line-height: 1.7; text-align: center;
}
.q-sigs { display: flex; justify-content: space-between; margin: 6px 22px 4px; direction: rtl; }
.q-sig-block .sig-lbl { font-size: 11px; color: #555; font-weight: 600; }
.q-sig-block .sig-line { border-top: 1px solid #999; width: 150px; margin: 28px auto 0; }

/* ISO */
.q-iso { text-align: center; margin: 4px 0 2px; }
.q-iso img { height: 42px; width: auto; opacity: 0.85; }

/* ===== PRINT ===== */
@media print {
    body { background: #fff; }
    .form-panel, .preview-toolbar { display: none !important; }
    .preview-panel { margin: 0; max-width: none; }
    .quote-page {
        width: 210mm; min-height: 297mm; margin: 0;
        page-break-after: always;
    }
    .quote-page:last-child { page-break-after: auto; }
    @page { size: A4; margin: 0; }
}
