:root {
    --primary: #ff2442;
    --primary-light: #ff6b81;
    --bg: #f5f5f5;
    --card: #ffffff;
    --text: #333333;
    --text-light: #999999;
    --border: #e8e8e8;
    --success: #52c41a;
    --warning: #faad14;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* Nav */
.navbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.navbar .logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin-right: 40px;
}

.navbar .nav-links {
    display: flex;
    gap: 4px;
}

.navbar .nav-links a {
    text-decoration: none;
    color: var(--text-light);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.navbar .nav-links a:hover,
.navbar .nav-links a.active {
    color: var(--primary);
    background: rgba(255, 36, 66, 0.06);
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* Cards */
.card {
    background: var(--card);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.card h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

/* Form elements */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 6px;
}

input[type="text"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: var(--card);
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
}

textarea { resize: vertical; min-height: 80px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: #e81e3c; }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }

.btn-secondary {
    background: #f0f0f0;
    color: var(--text);
}
.btn-secondary:hover { background: #e0e0e0; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { padding: 8px; border-radius: 50%; }

/* Upload area */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.upload-area:hover {
    border-color: var(--primary);
    background: rgba(255, 36, 66, 0.02);
}
.upload-area p { color: var(--text-light); font-size: 14px; }
.upload-area .icon { font-size: 32px; margin-bottom: 8px; }

/* Waterfall / Masonry gallery */
.waterfall {
    columns: 4;
    column-gap: 16px;
}

@media (max-width: 900px) { .waterfall { columns: 3; } }
@media (max-width: 600px) { .waterfall { columns: 2; } }

.waterfall-item {
    break-inside: avoid;
    margin-bottom: 16px;
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.waterfall-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.waterfall-item img {
    width: 100%;
    display: block;
}

.waterfall-item .item-info {
    padding: 12px;
}

.waterfall-item .item-info .title {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.waterfall-item .item-actions {
    display: flex;
    gap: 8px;
    padding: 0 12px 12px;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 200;
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--card);
    border-radius: 16px;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 1;
}

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

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-light);
    padding: 4px 8px;
    border-radius: 6px;
}
.modal-close:hover { background: #f0f0f0; }

.modal-body { padding: 20px; }

/* Analysis result */
.analysis-section { margin-bottom: 16px; }
.analysis-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 8px;
}

.prompt-box {
    background: #f8f8f8;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    font-size: 13px;
    line-height: 1.8;
    position: relative;
    white-space: pre-wrap;
    word-break: break-word;
}

.prompt-box .copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
}

.prompt-box .copy-btn:hover { background: #f0f0f0; }

/* Grid for generated images */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.image-card {
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.image-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

/* Controls row */
.controls {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.controls .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 150px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-light);
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Loading */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Status badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}
.badge-success { background: #f6ffed; color: var(--success); }
.badge-warning { background: #fffbe6; color: var(--warning); }

/* Toast notification */
.toast {
    position: fixed;
    top: 72px;
    right: 24px;
    background: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 300;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Responsive */
@media (max-width: 768px) {
    .container { padding: 16px; }
    .navbar { padding: 0 16px; }
    .card { padding: 16px; }
    .controls { flex-direction: column; }
}

/* Note grid — 按笔记分组的图片网格 */
.note-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

@media (max-width: 600px) {
    .note-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}

.note-grid-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: #f5f5f5;
    aspect-ratio: 1;
}

.note-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.2s;
}

.note-grid-item:hover img {
    transform: scale(1.04);
}

.note-grid-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 4px;
}

.note-grid-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    display: flex;
    gap: 4px;
    background: linear-gradient(transparent, rgba(0,0,0,0.5));
    opacity: 0;
    transition: opacity 0.2s;
}

.note-grid-item:hover .note-grid-actions {
    opacity: 1;
}

/* Image comparison slider */
.compare-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 8px;
    user-select: none;
    cursor: ew-resize;
}

.compare-container img {
    display: block;
    width: 100%;
    height: auto;
}

.compare-img-before {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

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

.compare-slider-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    background: white;
    box-shadow: 0 0 6px rgba(0,0,0,0.4);
    z-index: 2;
    pointer-events: none;
}

.compare-slider-handle {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #666;
    pointer-events: none;
}

.compare-label {
    position: absolute;
    top: 12px;
    padding: 4px 12px;
    background: rgba(0,0,0,0.5);
    color: white;
    font-size: 12px;
    border-radius: 4px;
    z-index: 2;
    pointer-events: none;
}

.compare-label-before { left: 12px; }
.compare-label-after { right: 12px; }

/* Compare thumb list */
.compare-thumbs {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    overflow-x: auto;
    padding: 4px 0;
}

.compare-thumb {
    width: 64px;
    height: 64px;
    border-radius: 6px;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid transparent;
    opacity: 0.6;
    transition: all 0.2s;
    flex-shrink: 0;
}

.compare-thumb:hover,
.compare-thumb.active {
    border-color: var(--primary);
    opacity: 1;
}

/* Compare info row */
.compare-info {
    margin-top: 12px;
    padding: 12px;
    background: #f8f8f8;
    border-radius: 8px;
    font-size: 13px;
}

/* 笔记卡片 checkbox */
.note-checkbox {
    width: 18px;
    height: 18px;
    margin-top: 3px;
    cursor: pointer;
    accent-color: var(--primary);
    flex-shrink: 0;
}

/* 图片选择 checkbox */
.img-checkbox {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 18px;
    height: 18px;
    z-index: 3;
    cursor: pointer;
    accent-color: var(--primary);
    opacity: 0;
    transition: opacity 0.15s;
}

.note-grid-item:hover .img-checkbox,
.note-grid-item.selected .img-checkbox,
.img-checkbox:checked {
    opacity: 1;
}

/* 选中态 */
.note-grid-item.selected {
    outline: 3px solid var(--primary);
    outline-offset: -3px;
}

/* 底部浮动操作栏 */
.batch-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 150;
    transform: translateY(100%);
    transition: transform 0.25s ease;
}

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

