/*
 * i18n.rtl.css - right-to-left adjustments for Arabic and Farsi.
 *
 * Scoped to html[dir="rtl"] so left-to-right layout is completely untouched.
 * The order-taking page was built LTR-only, so this flips the things that do
 * not mirror automatically.
 *
 * Deliberately NOT mirrored:
 *   - the drawing canvas and its sketch (the abaya drawing is not a mirror image)
 *   - numeric keypads (digits keep their standard arrangement)
 *   - Latin-coded fields such as model codes and barcodes
 */

html[dir="rtl"] body {
    direction: rtl;
    text-align: right;
}

/* Flow-relative alignment for the common blocks.
   These are flex rows whose children are already in reading order, so RTL
   only needs the text alignment flipped - NOT row-reverse, which was
   re-ordering the icon/label/value and putting the colon on the wrong side. */
html[dir="rtl"] .customer-info-item,
html[dir="rtl"] .info-row,
html[dir="rtl"] .form-group,
html[dir="rtl"] .totals-row,
html[dir="rtl"] .summary-row {
    text-align: right;
}

/* Labels used `margin-right` for the gap after "Name:" etc. In RTL that puts
   the gap on the far side of the value; the logical property follows the
   reading direction instead. */
html[dir="rtl"] .info-label {
    margin-right: 0;
    margin-inline-end: 5px;
}

/* The customer panel header keeps the title at the start edge and the
   Size / Order-History buttons at the end edge in both directions.
   The title must not wrap - it is short in every language. */
html[dir="rtl"] .customer-info-title {
    flex-direction: row;
}

/* Applies in BOTH directions: the panel title is short in every language and
   should never wrap onto a second line. */
.customer-info-title {
    flex-wrap: nowrap;
    gap: 8px;
}
.customer-info-title > span:first-child {
    white-space: nowrap;
    flex-shrink: 0;
}

/* Tables: headers and cells align to the start edge, but keep numeric
   columns readable by leaving explicitly numeric cells alone. */
html[dir="rtl"] table th,
html[dir="rtl"] table td {
    text-align: right;
}
html[dir="rtl"] table th.num,
html[dir="rtl"] table td.num,
html[dir="rtl"] .price-cell,
html[dir="rtl"] .amount-cell,
html[dir="rtl"] .qty-cell {
    text-align: left;
    direction: ltr;
}

/* Inputs: text fields follow the language, but fields holding numbers,
   codes, dates and phone numbers must stay LTR or the digits reorder. */
html[dir="rtl"] input[type="text"],
html[dir="rtl"] textarea {
    text-align: right;
}
html[dir="rtl"] input[type="number"],
html[dir="rtl"] input[type="tel"],
html[dir="rtl"] input[type="date"],
html[dir="rtl"] input[inputmode="numeric"],
html[dir="rtl"] input[inputmode="decimal"],
html[dir="rtl"] .numeric-input,
html[dir="rtl"] .ltr-field {
    direction: ltr;
    text-align: left;
}

/* Money and measurement readouts stay LTR so "AED 472.50" is not reordered. */
html[dir="rtl"] .amount-value,
html[dir="rtl"] .total-value,
html[dir="rtl"] .calc-display-amount,
html[dir="rtl"] .price-display,
html[dir="rtl"] .ltr-number {
    direction: ltr;
    unicode-bidi: embed;
    display: inline-block;
}

/* Modal close buttons and other absolutely-positioned corner controls. */
html[dir="rtl"] .payment-modal-close-btn-v2,
html[dir="rtl"] .modal-close-btn,
html[dir="rtl"] .close-btn {
    right: auto;
    left: 12px;
}

/* Sidebars / drawers that slide in from a fixed side. */
html[dir="rtl"] .left-panel,
html[dir="rtl"] .customer-panel {
    order: 2;
}
html[dir="rtl"] .right-panel,
html[dir="rtl"] .drawing-panel {
    order: 1;
}

/* Icon buttons that imply direction need mirroring; the pen/eraser do not.
   The gallery Back arrow points left, which is "backwards" only in LTR - in
   RTL the reading direction flips and it must point right. */
html[dir="rtl"] .btn-next-field svg,
html[dir="rtl"] .btn-prev-field svg,
html[dir="rtl"] .nav-arrow svg,
html[dir="rtl"] #backBtn svg,
html[dir="rtl"] .back-btn svg {
    transform: scaleX(-1);
}

/* The drawing canvas itself must never be mirrored - the abaya sketch and
   any annotation drawn on it are position-sensitive. */
