/* Utility */
.hidden {
  display: none !important;
}

/* IDE Container */
.ide-container {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* Left Sidebar */
.ide-sidebar {
  width: 250px;
  min-width: 150px;
  max-width: 500px;
  background: #f5f5f5;
  border-right: none;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Sidebar Resize Handle */
.sidebar-resize-handle {
  width: 4px;
  cursor: col-resize;
  background: #ddd;
  transition: background 0.15s;
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle.dragging {
  background: #007bff;
}

.ide-sidebar h2 {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
}

.ide-sidebar h3 {
  margin: 1rem 0 0.5rem 0;
  font-size: 1rem;
  color: #666;
}

/* Main Editor Area */
.ide-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  overflow: hidden;
  min-height: 0;
}

.ide-editor > turbo-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.ide-editor > turbo-frame > form,
.ide-editor > form {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.document-title-input {
  font-size: 1.5rem;
  font-weight: bold;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 0.5rem 0;
  width: 100%;
  margin-bottom: 1rem;
}

.document-title-input:focus {
  outline: none;
  border-bottom: 1px solid #007bff;
}

/* Trix Editor Styling */
.ide-editor trix-editor {
  flex: 1;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 1rem;
  min-height: 0;
}

.ide-editor trix-toolbar {
  flex-shrink: 0;
  border: 1px solid #ddd;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  background: #fafafa;
}

.ide-editor .editor-header {
  flex-shrink: 0;
}

/* Chat Sidebar */
.chat-sidebar {
  width: 300px;
  min-width: 300px;
  background: #f5f5f5;
  border-left: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-sidebar.hidden {
  display: none;
}

.chat-sidebar h3 {
  margin: 0;
  padding: 1rem;
  border-bottom: 1px solid #ddd;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.message {
  margin-bottom: 1rem;
  padding: 0.75rem;
  border-radius: 8px;
}

.message.user {
  background: #007bff;
  color: white;
  margin-left: 2rem;
}

.message.assistant {
  background: #e9ecef;
  margin-right: 2rem;
}

.message.tool {
  background: #fff3cd;
  font-family: monospace;
  font-size: 0.875rem;
}

/* Research Items */
#research-items {
  max-height: 200px;
  overflow-y: auto;
}

/* Chats Section */
.chats-section {
  margin-top: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.chats-header h3 {
  margin: 0;
}

.new-chat-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.new-chat-btn:hover {
  background: #0056b3;
}

#conversations-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 0.25rem;
  background: white;
}

.conversation-item.active {
  border-color: #007bff;
  background: #e7f1ff;
}

.conversation-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem;
  text-decoration: none;
  color: inherit;
}

.conversation-link:hover {
  background: #f0f0f0;
}

.conversation-item.active .conversation-link:hover {
  background: #d0e4ff;
}

.conversation-title {
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.conversation-date {
  font-size: 0.75rem;
  color: #666;
  margin-left: 0.5rem;
}

/* Chat Header */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid #ddd;
}

.chat-header h3 {
  margin: 0;
  padding: 0;
  border: none;
}

.chat-header button {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: #666;
}

.chat-header button:hover {
  color: #333;
}

/* Selection Indicator */
.selection-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
  font-size: 0.8rem;
}

.selection-indicator.hidden {
  display: none;
}

.selection-label {
  font-weight: bold;
  color: #856404;
  white-space: nowrap;
}

.selection-preview {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #856404;
  font-style: italic;
}

.selection-clear {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: #856404;
  padding: 0 0.25rem;
  line-height: 1;
}

.selection-clear:hover {
  color: #533f03;
}

/* Chat Input */
.chat-input {
  padding: 1rem;
  border-top: 1px solid #ddd;
}

.chat-input textarea {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 0.5rem;
  resize: none;
  margin-bottom: 0.5rem;
}

.chat-input input[type="submit"] {
  width: 100%;
  padding: 0.5rem;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.chat-input input[type="submit"]:hover {
  background: #0056b3;
}

/* Thinking Indicator */
.message.thinking {
  opacity: 0.7;
}

.thinking-dots span {
  animation: blink 1.4s infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%, 20% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

/* Editor Header */
.editor-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.editor-header .document-title-input {
  margin-bottom: 0;
}

/* Version Selector */
.version-selector {
  position: relative;
}

.version-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background: #e9ecef;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.version-btn:hover {
  background: #dee2e6;
}

.version-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  width: 280px;
  max-height: 400px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.version-dropdown.hidden {
  display: none;
}

.version-dropdown-header {
  padding: 0.75rem;
  font-weight: bold;
  border-bottom: 1px solid #ddd;
  background: #f5f5f5;
}

.version-list {
  overflow-y: auto;
  flex: 1;
}

.version-item {
  padding: 0.75rem;
  border-bottom: 1px solid #eee;
}

.version-item:hover {
  background: #f9f9f9;
}

.version-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.875rem;
}

.version-number {
  font-weight: bold;
}

.version-author {
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  font-size: 0.7rem;
  text-transform: uppercase;
}

.version-author.ai {
  background: #e7f1ff;
  color: #0056b3;
}

.version-author.human {
  background: #e9ecef;
  color: #666;
}

.version-date {
  color: #999;
  font-size: 0.75rem;
  margin-left: auto;
}

.version-description {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: #555;
}

.restore-btn {
  margin-top: 0.5rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

.restore-btn:hover {
  background: #0056b3;
}

.version-list .empty-state,
.version-list .loading,
.version-list .error {
  padding: 1rem;
  color: #666;
  text-align: center;
}

.version-list .error {
  color: #dc3545;
}

/* Version Actions */
.version-actions {
  margin-top: 0.5rem;
}

.view-btn {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
}

.view-btn:hover {
  background: #0056b3;
  color: white;
}

/* Preview Mode */
.editor-preview-mode {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.preview-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.preview-info {
  font-size: 0.875rem;
  color: #856404;
}

.preview-actions {
  display: flex;
  gap: 0.5rem;
}

.restore-edit-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.8rem;
  background: #28a745;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.restore-edit-btn:hover {
  background: #218838;
}

.back-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.8rem;
  background: #6c757d;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
}

.back-btn:hover {
  background: #5a6268;
  color: white;
}

.preview-content {
  flex: 1;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 1rem;
  background: #fafafa;
}

.editor-preview-mode .document-title-input:disabled {
  background: #f5f5f5;
  color: #666;
  cursor: not-allowed;
}

/* Research Item Compact */
.research-item {
  display: block;
  cursor: pointer;
  transition: background 0.15s;
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  background: white;
}

.research-item:hover {
  background: #e9ecef;
}

.research-item-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.research-item-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.research-item-type {
  font-size: 0.75rem;
  color: #666;
  flex-shrink: 0;
}

/* Research Modal */
.research-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.research-modal-content {
  background: white;
  border-radius: 8px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.research-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #666;
  line-height: 1;
  padding: 0.25rem;
}

.research-modal-close:hover {
  color: #333;
}

/* Research Detail View */
.research-detail {
  padding: 1.5rem;
}

.research-detail h2 {
  margin: 0 0 0.5rem 0;
  padding-right: 2rem;
}

.research-detail-type {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: #e9ecef;
  border-radius: 4px;
  font-size: 0.75rem;
  color: #666;
  margin-bottom: 1rem;
}

.research-detail-section {
  margin-top: 1rem;
}

.research-detail-section h4 {
  margin: 0 0 0.5rem 0;
  font-size: 0.875rem;
  color: #666;
}

.research-detail-content {
  background: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 1rem;
  max-height: 400px;
  overflow-y: auto;
}

.research-detail-actions {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.research-detail-actions form {
  margin: 0;
}

.research-detail-actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.25;
}

.research-detail-actions .btn-primary {
  background: #007bff;
  color: white;
}

.research-detail-actions .btn-primary:hover {
  background: #0056b3;
}

.research-detail-actions .btn-danger {
  background: #dc3545;
  color: white;
}

.research-detail-actions .btn-danger:hover {
  background: #c82333;
}

/* ========================================
   Mobile Responsive Styles
   ======================================== */

/* Mobile header - hidden on desktop */
.mobile-header {
  display: none;
}

/* Mobile backdrop - hidden by default */
.mobile-backdrop {
  display: none;
}

@media (max-width: 768px) {
  /* Mobile Header */
  .mobile-header {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: #fff;
    border-bottom: 1px solid #ddd;
    z-index: 100;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
  }

  .mobile-menu-btn,
  .mobile-chat-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
  }

  .mobile-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Mobile Backdrop */
  .mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 50px;
    background: rgba(0, 0, 0, 0.5);
    z-index: 55;
  }

  .ide-container.sidebar-open .mobile-backdrop {
    display: block;
  }

  /* Left Sidebar - off-canvas drawer */
  .ide-sidebar {
    position: fixed;
    left: 0;
    top: 50px;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 60;
    background: #f5f5f5;
  }

  .ide-container.sidebar-open .ide-sidebar {
    transform: translateX(0);
  }

  /* Hide resize handle on mobile */
  .sidebar-resize-handle {
    display: none;
  }

  /* Editor - full width with top offset */
  .ide-editor {
    padding-top: 60px;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    width: 100%;
  }

  /* Chat Sidebar - full screen overlay, hidden by default on mobile */
  .chat-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    min-width: 0;
    z-index: 200;
    display: none;
  }

  .chat-sidebar.mobile-visible {
    display: flex;
  }

  .chat-sidebar.hidden {
    display: none;
  }

  /* Larger close button for mobile */
  .chat-close-btn {
    font-size: 2rem !important;
    padding: 0.5rem !important;
    min-width: 44px;
    min-height: 44px;
  }

  .chat-header {
    padding: 0.75rem 1rem;
  }

  .chat-header h3 {
    font-size: 1.1rem;
  }

  /* Trix toolbar adjustments */
  .ide-editor trix-toolbar {
    padding: 0.25rem;
  }

  /* Message bubbles - less margin on mobile */
  .message.user {
    margin-left: 1rem;
  }

  .message.assistant {
    margin-right: 1rem;
  }

  /* Version dropdown on mobile */
  .version-dropdown {
    position: fixed;
    top: 60px;
    left: 0.5rem;
    right: 0.5rem;
    width: auto;
  }

  /* Research modal full-width on mobile */
  .research-modal-content {
    width: 95%;
    max-height: 90vh;
  }
}
