/* ================================================================
   Scarab Warsha — Workshop-specific extras
   - Always-scrollable modals (fix for content > viewport)
   - License plate preview component (interactive)
   - Misc workshop utilities
   ================================================================ */

/* Alpine.js x-cloak: hide before Alpine binds */
[x-cloak] { display: none !important; }

/* CI4 debug toolbar leftover container — hide if AJAX fetch fails */
#toolbarContainer, #debug-bar, #debug-icon { display: none !important; }

/* Bootstrap RTL assumes RTL corner logic for input groups.
   When a specific group opts into dir=ltr we need LTR merging/radii instead. */
html[dir="rtl"] .input-group[dir="ltr"] {
    direction: ltr;
}

html[dir="rtl"] .input-group[dir="ltr"] > :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) {
    margin-left: calc(var(--bs-border-width) * -1);
    margin-right: 0;
}

html[dir="rtl"] .input-group[dir="ltr"]:not(.has-validation) > .dropdown-toggle:nth-last-child(n+3),
html[dir="rtl"] .input-group[dir="ltr"]:not(.has-validation) > .form-floating:not(:last-child) > .form-control,
html[dir="rtl"] .input-group[dir="ltr"]:not(.has-validation) > .form-floating:not(:last-child) > .form-select,
html[dir="rtl"] .input-group[dir="ltr"]:not(.has-validation) > :not(:last-child):not(.dropdown-toggle):not(.dropdown-menu):not(.form-floating),
html[dir="rtl"] .input-group[dir="ltr"].has-validation > .dropdown-toggle:nth-last-child(n+4),
html[dir="rtl"] .input-group[dir="ltr"].has-validation > .form-floating:nth-last-child(n+3) > .form-control,
html[dir="rtl"] .input-group[dir="ltr"].has-validation > .form-floating:nth-last-child(n+3) > .form-select,
html[dir="rtl"] .input-group[dir="ltr"].has-validation > :nth-last-child(n+3):not(.dropdown-toggle):not(.dropdown-menu):not(.form-floating) {
    border-top-left-radius: var(--input-radius, var(--bs-border-radius)) !important;
    border-bottom-left-radius: var(--input-radius, var(--bs-border-radius)) !important;
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

html[dir="rtl"] .input-group[dir="ltr"] > :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback),
html[dir="rtl"] .input-group[dir="ltr"] > .form-floating:not(:first-child) > .form-control,
html[dir="rtl"] .input-group[dir="ltr"] > .form-floating:not(:first-child) > .form-select {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
}

html[dir="rtl"] .input-group[dir="ltr"] > :last-child:not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback),
html[dir="rtl"] .input-group[dir="ltr"] > .form-floating:last-child > .form-control,
html[dir="rtl"] .input-group[dir="ltr"] > .form-floating:last-child > .form-select {
    border-top-right-radius: var(--input-radius, var(--bs-border-radius)) !important;
    border-bottom-right-radius: var(--input-radius, var(--bs-border-radius)) !important;
}

/* ---------- 1. ALWAYS-SCROLLABLE MODALS ----------
   Bootstrap's modal-body doesn't scroll by default. Force every
   modal to behave like .modal-dialog-scrollable so long forms
   never get clipped on small screens. */
.modal-dialog {
    display: flex;
    align-items: center;
    min-height: calc(100% - var(--bs-modal-margin) * 2);
}
.modal-dialog .modal-content {
    max-height: calc(100vh - var(--bs-modal-margin) * 2);
    overflow: hidden;
}
.modal-dialog .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
/* Sticky modal header/footer so they stay visible while scrolling */
.modal-dialog .modal-header,
.modal-dialog .modal-footer { flex-shrink: 0; }

/* Wider modals on desktop for forms with many columns */
@media (min-width: 992px) {
    .modal-lg, .modal-xl { --bs-modal-width: 900px; }
}

/* ---------- 2. SELECT2 INSIDE MODAL ----------
   Ensures Select2 dropdowns open ABOVE the modal backdrop (z-index). */
.select2-container--open { z-index: 9999; }
.select2-container--bootstrap-5 .select2-selection {
    min-height: calc(1.5em + .9rem + 3px);
}
/* Match form-control sizing */
.select2-container--bootstrap-5 .select2-selection--single {
    padding: 5px 12px;
    font-size: .86rem;
}
.select2-container--bootstrap-5 .select2-dropdown {
    border-radius: var(--input-radius);
    border-color: var(--border-color);
    box-shadow: var(--shadow-lg);
}

html[dir="rtl"] .select2-container--bootstrap-5 .select2-selection--single {
    padding-right: .75rem;
    padding-left: 2.25rem;
    background-position: left .75rem center;
}

html[dir="rtl"] .select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear {
    left: 2.25rem;
    right: auto;
}

