/* ===================================================
   SHARED HELP SYSTEM
   Reusable help popover component for all pages
   Created: December 2024
   =================================================== */

/* CSS Custom Properties - Override these per page if needed
   
   Example: To customize on a specific page, add to your page's CSS:
   
   :root {
     --help-popover-max-width: 400px;
     --help-popover-max-height: 80vh;
     --help-popover-min-width: 250px;
   }
   
   Or target specific screen sizes:
   @media (max-width: 768px) {
     :root {
       --help-popover-max-width: 90vw;
       --help-popover-max-height: 50vh;
     }
   }
*/
:root {
  --help-popover-max-width: 320px;
  --help-popover-max-height: 60vh; /* 60% of viewport height */
  --help-popover-min-width: 200px;
}

/* Help Icon Trigger */
/* Help Icon - MUST have consistent blue circle background everywhere */
span.help-icon,
.help-icon {
  cursor: pointer !important;
  color: #2196F3 !important;
  font-style: normal !important;
  font-weight: bold !important;
  margin-left: 4px !important;
  font-size: 14px !important;
  display: inline-block !important;
  width: 18px !important;
  height: 18px !important;
  line-height: 18px !important;
  text-align: center !important;
  border-radius: 50% !important;
  background-color: rgba(33, 150, 243, 0.15) !important;
  background: rgba(33, 150, 243, 0.15) !important;
  border: 1px solid rgba(33, 150, 243, 0.3) !important;
  box-sizing: border-box !important;
  transition: all 0.2s !important;
  user-select: none !important;
  flex-shrink: 0 !important;
  vertical-align: middle !important;
  position: relative !important;
  top: -1px !important;
}

span.help-icon:hover,
.help-icon:hover {
  background-color: rgba(33, 150, 243, 0.25) !important;
  background: rgba(33, 150, 243, 0.25) !important;
  border-color: rgba(33, 150, 243, 0.5) !important;
  transform: scale(1.15) !important;
}

/* Popover Container */
.help-popover {
  position: fixed; /* Changed from absolute to fixed for better positioning */
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  padding: 16px;
  width: 500px; /* Fixed width for consistency */
  max-width: calc(100vw - 40px); /* Don't exceed viewport width minus margins */
  max-height: var(--help-popover-max-height);
  overflow-y: auto; /* Enable scrolling when content exceeds max-height */
  overflow-x: hidden;
  z-index: 10000;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  /* Smooth scrolling for better UX */
  scroll-behavior: smooth;
}

/* Custom scrollbar styling for modern browsers */
.help-popover::-webkit-scrollbar {
  width: 8px;
}

.help-popover::-webkit-scrollbar-track {
  background: #f5f5f5;
  border-radius: 4px;
}

.help-popover::-webkit-scrollbar-thumb {
  background: #c0c0c0;
  border-radius: 4px;
  transition: background 0.2s;
}

.help-popover::-webkit-scrollbar-thumb:hover {
  background: #2196F3;
}

/* Firefox scrollbar styling */
.help-popover {
  scrollbar-width: thin;
  scrollbar-color: #c0c0c0 #f5f5f5;
}

.help-popover.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

/* Popover Arrows (default: below) */
.help-popover::before {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border: 8px solid transparent;
  border-bottom-color: white;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
}

.help-popover::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border: 9px solid transparent;
  border-bottom-color: #e0e0e0;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: -1;
}

/* Arrow positioning when popover appears above */
.help-popover.above::before {
  top: auto;
  bottom: -16px;
  border-bottom-color: transparent;
  border-top-color: white;
}

.help-popover.above::after {
  top: auto;
  bottom: -18px;
  border-bottom-color: transparent;
  border-top-color: #e0e0e0;
}

/* Arrow positioning when popover appears to the right */
.help-popover.right::before {
  top: 50%;
  left: -16px;
  transform: translateY(-50%);
  border-bottom-color: transparent;
  border-right-color: white;
}

.help-popover.right::after {
  top: 50%;
  left: -18px;
  transform: translateY(-50%);
  border-bottom-color: transparent;
  border-right-color: #e0e0e0;
}

