/* ==========================================================================
   POS Touch Keyboard & Floating Popover Numpad Styling
   ========================================================================== */

:root {
    --pos-theme-primary: var(--clr-primary, #c52127);
    --pos-theme-primary-hover: #a8181d;
    --pos-theme-navy: #0f3d59;
    --pos-theme-navy-hover: #092537;
    --pos-theme-dark: #1e293b;
    --pos-theme-border: #e2e8f0;
    --pos-theme-bg: #f8fafc;
    --pos-theme-text: #1e293b;
    --pos-theme-muted: #64748b;
}

/* Fix Header Layout & Prevent Invisible Middle Grid Overlap */
.header-wrapper {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
}

.header-left {
    display: flex !important;
    align-items: center !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    position: relative !important;
    z-index: 2 !important;
}

.header-middle {
    display: none !important;
}

.header-right {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    flex-shrink: 0 !important;
    position: relative !important;
    z-index: 2 !important;
}

/* Header Toggle Button */
.pos-kb-toggle-btn {
    background-color: rgba(0, 122, 255, 0.1);
    color: #4d4d4d;
    padding: 5px 12px;
    border-radius: 6px;
    border: 1px solid rgba(0, 122, 255, 0.2);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer !important;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    text-decoration: none;
    position: relative !important;
    z-index: 5 !important;
}

.pos-kb-toggle-btn i {
    font-size: 14px;
    color: #4d4d4d;
    pointer-events: none;
}

.pos-kb-toggle-btn span {
    color: #4d4d4d;
    pointer-events: none;
}

.pos-kb-toggle-btn:hover,
.pos-kb-toggle-btn.active {
    background-color: var(--pos-theme-primary);
    border-color: var(--pos-theme-primary);
    color: #ffffff !important;
}

.pos-kb-toggle-btn:hover i,
.pos-kb-toggle-btn:hover span,
.pos-kb-toggle-btn.active i,
.pos-kb-toggle-btn.active span {
    color: #ffffff !important;
}

body.dark-mode .pos-kb-toggle-btn {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.2);
}

body.dark-mode .pos-kb-toggle-btn i,
body.dark-mode .pos-kb-toggle-btn span {
    color: #ffffff;
}

body.dark-mode .pos-kb-toggle-btn:hover,
body.dark-mode .pos-kb-toggle-btn.active {
    background-color: var(--pos-theme-primary);
    border-color: var(--pos-theme-primary);
    color: #ffffff !important;
}

/* Customer / Dropdown Keyboard Button & Select Wrapper Fixes */
.custom-select-wrapper {
    display: flex !important;
    align-items: stretch;
    position: relative;
}

.custom-select-wrapper .choices,
.custom-select-wrapper select {
    flex: 1 1 auto !important;
    min-width: 0;
    margin-bottom: 0 !important;
}

.custom-select-wrapper .choices .choices__inner {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    padding-right: 28px !important;
}

.custom-select-wrapper span {
    position: absolute !important;
    right: 88px !important;
    top: 50% !important;
    margin-top: -6px !important;
    pointer-events: none !important;
    z-index: 2 !important;
}

[dir="rtl"] .custom-select-wrapper span {
    right: auto !important;
    left: 88px !important;
}

.custom-add-button {
    flex-shrink: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    padding: 0 10px !important;
    height: 44px !important;
    background: color-mix(in srgb, var(--clr-primary) 10%, transparent) !important;
    border-left: 1px solid #eee !important;
    border-top-right-radius: 4px !important;
    border-bottom-right-radius: 4px !important;
}

[dir="rtl"] .custom-add-button {
    border-left: none !important;
    border-right: 1px solid #eee !important;
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    border-top-left-radius: 4px !important;
    border-bottom-left-radius: 4px !important;
}

.pos-customer-kb-btn {
    background: transparent;
    border: none;
    color: var(--pos-theme-primary);
    font-size: 16px;
    padding: 4px 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.15s ease;
    line-height: 1;
}

.pos-customer-kb-btn:hover,
.pos-customer-kb-btn.active {
    background: rgba(0, 0, 0, 0.08);
    color: var(--pos-theme-primary-hover);
}

