/* ==================== ПРОДВИНУТЫЕ СТИЛИ ФОРМ ==================== */

/* Базовые стили полей */
.form-control {
    width: 100%;
    padding: 14px 18px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

.form-control:hover {
    border-color: var(--border-light);
    background: var(--bg-card);
}

.form-control:focus {
    border-color: var(--accent-primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
}

.form-control:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form-control.is-invalid {
    border-color: var(--error);
}

.form-control.is-invalid:focus {
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15);
}

.form-control.is-valid {
    border-color: var(--success);
}

.form-control.is-valid:focus {
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15);
}

/* ==================== SELECT / ВЫПАДАЮЩИЕ СПИСКИ ==================== */

.form-select {
    width: 100%;
    padding: 14px 48px 14px 18px;
    background-color: var(--bg-tertiary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 20px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.form-select:hover {
    border-color: var(--border-light);
    background-color: var(--bg-card);
}

.form-select:focus {
    border-color: var(--accent-primary);
    background-color: var(--bg-card);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%237c3aed' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
}

.form-select option {
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 12px;
}

/* Кастомный Select с dropdown */
.custom-select {
    position: relative;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.custom-select-trigger:hover {
    border-color: var(--border-light);
    background: var(--bg-card);
}

.custom-select.open .custom-select-trigger {
    border-color: var(--accent-primary);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.custom-select-trigger .arrow {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.custom-select.open .custom-select-trigger .arrow {
    transform: rotate(180deg);
    color: var(--accent-primary);
}

.custom-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 2px solid var(--accent-primary);
    border-top: none;
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
    max-height: 280px;
    overflow-y: auto;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

.custom-select.open .custom-select-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.custom-select-option {
    padding: 12px 18px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.custom-select-option:hover {
    background: var(--bg-card-hover);
}

.custom-select-option.selected {
    background: rgba(124, 58, 237, 0.1);
    color: var(--accent-primary);
}

.custom-select-option .check-icon {
    width: 18px;
    height: 18px;
    opacity: 0;
    color: var(--accent-primary);
}

.custom-select-option.selected .check-icon {
    opacity: 1;
}

/* ==================== TEXTAREA ==================== */

.form-textarea {
    width: 100%;
    min-height: 120px;
    padding: 16px 18px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    transition: all 0.2s ease;
}

.form-textarea:hover {
    border-color: var(--border-light);
    background: var(--bg-card);
}

.form-textarea:focus {
    border-color: var(--accent-primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
}

/* Auto-resize textarea */
.form-textarea.auto-resize {
    overflow: hidden;
    resize: none;
}

/* ==================== INPUT GROUP (С ИКОНКОЙ) ==================== */

.input-group {
    position: relative;
    display: flex;
    align-items: stretch;
}

.input-group .form-control {
    padding-left: 50px;
}

.input-group-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    transition: color 0.2s ease;
    z-index: 1;
}

.input-group .form-control:focus ~ .input-group-icon,
.input-group .form-control:focus + .input-group-icon {
    color: var(--accent-primary);
}

/* Input с кнопкой справа */
.input-group-append {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
}

.input-group-append .btn {
    padding: 10px 16px;
}

/* Input с текстом/лейблом */
.input-group-text {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    background: var(--bg-elevated);
    border: 2px solid var(--border-color);
    border-right: none;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    color: var(--text-muted);
    font-size: 0.95rem;
    white-space: nowrap;
}

.input-group-text + .form-control {
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}

/* ==================== CHECKBOX И RADIO ==================== */

.form-check {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

.form-check-input {
    position: relative;
    width: 22px;
    height: 22px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    flex-shrink: 0;
    margin-top: 2px;
}

.form-check-input:hover {
    border-color: var(--accent-primary);
    background: var(--bg-card);
}

.form-check-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
}

.form-check-input:checked {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.form-check-input:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
    width: 6px;
    height: 10px;
    border: 2px solid white;
    border-top: none;
    border-left: none;
}

/* Radio */
.form-check-input[type="radio"] {
    border-radius: 50%;
}

.form-check-input[type="radio"]:checked::after {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: white;
    border: none;
    transform: translate(-50%, -50%);
}

.form-check-label {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.form-check-label a {
    color: var(--accent-primary);
}

/* ==================== SWITCH / TOGGLE ==================== */

.form-switch {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.form-switch-input {
    position: relative;
    width: 52px;
    height: 28px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.form-switch-input::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.form-switch-input:hover {
    border-color: var(--border-light);
}

.form-switch-input:checked {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.form-switch-input:checked::after {
    left: calc(100% - 22px);
    background: white;
}

.form-switch-input:focus {
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
}

.form-switch-label {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ==================== RANGE SLIDER ==================== */

.form-range {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.form-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.4);
}

.form-range::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.5);
}

.form-range::-moz-range-thumb {
    width: 22px;
    height: 22px;
    background: var(--accent-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.form-range:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
}

/* Range с значением */
.range-wrapper {
    position: relative;
}

.range-value {
    position: absolute;
    top: -32px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 10px;
    background: var(--accent-primary);
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.range-wrapper:hover .range-value,
.form-range:focus ~ .range-value {
    opacity: 1;
}

/* ==================== FILE INPUT ==================== */

.form-file {
    position: relative;
}

.form-file-input {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.form-file-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px;
    background: var(--bg-tertiary);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-xl);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.form-file-label:hover,
.form-file.dragover .form-file-label {
    border-color: var(--accent-primary);
    background: var(--bg-card);
}

.form-file-icon {
    width: 64px;
    height: 64px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: var(--accent-primary);
}

.form-file-text {
    color: var(--text-secondary);
}

.form-file-text strong {
    color: var(--accent-primary);
}

.form-file-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Превью файла */
.form-file-preview {
    margin-top: 16px;
    position: relative;
    display: inline-block;
}

.form-file-preview img {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--radius-lg);
    object-fit: cover;
}

.form-file-preview .remove-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    background: var(--error);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.form-file-preview .remove-btn:hover {
    transform: scale(1.1);
}

/* ==================== LABELS ==================== */

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-label.required::after {
    content: '*';
    color: var(--error);
    margin-left: 4px;
}

/* Floating label */
.form-floating {
    position: relative;
}

.form-floating .form-control {
    padding-top: 24px;
    padding-bottom: 8px;
}

.form-floating .form-label {
    position: absolute;
    top: 50%;
    left: 18px;
    transform: translateY(-50%);
    pointer-events: none;
    transition: all 0.2s ease;
    margin: 0;
    color: var(--text-muted);
}

.form-floating .form-control:focus ~ .form-label,
.form-floating .form-control:not(:placeholder-shown) ~ .form-label {
    top: 12px;
    transform: translateY(0);
    font-size: 0.75rem;
    color: var(--accent-primary);
}

/* ==================== FORM FEEDBACK ==================== */

.form-text {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.form-error {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--error);
}

.form-error i {
    font-size: 0.9rem;
}

.form-success {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--success);
}

/* ==================== FORM LAYOUT ==================== */

.form-group {
    margin-bottom: 24px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.form-row-2 {
    grid-template-columns: repeat(2, 1fr);
}

.form-row-3 {
    grid-template-columns: repeat(3, 1fr);
}

.form-row-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* Inline form */
.form-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px;
}

.form-inline .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 150px;
}

/* ==================== FORM SIZES ==================== */

.form-control-sm {
    padding: 10px 14px;
    font-size: 0.875rem;
    border-radius: var(--radius-md);
}

.form-control-lg {
    padding: 18px 22px;
    font-size: 1.1rem;
    border-radius: var(--radius-xl);
}

.form-select-sm {
    padding: 10px 40px 10px 14px;
    font-size: 0.875rem;
}

.form-select-lg {
    padding: 18px 52px 18px 22px;
    font-size: 1.1rem;
}

/* ==================== SEARCH INPUT ==================== */

.search-input-wrapper {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 14px 48px 14px 50px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: all 0.2s ease;
}

.search-input:hover {
    border-color: var(--border-light);
}

.search-input:focus {
    border-color: var(--accent-primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
}

.search-input-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input:focus ~ .search-input-icon {
    color: var(--accent-primary);
}

.search-input-clear {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    background: var(--bg-elevated);
    border: none;
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s ease;
}

.search-input:not(:placeholder-shown) ~ .search-input-clear {
    opacity: 1;
}

.search-input-clear:hover {
    background: var(--error);
    color: white;
}

/* ==================== TAGS INPUT ==================== */

.tags-input {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    min-height: 54px;
    cursor: text;
    transition: all 0.2s ease;
}

.tags-input:focus-within {
    border-color: var(--accent-primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--accent-primary);
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    color: white;
}

.tag-remove {
    width: 16px;
    height: 16px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.tag-remove:hover {
    background: rgba(255, 255, 255, 0.4);
}

.tags-input input {
    flex: 1;
    min-width: 100px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
}

.tags-input input::placeholder {
    color: var(--text-muted);
}

/* ==================== DATE/TIME INPUTS ==================== */

.form-control[type="date"],
.form-control[type="time"],
.form-control[type="datetime-local"] {
    position: relative;
}

.form-control[type="date"]::-webkit-calendar-picker-indicator,
.form-control[type="time"]::-webkit-calendar-picker-indicator,
.form-control[type="datetime-local"]::-webkit-calendar-picker-indicator {
    background: transparent;
    cursor: pointer;
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    opacity: 0;
}

.form-control[type="date"]::after,
.form-control[type="time"]::after,
.form-control[type="datetime-local"]::after {
    content: '📅';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

/* ==================== NUMBER INPUT ==================== */

.number-input-wrapper {
    display: flex;
    align-items: stretch;
}

.number-input-wrapper .form-control {
    border-radius: 0;
    text-align: center;
    -moz-appearance: textfield;
}

.number-input-wrapper .form-control::-webkit-outer-spin-button,
.number-input-wrapper .form-control::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.number-btn {
    width: 48px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.number-btn:first-child {
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    border-right: none;
}

.number-btn:last-child {
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    border-left: none;
}

.number-btn:hover {
    background: var(--bg-card);
    color: var(--accent-primary);
}

/* ==================== COLOR INPUT ==================== */

.form-color {
    width: 100%;
    height: 54px;
    padding: 6px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
}

.form-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

.form-color::-webkit-color-swatch {
    border: none;
    border-radius: var(--radius-md);
}

.form-color:hover {
    border-color: var(--border-light);
}

.form-color:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
}

/* ==================== PASSWORD STRENGTH ==================== */

.password-strength {
    margin-top: 12px;
}

.password-strength-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.password-strength-segment {
    flex: 1;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    transition: background 0.3s ease;
}

.password-strength[data-strength="1"] .password-strength-segment:nth-child(1) {
    background: var(--error);
}

.password-strength[data-strength="2"] .password-strength-segment:nth-child(-n+2) {
    background: var(--warning);
}

.password-strength[data-strength="3"] .password-strength-segment:nth-child(-n+3) {
    background: #84cc16;
}

.password-strength[data-strength="4"] .password-strength-segment {
    background: var(--success);
}

.password-strength-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.password-strength[data-strength="1"] .password-strength-text { color: var(--error); }
.password-strength[data-strength="2"] .password-strength-text { color: var(--warning); }
.password-strength[data-strength="3"] .password-strength-text { color: #84cc16; }
.password-strength[data-strength="4"] .password-strength-text { color: var(--success); }

/* ==================== AUTOCOMPLETE ==================== */

.autocomplete {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 2px solid var(--accent-primary);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    max-height: 240px;
    overflow-y: auto;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

.autocomplete.open .autocomplete-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.autocomplete.open .form-control {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.autocomplete-item {
    padding: 12px 18px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.autocomplete-item:hover,
.autocomplete-item.highlighted {
    background: var(--bg-card-hover);
}

.autocomplete-item mark {
    background: rgba(124, 58, 237, 0.3);
    color: var(--accent-primary);
    border-radius: 2px;
    padding: 0 2px;
}

.autocomplete-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .form-row-2,
    .form-row-3,
    .form-row-4 {
        grid-template-columns: 1fr;
    }

    .form-inline {
        flex-direction: column;
        align-items: stretch;
    }

    .form-inline .form-group {
        width: 100%;
    }
}