/**
 * wik.ai Term Tooltip Styles
 *
 * Provides hover tooltips for technical terms with definitions
 * and links to full concept pages.
 */

/* Term reference styling */
.term-reference {
  border-bottom: 1px dotted #72777d;
  cursor: help;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.term-reference:hover {
  border-bottom-color: #0645ad;
  color: #0645ad;
}

/* Tooltip container */
.term-tooltip {
  position: absolute;
  z-index: 1000;
  width: 300px;
  max-width: 90vw;
  background: #fff;
  border: 1px solid #a2a9b1;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  font-size: 0.9em;
  font-family: 'Linux Libertine', 'Georgia', 'Times', serif;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.term-tooltip.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.term-tooltip.above {
  transform: translateX(-50%) translateY(-4px);
}

.term-tooltip.above.visible {
  transform: translateX(-50%) translateY(0);
}

/* Tooltip header */
.term-tooltip-header {
  padding: 0.5em 0.75em;
  border-bottom: 1px solid #eaecf0;
  display: flex;
  align-items: center;
  gap: 0.5em;
  flex-wrap: wrap;
}

/* Category badge */
.term-tooltip-category {
  font-size: 0.7em;
  padding: 2px 6px;
  border-radius: 3px;
  color: #fff;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Term name */
.term-tooltip-name {
  font-weight: bold;
  color: #202122;
}

/* Definition text */
.term-tooltip-definition {
  padding: 0.75em;
  color: #54595d;
  line-height: 1.5;
}

/* Read more link */
.term-tooltip-link {
  display: block;
  padding: 0.5em 0.75em;
  background: #f8f9fa;
  border-top: 1px solid #eaecf0;
  color: #0645ad;
  font-size: 0.85em;
  text-align: right;
  text-decoration: none;
  border-radius: 0 0 3px 3px;
}

.term-tooltip-link:hover {
  background: #eaecf0;
  text-decoration: none;
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .term-tooltip {
    width: 280px;
    font-size: 0.85em;
  }

  .term-tooltip-header {
    padding: 0.4em 0.6em;
  }

  .term-tooltip-definition {
    padding: 0.6em;
  }
}

/* ================================
   Selection Popup Styles
   ================================ */

.selection-popup {
  position: absolute;
  z-index: 1001;
  width: 320px;
  max-width: 90vw;
  background: #fff;
  border: 1px solid #a2a9b1;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  font-family: 'Linux Libertine', 'Georgia', 'Times', serif;
  font-size: 0.9em;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  pointer-events: none;
}

.selection-popup.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.selection-popup-content {
  padding: 0;
}

.selection-popup-title {
  padding: 0.6em 0.8em;
  border-bottom: 1px solid #eaecf0;
  font-weight: bold;
  color: #202122;
  display: flex;
  align-items: center;
  gap: 0.5em;
  flex-wrap: wrap;
}

.popup-category {
  font-size: 0.65em;
  padding: 2px 6px;
  border-radius: 3px;
  color: #fff;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.popup-unknown {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: #e5e7eb;
  color: #6b7280;
  border-radius: 50%;
  font-size: 0.75em;
  font-weight: bold;
}

.selection-popup-body {
  padding: 0.8em;
  color: #54595d;
  line-height: 1.5;
}

.selection-popup-actions {
  display: flex;
  gap: 0;
  border-top: 1px solid #eaecf0;
}

.popup-action {
  flex: 1;
  padding: 0.6em 0.8em;
  background: #f8f9fa;
  color: #0645ad;
  font-size: 0.85em;
  text-align: center;
  text-decoration: none;
  border-right: 1px solid #eaecf0;
  transition: background 0.1s ease;
}

.popup-action:last-child {
  border-right: none;
  border-radius: 0 0 5px 0;
}

.popup-action:first-child:last-child {
  border-radius: 0 0 5px 5px;
}

.popup-action:first-child {
  border-radius: 0 0 0 5px;
}

.popup-action:hover {
  background: #eaecf0;
  text-decoration: none;
}

/* Mobile adjustments for selection popup */
@media (max-width: 480px) {
  .selection-popup {
    width: 280px;
    font-size: 0.85em;
  }
}

/* ================================
   Improvement Modal Styles
   ================================ */

.improve-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
}

.improve-modal.visible {
  display: block;
}

.improve-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.improve-modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  max-width: 90vw;
  max-height: 85vh;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.improve-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1em 1.25em;
  border-bottom: 1px solid #eaecf0;
  background: #f8f9fa;
}

.improve-modal-header h3 {
  margin: 0;
  font-size: 1.1em;
  font-weight: 600;
  color: #202122;
}

.improve-modal-close {
  background: none;
  border: none;
  font-size: 1.5em;
  cursor: pointer;
  color: #72777d;
  padding: 0;
  line-height: 1;
}

.improve-modal-close:hover {
  color: #202122;
}

.improve-modal-body {
  padding: 1.25em;
  overflow-y: auto;
  flex: 1;
}

.improve-section {
  margin-bottom: 1.25em;
}

.improve-section:last-child {
  margin-bottom: 0;
}

.improve-section label {
  display: block;
  font-weight: 600;
  color: #54595d;
  margin-bottom: 0.5em;
  font-size: 0.9em;
}

.improve-selected-text {
  background: #f8f9fa;
  border: 1px solid #eaecf0;
  border-radius: 4px;
  padding: 0.75em;
  font-size: 0.9em;
  color: #202122;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.improve-section textarea {
  width: 100%;
  min-height: 100px;
  padding: 0.75em;
  border: 1px solid #a2a9b1;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.95em;
  resize: vertical;
  box-sizing: border-box;
}

.improve-section textarea:focus {
  outline: none;
  border-color: #36c;
  box-shadow: 0 0 0 2px rgba(51, 102, 204, 0.2);
}

.improve-suggestion {
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 4px;
  padding: 1em;
  font-size: 0.9em;
  color: #202122;
  max-height: 250px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.6;
}

.improve-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75em;
  padding: 1em 1.25em;
  border-top: 1px solid #eaecf0;
  background: #f8f9fa;
}

