/* Groundwise Visual Content Editor — Overlay & UI Styles */
/* Loaded only when edit mode is active (cookie-verified) */

/* ─── Editable Element Overlays ─────────────────────────────────────── */
.gw-editable {
    outline: 2px dashed rgba(58, 78, 122, 0.3);
    outline-offset: 2px;
    cursor: pointer;
    transition: outline-color 0.2s ease, background-color 0.2s ease;
    border-radius: 3px;
}
.gw-editable:hover {
    outline-color: rgba(58, 78, 122, 0.7);
    background-color: rgba(58, 78, 122, 0.05);
}
.gw-editable.gw-editing {
    outline: 2px solid #3A4E7A;
    background-color: rgba(58, 78, 122, 0.08);
}

/* Block-level editable: ensures outline wraps block children properly */
.gw-editable.gw-editable-block {
    display: block;
}

/* ─── Source Color Coding ───────────────────────────────────────────── */
/* RED = content loaded from localStorage (unsaved local edit) */
.gw-editable.gw-source-local {
    outline-color: #e74c3c;
    background-color: rgba(231, 76, 60, 0.04);
}
.gw-editable.gw-source-local:hover {
    outline-color: #c0392b;
    background-color: rgba(231, 76, 60, 0.08);
}

/* GREEN = content from the template (unmodified, server-rendered) */
.gw-editable.gw-source-template {
    outline-color: #27ae60;
    background-color: rgba(39, 174, 96, 0.04);
}
.gw-editable.gw-source-template:hover {
    outline-color: #1e8449;
    background-color: rgba(39, 174, 96, 0.08);
}

/* BLUE = content saved to database */
.gw-editable.gw-source-saved {
    outline-color: #3498db;
    background-color: rgba(52, 152, 219, 0.04);
}
.gw-editable.gw-source-saved:hover {
    outline-color: #2980b9;
    background-color: rgba(52, 152, 219, 0.08);
}

