/**
 * FlowX4 Controls
 * ===============
 * Checkboxes, Toggle switches, Chips
 */

/* ============================================
   CHECKBOX
   ============================================ */
.checkbox {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
}

.checkbox input {
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--color-surface-input);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.checkbox input:hover {
    border-color: var(--color-accent-primary);
}

.checkbox input:checked {
    background: var(--color-accent-primary);
    border-color: var(--color-accent-primary);
}

.checkbox input:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox input:focus {
    box-shadow: var(--shadow-focus);
}

.checkbox-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
}

/* ============================================
   TOGGLE SWITCH
   ============================================ */
.toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    width: 40px;
    height: 22px;
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-full);
    transition: background var(--transition-fast);
}

.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: var(--color-text-secondary);
    border-radius: var(--radius-full);
    transition: all var(--transition-fast);
}

.toggle input:checked + .toggle-track {
    background: var(--color-accent-primary);
}

.toggle input:checked ~ .toggle-thumb {
    transform: translateX(18px);
    background: #fff;
}

/* Toggle Row */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface-primary);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
}

.toggle-row-label {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.toggle-row-text {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
}

.toggle-row-desc {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
}

/* ============================================
   CHIP GROUP
   ============================================ */
.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
}

.chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border-default);
    background: var(--color-surface-primary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
    min-width: 36px;
}

.chip svg {
    flex-shrink: 0;
}

.chip input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.chip:hover {
    border-color: var(--color-accent-primary);
    color: var(--color-text-primary);
}

.chip--active,
.chip:has(input:checked) {
    background: var(--color-accent-primary);
    border-color: var(--color-accent-primary);
    color: #fff;
}

.chip--saving {
    opacity: 0.6;
    pointer-events: none;
}

/* ============================================
   SLIDER CONTROL
   ============================================ */
.slider-control {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.input-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 120px;
    height: 6px;
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-full);
    outline: none;
    cursor: pointer;
}

.input-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--color-accent-primary);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.input-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.input-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--color-accent-primary);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
}

.slider-value {
    min-width: 52px;
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-sm);
    text-align: center;
}

/* ============================================
   RANGE INLINE (число на ползунке)
   ============================================ */
.range-inline {
    position: relative;
    display: inline-flex;
    align-items: center;
    height: 28px;
}

.range-inline input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 120px;
    height: 4px;
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-full);
    outline: none;
    cursor: pointer;
    margin: 0;
}

.range-inline input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 48px;
    height: 24px;
    background: transparent;
    cursor: grab;
}

.range-inline input[type="range"]::-webkit-slider-thumb:active {
    cursor: grabbing;
}

.range-inline input[type="range"]::-moz-range-thumb {
    width: 48px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: grab;
}

.range-inline .range-label {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    background: var(--color-accent-primary);
    color: #fff;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    white-space: nowrap;
    line-height: 1.4;
}

/* ============================================
   TABLE TOGGLE (для списков справочников)
   ============================================ */
.table-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 20px;
    border-radius: var(--radius-full);
    background: var(--color-surface-active);
    cursor: pointer;
    transition: background var(--transition-fast);
    position: relative;
}

.table-toggle.active {
    background: var(--color-accent-primary);
}

.table-toggle .toggle-knob {
    position: absolute;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: var(--radius-full);
    background: #fff;
    transition: transform var(--transition-fast);
}

.table-toggle.active .toggle-knob {
    transform: translateX(16px);
}

.table-toggle.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* ============================================
   FORM TOGGLE (для форм справочников)
   ============================================ */
.form-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3);
    background: var(--color-surface-input);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
}

.toggle-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.toggle-label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
}

.toggle-hint {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* Form Toggle Switch (44x24) */
.form-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--color-surface-active);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

.form-toggle.active {
    background: var(--color-accent-primary);
}

.form-toggle .toggle-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: var(--radius-full);
    transition: transform var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.form-toggle.active .toggle-knob {
    transform: translateX(20px);
}
