#client-floating-softphone .softphone-fab {
    --size: 3.5rem;
    --edge-left: max(.75rem, env(safe-area-inset-left));
    --edge-right: max(.75rem, env(safe-area-inset-right));
    --edge-top: max(.75rem, env(safe-area-inset-top));
    --edge-bottom: max(.75rem, env(safe-area-inset-bottom));
    position: fixed;
    z-index: 1041; /* Above the desktop sidebar and below the modal backdrop. */
    width: var(--size);
    height: var(--size);
    left: clamp(var(--edge-left), var(--phone-left, 100%), calc(100% - var(--size) - var(--edge-right)));
    top: clamp(var(--edge-top), var(--phone-top, 100%), calc(100dvh - var(--size) - var(--edge-bottom)));
    border-radius: 50%;
    box-shadow: var(--spech-shadow-soft);
    touch-action: none;
    user-select: none;
    cursor: grab;
}
#client-floating-softphone .softphone-fab:active { cursor: grabbing; }
body.driver-active #softphone-fab,
body.modal-open #softphone-fab,
body:has(.modal.show, .modal-backdrop, .offcanvas.show, .offcanvas-backdrop, dialog[open]) #softphone-fab {
    visibility: hidden;
}
body:has(#softphone-panel[open]) { overflow: hidden; }

#softphone-panel {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(55rem, calc(100% - 2rem));
    height: fit-content;
    max-height: calc(100dvh - 2rem);
    max-width: none;
    border-radius: 14px;
    box-shadow: var(--spech-shadow-soft);
    padding: 0;
    border: 1px solid var(--spech-border);
    background: var(--spech-bg);
    color: var(--spech-text);
}
#softphone-panel[open] { display: flex; flex-direction: column; }
#softphone-panel .softphone-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: max(.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .75rem max(1rem, env(safe-area-inset-left));
    border-bottom: 1px solid var(--spech-border);
    background: var(--spech-surface);
}
#softphone-panel .softphone-scroll { overflow: auto; overscroll-behavior: contain; }
#softphone-panel .softphone-layout {
    display: grid;
    grid-template-columns: minmax(0, 21rem) minmax(0, 1fr);
    align-items: start;
    gap: .75rem;
    margin: auto;
    padding: .875rem;
}
#softphone-panel .softphone-switch { display: none; }
#softphone-panel .softphone-keypad, #softphone-panel .softphone-actions {
    display: grid;
    gap: .5rem;
    grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
}
#softphone-panel .softphone-keypad { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: .875rem 0; }
#softphone-panel .softphone-display { position: relative; }
#softphone-number { padding-inline: 2.75rem; }
#softphone-erase { position: absolute; inset-block: 0; right: 0; width: 2.75rem; padding: 0; color: var(--spech-text-muted); }
#softphone-panel .softphone-key small { display: block; min-height: .75rem; font-size: .61rem; line-height: .75rem; letter-spacing: .09em; color: var(--spech-text-muted); }
#softphone-panel .softphone-actions button { min-height: 44px; padding-inline: .25rem; }
#softphone-panel .softphone-actions [aria-pressed="true"] { color: var(--spech-warning); border-color: currentColor; }
#softphone-panel .softphone-key { min-height: 50px; padding-block: .25rem; font-weight: 600; line-height: 1.15; background: var(--spech-surface-2); color: var(--spech-text); border-color: var(--spech-border); font-size: 1.125rem; }
#softphone-panel .softphone-key:hover, #softphone-panel .softphone-switch [aria-pressed="true"] {
    color: var(--spech-primary);
    background: var(--spech-primary-soft);
    border-color: var(--spech-primary);
}
#softphone-panel .softphone-history-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
#softphone-panel .softphone-history-header > div, #softphone-panel .softphone-header > div { min-width: 0; overflow-wrap: anywhere; }
#softphone-recent li { display: grid; gap: .125rem; padding: .625rem 0; border-top: 1px solid var(--spech-border-soft); overflow-wrap: anywhere; }
#softphone-recent span { color: var(--spech-text-muted); font-size: .875rem; }
@media (max-width: 767.98px) {
    #softphone-panel .softphone-layout { grid-template-columns: minmax(0, 1fr); max-width: 32rem; }
    #softphone-panel .softphone-switch { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
    #softphone-panel[data-view="dial"] #softphone-history,
    #softphone-panel[data-view="history"] #softphone-dial { display: none; }
}

#softphone-panel::backdrop { background: color-mix(in srgb, var(--spech-bg) 78%, transparent); }

