/* m546_share_x1000 - Share.x1000.ai
   LIGHT HOPE V5.3 活动图片分享平台
   iPhone/iOS 兼容性优化版本 */

/* ==================== 基础重置 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* 允许文本选择的元素 */
input, textarea, [contenteditable="true"] {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

/* 禁止图片长按菜单 */
img {
    -webkit-user-select: none;
    user-select: none;
}

:root {
    /* LIGHT HOPE 品牌色 */
    --primary: #F5A623;
    --primary-dark: #D4891A;
    --primary-light: rgba(245, 166, 35, 0.1);
    --secondary: #1A1A1A;
    --background: #0D0D0D;
    --surface: #1A1A1A;
    --surface-light: #2A2A2A;
    --text: #FFFFFF;
    --text-secondary: #888888;
    --border: #333333;
    --success: #4CAF50;
    --error: #F44336;

    /* 尺寸 */
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);

    /* iOS 安全区域 */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* iOS 100vh 修复 */
    --vh: 1vh;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    overflow-x: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 15px;
    padding-bottom: calc(15px + var(--safe-bottom));
}

/* ==================== 头部 ==================== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    gap: 10px;
    flex-wrap: wrap;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 36px;
    filter: drop-shadow(0 0 8px rgba(245, 166, 35, 0.3));
}

.logo-text h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.tagline {
    font-size: 12px;
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stats {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 6px 12px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

/* ==================== 按钮 ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
    -webkit-appearance: none;
    touch-action: manipulation;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 13px;
}

.btn-primary {
    background: var(--primary);
    color: var(--secondary);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-primary:active {
    background: var(--primary-dark);
    transform: scale(0.96);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-secondary:active {
    background: var(--border);
    transform: scale(0.96);
}

.btn-success {
    background: var(--success) !important;
    color: #fff !important;
}

.btn-icon {
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 18px;
    line-height: 1;
}

.btn-icon.spinning {
    animation: spin 0.5s linear;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ==================== 上传区域 ==================== */
.upload-section {
    margin-bottom: 25px;
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 30px 20px;
    text-align: center;
    background: var(--surface);
    transition: all 0.3s ease;
}

.upload-zone:not(.is-mobile *):hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-zone.uploading {
    opacity: 0.7;
    pointer-events: none;
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.upload-icon {
    font-size: 48px;
    opacity: 0.9;
}

.upload-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.upload-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

.upload-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* 上传按钮组 */
.upload-buttons {
    display: flex;
    gap: 10px;
    margin: 15px 0;
    flex-wrap: wrap;
    justify-content: center;
}

.upload-buttons label {
    cursor: pointer;
}

/* 桌面/移动端显示控制 */
.desktop-only {
    display: block;
}

.mobile-only {
    display: none;
}

/* 上传进度 */
.upload-progress {
    margin-top: 15px;
    padding: 15px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.progress-info {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.progress-bar {
    height: 6px;
    background: var(--surface-light);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

#progress-text {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 10px;
}

#cancel-upload {
    display: block;
    margin: 0 auto;
}

/* ==================== 图片画廊 ==================== */
.gallery-section {
    margin-bottom: 30px;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    gap: 10px;
    flex-wrap: wrap;
}

.gallery-header h2 {
    font-size: 18px;
    font-weight: 600;
}

#photo-count {
    color: var(--text-secondary);
    font-weight: 400;
}

.gallery-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sort-select {
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    -webkit-appearance: none;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.gallery-loading,
.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 50px 20px;
    color: var(--text-secondary);
    font-size: 16px;
    line-height: 1.8;
}

.gallery-empty small {
    font-size: 14px;
    opacity: 0.7;
}

/* 图片卡片 */
.photo-card {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid var(--border);
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(245, 166, 35, 0.3);
}

.photo-card:active {
    transform: scale(0.97);
    border-color: var(--primary);
}

.photo-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s ease;
}

.photo-card img.no-thumb {
    object-fit: contain;
    background: var(--surface-light);
}

.photo-card .overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    opacity: 0;
    transition: opacity 0.2s ease;
}

.photo-card:hover .overlay {
    opacity: 1;
}