.improve-btn {
  padding: 0.6em 1.25em;
  border: 1px solid #a2a9b1;
  border-radius: 4px;
  font-size: 0.9em;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.improve-btn-cancel {
  background: #fff;
  color: #54595d;
}

.improve-btn-cancel:hover {
  background: #f8f9fa;
}

.improve-btn-generate {
  background: #36c;
  color: #fff;
  border-color: #36c;
}

.improve-btn-generate:hover {
  background: #2a5db0;
}

.improve-btn-generate:disabled {
  background: #a2a9b1;
  border-color: #a2a9b1;
  cursor: not-allowed;
}

.improve-btn-apply {
  background: #22c55e;
  color: #fff;
  border-color: #22c55e;
}

.improve-btn-apply:hover {
  background: #16a34a;
}

/* Mobile adjustments for modal */
@media (max-width: 640px) {
  .improve-modal-content {
    width: 95vw;
    max-height: 90vh;
  }

  .improve-modal-header,
  .improve-modal-body,
  .improve-modal-footer {
    padding: 0.75em 1em;
  }
}

/* ================================
   Block Preview Styles (for editing confirmation)
   ================================ */

.improve-block-info {
  background: #fefce8;
  border: 1px solid #fde047;
  border-radius: 4px;
  padding: 0.75em;
  margin-bottom: 1em;
}

.improve-block-preview {
  font-size: 0.85em;
}

.block-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5em;
  padding: 0.4em 0;
  flex-wrap: wrap;
}

.block-item code {
  background: #374151;
  color: #f9fafb;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85em;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', monospace;
  white-space: nowrap;
}

.block-tag {
  color: #6366f1;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', monospace;
  font-size: 0.85em;
}

.block-preview {
  color: #6b7280;
  font-size: 0.9em;
  flex: 1;
  min-width: 150px;
}

/* Confirmation preview styles */
.improve-confirm {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 4px;
  padding: 0.75em;
}

.confirm-block-id {
  margin-bottom: 0.75em;
  font-size: 0.9em;
}