html[dir="rtl"] #drawingCanvas,
html[dir="rtl"] .canvas-container,
html[dir="rtl"] .upper-canvas,
html[dir="rtl"] .lower-canvas,
html[dir="rtl"] .drawing-area {
    direction: ltr;
}

/* Keypads keep their standard left-to-right digit order. */
html[dir="rtl"] .calc-buttons-grid,
html[dir="rtl"] .numpad,
html[dir="rtl"] #customer-keypad,
html[dir="rtl"] .keyboard-container {
    direction: ltr;
}

/* Arabic and Farsi render better with slightly more line height. */
html[dir="rtl"] {
    line-height: 1.7;
}

/* Farsi prefers its own digit shapes in prose but NOT in amounts; keep the
   default digits everywhere so totals stay consistent with the invoice. */
html[lang="fa"] .amount-value,
html[lang="fa"] .total-value {
    font-feature-settings: normal;
}

/* --- language switcher (shared, works in both directions) --- */
.lang-switcher {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 3px;
    direction: ltr; /* the switcher itself keeps a stable order */
}
.lang-switcher button {
    background: transparent;
    border: 0;
    color: #cfd3dc;
    font: inherit;
    font-size: 13px;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1.2;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.lang-switcher button:hover {
    background: rgba(255, 255, 255, 0.10);
    color: #fff;
}
.lang-switcher button.active {
    background: #ff9200;
    color: #1a1a1a;
    font-weight: 600;
}

/* Auto-created switcher when a page does not provide its own container. */
.lang-switcher-floating {
    position: fixed;
    top: 10px;
    inset-inline-end: 10px; /* right in LTR, left in RTL */
    z-index: 9999;
}

/* Switcher placed inside the login card, under the login button. */
.lang-switcher-login {
    display: flex;
    justify-content: center;
    width: fit-content;
    margin: 18px auto 0;
}

/* Phone-number display: the country code and the digits are separate spans,
   so in RTL the row order reverses and "+971 55123" renders as "55123 +971".
   A phone number is always read left-to-right, so pin the whole row LTR. */
html[dir="rtl"] .calc-display-second-row,
html[dir="rtl"] #calc-display-unit-customer,
html[dir="rtl"] #calc-display-amount-customer,
html[dir="rtl"] #customer-mobile-input,
html[dir="rtl"] .mobile-number-display {
    direction: ltr;
    unicode-bidi: isolate;
    text-align: left;
}

/* --- Directional spacing overrides for order_taking.css ---
   The stylesheet uses physical margin-left/right for gaps after labels. In RTL
   those land on the wrong side, so each is converted to its logical equivalent.
   Listed explicitly rather than globally, to avoid disturbing the drawing
   toolbar and keypads that are deliberately kept LTR. */

html[dir="rtl"] .detail-label {
    margin-right: 0;
    margin-inline-end: 10px;
}
html[dir="rtl"] #pd-row-discount-percent .detail-label,
html[dir="rtl"] #pd-row-discount-amount .detail-label {
    margin-right: 0;
    margin-inline-end: 5px;
}
html[dir="rtl"] .input-like-unit.prefix {
    margin-right: 0;
    margin-inline-end: 5px;
}
html[dir="rtl"] .input-like-unit:not(.prefix) {
    margin-left: 0;
    margin-inline-start: 5px;
}
html[dir="rtl"] .radio-group input[type="radio"] + label {
    padding-left: 0;
    padding-inline-start: 15px;
}
html[dir="rtl"] #signature-check {
    margin-left: 0;
    margin-inline-start: 8px;
}

/* --- Payment dialog in RTL ---
   Rows are `justify-content: space-between` with the label first and the value
   second. That order is already correct for RTL, so only the text alignment
   and the label gap need flipping - the amounts themselves stay LTR. */
html[dir="rtl"] .payment-detail-row {
    text-align: right;
}
html[dir="rtl"] .detail-value,
html[dir="rtl"] span.input-like-label,
html[dir="rtl"] #calc-display-amount {
    text-align: left;
    direction: ltr;          /* "AED 472.50" must never reorder */
    unicode-bidi: embed;
}
html[dir="rtl"] .calc-display-upper-row {
    text-align: right;
}
/* The AED prefix inside an amount box sits before the number in both
   directions, so the box itself stays LTR. */
