/* ========== AutoPublish - 自动排版发布工具 ========== */

/* --- Reset & Base --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;600;700&display=swap');

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

:root {
    --bg-base: #08081a;
    --bg-primary: #0c0c20;
    --bg-secondary: #12122a;
    --bg-card: #181838;
    --bg-input: #0e0e24;
    --bg-hover: #1e1e40;

    --accent-red: #e94560;
    --accent-red-dim: rgba(233, 69, 96, 0.15);
    --accent-green: #07c160;
    --accent-green-dim: rgba(7, 193, 96, 0.15);
    --accent-blue: #4361ee;
    --accent-purple: #bb86fc;

    --text-primary: #e8e8f0;
    --text-secondary: #8892b0;
    --text-muted: #505878;
    --text-accent: #c0c8e0;

    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);

    --glass-bg: rgba(18, 18, 42, 0.85);
    --glass-border: rgba(255, 255, 255, 0.08);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);

    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
    height: 100%;
    font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* --- Layout --- */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(233, 69, 96, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(67, 97, 238, 0.06) 0%, transparent 50%),
        var(--bg-base);
}

/* --- Header --- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-red), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.logo-sub {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
}

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

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-wechat {
    background: var(--accent-green);
    color: #fff;
    box-shadow: 0 2px 12px rgba(7, 193, 96, 0.3);
}
.btn-wechat:hover {
    background: #06ad56;
    box-shadow: 0 4px 20px rgba(7, 193, 96, 0.4);
    transform: translateY(-1px);
}

.btn-xhs {
    background: var(--accent-red);
    color: #fff;
    box-shadow: 0 2px 12px rgba(233, 69, 96, 0.3);
}
.btn-xhs:hover {
    background: #d63654;
    box-shadow: 0 4px 20px rgba(233, 69, 96, 0.4);
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--accent-blue);
    color: #fff;
}
.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.btn .icon {
    font-size: 16px;
    line-height: 1;
}

/* --- Main Content --- */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* --- Editor Panel --- */
.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    min-width: 0;
}

.editor-header {
    position: relative;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.autofill-guard {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

.autofill-guard input {
    width: 1px;
    height: 1px;
    border: none;
}

.title-input {
    width: 100%;
    padding: 8px 0;
    background: transparent;
    border: none;
    font-family: inherit;
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    outline: none;
    letter-spacing: -0.3px;
}
.title-input::placeholder {
    color: var(--text-muted);
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.toolbar-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.toolbar-select {
    padding: 4px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    cursor: pointer;
    transition: var(--transition);
}
.toolbar-select:hover, .toolbar-select:focus {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
}

.cover-upload-area {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cover-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-input);
    border: 1px dashed var(--border-hover);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}
.cover-upload-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-blue);
    color: var(--text-primary);
}

.cover-preview {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    border: 1px solid var(--border);
    display: none;
}
.cover-preview.active {
    display: block;
}

.cover-file-input {
    display: none;
}

.editor-body {
    flex: 1;
    padding: 0;
    overflow: hidden;
}

.content-textarea {
    width: 100%;
    height: 100%;
    padding: 20px;
    background: transparent;
    border: none;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', 'Noto Sans SC', monospace;
    font-size: 14px;
    line-height: 1.8;
    color: var(--text-primary);
    resize: none;
    outline: none;
    tab-size: 4;
}
.content-textarea::placeholder {
    color: var(--text-muted);
}

/* --- Preview Panel --- */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.preview-tabs {
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.preview-tab {
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}
.preview-tab:hover {
    color: var(--text-secondary);
}
.preview-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-red);
}
.preview-tab.active[data-tab="wechat"] {
    border-bottom-color: var(--accent-green);
}

.preview-tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    height: 18px;
    margin-left: 6px;
    background: var(--bg-hover);
    border-radius: 9px;
    font-size: 10px;
    color: var(--text-muted);
}

.preview-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.preview-content {
    display: none;
}
.preview-content.active {
    display: block;
}

/* WeChat Preview Frame */
.wechat-frame {
    max-width: 420px;
    margin: 0 auto;
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.wechat-frame-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #ededed;
    border-bottom: 1px solid #ddd;
}

.wechat-frame-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #bbb;
}

.wechat-frame-title {
    font-size: 12px;
    color: #666;
    flex: 1;
    text-align: center;
}

.wechat-frame-body {
    padding: 0;
    min-height: 200px;
}

