/* ============================================
   Create editor - autosave, recents, preflight
   Loaded only on create.html, after tool.css.
   ============================================ */

/* ---- Recent documents (setup view) ---- */
.ce-recent-head { align-items:center; }
.ce-recent-head-text { flex:1; min-width:0; }
.ce-recent-head-actions { display:flex; align-items:center; gap:8px; flex-shrink:0; }
.ce-recent-session-btn {
    display:inline-flex;
    align-items:center;
    gap:7px;
    padding:8px 14px;
    border-radius:10px;
    border:1px solid rgba(255,152,0,0.4);
    background:rgba(255,152,0,0.1);
    color:#ff9800;
    font-size:13px;
    font-weight:600;
    cursor:pointer;
    transition:background 0.15s, border-color 0.15s;
}
.ce-recent-session-btn:hover { background:rgba(255,152,0,0.18); border-color:rgba(255,152,0,0.65); }
.ce-recent-clear {
    display:inline-flex;
    align-items:center;
    gap:6px;
    padding:8px 12px;
    border-radius:10px;
    border:1px solid var(--glass-border);
    background:transparent;
    color:var(--text-secondary);
    font-size:12.5px;
    font-weight:600;
    cursor:pointer;
    transition:color 0.15s, border-color 0.15s;
}
.ce-recent-clear:hover { color:#ef4444; border-color:rgba(239,68,68,0.45); }
.ce-recent-grid {
    display:grid;
    grid-template-columns:repeat(auto-fill, minmax(210px, 1fr));
    gap:14px;
}
.ce-recent-card {
    position:relative;
    border:1px solid var(--glass-border);
    border-radius:14px;
    background:var(--bg-tertiary);
    overflow:hidden;
    transition:border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.ce-recent-card:hover {
    border-color:var(--glass-border-hover);
    transform:translateY(-2px);
    box-shadow:0 10px 26px -16px rgba(0,0,0,0.45);
}
.ce-recent-open {
    display:flex;
    align-items:center;
    gap:12px;
    width:100%;
    padding:12px;
    border:none;
    background:transparent;
    color:inherit;
    text-align:start;
    cursor:pointer;
}
.ce-recent-thumb {
    position:relative;
    flex-shrink:0;
    width:58px;
    height:76px;
    border-radius:7px;
    border:1px solid var(--glass-border);
    background:#fff;
    overflow:hidden;
}
.ce-recent-thumb img { width:100%; height:100%; object-fit:contain; display:block; }
.ce-recent-thumb-fallback {
    display:flex;
    align-items:center;
    justify-content:center;
    width:100%;
    height:100%;
    color:#94a3b8;
    background:var(--bg-secondary);
}
.ce-recent-badge {
    position:absolute;
    right:3px;
    bottom:3px;
    min-width:16px;
    padding:0 4px;
    height:16px;
    border-radius:8px;
    background:rgba(15,23,42,0.75);
    color:#fff;
    font-size:10px;
    font-weight:700;
    line-height:16px;
    text-align:center;
}
.ce-recent-info { min-width:0; display:flex; flex-direction:column; gap:4px; }
.ce-recent-name {
    display:block;
    font-size:13.5px;
    font-weight:600;
    color:var(--text-primary);
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
    max-width:150px;
}
.ce-recent-meta { font-size:11.5px; color:var(--text-tertiary); white-space:nowrap; }
.ce-recent-del {
    position:absolute;
    top:6px;
    right:6px;
    width:22px;
    height:22px;
    border:none;
    border-radius:6px;
    background:var(--bg-secondary);
    color:var(--text-tertiary);
    display:flex;
    align-items:center;
    justify-content:center;
    cursor:pointer;
    opacity:0;
    transition:opacity 0.15s, color 0.15s, background 0.15s;
    z-index:1;
}
.ce-recent-card:hover .ce-recent-del,
.ce-recent-del:focus-visible { opacity:1; }
.ce-recent-del:hover { color:#ef4444; background:rgba(239,68,68,0.12); }
.ce-recent-empty {
    padding:22px;
    text-align:center;
    font-size:13px;
    color:var(--text-tertiary);
}
@media (hover:none) {
    .ce-recent-del { opacity:1; }
}
[dir="rtl"] .ce-recent-del { right:auto; left:6px; }
[dir="rtl"] .ce-recent-badge { right:auto; left:3px; }

/* ---- Autosave indicator (editor topbar) ---- */
.ce-autosave {
    display:flex;
    align-items:center;
    gap:7px;
    padding:5px 10px;
    border-radius:8px;
    font-size:11.5px;
    font-weight:600;
    color:var(--text-tertiary);
    white-space:nowrap;
    user-select:none;
    max-width:150px;
    overflow:hidden;
}
.ce-autosave-dot {
    width:7px;
    height:7px;
    border-radius:50%;
    background:#94a3b8;
    flex-shrink:0;
    transition:background 0.2s;
}
.ce-autosave[data-state="saving"] .ce-autosave-dot { background:#ff9800; animation:ceAutoPulse 1s ease-in-out infinite; }
.ce-autosave[data-state="saved"] .ce-autosave-dot { background:#22c55e; }
.ce-autosave[data-state="paused"] .ce-autosave-dot,
.ce-autosave[data-state="error"] .ce-autosave-dot { background:#f59e0b; }
/* Deliberate policy, not a fault, so it stays off the warning amber. */
.ce-autosave[data-state="pdf"] .ce-autosave-dot { background:#64748b; }
.ce-autosave[data-state="error"] { color:#ef4444; }
.ce-autosave-text { overflow:hidden; text-overflow:ellipsis; }
@keyframes ceAutoPulse {
    0%, 100% { opacity:1; transform:scale(1); }
    50% { opacity:0.35; transform:scale(0.8); }
}

/* ---- Transform inspector extras ---- */
.editor-transform-unit {
    padding:2px 6px;
    border:1px solid var(--glass-border);
    border-radius:5px;
    font-size:10px;
    font-weight:700;
    letter-spacing:0.03em;
    text-transform:uppercase;
    color:var(--text-tertiary);
    line-height:16px;
    flex-shrink:0;
    cursor:default;
}
#tfLock { color:var(--text-secondary); }
#tfLock.active { background:rgba(255,152,0,0.16); color:#ff9800; }
.ce-tf-mixed::placeholder { color:var(--text-tertiary); }

/* ---- Export preflight ---- */
.ce-preflight-card { max-width:540px; }
.ce-preflight-title-row { display:flex; align-items:center; gap:12px; margin-bottom:12px; }
.ce-preflight-icon {
    width:38px;
    height:38px;
    border-radius:10px;
    display:flex;
    align-items:center;
    justify-content:center;
    flex-shrink:0;
    background:rgba(255,152,0,0.12);
    color:#ff9800;
    border:1px solid rgba(255,152,0,0.25);
}
.ce-preflight-title {
    font-size:17px;
    font-weight:700;
    color:var(--text-primary);
}
.ce-preflight-desc {
    font-size:13.5px;
    line-height:1.6;
    color:var(--text-secondary);
    margin-bottom:16px;
}
.ce-preflight-list {
    list-style:none;
    margin:0 0 20px;
    padding:0;
    display:flex;
    flex-direction:column;
    gap:8px;
}
.ce-preflight-list li {
    display:flex;
    align-items:flex-start;
    gap:10px;
    padding:11px 13px;
    border-radius:10px;
    border:1px solid var(--glass-border);
    background:var(--bg-tertiary);
    font-size:13px;
    line-height:1.5;
    color:var(--text-primary);
}
.ce-preflight-list li svg { flex-shrink:0; margin-top:1px; }
.ce-preflight-list li[data-kind="error"] svg { color:#ef4444; }
.ce-preflight-list li[data-kind="warn"] svg { color:#f59e0b; }
.ce-preflight-detail { display:block; color:var(--text-tertiary); font-size:12px; margin-top:2px; }
[dir="rtl"] .ce-preflight-title-row { flex-direction:row; }

@media (max-width:1240px) {
    .ce-autosave { max-width:120px; padding:5px 6px; }
}
@media (max-width:1080px) {
    .ce-autosave { display:none; }
    .editor-transform-unit { display:none; }
}

/* ---- html2canvas font metric probe ----
   html2canvas reads font metrics from a 1x1 <img> baseline probe that it
   appends to <body>. The global `img { display: block }` rule turns that probe
   into a block box on a line of its own, so its offset no longer marks the
   text baseline and every exported text baseline lands far too low. Keeping the
   probe inline restores it, and a 2px box makes html2canvas' metric equal the
   font's real ascent instead of one pixel below it. */
img[width="1"][height="1"][style*="vertical-align"] {
    display: inline-block;
    height: 2px;
}

/* ---- Auto-open hand-off (?open= / ?new) ---- */
/* Set by an inline <head> script before first paint; removed by create.js
   once the editor is up (or on failure). While present, the setup view and
   footer stay hidden and a spinner marks the wait, so the landing content
   never flashes ahead of the editor. */
html[data-autopen] #uploadView,
html[data-autopen] .footer {
    display: none;
}
html[data-autopen] body::after {
    content: '';
    position: fixed;
    top: 50%;
    left: 50%;
    width: 42px;
    height: 42px;
    margin: -21px 0 0 -21px;
    border-radius: 50%;
    border: 3px solid var(--glass-border);
    border-top-color: var(--accent-primary);
    animation: ceAutoOpenSpin 0.8s linear infinite;
}
@keyframes ceAutoOpenSpin {
    to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
    html[data-autopen] body::after { animation: none; }
}
