/**
 * compat.css - 跨浏览器兼容性全局样式
 * 支持：Chrome, Firefox, Safari, Edge, IE11+
 * 特别针对macOS Safari进行优化
 */

/* ========== CSS Reset & Normalize ========== */
*, *::before, *::after {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========== Safari/iOS 100vh 修复 ========== */
/* Safari上100vh包含地址栏高度，使用CSS变量动态计算 */
:root {
    --vh: 1vh;
    --full-height: 100vh;
}

@supports (-webkit-touch-callout: none) {
    /* iOS Safari 特定修复 */
    :root {
        --full-height: -webkit-fill-available;
    }
}

/* ========== Flexbox 兼容性前缀 ========== */
.d-flex,
.flex,
[style*="display: flex"],
[style*="display:flex"] {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
}

.d-inline-flex {
    display: -webkit-inline-box;
    display: -webkit-inline-flex;
    display: -moz-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
}

.flex-column {
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -moz-box-orient: vertical;
    -moz-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
}

.flex-row {
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -webkit-flex-direction: row;
    -moz-box-orient: horizontal;
    -moz-box-direction: normal;
    -ms-flex-direction: row;
    flex-direction: row;
}

.flex-wrap {
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
}

.justify-content-center {
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -moz-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
}

.justify-content-between {
    -webkit-box-pack: justify;
    -webkit-justify-content: space-between;
    -moz-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
}

.justify-content-end {
    -webkit-box-pack: end;
    -webkit-justify-content: flex-end;
    -moz-box-pack: end;
    -ms-flex-pack: end;
    justify-content: flex-end;
}

.align-items-center {
    -webkit-box-align: center;
    -webkit-align-items: center;
    -moz-box-align: center;
    -ms-flex-align: center;
    align-items: center;
}

.align-items-start {
    -webkit-box-align: start;
    -webkit-align-items: flex-start;
    -moz-box-align: start;
    -ms-flex-align: start;
    align-items: flex-start;
}

.align-items-end {
    -webkit-box-align: end;
    -webkit-align-items: flex-end;
    -moz-box-align: end;
    -ms-flex-align: end;
    align-items: flex-end;
}

.flex-1 {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -moz-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
}

.flex-shrink-0 {
    -webkit-flex-shrink: 0;
    -ms-flex-negative: 0;
    flex-shrink: 0;
}

/* ========== Gap 属性兼容性修复 ========== */
/* Safari 14.1之前不支持 flexbox gap，使用margin替代 */
@supports not (gap: 8px) {
    .gap-1 > * { margin: 0.125rem; }
    .gap-2 > * { margin: 0.25rem; }
    .gap-3 > * { margin: 0.5rem; }
    .gap-4 > * { margin: 0.75rem; }
    .gap-5 > * { margin: 1rem; }
}

/* ========== Transform 兼容性 ========== */
.transform-center {
    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    -o-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
}

/* ========== Transition 兼容性 ========== */
.transition-all {
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    -o-transition: all 0.3s ease;
    transition: all 0.3s ease;
}

/* ========== 表单元素 Safari 兼容性 ========== */
input, textarea, select, button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

/* 恢复select箭头 */
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.25rem;
}

/* checkbox 和 radio 恢复默认样式 */
input[type="checkbox"],
input[type="radio"] {
    -webkit-appearance: checkbox;
    -moz-appearance: checkbox;
    appearance: auto;
    width: auto;
    cursor: pointer;
}

input[type="radio"] {
    -webkit-appearance: radio;
    -moz-appearance: radio;
}

/* Safari focus outline 修复 */
input:focus, textarea:focus, select:focus, button:focus {
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

/* Safari 自动填充背景色修复 */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px white inset !important;
    box-shadow: 0 0 0 1000px white inset !important;
    -webkit-text-fill-color: inherit !important;
}

/* ========== 滚动条兼容性 ========== */
/* Webkit 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Firefox 滚动条样式 */
* {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}

/* ========== 按钮点击效果 Safari ========== */
button, a, .btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ========== 图片兼容性 ========== */
img {
    -webkit-user-drag: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* 图片object-fit兼容 */
.object-fit-cover {
    -o-object-fit: cover;
    object-fit: cover;
}

.object-fit-contain {
    -o-object-fit: contain;
    object-fit: contain;
}

/* ========== 文本选择兼容性 ========== */
.user-select-none {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.user-select-all {
    -webkit-user-select: all;
    -moz-user-select: all;
    -ms-user-select: all;
    user-select: all;
}

/* ========== Placeholder 样式兼容 ========== */
::-webkit-input-placeholder { color: #adb5bd; opacity: 1; }
::-moz-placeholder { color: #adb5bd; opacity: 1; }
:-ms-input-placeholder { color: #adb5bd; opacity: 1; }
::placeholder { color: #adb5bd; opacity: 1; }

/* ========== 文本换行兼容性 ========== */
.text-break {
    word-break: break-word;
    -ms-word-break: break-all;
    word-wrap: break-word;
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    -ms-hyphens: auto;
    hyphens: auto;
}

/* ========== 粘性定位兼容性 ========== */
.sticky-top {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 1020;
}

/* ========== 背景渐变兼容性 ========== */
.bg-gradient-primary {
    background: #667eea;
    background: -webkit-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background: -moz-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background: -o-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* ========== Box Shadow 兼容性 ========== */
.shadow {
    -webkit-box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    -moz-box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.shadow-sm {
    -webkit-box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    -moz-box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.shadow-lg {
    -webkit-box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.175);
    -moz-box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.175);
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.175);
}

/* ========== Backdrop Filter 兼容 (Safari) ========== */
.backdrop-blur {
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

/* ========== accent-color 兼容性修复 (Safari < 15) ========== */
@supports not (accent-color: auto) {
    input[type="checkbox"]:checked {
        background-color: #667eea;
        border-color: #667eea;
    }
    
    input[type="radio"]:checked {
        background-color: #667eea;
        border-color: #667eea;
    }
}

/* ========== 打印样式兼容 ========== */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
}

