/* ==================== 表单输入优化样式 ==================== */

/* ===== 通用表单元素优化 ===== */
.form-control,
.form-select,
textarea {
    border-radius: 0.375rem;
    transition: all 0.3s ease;
    border: 1px solid #dee2e6;
}

/* 输入框聚焦状态 */
.form-control:focus,
.form-select:focus,
textarea:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
    outline: none;
}

/* 输入错误状态 */
.form-control.is-invalid:focus,
.form-select.is-invalid:focus,
textarea.is-invalid:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

/* 输入成功状态 */
.form-control.is-valid:focus,
.form-select.is-valid:focus,
textarea.is-valid:focus {
    border-color: #198754;
    box-shadow: 0 0 0 0.2rem rgba(25, 135, 84, 0.25);
}

/* ===== 单选/复选框优化 ===== */
.form-check {
    padding-left: 0;
    margin-bottom: 0.75rem;
}

.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.125rem;
    margin-right: 0.5rem;
    cursor: pointer;
    border: 2px solid #dee2e6;
    transition: all 0.2s ease;
}

.form-check-input:focus {
    border-color: #0d6efd;
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.form-check-input:checked {
    background-color: #0d6efd;
    border-color: #0d6efd;
    box-shadow: inset 0 -0.375rem 0.75rem -0.375rem rgba(0, 0, 0, 0.125);
}

.form-check-label {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    margin-bottom: 0;
    padding-left: 0;
    font-weight: 500;
}

/* ===== 标签优化 ===== */
.form-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #495057;
    font-size: 0.95rem;
}

.form-label.required::after {
    content: ' *';
    color: #dc3545;
}

/* ===== 必填字段标记 ===== */
.form-group-required {
    position: relative;
}

/* ===== 日期时间输入优化 ===== */
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"],
input[type="week"] {
    position: relative;
}

/* 修复 iOS 中的日期选择器 */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover {
    background-color: #e9ecef;
}

/* ===== 数字输入优化 ===== */
input[type="number"] {
    -moz-appearance: textfield;
}

/* 隐藏 Chrome/Safari 的数字上下按钮 */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* 但在移动端保留大的可点击区域 */
@media (hover: none) and (pointer: coarse) {
    input[type="number"] {
        -moz-appearance: none;
        -webkit-appearance: none;
    }

    input[type="number"]::-webkit-outer-spin-button,
    input[type="number"]::-webkit-inner-spin-button {
        -webkit-appearance: auto;
        opacity: 1;
    }
}

/* ===== 文本框优化 ===== */
textarea {
    resize: vertical;
    min-height: 120px;
    font-family: inherit;
    line-height: 1.5;
}

@media (max-width: 575px) {
    textarea {
        min-height: 100px;
        max-height: 300px;
    }
}

/* ===== 选择框优化 ===== */
.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;
    padding-right: 2.5rem;
    cursor: pointer;
}

.form-select:focus {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%230d6efd' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
}

/* ===== 输入组优化 ===== */
.input-group {
    gap: 0.5rem;
}

@media (max-width: 575px) {
    .input-group {
        gap: 0.25rem;
    }

    .input-group > .form-control,
    .input-group > .btn {
        border-radius: 0.25rem;
    }
}

.input-group-text {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    padding: 0.5rem 0.75rem;
    font-weight: 500;
    color: #6c757d;
}

/* ===== 表单验证样式 ===== */
.was-validated .form-control:invalid,
.form-control.is-invalid {
    border-color: #dc3545;
}

.was-validated .form-control:invalid:focus,
.form-control.is-invalid:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.was-validated .form-control:valid,
.form-control.is-valid {
    border-color: #198754;
}

.was-validated .form-control:valid:focus,
.form-control.is-valid:focus {
    border-color: #198754;
    box-shadow: 0 0 0 0.2rem rgba(25, 135, 84, 0.25);
}

/* 验证反馈 */
.valid-feedback,
.invalid-feedback {
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: block;
}

.invalid-feedback {
    color: #dc3545;
}

.valid-feedback {
    color: #198754;
}

/* ===== 表单组优化 ===== */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

/* ===== 提示信息 ===== */
.form-text {
    font-size: 0.875rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

/* ===== 移动端专用优化 ===== */
@media (max-width: 575px) {
    /* 增加输入框高度便于触摸 */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="date"],
    textarea {
        height: auto;
        min-height: 44px;
        padding: 0.75rem;
        font-size: 16px !important;
        border-radius: 0.25rem;
    }

    /* 增加标签清晰度 */
    .form-label {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }

    /* 表单组间距 */
    .form-group {
        margin-bottom: 1.25rem;
    }

    /* 单选/复选框更大的触摸区域 */
    .form-check {
        padding-left: 0;
        display: flex;
        align-items: center;
        padding: 0.5rem;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }

    .form-check-input {
        width: 1.5rem;
        height: 1.5rem;
        margin: 0;
        margin-right: 0.75rem;
    }

    .form-check-label {
        flex: 1;
        margin: 0;
        font-size: 1rem;
        padding: 0.5rem;
    }

    /* 行组合优化 */
    .row .col-6,
    .row .col-md-2,
    .row .col-lg-2 {
        padding-right: 0.375rem;
        padding-left: 0.375rem;
    }

    /* 优化单选/复选框组 */
    .form-check-group {
        display: flex;
        gap: 1rem;
        flex-wrap: wrap;
    }

    .form-check-group .form-check {
        flex: 0 1 calc(50% - 0.5rem);
        margin-bottom: 0;
    }

    /* 隐藏虚拟键盘时的调整 */
    body.keyboard-visible {
        /* 移除 position: fixed 和 overflow: hidden，避免阻止页面滚动 */
    }
}

/* 平板设备优化 */
@media (min-width: 576px) and (max-width: 1023px) {
    .form-control,
    .form-select,
    textarea {
        font-size: 15px;
        min-height: 40px;
    }

    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
    }

    .btn {
        min-height: 40px;
    }
}

/* ===== 禁用状态 ===== */
.form-control:disabled,
.form-select:disabled,
textarea:disabled,
input:disabled {
    background-color: #e9ecef;
    cursor: not-allowed;
    opacity: 0.65;
}

/* ===== 焦点可见性优化 ===== */
:focus-visible {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* ===== 占位符样式 ===== */
::placeholder {
    color: #adb5bd;
    opacity: 1;
    font-style: italic;
}

/* ===== 移动设备输入法优化 ===== */
@supports (-webkit-touch-callout: none) {
    /* iOS 特定优化 */
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="tel"],
    textarea,
    select {
        font-size: 16px !important;
        -webkit-appearance: none;
        -webkit-border-radius: 0;
        -webkit-user-select: text;
    }
}
