:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 1px;
}

.button,
.input,
.select,
.textarea {
    height: var(--control-height);
    padding: 0 var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-background);
    color: var(--color-text);
}

.textarea {
    height: auto;
    min-height: calc(var(--control-height) * 2);
    padding: var(--space-2) var(--space-3);
    resize: vertical;
}

.input:hover,
.select:hover,
.textarea:hover {
    border-color: var(--color-text-muted);
}

.input::placeholder,
.textarea::placeholder {
    color: var(--color-text-muted);
}

.input:disabled,
.select:disabled,
.textarea:disabled,
.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input[aria-invalid="true"] {
    border-color: var(--color-danger);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    background-color: var(--color-surface);
    white-space: nowrap;
}

.button:hover:not(:disabled) {
    background-color: var(--color-surface-hover);
}

.button--primary {
    border-color: var(--color-primary);
    background-color: var(--color-primary);
    color: var(--color-primary-contrast);
}

.button--primary:hover:not(:disabled) {
    border-color: var(--color-primary-hover);
    background-color: var(--color-primary-hover);
}

.button--danger {
    border-color: var(--color-danger);
    background-color: var(--color-danger);
    color: var(--color-danger-contrast);
}

.button--danger:hover:not(:disabled) {
    border-color: var(--color-danger-hover);
    background-color: var(--color-danger-hover);
}

.button--ghost {
    border-color: transparent;
    background-color: transparent;
}

.button--small {
    height: calc(var(--control-height) - 6px);
    padding: 0 var(--space-3);
    font-size: var(--font-size-small);
}

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.field__label {
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

.field__hint {
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

.field__error {
    font-size: var(--font-size-small);
    color: var(--color-danger);
}

.check {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.check input {
    accent-color: var(--color-primary);
}

.fieldset {
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.fieldset legend {
    padding: 0 var(--space-2);
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border: 1px solid currentColor;
    border-radius: var(--radius-pill);
    font-size: var(--font-size-small);
    line-height: 1.3;
}

.badge--success { color: var(--color-success); }
.badge--warning { color: var(--color-warning); }
.badge--danger { color: var(--color-danger); }
.badge--primary { color: var(--color-link); }

.alert {
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-left-width: 3px;
    border-radius: var(--radius);
    background-color: var(--color-surface);
}

.alert--success { border-left-color: var(--color-success); }
.alert--warning { border-left-color: var(--color-warning); }
.alert--danger { border-left-color: var(--color-danger); }
.alert--info { border-left-color: var(--color-primary); }

.progress {
    width: 100%;
    height: 0.5rem;
    accent-color: var(--color-primary);
}

.card {
    padding: var(--space-4) var(--space-5);
    border: 1px solid var(--color-border);
    border-top: 3px solid transparent;
    border-radius: var(--radius);
    background-color: var(--color-surface);
}

.card--clickable {
    cursor: pointer;
}

.card--clickable:hover {
    border-color: var(--color-border-hover);
}

.card--success { border-top-color: var(--color-success); }
.card--warning { border-top-color: var(--color-warning); }
.card--danger { border-top-color: var(--color-danger); }
.card--disabled { opacity: 0.6; }

.card[aria-pressed="true"] {
    border-color: var(--color-primary);
}

.card__label {
    color: var(--color-text-muted);
}

.card__value {
    margin-bottom: var(--space-2);
    font-size: 1.8rem;
    font-weight: 700;
}

.card__meta {
    display: flex;
    justify-content: space-between;
    color: var(--color-text-muted);
    font-size: var(--font-size-small);
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
    gap: var(--space-4);
}

.row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
    gap: var(--space-3);
}

.grid-container {
    height: 24rem;
}

.logo {
    display: inline-block;
}

.logo--horizontal {
    height: 2rem;
}

.logo--stacked {
    height: 3.5rem;
}

.logo__image {
    height: 100%;
    width: auto;
}

.logo__image--on-dark {
    display: none;
}

:root[data-theme="dark"] .logo__image--on-light {
    display: none;
}

:root[data-theme="dark"] .logo__image--on-dark {
    display: block;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .logo__image--on-light {
        display: none;
    }

    :root:not([data-theme="light"]) .logo__image--on-dark {
        display: block;
    }
}

.icon {
    width: 1rem;
    height: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon--small {
    width: 0.75rem;
    height: 0.75rem;
}

.flag {
    width: 1.25rem;
    height: 0.875rem;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 0 0 1px var(--color-border);
}

.dropdown {
    position: relative;
}

.dropdown__toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    height: var(--control-height);
    padding: 0 var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-background);
    color: var(--color-text);
    font-size: var(--font-size-small);
    font-weight: 600;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.dropdown__toggle::-webkit-details-marker {
    display: none;
}

.dropdown__toggle:hover {
    border-color: var(--color-text-muted);
}

.dropdown[open] > .dropdown__toggle {
    border-color: var(--color-primary);
}

.dropdown__chevron {
    color: var(--color-text-muted);
    transition: transform 0.15s;
}

.dropdown[open] .dropdown__chevron {
    transform: rotate(180deg);
}

.dropdown__menu {
    position: fixed;
    top: var(--dropdown-top, 0);
    left: var(--dropdown-left, 0);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 10rem;
    padding: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-background);
    color: var(--color-text);
    box-shadow: var(--shadow-popup);
    visibility: hidden;
}

.dropdown__menu[data-positioned] {
    visibility: visible;
}

.dropdown__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius);
    background-color: transparent;
    color: var(--color-text);
    text-align: left;
}

