/* ft-gauge — track compacto de consumo de estoque (usado/reservado/disponível) com
   marcador de limite (threshold), sucessor visual de _ItemStockBar.cshtml (Bootstrap
   3 segmentos) para a aba "Itens New" do Acordo.

   Renderizado 100% por JS (FtGauge, Scripts/Components/ft-gauge.js) a partir de
   data-used/data-reserved/data-total/data-limit em elementos [data-ft-gauge].
   Ver contrato completo no cabeçalho do .js e em
   PortalWeb/Views/Agreement/_FtItemStockBar.cshtml.

   Cores mapeadas para os tokens --ft-* do tema (NÃO usar cores hardcoded do
   smelter.html de referência): usado -> perigo, reservado -> aviso,
   disponível -> sucesso. O threshold-marker do smelter (linha ~375-391 do anexo)
   foi portado como .ft-gauge__threshold, recolorido para --ft-color-primary para
   se destacar dos 3 segmentos de consumo. */

.ft-gauge {
    display: block;
    min-width: 6rem;
}

/* Trilho — compacto (12px) para caber em célula de tabela (ver plano: altura
   alvo ~10-14px). Cresce um pouco no hover/foco para dar área de leitura e de
   arraste (o hover é o gatilho liberatório de informação/edição). O trilho em
   si fica overflow:visible para marcador/knob/rótulos poderem vazar; quem
   recorta as regiões coloridas proporcionais é o .ft-gauge__fill interno. */
.ft-gauge__track {
    position: relative;
    display: flex;
    align-items: stretch;
    height: 0.75rem;
    overflow: visible;
    background: transparent;
    transition: height 0.15s ease;
}

.ft-gauge:hover .ft-gauge__track,
.ft-gauge:focus-within .ft-gauge__track,
.ft-gauge--labels-visible .ft-gauge__track {
    height: 1rem;
}

.ft-gauge--editable .ft-gauge__track {
    cursor: pointer;
}

.ft-gauge--dragging,
.ft-gauge--dragging * {
    user-select: none;
    -webkit-user-select: none;
}

/* Modificador que fixa o estado normalmente só-hover (trilho expandido,
   rótulos dos segmentos, balão de leitura e knob) — usado quando o gauge é o
   protagonista da tela (ex. modal de definição de limite em lote), onde a
   pessoa precisa ver o valor sendo definido sem precisar manter o mouse em
   cima. */

/* Camada que recorta (overflow:hidden) as regiões coloridas proporcionais —
   segmentos (modo segments) ou bandas (modo periods) — com cantos sempre
   arredondados via border-radius, independente de qual região está na ponta
   (fix da issue de segmento/banda de largura 0 não arredondar a ponta). */
.ft-gauge__fill {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    border-radius: var(--ft-radius-pill);
    background: var(--ft-bg-muted);
}

.ft-gauge__segment {
    position: relative;
    flex: 0 0 auto;
    height: 100%;
    overflow: hidden;
    transition: flex-basis 0.2s ease;
}

/* Rótulo percentual de cada segmento — escondido por padrão, revelado no
   hover/foco do gauge. */
.ft-gauge__segment-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.625rem;
    line-height: 1;
    font-weight: 600;
    color: var(--ft-text-inverse);
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
    white-space: nowrap;
}

.ft-gauge:hover .ft-gauge__segment-label,
.ft-gauge:focus-within .ft-gauge__segment-label,
.ft-gauge--labels-visible .ft-gauge__segment-label {
    opacity: 0.95;
}

/* Segmentos muito estreitos não têm espaço para o rótulo interno. */
.ft-gauge__segment--tiny .ft-gauge__segment-label {
    display: none;
}

.ft-gauge__segment--used {
    background: var(--ft-color-danger);
}

.ft-gauge__segment--reserved {
    background: var(--ft-color-warning);
}

.ft-gauge__segment--available {
    background: var(--ft-color-success);
}

/* Marcador de limite (StockLimit) — linha vertical + tick horizontal, adaptado
   de .threshold-marker (smelter.html, linha ~375-391). Sobrepõe o trilho,
   ancorado via left:<limit%> (ver FtGauge.render). Ignora toda a matemática de
   redistribuição do smelter — aqui é puramente um marcador de leitura. */
.ft-gauge__threshold {
    position: absolute;
    top: -0.25rem;
    bottom: -0.25rem;
    width: 2px;
    background: var(--ft-color-primary);
    transform: translateX(-1px);
    pointer-events: none;
    z-index: 3;
    transition: left 0.1s ease;
}

    .ft-gauge__threshold::before {
        content: "";
        position: absolute;
        top: -2px;
        left: -3px;
        width: 8px;
        height: 2px;
        background: var(--ft-color-primary);
    }

    .ft-gauge__threshold[hidden] {
        display: none;
    }

    /* Marcador ainda "não definido" (modo edição sem limite): fica esmaecido e
       tracejado, convidando o usuário a arrastá-lo. */
    .ft-gauge__threshold--unset {
        background: var(--ft-text-muted);
        opacity: 0.55;
    }

        .ft-gauge__threshold--unset::before {
            background: var(--ft-text-muted);
        }

/* Balão de leitura (%) do limite — ancorado acima do marcador, revelado no
   hover/foco. É a "informação liberada" do ponto divisor. */
