/* ═══════════════════════════════════════════════════════════════
   AI Chat Panel — Modern Dark / Warm Amber Theme
   ─────────────────────────────────────────────────────────────
   #B68655  warm amber      — Analyze accents, badges, borders
   #E7C582  warm light gold — Ask accents, badges, borders
   #704F00  dark amber      — Active bg (selected toggle, buttons)
   #1E1E1E  near-black      — Panel background
   ═══════════════════════════════════════════════════════════════ */

/* ── Typing dots ──────────────────────────────────────────────── */
@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30%            { opacity: 1;    transform: translateY(-4px); }
}

.typing-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #B68655;
  margin: 0 2px;
  animation: typing-bounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }


/* ═══════════════════════════════════════════════════════════════
   FLOATING PANEL
   ═══════════════════════════════════════════════════════════════ */

.ai-chat-panel {
  position: fixed;
  top: 60px; right: 80px;
  width: 370px; height: 480px;
  min-width: 280px; min-height: 200px;
  max-width: 90vw; max-height: calc(100vh - var(--statusbar-height, 22px) - 60px);
  background: #1E1E1E;
  border-radius: 10px;
  border: 1px solid #2C2C2C;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 1050;
  display: flex; flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  will-change: left, top, width, height;
  transition: height 0.2s ease, width 0.2s ease;
  /* Hidden until JS restoreLayout() runs — prevents flash-of-floating-panel */
  visibility: hidden;
}

.ai-chat-panel.panel-collapsed        { height: auto !important; min-height: 0 !important; overflow: hidden; }
.ai-chat-panel.dragging,
.ai-chat-panel.resizing               { transition: none !important; }
.ai-chat-panel.dragging               { box-shadow: 0 12px 40px rgba(0,0,0,0.65); opacity: 0.95; cursor: grabbing; }


/* ═══════════════════════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════════════════════ */

.ai-chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: #222;
  border-bottom: 1px solid #2C2C2C;
  border-radius: 10px 10px 0 0;
  cursor: move;
  user-select: none; -webkit-user-select: none;
  flex-shrink: 0;
}
.ai-chat-panel.panel-collapsed .ai-chat-header { border-bottom: none; border-radius: 10px; }

