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

body {
    font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background-color: #f8f9fa;
    color: #333;
    line-height: 1.6;
}

.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.sidebar {
    flex: 0 0 380px;
    position: relative;
}

.preview-section {
    flex: 1;
    min-width: 300px;
}

.card {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    margin-bottom: 15px;
    overflow: hidden;
}

.card-header {
    padding: 10px 15px;
    background-color: #f1f8ff;
    border-bottom: 1px solid #e3f2fd;
    font-weight: bold;
    color: #0056b3;
    font-size: 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-body {
    padding: 15px;
}

.upload-grid {
    display: flex;
    gap: 15px;
}

.file-input {
    flex: 1;
    min-width: 0;
}

.file-input-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #495057;
}

.file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 100%;
}

.file-input-button {
    background-color: #e9ecef;
    border: 1px solid #ced4da;
    color: #495057;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    display: block;
    text-align: center;
    width: 100%;
}

.file-input-button:hover {
    background-color: #dee2e6;
}

input[type="file"] {
    font-size: 100px;
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.file-name {
    margin-top: 5px;
    font-size: 0.9rem;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    width: 100%;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 15px;
}

.control-group {
    width: 100%;
}

.control-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-weight: 500;
    color: #495057;
}

.slider-value {
    color: #007bff;
    font-weight: normal;
}

input[type="range"] {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    background: #e9ecef;
    border-radius: 4px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: #007bff;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.15s ease-in-out;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #0056b3;
}

.toggle-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
    margin-bottom: 15px;
}

.toggle-group {
    display: flex;
    align-items: center;
}

.toggle-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    color: #495057;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    margin-right: 10px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: #007bff;
}

input:checked + .toggle-slider:before {
    transform: translateX(18px);
}

.button-primary {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background-color 0.3s, transform 0.2s;
    display: block;
    width: 100%;
    margin-top: 10px;
}

.button-primary:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

.button-primary:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
    transform: none;
}

.image-preview {
    width: 100%;
    height: 180px;
    object-fit: contain;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background-color: #f8f9fa;
    margin-top: 5px;
}

.button-secondary {
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.3s;
}

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

.button-secondary:disabled {
    background-color: #adb5bd;
    cursor: not-allowed;
}

.button-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.button-icon svg {
    margin-right: 4px;
}

.zoom-controls {
    display: flex;
    gap: 8px;
}

.zoom-control-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.zoom-control-wrapper input[type="range"] {
    flex: 1;
}

.zoom-buttons {
    display: flex;
    gap: 5px;
}

.preview-container {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    margin-bottom: 0;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f8f9fa;
    min-height: 200px;
    height: calc(100vh - 200px);
    max-height: calc(100vh - 100px);
}

#outputCanvas {
    display: block;
    max-width: none; /* Allow canvas to exceed container width */
}

@media (max-width: 900px) {
    .container {
        flex-direction: column;
    }
    
    .sidebar {
        flex: auto;
        width: 100%;
    }
    
    .upload-grid {
        flex-direction: column;
    }
    
    .preview-container {
        height: 400px;
        max-height: calc(100vh - 130px);
    }
}

/* Loading indicator */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 123, 255, 0.1);
    border-left-color: #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Help button */
.help-button {
    position: relative;
    width: 100%;
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    transition: all 0.2s ease;
}

.help-button:hover {
    background-color: #0056b3;
}

.help-button svg {
    margin-right: 5px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background-color: #fff;
    margin: 10% auto;
    padding: 0;
    width: 80%;
    max-width: 600px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    animation: modalFadeIn 0.3s;
}

.modal-header {
    padding: 15px 20px;
    background-color: #f1f8ff;
    border-bottom: 1px solid #e3f2fd;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.2rem;
    color: #0056b3;
    margin: 0;
}

.modal-body {
    padding: 20px;
    line-height: 1.8;
}

.modal-body ol {
    padding-left: 20px;
}

.modal-body li {
    margin-bottom: 8px;
}

.close-modal {
    color: #777;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close-modal:hover {
    color: #0056b3;
}

@keyframes modalFadeIn {
    from {opacity: 0; transform: translateY(-20px);}
    to {opacity: 1; transform: translateY(0);}
}

/* Zoom card styling */
.zoom-card {
    margin-bottom: 10px;
}

.zoom-card .card-body {
    padding: 12px 15px;
}