/* ============================================================================
   Klar - values: the value editor (inline, sheet, station, preview) and the
   display helpers (choice labels, file chips, times, people, masking, long
   text, product lines). Components in frontendlib/Components/Klar/Values.
   Only theme tokens (--mud-palette-*, --klar-*): every theme, light and dark.
   ============================================================================ */

/* --- small shared pieces ------------------------------------------------------ */

.klar-link-button {
    display: inline;
    margin: 0 0 0 .25rem;
    padding: 0 .125rem;
    border: 0;
    background: none;
    color: var(--klar-primary-ink);
    font: inherit;
    font-size: .8125rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
}

.klar-link-button:hover {
    text-decoration: underline;
}

.klar-link-button:focus-visible,
.klar-file-chip:focus-visible,
.klar-value-choice:focus-visible,
.klar-value-match:focus-visible {
    outline: 2px solid var(--klar-primary-ink);
    outline-offset: 2px;
}

.klar-kbd {
    display: inline-block;
    margin-inline-start: .5rem;
    padding: 0 .3125rem;
    border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
    border-radius: 4px;
    font-family: var(--klar-font-mono);
    font-size: .6875rem;
    font-weight: 500;
    line-height: 1.125rem;
    opacity: .85;
    text-transform: none;
}

/* --- display helpers ---------------------------------------------------------- */

.klar-value {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .375rem;
    max-width: 100%;
    min-width: 0;
}

.klar-value-number {
    font-variant-numeric: tabular-nums;
}

.klar-value-flag {
    display: inline-flex;
    color: color-mix(in srgb, var(--klar-tone-warning) 80%, var(--mud-palette-text-primary));
}

.klar-chip-large {
    height: 2.25rem;
    padding: 0 .875rem;
    font-size: 1rem;
    gap: .5rem;
}

.klar-chip-large .klar-dot {
    width: 10px;
    height: 10px;
}

/* a choice without the pill: tone dot and label, the text stays in text colour */
.klar-choice {
    --klar-tone: var(--klar-tone-neutral);
    display: inline-flex;
    align-items: center;
    gap: .4375rem;
    min-width: 0;
    color: var(--mud-palette-text-primary);
}

.klar-choice .klar-dot {
    background-color: var(--klar-tone);
}

.klar-choice-primary { --klar-tone: var(--klar-tone-primary); }
.klar-choice-success { --klar-tone: var(--klar-tone-success); }
.klar-choice-warning { --klar-tone: var(--klar-tone-warning); }
.klar-choice-error { --klar-tone: var(--klar-tone-error); }
.klar-choice-muted { --klar-tone: var(--klar-tone-muted); }

.klar-choice-muted .klar-choice-text {
    color: var(--mud-palette-text-secondary);
}

.klar-choice-large {
    font-size: 1.125rem;
}

.klar-choice-large .klar-dot {
    width: 10px;
    height: 10px;
}

/* a file chip is a button: the chip look with the button's focus and cursor */
button.klar-chip,
.klar-file-chip {
    font-family: inherit;
    cursor: pointer;
}

.klar-file-chip {
    gap: .3125rem;
    max-width: 100%;
}

span.klar-file-chip {
    cursor: default;
}

.klar-file-chip .mud-icon-root {
    font-size: 1rem;
}

.klar-file-chip-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.klar-file-chip-size {
    flex: none;
    font-weight: 500;
    opacity: .85;
    font-variant-numeric: tabular-nums;
}

.klar-time,
.klar-person {
    font-variant-numeric: tabular-nums;
}

.klar-masked {
    display: inline-flex;
    align-items: baseline;
    gap: .25rem;
}

.klar-masked-dots {
    letter-spacing: .125em;
    color: var(--mud-palette-text-secondary);
}

.klar-masked-value {
    font-family: var(--klar-font-mono);
}

