/*
 * 现代化组件样式系统
 * 可复用的UI组件样式，参考 Shadcn/UI 和 Tailwind 设计理念
 */

/* ========== 按钮组件系统 ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-6);
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
    min-height: 44px; /* Touch target size */
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* 按钮尺寸变体 */
.btn-sm {
    padding: var(--space-2) var(--space-4);
    font-size: 0.875rem;
    min-height: 36px;
}

.btn-lg {
    padding: var(--space-4) var(--space-8);
    font-size: 1.125rem;
    min-height: 52px;
}

.btn-xl {
    padding: var(--space-5) var(--space-10);
    font-size: 1.25rem;
    min-height: 60px;
}

/* 按钮样式变体 */
.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-medium);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    background: var(--bg-glass);
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-outline {
    background: transparent;
    color: var(--primary-400);
    border: 2px solid var(--primary-400);
}

.btn-outline:hover {
    background: var(--primary-400);
    color: white;
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid transparent;
}

.btn-ghost:hover {
    background: var(--bg-glass);
    border-color: var(--border-light);
}

.btn-danger {
    background: linear-gradient(135deg, var(--error-500) 0%, var(--error-600) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
}

.btn-success {
    background: linear-gradient(135deg, var(--success-500) 0%, var(--success-600) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
}

/* 加载状态按钮 */
.btn-loading {
    position: relative;
    color: transparent;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    color: inherit;
    opacity: 0.8;
}

/* ========== 卡片组件 ========== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    transition: all var(--transition-normal);
    position: relative;
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
    border-color: var(--border-medium);
}

.card-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-glass);
}

.card-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.card-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.card-body {
    padding: var(--space-6);
}

.card-footer {
    padding: var(--space-6);
    border-top: 1px solid var(--border-light);
    background: var(--bg-glass);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
}

/* 紧凑卡片 */
.card-compact .card-header,
.card-compact .card-body,
.card-compact .card-footer {
    padding: var(--space-4);
}

/* 玻璃效果卡片 */
.card-glass {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
}

/* ========== 表单组件 ========== */
.form-group {
    margin-bottom: var(--space-6);
}

.form-label {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
    letter-spacing: 0.025em;
}

.form-label.required::after {
    content: ' *';
    color: var(--error-500);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all var(--transition-fast);
    min-height: 44px; /* Touch target size */
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(103, 102, 241, 0.1);
    background: var(--bg-card);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
}

/* 表单验证状态 */
.form-input.error,
.form-select.error,
.form-textarea.error {
    border-color: var(--error-500);
}

.form-input.error:focus,
.form-select.error:focus,
.form-textarea.error:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-input.success,
.form-select.success,
.form-textarea.success {
    border-color: var(--success-500);
}

.form-input.success:focus,
.form-select.success:focus,
.form-textarea.success:focus {
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}

.form-error {
    margin-top: var(--space-1);
    font-size: 0.875rem;
    color: var(--error-500);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.form-help {
    margin-top: var(--space-1);
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* 复选框组件 */
.checkbox-group {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    cursor: pointer;
    min-height: 44px; /* 确保足够的触摸目标 */
    padding: var(--space-2) 0;
}

.checkbox-group input[type="checkbox"] {
    margin: 0;
    flex-shrink: 0;
    margin-top: 2px; /* 微调对齐 */
    cursor: pointer;
    width: 18px;
    height: 18px;
    accent-color: var(--primary-500);
}

.checkbox-group label {
    flex: 1;
    cursor: pointer;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-secondary);
    margin: 0;
}

.checkbox-group label a {
    color: var(--primary-500);
    text-decoration: none;
}

.checkbox-group label a:hover {
    text-decoration: underline;
}

/* 增强移动设备的触摸体验 */
@media (max-width: 768px) {
    .checkbox-group {
        min-height: 48px; /* 移动设备上更大的触摸目标 */
        padding: var(--space-3) 0;
    }
    
    .checkbox-group input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }
    
    .checkbox-group label {
        font-size: 1rem;
    }
}

/* ========== Toast 通知组件 ========== */
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: var(--space-4);
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    max-width: 400px;
    animation: slideInRight 0.3s ease-out;
    position: relative;
    overflow: hidden;
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
}

.toast::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--info-500);
}

.toast.success::before {
    background: var(--success-500);
}

.toast.error::before {
    background: var(--error-500);
}

.toast.warning::before {
    background: var(--warning-500);
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin-top: 2px;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
    margin-bottom: var(--space-1);
}

.toast-message {
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.toast-close:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ========== 模态框组件 ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    animation: scaleIn 0.2s ease-out;
}

.modal-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    max-height: calc(90vh - 200px); /* 减去header和footer的大概高度 */
}

.modal-footer {
    padding: var(--space-6);
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ========== 导航组件 ========== */
.nav {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: var(--space-2);
}

.nav-item {
    position: relative;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    font-weight: 500;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-glass);
}

.nav-link.active {
    color: var(--primary-400);
    background: var(--bg-glass);
    position: relative;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: var(--primary-500);
    border-radius: var(--radius-sm);
}

/* ========== 标签组件 ========== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-primary {
    background: var(--primary-100);
    color: var(--primary-800);
}

.badge-success {
    background: var(--success-100);
    color: var(--success-800);
}

.badge-error {
    background: var(--error-100);
    color: var(--error-800);
}

.badge-warning {
    background: var(--warning-100);
    color: var(--warning-800);
}

.badge-info {
    background: var(--info-100);
    color: var(--info-800);
}

/* 暗色模式标签 */
@media (prefers-color-scheme: dark) {
    .badge-primary {
        background: rgba(103, 102, 241, 0.2);
        color: var(--primary-300);
    }
    
    .badge-success {
        background: rgba(34, 197, 94, 0.2);
        color: var(--success-300);
    }
    
    .badge-error {
        background: rgba(239, 68, 68, 0.2);
        color: var(--error-300);
    }
    
    .badge-warning {
        background: rgba(245, 158, 11, 0.2);
        color: var(--warning-300);
    }
    
    .badge-info {
        background: rgba(59, 130, 246, 0.2);
        color: var(--info-300);
    }
}

/* ========== 进度条组件 ========== */
.progress {
    width: 100%;
    height: 8px;
    background: var(--gray-700);
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
}

.progress-bar {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: var(--radius-sm);
    transition: width 0.3s ease;
    position: relative;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ========== 响应式网格 ========== */
.grid {
    display: grid;
    gap: var(--space-6);
}

.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 768px) {
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ========== 实用工具类 ========== */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }

.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }

.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }

.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* ========== 移动设备模态框优化 ========== */
@media (max-width: 768px) {
    .modal-overlay {
        padding: var(--space-2);
        align-items: flex-start;
        padding-top: 20px;
    }
    
    .modal {
        max-height: calc(100vh - 40px);
        width: calc(100% - var(--space-4));
    }
    
    .modal-body {
        max-height: calc(100vh - 160px);
        padding: var(--space-4);
    }
    
    .modal-header,
    .modal-footer {
        padding: var(--space-4);
    }
}

@media (max-width: 480px) {
    .modal {
        max-height: calc(100vh - 20px);
        border-radius: var(--radius-lg);
    }
    
    .modal-body {
        max-height: calc(100vh - 120px);
        padding: var(--space-3);
    }
    
    .modal-header,
    .modal-footer {
        padding: var(--space-3);
    }
}