/* POS on-screen keyboard (Components/SoftKeyboard.razor, js/softkeyboard.js).
   Sizes and colours arrive as custom properties on .softkb-host from the terminal's settings
   (Terminal Setup > Screens > Soft Keyboard). State classes on #pos-softkb come from the script. */

.softkb-host {
    display: contents;
}

.softkb {
    --kc: var(--softkb-key);
    position: fixed;
    bottom: 0;
    left: calc((100vw - var(--softkb-width)) / 2);
    z-index: 10050;
    display: none;
    flex-direction: column;
    box-sizing: border-box;
    width: var(--softkb-width);
    height: var(--softkb-height);
    min-height: 220px;
    padding: 8px 10px 10px;
    background: var(--softkb-bg);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.25);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.softkb.is-visible {
    display: flex;
    animation: softkb-up 0.18s ease-out;
}

.softkb-host[data-align="Left"] .softkb.layout-full { left: 0; }
.softkb-host[data-align="Right"] .softkb.layout-full { left: auto; right: 0; }

.softkb.layout-numeric {
    width: var(--softkb-num-width);
    height: var(--softkb-num-height);
    min-width: 280px;
    min-height: 260px;
    left: auto;
    right: 0;
}

.softkb-host[data-num-align="Left"] .softkb.layout-numeric { left: 0; right: auto; }
.softkb-host[data-num-align="Center"] .softkb.layout-numeric {
    left: calc((100vw - var(--softkb-num-width)) / 2);
    right: auto;
}

/* ---------- header: field label, live value, Hide ---------- */

.softkb-header {
    display: flex;
    align-items: stretch;
    gap: 8px;
    flex: 0 0 auto;
    height: max(44px, calc(var(--softkb-font-size) * 1.9));
    margin-bottom: 6px;
}

.softkb-field {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    overflow: hidden;
    white-space: nowrap;
    color: var(--softkb-font);
    background: color-mix(in srgb, var(--softkb-key) 88%, transparent);
    border: 2px solid color-mix(in srgb, var(--softkb-accent) 55%, transparent);
    border-radius: var(--softkb-radius);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.12);
}

.softkb-field-label {
    flex: 0 0 auto;
    font-size: calc(var(--softkb-font-size) * 0.55);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.65;
}

.softkb-field-label:empty { display: none; }

.softkb-field-value {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: clip;
    font-size: calc(var(--softkb-font-size) * 0.85);
    font-weight: 500;
}

.softkb-caret {
    flex: 0 0 auto;
    width: 2px;
    height: 1.2em;
    margin-left: -8px;
    background: var(--softkb-accent);
    animation: softkb-blink 1s steps(1) infinite;
}

.softkb-header.softkb-reject .softkb-field {
    border-color: #dc2626;
    animation: softkb-shake 0.3s;
}

.softkb .softkb-hide {
    --kc: var(--softkb-accent);
    flex: 0 0 auto;
    width: auto;
    padding: 0 22px;
    margin-bottom: var(--softkb-depth);
    color: #fff;
    font-size: calc(var(--softkb-font-size) * 0.7);
}

/* ---------- body, pages, rows ---------- */

.softkb-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    gap: calc(var(--softkb-gap) * 2.5);
}

.softkb-page,
.softkb-side-numpad {
    display: none;
    flex-direction: column;
    gap: var(--softkb-gap);
    min-width: 0;
}

.softkb-page { flex: 1 1 0; }
.softkb-side-numpad { flex: 0 0 22%; }

.softkb.layout-full.page-letters .softkb-page-letters,
.softkb.layout-full.page-symbols .softkb-page-symbols,
.softkb.layout-numeric .softkb-page-numeric,
.softkb-host[data-numpad="on"] .softkb.layout-full .softkb-side-numpad {
    display: flex;
}

.softkb-host[data-numrow="off"] .softkb-numrow { display: none; }

.softkb-row {
    display: flex;
    flex: 1 1 0;
    gap: var(--softkb-gap);
    min-height: 0;
}

/* ---------- keys: 3D caps that sink when pressed ---------- */

