/* ══════════════════════════════════════
   SimpleEdit — Editor Overlay Styles
   Only loaded for authenticated users
   ══════════════════════════════════════ */

/* ── Edit Bar ── */
.edit-bar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    background: rgba(37,99,235,0.95); backdrop-filter: blur(10px);
    padding: 8px 16px; display: flex; align-items: center; justify-content: space-between;
    font-family: 'DM Sans', sans-serif; font-size: 14px; color: white;
    transform: translateY(-100%); transition: transform 0.3s;
}
.edit-bar.visible { transform: translateY(0); }
.edit-bar-left { display: flex; align-items: center; gap: 12px; }
.edit-bar-right { display: flex; align-items: center; gap: 8px; }
.edit-bar .status-dot { width: 8px; height: 8px; border-radius: 50%; }
.edit-bar .status-dot.saved { background: #4ade80; }
.edit-bar .status-dot.unsaved { background: #fbbf24; }
.eb-btn { padding: 6px 14px; border-radius: 6px; border: 1.5px solid rgba(255,255,255,0.3); background: transparent; color: white; font-size: 13px; font-weight: 500; font-family: inherit; cursor: pointer; transition: all 0.15s; text-decoration: none; }
.eb-btn:hover { background: rgba(255,255,255,0.15); }
.eb-btn.save { background: white; color: #2563eb; border-color: white; font-weight: 600; }
.eb-btn.save:hover { background: #e0e7ff; }
.eb-btn.save:disabled { opacity: 0.5; cursor: default; }

/* ── Edit mode section highlighting ── */
body.editing [data-field] { cursor: text; }
body.editing .section-block { position: relative; outline: 2px dashed transparent; outline-offset: 8px; transition: outline-color 0.2s; }
body.editing .section-block:hover { outline-color: rgba(37,99,235,0.4); }
body.editing .section-block.active-section { outline-color: #2563eb; }
[contenteditable="true"] { outline: none; border-radius: 3px; }
[contenteditable="true"]:focus { box-shadow: 0 0 0 2px rgba(37,99,235,0.3); }

/* ── Section toolbar ── */
.sec-toolbar { display: none; position: absolute; top: -12px; right: 12px; z-index: 50; background: white; border-radius: 8px; box-shadow: 0 2px 12px rgba(0,0,0,0.15); padding: 4px; gap: 2px; }
body.editing .section-block:hover .sec-toolbar,
body.editing .section-block.active-section .sec-toolbar { display: flex; }
.stb { width: 30px; height: 30px; border-radius: 5px; border: none; background: transparent; cursor: pointer; font-size: 13px; display: flex; align-items: center; justify-content: center; color: #333; }
.stb:hover { background: #f0f0f0; }
.stb.danger:hover { background: #fee2e2; color: #dc2626; }

/* ── Edit toggle button ── */
.edit-toggle-btn { position: fixed; bottom: 24px; left: 24px; z-index: 190; width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(8px); transition: all 0.2s; }
.edit-toggle-btn.active { background: #2563eb; border-color: #2563eb; }

/* ── AI FAB ── */
.ai-fab { position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: white; border: none; box-shadow: 0 4px 20px rgba(99,102,241,0.4); cursor: pointer; display: none; align-items: center; justify-content: center; z-index: 190; transition: transform 0.15s; }
.ai-fab:hover { transform: scale(1.05); }
body.editing .ai-fab { display: flex; }

/* ── AI Panel ── */
.ai-panel {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 250;
    background: white; border-top: 1px solid #e5e5e5;
    border-radius: 20px 20px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,0.1);
    color: #1a1a1a; transform: translateY(100%); transition: transform 0.3s;
    display: flex; flex-direction: column; max-height: 70vh;
}
.ai-panel.open { transform: translateY(0); }
.ai-panel-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 16px 12px; flex-shrink: 0;
}
.ai-header-left { display: flex; align-items: center; gap: 8px; }
.ai-header-left h3 { font-size: 16px; font-weight: 600; margin: 0; }
.ai-header-left .ai-dot { width: 8px; height: 8px; border-radius: 50%; background: linear-gradient(135deg, #6366f1, #8b5cf6); flex-shrink: 0; }
.ai-section-label { font-size: 12px; color: #888; font-weight: 400; }
.ai-close { width: 32px; height: 32px; border-radius: 50%; border: none; background: #f0f0f0; cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* Chat area */
.ai-chat-area {
    flex: 1; overflow-y: auto; padding: 0 16px;
    min-height: 0; scroll-behavior: smooth;
}
.ai-messages { display: flex; flex-direction: column; gap: 12px; }

/* Message bubbles */
.ai-msg { display: flex; flex-direction: column; max-width: 85%; }
.ai-msg-user { align-self: flex-end; }
.ai-msg-ai { align-self: flex-start; }
.ai-bubble {
    padding: 10px 14px; border-radius: 16px;
    font-size: 14px; line-height: 1.5; font-family: 'Source Sans 3', sans-serif;
    word-wrap: break-word;
}
.ai-bubble-user {
    background: linear-gradient(135deg, #6366f1, #8b5cf6); color: white;
    border-bottom-right-radius: 4px;
}
.ai-bubble-ai {
    background: #f3f4f6; color: #1a1a1a;
    border-bottom-left-radius: 4px;
}

/* Content preview */
.ai-preview {
    margin-top: 8px; padding: 12px; border-radius: 10px;
    border: 1.5px solid #e0e7ff; background: #f8faff;
    font-size: 13px; line-height: 1.5; max-height: 200px; overflow-y: auto;
}
.ai-preview p { margin: 0 0 8px; }
.ai-preview p:last-child { margin-bottom: 0; }
.ai-preview-label {
    font-size: 11px; font-weight: 600; color: #6366f1;
    text-transform: uppercase; letter-spacing: 0.05em;
    margin-bottom: 6px;
}
/* Card field preview */
.ai-card-field {
    padding: 3px 0; font-size: 13px; line-height: 1.4;
}
.ai-card-field strong {
    color: #6366f1; font-weight: 600;
}
.ai-preview-actions { display: flex; gap: 8px; margin-top: 8px; }
.ai-apply-btn {
    padding: 6px 16px; border-radius: 6px; border: none;
    background: #6366f1; color: white; font-size: 13px; font-weight: 600;
    font-family: inherit; cursor: pointer; transition: background 0.15s;
}
.ai-apply-btn:hover { background: #4f46e5; }
.ai-revise-btn {
    padding: 6px 16px; border-radius: 6px;
    border: 1.5px solid #e5e5e5; background: white; color: #333;
    font-size: 13px; font-weight: 500; font-family: inherit; cursor: pointer;
    transition: all 0.15s;
}
.ai-revise-btn:hover { border-color: #6366f1; color: #6366f1; }

/* Typing indicator */
.ai-typing {
    display: flex; align-items: center; gap: 4px;
    padding: 12px 14px; align-self: flex-start;
}
.ai-typing-dot {
    width: 8px; height: 8px; border-radius: 50%; background: #c4c4c4;
    animation: ai-bounce 1.4s ease-in-out infinite;
}
.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Previous conversation */
.ai-prev-convo { margin-bottom: 12px; }
.ai-prev-toggle {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border: none; border-radius: 4px;
    background: #f3f4f6; color: #666; font-size: 12px;
    font-family: inherit; cursor: pointer; transition: background 0.15s;
}
.ai-prev-toggle:hover { background: #e5e7eb; }
.ai-prev-arrow { font-size: 10px; transition: transform 0.2s; display: inline-block; }
.ai-prev-convo.open .ai-prev-arrow { transform: rotate(90deg); }
.ai-prev-messages {
    max-height: 0; overflow: hidden; opacity: 0;
    transition: max-height 0.3s ease, opacity 0.2s;
}
.ai-prev-convo.open .ai-prev-messages {
    max-height: 300px; opacity: 1; margin-top: 8px; overflow-y: auto;
}
.ai-prev-messages .ai-msg { opacity: 0.7; }

/* Quick actions */
.ai-quick-actions {
    display: flex; flex-wrap: wrap; gap: 8px;
    padding: 8px 16px; flex-shrink: 0;
}
.ai-quick-btn {
    padding: 6px 14px; border-radius: 20px;
    border: 1.5px solid #e5e5e5; background: white;
    font-size: 13px; font-family: inherit; cursor: pointer;
    transition: all 0.15s;
}
.ai-quick-btn:hover { border-color: #6366f1; background: #eef2ff; }

/* Input row */
.ai-input-row {
    display: flex; gap: 8px; padding: 12px 16px 16px;
    flex-shrink: 0; border-top: 1px solid #f0f0f0;
}
.ai-input {
    flex: 1; padding: 12px 14px; border: 1.5px solid #e5e5e5;
    border-radius: 12px; font-size: 15px; font-family: inherit;
    outline: none; resize: none; min-height: 44px; max-height: 120px;
    color: #1a1a1a;
}
.ai-input:focus { border-color: #6366f1; }
.ai-send {
    width: 44px; height: 44px; border-radius: 12px; border: none;
    background: linear-gradient(135deg, #6366f1, #8b5cf6); color: white;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.ai-send:disabled { opacity: 0.5; }

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

/* ── Site DNA Panel ── */
.dna-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 240;
}
.dna-overlay.open { display: block; }
.dna-panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 90vw; z-index: 245;
    background: #1a1a1a; color: #e8e4dc; box-shadow: -4px 0 24px rgba(0,0,0,0.3);
    display: flex; flex-direction: column;
    transform: translateX(100%); transition: transform 0.3s ease;
}
.dna-panel.open { transform: translateX(0); }
.dna-panel-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.dna-panel-header h3 {
    font-size: 16px; font-weight: 600; font-family: 'DM Sans', sans-serif; margin: 0;
    display: flex; align-items: center; gap: 8px;
}
.dna-panel-header h3::before {
    content: ''; width: 8px; height: 8px; border-radius: 50%;
    background: linear-gradient(135deg, #d4643a, #e8956a);
}
.dna-close {
    width: 32px; height: 32px; border-radius: 50%; border: none;
    background: rgba(255,255,255,0.1); color: #e8e4dc; cursor: pointer;
    font-size: 18px; display: flex; align-items: center; justify-content: center;
}
.dna-close:hover { background: rgba(255,255,255,0.2); }
.dna-panel-body {
    flex: 1; overflow-y: auto; padding: 20px;
}
.dna-label {
    display: block; font-size: 13px; font-weight: 600; color: #e8e4dc;
    margin-bottom: 4px; font-family: 'DM Sans', sans-serif;
}
.dna-hint {
    font-size: 12px; color: #9e9890; margin: 0 0 8px 0; line-height: 1.4;
}
.dna-textarea {
    width: 100%; min-height: 140px; padding: 12px; border-radius: 8px;
    border: 1.5px solid rgba(255,255,255,0.15); background: rgba(255,255,255,0.05);
    color: #e8e4dc; font-size: 14px; font-family: 'Source Sans 3', sans-serif;
    line-height: 1.5; resize: vertical; outline: none; box-sizing: border-box;
    margin-bottom: 20px;
}
.dna-textarea:focus { border-color: #d4643a; }
.dna-textarea::placeholder { color: #6e6a62; }
.dna-panel-footer {
    padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.1);
    display: flex; align-items: center; justify-content: space-between;
}
.dna-status { font-size: 13px; color: #9e9890; }
.dna-save {
    padding: 8px 20px; border-radius: 6px; border: none;
    background: #d4643a; color: white; font-size: 14px; font-weight: 600;
    font-family: 'DM Sans', sans-serif; cursor: pointer; transition: background 0.15s;
}
.dna-save:hover { background: #c05530; }

/* ── Section Context Bar ── */
.sec-context-bar {
    display: none; margin-bottom: 8px;
}
body.editing .sec-context-bar {
    display: block;
}
.sec-context-toggle {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border: none; border-radius: 4px;
    background: rgba(212,100,58,0.1); color: #d4643a;
    font-size: 11px; font-weight: 500; font-family: 'DM Sans', sans-serif;
    cursor: pointer; transition: background 0.15s;
    letter-spacing: 0.03em; text-transform: uppercase;
}
.sec-context-toggle:hover { background: rgba(212,100,58,0.2); }
.sec-context-arrow {
    font-size: 10px; transition: transform 0.2s; display: inline-block;
}
.sec-context-bar.open .sec-context-arrow { transform: rotate(90deg); }
.sec-context-body {
    max-height: 0; overflow: hidden; transition: max-height 0.3s ease, opacity 0.2s;
    opacity: 0;
}
.sec-context-bar.open .sec-context-body {
    max-height: 200px; opacity: 1; margin-top: 6px;
}
.sec-context-input {
    width: 100%; min-height: 60px; padding: 8px 10px; border-radius: 6px;
    border: 1px solid rgba(212,100,58,0.25); background: rgba(212,100,58,0.05);
    color: #e8e4dc; font-size: 13px; font-family: 'Source Sans 3', sans-serif;
    line-height: 1.4; resize: vertical; outline: none; box-sizing: border-box;
}
.sec-context-input:focus { border-color: #d4643a; }
.sec-context-input::placeholder { color: #6e6a62; font-size: 12px; }

/* ── Card Management ── */
.card-manage-wrap { position: relative; }
.card-drag-handle, .card-delete-btn, .card-add-btn, .card-link-input { display: none; }

body.editing .card-drag-handle {
    display: flex; position: absolute; top: 8px; left: 8px; z-index: 10;
    width: 44px; height: 44px; align-items: center; justify-content: center;
    border-radius: 8px; border: none; background: rgba(0,0,0,0.6); color: white;
    font-size: 20px; cursor: grab; touch-action: none; transition: background 0.15s;
}
body.editing .card-drag-handle:hover { background: rgba(0,0,0,0.8); }
body.editing .card-drag-handle:active { cursor: grabbing; }

body.editing .card-delete-btn {
    display: flex; position: absolute; top: 8px; right: 8px; z-index: 10;
    width: 44px; height: 44px; align-items: center; justify-content: center;
    border-radius: 8px; border: none; background: rgba(0,0,0,0.6); color: white;
    font-size: 22px; cursor: pointer; transition: background 0.15s, color 0.15s;
}
body.editing .card-delete-btn:hover { background: #dc2626; color: white; }

body.editing .card-link-input {
    display: block; width: 100%; padding: 6px 10px; margin-top: 8px;
    border: 1.5px solid rgba(255,255,255,0.2); border-radius: 6px;
    background: rgba(0,0,0,0.3); color: #e8e4dc; font-size: 13px;
    font-family: 'IBM Plex Mono', monospace; outline: none; box-sizing: border-box;
}
body.editing .card-link-input:focus { border-color: #2563eb; }

body.editing .card-add-btn {
    display: block; width: 100%; padding: 20px; margin-top: 24px;
    border: 2px dashed rgba(255,255,255,0.2); border-radius: 12px;
    background: transparent; color: rgba(255,255,255,0.5); font-size: 16px;
    font-family: inherit; font-weight: 500; cursor: pointer; transition: all 0.15s;
}
body.editing .card-add-btn:hover {
    border-color: #2563eb; color: #2563eb; background: rgba(37,99,235,0.05);
}

.card-dragging {
    opacity: 0.7; box-shadow: 0 8px 32px rgba(0,0,0,0.3); pointer-events: none;
}
.card-drag-placeholder {
    border: 2px dashed rgba(37,99,235,0.5); border-radius: 12px;
    background: rgba(37,99,235,0.05); min-height: 100px;
}

body.editing [data-card-field] { cursor: text; }
body.editing [data-card-field]:hover { outline: 1px dashed rgba(37,99,235,0.3); outline-offset: 2px; }

/* ── Toast ── */
.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px); background: #1a1a1a; color: white; padding: 12px 24px; border-radius: 12px; font-size: 14px; font-weight: 500; box-shadow: 0 4px 24px rgba(0,0,0,0.2); z-index: 300; opacity: 0; transition: all 0.3s; pointer-events: none; font-family: 'DM Sans', sans-serif; }
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