.klar-longtext {
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.klar-longtext.is-long:not(.is-open) {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: var(--klar-lines, 2);
    line-clamp: var(--klar-lines, 2);
    overflow: hidden;
}

.klar-longtext-toggle {
    margin-inline-start: 0;
}

/* inline text: wraps like a sentence and copies as "sh2035433 · Thermonom Displayplatine" */
.klar-product-line {
    display: inline;
    overflow-wrap: anywhere;
}

.klar-product-line .klar-chip {
    vertical-align: baseline;
}

.klar-product-serial {
    font-weight: 600;
}

a.klar-product-serial {
    color: var(--klar-primary-ink);
    text-decoration: none;
}

a.klar-product-serial:hover {
    text-decoration: underline;
}

.klar-product-sep {
    color: var(--mud-palette-text-disabled);
}

.klar-product-line-large {
    font-size: 1.25rem;
}

/* --- editor: inline and sheet ------------------------------------------------- */

.klar-value-editor {
    display: flex;
    flex-direction: column;
    gap: .375rem;
    min-width: 0;
}

.klar-value-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: .5rem .75rem;
}

.klar-value-main {
    flex: 1 1 12rem;
    min-width: 0;
}

.klar-value-reason {
    flex: 2 1 16rem;
    min-width: 0;
}

/* a long text takes the whole width, the reason goes below it */
.klar-value-editor.is-multiline .klar-value-row {
    flex-direction: column;
    align-items: stretch;
}

.klar-value-editor.is-multiline .klar-value-main,
.klar-value-editor.is-multiline .klar-value-reason {
    flex: none;
    width: 100%;
}

.klar-value-editor .mud-input-control {
    margin-top: 0;
}

.klar-value-message {
    display: flex;
    flex-direction: column;
    gap: .125rem;
    font-size: .8125rem;
}

.klar-value-message:empty {
    display: none;
}

.klar-value-error {
    color: color-mix(in srgb, var(--mud-palette-error) 85%, var(--mud-palette-text-primary));
    font-weight: 600;
}

.klar-value-error::before {
    content: "⚠ ";
}

.klar-value-note {
    color: var(--mud-palette-text-secondary);
}

.klar-value-hint {
    color: var(--mud-palette-text-secondary);
}

.klar-value-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .375rem .875rem;
    font-size: .75rem;
    color: var(--mud-palette-text-secondary);
}

.klar-value-help {
    font-size: .75rem;
    color: var(--mud-palette-text-secondary);
}

.klar-value-before {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .3125rem;
}

.klar-value-before b {
    color: var(--mud-palette-text-primary);
}

.klar-value-foot .mud-button-root {
    white-space: nowrap;
}

/* Advanced, Cancel and Save stay together at the end of the line */
.klar-value-buttons {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem;
    margin-inline-start: auto;
}

.klar-value-buttons:empty {
    display: none;
}

.klar-value-advanced {
    padding: .5rem .75rem .25rem;
    border-inline-start: 3px solid color-mix(in srgb, var(--mud-palette-warning) 60%, var(--klar-hairline));
    background-color: color-mix(in srgb, var(--mud-palette-warning) 5%, var(--mud-palette-surface));
    border-radius: 0 var(--klar-radius-control) var(--klar-radius-control) 0;
}

.klar-value-option-desc {
    display: block;
    margin-inline-start: 1rem;
    font-size: .71875rem;
    color: var(--mud-palette-text-secondary);
}

/* the sheet stacks the fields and gives the buttons the full width */
.klar-value-mode-sheet .klar-value-row {
    flex-direction: column;
    align-items: stretch;
}

.klar-value-mode-sheet .klar-value-main,
.klar-value-mode-sheet .klar-value-reason {
    flex: none;
    width: 100%;
}

.klar-value-mode-sheet .klar-value-foot .klar-spacer {
    flex-basis: 100%;
}

.klar-value-mode-sheet .klar-value-buttons {
    flex: 1 1 100%;
}

.klar-value-mode-sheet .klar-value-cancel,
.klar-value-mode-sheet .klar-value-save {
    flex: 1 1 8rem;
    min-height: 44px;
}

.klar-value-mode-sheet .klar-kbd {
    display: none;
}

/* --- running total, date, file, signature, formula ----------------------------- */

.klar-value-total {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem .75rem;
}

.klar-value-total > .mud-input-control {
    flex: 1 1 10rem;
}

.klar-value-total-current {
    font-size: .8125rem;
    color: var(--mud-palette-text-secondary);
    font-variant-numeric: tabular-nums;
}

.klar-value-date {
    position: relative;
}

.klar-value-file {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem .75rem;
}