.ai-chat-header-title { font-size: 12px; font-weight: 600; color: #C8B99A; letter-spacing: 0.04em; }

.ai-chat-toggle-btn {
  background: none; border: 1px solid #3A3A3A; border-radius: 4px;
  color: #777; font-size: 16px; font-weight: bold; cursor: pointer;
  padding: 0 6px; line-height: 1.2;
  transition: color 0.15s, border-color 0.15s;
  min-width: 24px; text-align: center;
}
.ai-chat-toggle-btn:hover { color: #DDD; border-color: #666; }


/* ═══════════════════════════════════════════════════════════════
   CONTENT & MESSAGES
   ═══════════════════════════════════════════════════════════════ */

.ai-chat-content {
  display: flex; flex-direction: column; flex: 1 1 0; min-height: 0; overflow: hidden;
}
.ai-chat-content.collapsed { display: none !important; }

.ai-chat-messages {
  flex: 1 1 0; min-height: 40px;
  overflow-y: auto; overflow-x: hidden;
  padding: 8px 10px;
}
.ai-chat-messages::-webkit-scrollbar       { width: 3px; }
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }
.ai-chat-messages::-webkit-scrollbar-thumb:hover { background: #555; }


/* ═══════════════════════════════════════════════════════════════
   INPUT AREA — transparent bg, stylish amber edge
   ═══════════════════════════════════════════════════════════════ */

.ai-chat-input-area {
  flex-shrink: 0;
  padding: 0 10px 10px;
}

/* ── Unified container: no fill, right-side accent line only ── */
.ai-input-container {
  background: transparent;
  border: none;
  border-right: 2px solid rgba(182, 134, 85, 0.35);
  border-radius: 8px;
  overflow: visible;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.ai-input-container:focus-within {
  border-right-color: rgba(182, 134, 85, 0.75);
  box-shadow: 4px 0 12px -4px rgba(182, 134, 85, 0.2);
}

/* Textarea — strip every possible background source, incl. browser autofill */
#ai-chat-panel #ai-chat-input,
#ai-chat-panel #ai-chat-input:focus,
#ai-chat-panel #ai-chat-input:hover,
.ai-input-container textarea,
.ai-input-container .dash-textarea {
  display: block;
  width: 100% !important;
  box-sizing: border-box;
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
  -webkit-appearance: none;
  caret-color: #B68655;
}

/* Kill browser autofill golden/yellow tint */
#ai-chat-panel #ai-chat-input:-webkit-autofill,
#ai-chat-panel #ai-chat-input:-webkit-autofill:focus,
#ai-chat-panel #ai-chat-input:-webkit-autofill:hover {
  -webkit-box-shadow: 0 0 0 100px #1E1E1E inset !important;
  -webkit-text-fill-color: #CCC !important;
  background-color: transparent !important;
}

/* Footer toolbar */
.ai-input-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 8px 7px;
}


/* ═══════════════════════════════════════════════════════════════
   MODE TOGGLE  ●ASK  ●ANALYZE
   Active  → border outline + bright text, NO background fill
   Dimmed  → no border, muted text
   ═══════════════════════════════════════════════════════════════ */

.ai-mode-toggle               { display: flex !important; gap: 4px !important; }
.ai-mode-toggle .form-check-input { display: none !important; }
.ai-mode-toggle .form-check,
.ai-mode-toggle .form-check-inline { margin: 0 !important; padding: 0 !important; }

/* Dimmed base */
.ai-mode-toggle .form-check-label {
  display: block;
  padding: 3px 10px;
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.07em;
  color: #3E3E3E;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
  line-height: 1.4;
  user-select: none;
}
.ai-mode-toggle .form-check-label:hover { color: #666; }

/* ── ASK active — gold outline, no fill ── */
.ai-mode-toggle .form-check-input[value="ask"]:checked + .form-check-label {
  background: transparent;
  color: #E7C582;
  border-color: rgba(231, 197, 130, 0.5);
}

/* ── ANALYZE active — amber outline, no fill ── */
.ai-mode-toggle .form-check-input[value="analyze"]:checked + .form-check-label {
  background: transparent;
  color: #B68655;
  border-color: rgba(182, 134, 85, 0.5);
}


/* ═══════════════════════════════════════════════════════════════
   SEND / STOP BUTTONS  — #704F00 bg, light text
   ═══════════════════════════════════════════════════════════════ */

#ai-chat-send-btn,
#ai-chat-stop-btn {
  transition: opacity 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
#ai-chat-send-btn:hover,
#ai-chat-stop-btn:hover {
  opacity: 0.88;
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(112, 79, 0, 0.45);
}
#ai-chat-send-btn:active,
#ai-chat-stop-btn:active { transform: scale(0.95); }


/* ═══════════════════════════════════════════════════════════════
   RESIZE HANDLES
   ═══════════════════════════════════════════════════════════════ */

.ai-chat-resize-left   { position: absolute; top: 30px; left: -3px;  width: 6px;  bottom: 10px; cursor: ew-resize; z-index: 2; }
.ai-chat-resize-right  { position: absolute; top: 30px; right: -3px; width: 6px;  bottom: 10px; cursor: ew-resize; z-index: 2; }
.ai-chat-resize-bottom { position: absolute; bottom: -3px; left: 10px; right: 10px; height: 6px; cursor: ns-resize; z-index: 2; }

.ai-chat-resize-corner {
  position: absolute; bottom: -3px; right: -3px;
  width: 14px; height: 14px; cursor: nwse-resize; z-index: 3;
}
.ai-chat-resize-corner::after {
  content: ""; position: absolute; bottom: 4px; right: 4px;
  width: 8px; height: 8px;
  border-right: 2px solid #3A3A3A; border-bottom: 2px solid #3A3A3A; opacity: 0.5;
}
.ai-chat-resize-corner:hover::after { border-color: #777; opacity: 1; }

.ai-chat-resize-corner-tl { position: absolute; top: -3px; left: -3px; width: 14px; height: 14px; cursor: nwse-resize; z-index: 3; }
.ai-chat-resize-corner-tr { position: absolute; top: -3px; right: -3px; width: 14px; height: 14px; cursor: nesw-resize; z-index: 3; }
.ai-chat-resize-corner-bl { position: absolute; bottom: -3px; left: -3px; width: 14px; height: 14px; cursor: nesw-resize; z-index: 3; }

.ai-chat-panel.panel-collapsed .ai-chat-resize-left,
.ai-chat-panel.panel-collapsed .ai-chat-resize-right,
.ai-chat-panel.panel-collapsed .ai-chat-resize-bottom,
.ai-chat-panel.panel-collapsed .ai-chat-resize-corner,
.ai-chat-panel.panel-collapsed .ai-chat-resize-corner-tl,
.ai-chat-panel.panel-collapsed .ai-chat-resize-corner-tr,
.ai-chat-panel.panel-collapsed .ai-chat-resize-corner-bl { display: none; }


/* ═══════════════════════════════════════════════════════════════
   PLOTLY MODEBAR  — transparent, warm amber highlight
   ID selector beats global .modebar rules in map_styles.css
   ═══════════════════════════════════════════════════════════════ */

#ai-chat-panel .modebar-container {
  display: flex !important; flex-direction: row !important;
  flex-wrap: nowrap !important; justify-content: flex-start !important;
  left: 10px !important; right: auto !important; top: 4px !important;
}
#ai-chat-panel .modebar             { background: transparent !important; background-color: transparent !important; border: none !important; box-shadow: none !important; padding: 0 !important; position: static !important; }
#ai-chat-panel .modebar-group       { display: flex !important; flex-direction: row !important; background: transparent !important; background-color: transparent !important; }
#ai-chat-panel .modebar-btn         { display: inline-flex !important; background: transparent !important; background-color: transparent !important; filter: none !important; }
#ai-chat-panel .modebar-btn:hover   { background: rgba(182,134,85,0.14) !important; background-color: rgba(182,134,85,0.14) !important; border-radius: 3px !important; }
#ai-chat-panel .modebar-btn:active,
#ai-chat-panel .modebar-btn.active  { background: transparent !important; background-color: transparent !important; }
#ai-chat-panel .modebar-btn:focus   { outline: none !important; box-shadow: none !important; }

#ai-chat-panel .modebar-btn path        { fill: rgba(180,165,145,0.38) !important; }
#ai-chat-panel .modebar-btn:hover path,
#ai-chat-panel .modebar-btn.active path { fill: #B68655 !important; }
#ai-chat-panel .modebar-btn svg         { width: 14px !important; height: 14px !important; }

#ai-chat-panel .modebar-icon,
#ai-chat-panel .modebar-btn:hover .modebar-icon,
#ai-chat-panel .modebar-btn.active .modebar-icon { filter: none !important; }


/* ═══════════════════════════════════════════════════════════════
   SUGGESTION CHIPS
   ═══════════════════════════════════════════════════════════════ */

.ai-suggestions-grid { display: flex; flex-direction: column; gap: 6px; }

.ai-suggestion-chip {
  background: rgba(182, 134, 85, 0.04);
  border: 1px solid rgba(182, 134, 85, 0.12);
  border-radius: 8px; color: #888; font-size: 11px;
  padding: 7px 10px; text-align: left; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  line-height: 1.3; white-space: normal;
}
.ai-suggestion-chip:hover  { background: rgba(182,134,85,0.09); border-color: rgba(182,134,85,0.28); color: #CCC; }
.ai-suggestion-chip:active { background: rgba(182,134,85,0.15); }


/* ═══════════════════════════════════════════════════════════════
   DOCKED MODE — panel fills sidebar tab content
   Height chain: sidebar → tab-content → tab-pane → dock-target → panel
   ═══════════════════════════════════════════════════════════════ */

/* Give the sidebar tab-content a fixed height so children can % from it.
   IMPORTANT: Do NOT change display — ilayout.js manages block/none.
   NOTE: .tab-content is inside #left-sidebar-tabs (dbc.Tabs wrapper), not a direct child. */
#left-sidebar .tab-content {
    height: calc(100vh - var(--statusbar-height, 22px)) !important;
    max-height: calc(100vh - var(--statusbar-height, 22px)) !important;
}

/* Ensure the dbc.Tabs wrapper propagates height from the sidebar */
#left-sidebar-tabs {
    height: 100%;
}

