/* ============================================================
   RB Product Customizer — styles.css  v3.2.0

   DESKTOP (> 768 px) — Modal popup:
     .rb-modal-container   96% wide, max 1280px, 88vh tall, flex column
     .rb-modal-header      flex-shrink:0  ~56px
     .rb-modal-body        flex:1, overflow:hidden, flex ROW
       .rb-preview-section flex:1   → canvas fills available space
       .rb-inputs-section  360px, overflow-y:auto (scroll only if needed)
         .rb-text-inputs-row → flex ROW (side-by-side)
         .rb-upload-row      → flex ROW (upload left, controls right)
         .rb-qty-row         → qty stepper
     .rb-modal-footer      flex-shrink:0  ~56px
                           CANCEL | Add to Cart | Buy Now

   MOBILE (≤ 768 px) — Full-screen (100dvh), flex column:
     .rb-modal-header      ~52px
     .rb-modal-body        flex:1, overflow:hidden, flex COLUMN
       .rb-preview-section 38dvh (canvas fills this exactly)
       .rb-inputs-section  flex:1, overflow-y:auto
     .rb-modal-footer      flex-shrink:0  ~56px
                           Add to Cart | Buy Now  (CANCEL hidden on mobile)

   No scrollbar ever appears on the modal itself.
   ============================================================ */

/* ── Tokens ────────────────────────────────────────────────── */
:root {
    --rb-orange:    #f5a623;
    --rb-dark:      #1c2b33;
    --rb-green:     #3a7d34;
    --rb-green-h:   #2e6129;
    --rb-error:     #c0152f;
    --rb-border:    #d0d0d0;
    --rb-body-bg:   #ffffff;
    --rb-header-bg: #f7f7f7;
    --rb-radius:    8px;
    --rb-dur:       150ms;
    --rb-ease:      cubic-bezier(0.16,1,0.3,1);
    --font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*,*::before,*::after { box-sizing: border-box; }

/* ── Body lock when modal open ─────────────────────────────── */
body.rb-modal-open { overflow: hidden !important; }

/* ── Trigger button ─────────────────────────────────────────── */
.rb-customizer-trigger { margin: 12px 0 4px; width: 100%; }

.rb-open-customizer-btn {
    display:         flex;
    align-items:     center;
    justify-content: center;
    gap:             8px;
    width:           100%;
    padding:         14px 24px;
    font-size:       15px;
    font-weight:     700;
    font-family:     var(--font);
    background:      #21808d;
    color:           #fff;
    border:          none;
    border-radius:   var(--rb-radius);
    cursor:          pointer;
    letter-spacing:  0.04em;
    text-transform:  uppercase;
    transition:      background var(--rb-dur) var(--rb-ease), transform var(--rb-dur) var(--rb-ease);
    box-shadow:      0 3px 10px rgba(33,128,141,0.35);
}
.rb-open-customizer-btn:hover  { background: #1a6670; transform: translateY(-1px); }
.rb-open-customizer-btn:active { transform: translateY(0); }
.rb-open-customizer-btn .dashicons { font-size: 20px; width: 20px; height: 20px; }

/* ── Modal overlay ──────────────────────────────────────────── */
.rb-modal {
    position:   fixed;
    inset:      0;
    z-index:    999999;
    display:    flex;
    align-items: center;
    justify-content: center;
    padding:    16px;
    background: rgba(0,0,0,0.65);
}
/* Hide via JS, not display:none by default (JS sets style=display:none) */

.rb-modal-overlay {
    position: absolute;
    inset:    0;
    cursor:   pointer;
}

/* ── Modal container ────────────────────────────────────────── */
.rb-modal-container {
    position:        relative;
    width:           96%;
    max-width:       1280px;
    /* Height budget: 88vh, flex column, no inner overflow on container */
    height:          88vh;
    max-height:      88vh;
    display:         flex;
    flex-direction:  column;
    background:      var(--rb-body-bg);
    border-radius:   12px;
    overflow:        hidden;
    box-shadow:      0 24px 64px rgba(0,0,0,0.3);
    animation:       rb-pop 200ms var(--rb-ease) both;
}

@keyframes rb-pop {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1)    translateY(0); }
}

