:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --radius: 10px;
    --shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
    --sidebar-width: 240px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.logo {
    font-size: 1.35rem;
    font-weight: 700;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.layout {
    display: flex;
    flex: 1;
    min-height: 0;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 16px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.group-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 8px;
}

.group-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 4px;
}

.group-item:hover {
    background: #f1f5f9;
}

.group-item.active {
    background: #dbeafe;
    color: var(--primary-hover);
    font-weight: 600;
}

.group-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.group-item-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: #f1f5f9;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 8px;
}

.group-item.active .group-item-count {
    background: #bfdbfe;
    color: var(--primary-hover);
}

.group-item.drop-target {
    background: #dcfce7;
    outline: 2px dashed #16a34a;
}

.group-item.child-group .group-item-name::before {
    content: "└ ";
    color: var(--text-muted);
    font-size: 0.75rem;
}

.group-empty {
    padding: 16px;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
}

.main {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    position: relative;
}

.main-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.toolbar-info h2 {
    font-size: 1.2rem;
}

.image-count {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
    background: #e2e8f0;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-hover);
}

.btn-danger-outline {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger-outline:hover:not(:disabled) {
    background: #fef2f2;
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 28px;
    text-align: center;
    margin-bottom: 20px;
    transition: border-color 0.2s, background 0.2s;
}

.upload-zone[data-images-disabled="true"] .upload-title::after {
    content: "（图片需先选分组）";
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: normal;
}

.upload-zone.drag-over {
    border-color: var(--primary);
    background: #eff6ff;
}

.upload-icon {
    font-size: 2rem;
    color: var(--primary);
    margin-bottom: 8px;
}

.upload-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.upload-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.image-grid-wrapper {
    position: relative;
    min-height: 80px;
}

#main-content {
    user-select: none;
}

.selection-marquee {
    position: absolute;
    border: 1px solid var(--primary);
    background: rgba(59, 130, 246, 0.15);
    pointer-events: none;
    z-index: 20;
}

.batch-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
    margin-bottom: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.selection-info {
    font-size: 0.9rem;
    font-weight: 600;
}

.clipboard-info {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.batch-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.82rem;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    align-items: start;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.image-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
}

.image-card.selected::before {
    content: "✓";
    position: absolute;
    top: 8px;
    left: 8px;
    width: 22px;
    height: 22px;
    background: var(--primary);
    color: #fff;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    pointer-events: none;
}

.image-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: visible;
    box-shadow: var(--shadow);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    display: flex;
    flex-direction: column;
    position: relative;
}

.image-card:hover {
    transform: translateY(-2px);
}

.image-card.dragging {
    opacity: 0.45;
}

.image-card[draggable="true"] {
    cursor: grab;
}

.image-card[draggable="true"]:active {
    cursor: grabbing;
}

.image-thumb-wrap {
    position: relative;
    aspect-ratio: 1;
    background: #f8fafc;
    cursor: zoom-in;
    border-radius: var(--radius) var(--radius) 0 0;
    overflow: hidden;
    flex-shrink: 0;
}

.image-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.image-card-actions {
    position: absolute;
    top: 6px;
    right: 6px;
}

.btn-icon {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}

.btn-icon:hover {
    background: var(--danger);
}

.image-card-body {
    padding: 10px;
    flex: 1;
    min-width: 0;
}

.filename-display {
    font-size: 0.82rem;
    line-height: 1.45;
    white-space: normal;
    word-break: break-all;
    overflow-wrap: anywhere;
    overflow: visible;
    cursor: text;
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid transparent;
}

.filename-display:hover {
    background: #f8fafc;
    border-color: var(--border);
}

.filename-input {
    width: 100%;
    font-size: 0.82rem;
    padding: 4px 6px;
    border: 1px solid var(--primary);
    border-radius: 4px;
    outline: none;
}

.image-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.modal-dialog {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    width: min(420px, 92vw);
    box-shadow: var(--shadow);
    z-index: 1;
}

.modal-dialog h3 {
    margin-bottom: 16px;
}

.input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    margin-bottom: 16px;
    outline: none;
}

.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.confirm-message {
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.5;
}

.modal-hint {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 12px;
    line-height: 1.5;
}

.field-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.modal-preview {
    width: min(800px, 95vw);
    text-align: center;
}

.modal-preview img {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 8px;
    margin-bottom: 16px;
}

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 18px;
    border-radius: 8px;
    color: #fff;
    font-size: 0.9rem;
    box-shadow: var(--shadow);
    animation: slideIn 0.25s ease;
}

.toast-success {
    background: #16a34a;
}

.toast-error {
    background: var(--danger);
}

.toast-info {
    background: var(--primary);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    font-weight: 600;
    color: var(--primary);
}

@media (max-width: 768px) {
    .layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 200px;
    }
}