/* When the AI tab-pane is active, fill the height.
   dbc 2.x generates pane ID as {tabs_id}-tabpane-{tab_id}.
   Also target by className (sidebar__tab) and :has() as robust fallbacks. */
#left-sidebar-tabs-tabpane-tab-ai-assistant.active.show,
#left-sidebar-tabs-tabpane-tab-ai-assistant.active,
#tab-ai-assistant.tab-pane.active.show,
#tab-ai-assistant.tab-pane.active,
.tab-pane:has(> .ai-dock-target),
.sidebar__tab:has(> .ai-dock-target),
#left-sidebar .tab-content > *:has(> .ai-dock-target) {
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden;
}

.ai-dock-target {
    display: flex;
    flex-direction: column;
    /* height: 100%; */
    max-height: calc(100% - var(--statusbar-height, 22px) - 20px) !important;
    min-height: 0;
    overflow: hidden;
}

.ai-chat-panel.ai-chat-docked {
    position: relative !important;
    top: auto !important; left: auto !important; right: auto !important;
    width: 100% !important; height: 100% !important;
    max-width: none; max-height: none;
    min-height: 0;
    box-shadow: none;
    border-radius: 0;
    border: none;
    z-index: auto;
    overflow: hidden;
    visibility: visible;
}
.ai-chat-panel.ai-chat-docked .ai-chat-header {
    border-radius: 0;
    cursor: grab;
    flex-shrink: 0;
}
.ai-chat-panel.ai-chat-docked .ai-chat-content {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.ai-chat-panel.ai-chat-docked .ai-chat-messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
}
.ai-chat-panel.ai-chat-docked .ai-chat-input-area {
    flex-shrink: 0;
}
.ai-chat-panel.ai-chat-docked .ai-chat-resize-left,
.ai-chat-panel.ai-chat-docked .ai-chat-resize-right,
.ai-chat-panel.ai-chat-docked .ai-chat-resize-bottom,
.ai-chat-panel.ai-chat-docked .ai-chat-resize-corner,
.ai-chat-panel.ai-chat-docked .ai-chat-resize-corner-tl,
.ai-chat-panel.ai-chat-docked .ai-chat-resize-corner-tr,
.ai-chat-panel.ai-chat-docked .ai-chat-resize-corner-bl {
    display: none !important;
}


/* ═══════════════════════════════════════════════════════════════
   MISC
   ═══════════════════════════════════════════════════════════════ */

.ai-chat-panel details > summary                 { list-style: none; }
.ai-chat-panel details > summary::-webkit-details-marker { display: none; }
.ai-chat-panel .dash-table-container .dash-spreadsheet-container { background: transparent !important; }

.ai-chat-panel .btn-outline-secondary       { color: #777 !important; border-color: #333 !important; }
.ai-chat-panel .btn-outline-secondary:hover { color: #BBB !important; background-color: rgba(255,255,255,0.04) !important; }