html[dir="rtl"] .select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__clear {
    left: .75rem;
    right: auto;
}

/* ---------- 3. LICENSE PLATE PREVIEW COMPONENT ----------
   Interactive Saudi-style license plate. Uses CSS variables so plate
   colors change based on plate type (private/public/transport/diplomatic).
   Usage:
     <div class="plate-preview" data-plate-type="private">
       <div class="plate-band">
         <span class="plate-flag"></span> KSA
       </div>
       <div class="plate-grid">
         <div class="plate-cell"><span class="plate-en">1234</span><span class="plate-ar">١٢٣٤</span></div>
         <div class="plate-cell"><span class="plate-en">ABC</span><span class="plate-ar">ا ب ج</span></div>
       </div>
     </div>
*/
.plate-preview {
    --pp-bg:        #ffffff;
    --pp-fg:        #0f172a;
    --pp-band-bg:   #1e3a8a;
    --pp-band-fg:   #ffffff;
    --pp-border:    #1e293b;
    --pp-accent:    #16a34a;

    display: inline-flex;
    flex-direction: column;
    width: 100%;
    max-width: 360px;
    background: var(--pp-bg);
    color: var(--pp-fg);
    border: 3px solid var(--pp-border);
    border-radius: 14px;
    box-shadow: 0 6px 18px rgba(0,0,0,.12), inset 0 0 0 1px rgba(255,255,255,.4);
    font-family: 'Arial Black','IBM Plex Sans Arabic',sans-serif;
    overflow: hidden;
    direction: ltr;
    user-select: none;
    transition: transform .25s var(--ease-out, ease), box-shadow .25s ease;
}
.plate-preview:hover {
    transform: translateY(-2px) rotate(-.5deg);
    box-shadow: 0 12px 28px rgba(0,0,0,.18);
}

/* Top band (country/region strip) */
.plate-preview .plate-band {
    background: var(--pp-band-bg);
    color: var(--pp-band-fg);
    font-size: .72rem;
    letter-spacing: .15em;
    font-weight: 800;
    padding: 4px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-transform: uppercase;
}
.plate-preview .plate-band .plate-flag {
    width: 22px; height: 14px;
    background: var(--pp-accent);
    border-radius: 2px;
    display: inline-block;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.3);
}

/* Two-cell grid: numbers (left) + letters (right) */
.plate-preview .plate-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 0;
    background: var(--pp-bg);
}
.plate-preview .plate-cell {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 80px;
    border-inline-start: 2px dashed rgba(15,23,42,.18);
}
.plate-preview .plate-cell:first-child { border-inline-start: 0; }

.plate-preview .plate-en {
    font-size: 1.9rem;
    font-weight: 900;
    line-height: 1;
    letter-spacing: .08em;
    color: var(--pp-fg);
}
.plate-preview .plate-ar {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: .25em;
    color: var(--pp-fg);
    direction: rtl;
}
.plate-preview .plate-empty { opacity: .25; }