.photo-card .filename {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.photo-card .filesize {
    font-size: 10px;
    color: var(--text-secondary);
}

/* ==================== 模态框 ==================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--safe-top) 0 var(--safe-bottom) 0;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
}

.modal-content {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
}

.modal-close {
    position: fixed;
    top: calc(15px + var(--safe-top));
    right: 15px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255,255,255,0.3);
    color: #fff;
    font-size: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    z-index: 1010;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(255,255,255,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-image-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 200px;
}

#modal-image {
    max-width: 100%;
    max-height: 60vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

#modal-image.loading {
    opacity: 0.3;
}

.modal-info {
    margin-top: 15px;
    text-align: center;
    width: 100%;
}

#modal-filename {
    font-size: 14px;
    margin-bottom: 4px;
    word-break: break-all;
}

#modal-details {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    position: relative;
    z-index: 50;
}

.modal-actions .btn {
    padding: 12px 18px;
    font-size: 14px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(245, 166, 35, 0.3);
    cursor: pointer;
    min-height: 44px;
}

.modal-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255,255,255,0.3);
    color: #fff;
    font-size: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1010;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(255,255,255,0.3);
    font-weight: bold;
}

.modal-prev { left: 15px; }
.modal-next { right: 15px; }

.modal-nav:active {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-50%) scale(0.95);
}

.modal-close:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

/* ==================== Toast 提示 ==================== */
.toast {
    position: fixed;
    bottom: calc(30px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 2000;
    font-size: 14px;
    max-width: 90vw;
    text-align: center;
}

.toast.success {
    border-color: var(--success);
    background: rgba(76, 175, 80, 0.15);
    color: var(--success);
}

.toast.error {
    border-color: var(--error);
    background: rgba(244, 67, 54, 0.15);
    color: var(--error);
}

.toast:not(.hidden) {
    animation: toastSlideIn 0.3s ease-out;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ==================== 加载遮罩 ==================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--surface-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

#loading-text {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ==================== 页脚 ==================== */
.footer {
    text-align: center;
    padding: 20px 0;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 12px;
}

.footer strong {
    color: var(--primary);
}

.footer-sub {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 4px;
}

/* ==================== 工具类 ==================== */
.hidden {
    display: none !important;
}

/* ==================== 移动端响应式 ==================== */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .logo-icon {
        font-size: 32px;
    }

    .logo-text h1 {
        font-size: 18px;
    }

    .tagline {
        font-size: 11px;
    }

    .stats {
        padding: 5px 10px;
        font-size: 12px;
    }

    .btn-text {
        display: none;
    }

    .desktop-only {
        display: none;
    }

    .mobile-only {
        display: block;
    }

    .upload-zone {
        padding: 25px 15px;
    }

    .upload-icon {
        font-size: 40px;
    }

    .upload-title {
        font-size: 16px;
    }

    .upload-buttons {
        flex-direction: column;
        width: 100%;
        max-width: 300px;
    }

    .upload-buttons .btn {
        width: 100%;
        padding: 16px 24px;
        font-size: 16px;
        min-height: 54px;
    }

    .gallery {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .photo-card {
        border-radius: 6px;
    }

    .photo-card .overlay {
        opacity: 1;
        padding: 6px;
        background: linear-gradient(transparent 30%, rgba(0, 0, 0, 0.7));
    }

    .photo-card .filename {
        display: none;
    }

    .modal-content {
        padding: 5px;
    }

    #modal-image {
        max-height: 50vh;
    }

    .modal-actions {
        gap: 6px;
    }

    .modal-actions .btn {
        padding: 12px 14px;
        font-size: 13px;
        min-height: 48px;
    }
}

/* ==================== iOS 特殊样式 ==================== */
body.is-ios {
    /* iOS 滚动优化 */
    -webkit-overflow-scrolling: touch;
}

body.is-ios .upload-zone {
    /* iOS 点击优化 */
    cursor: pointer;
}

body.is-ios input[type="file"] {
    /* iOS 文件选择器修复 */
    font-size: 16px;
}

/* ==================== 桌面端增强 ==================== */
@media (min-width: 769px) {
    .container {
        padding: 20px;
    }

    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 15px;
    }

    .photo-card:hover {
        transform: translateY(-3px);
        box-shadow: var(--shadow);
    }

    .photo-card:hover img {
        transform: scale(1.03);
    }

    .modal-nav:hover {
        opacity: 1;
        background: rgba(255, 255, 255, 0.2);
    }

    .modal-close:hover {
        background: rgba(255, 255, 255, 0.2);
    }
}

/* ==================== 动画 ==================== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.photo-card {
    animation: fadeIn 0.3s ease;
}

/* 防止动画累积 */
.photo-card:nth-child(n+20) {
    animation: none;
}

/* ==================== 骨架屏 ==================== */
.photo-card.skeleton {
    background: var(--surface);
    animation: none;
}

.skeleton-shimmer {
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        var(--surface) 25%,
        var(--surface-light) 50%,
        var(--surface) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* ==================== 加载动画 ==================== */
.spinner-small {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--primary);
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* 刷新按钮旋转 */
.spinning {
    animation: spin 0.6s linear infinite;
}

/* ==================== 空状态和错误状态 ==================== */
.gallery-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.gallery-empty .empty-icon,
.gallery-empty .error-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.gallery-empty h3 {
    font-size: 18px;
    color: var(--text);
    margin-bottom: 8px;
}

.gallery-empty p {
    font-size: 14px;
    margin-bottom: 20px;
}

.gallery-empty.error {
    color: var(--error);
}

/* ==================== 进度条成功状态 ==================== */
.progress-fill.success {
    background: var(--success);
}

/* ==================== 模态框图片加载 ==================== */
#modal-image {
    transition: opacity 0.15s ease;
}

#modal-image.loading {
    opacity: 0.3;
    animation: pulse 1s ease-in-out infinite;
}

/* ==================== 按钮禁用状态 ==================== */
.btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none !important;
}

/* ==================== 模态框活动状态 ==================== */
.modal.active .modal-content {
    animation: fadeIn 0.2s ease;
}

/* ==================== 横屏优化 ==================== */
@media (orientation: landscape) and (max-height: 500px) {
    .upload-section {
        padding: 10px 0;
    }

    .upload-zone {
        padding: 15px;
    }

    .upload-icon {
        font-size: 24px;
    }

    .upload-title {
        font-size: 14px;
    }

    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    #modal-image {
        max-height: 70vh;
    }

    .modal-info {
        margin-top: 10px;
    }
}

/* ==================== 平板优化 ==================== */
@media (min-width: 768px) and (max-width: 1024px) {
    .gallery {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
    }

    .upload-buttons {
        flex-direction: row;
    }

    .modal-actions .btn {
        padding: 14px 20px;
    }
}

/* ==================== 打印样式 ==================== */
@media print {
    .upload-section,
    .modal,
    .toast,
    .loading-overlay {
        display: none !important;
    }
}
