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

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.github-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--text-muted);
    transition: all 0.2s;
    border: 1px solid transparent;
}

.github-link:hover {
    color: var(--text);
    background: var(--bg);
    border-color: var(--border);
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn:hover {
    background: var(--bg);
    border-color: var(--text-muted);
}

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

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

.btn-danger {
    color: #dc2626;
    border-color: #fecaca;
}

.btn-danger:hover {
    background: #fef2f2;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* Main Layout */
.main-container {
    display: flex;
    height: calc(100vh - 73px);
    overflow: hidden;
}

/* Editor Panel */
.editor-panel {
    flex: 0 0 45%;
    max-width: 600px;
    background: var(--bg);
    overflow-y: auto;
    padding: 1.5rem;
    border-right: 1px solid var(--border);
}

.section {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.section-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title .icon {
    font-size: 1.25rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--text);
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-row .form-group {
    margin-bottom: 0;
}

/* Item Cards */
.item-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.item-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.item-card-title {
    font-weight: 500;
    font-size: 0.9375rem;
}

.item-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    padding: 0.25rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 0.25rem;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--border);
    color: var(--text);
}

.btn-icon.delete:hover {
    background: #fef2f2;
    color: #dc2626;
}

/* Add Button */
.btn-add {
    width: 100%;
    padding: 0.75rem;
    border: 2px dashed var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn-add:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

/* Custom Section Dialog */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.dialog-overlay.active {
    display: flex;
}

.dialog {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1.5rem;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.dialog-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* Tags */
.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    border-radius: 1rem;
    font-size: 0.8125rem;
    font-weight: 500;
}

.tag .remove {
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.tag .remove:hover {
    opacity: 1;
}

.tag-input {
    flex: 1;
    min-width: 120px;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 1rem;
    font-size: 0.8125rem;
}

/* Preview Panel */
.preview-panel {
    flex: 1;
    background: #e5e7eb;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.preview-container {
    width: 210mm;
    font-size: 11pt;
    line-height: 1.6;
    flex-shrink: 0;
}

.preview-page {
    background: white;
    width: 210mm;
    height: 297mm;
    padding: 20mm;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    position: relative;
}
.preview-page + .preview-page {
    box-shadow: var(--shadow-lg), 0 -0.5rem 1rem rgba(0,0,0,0.05);
}

.page-gap {
    width: 210mm;
    height: 1.5rem;
    background: #e5e7eb;
}

/* Resume Styles */
.resume-header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--primary);
}

.resume-name {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.resume-title {
    font-size: 1.125rem;
    color: var(--primary);
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.resume-contact {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.75rem 1.5rem;
    font-size: 0.9375rem;
    color: var(--text-muted);
}

.resume-contact span {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.resume-section-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.375rem;
    margin-bottom: 0.75rem;
    margin-top: 1.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.resume-item {
    margin-bottom: 0.875rem;
}

.resume-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
    margin-top: 0.75rem;
}

/* 第一个 header（紧跟 section-title 后）不需要额外间距 */
.resume-section-title + .resume-item-header {
    margin-top: 0;
}

.resume-item-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

/* 平铺后的段落样式 */
.resume-item-header + p {
    margin-top: 0.25rem;
}

/* 平铺后的通用列表样式（排除已定义样式的 .resume-list） */
.preview-page ul:not(.resume-list),
.preview-page ol:not(.resume-list) {
    list-style: none;
    padding-left: 1.25rem;
    margin: 0.25rem 0;
}

.preview-page ul:not(.resume-list) > li,
.preview-page ol:not(.resume-list) > li {
    position: relative;
    margin-bottom: 0.125rem;
}

.preview-page ul:not(.resume-list) > li::before,
.preview-page ol:not(.resume-list) > li::before {
    content: "\2022";
    position: absolute;
    left: -1rem;
    color: var(--primary);
}

.resume-item-title {
    font-weight: 600;
    font-size: 1rem;
}

.resume-item-subtitle {
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.resume-item-date {
    color: var(--text-muted);
    font-size: 0.875rem;
    white-space: nowrap;
}

.resume-item-description {
    color: var(--text);
    font-size: 0.9375rem;
    margin-top: 0.25rem;
    margin-bottom: 0.875rem;
    line-height: 1.6;
}
.resume-item-url {
    font-size: 0.875rem;
    color: var(--primary);
    margin-top: 0.25rem;
}
.resume-item-description ul,
.resume-item-description ol {
    padding-left: 1.25rem;
    margin: 0.25rem 0;
}
.resume-item-description li {
    margin-bottom: 0.125rem;
}

.resume-skills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.resume-skill {
    background: var(--bg);
    padding: 0.25rem 0.625rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
}

.resume-list {
    list-style: none;
    padding: 0;
}

.resume-list li {
    padding-left: 1rem;
    position: relative;
    margin-bottom: 0.375rem;
}

.resume-list li::before {
    content: "\2022";
    position: absolute;
    left: 0;
    color: var(--primary);
}

/* Checkbox */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

/* Responsive */
@media (max-width: 1024px) {
    .main-container {
        flex-direction: column;
    }

    .editor-panel {
        flex: none;
        max-width: none;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 50vh;
    }

    .preview-panel {
        padding: 1rem;
    }

    .preview-container {
        transform: scale(0.7);
        transform-origin: top center;
    }
}

/* Loading */
.loading {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
    z-index: 300;
}

.loading.active {
    display: flex;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Save indicator */
.save-indicator {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    box-shadow: var(--shadow);
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 100;
}

.save-indicator.show {
    opacity: 1;
}

/* ==================== AI Feature Styles ==================== */

/* AI optimize button */
.btn-ai {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border-color: #6366f1;
}
.btn-ai:hover {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    border-color: #4f46e5;
}

/* Settings dialog */
.ai-settings-dialog { max-width: 480px; }
.ai-key-row {
    display: flex;
    gap: 0.5rem;
}
.ai-key-row input { flex: 1; }

/* JD input dialog */
.ai-jd-dialog { max-width: 560px; }
.ai-jd-dialog textarea { min-height: 200px; }

/* Result dialog */
.ai-result-dialog {
    max-width: 720px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}
.ai-result-menu {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.btn-ai-option {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 0.5rem;
    cursor: pointer;
    text-align: left;
    font-size: 0.9375rem;
    transition: all 0.2s;
}
.btn-ai-option:hover {
    border-color: #6366f1;
    background: #f5f3ff;
}
.btn-ai-option > span:first-child {
    font-size: 1.75rem;
    flex-shrink: 0;
}
.ai-option-title {
    font-weight: 600;
    color: var(--text);
}
.ai-option-desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

/* Result summary */
.ai-result-summary {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

/* Result list */
.ai-result-list {
    overflow-y: auto;
    flex: 1;
    margin: 0;
    padding-right: 0.25rem;
}

/* Compare card */
.ai-compare-card {
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 0.875rem;
    transition: all 0.3s;
}
.ai-compare-card.ai-compare-accepted {
    border-left: 3px solid #16a34a;
    background: #f0fdf4;
}
.ai-compare-card.ai-compare-rejected {
    border-left: 3px solid var(--text-muted);
    opacity: 0.5;
}
.ai-compare-card.ai-compare-rejected .ai-compare-after {
    text-decoration: line-through;
}

/* Compare header */
.ai-compare-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.625rem;
}
.ai-compare-label {
    font-weight: 600;
    font-size: 0.875rem;
}
.ai-compare-actions {
    display: flex;
    gap: 0.375rem;
}

/* Compare body - side by side */
.ai-compare-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
.ai-compare-before {
    background: #f8fafc;
    border-radius: 0.375rem;
    padding: 0.625rem 0.75rem;
}
.ai-compare-after {
    background: #f0fdf4;
    border-radius: 0.375rem;
    padding: 0.625rem 0.75rem;
}
.ai-compare-side-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.375rem;
}
.ai-compare-content {
    font-size: 0.8125rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}
.ai-compare-content ul,
.ai-compare-content ol {
    padding-left: 1.25rem;
    margin: 0.25rem 0;
}
.ai-compare-content li {
    margin-bottom: 0.125rem;
}

/* Result actions */
#ai-result-actions {
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    margin-top: 0.75rem;
}

/* Responsive */
@media (max-width: 768px) {
    .ai-compare-body { grid-template-columns: 1fr; }
    .ai-result-dialog { max-width: 95%; }
}