.confirm-block-id code {
  background: #374151;
  color: #f9fafb;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85em;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', monospace;
}

.confirm-block-content {
  font-size: 0.85em;
}

.confirm-block-content .current-content {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 0.5em;
  margin-top: 0.5em;
}

.confirm-block-content pre {
  margin: 0.5em 0 0 0;
  padding: 0.5em;
  background: #f8f9fa;
  border-radius: 3px;
  font-size: 0.85em;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #374151;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', monospace;
}

/* Review & Confirm button style */
.improve-btn-confirm {
  background: #f59e0b;
  color: #fff;
  border-color: #f59e0b;
}

.improve-btn-confirm:hover {
  background: #d97706;
}

.improve-btn-apply:disabled {
  background: #a2a9b1;
  border-color: #a2a9b1;
  cursor: not-allowed;
}

/* ================================
   Three-Stage Modal Styles
   ================================ */

.improve-stage-indicator {
  font-size: 0.8em;
  color: #6b7280;
  background: #f3f4f6;
  padding: 4px 10px;
  border-radius: 12px;
  margin-left: auto;
  margin-right: 1em;
}

.improve-modal-header {
  display: flex;
  align-items: center;
}

.improve-stage {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* HTML Editor */
.html-editor {
  width: 100%;
  min-height: 200px;
  padding: 0.75em;
  border: 1px solid #a2a9b1;
  border-radius: 4px;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.85em;
  line-height: 1.5;
  resize: vertical;
  box-sizing: border-box;
  background: #1e1e1e;
  color: #d4d4d4;
}

.html-editor:focus {
  outline: none;
  border-color: #36c;
  box-shadow: 0 0 0 2px rgba(51, 102, 204, 0.2);
}

.html-status {
  font-weight: normal;
  font-size: 0.85em;
  margin-left: 0.5em;
}

/* Content Preview */
.improve-content-preview {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 1em;
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.9em;
  line-height: 1.6;
}

.improve-content-preview ul,
.improve-content-preview ol {
  margin: 0.5em 0 0.5em 1.5em;
}

.improve-content-preview li {
  margin: 0.3em 0;
}

/* Final HTML Preview */
.final-html-preview {
  background: #f8f9fa;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  max-height: 300px;
  overflow: auto;
}

.final-html-preview .html-code {
  margin: 0;
  padding: 1em;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.8em;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: #374151;
}

/* Validation Messages */
.validation-success {
  color: #16a34a;
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 4px;
  padding: 0.75em;
  font-size: 0.9em;
}

.validation-warning {
  color: #d97706;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 4px;
  padding: 0.75em;
  font-size: 0.9em;
}

/* Back Button */
.improve-btn-back {
  background: #fff;
  color: #54595d;
  margin-right: auto;
}

.improve-btn-back:hover {
  background: #f8f9fa;
}

/* Format Button (stage 2) */
.improve-btn-format {
  background: #8b5cf6;
  color: #fff;
  border-color: #8b5cf6;
}

.improve-btn-format:hover {
  background: #7c3aed;
}

/* Refine Section (Stage 2) */
.improve-refine-section {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 4px;
  padding: 0.75em;
  margin-top: 1em;
}

.improve-refine-section label {
  color: #0369a1;
  font-size: 0.85em;
}

.refine-input-row {
  display: flex;
  gap: 0.5em;
  margin-top: 0.5em;
}

.refine-input-row textarea {
  flex: 1;
  min-height: 60px;
  padding: 0.5em;
  border: 1px solid #a2a9b1;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.9em;
  resize: vertical;
}

.refine-input-row textarea:focus {
  outline: none;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2);
}

.improve-btn-refine {
  background: #0ea5e9;
  color: #fff;
  border-color: #0ea5e9;
  white-space: nowrap;
  align-self: flex-end;
  padding: 0.5em 1em;
}

.improve-btn-refine:hover {
  background: #0284c7;
}

.improve-btn-refine:disabled {
  background: #a2a9b1;
  border-color: #a2a9b1;
  cursor: not-allowed;
}
