* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4a90d9;
    --primary-hover: #357abd;
    --success-color: #5cb85c;
    --success-hover: #4cae4c;
    --bg-color: #f5f5f5;
    --sidebar-width: 320px;
    --border-color: #ddd;
    --text-color: #333;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* 侧边栏样式 */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 20px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--primary-color);
}

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

.logo h1 {
    font-size: 20px;
    color: var(--primary-color);
}

/* 导航链接样式 */
.nav-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    text-decoration: none;
    color: #666;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
}

.nav-link:hover {
    background: #f0f7ff;
    color: var(--primary-color);
}

.nav-link.active {
    background: var(--primary-color);
    color: white;
}

.nav-icon {
    font-size: 18px;
}

.upload-section {
    margin-bottom: 25px;
}

.upload-section h2 {
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.upload-box {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: #fafafa;
}

.upload-box:hover {
    border-color: var(--primary-color);
    background: #f0f7ff;
}

.upload-box.dragover {
    border-color: var(--primary-color);
    background: #e3f2fd;
}

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

.upload-box p {
    font-size: 13px;
    color: #666;
    margin-bottom: 5px;
}

.file-name {
    display: block;
    font-size: 12px;
    color: var(--primary-color);
    word-break: break-all;
    margin-top: 8px;
}

/* 印章素材库 */
.stamp-library {
    min-height: 100px;
    background: #f9f9f9;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: center;
}

.library-hint {
    font-size: 12px;
    color: #999;
    text-align: center;
    width: 100%;
}

.library-stamp-item {
    width: 70px;
    height: 70px;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s;
    background: white;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.library-stamp-item:hover {
    border-color: var(--primary-color);
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.library-stamp-item:active {
    cursor: grabbing;
}

.library-stamp-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    pointer-events: none; /* 防止图片干扰拖拽 */
}

.library-stamp-item .delete-library-stamp {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #d9534f;
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.library-stamp-item:hover .delete-library-stamp {
    opacity: 1;
}

/* 设置区域样式 */
.settings-section {
    margin-bottom: 25px;
}

.settings-section h2 {
    font-size: 14px;
    color: #666;
    margin-bottom: 15px;
    text-transform: uppercase;
}

.setting-item {
    margin-bottom: 15px;
}

.setting-item label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 8px;
    color: #555;
}

.range-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.range-wrapper input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

.range-wrapper input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
}

.range-wrapper span {
    min-width: 50px;
    text-align: right;
    font-size: 12px;
    color: #666;
}

.setting-item select,
.setting-item input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
}

.setting-item select:focus,
.setting-item input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* 按钮样式 */
.action-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    width: 100%;
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(74, 144, 217, 0.3);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(92, 184, 92, 0.3);
}

.btn-danger {
    background: #d9534f;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #c9302c;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(217, 83, 79, 0.3);
}

.btn-icon {
    font-size: 16px;
}

/* 主内容区样式 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #e9ecef;
}

.toolbar {
    background: white;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.page-nav {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-nav {
    padding: 6px 16px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.btn-nav:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

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

.page-info {
    font-size: 13px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-info input {
    width: 50px;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-color);
    text-align: center;
}

.page-info input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.page-info input:hover {
    border-color: #bbb;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-zoom {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-zoom:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

#zoomLevel {
    min-width: 50px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
}

/* PDF容器样式 */
.pdf-container {
    flex: 1;
    overflow: auto;
    padding: 30px;
    display: flex;
    justify-content: center;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #999;
}

.placeholder-icon {
    font-size: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.placeholder h2 {
    font-size: 24px;
    margin-bottom: 10px;
    color: #666;
}

.placeholder p {
    font-size: 14px;
}

.pdf-canvas-wrapper {
    position: relative;
    display: inline-block;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    background: white;
}

#pdfCanvas {
    display: block;
}

.stamp-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.stamp-on-canvas {
    position: absolute;
    cursor: move;
    pointer-events: auto;
    user-select: none;
    border: 2px dashed transparent;
    transition: border-color 0.2s;
}

.stamp-on-canvas:hover,
.stamp-on-canvas.dragging {
    border-color: var(--primary-color);
}

.stamp-on-canvas img {
    width: 100%;
    height: 100%;
    display: block;
}