/* Arrow positioning when popover appears to the left */
.help-popover.left::before {
  top: 50%;
  left: auto;
  right: -16px;
  transform: translateY(-50%);
  border-bottom-color: transparent;
  border-left-color: white;
}

.help-popover.left::after {
  top: 50%;
  left: auto;
  right: -18px;
  transform: translateY(-50%);
  border-bottom-color: transparent;
  border-left-color: #e0e0e0;
}

/* No arrow when centered */
.help-popover.center::before,
.help-popover.center::after {
  display: none;
}

/* Popover Header */
.help-popover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e0e0e0;
}

.help-popover-title {
  font-weight: 600;
  font-size: 14px;
  color: #333;
  display: flex;
  align-items: center;
  gap: 6px;
}

.help-popover-close {
  background: none;
  border: none;
  font-size: 20px;
  color: #999;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.help-popover-close:hover {
  background: #f5f5f5;
  color: #333;
}

/* Popover Content */
.help-popover-content {
  font-size: 13px;
  line-height: 1.6;
  color: #555;
  /* Ensure content doesn't break scrolling */
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.help-popover-content p {
  margin: 0 0 8px 0;
}

.help-popover-content p:last-child {
  margin-bottom: 0;
}

.help-popover-content strong {
  color: #333;
  font-weight: 600;
}

.help-popover-content code {
  background: #f5f5f5;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: #e91e63;
}

.help-popover-content ul {
  margin: 8px 0;
  padding-left: 20px;
}

.help-popover-content li {
  margin: 4px 0;
}

.help-popover-section {
  margin: 12px 0;
}

.help-popover-section-title {
  font-weight: 600;
  font-size: 12px;
  color: #2196F3;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ============================================ */
/* EXAMPLES SECTION */
/* ============================================ */

.help-examples {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e0e0e0;
}

.help-examples h5 {
  font-size: 14px;
  font-weight: 600;
  color: #2196F3;
  margin: 0 0 12px 0;
}

.help-examples-list {
  max-height: 400px;
  overflow-y: auto;
  padding-right: 8px;
}

.help-example-item {
  margin-bottom: 16px;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  overflow: hidden;
  transition: all 0.2s ease;
}

.help-example-item:hover {
  border-color: #2196F3;
  box-shadow: 0 2px 8px rgba(33, 150, 243, 0.1);
}

.help-example-title {
  font-size: 12px;
  font-weight: 600;
  color: #333;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

.help-example-code {
  margin: 0;
  padding: 12px;
  background: #f8f9fa;
  border: none;
  border-radius: 0;
  font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
  overflow-x: auto;
}

.help-example-code:hover {
  background: #e8f4f8;
  color: #2196F3;
}

.help-example-code:active {
  background: #4CAF50;
  color: white;
}

/* Scrollbar for examples list */
.help-examples-list::-webkit-scrollbar {
  width: 6px;
}

.help-examples-list::-webkit-scrollbar-track {
  background: #f0f0f0;
  border-radius: 3px;
}

.help-examples-list::-webkit-scrollbar-thumb {
  background: #c0c0c0;
  border-radius: 3px;
}

.help-examples-list::-webkit-scrollbar-thumb:hover {
  background: #a0a0a0;
}

/* ===================================================
   HELP ASSISTANT CHAT PANEL (global floating button + panel)
   Reuses this file's existing help-icon blue identity.
   =================================================== */
.help-assistant-button {
  width: 44px;
  height: 32px;
  background-color: var(--color-info);
  color: white;
  border: none;
  border-radius: 8px 0 0 8px;
  font-size: var(--font-size-base);
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  box-shadow: -2px 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.4s ease;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 8px;
}
.help-assistant-button:hover,
.help-assistant-button:focus,
.help-assistant-button.peeking {
  transform: translateX(0);
}

:root {
  --help-assistant-panel-width: 320px;
  --help-assistant-panel-max-height: 60vh;
}
[data-screen-mode="desktop"] {
  --help-assistant-panel-width: 460px;
  --help-assistant-panel-max-height: 70vh;
}

.help-assistant-panel {
  display: none;
  width: var(--help-assistant-panel-width);
  /* mirrors app_ui.css .help-assistant-panel bottom offset: logdivheight + --help-assistant-panel-bottom-offset */
  max-height: min(var(--help-assistant-panel-max-height), calc(100vh - var(--logdivheight) - var(--help-assistant-panel-bottom-offset) - 16px));
  /* 420px mirrors RESIZE_MIN_HEIGHT in js/help/chat_panel.js; capped by the same available space so the panel never runs off the top of the window */
  min-height: min(420px, calc(100vh - var(--logdivheight) - var(--help-assistant-panel-bottom-offset) - 16px));
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: var(--z-modal);
}
.help-assistant-panel.show { display: flex; opacity: 1; transform: translateY(0); }
.help-assistant-panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background-color: var(--color-info); color: white; font-weight: bold;
  flex-shrink: 0;
}
.help-assistant-panel-minimize,
.help-assistant-panel-maximize { background: none; border: none; color: white; font-size: 18px; cursor: pointer; }

.help-assistant-panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
}

#help-assistant-usage-badge {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.help-assistant-panel-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.help-assistant-thread {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  min-height: 0;
}