.ft-gauge__readout {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translate(-50%, -0.25rem);
    padding: 0.05rem 0.3rem;
    font-size: 0.625rem;
    line-height: 1.4;
    font-weight: 600;
    white-space: nowrap;
    color: var(--ft-text-inverse);
    background: var(--ft-color-primary);
    border-radius: var(--ft-radius-sm);
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}

.ft-gauge:hover .ft-gauge__readout,
.ft-gauge:focus-within .ft-gauge__readout,
.ft-gauge--dragging .ft-gauge__readout,
.ft-gauge--labels-visible .ft-gauge__readout {
    opacity: 1;
}

/* Alça arrastável (só no modo edição). Escondida até o hover/foco para não
   poluir a célula em repouso; então cresce numa pega confortável. */
.ft-gauge__knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0.75rem;
    height: 0.75rem;
    transform: translate(-50%, -50%) scale(0.6);
    background: var(--ft-bg-surface);
    border: 2px solid var(--ft-color-primary);
    border-radius: 50%;
    box-shadow: var(--ft-shadow-sm);
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.1s ease;
    pointer-events: none;
    cursor: grab;
}

.ft-gauge--editable:hover .ft-gauge__knob,
.ft-gauge--editable:focus-within .ft-gauge__knob,
.ft-gauge--editable.ft-gauge--labels-visible .ft-gauge__knob {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.ft-gauge--editable.ft-gauge--dragging .ft-gauge__knob {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15);
    cursor: grabbing;
}

.ft-gauge--editable .ft-gauge__threshold:focus-visible {
    outline: none;
}

.ft-gauge--editable .ft-gauge__threshold:focus-visible .ft-gauge__knob {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.35), var(--ft-shadow-sm);
}

/* Legenda textual opcional (usado/reservado/disponível de total), renderizada
   pela partial _FtItemStockBar.cshtml ao lado do componente — mantém paridade
   com a legenda em <small> do _ItemStockBar.cshtml antigo. */
.ft-gauge__legend {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--ft-text-muted);
}

.ft-gauge__legend-item--used {
    color: var(--ft-color-danger);
}

.ft-gauge__legend-item--reserved {
    color: var(--ft-color-warning);
}

.ft-gauge__legend-item--available {
    color: var(--ft-color-success);
}

/* ═══════════════════════════ MODO periods ═══════════════════════════
   Timeline de períodos (ex. versões de um acordo) com bandas coloridas,
   ticks/rótulos de fronteira e marcador de valor — generalização de
   .ft-simulation-version-timeline* (ft-simulation-override.css). Mais alto
   que o modo segments para caber rótulo acima + marcador (caret+texto)
   abaixo. */
.ft-gauge--periods .ft-gauge__track {
    height: 48px;
}

.ft-gauge--periods:hover .ft-gauge__track,
.ft-gauge--periods:focus-within .ft-gauge__track {
    height: 48px;
}

.ft-gauge--periods .ft-gauge__fill {
    top: 18px;
    bottom: auto;
    height: 2px;
    border-radius: 1px;
    background: var(--ft-border-color);
}

/* Bandas por período — recortadas dentro do fill (linha do eixo). */
.ft-gauge__band {
    position: absolute;
    top: -6px;
    height: 8px;
    background: color-mix(in srgb, var(--ft-gauge-band, var(--ft-color-primary)) 22%, transparent);
    border-radius: 2px;
}

.ft-gauge__band--active {
    background: color-mix(in srgb, var(--ft-gauge-band, var(--ft-color-primary)) 45%, transparent);
}

/* Camada de overlay (ticks/rótulos/endcap/marker) — irmã do fill, fora do
   recorte, para poder vazar acima/abaixo do eixo. */
.ft-gauge__periods-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Rótulo do período, acima do eixo, ancorado no início do período. */
.ft-gauge__period-label {
    position: absolute;
    top: 0;
    font-size: 0.6875rem;
    line-height: 1.1;
    color: var(--ft-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ft-gauge__period-label--active {
    color: var(--ft-color-primary);
    font-weight: 600;
}

/* Tick vertical no início de cada período, cruzando o eixo (cor via
   --ft-gauge-tick). */
.ft-gauge__tick {
    position: absolute;
    top: 13px;
    width: 2px;
    height: 12px;
    background: var(--ft-gauge-tick, var(--ft-border-color));
    border-radius: 1px;
    transform: translateX(-1px);
}

/* Cap de fim do eixo — evita a sensação de eixo "sem fim". */
.ft-gauge__endcap {
    position: absolute;
    right: 0;
    top: 11px;
    width: 2px;
    height: 16px;
    background: var(--ft-text-muted);
    border-radius: 1px;
}

/* Marcador do valor corrente: ▲ apontando o eixo + rótulo, abaixo do eixo. */
.ft-gauge__marker {
    position: absolute;
    top: 23px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translateX(-50%);
    pointer-events: none;
}

.ft-gauge__marker-caret {
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 5px solid var(--ft-color-primary);
}

.ft-gauge__marker-label {
    margin-top: 1px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--ft-color-primary);
    white-space: nowrap;
}

.ft-gauge--periods.ft-gauge--editable .ft-gauge__track {
    cursor: pointer;
}

.ft-gauge--periods.ft-gauge--editable .ft-gauge__track:focus-visible {
    outline: 2px solid var(--ft-color-primary);
    outline-offset: 2px;
    border-radius: 2px;
}