.dropdown__item:hover {
    background-color: var(--color-surface-hover);
}

.dropdown__item[aria-current="true"] {
    color: var(--color-link);
    font-weight: 600;
}

.dropdown__item[aria-current="true"]::after {
    content: "\2713";
    margin-left: auto;
}

.segmented {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-background);
}

.segmented__option {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 1.75rem;
    height: calc(var(--control-height) - 6px);
    border-radius: 2px;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.segmented__option:hover {
    background-color: var(--color-surface-hover);
    color: var(--color-text);
}

.segmented__option:has(:checked) {
    background-color: var(--color-primary);
    color: var(--color-primary-contrast);
}

.segmented__option:has(:focus-visible) {
    outline: 2px solid var(--color-focus);
    outline-offset: 1px;
}

.segmented__input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
    .dropdown__chevron,
    .segmented__option {
        transition: none;
    }
}

.tree {
    display: flex;
    flex-direction: column;
}

/* Tamaño pequeño */
.tree--small {
    font-size: var(--font-size-small);
}

.tree--small .tree__link,
.tree--small .tree__label {
    padding-block: 0.25rem;
}

.tree--depth-1 { --tree-depth: 1; }
.tree--depth-2 { --tree-depth: 2; }
.tree--depth-3 { --tree-depth: 3; }
.tree--depth-4 { --tree-depth: 4; }

/* Como el mockup: la fila ocupa todo el ancho y solo el texto se mete hacia dentro */
.tree__link,
.tree__label {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0.35rem var(--space-5) 0.35rem calc(var(--space-5) + var(--tree-depth, 0) * 1.1rem);
    color: var(--color-text);
    white-space: nowrap;
    cursor: pointer;
}

.tree__link:hover,
.tree__label:hover {
    background-color: var(--color-surface-hover);
    text-decoration: none;
}

.tree__link[aria-current="page"],
.tree__label[aria-current="page"] {
    background-color: var(--color-surface-hover);
    box-shadow: inset 3px 0 0 var(--color-primary);
    color: var(--color-link);
}

/* Texto de un grupo que también es página: se ve como el resto de la fila */
.tree__text {
    color: inherit;
}

.tree__text:hover {
    text-decoration: none;
}

.tree__label {
    list-style: none;
}

.tree__label::-webkit-details-marker {
    display: none;
}

