/* ── ff WYSIWYG toolbar ──────────────────────────────────────────────── */

#ff-wysiwyg-bar {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 9998;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  padding: 3px 12px;
  display: flex;
  align-items: center;
  gap: 1px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.15s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
}

#ff-wysiwyg-bar.vw-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ── Button styles ──────────────────────────────────────────────────────── */

.vw-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 28px;
  padding: 0 6px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #374151;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease;
  white-space: nowrap;
}

.vw-btn:hover {
  background: #f1f5f9;
  color: #111827;
}

.vw-btn.vw-active {
  background: #e0e7ff;
  color: #3730a3;
}

.vw-btn:active {
  background: #c7d2fe;
}

.vw-btn i {
  font-size: 15px;
}

.vw-btn .vw-label {
  font-weight: 600;
  font-size: 12px;
  line-height: 1;
}

/* Separator */
.vw-sep {
  width: 1px;
  height: 20px;
  background: #e2e8f0;
  margin: 0 4px;
  flex-shrink: 0;
}

/* Group */
.vw-group {
  display: flex;
  align-items: center;
  gap: 1px;
}

/* ── Table context bar (inside main bar, right side) ────────────────────── */

.vw-table-ctx {
  display: none;
  align-items: center;
  gap: 1px;
  margin-left: auto;
  padding-left: 8px;
  border-left: 2px solid #c7d2fe;
}

.vw-table-ctx.vw-active {
  display: flex;
}

.vw-table-ctx .vw-btn {
  font-size: 11px;
  gap: 3px;
}

/* ── Link popup ─────────────────────────────────────────────────────────── */

#vw-link-popup {
  position: absolute;
  top: 100%;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  display: none;
  align-items: center;
  gap: 6px;
  z-index: 10;
}

#vw-link-popup.vw-open {
  display: flex;
}

#vw-link-url {
  width: 260px;
  padding: 5px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

#vw-link-url:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}

#vw-link-apply,
#vw-link-remove {
  padding: 5px 10px;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

#vw-link-apply {
  background: #4f46e5;
  color: #fff;
}

#vw-link-apply:hover {
  background: #4338ca;
}

#vw-link-remove {
  background: #fee2e2;
  color: #dc2626;
}

#vw-link-remove:hover {
  background: #fecaca;
}

/* ── Table grid picker ──────────────────────────────────────────────────── */

#vw-table-picker {
  position: absolute;
  top: 100%;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  display: none;
  flex-direction: column;
  align-items: center;
  z-index: 10;
}

#vw-table-picker.vw-open {
  display: flex;
}

.vw-grid {
  display: grid;
  grid-template-columns: repeat(6, 20px);
  grid-template-rows: repeat(6, 20px);
  gap: 2px;
}

.vw-grid-cell {
  width: 20px;
  height: 20px;
  border: 1px solid #d1d5db;
  border-radius: 2px;
  background: #fff;
  cursor: pointer;
  transition: background 0.05s ease, border-color 0.05s ease;
}

.vw-grid-cell.vw-highlight {
  background: #c7d2fe;
  border-color: #818cf8;
}

.vw-grid-label {
  margin-top: 6px;
  font-size: 12px;
  color: #6b7280;
  font-weight: 500;
}

/* ── Color + size buttons ───────────────────────────────────────────────── */

#vw-color-btn,
#vw-size-btn {
  gap: 2px;
  padding-right: 4px;
}

.vw-color-swatch-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  border-bottom: 3px solid var(--fnf-color-primary, #4f46e5);
  padding: 0 2px;
  line-height: 1;
}

.vw-caret {
  font-size: 9px;
  color: #9ca3af;
}

/* ── Color popover ──────────────────────────────────────────────────────── */

#vw-color-popup {
  position: absolute;
  top: 100%;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  display: none;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
}

#vw-color-popup.vw-open { display: flex; }

.vw-color-grid {
  display: grid;
  grid-template-columns: repeat(3, 28px);
  gap: 4px;
}

.vw-color-swatch {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  transition: transform 0.05s ease, box-shadow 0.05s ease;
}

.vw-color-swatch:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.vw-color-clear {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #fff;
  color: #64748b;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.vw-color-clear:hover { background: #f1f5f9; color: #111827; }

/* ── Size popover ──────────────────────────────────────────────────────── */

#vw-size-popup,
#vw-font-popup,
#vw-style-popup {
  position: absolute;
  top: 100%;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  display: none;
  flex-direction: column;
  min-width: 140px;
  z-index: 10;
}

#vw-size-popup.vw-open,
#vw-font-popup.vw-open,
#vw-style-popup.vw-open { display: flex; }