body.dark-mode .pos-customer-kb-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* Input with Keypad Button wrapper */
.pos-input-group {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.pos-input-group input.custom-input {
    padding-right: 36px !important;
    width: 100%;
}

[dir="rtl"] .pos-input-group input.custom-input,
html[dir="rtl"] .pos-input-group input.custom-input {
    padding-right: 12px !important;
    padding-left: 36px !important;
}

.pos-input-numpad-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 14px;
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.15s ease;
    z-index: 2;
}

[dir="rtl"] .pos-input-numpad-btn,
html[dir="rtl"] .pos-input-numpad-btn {
    right: auto;
    left: 8px;
}

.pos-input-numpad-btn:hover,
.pos-input-numpad-btn.active {
    color: var(--pos-theme-primary);
    background: rgba(0, 0, 0, 0.05);
}

body.dark-mode .pos-input-numpad-btn {
    color: #94a3b8;
}

body.dark-mode .pos-input-numpad-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

/* ==========================================================================
   Floating Popover Keypad Styling (No Form Disruption)
   ========================================================================== */

.pos-popover-keypad {
    position: fixed;
    z-index: 100000;
    width: 290px;
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #cbd5e1;
    box-shadow: 0 14px 38px rgba(15, 61, 89, 0.22), 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: posPopoverIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
}

@keyframes posPopoverIn {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

body.dark-mode .pos-popover-keypad {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.5);
}

.pos-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 6px;
    border-bottom: 1px solid #f1f5f9;
}

body.dark-mode .pos-popover-header {
    border-color: #334155;
}

.pos-popover-title {
    font-size: 12px;
    font-weight: 700;
    color: #334155;
}

body.dark-mode .pos-popover-title {
    color: #f1f5f9;
}

.pos-popover-btn-clear {
    background: #fff1f2;
    color: #e11d48;
    border: 1px solid #fecdd3;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.pos-popover-btn-clear:hover {
    background: #e11d48;
    color: #ffffff;
}

body.dark-mode .pos-popover-btn-clear {
    background: rgba(225, 29, 72, 0.15);
    border-color: rgba(225, 29, 72, 0.3);
    color: #fb7185;
}

.pos-popover-close-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 13px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.pos-popover-close-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
}

body.dark-mode .pos-popover-close-btn:hover {
    background: #334155;
    color: #ffffff;
}

.pos-popover-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.pos-modal-preset {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 6px;
    border-radius: 5px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #334155;
    cursor: pointer;
    transition: all 0.12s ease;
    text-align: center;
}

body.dark-mode .pos-modal-preset {
    background: #334155;
    border-color: #475569;
    color: #f8fafc;
}

.pos-modal-preset:hover {
    background: #ffffff;
    border-color: var(--pos-theme-primary);
    color: var(--pos-theme-primary);
}

body.dark-mode .pos-modal-preset:hover {
    background: #475569;
    color: #ffffff;
}

.pos-modal-preset.preset-exact {
    background: var(--pos-theme-primary);
    border-color: var(--pos-theme-primary);
    color: #ffffff;
    font-weight: 800;
}

.pos-modal-preset.preset-exact:hover {
    filter: brightness(0.92);
    color: #ffffff;
}