#softphone-panel .softphone-line { display: flex; align-items: center; gap: .5rem; margin-left: auto; min-width: 0; max-width: 42%; }
#softphone-panel .softphone-dial-footer { display: flex; justify-content: space-between; align-items: center; gap: .25rem; margin-top: .45rem; min-height: 1rem; }
#softphone-panel #softphone-clock { color: var(--spech-info); font: 600 .8rem var(--bs-font-monospace); }
#softphone-panel #softphone-hint { font-size: .75rem; }
#softphone-panel #softphone-audio { display: grid; gap: .5rem; padding-top: .625rem; margin-top: .625rem; border-top: 1px solid var(--spech-border); }
#softphone-panel .softphone-channel { display: grid; grid-template-columns: 1fr auto; gap: 0 .65rem; align-items: center; color: var(--spech-text-muted); font-size: .8rem; }
#softphone-panel .softphone-channel span { min-width: 2.5rem; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
#softphone-panel .softphone-level-control { grid-column: 1 / -1; display: grid; align-items: center; }
#softphone-panel .softphone-level-control > * { grid-area: 1 / 1; }
#softphone-panel .softphone-level-control input {
    appearance: none;
    position: relative;
    width: 100%;
    height: 24px;
    margin: 0;
    background: transparent;
    cursor: pointer;
    touch-action: pan-y;
}
#softphone-panel .softphone-level-control input:focus-visible { outline: 2px solid var(--spech-primary); outline-offset: 1px; }
#softphone-panel .softphone-level-control input:disabled { cursor: default; opacity: .45; }
#softphone-panel .softphone-level-control input::-webkit-slider-runnable-track { height: .625rem; background: transparent; }
#softphone-panel .softphone-level-control input::-moz-range-track { height: .625rem; background: transparent; }
#softphone-panel .softphone-level-control input::-webkit-slider-thumb { appearance: none; width: 4px; height: .625rem; background: var(--spech-text); border: 0; border-radius: 1px; }
#softphone-panel .softphone-level-control input::-moz-range-thumb { width: 4px; height: .625rem; background: var(--spech-text); border: 0; border-radius: 1px; }
#softphone-panel .softphone-channel meter {
    appearance: none;
    width: 100%;
    height: .625rem;
    border: 0;
    border-radius: 0;
    background: var(--spech-surface-3);
    mask-image: repeating-linear-gradient(to right, var(--spech-text) 0 4px, transparent 4px 6px);
}
#softphone-panel .softphone-channel meter::-webkit-meter-bar { height: 100%; border: 0; border-radius: 0; background: var(--spech-surface-3); }
#softphone-recent { max-height: min(24rem, 52dvh); overflow: auto; overscroll-behavior: contain; }
#softphone-recent li { grid-template-columns: minmax(0,1fr) auto; padding: .55rem 0; }
#softphone-recent li > strong, #softphone-recent li > span { grid-column: 1; }
#softphone-recent li > strong { grid-row: 1; }
#softphone-recent .softphone-row-call { grid-column: 2; grid-row: 1 / 3; align-self: center; }
#softphone-recent .softphone-destination { background: transparent; border: 0; color: var(--spech-primary); padding: 0; text-align: left; }
#softphone-panel .softphone-pages { display: flex; justify-content: space-between; align-items: center; gap: .5rem; border-top: 1px solid var(--spech-border); padding-top: .625rem; }
#softphone-fab.in-call { background: var(--spech-success); }
@media (max-width: 767.98px) {
    #softphone-panel { width: 100%; max-height: 100dvh; border-radius: 0; }
    #softphone-panel .softphone-header { gap: .375rem; }
    #softphone-panel .softphone-layout { grid-template-columns: minmax(0,1fr); padding: .5rem max(.5rem, env(safe-area-inset-right)) max(.5rem,env(safe-area-inset-bottom)) max(.5rem,env(safe-area-inset-left)); gap: .5rem; }
    #softphone-panel .softphone-keypad { gap: .375rem; margin: .5rem 0; }
}

@media (max-width: 480px) {
    #softphone-panel .softphone-header { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: .35rem .75rem; padding-block: .5rem; }
    #softphone-panel .softphone-header > div { display: flex; align-items: baseline; flex-wrap: wrap; gap: .2rem .5rem; }
    #softphone-panel .softphone-header h2 { font-size: 1.05rem; }
    #softphone-panel .softphone-line { grid-row: 2; max-width: 100%; margin: 0; }
    #softphone-panel #softphone-close { grid-column: 2; grid-row: 1 / 3; }
    #softphone-panel .card-body { padding: .65rem; }
}

#softphone-panel .softphone-channel meter::-webkit-meter-optimum-value { background: var(--spech-info); }
#softphone-panel .softphone-channel meter::-moz-meter-bar { background: var(--spech-info); }
@media (max-width: 480px) and (max-height: 690px) {
    #softphone-panel .softphone-key { height: 44px; padding-block: 0; }
    #softphone-panel .softphone-keypad { gap: .25rem; }
    #softphone-panel .form-label { margin-bottom: .25rem; }
    #softphone-panel #softphone-audio { margin-top: .25rem; padding-top: .125rem; }
    #softphone-panel #softphone-audio { gap: .25rem; }
    #softphone-panel .softphone-level-control { height: .875rem; align-content: center; }
}