.softkb .softkb-key {
    position: relative;
    flex: var(--u, 1) 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    margin: 0 0 var(--softkb-depth) 0;
    padding: 0;
    border: none;
    border-radius: var(--softkb-radius);
    outline: none;
    color: var(--softkb-font);
    font-family: inherit;
    font-size: var(--softkb-font-size);
    font-weight: 600;
    line-height: 1;
    background: linear-gradient(180deg,
        color-mix(in srgb, var(--kc), #fff 24%) 0%,
        var(--kc) 55%,
        color-mix(in srgb, var(--kc), #000 6%) 100%);
    box-shadow:
        0 var(--softkb-depth) 0 color-mix(in srgb, var(--kc), #000 40%),
        0 calc(var(--softkb-depth) + 3px) 6px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.55);
    transform: translateY(0);
    transition: transform 50ms ease-out, box-shadow 50ms ease-out, filter 50ms ease-out;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.softkb .softkb-key::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0) 70%);
    opacity: 0;
    transition: opacity 160ms ease-out;
    pointer-events: none;
}

.softkb .softkb-key.is-pressed {
    transform: translateY(var(--softkb-depth));
    filter: brightness(1.12);
    box-shadow:
        0 0 0 color-mix(in srgb, var(--kc), #000 40%),
        0 1px 2px rgba(0, 0, 0, 0.35),
        inset 0 2px 6px rgba(0, 0, 0, 0.28);
}

.softkb .softkb-key.is-pressed::after {
    opacity: 1;
    transition: none;
}

.softkb .softkb-key > span { pointer-events: none; }

.softkb .softkb-act {
    --kc: var(--softkb-action);
    font-size: calc(var(--softkb-font-size) * 0.72);
}

.softkb .softkb-accent {
    --kc: var(--softkb-accent);
    color: #fff;
}

.softkb .softkb-space .k-main {
    font-size: 0.6em;
    letter-spacing: 0.12em;
    opacity: 0.5;
}

/* Shift legend in the corner; with one-shot Shift it swaps places with the main legend. */
.softkb .k-alt {
    position: absolute;
    top: 5px;
    right: 8px;
    font-size: 0.5em;
    opacity: 0.6;
}

.softkb.shift-once .softkb-key[data-s]:not(.softkb-letter) .k-main {
    position: absolute;
    top: 5px;
    right: 8px;
    font-size: 0.5em;
    opacity: 0.6;
}

.softkb.shift-once .softkb-key[data-s]:not(.softkb-letter) .k-alt {
    position: static;
    font-size: 1em;
    opacity: 1;
}

.softkb.shift-once .softkb-letter .k-main,
.softkb.shift-lock .softkb-letter .k-main {
    text-transform: uppercase;
}

.softkb.shift-once .softkb-shift,
.softkb.shift-lock .softkb-shift,
.softkb.shift-lock .softkb-caps {
    --kc: var(--softkb-accent);
    color: #fff;
}

/* Caps Lock: a bar under the label, so it reads differently from a one-shot Shift. */
.softkb.shift-lock .softkb-shift::before,
.softkb.shift-lock .softkb-caps::before {
    content: "";
    position: absolute;
    left: 28%;
    right: 28%;
    bottom: 7px;
    height: 3px;
    border-radius: 2px;
    background: #fff;
}

/* ---------- numeric pad ---------- */

.softkb.layout-numeric .softkb-page-numeric .softkb-key:not(.softkb-act) {
    font-size: calc(var(--softkb-font-size) * 1.3);
}

.softkb:not(.allow-decimal) .softkb-key[data-cond="decimal"] {
    visibility: hidden;
    pointer-events: none;
}

.softkb:not(.allow-negative) .softkb-key[data-cond="negative"],
.softkb.allow-negative .softkb-key[data-cond="no-negative"] {
    display: none;
}

.softkb .lbl-done,
.softkb:not(.has-next) .lbl-next { display: none; }
.softkb:not(.has-next) .lbl-done { display: inline; }

/* ---------- the field being typed into, and the key preview ---------- */

.softkb-target {
    outline: 3px solid #2563eb !important;
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.22) !important;
}

.softkb-bubble {
    position: fixed;
    z-index: 10060;
    display: none;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    color: var(--softkb-font, #111827);
    background: var(--softkb-key, #ffffff);
    border-radius: calc(var(--softkb-radius, 10px) + 4px);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35), 0 0 0 2px var(--softkb-accent, #2563eb);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: calc(var(--softkb-font-size, 24px) * 1.6);
    font-weight: 700;
    pointer-events: none;
}

.softkb-bubble.is-visible { display: flex; }

@keyframes softkb-up {
    from { transform: translateY(100%); opacity: 0.4; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes softkb-blink {
    50% { opacity: 0; }
}

@keyframes softkb-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
    .softkb.is-visible,
    .softkb-caret,
    .softkb-header.softkb-reject .softkb-field { animation: none; }
}