html[dir="rtl"] .input-like-label-container {
    direction: ltr;
}
html[dir="rtl"] .input-like-unit.prefix {
    margin-right: 0;
    margin-inline-end: 5px;
}
/* The status pill keeps its own centred text. */
html[dir="rtl"] .payment-status-v2 {
    direction: rtl;
    text-align: center;
}
/* Footer button sits at the reading-end edge.
   The footer is not a flex container - its button is absolutely positioned
   with a physical `right: 20px`, so direction alone will not move it. Flip
   the offset to the left edge and clear the inherited `right`. */
html[dir="rtl"] .payment-modal-footer-v2 {
    justify-content: flex-start;
}
html[dir="rtl"] .payment-modal-footer-v2 .payment-action-btn-v2 {
    right: auto;
    left: 20px;
}

/* --- Hide scrollbars inside the modals (they scroll by drag on a tablet) --- */
.payment-details-column,
.payment-modal-main-area,
.payment-modal-content-v2,
#size-details-list-container,
.country-list-column,
.signature-modal-content {
    scrollbar-width: none;          /* Firefox */
    -ms-overflow-style: none;       /* old Edge */
}
.payment-details-column::-webkit-scrollbar,
.payment-modal-main-area::-webkit-scrollbar,
.payment-modal-content-v2::-webkit-scrollbar,
#size-details-list-container::-webkit-scrollbar,
.country-list-column::-webkit-scrollbar,
.signature-modal-content::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;                  /* Chrome / Safari */
}

/* The connector line grows from the label towards the input. In RTL that is
   right-to-left, so the scale must originate from the opposite edge. */
html[dir="rtl"] #payment-connecting-line {
    transform-origin: right center;
}

/* --- Language-change animation (shared) ---
   Switching language replays the page's own load animation (see
   replayLoadAnimation in i18n.switcher.js): the declared CSS animations are
   restarted, so a switch looks exactly like a refresh. Nothing here defines
   the motion - it only guarantees elements end up visible. */

/* Elements whose base state is opacity:0 are revealed by a one-shot load
   animation with `forwards`. If a replay is skipped or interrupted, that never
   lands and they would be stuck invisible; the switcher adds this class on a
   timer as a safety net. */
.i18n-animate-done {
    opacity: 1 !important;
}

/* --- Form controls must inherit the page font -----------------------------
   <button>, <input>, <select> and <textarea> do NOT inherit font-family by
   default; browsers substitute a system UI font. That font has poor Arabic and
   Farsi shaping, so buttons rendered with cramped, badly joined glyphs while
   ordinary text and <a> links (which do inherit) looked correct.

   This applies in every language - inheriting the page font is right for
   English too - so it is deliberately not scoped to [dir="rtl"]. */
button,
input,
select,
textarea {
    font-family: inherit;
}

/* Arabic and Farsi need a face with real Arabic-script coverage and a little
   more line-height, or descenders and diacritics clip inside buttons. */
html[lang="ar"] body,
html[lang="ar"] button,
html[lang="ar"] input,
html[lang="ar"] select,
html[lang="ar"] textarea {
    font-family: 'Segoe UI', Tahoma, 'Dubai', 'Noto Naskh Arabic', Arial, sans-serif;
}
html[lang="fa"] body,
html[lang="fa"] button,
html[lang="fa"] input,
html[lang="fa"] select,
html[lang="fa"] textarea {
    font-family: 'Segoe UI', Tahoma, 'Iranian Sans', 'Vazirmatn', 'Noto Naskh Arabic', Arial, sans-serif;
}
html[lang="ar"] button,
html[lang="fa"] button {
    line-height: 1.8;
}

/* --- Customer dialog: extra room in RTL -------------------------------
   The dialog is capped at max-height: 700px, sized for the LTR layout. In
   Arabic and Farsi the `line-height: 1.7` above grows the header, the footer
   button and every country row, so the last country and the bottom keypad
   row get clipped. Give the RTL dialog more height and trim the row padding
   that the taller line box already pays for. */
html[dir="rtl"] #customer-selection-modal-overlay .payment-modal-content-v2 {
    height: 88vh;
    max-height: 800px;
}

html[dir="rtl"] #customer-selection-modal-overlay .country-list-column li {
    padding: 14px 20px;
    line-height: 1.4;
}

/* On a short screen the 80px keys overflow before anything else; let them
   shrink rather than push the last keypad row past the bottom edge. */
@media (max-height: 800px) {
    html[dir="rtl"] #customer-selection-modal-overlay .calc-btn {
        min-height: 64px;
        max-height: 64px;
    }
}