/* Hueco de la flecha también en los enlaces, para que los textos queden alineados */
.tree__link::before,
.tree__label::before {
    content: "";
    flex-shrink: 0;
    width: 0.75rem;
    color: var(--color-text-muted);
    font-size: 0.7rem;
    text-align: center;
}

.tree__label::before {
    content: "\25B6";
    transition: transform 0.15s;
}

.tree__group[open] > .tree__label::before {
    transform: rotate(90deg);
}

@media (prefers-reduced-motion: reduce) {
    .tree__label::before {
        transition: none;
    }
}
/* ---------- Controles del mockup KPI ---------- */

/* Pestañas */
.tabs {
    display: flex;
    gap: var(--space-2);
    border-bottom: 1px solid var(--color-border);
}

.tabs__tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: -1px;
    padding: 0.4rem 0.9rem;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.tabs__tab:hover {
    color: var(--color-text);
}

.tabs__tab[aria-selected="true"] {
    border-bottom-color: var(--color-primary);
    color: var(--color-link);
    font-weight: 600;
}

/* Niveles: círculos unidos con el nombre debajo */
.stepper {
    display: flex;
    align-items: flex-start;
}

.stepper__step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    width: 3.25rem;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-text-muted);
    font-size: 0.7rem;
    line-height: 1.1;
    text-align: center;
}

.stepper__number {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border: 1px solid currentColor;
    border-radius: 50%;
    background-color: var(--color-surface);
    font-size: 0.7rem;
    font-weight: 600;
}

.stepper__line {
    width: 2rem;
    height: 2px;
    margin: 0.5625rem -1rem 0;
    background-color: var(--color-border);
    pointer-events: none;
}

.stepper__line--done {
    background-color: var(--color-primary);
}

.stepper__step--reached {
    color: var(--color-text);
}

.stepper__step--reached .stepper__number {
    border-color: var(--color-primary);
    color: var(--color-link);
}

.stepper__step--reached:hover {
    color: var(--color-link);
}

.stepper__step--active {
    color: var(--color-link);
}

.stepper__step--active .stepper__number {
    border-color: var(--color-primary);
    background-color: var(--color-primary);
    color: var(--color-primary-contrast);
}

.stepper__step--skipped,
.stepper__step--disabled {
    opacity: 0.45;
    cursor: default;
}

.stepper__step--skipped .stepper__number {
    border-style: dashed;
}

/* Migas de pan */
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    color: var(--color-text-muted);
    font-size: var(--font-size-small);
}

.breadcrumb__separator::before {
    content: "\203A";
}

/* Panel con título */
.panel {
    min-width: 0;
    padding: var(--space-4) var(--space-5) var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-surface);
}

.panel__title {
    margin-bottom: var(--space-4);
    font-weight: 600;
}

/* Barra de filtros en caja */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-5);
    padding: var(--space-3) var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-surface);
    color: var(--color-text-muted);
}

.toolbar__item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
}

/* Punto de estado */
.status-dot {
    display: inline-block;
    flex-shrink: 0;
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 50%;
    background-color: var(--color-neutral);
}

.status-dot--success { background-color: var(--color-success); }
.status-dot--warning { background-color: var(--color-warning); }
.status-dot--danger { background-color: var(--color-danger); }

/* Punto "en vivo" que parpadea */
.live-dot {
    display: inline-block;
    flex-shrink: 0;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background-color: var(--color-success);
    animation: live-dot-pulse 2s ease-in-out infinite;
}

@keyframes live-dot-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Textos de estado y de mejora o empeora */
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.text-muted { color: var(--color-text-muted); }

/* Tabla sencilla */
.table-wrapper {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--color-border);
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.table th:first-child,
.table td:first-child {
    text-align: left;
}

.table th {
    color: var(--color-text-muted);
    font-weight: 600;
}

.table__row--clickable {
    cursor: pointer;
}

.table__row--clickable:hover,
.table tr[aria-current="true"] {
    background-color: var(--color-surface-hover);
}

.table tr[aria-current="true"] td:first-child {
    color: var(--color-link);
    font-weight: 700;
}