.batch-bar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
    border-radius: 12px 12px 0 0;
}

.batch-bar-count {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
}

/* 分析进度条 */
#analyzeProgress {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 8px;
}

.progress-bar-wrap {
    width: 120px;
    height: 6px;
    background: #eee;
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
}

.progress-text {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
}

/* ===== Auth ===== */

/* Login/Register page */
.auth-container {
    max-width: 400px;
    margin: 80px auto;
    padding: 0 24px;
}

.auth-card {
    background: var(--card);
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.auth-card h2 {
    text-align: center;
    margin-bottom: 24px;
    color: var(--primary);
}

.auth-card .btn { width: 100%; justify-content: center; margin-top: 8px; }

.auth-card input[type="text"],
.auth-card input[type="password"] {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: var(--card);
}

.auth-card input:focus { border-color: var(--primary); }

.auth-link {
    text-align: center;
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-light);
}

.auth-link a { color: var(--primary); text-decoration: none; }
.auth-link a:hover { text-decoration: underline; }

.auth-error {
    color: var(--primary);
    font-size: 13px;
    text-align: center;
    margin-top: 8px;
    min-height: 20px;
}

/* Nav user info */
.nav-user {
    font-size: 13px;
    color: var(--text-light);
    padding: 8px 8px;
    display: flex;
    align-items: center;
}

.nav-logout {
    font-size: 13px !important;
    color: var(--text-light) !important;
}

/* Admin panel */
.admin-section { margin-bottom: 24px; }
.admin-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.admin-table th {
    color: var(--text-light);
    font-weight: 500;
    font-size: 13px;
}

.admin-table .actions {
    display: flex;
    gap: 6px;
}

/* Stats cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--card);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.stat-number {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

/* Invite code display */
.invite-codes-display {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.invite-code-chip {
    background: #f0f0f0;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 14px;
    font-family: monospace;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 0.2s;
}

.invite-code-chip:hover { background: #e0e0e0; }

/* ===== Note Imitation ===== */

/* Note queue chips */
.note-queue {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.note-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    max-width: 220px;
}

.note-chip:hover {
    border-color: var(--primary);
}

.note-chip.active {
    border-color: var(--primary);
    background: rgba(255, 36, 66, 0.06);
}

.note-chip.done {
    border-color: #52c41a;
}

.note-chip.error {
    border-color: var(--primary);
    background: rgba(255, 36, 66, 0.04);
}

.note-chip-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.note-chip-status {
    font-size: 14px;
    flex-shrink: 0;
}

/* Tag chips */
.original-note-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    margin-bottom: 8px;
}

.tag-chip {
    display: inline-block;
    padding: 2px 10px;
    background: rgba(255, 36, 66, 0.08);
    color: var(--primary);
    border-radius: 12px;
    font-size: 12px;
}

/* Per-image generation progress item */
.img-gen-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
}

.img-gen-item > img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

/* Generated content form (edit mode) */
#noteEditMode input[type="text"],
#noteEditMode textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: var(--card);
    font-family: inherit;
    resize: vertical;
}

#noteEditMode input:focus,
#noteEditMode textarea:focus {
    border-color: var(--primary);
}

/* Generated note preview (view mode) */
.gen-note-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 12px;
    line-height: 1.4;
    color: var(--text);
}

.gen-note-text {
    font-size: 15px;
    line-height: 1.7;
    color: #444;
    margin: 0 0 12px;
}

.gen-note-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Model selection radio cards */
.model-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
    min-width: 180px;
}

.model-option:hover {
    border-color: var(--primary);
}

.model-option input[type="radio"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.model-option input[type="radio"]:checked ~ div strong {
    color: var(--primary);
}

.model-option:has(input:checked) {
    border-color: var(--primary);
    background: rgba(255, 36, 66, 0.04);
}

/* History note cards */
.history-note-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    background: var(--card);
}

.history-note-card:last-child {
    margin-bottom: 0;
}

.history-note-header {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

/* Note detail comparison */
.note-compare-section {
    margin-bottom: 24px;
}

.note-compare-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 768px) {
    .note-compare-row { grid-template-columns: 1fr; }
}

.note-compare-col {
    padding: 20px;
    background: #fafafa;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.note-compare-label {
    display: inline-block;
    padding: 4px 12px;
    background: #666;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    margin-bottom: 12px;
}

.note-compare-label-gen {
    background: var(--primary);
}

.note-compare-images-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.note-compare-img-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 16px;
    padding: 16px;
    background: #fafafa;
    border-radius: 12px;
    border: 1px solid var(--border);
}

@media (max-width: 768px) {
    .note-compare-img-row { grid-template-columns: 1fr; }
}

.note-compare-img-col {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.note-compare-img-label {
    font-size: 12px;
    color: #999;
    margin-bottom: 8px;
    padding: 2px 10px;
    background: #eee;
    border-radius: 4px;
}

.note-compare-img-label.note-compare-label-gen {
    background: var(--primary);
    color: #fff;
}

.note-compare-img {
    width: 100%;
    max-height: 360px;
    object-fit: contain;
    border-radius: 8px;
    display: block;
}

.note-compare-gen-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.note-compare-gen-item {
    flex: 1;
    min-width: 120px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.note-compare-gen-item .note-compare-img {
    max-height: 360px;
    object-fit: contain;
}

.note-compare-img-placeholder {
    width: 100%;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border-radius: 8px;
    color: #bbb;
    font-size: 13px;
}