/* XHS Preview */
.xhs-preview-content {
    max-width: 420px;
    margin: 0 auto;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 20px;
    border: 1px solid var(--border);
}

.xhs-preview-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.xhs-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-red), #ff6b6b);
}

.xhs-username {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.xhs-text {
    font-size: 14px;
    line-height: 2;
    color: var(--text-accent);
    white-space: pre-wrap;
    word-break: break-word;
}

.xhs-char-count {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
    text-align: right;
}
.xhs-char-count.warning {
    color: var(--accent-red);
}

/* --- More Options (Collapsible) --- */
.more-options {
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.more-options-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 20px;
    background: transparent;
    border: none;
    font-family: inherit;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}
.more-options-toggle:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}
.more-options-toggle .chevron {
    transition: transform 0.2s;
    font-size: 10px;
}
.more-options-toggle.open .chevron {
    transform: rotate(90deg);
}

.more-options-body {
    display: none;
    padding: 0 20px 12px;
}
.more-options-body.open {
    display: block;
}

.option-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.option-label {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 60px;
    flex-shrink: 0;
}

.option-input {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
    transition: var(--transition);
}
.option-input:focus {
    border-color: var(--accent-blue);
}
.option-input::placeholder {
    color: var(--text-muted);
}

.btn-inline {
    padding-inline: 12px;
}

.reference-box {
    margin-top: 12px;
    padding: 14px;
    background: rgba(67, 97, 238, 0.08);
    border: 1px solid rgba(67, 97, 238, 0.18);
    border-radius: var(--radius-md);
}

.reference-box-header {
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.reference-box-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

#referenceHtmlInput {
    display: none;
}

.reference-file-name {
    flex: 1;
    min-height: 36px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: var(--bg-input);
    border: 1px dashed var(--border-hover);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
}

/* --- Footer --- */
.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 100;
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.footer-status {
    font-size: 12px;
    color: var(--text-muted);
}

.footer-actions {
    display: flex;
    gap: 10px;
}

/* --- Settings Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s;
}
.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal {
    width: 440px;
    max-width: 90vw;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s;
}
.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

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

.modal-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    border-radius: 50%;
    transition: var(--transition);
}
.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

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

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

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    transition: var(--transition);
}
.form-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    color: var(--text-primary);
    animation: toast-in 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 380px;
}

.toast.success {
    border-left: 3px solid var(--accent-green);
}
.toast.error {
    border-left: 3px solid var(--accent-red);
}
.toast.info {
    border-left: 3px solid var(--accent-blue);
}

.toast-icon {
    font-size: 16px;
    flex-shrink: 0;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(20px);
    }
}

/* --- Loading Spinner --- */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* --- Empty State --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
    gap: 8px;
}

.empty-state-icon {
    font-size: 48px;
    opacity: 0.3;
}

/* --- AI Buttons --- */
.btn-ai {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    color: #fff;
    box-shadow: 0 2px 12px rgba(124, 58, 237, 0.3);
}
.btn-ai:hover {
    background: linear-gradient(135deg, #6d28d9, #9333ea);
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4);
    transform: translateY(-1px);
}

.btn-ai-sm {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.btn-ai-sm:hover {
    background: linear-gradient(135deg, #6d28d9, #9333ea);
    transform: translateY(-1px);
    box-shadow: 0 2px 12px rgba(124, 58, 237, 0.4);
}

/* --- Loading Overlay --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(12px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    flex-direction: column;
    gap: 20px;
}
.loading-overlay.active {
    display: flex;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.spinner-large {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(124, 58, 237, 0.2);
    border-top-color: #a855f7;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    font-size: 15px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* --- Settings Sections --- */
.modal-wide {
    width: 520px;
}

.settings-section {
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 14px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 12px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-half {
    flex: 1;
}

.form-textarea {
    resize: vertical;
    min-height: 72px;
    line-height: 1.6;
}

.modal-body {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }
    .editor-panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
        flex: none;
        height: 45vh;
    }
    .preview-panel {
        flex: 1;
    }
    .footer-actions {
        flex-wrap: wrap;
    }
    .btn {
        font-size: 12px;
        padding: 6px 12px;
    }
    .form-row {
        flex-direction: column;
    }
    .reference-box-row {
        flex-direction: column;
        align-items: stretch;
    }
    .modal-wide {
        width: 90vw;
    }
    .footer {
        padding: 12px 16px;
        gap: 12px;
        flex-direction: column;
        align-items: stretch;
    }
    .footer-actions .btn {
        flex: 1;
        justify-content: center;
    }
}