.vw-size-item {
  display: block;
  text-align: left;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: #374151;
  font-family: inherit;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1.2;
}

.vw-size-item:hover { background: #f1f5f9; color: #111827; }

/* ── Content-area table styling ─────────────────────────────────────────── */

[contenteditable] table,
[data-ff] table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: inherit;
}

[contenteditable] table th,
[contenteditable] table td,
[data-ff] table th,
[data-ff] table td {
  border: 1px solid #d1d5db;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  min-width: 60px;
}

[contenteditable] table th,
[data-ff] table th {
  background: #f8fafc;
  font-weight: 600;
}

[contenteditable] table tr:hover td,
[data-ff] table tr:hover td {
  background: #fafbfd;
}

/* Highlight active cell when editing */
[contenteditable] td:focus,
[contenteditable] th:focus {
  outline: 2px solid #6366f1;
  outline-offset: -2px;
}

/* ── AI assist (✨) ──────────────────────────────────────────────────────── */

#vw-ai-btn .vw-ai-spark {
  font-size: 16px;
  line-height: 1;
}

/* Subtle gradient hover so AI feels distinct from utility buttons. */
#vw-ai-btn:hover {
  background: linear-gradient(135deg, #ede9fe 0%, #fce7f3 100%);
}

#vw-ai-popup {
  position: absolute;
  top: 100%;
  margin-top: 4px;
  width: 360px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 11;
}

#vw-ai-popup.vw-open {
  display: flex;
}

.vw-ai-stage {
  display: none;
  flex-direction: column;
  gap: 8px;
}

.vw-ai-stage.vw-ai-current {
  display: flex;
}

.vw-ai-label {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}

#vw-ai-popup textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  outline: none;
}

#vw-ai-popup textarea:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}

.vw-ai-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vw-ai-segment {
  display: inline-flex;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  overflow: hidden;
}

.vw-ai-segment button {
  padding: 5px 12px;
  border: none;
  background: #fff;
  color: #374151;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  border-right: 1px solid #e5e7eb;
}

.vw-ai-segment button:last-child {
  border-right: none;
}

.vw-ai-segment button.vw-ai-active {
  background: #e0e7ff;
  color: #3730a3;
  font-weight: 600;
}

.vw-ai-segment button:hover:not(.vw-ai-active) {
  background: #f9fafb;
}

.vw-ai-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
}

.vw-ai-actions button {
  padding: 6px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.vw-ai-actions button:hover {
  background: #f3f4f6;
}

.vw-ai-actions button.vw-ai-primary {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

.vw-ai-actions button.vw-ai-primary:hover {
  filter: brightness(1.05);
}

.vw-ai-actions button.vw-ai-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.vw-ai-actions button.vw-ai-link {
  border: none;
  background: transparent;
  color: #6366f1;
  margin-right: auto;
  padding-left: 0;
}

.vw-ai-actions button.vw-ai-link:hover {
  text-decoration: underline;
  background: transparent;
}

.vw-ai-result {
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  color: #1f2937;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.vw-ai-result:focus {
  outline: none;
  border-color: #6366f1;
}

.vw-ai-meta {
  font-size: 11px;
  color: #6b7280;
}

.vw-ai-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 0;
  color: #6b7280;
  font-size: 13px;
}

.vw-ai-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #e5e7eb;
  border-top-color: #6366f1;
  border-radius: 50%;
  animation: vw-ai-spin 0.7s linear infinite;
}

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

.vw-ai-error {
  padding: 8px 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 12px;
  color: #991b1b;
}

/* Tone dropdown */
.vw-ai-tone-label {
  font-size: 12px;
  color: #4b5563;
}

#vw-ai-tone {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  color: #374151;
  background: #fff;
  outline: none;
  cursor: pointer;
}

#vw-ai-tone:focus {
  border-color: #6366f1;
}

/* Target-slot dropdown — same shape as tone */
#vw-ai-target {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  color: #374151;
  background: #fff;
  outline: none;
  cursor: pointer;
}

#vw-ai-target:focus {
  border-color: #6366f1;
}

#vw-ai-target optgroup {
  font-style: normal;
  font-weight: 600;
  color: #6b7280;
}

/* Rewrite-mode toggle (checkbox) */
.vw-ai-rewrite-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #4b5563;
  cursor: pointer;
  user-select: none;
}

.vw-ai-rewrite-toggle input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
  accent-color: #6366f1;
}

/* Source content preview (rewrite mode) */
.vw-ai-source {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  background: #f9fafb;
  border: 1px dashed #d1d5db;
  border-radius: 6px;
}

.vw-ai-source-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.vw-ai-source-text {
  font-size: 12px;
  line-height: 1.45;
  color: #6b7280;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
}