/* 印章控制按钮容器 */
.stamp-controls {
    position: absolute;
    bottom: -45px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    padding: 6px 8px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 999;
    pointer-events: auto;
}

/* 印章本身支持滚轮 */
.stamp-on-canvas {
    pointer-events: auto;
}

.stamp-on-canvas:hover .stamp-controls {
    opacity: 1;
}

/* 控制按钮样式 */
.stamp-control-btn {
    width: 28px;
    height: 28px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #666;
    transition: all 0.2s;
}

.stamp-control-btn:hover {
    background: #f0f0f0;
    border-color: #4a90d9;
    color: #4a90d9;
    transform: scale(1.1);
}

/* 印章删除按钮 (在控制栏中) */
.stamp-delete-btn {
    width: 28px;
    height: 28px;
    background: #d9534f;
    color: white;
    border: 1px solid #d9534f;
    border-radius: 4px;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.stamp-delete-btn:hover {
    background: #c9302c;
    border-color: #c9302c;
    transform: scale(1.1);
}

/* 加载遮罩 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    color: white;
    font-size: 16px;
    margin-top: 20px;
}

/* 滚动条美化 */
.sidebar::-webkit-scrollbar,
.pdf-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.sidebar::-webkit-scrollbar-track,
.pdf-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.sidebar::-webkit-scrollbar-thumb,
.pdf-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.pdf-container::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* 去背景模态框 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #e9ecef;
    color: #333;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.remove-bg-canvas-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f5f5f5;
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    min-height: 300px;
}

#removeBgCanvas {
    max-width: 100%;
    max-height: 60vh;
    border: 1px solid #ddd;
    cursor: crosshair;
}

.selection-rect {
    position: absolute;
    border: 2px solid var(--primary-color);
    background: rgba(74, 144, 217, 0.1);
    pointer-events: none;
}

.remove-bg-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-warning {
    background: #ffc107;
    color: #333;
}

.btn-warning:hover {
    background: #e0a800;
}

.btn-warning:disabled {
    background: #ffc107;
    opacity: 0.5;
    cursor: not-allowed;
}

/* 印章拉伸控制点样式 */
.stamp-resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border: 1px solid #4a90d9;
    border-radius: 2px;
    z-index: 1000;
}

.stamp-resize-handle.nw { /* 左上 */
    top: -5px;
    left: -5px;
    cursor: nwse-resize;
}

.stamp-resize-handle.ne { /* 右上 */
    top: -5px;
    right: -5px;
    cursor: nesw-resize;
}

.stamp-resize-handle.sw { /* 左下 */
    bottom: -5px;
    left: -5px;
    cursor: nesw-resize;
}

.stamp-resize-handle.se { /* 右下 */
    bottom: -5px;
    right: -5px;
    cursor: nwse-resize;
}

/* 隐藏移动端，仅在小屏幕显示 */
@media (max-width: 768px) {
    .stamp-resize-handle {
        display: none;
    }
}

/* Toast 通知样式 */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    font-size: 14px;
    pointer-events: none;
}

.toast-show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-success {
    background: #5cb85c;
}

.toast-error {
    background: #dc3545;
}

.toast-info {
    background: #4a90d9;
}

/* ==================== 移动端响应式设计 ==================== */

/* 移动端菜单按钮 */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1001;
    width: 44px;
    height: 44px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    touch-action: manipulation;
}

/* 移动端侧边栏遮罩 */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    opacity: 1;
}

/* 平板设备 (768px - 1024px) */
@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }

    .toolbar {
        flex-wrap: wrap;
        gap: 8px;
    }

    .page-nav, .zoom-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* 移动设备 (最大 768px) */