/* ─── Corner Menu ──────────────────────────────────────────────────── */
#gw-editor-menu {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.gw-em-toggle {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: #3A4E7A;
    color: white;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    font-size: 16px;
}
.gw-em-toggle:hover { background: #2c3d5e; transform: scale(1.1); box-shadow: 0 4px 16px rgba(0,0,0,0.35); }
.gw-em-toggle.gw-em-active { background: #A8C64A; }
.gw-em-toggle.gw-em-active:hover { background: #97b53d; }
.gw-em-count {
    position: absolute; top: -4px; right: -4px;
    background: #e74c3c; color: white;
    border-radius: 10px; padding: 1px 6px;
    font-size: 11px; font-weight: 700;
    display: none;
    line-height: 16px;
}
.gw-em-panel {
    position: absolute; bottom: 48px; right: 0;
    width: 300px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    overflow: hidden;
    transform-origin: bottom right;
    animation: gw-panel-pop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes gw-panel-pop {
    0% { opacity: 0; transform: scale(0.7) translateY(8px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
.gw-em-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    background: #3A4E7A; color: white;
}
.gw-em-header h4 { margin: 0; font-size: 14px; }
.gw-em-close { background: none; border: none; color: white; cursor: pointer; font-size: 16px; opacity: 0.8; }
.gw-em-close:hover { opacity: 1; }

/* ─── Legend ────────────────────────────────────────────────────────── */
.gw-em-legend {
    display: flex; gap: 12px; padding: 8px 16px;
    border-bottom: 1px solid #eee; font-size: 11px; color: #666;
}
.gw-em-legend-item {
    display: flex; align-items: center; gap: 4px;
}

.gw-em-stats { padding: 10px 16px; border-bottom: 1px solid #eee; }
.gw-em-stat { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.gw-em-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.gw-em-actions { padding: 10px 16px; display: flex; gap: 6px; border-bottom: 1px solid #eee; flex-wrap: wrap; }
.gw-em-btn, .gw-em-actions a.gw-em-btn {
    flex: 1; padding: 7px 6px; border: none; border-radius: 5px;
    font-size: 11px; font-weight: 600; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 4px;
    transition: all 0.15s ease;
    text-decoration: none; color: white;
}
.gw-em-btn-db { background: #27ae60; color: white; }
.gw-em-btn-db:hover { background: #219a52; }
.gw-em-btn-publish { background: #3498db; color: white; }
.gw-em-btn-publish:hover { background: #2980b9; }
.gw-em-btn-clear { background: #e74c3c; color: white; flex: 0; padding: 7px 10px; }
.gw-em-btn-clear:hover { background: #c0392b; }
.gw-em-btn-exit { background: #6c757d; color: white; }
.gw-em-btn-exit:hover { background: #5a6268; }

/* Fetcher link — centered flex container at bottom of panel */
.gw-em-fetcher-link {
    display: flex; justify-content: center; padding-top: 8px;
}
.gw-em-fetcher-btn {
    position: relative;
    width: 36px; height: 36px; border-radius: 50%;
    background: #fff; color: #3A4E7A;
    display: flex; align-items: center; justify-content: center;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    border: 2px solid #e8e8e8;
    transition: all 0.2s ease;
}
.gw-em-fetcher-btn:hover { transform: scale(1.1); box-shadow: 0 4px 12px rgba(0,0,0,0.2); border-color: #3A4E7A; }
.gw-em-fetcher-btn:focus { outline: 2px solid #3A4E7A; outline-offset: 2px; }
.gw-em-fetcher-icon {
    width: 24px; height: 24px; border-radius: 4px; object-fit: cover;
}
.gw-em-fetcher-overlay {
    position: absolute; bottom: -2px; right: -2px;
    width: 14px; height: 14px; border-radius: 50%;
    background: #3A4E7A; color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 8px; font-weight: bold;
    border: 2px solid white;
}
.gw-em-edits-list { max-height: 200px; overflow-y: auto; padding: 8px 16px; }
.gw-em-edit-item { padding: 6px 0; border-bottom: 1px solid #f0f0f0; display: flex; justify-content: space-between; align-items: center; }
.gw-em-edit-path { font-size: 11px; color: #555; font-family: monospace; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gw-em-edit-status { font-size: 10px; padding: 2px 6px; border-radius: 3px; font-weight: 600; text-transform: uppercase; margin-left: 8px; }
.gw-em-status-local { background: #fef3cd; color: #856404; }
.gw-em-status-db { background: #d4edda; color: #155724; }
.gw-em-status-published { background: #cce5ff; color: #004085; }
.gw-em-empty { font-size: 12px; color: #999; padding: 12px 0; text-align: center; }

/* ─── Edit Modal ───────────────────────────────────────────────────── */
.gw-edit-modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100000;
    display: flex; align-items: center; justify-content: center;
}
.gw-edit-modal {
    background: white; border-radius: 10px; width: 90%; max-width: 600px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    overflow: hidden;
    max-height: 90vh; display: flex; flex-direction: column;
}
.gw-edit-modal-lg { max-width: 800px; }
.gw-edit-modal-header {
    padding: 14px 18px; background: #3A4E7A; color: white;
    display: flex; justify-content: space-between; align-items: center;
    flex-shrink: 0;
}
.gw-edit-modal-header h4 { margin: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gw-edit-modal-body {
    padding: 18px; overflow-y: auto; overflow-x: hidden;
    flex: 1 1 auto; min-height: 0;
}
.gw-edit-modal-body textarea {
    width: 100%; min-height: 150px; border: 1px solid #ccc; border-radius: 6px;
    padding: 10px; font-size: 14px; font-family: inherit; resize: vertical;
    max-width: 100%; box-sizing: border-box;
}
.gw-edit-modal-body .gw-edit-label {
    font-size: 12px; color: #888; margin-bottom: 6px; font-family: monospace;
}
.gw-edit-modal-footer {
    padding: 12px 18px; border-top: 1px solid #eee;
    display: flex; justify-content: flex-end; gap: 8px;
    flex-shrink: 0;
}
.gw-edit-modal-footer button {
    padding: 8px 16px; border: none; border-radius: 5px;
    font-size: 13px; font-weight: 600; cursor: pointer;
}
.gw-edit-btn-cancel { background: #eee; color: #555; }
.gw-edit-btn-cancel:hover { background: #ddd; }
.gw-edit-btn-save { background: #3A4E7A; color: white; }
.gw-edit-btn-save:hover { background: #2c3d5e; }

/* ─── HTML Field (SunEditor MIT + Monaco Toggle) ─────────────────── */
.gw-html-field {
    width: 100%; min-width: 0; overflow: hidden;
    box-sizing: border-box;
}
.gw-html-toggle {
    display: flex; gap: 0; margin-bottom: 8px;
}
.gw-html-toggle-btn {
    padding: 5px 12px; border: 1px solid #ccc; background: #f5f5f5; color: #666;
    font-size: 11px; font-weight: 600; cursor: pointer;
    display: flex; align-items: center; gap: 4px;
    transition: all 0.15s ease;
}
.gw-html-toggle-btn:first-child { border-radius: 4px 0 0 4px; }
.gw-html-toggle-btn:last-child  { border-radius: 0 4px 4px 0; border-left: none; }
.gw-html-toggle-btn.active {
    background: #3A4E7A; color: white; border-color: #3A4E7A;
}
.gw-html-toggle-btn:hover:not(.active) { background: #e9ecef; }
.gw-html-textarea {
    display: none;
}
.gw-html-monaco {
    display: none;
    width: 100%; height: 380px;
    border: 1px solid #ccc; border-radius: 6px;
    overflow: hidden;
}
/* SunEditor container to fit inside modal */
.gw-edit-modal .sun-editor {
    border-radius: 6px !important;
    border: 1px solid #ccc !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    width: 100% !important;
}
.gw-edit-modal .sun-editor .se-wrapper {
    max-width: 100% !important;
}
/* Prevent SunEditor content area from blowing out width */
.gw-edit-modal .se-wrapper-inner,
.gw-edit-modal .se-wrapper-wysiwyg {
    overflow: auto !important;
}
/* Hide textarea when SunEditor is active */
.gw-html-textarea[data-sun="1"] { display: none !important; }
.gw-html-textarea[data-tiny="1"] { display: none !important; }
