/**
 * Fullwidth Mode Three-Column Layout
 * Enhanced styles for Widget/Sidebar/Fullwidth modes with Weavy integration
 */

/* ============================================
   Fullwidth Layout Structure
   ============================================ */

.ai_modal.fullwidth-mode {
  --fw-left: 280px;
  --fw-right: 320px;
  display: grid;
  grid-template-columns: var(--fw-left) 1fr var(--fw-right);
  gap: 0;
  position: fixed;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: min(1400px, 96vw);
  height: min(900px, 92vh);
  max-width: 96vw;
  max-height: 92vh;
  border-radius: 16px;
  background: linear-gradient(to bottom, #e8f4f8 0%, #ffffff 100%) !important;
  overflow: visible;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}

/* Wrapper spans all columns and creates layout for children */
.ai_modal.fullwidth-mode .ai_modal_wrapper {
  grid-column: 1 / -1 !important;
  display: grid !important;
  grid-template-columns: var(--fw-left) 1fr var(--fw-right) !important;
  grid-template-rows: auto 1fr !important;
  height: 100%;
  width: 100%;
  background: linear-gradient(to bottom right, #acd2e4 4%, #f2f4f7 30%, #f2f4f7 30%, #f2f4f7 40%, #b2ccff97);
  border: 1px solid #d0d5dd;
  border-radius: 16px;
  overflow: hidden;
  padding: 15px !important;
  gap: 0 !important;
  box-sizing: border-box !important;
}

/* Left Column - History */
.sg-wavy-fullwidth-history {
  grid-column: 1 !important;
  grid-row: 1 / -1 !important;
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  width: 100% !important;
  box-sizing: border-box;
  padding: 0 24px 24px !important;
}

/* Header spans remaining space (center + right) to fill background */
.ai_modal.fullwidth-mode .modal-header {
  grid-column: 2 / -1 !important;
  grid-row: 1 !important;
  width: 100% !important;
  box-sizing: border-box !important;
  padding: 16px 24px 0 !important;
  display: flex !important;
  align-items: center !important;
  gap: 16px !important;
}

.ai_modal.fullwidth-mode .sg-wavy-header-search {
  flex: 1 !important;
  max-width: none !important;
}

.ai_modal.fullwidth-mode .sg-wavy-header-actions {
  margin-left: auto !important;
  display: flex !important;
  flex-direction: row !important;
  gap: 12px !important;
  align-items: center !important;
}

.fullwidth-history-header {
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
  background: white;
}

.history-search {
  width: 100%;
  padding: 10px 12px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: var(--gf-text-body);
  color: #1f2937;
  transition: all 160ms cubic-bezier(0.2, 0, 0, 1);
  margin-bottom: 12px;
}

.history-search:focus {
  outline: none;
  background: white;
  border-color: #2966F4;
  box-shadow: 0 0 0 3px rgba(41, 112, 255, 0.1);
}

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: linear-gradient(135deg, #2966F4 0%, #2054CC 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: var(--gf-text-body);
  font-weight: var(--gf-weight-semibold);
  cursor: pointer;
  transition: transform 160ms cubic-bezier(0.2, 0, 0, 1);
}

.new-chat-btn:hover {
  transform: translateY(-1px);
}

.new-chat-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.5;
}

/* History List */
.fullwidth-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.history-group {
  margin-bottom: 16px;
}

.history-group-title {
  padding: 8px 12px;
  font-size: var(--gf-text-caption);
  font-weight: var(--gf-weight-semibold);
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-item {
  padding: 12px;
  margin-bottom: 4px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: all 160ms cubic-bezier(0.2, 0, 0, 1);
}

.history-item:hover {
  background: #f9fafb;
  border-color: #d1d5db;
  transform: translateX(2px);
}

.history-item.active {
  background: linear-gradient(135deg, rgba(41, 112, 255, 0.1) 0%, rgba(0, 78, 235, 0.1) 100%);
  border-color: #2966F4;
}

.history-item-title {
  font-size: var(--gf-text-body);
  font-weight: var(--gf-weight-semibold);
  color: #1f2937;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item.active .history-item-title {
  color: #2966F4;
}

.history-item-preview {
  font-size: var(--gf-text-caption);
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: #9ca3af;
  font-size: var(--gf-text-body);
}

/* Center content spans remaining space (center + right) to fill background */
.ai_modal.fullwidth-mode .modal-content {
  grid-column: 2 / -1 !important;
  grid-row: 2 !important;
  background: transparent;
  width: 100% !important;
  box-sizing: border-box;
  padding: 20px 24px 20px !important;
  overflow-y: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.ai_modal.fullwidth-mode .sg-wavy-header-search {
  flex: 0 1 400px !important;
  max-width: 400px !important;
}

.ai_modal.fullwidth-mode .sg-wavy-header-actions {
  margin-left: auto !important;
  display: flex !important;
  gap: 12px !important;
}

/* Keep initial screen on gradient background */
.ai_modal.fullwidth-mode #sgWavyModalInitial {
  background: transparent;
}

.ai_modal.fullwidth-mode #sgWavyModalChat {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.ai_modal.fullwidth-mode .sg-wavy-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 24px !important;
  width: 100% !important;
  max-width: 100% !important;
}

.ai_modal.fullwidth-mode .sg-wavy-textarea-container {
  padding: 16px 24px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

/* Right Column - Inspector (hidden, content spans its space) */
.sg-wavy-inspector {
  display: none !important;
}

.inspector-tabs {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.inspector-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: var(--gf-text-caption);
  font-weight: var(--gf-weight-medium);
  color: #6b7280;
  cursor: pointer;
  transition: all 160ms cubic-bezier(0.2, 0, 0, 1);
}

.inspector-tab:hover {
  color: #1f2937;
  background: #f3f4f6;
}

.inspector-tab.active {
  color: #2966F4;
  border-bottom-color: #2966F4;
  background: white;
}

.inspector-tab svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

.inspector-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.inspector-panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 160ms cubic-bezier(0.2, 0, 0, 1);
}

.inspector-panel.active {
  opacity: 1;
  visibility: visible;
}

/* Document container in chat */
.sg-wavy-document-container {
  padding: 0;
  max-height: none;
  overflow: visible;
}

/* Session title */
.sg-wavy-session-title {
  font-size: var(--gf-text-card);
  font-weight: var(--gf-weight-semibold);
  color: #1f2937;
  padding: 16px 24px;
  border-bottom: 1px solid #e5e7eb;
  background: white;
}

/* Tool message in chat */
.sg-wavy-tool-message {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin: 8px 0;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  max-width: 400px;
}

.tool-message-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.tool-message-content {
  flex: 1;
}

.tool-message-title {
  font-size: var(--gf-text-caption);
  font-weight: var(--gf-weight-semibold);
  color: #1f2937;
  margin-bottom: 2px;
}

.tool-message-status {
  font-size: var(--gf-text-caption);
  color: #6b7280;
}

/* ============================================
   Widget Mode Enhancements
   ============================================ */

.ai_modal:not(.sidebar-mode):not(.fullwidth-mode) .sg-wavy-document-container {
  max-height: none;
  overflow: visible;
  padding: 0;
}

.ai_modal:not(.sidebar-mode):not(.fullwidth-mode) .sg-wavy-document-preview {
  padding: 12px;
}

.ai_modal:not(.sidebar-mode):not(.fullwidth-mode) .doc-preview-summary,
.ai_modal:not(.sidebar-mode):not(.fullwidth-mode) .doc-preview-structure {
  display: block;
}

.ai_modal:not(.sidebar-mode):not(.fullwidth-mode) .sg-wavy-composer-actions {
  flex-wrap: wrap;
}

/* ============================================
   Sidebar Mode Enhancements
   ============================================ */

.ai_modal.sidebar-mode .sg-wavy-document-container {
  max-height: none;
  overflow: visible;
  padding: 0;
}

.ai_modal.sidebar-mode .sg-wavy-composer-actions {
  flex-wrap: wrap;
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 1400px) {
  .ai_modal.fullwidth-mode {
    --fw-left: 260px;
    --fw-right: 300px;
  }
}

@media (max-width: 1200px) {
  .ai_modal.fullwidth-mode {
    --fw-left: 240px;
    --fw-right: 280px;
  }
  
  .sg-wavy-fullwidth-history {
    font-size: var(--gf-text-caption);
  }
  
  .history-item-title {
    font-size: var(--gf-text-caption);
  }
}

@media (max-width: 1024px) {
  .ai_modal.fullwidth-mode {
    --fw-left: 220px;
    --fw-right: 260px;
  }
  
  .inspector-tab {
    font-size: var(--gf-text-caption);
    padding: 12px 8px;
  }
  
  .inspector-tab svg {
    width: 14px;
    height: 14px;
  }
}

/* Mobile fallback */
@media (max-width: 768px) {
  .ai_modal.fullwidth-mode {
    --fw-left: 0px;
    --fw-right: 0px;
    grid-template-columns: 1fr;
    width: 96vw;
    height: 92vh;
  }
  
  .sg-wavy-fullwidth-history,
  .sg-wavy-inspector {
    display: none;
  }
  
  .ai_modal.fullwidth-mode .modal-content {
    grid-column: 1;
    border-right: none;
  }
}

/* ============================================
   Animations
   ============================================ */

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

.history-item,
.sg-wavy-document-preview {
  animation: fadeInUp 0.3s ease;
}

/* ============================================
   Scrollbar Styling
   ============================================ */

.fullwidth-history-list::-webkit-scrollbar,
.sg-wavy-document-container::-webkit-scrollbar,
.inspector-panel::-webkit-scrollbar {
  width: 6px;
}

.fullwidth-history-list::-webkit-scrollbar-track,
.sg-wavy-document-container::-webkit-scrollbar-track,
.inspector-panel::-webkit-scrollbar-track {
  background: transparent;
}

.fullwidth-history-list::-webkit-scrollbar-thumb,
.sg-wavy-document-container::-webkit-scrollbar-thumb,
.inspector-panel::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.fullwidth-history-list::-webkit-scrollbar-thumb:hover,
.sg-wavy-document-container::-webkit-scrollbar-thumb:hover,
.inspector-panel::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  .sg-wavy-fullwidth-history,
  .sg-wavy-inspector,
  .sg-wavy-composer-actions,
  .sg-wavy-textarea-container {
    display: none !important;
  }
  
  .ai_modal.fullwidth-mode {
    grid-template-columns: 1fr;
  }
  
  .sg-wavy-chat-messages {
    overflow: visible !important;
    height: auto !important;
  }
}