/* ── Header ─────────────────────────────────────────────────── */
.rb-modal-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    padding:         0 24px;
    height:          56px;
    flex-shrink:     0;
    background:      var(--rb-header-bg);
    border-bottom:   1px solid #e0e0e0;
}
.rb-modal-header h2 {
    margin:      0;
    font-size:   18px;
    font-weight: 700;
    color:       #1a1a2e;
    font-family: var(--font);
}
.rb-modal-close {
    width:       36px;
    height:      36px;
    display:     flex;
    align-items: center;
    justify-content: center;
    font-size:   26px;
    line-height: 1;
    background:  none;
    border:      none;
    cursor:      pointer;
    color:       #666;
    border-radius: 50%;
    padding:     0;
    transition:  background var(--rb-dur);
}
.rb-modal-close:hover { background: #e8e8e8; color: #111; }

/* ── Body ───────────────────────────────────────────────────── */
.rb-modal-body {
    display:        flex;
    flex-direction: row;   /* overridden to column on mobile */
    flex:           1;
    min-height:     0;     /* CRITICAL: allow flex shrink */
    overflow:       hidden;
    gap:            20px;
    padding:        20px;
    background:     var(--rb-body-bg);
}

/* ── Left: preview (canvas) ─────────────────────────────────── */
.rb-preview-section {
    flex:            1;
    min-width:       0;
    min-height:      0;
    display:         flex;
    align-items:     center;
    justify-content: center;
}
.rb-canvas-wrapper {
    width:         100%;
    height:        100%;
    display:       flex;
    align-items:   center;
    justify-content: center;
    overflow:      hidden;
    border-radius: var(--rb-radius);
    background:    #f5f5f5;
}
#rb-preview-canvas {
    display:    block;
    max-width:  100%;
    max-height: 100%;
    object-fit: contain;
}

/* ── Right: inputs ──────────────────────────────────────────── */
.rb-inputs-section {
    width:           360px;
    flex-shrink:     0;
    display:         flex;
    flex-direction:  column;
    gap:             10px;
    overflow-y:      auto;
    -webkit-overflow-scrolling: touch;
    /* Custom thin scrollbar */
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}
.rb-inputs-section::-webkit-scrollbar { width: 4px; }
.rb-inputs-section::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* Text inputs — side-by-side always */
.rb-text-inputs-row { display: flex; flex-direction: row; gap: 10px; }
.rb-text-group { flex: 1 1 0; min-width: 0; margin: 0; padding: 0; }