.help-assistant-exchange { margin-bottom: 16px; }
.help-assistant-exchange:last-child { margin-bottom: 0; }
.help-assistant-exchange-question {
  font-weight: bold;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-light);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 8px;
}
.help-assistant-exchange-answer { margin-bottom: 8px; }
.help-assistant-answer-message { font-size: 13px; color: var(--text-primary); line-height: 1.4; }
.help-assistant-real-answer {
  background-color: rgba(33, 150, 243, 0.08);
  border-left: 3px solid var(--color-info);
  border-radius: 4px;
  padding: 8px 10px;
}

/* Spacing only -- button visuals (color/background/border/sizing) come
   from the shared .btn/.btn-info/.btn-small system in app_ui.css. */
.help-assistant-take-me-there-btn {
  margin-bottom: 8px;
}

.help-assistant-exchange-references { margin-top: 4px; }
.help-assistant-references-summary {
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 0;
}
.help-assistant-references-summary:hover { color: var(--color-info); }
.help-assistant-references-list { margin-top: 4px; }

.help-assistant-input-row { display: flex; gap: 6px; padding: 8px 12px 12px; flex-shrink: 0; border-top: 1px solid #e0e0e0; }
.help-assistant-input-row textarea {
  flex: 1; padding: 6px 8px; border: 1px solid #ccc; border-radius: 4px;
  resize: none; font-family: inherit; font-size: 13px; min-height: 44px;
}
.help-assistant-input-row button {
  background-color: var(--color-info); color: white; border: none; border-radius: 4px; padding: 6px 12px; cursor: pointer;
  align-self: flex-end;
}
.help-assistant-word-count { padding: 0 12px 8px; text-align: right; flex-shrink: 0; }
.help-assistant-word-count.over-limit { color: var(--color-error); font-weight: bold; }

.help-assistant-result-item { border-bottom: 1px solid #e0e0e0; }
.help-assistant-result-summary { padding: 8px; cursor: pointer; }
.help-assistant-result-summary:hover { background-color: rgba(33, 150, 243, 0.08); }
.help-assistant-result-full-content { padding: 4px 8px 10px 8px; font-size: 12px; color: var(--text-primary); line-height: 1.4; }
.help-assistant-result-title { font-weight: bold; color: var(--color-info); font-size: 13px; }
.help-assistant-result-snippet { font-size: 12px; color: #555; margin-top: 2px; }
.help-assistant-loading, .help-assistant-empty { font-size: 13px; color: #777; padding: 8px; text-align: center; }
.help-assistant-highlight { outline: 3px solid var(--color-info); outline-offset: 2px; transition: outline-color 0.3s ease; }

.help-assistant-panel-resize-handle {
  top: 0;
  left: 0;
  width: 14px;
  height: 14px;
  background: transparent;
  border-radius: 8px 0 0 0;
}
.help-assistant-panel-resize-handle:hover {
  background: var(--color-info);
  opacity: 0.4;
}
[data-screen-mode="mobile"] .help-assistant-panel-resize-handle {
  display: none;
}