.pos-modal-keys-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.pos-modal-key {
    height: 36px;
    font-size: 15px;
    font-weight: 700;
    color: #1e293b;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

body.dark-mode .pos-modal-key {
    background: #334155;
    border-color: #475569;
    color: #f8fafc;
}

.pos-modal-key:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

body.dark-mode .pos-modal-key:hover {
    background: #475569;
    border-color: #64748b;
}

.pos-modal-key:active {
    transform: scale(0.96);
    background: #e2e8f0;
}

.pos-modal-key.key-backspace {
    background: #f8fafc;
    color: #0f3d59;
    font-size: 16px;
}

body.dark-mode .pos-modal-key.key-backspace {
    background: #1e293b;
    color: #38bdf8;
}

.pos-modal-key.key-clear {
    background: #fff1f2;
    color: #e11d48;
    border-color: #fecdd3;
    font-weight: 800;
}

body.dark-mode .pos-modal-key.key-clear {
    background: rgba(225, 29, 72, 0.15);
    border-color: rgba(225, 29, 72, 0.3);
    color: #fb7185;
}

.pos-modal-key.key-done {
    background: var(--pos-theme-primary);
    border-color: var(--pos-theme-primary);
    color: #ffffff !important;
    font-size: 13px;
    font-weight: 700;
}

.pos-modal-key.key-done:hover {
    filter: brightness(0.92);
}

/* ==========================================================================
   Floating Virtual Full Keyboard Window Styling
   ========================================================================== */

.pos-virtual-keyboard-wrapper {
    position: fixed;
    bottom: 20px;
    right: 25px;
    z-index: 99999;
    pointer-events: auto;
}

[dir="rtl"] .pos-virtual-keyboard-wrapper,
html[dir="rtl"] .pos-virtual-keyboard-wrapper {
    right: auto;
    left: 25px;
}

.pos-keyboard-card {
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 18px 45px rgba(15, 61, 89, 0.18), 0 4px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(15, 61, 89, 0.15);
    overflow: hidden;
    transition: width 0.2s ease;
    user-select: none;
}

body.dark-mode .pos-keyboard-card {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.4);
}

.pos-keyboard-card.mode-num {
    width: 320px;
}

.pos-keyboard-card.mode-full {
    width: 660px;
}

.pos-keyboard-header {
    background: linear-gradient(135deg, #0f3d59 0%, #174b6c 100%);
    color: #ffffff;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: move;
}

.pos-kb-title {
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.pos-kb-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pos-kb-modes {
    display: flex;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    padding: 2px;
    gap: 2px;
}

.pos-kb-mode-btn {
    border: none;
    background: transparent;
    color: #ffffff;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.pos-kb-mode-btn.active {
    background: #ffffff;
    color: #0f3d59;
}

.pos-kb-close-btn {
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 11px;
    transition: background 0.15s ease;
}

.pos-kb-close-btn:hover {
    background: #e11d48;
}

.pos-keyboard-body {
    padding: 10px;
    background: #f8fafc;
}

body.dark-mode .pos-keyboard-body {
    background: #0f172a;
}

.pos-kb-grid-num {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.pos-kb-row {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
    justify-content: center;
}

.pos-key {
    height: 40px;
    font-size: 15px;
    font-weight: 700;
    color: #1e293b;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    transition: all 0.1s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

body.dark-mode .pos-key {
    background: #1e293b;
    border-color: #334155;
    color: #f8fafc;
}

.pos-key:hover {
    background: #f1f5f9;
    border-color: var(--pos-theme-primary);
}

body.dark-mode .pos-key:hover {
    background: #334155;
    border-color: var(--pos-theme-primary);
}

.pos-key:active {
    transform: scale(0.96);
    background: #e2e8f0;
}

.pos-key.key-action {
    background: #f1f5f9;
    color: #0f3d59;
}

body.dark-mode .pos-key.key-action {
    background: #1e293b;
    color: #38bdf8;
}

.pos-key.key-enter {
    background: var(--pos-theme-primary);
    color: #ffffff !important;
    border-color: var(--pos-theme-primary);
}

.pos-key.key-clear {
    background: #fff1f2;
    color: #e11d48;
    border-color: #fecdd3;
}

body.dark-mode .pos-key.key-clear {
    background: rgba(225, 29, 72, 0.15);
    border-color: rgba(225, 29, 72, 0.3);
    color: #fb7185;
}

.pos-key.key-space {
    flex: 6;
}

.pos-key.key-caps.active,
.pos-key.key-shift.active {
    background: #0f3d59 !important;
    color: #ffffff !important;
}

@media (max-width: 768px) {
    .pos-virtual-keyboard-wrapper {
        bottom: 0;
        right: 0 !important;
        left: 0 !important;
        width: 100%;
        display: flex;
        justify-content: center;
    }
    .pos-keyboard-card,
    .pos-keyboard-card.mode-num,
    .pos-keyboard-card.mode-full {
        width: 100%;
        border-radius: 14px 14px 0 0;
    }
    .pos-popover-keypad {
        position: fixed !important;
        bottom: 10px !important;
        left: 50% !important;
        top: auto !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        width: calc(100% - 24px) !important;
        max-width: 340px !important;
    }
}
