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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
    height: 100vh;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

.studio-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 左侧画廊 */
.studio-sidebar {
    flex: 1;
    min-width: 0;
    min-height: 0;
    background: #fff;
    border-right: 1px solid #e8ecf0;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.sidebar-header-logo {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

.studio-brand {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.studio-brand:hover {
    opacity: 0.88;
}

.studio-logo {
    display: block;
    height: 34px;
    width: auto;
    border-radius: 8px;
}

.sidebar-tip {
    background: #e8f8ef;
    color: #2d6a4f;
    border: 1px solid #b7e4c7;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 16px;
}

.gallery-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    grid-auto-rows: minmax(140px, auto);
    gap: 12px;
    overflow-y: auto;
    align-content: start;
    padding-right: 4px;
}

.gallery-grid::-webkit-scrollbar {
    width: 6px;
}

.gallery-grid::-webkit-scrollbar-thumb {
    background: #d0d5dd;
    border-radius: 3px;
}

.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: #98a2b3;
    padding: 60px 20px;
    font-size: 14px;
}

.gallery-item {
    position: relative;
    width: 100%;
    min-height: 140px;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid #e8ecf0;
    background: #f9fafb;
    transition: box-shadow 0.15s;
}

.gallery-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-item.failed {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: #fafafa;
}

.gallery-item.failed .fail-icon {
    width: 40px;
    height: 40px;
    color: #98a2b3;
    margin-bottom: 8px;
}

.gallery-item.failed .fail-text {
    font-size: 11px;
    color: #667085;
    text-align: center;
    line-height: 1.4;
    word-break: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    max-width: 100%;
    cursor: pointer;
}

.gallery-retry-btn {
    margin-top: 8px;
    padding: 4px 12px;
    border: 1px solid #2563eb;
    border-radius: 6px;
    background: #eff6ff;
    color: #2563eb;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
}

.gallery-retry-btn:hover:not(:disabled) {
    background: #dbeafe;
}

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

.gallery-item.processing {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #f0f4ff;
}

.gallery-item.processing .processing-text {
    font-size: 12px;
    color: #2563eb;
    font-weight: 500;
}

.gallery-item.failed .fail-label {
    font-size: 12px;
    color: #dc2626;
    font-weight: 500;
    margin-bottom: 4px;
}

.gallery-item .spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #dbeafe;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* 右侧控制区 */
.studio-main {
    width: 600px;
    min-width: 560px;
    flex-shrink: 0;
    min-height: 0;
    align-self: stretch;
    background: #fff;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.user-info {
    font-size: 13px;
    color: #667085;
}

.user-name {
    font-weight: 500;
    color: #344054;
}

.user-points {
    margin-left: 8px;
    color: #2563eb;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.upload-zone {
    position: relative;
    border: 2px dashed #d0d5dd;
    border-radius: 12px;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    margin-bottom: 12px;
    overflow: hidden;
}

.upload-zone.has-files {
    align-items: stretch;
    justify-content: flex-start;
    cursor: default;
    padding: 12px;
}

.upload-preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
}

.upload-preview-item {
    position: relative;
    width: 88px;
    height: 88px;
    flex-shrink: 0;
}

.upload-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #e8ecf0;
    display: block;
}

.upload-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.upload-preview-item.is-uploading img,
.upload-preview-item.is-failed img {
    opacity: 0.72;
}

.upload-preview-mask {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.45);
    color: #fff;
    font-size: 11px;
    border-radius: 8px;
    pointer-events: none;
}

.upload-preview-mask.is-error {
    background: rgba(220, 38, 38, 0.55);
}

.preview-remove-all,
.preview-add-more {
    padding: 4px 10px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    background: #fff;
    color: #667085;
    font-size: 12px;
    cursor: pointer;
}

.upload-preview-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    width: 100%;
    margin-top: 10px;
}

.preview-add-more {
    color: #2563eb;
    border-color: #bfdbfe;
    background: #eff6ff;
}

.preview-add-more:hover {
    background: #dbeafe;
}

.preview-remove-all:hover {
    background: #f9fafb;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: #2563eb;
    background: #f0f4ff;
}

.upload-placeholder {
    text-align: center;
    padding: 24px;
}

.upload-icon {
    color: #98a2b3;
    margin-bottom: 12px;
}

.upload-title {
    font-size: 14px;
    color: #344054;
    margin-bottom: 6px;
}

.upload-hint {
    font-size: 12px;
    color: #98a2b3;
}

.preview-image {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 8px;
}

.section-tip {
    font-size: 13px;
    color: #667085;
    margin-bottom: 16px;
}

.form-row {
    margin-bottom: 14px;
}

.form-row label {
    display: block;
    font-size: 13px;
    color: #344054;
    margin-bottom: 6px;
    font-weight: 500;
}

.form-row-3,
.form-row-4 {
    display: flex;
    gap: 10px;
}

@media (max-width: 768px) {
    .form-row-4 {
        flex-wrap: wrap;
    }

    .form-row-4 .form-col {
        flex: 1 1 calc(50% - 5px);
    }
}

.form-col {
    flex: 1;
    min-width: 0;
}

.form-select,
.form-input,
.form-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    font-size: 13px;
    color: #344054;
    background: #fff;
    outline: none;
    transition: border-color 0.2s;
}

.form-select:focus,
.form-input:focus,
.form-textarea:focus {
    border-color: #2563eb;
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-primary {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-outline {
    background: #fff;
    color: #344054;
    border-color: #d0d5dd;
}

.btn-outline:hover {
    background: #f9fafb;
}

.btn-generate {
    width: 100%;
    padding: 14px;
    font-size: 15px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 10px;
    margin-top: auto;
}

.btn-generate:hover {
    background: #1d4ed8;
}

.btn-generate:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}

.btn-block {
    width: 100%;
}

/* 弹窗 */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: #fff;
    border-radius: 12px;
    z-index: 1;
    max-width: 90vw;
    max-height: 90vh;
}

.modal-preview {
    padding: 20px;
}

.modal-preview img {
    max-width: 80vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
}

.modal-form {
    width: 400px;
    padding: 24px;
}

.modal-form h3 {
    margin-bottom: 20px;
    font-size: 18px;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 24px;
    color: #667085;
    cursor: pointer;
    line-height: 1;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    margin-bottom: 6px;
    color: #344054;
}

.form-switch {
    text-align: center;
    margin-top: 12px;
    font-size: 13px;
}

.form-switch a {
    color: #2563eb;
    text-decoration: none;
}

.preview-error {
    color: #dc2626;
    font-size: 14px;
    margin-top: 12px;
    text-align: center;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 2000;
}

@media (max-width: 960px) {
    body {
        height: auto;
        overflow: auto;
    }

    .studio-app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .studio-sidebar {
        overflow: visible;
        min-height: auto;
    }

    .gallery-grid {
        min-height: 300px;
        max-height: 50vh;
    }

    .studio-main {
        width: 100%;
        min-width: 0;
        min-height: auto;
    }
}
