  :root {
    --ink: #1a1a1a;
    --paper: #f6f4f0;
    --cream: #eae7e0;
    --stone: #c8c3ba;
    --muted: #8a857e;
    --accent: #c8553d;
    --accent-soft: #c8553d18;
    --accent-hover: #b04530;
    --sidebar-bg: #252320;
    --sidebar-text: #b8b4ac;
    --sidebar-highlight: #f6f4f0;
    --field-bg: #2e2b27;
    --field-border: #3d3a35;
    --success: #5a9a6e;
    --danger: #c8553d;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-card: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
    --shadow-phone: 0 2px 8px rgba(0,0,0,.08), 0 16px 48px rgba(0,0,0,.10);
    --transition: 0.2s cubic-bezier(.4,0,.2,1);
    --font-display: 'Instrument Serif', 'Noto Serif SC', Georgia, serif;
    --font-body: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'DM Mono', 'SF Mono', Consolas, monospace;
    --font-cn: 'Noto Serif SC', 'PingFang SC', sans-serif;
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }
  html, body { height: 100%; overflow: hidden; }
  body {
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    display: flex;
  }

  /* ═══════════════════════════════════════════ */
  /* ARTICLE LIST PANEL (LEFT)                    */
  /* ═══════════════════════════════════════════ */
  .article-panel {
    width: 240px;
    min-width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
    transition: width 0.25s ease, min-width 0.25s ease;
    overflow: hidden;
  }
  .article-panel.collapsed {
    width: 44px;
    min-width: 44px;
  }
  .article-panel-header {
    padding: 16px 14px 12px;
    border-bottom: 1px solid var(--field-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
  }
  .article-panel.collapsed .article-panel-header {
    justify-content: center;
    padding: 16px 8px 12px;
  }
  .article-panel-title {
    font-family: var(--font-cn);
    font-size: 15px;
    font-weight: 600;
    color: var(--sidebar-highlight);
    white-space: nowrap;
  }
  .article-panel.collapsed .article-panel-title,
  .article-panel.collapsed .article-panel-new-btn {
    display: none;
  }
  .article-panel-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }
  .article-panel-new-btn,
  .article-panel-toggle-btn {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
  }
  .article-panel-new-btn:hover,
  .article-panel-toggle-btn:hover {
    background: var(--field-bg);
    color: var(--sidebar-highlight);
  }
  .article-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
  }
  .article-panel.collapsed .article-panel-body {
    display: none;
  }
  .article-panel-login-hint {
    padding: 20px 12px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
  }
  .article-panel-login-hint a {
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
  }
  .article-panel-login-hint a:hover { text-decoration: underline; }

  /* Article card in panel */
  .ap-card {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
    position: relative;
  }
  .ap-card:hover { background: var(--field-bg); }
  .ap-card.active { background: var(--accent); color: #fff; }
  .ap-card.active .ap-card-meta { color: rgba(255,255,255,.7); }
  .ap-card.active .ap-status { background: rgba(255,255,255,.2); color: #fff; }
  .ap-card-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--sidebar-highlight);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
  }
  .ap-card.active .ap-card-title { color: #fff; }
  .ap-card-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 10px;
    color: var(--muted);
  }
  .ap-status {
    display: inline-block;
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
  }
  .ap-status.draft { background: #fef3c730; color: #fbbf24; }
  .ap-status.published { background: #d1fae530; color: #34d399; }
  .ap-card-del {
    display: none;
    position: absolute;
    top: 8px;
    right: 6px;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    transition: var(--transition);
  }
  .ap-card:hover .ap-card-del { display: block; }
  .ap-card-del:hover { color: var(--danger); background: rgba(200,85,61,.15); }
  .ap-card.active .ap-card-del { color: rgba(255,255,255,.6); }
  .ap-card.active .ap-card-del:hover { color: #fff; background: rgba(255,255,255,.15); }
  .ap-empty {
    text-align: center;
    padding: 24px 8px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
  }

  /* ═══════════════════════════════════════════ */
  /* SETTINGS OVERLAY (RIGHT)                    */
  /* ═══════════════════════════════════════════ */
  .settings-gear-btn {
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--cream);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: var(--transition);
    flex-shrink: 0;
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
  }
  .settings-gear-btn:hover { border-color: var(--stone); color: var(--ink); }
  .settings-gear-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

  /* ═══ ARTICLE TITLE INPUT ═══ */
  .title-input-row {
    padding: 8px 24px;
    background: #fff;
    border-bottom: 1px solid var(--cream);
    flex-shrink: 0;
  }
  .title-input-row input {
    width: 100%;
    border: none;
    outline: none;
    font-family: var(--font-cn);
    font-size: 18px;
    font-weight: 600;
    color: var(--ink);
    background: transparent;
  }
  .title-input-row input::placeholder { color: var(--stone); font-weight: 400; }

  /* ═══ TITLE PROMPT MODAL ═══ */
  .title-prompt-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(0,0,0,.4);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
  }
  .title-prompt-overlay.show { display: flex; }
  .title-prompt {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: 0 16px 64px rgba(0,0,0,.2);
    padding: 32px;
    width: 400px;
    text-align: center;
  }
  .title-prompt h3 { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
  .title-prompt p { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
  .title-prompt input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--stone);
    border-radius: var(--radius-md);
    font-family: var(--font-cn);
    font-size: 15px;
    outline: none;
    transition: var(--transition);
  }
  .title-prompt input:focus { border-color: var(--accent); }
  .title-prompt-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    justify-content: flex-end;
  }
  .title-prompt-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
  }
  .title-prompt-cancel { background: var(--cream); color: var(--ink); }
  .title-prompt-cancel:hover { background: var(--stone); }
  .title-prompt-confirm { background: var(--accent); color: white; }
  .title-prompt-confirm:hover { background: var(--accent-hover); }

  /* ═══ PASTE UPLOAD INDICATOR ═══ */
  .upload-indicator {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--sidebar-bg);
    color: var(--sidebar-highlight);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    z-index: 200;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
  }
  .upload-indicator.show { display: block; }

  .settings-drawer {
    width: 0;
    min-width: 0;
    overflow: hidden;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    transition: width 0.3s cubic-bezier(.4,0,.2,1), min-width 0.3s cubic-bezier(.4,0,.2,1);
    flex-shrink: 0;
    border-left: 0px solid var(--field-border);
  }
  .settings-drawer.show {
    width: 320px;
    min-width: 320px;
    overflow-y: auto;
    border-left-width: 1px;
  }

  .settings-drawer-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--field-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .settings-drawer-title {
    font-family: var(--font-cn);
    font-size: 16px;
    font-weight: 600;
    color: var(--sidebar-highlight);
  }
  .settings-drawer-close {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 20px;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
  }
  .settings-drawer-close:hover { color: var(--sidebar-highlight); background: var(--field-bg); }

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

  .sidebar-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .sidebar-label .dot {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--accent);
    display: inline-block;
  }

  .field-group { margin-bottom: 12px; }
  .field-group:last-child { margin-bottom: 0; }
  .field-label {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 4px;
    font-weight: 500;
  }

  .settings-drawer select,
  .settings-drawer input[type="text"],
  .settings-drawer input[type="password"],
  .settings-drawer input[type="number"],
  .settings-drawer textarea {
    width: 100%;
    padding: 8px 10px;
    background: var(--field-bg);
    border: 1px solid var(--field-border);
    border-radius: var(--radius-sm);
    color: var(--sidebar-highlight);
    font-family: var(--font-body);
    font-size: 12px;
    outline: none;
    transition: border-color var(--transition);
    appearance: none;
    -webkit-appearance: none;
  }
  .settings-drawer select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238a857e' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 6l3.5 4 3.5-4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
  }
  .settings-drawer select option { background: var(--sidebar-bg); color: var(--sidebar-text); }
  .settings-drawer select:focus,
  .settings-drawer input:focus { border-color: var(--accent); }

  .settings-drawer input::placeholder { color: #5a5752; }
  .settings-drawer textarea::placeholder { color: #5a5752; }

  /* Recommend sort toggle buttons */
  .rec-sort-btn {
    flex: 1;
    padding: 6px 0;
    background: var(--field-bg);
    border: 1px solid var(--field-border);
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
  }
  .rec-sort-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }
  .rec-sort-btn:hover:not(.active) {
    border-color: var(--muted);
    color: var(--sidebar-highlight);
  }

  /* Recommend advanced toggle */
  .rec-advanced-toggle {
    display: flex; align-items: center; gap: 4px;
    background: none; border: none; padding: 6px 0; margin-top: 4px;
    font-size: 11px; color: var(--muted); cursor: pointer;
    font-family: var(--font-body); transition: color var(--transition);
  }
  .rec-advanced-toggle:hover { color: var(--accent); }
  .rec-advanced-toggle.open { color: var(--accent); }
  .rec-advanced-toggle .rec-advanced-arrow {
    transition: transform .2s ease;
  }
  .rec-advanced-toggle.open .rec-advanced-arrow {
    transform: rotate(90deg);
  }

  /* Spinner animation */
  @keyframes spin { to { transform: rotate(360deg); } }

  /* Recommend style picker modal */
  .rec-style-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.55);
    z-index: 10000; display: flex; align-items: center; justify-content: center;
  }
  .rec-style-modal {
    background: #fff; border-radius: 16px;
    width: 92%; max-width: 720px; overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: slideUpModal .3s cubic-bezier(.16,1,.3,1);
  }
  .rec-style-modal-header {
    padding: 16px 20px; border-bottom: 1px solid var(--cream);
    display: flex; align-items: center; justify-content: space-between;
  }
  .rec-style-modal-header span { font-size: 15px; font-weight: 600; color: var(--ink); }
  .rec-style-modal-header button { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
  .rec-style-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 12px; padding: 16px; max-height: 65vh; overflow-y: auto;
  }
  .rec-style-card {
    background: #fff; border: 2px solid var(--cream);
    border-radius: 10px; cursor: pointer; transition: all .15s ease;
    overflow: hidden;
  }
  .rec-style-card:hover { border-color: var(--stone); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
  .rec-style-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(200,85,61,.15); }
  .rec-style-card-preview {
    height: 160px; overflow: hidden; background: #fafaf8;
    position: relative;
  }
  .rec-style-card-preview > div {
    transform: scale(0.5); transform-origin: top left;
    width: 200%; pointer-events: none;
  }
  .rec-style-card-info {
    padding: 8px 10px; border-top: 1px solid #f0ede8;
    display: flex; align-items: center; gap: 6px;
  }
  .rec-style-card-icon { font-size: 14px; }
  .rec-style-card-name { font-size: 12px; font-weight: 600; color: var(--ink); }
  @media (max-width: 600px) {
    .rec-style-grid { grid-template-columns: repeat(2, 1fr); }
  }

  /* Article picker modal (dark theme) */
  .article-picker-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.55);
    z-index: 10000; display: flex; align-items: center; justify-content: center;
  }
  .article-picker-modal {
    background: var(--sidebar-bg); border-radius: 12px;
    width: 90%; max-width: 520px; max-height: 70vh;
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  }
  .article-picker-header {
    padding: 14px 20px; border-bottom: 1px solid var(--field-border);
    display: flex; align-items: center; justify-content: space-between;
  }
  .article-picker-header span { font-size: 14px; font-weight: 600; color: var(--sidebar-highlight); }
  .article-picker-header button { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
  .article-picker-list { flex: 1; overflow-y: auto; padding: 4px 0; }
  .article-picker-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px; cursor: pointer; transition: background var(--transition);
    color: var(--sidebar-text); font-size: 13px;
  }
  .article-picker-item:hover { background: var(--field-bg); }
  .article-picker-item input[type="checkbox"] {
    flex-shrink: 0; width: 16px; height: 16px; accent-color: var(--accent);
  }
  .article-picker-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .article-picker-footer {
    padding: 12px 20px; border-top: 1px solid var(--field-border); text-align: right;
  }
  .article-picker-footer button {
    padding: 7px 24px; background: var(--accent); color: #fff;
    border: none; border-radius: 6px; font-size: 13px; cursor: pointer;
  }

  /* Device chips */
  .device-chips {
    display: flex; flex-wrap: wrap; gap: 4px;
  }
  .device-chip {
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 500;
    border-radius: 20px;
    border: 1px solid var(--field-border);
    background: transparent;
    color: var(--sidebar-text);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    font-family: var(--font-body);
  }
  .device-chip:hover { border-color: var(--muted); color: var(--sidebar-highlight); }
  .device-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }

  /* Toggle */
  .toggle-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 0;
  }
  .toggle-row .toggle-label { font-size: 12px; color: var(--sidebar-text); }
  .toggle-switch {
    position: relative; width: 36px; height: 20px;
    background: var(--field-border);
    border-radius: 10px;
    cursor: pointer;
    transition: background var(--transition);
  }
  .toggle-switch.on { background: var(--accent); }
  .toggle-switch .toggle-knob {
    position: absolute; top: 2px; left: 2px;
    width: 16px; height: 16px;
    background: #fff; border-radius: 50%;
    transition: transform var(--transition);
  }
  .toggle-switch.on .toggle-knob { transform: translateX(16px); }

  /* Save as template button */
  #btn-save-as-tpl:hover { border-color: var(--accent); color: #fff; background: var(--accent); }

  /* Sidebar buttons */
  .sidebar-btn {
    width: 100%; padding: 9px 12px;
    border: none; border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 12px; font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex; align-items: center; justify-content: center; gap: 6px;
  }
  .sidebar-btn-primary {
    background: var(--accent);
    color: #fff;
  }
  .sidebar-btn-primary:hover { background: var(--accent-hover); }
  .sidebar-btn-secondary {
    background: var(--field-bg);
    color: var(--sidebar-text);
    border: 1px solid var(--field-border);
  }
  .sidebar-btn-secondary:hover { border-color: var(--muted); color: var(--sidebar-highlight); }

  .btn-group { display: flex; gap: 6px; }
  .btn-group .sidebar-btn { flex: 1; }

  /* Login status */
  /* ═══ USER AUTH (action bar) ═══ */
  .user-auth-area { position: relative; }
  .user-pill {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 10px 4px 4px; border-radius: 99px;
    background: var(--cream); cursor: pointer;
    transition: var(--transition); font-size: 12px; font-weight: 500;
  }
  .user-pill:hover { background: var(--stone); }
  .user-avatar {
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--accent); color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
  }
  .user-dropdown {
    display: none; position: absolute; top: calc(100% + 6px); right: 0;
    background: white; border-radius: var(--radius-md);
    box-shadow: 0 4px 24px rgba(0,0,0,.12), 0 1px 4px rgba(0,0,0,.08);
    min-width: 200px; z-index: 50; overflow: hidden;
  }
  .user-dropdown.show { display: block; }
  .user-dropdown-header {
    padding: 12px 16px; border-bottom: 1px solid #eee;
    font-size: 11px; color: var(--muted);
    font-family: var(--font-mono);
  }
  .user-dropdown-item {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 16px; font-size: 13px; color: var(--ink);
    text-decoration: none; transition: var(--transition);
  }
  .user-dropdown-item:hover { background: var(--paper); }
  .user-dropdown-danger { color: var(--danger); }
  .user-dropdown-danger:hover { background: #fef2f2; }
  .user-dropdown-divider { height: 1px; background: #eee; }

  /* ═══ PUBLISH DRAWER ═══ */
  .publish-drawer {
    position: fixed; right: 0; top: 0; bottom: 0;
    width: 0; overflow: hidden;
    background: #fff;
    color: var(--ink);
    z-index: 9999;
    box-shadow: -4px 0 24px rgba(0,0,0,.12);
    transition: width 0.3s cubic-bezier(.4,0,.2,1);
    display: flex; flex-direction: column;
  }
  .publish-drawer.show {
    width: 380px;
  }
  .publish-drawer-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid #eee;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
  }
  .publish-drawer-title {
    font-family: var(--font-cn);
    font-size: 16px; font-weight: 700; color: var(--ink);
  }
  .publish-drawer-close {
    background: none; border: none; color: var(--muted);
    cursor: pointer; font-size: 22px; padding: 2px 8px;
    border-radius: var(--radius-sm); transition: var(--transition);
  }
  .publish-drawer-close:hover { color: var(--ink); background: #f5f5f5; }
  .publish-drawer-body {
    flex: 1; overflow-y: auto; padding: 0;
  }
  .publish-section {
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
  }
  .publish-section:last-child { border-bottom: none; }
  .publish-section-action { padding: 20px; }
  .publish-label {
    font-size: 13px; font-weight: 600; color: var(--ink);
    margin-bottom: 8px;
  }
  .publish-hint {
    font-weight: 400; font-size: 11px; color: var(--muted);
  }
  .publish-drawer input[type="text"],
  .publish-drawer textarea {
    width: 100%; padding: 9px 12px;
    background: #f8f8f8; border: 1px solid #e5e5e5;
    border-radius: 6px; font-size: 13px; color: var(--ink);
    font-family: var(--font-body);
    transition: border-color .15s ease;
  }
  .publish-drawer input:focus,
  .publish-drawer textarea:focus {
    outline: none; border-color: var(--accent);
    background: #fff;
  }
  .publish-drawer textarea { resize: vertical; line-height: 1.5; }
  .publish-cover-preview {
    width: 100%; height: 140px;
    background: #f8f8f8; border: 1px solid #e5e5e5;
    border-radius: 8px; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 10px; position: relative;
  }
  .publish-cover-preview img {
    width: 100%; height: 100%; object-fit: cover;
  }
  .publish-cover-empty {
    font-size: 12px; color: #bbb;
  }
  .publish-cover-actions {
    display: flex; gap: 6px; align-items: center;
  }
  .publish-cover-actions input {
    flex: 1; min-width: 0;
  }
  .publish-upload-btn {
    flex-shrink: 0; padding: 8px 14px;
    background: #f0f0f0; border: 1px solid #ddd;
    border-radius: 6px; font-size: 12px; font-weight: 600;
    color: #555; cursor: pointer; transition: all .15s ease;
    white-space: nowrap;
  }
  .publish-upload-btn:hover { background: #e8e8e8; color: var(--ink); }
  .publish-cover-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .publish-cover-grid img {
    width: 100%; aspect-ratio: 16/9; object-fit: cover;
    border-radius: 4px; cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .15s ease, transform .15s ease;
  }
  .publish-cover-grid img:hover {
    border-color: var(--accent); transform: scale(1.03);
  }
  .publish-cover-grid img.selected {
    border-color: #16a34a;
    box-shadow: 0 0 0 1px #16a34a;
  }
  .publish-digest-count {
    text-align: right; font-size: 11px; color: var(--muted);
    margin-top: 4px;
  }
  .publish-confirm-btn {
    width: 100%; padding: 13px;
    background: #16a34a; color: #fff; border: none;
    border-radius: 8px; font-size: 14px; font-weight: 700;
    cursor: pointer; transition: all .15s ease;
    display: flex; align-items: center; justify-content: center; gap: 6px;
  }
  .publish-confirm-btn:hover { background: #15803d; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(22,163,74,.3); }
  .publish-confirm-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; box-shadow: none; }
  .publish-drawer-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.3);
    z-index: 9998; display: none;
  }
  .publish-drawer-overlay.show { display: block; }

  /* ═══ UPGRADE MODAL ═══ */
  .upgrade-overlay {
    position: fixed; inset: 0; z-index: 10001;
    background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    animation: fadeIn .2s ease-out;
  }
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  .upgrade-modal {
    background: #fff; border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    width: 380px; max-width: 92vw;
    text-align: center; overflow: hidden;
    animation: slideUpModal .3s cubic-bezier(.16,1,.3,1);
  }
  @keyframes slideUpModal { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
  .upgrade-modal-header {
    padding: 28px 24px 16px;
  }
  .upgrade-modal-icon { font-size: 40px; margin-bottom: 12px; }
  .upgrade-modal-title { font-size: 18px; font-weight: 700; color: #1a1a1a; margin-bottom: 8px; }
  .upgrade-modal-desc { font-size: 13px; color: #666; line-height: 1.6; }
  .upgrade-modal-actions {
    padding: 16px 24px 24px;
    display: flex; gap: 10px;
  }
  .upgrade-modal-actions button {
    flex: 1; padding: 12px; border-radius: 10px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: all .15s ease;
  }
  .upgrade-btn-secondary {
    background: #f5f5f5; border: 1px solid #e0e0e0; color: #666;
  }
  .upgrade-btn-secondary:hover { background: #eee; }
  .upgrade-btn-primary {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    border: none; color: #fff;
  }
  .upgrade-btn-primary:hover { opacity: .9; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(245,158,11,.3); }

  .login-status {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 10px;
    background: var(--field-bg);
    border-radius: var(--radius-sm);
    font-size: 11px;
  }
  .login-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .login-dot.offline { background: var(--muted); }
  .login-dot.online { background: var(--success); }
  .login-hint { color: var(--muted); font-size: 10px; margin-top: 6px; }

  /* Template editor */
  .tpl-editor-area { display: none; margin-top: 10px; } /* legacy */
  .tpl-editor-area.show { display: block; }
  .tpl-editor-area textarea {
    width: 100%; height: 72px;
    padding: 8px; font-family: var(--font-mono); font-size: 11px;
    background: var(--field-bg); border: 1px solid var(--field-border);
    border-radius: var(--radius-sm); color: var(--sidebar-highlight);
    resize: vertical; outline: none; line-height: 1.5;
  }
  .tpl-editor-area textarea:focus { border-color: var(--accent); }
  .tpl-editor-area .tpl-name-row {
    display: flex; gap: 6px; margin-top: 6px;
  }
  .tpl-editor-area .tpl-name-row input {
    flex: 1;
  }
  .tpl-mini-btn {
    padding: 6px 10px; border: none; border-radius: var(--radius-sm);
    font-family: var(--font-body); font-size: 10px; font-weight: 600;
    cursor: pointer; transition: all var(--transition); white-space: nowrap;
  }
  .tpl-mini-btn.save { background: var(--accent); color: #fff; }
  .tpl-mini-btn.save:hover { background: var(--accent-hover); }
  .tpl-mini-btn.del { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
  .tpl-mini-btn.del:hover { background: var(--danger); color: #fff; }

  /* ═══════════════════════════════════════════ */
  /* MAIN CONTENT                                */
  /* ═══════════════════════════════════════════ */
  .content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

  /* Top action bar */
  .action-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px;
    background: var(--paper);
    border-bottom: 1px solid var(--cream);
    flex-shrink: 0;
  }
  .action-bar-left {
    display: flex; align-items: center; gap: 16px;
  }
  .tab-switcher {
    display: flex; background: var(--cream); border-radius: 6px; padding: 3px;
  }
  .tab-btn {
    padding: 6px 14px; border: none; border-radius: 4px;
    font-family: var(--font-body); font-size: 12px; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
    background: transparent; color: var(--muted);
  }
  .tab-btn.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.06); }

  .render-status {
    font-size: 11px; color: var(--muted); font-family: var(--font-mono);
    display: flex; align-items: center; gap: 6px;
  }
  .render-dot {
    width: 6px; height: 6px; border-radius: 50%; background: var(--success);
    transition: background var(--transition);
  }
  .render-dot.pending { background: var(--stone); animation: pulse-dot 1s infinite; }
  @keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

  .save-status {
    font-size: 11px; color: var(--muted); font-family: var(--font-mono);
    display: flex; align-items: center; gap: 5px;
    min-width: 60px;
  }
  .save-status.saving { color: var(--accent); }
  .save-status.saved { color: var(--success); }

  .action-bar-right { display: flex; align-items: center; gap: 8px; }
  .action-btn {
    padding: 7px 14px; border: none; border-radius: var(--radius-sm);
    font-family: var(--font-body); font-size: 12px; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
    display: flex; align-items: center; gap: 5px;
  }
  .action-btn-primary {
    background: var(--accent); color: #fff;
  }
  .action-btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
  .action-btn-primary.copied { background: var(--success); }
  .action-btn-publish {
    background: #16a34a; color: #fff;
  }
  .action-btn-publish:hover { background: #15803d; transform: translateY(-1px); }
  .action-btn-publish:disabled { opacity: .6; cursor: not-allowed; transform: none; }
  .action-btn-ghost {
    background: transparent; color: var(--muted);
    border: 1px solid var(--cream);
  }
  .action-btn-ghost:hover { border-color: var(--stone); color: var(--ink); }

  /* ═══════════════════════════════════════════ */
  /* SPLIT PANES                                 */
  /* ═══════════════════════════════════════════ */
  .workspace { display: flex; flex: 1; overflow: hidden; }

  .editor-pane {
    flex: 1 1 50%; display: flex; flex-direction: column;
    background: #fff;
    border-right: 1px solid var(--cream);
    min-width: 0;
  }
  .pane-header {
    padding: 10px 20px;
    font-size: 10px; font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    background: #fafaf8;
    border-bottom: 1px solid var(--cream);
    display: flex; align-items: center; gap: 6px;
    flex-shrink: 0;
  }
  .pane-header-icon {
    width: 14px; height: 14px;
    display: flex; align-items: center; justify-content: center;
    opacity: 0.5;
  }
  #editor {
    flex: 1; padding: 20px 24px;
    font-family: var(--font-mono);
    font-size: 13px; line-height: 1.7;
    border: none; outline: none; resize: none;
    color: var(--ink); background: #fff;
    tab-size: 2;
  }
  #editor::placeholder { color: var(--stone); }

  /* Preview pane */
  .preview-pane {
    flex: 1 1 50%; display: flex; flex-direction: column;
    background: var(--cream);
    min-width: 0;
  }
  .preview-scroll {
    flex: 1; overflow-y: auto; padding: 28px;
    display: flex; justify-content: center;
  }

  /* ═══════════════════════════════════════════ */
  /* DEVICE SHELL                                */
  /* ═══════════════════════════════════════════ */
  .device-shell {
    align-self: flex-start;
    transition: all 0.35s cubic-bezier(.4,0,.2,1);
    position: relative;
  }

  /* The outer bezel */
  .device-bezel {
    position: relative;
    border-radius: 48px;
    padding: 14px;
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    box-shadow:
      0 2px 8px rgba(0,0,0,.15),
      0 16px 48px rgba(0,0,0,.18),
      inset 0 1px 0 rgba(255,255,255,.08),
      inset 0 -1px 0 rgba(0,0,0,.3);
    transition: all 0.35s cubic-bezier(.4,0,.2,1);
  }

  /* Side buttons (iPhone) */
  .device-bezel::before {
    content: '';
    position: absolute;
    right: -3px; top: 120px;
    width: 3px; height: 50px;
    background: linear-gradient(180deg, #333, #222, #333);
    border-radius: 0 2px 2px 0;
  }
  .device-bezel::after {
    content: '';
    position: absolute;
    left: -3px; top: 100px;
    width: 3px; height: 30px;
    background: linear-gradient(180deg, #333, #222, #333);
    border-radius: 2px 0 0 2px;
    box-shadow: 0 40px 0 #282828, 0 70px 0 #282828;
  }

  /* The screen area */
  .device-screen {
    position: relative;
    border-radius: 36px;
    overflow: hidden;
    background: #fff;
  }

  /* Status bar */
  .device-statusbar {
    height: 54px;
    background: #fff;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px 24px 0;
    position: relative;
    z-index: 2;
  }
  .statusbar-time {
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif;
    line-height: 1;
  }
  .statusbar-icons {
    display: flex;
    align-items: center;
    gap: 5px;
  }
  .statusbar-icons svg { display: block; }

  /* Dynamic Island */
  .dynamic-island {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 34px;
    background: #000;
    border-radius: 20px;
    z-index: 5;
  }

  /* Home indicator */
  .device-home-indicator {
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
  }
  .home-indicator-bar {
    width: 134px;
    height: 5px;
    background: #1a1a1a;
    border-radius: 3px;
    opacity: 0.2;
  }

  /* Phone body (content area) */
  .phone-body {
    padding: 0 16px 8px;
    overflow-y: auto;
  }
  .phone-body > section { max-width: 100% !important; }
  .phone-body img { max-width: 100%; height: auto; }

  /* ── Device variants ── */

  /* iPhone SE — smaller radius, thicker bezel, home button */
  .device-shell[data-device="iphone-se"] .device-bezel {
    border-radius: 42px;
    padding: 16px;
  }
  .device-shell[data-device="iphone-se"] .device-screen {
    border-radius: 0;
  }
  .device-shell[data-device="iphone-se"] .dynamic-island { display: none; }
  .device-shell[data-device="iphone-se"] .device-statusbar { height: 24px; padding-top: 4px; }
  .device-shell[data-device="iphone-se"] .device-home-indicator {
    height: 60px;
  }
  .device-shell[data-device="iphone-se"] .home-indicator-bar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: transparent;
    border: 3px solid rgba(0,0,0,.1);
    opacity: 1;
  }

  /* iPhone 14 — Dynamic Island */
  .device-shell[data-device="iphone-14"] .dynamic-island { width: 120px; height: 34px; }

  /* iPhone 15 Pro — Titanium frame, thinner bezels */
  .device-shell[data-device="iphone-15-pro"] .device-bezel {
    background: linear-gradient(145deg, #4a4843, #3a3835, #2a2825);
    padding: 10px;
    border-radius: 50px;
    box-shadow:
      0 2px 8px rgba(0,0,0,.15),
      0 16px 48px rgba(0,0,0,.18),
      inset 0 1px 0 rgba(255,255,255,.12),
      inset 0 -1px 0 rgba(0,0,0,.3);
  }
  .device-shell[data-device="iphone-15-pro"] .device-bezel::before,
  .device-shell[data-device="iphone-15-pro"] .device-bezel::after {
    background: linear-gradient(180deg, #4a4843, #3a3835, #4a4843);
  }
  .device-shell[data-device="iphone-15-pro"] .device-bezel::after {
    box-shadow: 0 40px 0 #3a3835, 0 70px 0 #3a3835;
  }
  .device-shell[data-device="iphone-15-pro"] .device-screen {
    border-radius: 42px;
  }
  .device-shell[data-device="iphone-15-pro"] .dynamic-island { width: 120px; height: 34px; }

  /* iPhone 15 Pro Max — same as Pro */
  .device-shell[data-device="iphone-15-pm"] .device-bezel {
    background: linear-gradient(145deg, #4a4843, #3a3835, #2a2825);
    padding: 10px;
    border-radius: 52px;
    box-shadow:
      0 2px 8px rgba(0,0,0,.15),
      0 16px 48px rgba(0,0,0,.18),
      inset 0 1px 0 rgba(255,255,255,.12),
      inset 0 -1px 0 rgba(0,0,0,.3);
  }
  .device-shell[data-device="iphone-15-pm"] .device-bezel::before,
  .device-shell[data-device="iphone-15-pm"] .device-bezel::after {
    background: linear-gradient(180deg, #4a4843, #3a3835, #4a4843);
  }
  .device-shell[data-device="iphone-15-pm"] .device-bezel::after {
    box-shadow: 0 40px 0 #3a3835, 0 70px 0 #3a3835;
  }
  .device-shell[data-device="iphone-15-pm"] .device-screen {
    border-radius: 44px;
  }
  .device-shell[data-device="iphone-15-pm"] .dynamic-island { width: 120px; height: 34px; }

  /* Pixel 7 — Camera bar, rounder corners */
  .device-shell[data-device="pixel"] .device-bezel {
    background: linear-gradient(145deg, #e8e5e0, #d8d5d0, #c8c5c0);
    border-radius: 38px;
    padding: 10px;
    box-shadow:
      0 2px 8px rgba(0,0,0,.1),
      0 16px 48px rgba(0,0,0,.12),
      inset 0 1px 0 rgba(255,255,255,.5),
      inset 0 -1px 0 rgba(0,0,0,.1);
  }
  .device-shell[data-device="pixel"] .device-bezel::before { display: none; }
  .device-shell[data-device="pixel"] .device-bezel::after { display: none; }
  .device-shell[data-device="pixel"] .device-screen {
    border-radius: 30px;
  }
  .device-shell[data-device="pixel"] .dynamic-island {
    width: 10px; height: 10px;
    border-radius: 50%;
    top: 14px;
  }
  .device-shell[data-device="pixel"] .device-statusbar { height: 36px; padding-top: 8px; }

  /* iPad Mini — no buttons, thin bezel, no island */
  .device-shell[data-device="ipad"] .device-bezel {
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border-radius: 24px;
    padding: 14px;
  }
  .device-shell[data-device="ipad"] .device-bezel::before { display: none; }
  .device-shell[data-device="ipad"] .device-bezel::after { display: none; }
  .device-shell[data-device="ipad"] .device-screen {
    border-radius: 12px;
  }
  .device-shell[data-device="ipad"] .dynamic-island { display: none; }
  .device-shell[data-device="ipad"] .device-statusbar { height: 28px; padding-top: 6px; }
  .device-shell[data-device="ipad"] .device-home-indicator { height: 20px; }
  .device-shell[data-device="ipad"] .home-indicator-bar { width: 100px; }

  /* Full Width — no device shell */
  .device-shell[data-device="full"] .device-bezel {
    background: none;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  }
  .device-shell[data-device="full"] .device-bezel::before,
  .device-shell[data-device="full"] .device-bezel::after { display: none; }
  .device-shell[data-device="full"] .device-screen { border-radius: 8px; }
  .device-shell[data-device="full"] .device-statusbar { display: none; }
  .device-shell[data-device="full"] .dynamic-island { display: none; }
  .device-shell[data-device="full"] .device-home-indicator { display: none; }
  .device-shell[data-device="full"] .phone-body { padding: 16px; }

  /* ═══════════════════════════════════════════ */
  /* DIVIDER                                     */
  /* ═══════════════════════════════════════════ */
  .divider {
    width: 6px; cursor: col-resize;
    background: transparent; flex-shrink: 0;
    position: relative;
    transition: background var(--transition);
  }
  .divider::after {
    content: ''; position: absolute;
    top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 2px; height: 32px;
    background: var(--stone); border-radius: 1px;
    opacity: 0; transition: opacity var(--transition);
  }
  .divider:hover::after, .divider.dragging::after { opacity: 1; }
  .divider:hover { background: var(--accent-soft); }
  .divider.dragging { background: var(--accent-soft); }

  /* ═══════════════════════════════════════════ */
  /* STATUS BAR                                  */
  /* ═══════════════════════════════════════════ */
  .status-bar {
    padding: 6px 24px;
    font-size: 10px; font-family: var(--font-mono);
    color: var(--muted); background: #fafaf8;
    border-top: 1px solid var(--cream);
    display: flex; gap: 24px; flex-shrink: 0;
    letter-spacing: 0.02em;
  }

  /* ═══════════════════════════════════════════ */
  /* TOAST                                       */
  /* ═══════════════════════════════════════════ */
  .toast {
    position: fixed; bottom: 48px; left: 50%; transform: translateX(-50%) translateY(8px);
    background: var(--sidebar-bg); color: var(--sidebar-highlight);
    padding: 10px 24px; border-radius: 24px;
    font-size: 12px; font-weight: 500;
    opacity: 0; transition: all 0.3s cubic-bezier(.4,0,.2,1);
    pointer-events: none; z-index: 200;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

  /* ═══════════════════════════════════════════ */
  /* RENDERING STATE                             */
  /* ═══════════════════════════════════════════ */
  .rendering .device-screen { opacity: 0.4; transition: opacity 0.15s; }
  .rendering .render-dot { background: var(--accent); animation: pulse-dot 0.6s infinite; }

  /* ═══════════════════════════════════════════ */
  /* SCROLLBAR                                   */
  /* ═══════════════════════════════════════════ */
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--stone); border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--muted); }
  .sidebar::-webkit-scrollbar-thumb { background: var(--field-border); }
  .sidebar::-webkit-scrollbar-thumb:hover { background: var(--muted); }

  /* ═══════════════════════════════════════════ */
  /* RESPONSIVE                                  */
  /* ═══════════════════════════════════════════ */
  /* ═══════════════════════════════════════════ */
  /* THEME PICKER BUTTON                        */
  /* ═══════════════════════════════════════════ */
  .theme-picker-btn {
    width: 100%; padding: 8px 10px;
    background: var(--field-bg);
    border: 1px solid var(--field-border);
    border-radius: var(--radius-sm);
    color: var(--sidebar-highlight);
    font-family: var(--font-body); font-size: 12px;
    cursor: pointer; transition: border-color var(--transition);
    display: flex; align-items: center; justify-content: space-between;
    text-align: left;
  }
  .theme-picker-btn:hover { border-color: var(--accent); }
  .theme-picker-btn .theme-picker-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .theme-picker-btn .theme-picker-icon {
    font-size: 10px; color: var(--muted); flex-shrink: 0; margin-left: 6px;
    transition: transform var(--transition);
  }

  /* ═══════════════════════════════════════════ */
  /* THEME MODAL                                */
  /* ═══════════════════════════════════════════ */
  .theme-modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 100;
    background: rgba(0,0,0,.5); backdrop-filter: blur(6px);
    align-items: center; justify-content: center;
    padding: 24px;
  }
  .theme-modal-overlay.show { display: flex; }

  /* Picker mode: no overlay bg, modal fills iframe */
  .picker-mode .theme-modal-overlay {
    background: transparent; backdrop-filter: none; padding: 0;
  }
  .picker-mode .theme-modal {
    max-width: 100%; max-height: 100%; border-radius: 0;
    height: 100%;
  }

  .theme-modal {
    background: var(--paper);
    border-radius: var(--radius-lg);
    box-shadow: 0 16px 64px rgba(0,0,0,.25);
    width: 100%; max-width: 1280px;
    min-height: 520px;
    max-height: 88vh;
    display: flex; flex-direction: column;
    overflow: hidden;
  }

  .theme-modal-header {
    padding: 16px 24px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--cream);
    flex-shrink: 0;
  }
  .theme-modal-header-left {
    display: flex; align-items: center; gap: 16px;
  }
  .theme-modal-title {
    font-family: var(--font-display);
    font-size: 22px; color: var(--ink); line-height: 1.2;
  }
  .theme-modal-title em { color: var(--accent); font-style: italic; }
  .theme-modal-page-info {
    font-size: 11px; color: var(--muted); font-family: var(--font-mono);
  }
  .theme-modal-close {
    background: none; border: none; font-size: 22px; line-height: 1;
    color: var(--muted); cursor: pointer; padding: 4px 8px;
    border-radius: var(--radius-sm); transition: all var(--transition);
  }
  .theme-modal-close:hover { color: var(--ink); background: var(--cream); }

  .theme-modal-content {
    flex: 1; display: flex; overflow: hidden; min-height: 0;
  }

  /* Left: card grid + pagination */
  .theme-modal-left {
    flex: 1; display: flex; flex-direction: column; overflow: hidden;
    min-width: 0;
    transition: flex var(--transition);
  }
  .theme-modal-grid-wrap {
    flex: 1; overflow-y: auto; padding: 20px;
  }
  .theme-modal-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px;
    transition: all var(--transition);
  }
  .theme-modal.has-preview .theme-modal-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .theme-modal-pagination {
    flex-shrink: 0;
    padding: 12px 20px;
    border-top: 1px solid var(--cream);
    display: flex; align-items: center; justify-content: center; gap: 8px;
  }
  .page-btn {
    padding: 5px 12px; border: 1px solid var(--cream); border-radius: var(--radius-sm);
    background: #fff; color: var(--ink);
    font-family: var(--font-body); font-size: 12px; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
  }
  .page-btn:hover { border-color: var(--accent); color: var(--accent); }
  .page-btn:disabled { opacity: .35; cursor: not-allowed; }
  .page-btn:disabled:hover { border-color: var(--cream); color: var(--ink); }
  .page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
  .page-dots {
    font-size: 11px; color: var(--muted); font-family: var(--font-mono);
    padding: 0 2px;
  }

  /* Right: preview panel */
  .theme-modal-preview {
    width: 0; overflow: hidden;
    border-left: 1px solid var(--cream);
    background: var(--cream);
    display: flex; flex-direction: column;
    transition: width 0.3s cubic-bezier(.4,0,.2,1);
    flex-shrink: 0;
  }
  .theme-modal.has-preview .theme-modal-preview {
    width: 380px;
  }
  .theme-preview-header {
    padding: 14px 20px;
    border-bottom: 1px solid #ddd8d0;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
  }
  .theme-preview-title {
    font-size: 14px; font-weight: 600; color: var(--ink);
  }
  .theme-preview-use-btn {
    padding: 6px 16px; border: none; border-radius: var(--radius-sm);
    background: var(--accent); color: #fff;
    font-family: var(--font-body); font-size: 12px; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
  }
  .theme-preview-use-btn:hover { background: var(--accent-hover); }
  .theme-preview-scroll {
    flex: 1; overflow-y: auto;
    padding: 20px;
    display: flex; justify-content: center;
  }
  .theme-preview-phone {
    border-radius: 36px;
    border: 8px solid #1a1a1a;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    width: 320px;
    align-self: flex-start;
  }
  .theme-preview-phone-status {
    height: 32px; background: #fff;
    display: flex; align-items: center; justify-content: center;
    position: relative;
  }
  .theme-preview-phone-notch {
    width: 90px; height: 24px;
    background: #1a1a1a; border-radius: 0 0 14px 14px;
    position: absolute; top: 0;
  }
  .theme-preview-phone-body {
    padding: 0 12px 12px;
    overflow: hidden;
  }
  .theme-preview-phone-body img { max-width: 100%; height: auto; }
  .theme-preview-phone-home {
    height: 18px; display: flex; align-items: center; justify-content: center;
    background: #fff;
  }
  .theme-preview-phone-home-bar {
    width: 96px; height: 4px; background: #1a1a1a;
    border-radius: 2px; opacity: 0.2;
  }

  /* Style Guide Panel */
  .style-guide-toggle-btn {
    width: 32px; height: 32px;
    border: 1px solid #ddd8d0; border-radius: var(--radius-sm);
    background: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; transition: all var(--transition);
  }
  .style-guide-toggle-btn:hover { background: var(--cream); border-color: var(--stone); }
  .style-guide-toggle-btn.active { background: var(--accent); border-color: var(--accent); }
  .style-guide-panel {
    display: none;
    border-top: 1px solid #ddd8d0;
    background: #faf9f7;
    flex-shrink: 0;
    max-height: 50%;
    overflow: hidden;
    flex-direction: column;
  }
  .style-guide-panel.show {
    display: flex;
  }
  .style-guide-header {
    padding: 10px 20px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid #eee9e2;
    flex-shrink: 0;
  }
  .style-guide-label {
    font-size: 13px; font-weight: 600; color: var(--ink);
  }
  .style-guide-copy-btn {
    padding: 4px 12px; border: 1px solid #ddd8d0; border-radius: var(--radius-sm);
    background: #fff; color: var(--ink);
    font-family: var(--font-body); font-size: 11px; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
  }
  .style-guide-copy-btn:hover { background: var(--cream); border-color: var(--stone); }
  .style-guide-content {
    padding: 16px 20px;
    overflow-y: auto;
    font-size: 13px; line-height: 1.7; color: #444;
    white-space: pre-wrap;
    font-family: var(--font-body);
  }

  /* Theme cards — compact */
  .theme-card {
    background: #fff;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(.4,0,.2,1);
    position: relative;
    border: 2px solid transparent;
  }
  .theme-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.06);
  }
  .theme-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 3px 10px rgba(200,85,61,.15);
  }

  .theme-card-info {
    padding: 8px 10px;
    display: flex; align-items: center; justify-content: space-between;
    background: #fafaf8;
    border-bottom: 1px solid #f0ede8;
  }
  .theme-card-name {
    font-size: 11px; font-weight: 600; color: var(--ink);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .theme-card-tier {
    font-size: 8px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.04em; padding: 1px 5px;
    border-radius: 20px; flex-shrink: 0; margin-left: 4px;
  }
  .theme-card-tier.free { background: #e8f5e9; color: #2e7d32; }
  .theme-card-tier.pro { background: #fff3e0; color: #e65100; }

  .theme-card-preview {
    height: 220px;
    overflow: hidden;
    position: relative;
    background: var(--cream);
    padding: 12px;
    display: flex;
    justify-content: center;
  }
  .theme-card-preview::after {
    content: '';
    position: absolute; bottom: 0; left: 0; right: 0;
    height: 40px;
    background: linear-gradient(transparent, var(--cream));
    pointer-events: none;
    z-index: 1;
  }
  .theme-card.loading .theme-card-preview {
    align-items: center;
    height: 220px;
  }

  .theme-card-phone {
    border-radius: 18px;
    border: 4px solid #1a1a1a;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.10);
    width: 100%;
    max-width: 180px;
    align-self: flex-start;
  }
  .theme-card-phone-status {
    height: 16px; background: #fff;
    display: flex; align-items: center; justify-content: center;
    position: relative;
  }
  .theme-card-phone-notch {
    width: 44px; height: 12px;
    background: #1a1a1a; border-radius: 0 0 8px 8px;
    position: absolute; top: 0;
  }
  .theme-card-phone-body {
    padding: 0 6px 4px;
    font-size: 7px; line-height: 1.3;
    overflow: hidden;
  }
  .theme-card-phone-body img { max-width: 100%; height: auto; }
  .theme-card-phone-home {
    height: 10px; display: flex; align-items: center; justify-content: center;
    background: #fff;
  }
  .theme-card-phone-home-bar {
    width: 40px; height: 2px; background: #1a1a1a;
    border-radius: 1px; opacity: 0.2;
  }

  .theme-card-footer {
    padding: 8px 10px;
    display: flex; align-items: center; justify-content: space-between;
    border-top: 1px solid #f0ede8;
    background: #fff;
  }
  .theme-card-footer-name {
    font-size: 10px; color: var(--muted); font-family: var(--font-mono);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .theme-card-use-btn {
    padding: 4px 10px; border: none; border-radius: var(--radius-sm);
    background: var(--accent); color: #fff;
    font-family: var(--font-body); font-size: 10px; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
    flex-shrink: 0;
  }
  .theme-card-use-btn:hover { background: var(--accent-hover); }

  .theme-spinner {
    width: 18px; height: 18px;
    border: 2px solid var(--cream); border-top-color: var(--accent);
    border-radius: 50%;
    animation: theme-spin 0.7s linear infinite;
  }
  @keyframes theme-spin { to { transform: rotate(360deg); } }

  @media (max-width: 1100px) {
    .sidebar { width: 240px; min-width: 240px; }
    .theme-modal { max-width: 98vw; }
    .theme-modal-grid { grid-template-columns: repeat(3, 1fr); }
    .theme-modal.has-preview .theme-modal-grid { grid-template-columns: repeat(2, 1fr); }
    .theme-modal.has-preview .theme-modal-preview { width: 320px; }
  }
  @media (max-width: 800px) {
    .theme-modal-grid { grid-template-columns: repeat(2, 1fr); }
    .theme-modal.has-preview .theme-modal-grid { grid-template-columns: 1fr; }
    .theme-modal.has-preview .theme-modal-preview { width: 280px; }
  }

  /* (Articles modal CSS removed — articles are now in the left panel) */

  /* ═══ STYLE PICKER MODAL ═══ */
  .style-picker-overlay {
    display: none; position: fixed; inset: 0; z-index: 120;
    background: rgba(20,18,15,.55); backdrop-filter: blur(8px);
    align-items: center; justify-content: center;
    padding: 24px;
    animation: sp-overlay-in .25s ease-out;
  }
  @keyframes sp-overlay-in { from { opacity: 0; } }
  .style-picker-overlay.show { display: flex; }

  .style-picker-dialog {
    background: var(--paper); border-radius: 16px;
    width: 100%; max-width: 860px; max-height: 86vh;
    display: flex; flex-direction: column;
    box-shadow: 0 4px 16px rgba(0,0,0,.1), 0 24px 80px rgba(0,0,0,.22);
    overflow: hidden;
    animation: sp-dialog-in .3s cubic-bezier(.2,.9,.3,1);
  }
  @keyframes sp-dialog-in {
    from { opacity: 0; transform: translateY(12px) scale(.97); }
  }

  .style-picker-header {
    padding: 18px 24px; border-bottom: 1px solid var(--cream);
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
  }
  .style-picker-title {
    font-family: var(--font-display); font-size: 22px; color: var(--ink);
    line-height: 1.2;
  }
  .style-picker-title em { color: var(--accent); font-style: italic; }
  .style-picker-close {
    background: none; border: none; font-size: 22px; line-height: 1;
    color: var(--muted); cursor: pointer; padding: 4px 8px;
    border-radius: var(--radius-sm); transition: all var(--transition);
  }
  .style-picker-close:hover { color: var(--ink); background: var(--cream); }

  .style-picker-body {
    flex: 1; overflow-y: auto; padding: 20px 24px 24px;
  }

  /* Category labels inside grid */
  .sp-category {
    grid-column: 1 / -1;
    font-family: var(--font-cn); font-size: 12px; font-weight: 600;
    color: var(--muted); letter-spacing: .04em;
    padding: 6px 0 2px;
    border-bottom: 1px solid var(--cream);
    margin-bottom: -2px;
    display: flex; align-items: center; gap: 8px;
  }
  .sp-category:first-child { padding-top: 0; }
  .sp-category::after {
    content: ''; flex: 1; height: 1px; background: var(--cream);
  }

  .style-picker-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  }

  /* Cards */
  .style-picker-card {
    background: #fff; border-radius: 10px;
    overflow: hidden; cursor: pointer;
    border: 2px solid transparent;
    transition: all .22s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
    position: relative;
  }
  .style-picker-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0,0,0,.08), 0 12px 28px rgba(0,0,0,.07);
  }
  .style-picker-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 4px 16px rgba(200,85,61,.18);
  }
  /* Check badge on active card */
  .style-picker-card.active::before {
    content: '✓';
    position: absolute; top: 8px; right: 8px; z-index: 5;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--accent); color: #fff;
    font-size: 11px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 6px rgba(200,85,61,.35);
  }

  /* Phone preview area */
  .style-picker-card-preview {
    height: 210px; overflow: hidden; position: relative;
    background: #f4f2ee; padding: 8px;
    display: flex; justify-content: center;
  }
  .style-picker-card-preview::after {
    content: ''; position: absolute; bottom: 0; left: 0; right: 0;
    height: 36px;
    background: linear-gradient(transparent, #f4f2ee);
    pointer-events: none; z-index: 1;
  }

  /* Render at real phone width → zoom shrink to fit */
  .style-picker-card-preview .sp-phone {
    width: 375px;
    zoom: 0.44;
    border-radius: 32px;
    border: 6px solid #1a1a1a;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    align-self: flex-start;
  }
  .style-picker-card-preview .sp-phone-status {
    height: 28px; background: #fff;
    display: flex; align-items: center; justify-content: center;
    position: relative;
  }
  .style-picker-card-preview .sp-phone-notch {
    width: 80px; height: 20px;
    background: #1a1a1a; border-radius: 0 0 12px 12px;
    position: absolute; top: 0;
  }
  .style-picker-card-preview .sp-phone-body {
    padding: 0 10px 8px;
    overflow: hidden;
  }
  .style-picker-card-preview .sp-phone-body img {
    max-width: 100%; height: auto;
  }
  .style-picker-card-preview .sp-phone-home {
    height: 16px; display: flex; align-items: center; justify-content: center;
    background: #fff;
  }
  .style-picker-card-preview .sp-phone-home-bar {
    width: 80px; height: 4px; background: #1a1a1a;
    border-radius: 2px; opacity: 0.18;
  }

  /* Info bar */
  .style-picker-card-info {
    padding: 8px 10px; background: #fff;
    border-top: 1px solid #f0ede8;
  }
  .style-picker-card-name {
    font-size: 12px; font-weight: 600; color: var(--ink);
    margin-bottom: 1px;
  }
  .style-picker-card-desc {
    font-size: 10px; color: var(--muted); line-height: 1.3;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }

  /* Loading state */
  .style-picker-card.loading .style-picker-card-preview {
    align-items: center; justify-content: center;
  }

  /* Footer cards: show from bottom so footer is visible */
  .style-picker-card.sp-footer-mode .style-picker-card-preview .sp-phone {
    align-self: flex-end;
  }
  .style-picker-card.sp-footer-mode .style-picker-card-preview::after {
    top: 0; bottom: auto;
    background: linear-gradient(#f4f2ee, transparent);
  }

  /* "None" card — distinct look */
  .style-picker-card.sp-card-none .style-picker-card-preview {
    background: repeating-linear-gradient(
      -45deg, #f4f2ee, #f4f2ee 6px, #eceae5 6px, #eceae5 7px
    );
    display: flex; align-items: center; justify-content: center;
  }
  .sp-none-label {
    font-family: var(--font-cn); font-size: 13px; color: var(--stone);
    letter-spacing: 2px;
  }

  @media (max-width: 900px) {
    .style-picker-grid { grid-template-columns: repeat(3, 1fr); }
    .style-picker-dialog { max-width: 96vw; }
  }
  @media (max-width: 600px) {
    .style-picker-grid { grid-template-columns: repeat(2, 1fr); }
    .style-picker-body { padding: 14px; }
  }

  /* ═══ Sidebar style picker button ═══ */
  .style-picker-btn {
    width: 100%; padding: 8px 10px;
    border: 1px solid var(--field-border); border-radius: var(--radius-sm);
    background: var(--field-bg); color: var(--sidebar-text);
    font-family: var(--font-body); font-size: 12px;
    cursor: pointer; transition: border-color var(--transition);
    display: flex; align-items: center; justify-content: space-between;
    text-align: left;
  }
  .style-picker-btn:hover { border-color: var(--accent); }
  .edit-html-btn {
    width: 30px; height: 30px; flex-shrink: 0;
    border: 1px solid var(--field-border); border-radius: var(--radius-sm);
    background: var(--field-bg); color: var(--sidebar-text);
    font-size: 14px; cursor: pointer; transition: all var(--transition);
    display: flex; align-items: center; justify-content: center;
  }
  .edit-html-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(99,102,241,.08); }
  .edit-html-toggle {
    width: 100%; margin-top: 4px; padding: 4px 0;
    border: none; background: none; color: var(--muted);
    font-size: 11px; cursor: pointer; text-align: left;
    transition: color var(--transition);
  }
  .edit-html-toggle:hover { color: var(--accent); }
  .edit-html-toggle.active { color: var(--accent); }
  .style-picker-btn .picker-label {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .style-picker-btn .picker-arrow {
    color: var(--muted); flex-shrink: 0; margin-left: 6px;
    font-size: 10px; transition: transform var(--transition);
  }
  .style-picker-btn:hover .picker-arrow { transform: translateX(2px); }

  /* ═══ TEMPLATE TABS ═══ */
  .tpl-tabs {
    display: flex; gap: 2px; background: var(--cream); border-radius: 6px; padding: 2px; margin-left: 16px;
  }
  .tpl-tab {
    padding: 5px 14px; border: none; background: none; border-radius: 4px;
    font-family: var(--font-body); font-size: 12px; font-weight: 600;
    color: var(--muted); cursor: pointer; transition: var(--transition);
    white-space: nowrap;
  }
  .tpl-tab:hover { color: var(--ink); }
  .tpl-tab.active { background: white; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

  /* Template card extra buttons */
  .theme-card-actions {
    display: flex; gap: 4px; padding: 0 8px 8px;
  }
  .theme-card-action-btn {
    flex: 1; padding: 4px 0; border: 1px solid #e5e7eb; border-radius: 4px;
    background: white; font-size: 10px; font-weight: 600; color: var(--muted);
    cursor: pointer; transition: var(--transition); font-family: var(--font-body);
  }
  .theme-card-action-btn:hover { border-color: var(--accent); color: var(--accent); }
  .theme-card-action-btn.primary {
    background: var(--accent); color: white; border-color: var(--accent);
  }
  .theme-card-action-btn.primary:hover { background: var(--accent-hover); }
  .theme-card-action-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
  .theme-card-id-row {
    position: absolute; top: 4px; right: 4px; z-index: 2;
    display: flex; align-items: center; gap: 2px;
    background: rgba(0,0,0,.45); border-radius: 4px; padding: 1px 4px 1px 6px;
    backdrop-filter: blur(4px); opacity: 0; transition: opacity .2s;
  }
  .theme-card:hover .theme-card-id-row { opacity: 1; }
  .theme-card-id {
    font-size: 10px; color: #fff; font-family: monospace;
    max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .theme-card-copy-btn {
    border: none; background: none; cursor: pointer; font-size: 11px;
    padding: 2px; line-height: 1; color: rgba(255,255,255,.7); flex-shrink: 0;
  }
  .theme-card-copy-btn:hover { color: #fff; }
  .theme-card-desc {
    font-size: 10px; color: var(--muted); padding: 0 8px; margin-bottom: 4px;
    line-height: 1.4; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap;
  }
  .tpl-new-btn-wrap {
    grid-column: 1 / -1; display: flex; justify-content: center; padding: 16px 0;
  }
  .tpl-new-btn {
    padding: 8px 20px; border: 2px dashed var(--stone); border-radius: var(--radius-md);
    background: none; color: var(--muted); font-size: 12px; font-weight: 600;
    cursor: pointer; transition: var(--transition); font-family: var(--font-body);
  }
  .tpl-new-btn:hover { border-color: var(--accent); color: var(--accent); }

  /* ═══ TEMPLATE EDIT MODAL ═══ */
  .tpl-edit-overlay {
    display: none; position: fixed; inset: 0; z-index: 110;
    background: rgba(0,0,0,.45); backdrop-filter: blur(4px);
    align-items: center; justify-content: center;
  }
  .tpl-edit-overlay.show { display: flex; }
  .tpl-edit-dialog {
    background: white; border-radius: var(--radius-lg);
    width: 1100px; max-width: 96vw; height: 92vh; max-height: 92vh;
    display: flex; flex-direction: column;
    box-shadow: 0 8px 40px rgba(0,0,0,.18);
  }
  .tpl-edit-header {
    padding: 18px 24px; border-bottom: 1px solid #eee;
    display: flex; align-items: center; justify-content: space-between;
  }
  .tpl-edit-title {
    font-family: var(--font-cn); font-size: 17px; font-weight: 600; color: var(--ink);
  }
  .tpl-edit-close {
    background: none; border: none; font-size: 22px; color: var(--muted);
    cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm);
  }
  .tpl-edit-close:hover { background: var(--cream); color: var(--ink); }
  .tpl-edit-body {
    display: flex; flex: 1; overflow: hidden;
  }
  .tpl-edit-form {
    flex: 1; padding: 20px 24px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 14px;
  }
  .tpl-edit-label {
    display: block; font-size: 11px; font-weight: 600; color: var(--muted);
    margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.05em;
  }
  .tpl-edit-input, .tpl-edit-select {
    width: 100%; padding: 8px 10px;
    border: 1px solid #ddd; border-radius: var(--radius-sm);
    font-family: var(--font-body); font-size: 13px; color: var(--ink);
    outline: none; transition: border-color var(--transition);
  }
  .tpl-edit-input:focus, .tpl-edit-select:focus { border-color: var(--accent); }
  .tpl-edit-textarea {
    width: 100%; min-height: 80px; padding: 8px 10px;
    border: 1px solid #ddd; border-radius: var(--radius-sm);
    font-family: var(--font-mono); font-size: 12px; color: var(--ink);
    outline: none; resize: vertical; line-height: 1.5;
  }
  .tpl-edit-textarea:focus { border-color: var(--accent); }
  .tpl-edit-save-btn {
    padding: 10px 20px; border: none; border-radius: var(--radius-sm);
    background: var(--accent); color: white; font-weight: 600; font-size: 13px;
    cursor: pointer; transition: var(--transition); font-family: var(--font-body);
    align-self: flex-start;
  }
  .tpl-edit-save-btn:hover { background: var(--accent-hover); }
  .tpl-edit-picker-btn {
    width: 100%; padding: 10px 14px; background: var(--paper);
    border: 1px solid #ddd; border-radius: var(--radius-md);
    font-family: var(--font-body); font-size: 13px; color: var(--ink);
    cursor: pointer; text-align: left;
    display: flex; align-items: center; justify-content: space-between;
    transition: all var(--transition);
  }
  .tpl-edit-picker-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
  .tpl-edit-picker-btn .picker-arrow {
    color: var(--muted); flex-shrink: 0; margin-left: 8px;
    font-size: 11px; transition: transform var(--transition);
  }
  .tpl-edit-picker-btn:hover .picker-arrow { transform: translateX(2px); color: var(--accent); }
  .tpl-edit-sort-btn {
    flex: 1; padding: 6px 0; background: #f5f5f5; border: 1px solid #ddd;
    border-radius: var(--radius-sm); color: var(--muted); font-size: 12px;
    cursor: pointer; transition: all var(--transition); font-family: var(--font-body);
  }
  .tpl-edit-sort-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
  .tpl-edit-sort-btn:hover:not(.active) { border-color: var(--stone); color: var(--ink); }
  /* Light theme picker popover for edit modal */
  .tpl-pick-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 120;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(2px);
  }
  .tpl-pick-modal {
    background: white; border-radius: 12px; width: 90%; max-width: 480px;
    max-height: 60vh; display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  }
  .tpl-pick-header {
    padding: 14px 20px; border-bottom: 1px solid #eee;
    display: flex; align-items: center; justify-content: space-between;
    font-size: 14px; font-weight: 600; color: var(--ink);
  }
  .tpl-pick-header button { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
  .tpl-pick-grid {
    flex: 1; overflow-y: auto; padding: 12px;
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
  }
  .tpl-pick-item {
    padding: 12px 14px; cursor: pointer; font-size: 13px; color: var(--ink);
    display: flex; align-items: center; gap: 10px;
    border: 1.5px solid #eee; border-radius: var(--radius-md);
    transition: all 0.15s; background: white;
  }
  .tpl-pick-item:hover { border-color: var(--accent); background: var(--accent-soft); }
  .tpl-pick-item.active { border-color: var(--accent); background: var(--accent-soft); }
  .tpl-pick-item .pick-check {
    width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
    border: 1.5px solid #ddd; display: flex; align-items: center; justify-content: center;
    font-size: 11px; color: white; transition: all 0.15s;
  }
  .tpl-pick-item.active .pick-check {
    background: var(--accent); border-color: var(--accent);
  }
  .tpl-pick-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .tpl-pick-item .pick-check { width: 16px; color: var(--accent); flex-shrink: 0; }
  .tpl-edit-preview {
    width: 360px; border-left: 1px solid #eee; padding: 16px;
    display: flex; flex-direction: column; overflow-y: auto;
    background: var(--paper);
  }
  .tpl-edit-preview-title {
    font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 12px;
    text-transform: uppercase; letter-spacing: 0.05em;
  }
  .tpl-edit-preview-phone {
    background: white; border-radius: 24px; overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,.1); border: 3px solid #e5e5e5;
    flex: 1; display: flex; flex-direction: column;
  }
  .tpl-edit-preview-body {
    flex: 1; overflow-y: auto; padding: 8px;
    font-size: 8px; line-height: 1.4;
  }
  .tpl-edit-preview-body img { max-width: 100%; height: auto; }
  @media (max-width: 900px) {
    .tpl-edit-dialog { width: 98vw; }
    .tpl-edit-preview { width: 280px; }
  }
  @media (max-width: 700px) {
    .tpl-edit-body { flex-direction: column; }
    .tpl-edit-preview { width: 100%; border-left: none; border-top: 1px solid #eee; max-height: 300px; }
  }

  /* ═══ HTML EDITOR MODAL (split: code + live preview) ═══ */
  .html-editor-overlay {
    display: none; position: fixed; inset: 0; z-index: 500;
    background: rgba(0,0,0,.5); backdrop-filter: blur(6px);
    align-items: center; justify-content: center;
  }
  .html-editor-overlay.show { display: flex; }
  .html-editor-dialog {
    background: white; border-radius: var(--radius-lg);
    width: 1200px; max-width: 96vw; height: 88vh; max-height: 88vh;
    display: flex; flex-direction: column;
    box-shadow: 0 12px 60px rgba(0,0,0,.25);
    animation: htmlEditorIn .25s ease-out;
  }
  @keyframes htmlEditorIn {
    from { opacity: 0; transform: scale(.96) translateY(12px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
  }
  .html-editor-topbar {
    padding: 16px 24px; border-bottom: 1px solid #eee;
    display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
  }
  .html-editor-topbar-left { display: flex; align-items: center; gap: 12px; }
  .html-editor-topbar-title {
    font-family: var(--font-cn); font-size: 16px; font-weight: 600; color: var(--ink);
  }
  .html-editor-topbar-badge {
    font-size: 10px; font-weight: 600; padding: 2px 8px;
    border-radius: 10px; background: var(--accent-soft); color: var(--accent);
    text-transform: uppercase; letter-spacing: .04em;
  }
  .html-editor-topbar-close {
    background: none; border: none; font-size: 22px; color: var(--muted);
    cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm);
    transition: all var(--transition);
  }
  .html-editor-topbar-close:hover { background: var(--cream); color: var(--ink); }
  .html-editor-split {
    display: flex; flex: 1; overflow: hidden;
  }
  .html-editor-code-pane {
    flex: 1; display: flex; flex-direction: column; border-right: 1px solid #eee;
    min-width: 0;
  }
  .html-editor-hints {
    padding: 10px 20px; background: #fafafa; border-bottom: 1px solid #f0f0f0;
    font-size: 11px; color: var(--muted); line-height: 1.6; flex-shrink: 0;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
  }
  .html-editor-hints code {
    background: var(--accent-soft); color: var(--accent); padding: 1px 5px;
    border-radius: 3px; font-size: 10.5px; font-family: var(--font-mono);
  }
  .html-editor-format-btn {
    flex-shrink: 0; padding: 3px 10px; border: 1px solid #ddd;
    border-radius: var(--radius-sm); background: white; color: var(--muted);
    font-size: 11px; font-family: var(--font-mono); cursor: pointer;
    transition: all var(--transition); white-space: nowrap;
  }
  .html-editor-format-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
  .html-editor-code {
    flex: 1; width: 100%; border: none; outline: none; resize: none;
    padding: 16px 20px; font-family: var(--font-mono); font-size: 12.5px;
    line-height: 1.65; color: var(--ink); background: white;
    tab-size: 2;
  }
  .html-editor-code::placeholder { color: #ccc; }
  .html-editor-preview-pane {
    width: 400px; flex-shrink: 0; display: flex; flex-direction: column;
    background: var(--paper); overflow: hidden;
  }
  .html-editor-preview-header {
    padding: 10px 16px; border-bottom: 1px solid #eee;
    display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
  }
  .html-editor-preview-label {
    font-size: 11px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .05em;
  }
  .html-editor-preview-status {
    font-size: 10px; color: var(--accent); opacity: 0; transition: opacity .2s;
  }
  .html-editor-preview-status.loading { opacity: 1; }
  .html-editor-preview-scroll {
    flex: 1; overflow-y: auto; padding: 16px; display: flex; justify-content: center;
  }
  .html-editor-preview-phone {
    width: 340px; background: white; border-radius: 28px; overflow: hidden;
    box-shadow: 0 2px 16px rgba(0,0,0,.1); border: 3px solid #e5e5e5;
    display: flex; flex-direction: column; flex-shrink: 0;
  }
  .html-editor-preview-body {
    padding: 8px; font-size: 8px; line-height: 1.4;
    min-height: 300px; overflow-y: auto; max-height: 65vh;
  }
  .html-editor-preview-body img { max-width: 100%; height: auto; }
  .html-editor-footer {
    padding: 14px 24px; border-top: 1px solid #eee;
    display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-shrink: 0;
  }
  .html-editor-btn {
    padding: 8px 20px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; cursor: pointer;
    font-family: var(--font-body); transition: all var(--transition);
  }
  .html-editor-btn-cancel {
    background: none; border: 1px solid #ddd; color: var(--muted);
  }
  .html-editor-btn-cancel:hover { border-color: var(--ink); color: var(--ink); }
  .html-editor-btn-save {
    background: var(--accent); border: none; color: white;
  }
  .html-editor-btn-save:hover { background: var(--accent-hover); }
  @media (max-width: 800px) {
    .html-editor-dialog { width: 98vw; height: 95vh; }
    .html-editor-split { flex-direction: column; }
    .html-editor-preview-pane { width: 100%; border-left: none; border-top: 1px solid #eee; max-height: 40vh; }
    .html-editor-code-pane { border-right: none; }
  }

  /* ═══════════════════════════════════════════ */
  /* EDITOR MODE TABS (Article / Visual)         */
  /* ═══════════════════════════════════════════ */
  .editor-mode-tabs {
    display: flex; gap: 2px;
    background: var(--cream);
    border-radius: var(--radius-sm);
    padding: 2px;
  }
  .editor-mode-tab {
    padding: 5px 14px;
    font-size: 10px; font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    background: transparent;
    border: none; border-radius: 3px;
    cursor: pointer;
    display: flex; align-items: center; gap: 5px;
    transition: all var(--transition);
    white-space: nowrap;
  }
  .editor-mode-tab:hover { color: var(--ink); }
  .editor-mode-tab.active {
    background: #fff;
    color: var(--ink);
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
  }

  /* ═══════════════════════════════════════════ */
  /* VISUAL EDITOR                               */
  /* ═══════════════════════════════════════════ */
  .visual-editor {
    flex: 1; display: flex; flex-direction: column;
    overflow-y: auto; background: #fff;
  }
  .visual-images-area {
    padding: 16px 24px;
    border-bottom: 1px solid var(--cream);
  }
  .visual-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
  }
  .visual-image-grid:empty { margin-bottom: 0; }

  .visual-image-card {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--cream);
    aspect-ratio: 1;
    cursor: grab;
  }
  .visual-image-card img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
  }
  .visual-image-card .visual-img-cover-badge {
    position: absolute; top: 6px; left: 6px;
    background: var(--accent); color: #fff;
    font-size: 9px; font-weight: 700;
    padding: 2px 6px; border-radius: 3px;
    text-transform: uppercase; letter-spacing: 0.05em;
  }
  .visual-image-card .visual-img-actions {
    position: absolute; top: 4px; right: 4px;
    display: flex; gap: 3px; opacity: 0;
    transition: opacity 0.15s ease;
  }
  .visual-image-card:hover .visual-img-actions { opacity: 1; }
  .visual-img-action-btn {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,.55); color: #fff;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; line-height: 1;
    transition: background 0.15s;
  }
  .visual-img-action-btn:hover { background: rgba(0,0,0,.8); }
  .visual-image-card.uploading {
    opacity: 0.5;
  }
  .visual-image-card.uploading::after {
    content: '';
    position: absolute; inset: 0;
    background: rgba(255,255,255,.6);
    display: flex; align-items: center; justify-content: center;
  }
  .visual-image-card .visual-img-index {
    position: absolute; bottom: 6px; right: 6px;
    background: rgba(0,0,0,.45); color: #fff;
    font-size: 10px; font-weight: 600;
    width: 20px; height: 20px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
  }

  .visual-add-actions {
    display: flex; gap: 8px;
  }
  .visual-add-btn {
    padding: 8px 16px;
    font-size: 12px; font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex; align-items: center; gap: 5px;
    font-family: var(--font-body);
    transition: all var(--transition);
    background: var(--cream); color: var(--ink);
    border: 1px solid var(--stone);
  }
  .visual-add-btn:hover { border-color: var(--ink); }
  .visual-add-btn-primary {
    background: var(--accent); color: #fff;
    border-color: var(--accent);
  }
  .visual-add-btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

  .visual-caption-area {
    padding: 16px 24px; flex: 1;
    display: flex; flex-direction: column;
  }
  .visual-caption-label {
    font-size: 10px; font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    margin-bottom: 8px;
  }
  .visual-caption-area textarea {
    flex: 1; min-height: 120px;
    padding: 12px 0;
    font-family: var(--font-cn);
    font-size: 14px; line-height: 1.8;
    border: none; outline: none; resize: none;
    color: var(--ink); background: transparent;
  }
  .visual-caption-area textarea::placeholder { color: var(--stone); }

  /* Visual URL input dialog */
  .visual-url-dialog {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
  }
  .visual-url-dialog-inner {
    background: #fff; border-radius: var(--radius-lg);
    padding: 24px; width: 420px; max-width: 90vw;
    box-shadow: 0 16px 48px rgba(0,0,0,.15);
  }
  .visual-url-dialog-inner h4 {
    font-size: 15px; font-weight: 600;
    margin-bottom: 12px; color: var(--ink);
  }
  .visual-url-dialog-inner textarea {
    width: 100%; min-height: 80px;
    padding: 10px; font-size: 13px;
    border: 1px solid var(--cream); border-radius: var(--radius-sm);
    outline: none; resize: vertical;
    font-family: var(--font-mono);
  }
  .visual-url-dialog-inner textarea:focus { border-color: var(--accent); }
  .visual-url-dialog-actions {
    display: flex; gap: 8px; justify-content: flex-end;
    margin-top: 12px;
  }
  .visual-url-dialog-actions button {
    padding: 7px 18px; font-size: 13px; font-weight: 600;
    border-radius: var(--radius-sm); cursor: pointer;
    font-family: var(--font-body);
  }