.rb-field-label { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 700; color: #1a1a2e; font-family: var(--font); }
.rb-label-text  { letter-spacing: 0.02em; }
.rb-label-max   { margin-left: 3px; color: var(--rb-orange); font-weight: 500; }

.rb-text-input {
    display:     block;
    width:       100%;
    margin:      0 !important;
    padding:     8px 10px;
    border:      1px solid var(--rb-border);
    border-radius: var(--rb-radius);
    font-size:   13px;
    font-family: var(--font);
    color:       #1a1a2e;
    background:  #fff;
    transition:  border-color var(--rb-dur), box-shadow var(--rb-dur);
}
.rb-text-input:focus { outline: none; border-color: #21808d; box-shadow: 0 0 0 2px rgba(33,128,141,0.2); }
.rb-text-input.rb-input-error { border-color: var(--rb-error); box-shadow: 0 0 0 2px rgba(192,21,47,0.12); }

.rb-field-error { display: block; margin-top: 3px; font-size: 11px; color: var(--rb-error); font-weight: 500; font-family: var(--font); }

/* Image group */
.rb-image-group { display: flex; flex-direction: column; gap: 6px; }

.rb-upload-row { display: flex; flex-direction: row; gap: 10px; align-items: flex-start; }

/* Upload area — dashed box */
.rb-upload-area {
    flex:            1 1 0;
    min-width:       0;
    border:          2px dashed #c8b89a;
    border-radius:   var(--rb-radius);
    background:      #fff;
    padding:         14px 10px;
    display:         flex;
    flex-direction:  column;
    align-items:     center;
    justify-content: center;
    gap:             8px;
    cursor:          pointer;
    min-height:      120px;
    transition:      border-color var(--rb-dur);
}
.rb-upload-area:hover          { border-color: var(--rb-orange); }
.rb-upload-area.rb-upload-error { border-color: var(--rb-error); background: rgba(192,21,47,0.03); }

.rb-upload-icon { display: flex; align-items: center; justify-content: center; }
.rb-upload-icon svg { display: block; }

.rb-upload-btn {
    background:  var(--rb-dark);
    color:       #fff;
    border:      none;
    border-radius: 6px;
    padding:     7px 12px;
    font-size:   11px;
    font-family: var(--font);
    font-weight: 700;
    cursor:      pointer;
    white-space: nowrap;
    letter-spacing: 0.06em;
    transition:  background var(--rb-dur);
}
.rb-upload-btn:hover    { background: #243f52; }
.rb-upload-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.rb-upload-preview { max-width: 100%; max-height: 90px; border-radius: 6px; border: 1px solid #e0e0e0; object-fit: contain; display: block; }

/* Controls — 2×4 grid */
.rb-image-controls {
    flex-shrink:     0;
    display:         flex;
    flex-direction:  column;
    gap:             6px;
    background:      #f5f5f5;
    border:          1px solid #e0e0e0;
    border-radius:   var(--rb-radius);
    padding:         8px;
    align-self:      flex-start;
}
.rb-controls-dimmed { opacity: 0.3; pointer-events: none; user-select: none; }
.rb-controls-row    { display: flex; gap: 5px; }

.rb-ctrl-btn {
    display:         flex;
    align-items:     center;
    justify-content: center;
    width:           36px;
    height:          36px;
    background:      #e8e8e8;
    border:          1px solid #d0d0d0;
    border-radius:   6px;
    cursor:          pointer;
    color:           #444;
    padding:         0;
    flex-shrink:     0;
    transition:      all var(--rb-dur);
}
.rb-ctrl-btn:hover  { background: var(--rb-dark); color: #fff; border-color: var(--rb-dark); }
.rb-ctrl-btn:active { transform: scale(0.93); }
.rb-ctrl-btn svg    { pointer-events: none; }

/* Qty row */
.rb-qty-row { display: flex; margin-top: 4px; }
.rb-qty-wrap {
    display:       flex;
    align-items:   center;
    border:        1px solid var(--rb-border);
    border-radius: var(--rb-radius);
    overflow:      hidden;
    height:        38px;
}
.rb-qty-btn {
    width:       34px;
    height:      100%;
    border:      none;
    background:  #ebebeb;
    font-size:   18px;
    cursor:      pointer;
    display:     flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color:       #333;
    transition:  background var(--rb-dur);
}
.rb-qty-btn:hover { background: #ddd; }
.rb-qty-input {
    width:       46px;
    height:      100%;
    border:      none;
    border-left:  1px solid var(--rb-border);
    border-right: 1px solid var(--rb-border);
    text-align:  center;
    font-size:   14px;
    font-family: var(--font);
    background:  #fff;
    color:       #1a1a2e;
    -moz-appearance: textfield;
}
.rb-qty-input::-webkit-outer-spin-button,
.rb-qty-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.rb-qty-input:focus { outline: none; }

/* ── Footer ─────────────────────────────────────────────────── */
.rb-modal-footer {
    display:         flex;
    align-items:     center;
    justify-content: flex-end;
    gap:             10px;
    padding:         0 24px;
    height:          60px;
    flex-shrink:     0;
    background:      var(--rb-header-bg);
    border-top:      1px solid #e0e0e0;
}

.rb-modal-cancel {
    padding:       0 22px;
    height:        40px;
    font-size:     13px;
    font-weight:   600;
    font-family:   var(--font);
    background:    #e0e0e0;
    border:        1px solid #ccc;
    border-radius: var(--rb-radius);
    cursor:        pointer;
    color:         #444;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    transition:    background var(--rb-dur);
}
.rb-modal-cancel:hover { background: #d0d0d0; }

.rb-modal-add-to-cart,
.rb-buy-now-btn {
    padding:       0 22px;
    height:        40px;
    font-size:     13px;
    font-weight:   700;
    font-family:   var(--font);
    border:        none;
    border-radius: var(--rb-radius);
    cursor:        pointer;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    display:       flex;
    align-items:   center;
    gap:           6px;
    transition:    background var(--rb-dur), transform var(--rb-dur);
    white-space:   nowrap;
}
.rb-modal-add-to-cart {
    background: #1c3a4e;
    color:      #fff;
}
.rb-modal-add-to-cart:hover    { background: #243f52; }
.rb-modal-add-to-cart:disabled { opacity: 0.6; cursor: not-allowed; }

.rb-buy-now-btn {
    background: var(--rb-green);
    color:      #fff;
}
.rb-buy-now-btn:hover    { background: var(--rb-green-h); }
.rb-buy-now-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ============================================================
   ADMIN EDITOR
   ============================================================ */
#rb-customizer-admin-container { background: #fff; padding: 20px; border: 1px solid #ddd; border-radius: 12px; }
.rb-admin-header { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 2px solid #21808d; }
.rb-toolbar { display: flex; gap: 10px; align-items: center; padding: 16px; background: #f2f2f2; border-radius: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.rb-tool-separator { width: 1px; height: 30px; background: #ccc; margin: 0 6px; }
.rb-tool-btn.active { background: #21808d; color: #fff; border-color: #1a6670; }
.rb-editor-workspace { display: flex; gap: 20px; }
.rb-canvas-container { flex: 1; border: 2px solid #ddd; border-radius: 12px; overflow: auto; background: #f2f2f2; padding: 20px; min-height: 400px; display: flex; justify-content: center; align-items: flex-start; }
#rb-editor-canvas { display: block; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.rb-properties-panel { width: 300px; flex-shrink: 0; border: 1px solid #ddd; border-radius: 12px; padding: 20px; background: #fff; }
.rb-properties-panel h3 { margin: 0 0 16px; color: #21808d; font-size: 16px; font-weight: 600; border-bottom: 2px solid #21808d; padding-bottom: 10px; }
.rb-property-group { margin-bottom: 16px; }
.rb-property-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 12px; }
.rb-property-group input[type="text"],
.rb-property-group input[type="number"],
.rb-property-group input[type="color"],
.rb-property-group select { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; background: #fff; }
.rb-property-group input[type="color"] { height: 40px; cursor: pointer; padding: 2px; }
.rb-property-group select { -webkit-appearance: none; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 14px; padding-right: 30px; }

/* ── Order view ─────────────────────────────────────────────── */
.rb-order-customization { margin-top: 16px; padding: 16px; background: #f9f9f9; border: 1px solid #e0e0e0; border-radius: 8px; }
.rb-order-customization h4 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.rb-order-customization img { max-width: 150px; border: 2px solid #ddd; border-radius: 6px; display: block; margin-bottom: 10px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* ── Tablet 769–1024 px ─────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
    .rb-inputs-section { width: 300px; }
    .rb-modal-body     { gap: 14px; padding: 14px; }
    .rb-ctrl-btn       { width: 32px; height: 32px; }
    .rb-ctrl-btn svg   { width: 15px; height: 15px; }
}

/* ── Mobile ≤ 768 px ─────────────────────────────────────────── */
@media (max-width: 768px) {

    /* Full-screen modal */
    .rb-modal {
        padding:    0;
        align-items: stretch;
        justify-content: stretch;
    }
    .rb-modal-container {
        width:         100%;
        max-width:     100%;
        height:        100vh;
        height:        100dvh;   /* dynamic viewport — excludes iOS URL bar */
        max-height:    none;
        border-radius: 0;
    }

    /* Smaller header */
    .rb-modal-header { height: 48px; padding: 0 14px; }
    .rb-modal-header h2 { font-size: 15px; }
    .rb-modal-close { width: 30px; height: 30px; font-size: 22px; }

    /* Body becomes column: canvas on top, inputs scroll below */
    .rb-modal-body {
        flex-direction: column;
        gap:            10px;
        padding:        10px;
        overflow:       hidden;
    }

    /* Canvas section: fixed height = 38 dvh */
    .rb-preview-section {
        flex:       none;
        height:     38dvh;
        min-height: 0;
        width:      100%;
    }
    /* Fallback for browsers without dvh */
    @supports not (height: 1dvh) {
        .rb-preview-section { height: 38vh; }
    }

    .rb-canvas-wrapper {
        border-radius: 6px;
        width:  100%;
        height: 100%;
    }
    #rb-preview-canvas {
        width:      100%;
        height:     100%;
        object-fit: contain;
    }

    /* Inputs: fill remaining space, scroll internally */
    .rb-inputs-section {
        flex:       1;
        width:      100%;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        gap:        8px;
    }

    /* Text inputs: side-by-side on mobile (matches ranbazaar) */
    .rb-text-inputs-row { flex-direction: row; gap: 8px; }
    .rb-text-group { flex: 1 1 0; }

    /* Upload + controls: side-by-side */
    .rb-upload-row     { flex-direction: row; gap: 8px; }
    .rb-upload-area    { min-height: 100px; padding: 10px 8px; }

    /* Controls: compact */
    .rb-image-controls { padding: 6px; gap: 4px; }
    .rb-controls-row   { gap: 4px; }
    .rb-ctrl-btn       { width: 32px; height: 32px; }
    .rb-ctrl-btn svg   { width: 14px; height: 14px; }

    /* Qty */
    .rb-qty-row        { margin-top: 0; }

    /* Footer: no Cancel on mobile, two full-width buttons */
    .rb-modal-footer {
        height:          56px;
        padding:         0 12px;
        gap:             8px;
        justify-content: stretch;
        /* Safe area for iPhone home bar */
        padding-bottom:  max(0px, env(safe-area-inset-bottom));
        height:          calc(56px + env(safe-area-inset-bottom));
    }
    .rb-modal-cancel { display: none; }  /* hidden on mobile */

    .rb-modal-add-to-cart,
    .rb-buy-now-btn {
        flex:       1;
        justify-content: center;
        padding:    0 10px;
        font-size:  13px;
        height:     42px;
    }
}

/* ── Very small phone ≤ 380 px ──────────────────────────────── */
@media (max-width: 380px) {
    .rb-text-inputs-row { gap: 6px; }
    .rb-field-label     { font-size: 11px; }
    .rb-text-input      { font-size: 12px; padding: 6px 8px; }
    .rb-ctrl-btn        { width: 28px; height: 28px; }
    .rb-ctrl-btn svg    { width: 12px; height: 12px; }
    .rb-controls-row    { gap: 3px; }
    .rb-upload-btn      { font-size: 10px; padding: 5px 8px; }
    .rb-upload-icon svg { width: 32px; height: 32px; }
    .rb-preview-section { height: 34dvh; }
}

/* ── Admin responsive ────────────────────────────────────────── */
@media (max-width: 1024px) {
    .rb-editor-workspace { flex-direction: column; }
    .rb-properties-panel { width: 100%; }
    .rb-toolbar          { flex-wrap: wrap; gap: 8px; }
}
@media (max-width: 600px) {
    #rb-customizer-admin-container { padding: 12px; }
    .rb-canvas-container           { padding: 12px; min-height: 280px; }
    .rb-properties-panel           { padding: 12px; }
}

/* ── Print ──────────────────────────────────────────────────── */
@media print {
    .rb-image-controls, .rb-modal, .rb-customizer-trigger { display: none !important; }
}