.klar-value-drop {
    position: relative;
    display: flex;
    flex: 1 1 18rem;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: .375rem .75rem;
    min-height: 4.5rem;
    padding: .75rem 1rem;
    border: 1.5px dashed var(--klar-hairline);
    border-radius: var(--klar-radius-card);
    background-color: var(--mud-palette-background-gray);
    color: var(--mud-palette-text-secondary);
    text-align: center;
    cursor: pointer;
}

.klar-value-drop:hover,
.klar-value-drop:focus-within {
    border-color: var(--klar-primary-ink);
    color: var(--mud-palette-text-primary);
}

.klar-value-drop:focus-within {
    outline: 2px solid var(--klar-primary-ink);
    outline-offset: 2px;
}

.klar-value-drop.is-error {
    border-color: var(--mud-palette-error);
}

.klar-value-drop.is-disabled {
    opacity: .6;
    cursor: default;
}

/* the file input covers the zone: a click chooses, a drop is taken, the keyboard reaches it */
.klar-value-drop-input,
.klar-value-photo-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.klar-value-drop-icon {
    color: var(--mud-palette-text-disabled);
}

.klar-value-drop-button,
.klar-value-photo {
    display: inline-flex;
    align-items: center;
    gap: .375rem;
    padding: .25rem .75rem;
    border: 1px solid var(--klar-hairline);
    border-radius: var(--klar-radius-control);
    background-color: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font-size: .8125rem;
    font-weight: 600;
}

.klar-value-drop .klar-value-help {
    flex-basis: 100%;
}

.klar-value-photo {
    position: relative;
    min-height: 2.25rem;
    cursor: pointer;
}

.klar-value-photo:focus-within {
    outline: 2px solid var(--klar-primary-ink);
    outline-offset: 2px;
}

/* taking a photo is a phone and tablet thing; a mouse and a fine pointer choose a file */
@media (hover: hover) and (pointer: fine) {
    .klar-value-photo {
        display: none;
    }
}

.klar-value-file-now {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .375rem;
    flex-basis: 100%;
    font-size: .8125rem;
}

.klar-value-signature,
.klar-value-formula {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem .75rem;
    min-height: 2.5rem;
}

.klar-value-formula-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* --- editor: station ---------------------------------------------------------- */

.klar-value-mode-station {
    gap: .5rem;
}

.klar-value-station-label {
    display: flex;
    align-items: baseline;
    gap: .375rem;
    font-size: 1.25rem;
    font-weight: 650;
    color: var(--mud-palette-text-primary);
}

.klar-value-station-label .klar-muted {
    font-size: 1rem;
    font-weight: 500;
}

.klar-value-required {
    color: color-mix(in srgb, var(--mud-palette-error) 80%, var(--mud-palette-text-primary));
}

.klar-value-mode-station .klar-value-help,
.klar-value-mode-station .klar-value-message {
    font-size: 1rem;
}

/* the message of a field is the frame's (klar-value-message); the helper MudBlazor draws for the error of its own validation is only there to
   make the field "invalid" (aria-invalid, red outline), it takes no room (R3-P3-18) */
.klar-value-field .mud-input-control-helper-container {
    display: none;
}

.klar-value-field-station .mud-input.mud-input-outlined {
    min-height: 3.5rem;
    font-size: 1.25rem;
}

.klar-value-field-station .mud-input-slot {
    min-height: 3.5rem;
    font-size: 1.25rem;
}

.klar-value-station-button.mud-button-root {
    min-height: 3.5rem;
    padding-inline: 1.25rem;
    font-size: 1.125rem;
}

.klar-value-choices {
    display: flex;
    flex-wrap: wrap;
    gap: .625rem;
}

.klar-value-choices:focus {
    outline: none;
}

.klar-value-choice {
    display: inline-flex;
    align-items: center;
    gap: .75rem;
    min-height: 3.5rem;
    min-width: 8rem;
    padding: .5rem 1.25rem .5rem .625rem;
    border: 1.5px solid var(--klar-hairline);
    border-radius: var(--klar-radius-card);
    background-color: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font: inherit;
    text-align: start;
    cursor: pointer;
}

.klar-value-choice:hover {
    border-color: var(--klar-primary-ink);
}

.klar-value-choice.is-selected {
    border-color: var(--klar-primary-ink);
    background-color: color-mix(in srgb, var(--mud-palette-primary) 12%, var(--mud-palette-surface));
    box-shadow: inset 0 0 0 1px var(--klar-primary-ink);
}