/* ---- Plate type variants (Saudi color codes) ---- */
.plate-preview[data-plate-type="private"]      { /* white default */ }
.plate-preview[data-plate-type="public"]       { --pp-bg: #fde047; --pp-fg: #0f172a; --pp-border: #a16207; }
.plate-preview[data-plate-type="transport"]    { --pp-bg: #fef3c7; --pp-fg: #0f172a; --pp-border: #b45309; }
.plate-preview[data-plate-type="taxi"]         { --pp-bg: #fde047; --pp-fg: #0f172a; --pp-border: #a16207; --pp-band-bg: #ca8a04; }
.plate-preview[data-plate-type="diplomatic"]   { --pp-bg: #1e3a8a; --pp-fg: #ffffff; --pp-border: #0c1c4a; --pp-band-bg: #f59e0b; --pp-band-fg: #1e3a8a; }
.plate-preview[data-plate-type="commercial"]   { --pp-bg: #ffffff; --pp-fg: #0f172a; --pp-border: #16a34a; --pp-band-bg: #16a34a; }
.plate-preview[data-plate-type="motorcycle"]   { --pp-bg: #ffffff; --pp-fg: #0f172a; --pp-border: #1e293b; }
.plate-preview[data-plate-type="temporary"]    { --pp-bg: #fee2e2; --pp-fg: #7f1d1d; --pp-border: #dc2626; --pp-band-bg: #dc2626; }

/* DB-driven dynamic plate type — when style is set inline via CSS variables. */
.plate-preview[data-plate-source="db"] {
    /* Inline `style` on the element provides --pp-bg, --pp-fg, --pp-border, --pp-band-bg. */
}

/* Compact size variant */
.plate-preview.plate-sm {
    max-width: 220px;
}
.plate-preview.plate-sm .plate-cell { min-height: 54px; padding: 6px 8px; }
.plate-preview.plate-sm .plate-en { font-size: 1.2rem; }
.plate-preview.plate-sm .plate-ar { font-size: .8rem; }
.plate-preview.plate-sm .plate-band { font-size: .6rem; padding: 2px 6px; }
.plate-preview.plate-sm .plate-band .plate-flag { width: 16px; height: 10px; }

/* ---------- 4. WORKSHOP MISC ---------- */
.brand-logo-thumb {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--surface-2);
    display: inline-flex; align-items: center; justify-content: center;
    overflow: hidden;
    border: 1px solid var(--border-color);
}
.brand-logo-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* Status pill colors used by work orders */
.status-pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 999px;
    font-size: .73rem; font-weight: 700;
    border: 1px solid transparent;
}
.status-pill.s-open      { background: rgba(14,165,233,.10); color: #0369a1; border-color: rgba(14,165,233,.25); }
.status-pill.s-progress  { background: rgba(245,158,11,.10); color: #b45309; border-color: rgba(245,158,11,.25); }
.status-pill.s-done      { background: rgba(16,185,129,.10); color: #047857; border-color: rgba(16,185,129,.25); }
.status-pill.s-cancel    { background: rgba(239,68,68,.10);  color: #b91c1c; border-color: rgba(239,68,68,.25); }
.status-pill.s-paid      { background: rgba(16,185,129,.10); color: #047857; border-color: rgba(16,185,129,.25); }
.status-pill.s-unpaid    { background: rgba(239,68,68,.10);  color: #b91c1c; border-color: rgba(239,68,68,.25); }
.status-pill.s-partial   { background: rgba(245,158,11,.10); color: #b45309; border-color: rgba(245,158,11,.25); }

[data-theme="dark"] .status-pill.s-open    { color: #7dd3fc; }
[data-theme="dark"] .status-pill.s-progress{ color: #fcd34d; }
[data-theme="dark"] .status-pill.s-done    { color: #6ee7b7; }
[data-theme="dark"] .status-pill.s-cancel  { color: #fca5a5; }
[data-theme="dark"] .status-pill.s-paid    { color: #6ee7b7; }
[data-theme="dark"] .status-pill.s-unpaid  { color: #fca5a5; }
[data-theme="dark"] .status-pill.s-partial { color: #fcd34d; }

/* ---------- 9. ACCORDION (FAQ) — readable text in expanded state ----------
   Bootstrap 5 default switches `.accordion-button` to a faint blue tint
   when expanded which can clash with the tealish brand palette. Force a
   neutral, readable color and a soft brand-tinted background. */
.accordion-button {
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg, #fff);
}
.accordion-button:not(.collapsed) {
    color: var(--bs-body-color) !important;
    background-color: rgba(13,148,136,.08) !important;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,.06);
}
.accordion-button:focus {
    box-shadow: 0 0 0 .2rem rgba(13,148,136,.18);
    border-color: transparent;
}
.accordion-body {
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg, #fff);
}
/* keep the muted helper readable on light bg */
.accordion-body.text-muted,
.accordion-body .text-muted {
    color: #475569 !important;
}
[data-theme="dark"] .accordion-button {
    color: #e2e8f0;
    background-color: #1e293b;
}
[data-theme="dark"] .accordion-button:not(.collapsed) {
    color: #f1f5f9 !important;
    background-color: rgba(13,148,136,.20) !important;
}
[data-theme="dark"] .accordion-body {
    color: #cbd5e1;
    background-color: #0f172a;
}
[data-theme="dark"] .accordion-body.text-muted,
[data-theme="dark"] .accordion-body .text-muted {
    color: #94a3b8 !important;
}
.accordion-item {
    background-color: var(--bs-body-bg, #fff);
    border-color: var(--bs-border-color, rgba(0,0,0,.125));
}

/* ---------- 10. MODAL ROUNDED CORNERS ----------
   Some modals showed mismatched corner radii because the header/footer
   override the parent radius. Force a consistent 16px on the content
   and inherit on the children to keep everything clipped cleanly. */
.modal-content {
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(15, 23, 42, .06);
    box-shadow: 0 30px 80px -30px rgba(15, 23, 42, .35);
}
.modal-header {
    border-top-left-radius: inherit;
    border-top-right-radius: inherit;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
.modal-footer {
    border-bottom-left-radius: inherit;
    border-bottom-right-radius: inherit;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}
/* SweetAlert2 popups should match the same vibe */
.swal2-popup { border-radius: 18px !important; }

/* ---------- 11. SUBSCRIPTION CARDS — make sure no text is truncated ----------
   Long Arabic plan descriptions can wrap awkwardly inside fixed-height
   cards. Allow plan cards to grow naturally and never clip text. */
.plans-grid .card,
.plan-card { overflow: visible; }
.plan-card .card-body { white-space: normal; }
.plan-card .price-amount { word-break: keep-all; }