@media (max-width: 768px) {
    /* 显示移动端菜单按钮 */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* 侧边栏变为抽屉式 */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        width: 85%;
        max-width: 320px;
        z-index: 1000;
        transition: left 0.3s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar.active {
        left: 0;
    }

    /* 遮罩显示 */
    .sidebar-overlay {
        display: block;
    }

    /* 主内容区全屏 */
    .main-content {
        width: 100%;
    }

    /* 工具栏响应式 */
    .toolbar {
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .page-nav {
        width: 100%;
        justify-content: space-between;
        gap: 8px;
        order: 2;
    }

    .zoom-controls {
        width: 100%;
        justify-content: center;
        order: 1;
        margin-bottom: 4px;
    }

    /* 页面导航按钮更大，方便触摸 */
    .btn-nav {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 40px;
    }

    /* 页面信息更紧凑 */
    .page-info {
        font-size: 12px;
        flex: 1;
        justify-content: center;
    }

    .page-info input {
        width: 45px;
        font-size: 14px;
    }

    /* 缩放按钮更大 */
    .btn-zoom {
        min-width: 40px;
        height: 40px;
        font-size: 16px;
    }

    /* PDF容器减少内边距 */
    .pdf-container {
        padding: 15px;
    }

    /* 上传区域优化 */
    .upload-box {
        padding: 20px 15px;
    }

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

    /* 按钮触摸优化 */
    .btn {
        min-height: 48px;
        padding: 14px 20px;
        font-size: 15px;
    }

    /* 印章库项目更大 */
    .library-stamp-item {
        width: 80px;
        height: 80px;
    }

    /* 设置区域 */
    .setting-item label {
        font-size: 14px;
    }

    /* Toast位置调整 */
    .toast {
        bottom: 20px;
        left: 20px;
        right: 20px;
        transform: translateY(100px);
    }

    .toast-show {
        transform: translateY(0);
    }

    /* 模态框移动端优化 */
    .modal-container {
        max-width: 95%;
        max-height: 95vh;
        border-radius: 8px;
    }

    .modal-header {
        padding: 15px;
    }

    .modal-header h3 {
        font-size: 16px;
    }

    .modal-body {
        padding: 15px;
    }

    /* 占位符优化 */
    .placeholder-icon {
        font-size: 60px;
    }

    .placeholder h2 {
        font-size: 20px;
    }

    .placeholder p {
        font-size: 13px;
    }
}

/* 小屏手机 (最大 480px) */
@media (max-width: 480px) {
    .mobile-menu-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .sidebar {
        width: 90%;
    }

    .toolbar {
        padding: 6px 10px;
    }

    .page-nav {
        gap: 6px;
    }

    .btn-nav {
        padding: 8px 12px;
        font-size: 13px;
        min-height: 36px;
    }

    .btn-zoom {
        min-width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .pdf-container {
        padding: 10px;
    }

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

    .upload-section h2,
    .settings-section h2 {
        font-size: 13px;
    }

    /* 印章库更紧凑 */
    .library-stamp-item {
        width: 70px;
        height: 70px;
    }

    /* 印章控制按钮在移动端始终显示 */
    .stamp-on-canvas .stamp-controls {
        opacity: 1;
    }

    .stamp-controls {
        bottom: -50px;
        padding: 8px 10px;
        gap: 8px;
    }

    .stamp-control-btn,
    .stamp-delete-btn {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    /* 移除hover效果 */
    .library-stamp-item:hover,
    .library-stamp-item:active {
        transform: none;
    }

    /* 点击反馈 */
    .library-stamp-item:active {
        opacity: 0.7;
    }

    /* 印章控制按钮始终可见 */
    .stamp-on-canvas .stamp-controls {
        opacity: 1;
    }

    /* 按钮点击效果 */
    .btn:active,
    .btn-nav:active,
    .btn-zoom:active {
        transform: scale(0.97);
        opacity: 0.8;
    }

    /* 增大触摸目标 */
    .library-stamp-item .delete-library-stamp {
        opacity: 1;
        width: 22px;
        height: 22px;
    }
}

/* 横屏模式优化 */
@media (max-width: 768px) and (orientation: landscape) {
    .sidebar {
        width: 70%;
        max-width: 280px;
    }

    .pdf-container {
        padding: 10px;
    }

    .toolbar {
        padding: 6px 10px;
    }

    /* 缩小标题 */
    .logo {
        margin-bottom: 15px;
        padding-bottom: 15px;
    }

    .logo h1 {
        font-size: 16px;
    }

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

/* 防止iOS Safari回弹效果 */
body {
    overscroll-behavior: none;
}

.sidebar, .pdf-container {
    overscroll-behavior: contain;
}

/* 优化iOS上的点击高亮 */
.btn,
.btn-nav,
.btn-zoom,
.library-stamp-item,
.mobile-menu-btn {
    -webkit-tap-highlight-color: transparent;
}