/* Leyenda de gráficos */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
    color: var(--color-text-muted);
}

.legend__item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
}

.legend__item[aria-pressed="false"] {
    opacity: 0.35;
    text-decoration: line-through;
}

.legend__swatch {
    display: inline-block;
    width: 0.75rem;
    height: 3px;
    border-radius: 2px;
    background-color: currentColor;
}

.legend__swatch--dot {
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 50%;
}

/* Barra horizontal con marca de objetivo */
.bar {
    position: relative;
    height: 0.875rem;
    border-radius: 2px;
    background-color: var(--color-background);
}

.bar__fill {
    height: 100%;
    border-radius: 2px;
    background-color: var(--color-primary);
}

.bar__fill--success { background-color: var(--color-success); }
.bar__fill--warning { background-color: var(--color-warning); }
.bar__fill--danger { background-color: var(--color-danger); }

.bar__target {
    position: absolute;
    top: -3px;
    bottom: -3px;
    width: 2px;
    background-color: var(--color-text);
}

/* Barra apilada (reparto de tiempos) */
.stacked-bar {
    display: flex;
    height: 0.875rem;
    overflow: hidden;
    border-radius: 2px;
    background-color: var(--color-background);
}

.stacked-bar__part {
    height: 100%;
}

.stacked-bar__part--success { background-color: var(--color-success); }
.stacked-bar__part--warning { background-color: var(--color-warning); }
.stacked-bar__part--danger { background-color: var(--color-danger); }

/* Ficha de máquina con borde de estado a la izquierda */
.tile {
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-left: 4px solid transparent;
    border-radius: var(--radius);
    background-color: var(--color-background);
}

.tile--success { border-left-color: var(--color-success); }
.tile--warning { border-left-color: var(--color-warning); }
.tile--danger { border-left-color: var(--color-danger); }

.tile__head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
}

.tile__tag {
    margin-left: auto;
    color: var(--color-text-muted);
    font-size: var(--font-size-small);
}

.tile__meta {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-2);
    color: var(--color-text-muted);
    font-size: var(--font-size-small);
}

/* Lista de avisos */
.list__item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: var(--space-3) 0;
    border: 0;
    border-bottom: 1px solid var(--color-border);
    background: none;
    text-align: left;
}

.list__item:last-child {
    border-bottom: 0;
}

.list__item:hover .list__name {
    color: var(--color-link);
}

.list__name {
    flex: 1;
}

.list__detail {
    color: var(--color-text-muted);
    font-size: var(--font-size-small);
}

/* Avatar con iniciales */
.avatar {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 1.875rem;
    height: 1.875rem;
    border-radius: 50%;
    background-color: var(--color-primary);
    color: var(--color-primary-contrast);
    font-size: var(--font-size-small);
    font-weight: 700;
}

/* Globo de ayuda */
.tooltip {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-background);
    box-shadow: var(--shadow-popup);
    font-size: var(--font-size-small);
    pointer-events: none;
}

.tooltip--floating {
    position: fixed;
    z-index: 1000;
}

/* Nota al pie */
.note {
    color: var(--color-text-muted);
    font-size: var(--font-size-small);
}

@media (prefers-reduced-motion: reduce) {
    .live-dot {
        animation: none;
    }
}

.controls-page {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    max-width: 60rem;
    padding: var(--space-4);
}

.controls-page__form {
    display: contents;
}

.controls-page__section {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--color-border);
}

.controls-page__section .row {
    gap: var(--space-4);
}

.controls-page__section .controls-page__trees {
    align-items: flex-start;
}

.controls-page__section .grid {
    gap: var(--space-4);
}

.controls-page__section .stack {
    gap: var(--space-4);
}

/* Mismo fondo que el menú lateral, como en el mockup */
.controls-page__tree {
    width: 16rem;
    padding: var(--space-4) 0;
    border: 1px solid var(--color-border);
    background-color: var(--color-surface);
}

.controls-page__tile {
    max-width: 16rem;
}

.controls-page__bars {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    max-width: 24rem;
}