.klar-value-choice:disabled {
    opacity: .6;
    cursor: default;
}

.klar-value-choice-key {
    display: grid;
    place-items: center;
    flex: none;
    width: 2rem;
    height: 2rem;
    border-radius: 8px;
    background-color: var(--mud-palette-background-gray);
    color: var(--mud-palette-text-primary);
    font-family: var(--klar-font-mono);
    font-size: 1.125rem;
    font-weight: 700;
}

.klar-value-choice.is-selected .klar-value-choice-key {
    background-color: var(--klar-primary-ink);
    color: var(--mud-palette-primary-text);
}

.klar-value-choice-text {
    font-size: 1.125rem;
    font-variant-numeric: tabular-nums;
}

.klar-value-keys {
    font-size: .875rem;
    color: var(--mud-palette-text-secondary);
}

.klar-value-matches {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin: .25rem 0 0;
    padding: 0;
    list-style: none;
}

.klar-value-match {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    padding: .25rem .875rem;
    border: 1px solid var(--klar-hairline);
    border-radius: var(--klar-radius-control);
    background-color: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font: inherit;
    font-size: 1rem;
    cursor: pointer;
}

/* --- editor: designer preview ------------------------------------------------- */

.klar-value-preview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: 1rem;
}

.klar-value-preview-title {
    margin: 0 0 .5rem;
    font-size: .8125rem;
    font-weight: 650;
    color: var(--mud-palette-text-secondary);
}

.klar-value-preview-device {
    padding: 1rem;
    border: 1px solid var(--klar-hairline);
    border-radius: var(--klar-radius-card);
    background-color: var(--mud-palette-background);
}

.klar-value-preview-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .375rem;
}

/* --- bottom sheet (phones) ---------------------------------------------------- */

/* below MudBlazor's pop-overs (1200), so the lists of the fields open above the sheet - and below the phone's bottom
   tabs, which go while a sheet is open (klar/shell.css) */
.klar-value-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1149;
    background-color: var(--mud-palette-overlay-dark);
}

.klar-value-sheet {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1150;
    max-height: calc(100vh - var(--mud-appbar-height, 64px) - 1rem);
    overflow-y: auto;
    padding: .5rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
    border-radius: var(--klar-radius-card) var(--klar-radius-card) 0 0;
    background-color: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    box-shadow: 0 -12px 32px -12px rgba(0, 0, 0, .45);
}

.klar-value-sheet-handle {
    width: 2.5rem;
    height: 4px;
    margin: 0 auto .75rem;
    border-radius: 2px;
    background-color: var(--mud-palette-text-disabled);
}

.klar-value-sheet-title {
    margin: 0 0 .25rem;
    font-family: var(--klar-font-display);
    font-size: 1.125rem;
    font-weight: 650;
}

.klar-value-sheet-desc {
    margin: 0 0 .75rem;
    font-size: .8125rem;
    color: var(--mud-palette-text-secondary);
}

@media (min-width: 600px) {
    .klar-value-sheet {
        inset: auto 0 0 50%;
        width: min(36rem, 100vw);
        transform: translateX(-50%);
    }
}

/* --- the demo page /dev/klar/values (Development only) ------------------------- */

.klar-values-demo {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    max-width: 90rem;
}

.klar-values-demo-title {
    margin: 0;
    font-family: var(--klar-font-display);
    font-size: 1.5rem;
    font-weight: 650;
}

.klar-values-demo-h2 {
    margin: 1rem 0 0;
    font-size: 1rem;
    font-weight: 650;
}

.klar-values-demo-tools {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1rem;
}

.klar-values-demo-tools .mud-toggle-group {
    max-width: 100%;
    overflow-x: auto;
}

.klar-values-demo-result {
    min-height: 1.5rem;
    display: flex;
    gap: .5rem;
    font-size: .8125rem;
}

.klar-values-demo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 30rem), 1fr));
    gap: 1rem;
}

.klar-values-demo-prop {
    margin-bottom: .75rem;
}

.klar-values-demo-shown,
.klar-values-demo-sheetrow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    margin-top: .75rem;
    font-size: .8125rem;
}

.klar-values-demo-stack {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.klar-values-demo-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem .875rem;
}

.klar-values-demo-long {
    max-width: 32rem;
}
