/* ========================================
   Write 写作站点 — 公共 CSS 变量和组件
   品牌色系与主站对齐，浅色主题适配写作场景
   ======================================== */

:root {
    --primary: #00a888;
    --primary-light: #00d4aa;
    --secondary: #6366f1;
    --accent: #f59e0b;
    --bg: #f0f2f5;
    --bg-white: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

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

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

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    padding: 0.5rem 1.1rem; border-radius: 8px; font-weight: 600; font-size: 0.85rem;
    text-decoration: none; border: none; cursor: pointer; transition: all 0.2s;
    white-space: nowrap;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,168,136,0.3); }
.btn-outline {
    background: transparent; color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-secondary { background: var(--text-secondary); color: #fff; }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.78rem; }
.btn-xs { padding: 0.2rem 0.55rem; font-size: 0.72rem; border-radius: 6px; }
.btn:disabled, .btn-disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* ===== Cards ===== */
.card {
    background: var(--bg-white); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow-sm);
    transition: all 0.2s;
}
.card:hover { border-color: var(--primary); box-shadow: var(--shadow); }

/* ===== Status Badges ===== */
.badge {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.15rem 0.6rem; border-radius: 50px; font-size: 0.72rem; font-weight: 600;
}
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-published { background: #d1fae5; color: #065f46; }
.badge-archived { background: #fee2e2; color: #991b1b; }
.badge-running { background: #e0e7ff; color: #3730a3; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-failed { background: #fee2e2; color: #991b1b; }

/* ===== Status badges (legacy .status-badge) ===== */
.status-badge {
    display: inline-block; padding: 0.15rem 0.6rem; border-radius: 50px; font-size: 0.72rem; font-weight: 600;
}
.status-badge.draft { background: #fef3c7; color: #92400e; }
.status-badge.published { background: #d1fae5; color: #065f46; }

/* ===== Modals ===== */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 10000;
    background: rgba(0,0,0,0.4); backdrop-filter: blur(2px);
    align-items: center; justify-content: center;
}
.modal-overlay.active, .modal-overlay.show { display: flex; }
.modal {
    background: var(--bg-white); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    padding: 1.75rem; max-width: 500px; width: 92%; max-height: 85vh; overflow-y: auto;
    animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal h3 { font-size: 1.05rem; color: var(--text); margin-bottom: 0.75rem; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal-close { background: none; border: none; font-size: 1.5rem; color: var(--text-muted); cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { margin-bottom: 1.25rem; color: var(--text-secondary); font-size: 0.9rem; line-height: 1.6; }
.modal-footer { display: flex; gap: 0.6rem; justify-content: flex-end; }

/* ===== Header ===== */
.header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    background: var(--bg-white); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.header-inner {
    max-width: 1400px; margin: 0 auto; padding: 10px 20px;
    display: flex; justify-content: space-between; align-items: center;
}
.header .logo { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.header .logo-text { font-size: 18px; font-weight: 700; color: var(--text); }
.header .logo-text span { color: var(--primary); }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* Sub Navigation */
.write-subnav {
    display: flex; align-items: center; gap: 0;
    max-width: 1400px; margin: 0 auto; padding: 0 20px;
    font-size: 0.82rem; overflow-x: auto;
}
.write-subnav a {
    color: var(--text-muted); text-decoration: none; padding: 0.5rem 1rem;
    border-bottom: 2px solid transparent; transition: all 0.15s; white-space: nowrap;
}
.write-subnav a:hover { color: var(--text); }
.write-subnav a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.write-subnav .btn { margin: 0.3rem 0; flex-shrink: 0; }

/* ===== User Menu ===== */
.user-info {
    display: none; position: relative; align-items: center; gap: 6px;
    background: var(--bg); padding: 5px 10px; border-radius: 8px; cursor: pointer;
    border: 1px solid var(--border);
}
.user-info.show { display: flex; }
.user-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600; color: #fff; overflow: hidden;
    flex-shrink: 0;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-nickname { color: var(--text); font-size: 13px; }
.dropdown-arrow { font-size: 9px; color: var(--text-muted); transition: transform 0.2s; }
.dropdown-arrow { font-size: 9px; color: var(--text-muted); transition: transform 0.2s; }
.user-info.open .dropdown-arrow { transform: rotate(180deg); }
.dropdown-menu {
    display: none; position: absolute; top: 100%; right: 0; margin-top: 4px;
    background: var(--bg-white); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: var(--shadow-lg); overflow: hidden; min-width: 120px; z-index: 100;
}
.user-info.open .dropdown-menu { display: block; }
.dropdown-item {
    display: block; width: 100%; padding: 8px 14px; background: none; border: none;
    color: var(--text); text-align: left; cursor: pointer; font-size: 13px;
}
.dropdown-item:hover { background: var(--bg); color: var(--primary); }

/* ===== Stats Bar ===== */
.stats-bar {
    display: flex; gap: 1rem; flex-wrap: wrap;
    padding: 1rem 1.5rem; background: var(--bg-white);
    border-bottom: 1px solid var(--border);
}
.stat-item {
    display: flex; flex-direction: column; align-items: center;
    padding: 0.4rem 1rem; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); min-width: 80px;
}
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.72rem; color: var(--text-muted); }

/* ===== Filter Bar ===== */
.filter-bar {
    display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap;
    padding: 0.7rem 1.5rem; background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
}
.filter-bar select, .filter-bar input {
    padding: 0.4rem 0.75rem; border: 1px solid var(--border);
    border-radius: 8px; background: var(--bg-white); color: var(--text);
    font-size: 0.82rem; font-family: inherit;
}
.filter-bar select:focus, .filter-bar input:focus {
    border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(0,168,136,0.1);
}
.filter-bar input::placeholder { color: var(--text-muted); }

/* ===== Article Grid ===== */
.article-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem; padding: 1rem 1.5rem;
}
.article-card {
    background: var(--bg-white); border: 1px solid var(--border);
    border-radius: var(--radius-lg); overflow: hidden; cursor: pointer;
    box-shadow: var(--shadow-sm); transition: all 0.2s;
}
.article-card:hover { border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-2px); }
.article-card .card-cover {
    width: 100%; height: 130px; object-fit: cover;
    background: linear-gradient(135deg, rgba(0,168,136,0.08), rgba(99,102,241,0.08));
}
.article-card .card-body { padding: 1rem; }
.article-card .card-title { font-size: 0.95rem; font-weight: 600; color: var(--text); margin-bottom: 0.3rem;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.article-card .card-summary { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.6rem;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.article-card .card-meta { display: flex; justify-content: space-between; align-items: center; font-size: 0.72rem; color: var(--text-muted); }

/* ===== Editor Layout ===== */
.editor-layout { display: flex; height: calc(100vh - 56px); }
.editor-panel { flex: 1; display: flex; flex-direction: column; border-right: 1px solid var(--border); overflow: hidden; }
.preview-panel { width: 420px; flex-shrink: 0; overflow-y: auto; padding: 1.25rem; background: #f5f5f0; }
.editor-toolbar { display: flex; gap: 0.5rem; padding: 0.5rem 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; background: var(--bg-white); }
.editor-textarea { flex: 1; padding: 1.25rem; background: var(--bg-white); border: none; color: var(--text);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; font-size: 0.88rem; line-height: 1.8; resize: none; }
.editor-textarea:focus { outline: none; }

/* ===== AI Generation Panel (dark, focused workspace) ===== */
.ai-panel-overlay { display: none; position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,0.25); }
.ai-panel-overlay.show { display: block; }
.ai-panel {
    position: fixed; top: 0; right: 0; width: 480px; height: 100vh; z-index: 10000;
    background: #111827; border-left: 1px solid rgba(255,255,255,0.08); color: #e2e8f0;
    display: flex; flex-direction: column; transform: translateX(100%); transition: transform 0.3s ease;
}
.ai-panel.open { transform: translateX(0); }
.ai-panel-header { display: flex; justify-content: space-between; align-items: center;
    padding: 0.9rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,0.08); }
.ai-panel-header h3 { font-size: 0.95rem; color: #f1f5f9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-panel-close { background: none; border: none; color: #94a3b8; font-size: 1.4rem; cursor: pointer; }
.ai-panel-close:hover { color: #f1f5f9; }
.ai-panel-body { flex: 1; overflow-y: auto; padding: 1.25rem; }
.ai-panel-body .stream-output { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.82rem;
    line-height: 1.7; color: #94a3b8; white-space: pre-wrap; }
.ai-panel-body .stream-stage { color: var(--primary-light); font-weight: 600; margin-top: 0.8rem; margin-bottom: 0.2rem; }
.ai-panel-footer { padding: 0.9rem 1.25rem; border-top: 1px solid rgba(255,255,255,0.08);
    display: flex; gap: 0.5rem; }
.ai-panel-footer .btn { flex: 1; }

/* ===== Iteration Items ===== */
.iteration-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.6rem 0.8rem; background: var(--bg); border: 1px solid var(--border-light);
    border-radius: 8px; cursor: pointer; transition: all 0.15s; margin-bottom: 0.4rem;
}
.iteration-item:hover { border-color: var(--primary); background: #f0fdf9; }
.iteration-info { flex: 1; min-width: 0; }
.iteration-type { font-size: 0.82rem; color: var(--text); font-weight: 500; }
.iteration-time { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.15rem; }
.iteration-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.iteration-status { font-size: 0.7rem; padding: 0.15rem 0.5rem; border-radius: 50px; font-weight: 600; }
.status-completed { background: #d1fae5; color: #065f46; }
.status-running { background: #e0e7ff; color: #3730a3; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-failed { background: #fee2e2; color: #991b1b; }

/* ===== Phone Preview Frame ===== */
.phone-frame {
    width: 375px; margin: 0 auto; background: #1a1a1a; border-radius: 36px;
    padding: 10px; box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.phone-status-bar {
    height: 40px; background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 28px 28px 0 0; display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 11px; font-weight: 500;
}
.preview-frame {
    width: 100%; height: 620px; border: none; border-radius: 0 0 26px 26px;
    overflow-y: auto; background: #fff;
}

/* ===== Subscribe Modal ===== */
.subscribe-modal .modal { max-width: 1000px; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .editor-layout { flex-direction: column; }
    .preview-panel { width: 100%; height: auto; min-height: 300px; }
    .ai-panel { width: 100%; }
}
@media (max-width: 768px) {
    .stats-bar { padding: 0.8rem 1rem; gap: 0.6rem; }
    .filter-bar { padding: 0.5rem 1rem; }
    .article-grid { padding: 0.8rem 1rem; grid-template-columns: 1fr; }
    .phone-frame { width: 100%; }
}

/* ===== Toast Notifications ===== */
.toast-container { position: fixed; top: 72px; right: 20px; z-index: 20000; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
    padding: 0.7rem 1.2rem; border-radius: 8px; font-size: 0.85rem; font-weight: 500;
    box-shadow: var(--shadow-lg); animation: toastIn 0.3s ease; max-width: 360px;
    display: flex; align-items: center; gap: 0.5rem;
}
.toast-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.toast-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.toast-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(40px); } }
.toast.removing { animation: toastOut 0.25s ease forwards; }

/* ===== Skeleton Loading ===== */
.skeleton {
    background: linear-gradient(90deg, var(--bg) 25%, #e2e8f0 50%, var(--bg) 75%);
    background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-card { height: 220px; border-radius: var(--radius-lg); }
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-text.short { width: 60%; }
.skeleton-cover { height: 130px; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }

/* ===== Empty State ===== */
.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 3rem 2rem; text-align: center; grid-column: 1 / -1;
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.6; }
.empty-state .empty-title { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 0.5rem; }
.empty-state .empty-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.5rem; max-width: 400px; }

/* ===== Save Indicator ===== */
.save-indicator {
    display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.75rem;
    padding: 0.2rem 0.6rem; border-radius: 6px; transition: all 0.2s;
}
.save-indicator.saved { color: var(--success); background: #f0fdf4; }
.save-indicator.saving { color: var(--warning); background: #fffbeb; }
.save-indicator.unsaved { color: var(--danger); background: #fef2f2; }
.save-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.saved .save-dot { background: var(--success); }
.saving .save-dot { background: var(--warning); animation: pulse 0.8s infinite; }
.unsaved .save-dot { background: var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ===== Quick Actions (hover reveal) ===== */
.article-card .card-actions {
    position: absolute; top: 8px; right: 8px; display: flex; gap: 4px;
    opacity: 0; transition: opacity 0.2s;
}
.article-card { position: relative; }
.article-card:hover .card-actions { opacity: 1; }
.card-action-btn {
    width: 28px; height: 28px; border-radius: 6px; border: none;
    background: var(--bg-white); box-shadow: var(--shadow); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; color: var(--text-secondary); transition: all 0.15s;
}
.card-action-btn:hover { color: var(--primary); background: #f0fdf9; }
.card-action-btn.danger:hover { color: var(--danger); background: #fef2f2; }

/* ===== Toolbar Separator ===== */
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }
