:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #64748b;
  --bg-slate: #f8fafc;
  --bg-white: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-slate);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

body.list-page {
  height: auto;
  min-height: 100vh;
}

/* Header */
.app-header {
  background: white;
  color: black;
  padding: 0.5rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
  z-index: 10;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.btn-back {
  padding: 0.3rem 0.6rem;
}

.user-info {
  font-size: 0.875rem;
  background: rgba(255, 255, 255, 0.1);
  padding: 0.4rem 1rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 2px solid rgb(219, 217, 217);
}

/* Common Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: white;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background-color: #f1f5f9;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Layout */
.app-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.list-page .app-container {
  overflow: visible;
  display: block;
}

/* List View */
.list-view {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
  overflow-y: auto;
}

.list-page .list-view {
  overflow-y: visible;
  padding-bottom: 5rem;
}

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

.thread-card {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.thread-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.thread-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--primary);
}

.thread-desc {
  color: var(--text-muted);
  font-size: 0.875rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.thread-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--secondary);
  margin-top: 0.5rem;
}

/* Thread View */
.thread-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.thread-toolbar {
  background: white;
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
}

#edit-view,
#compare-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-pane {
  flex: 2;
  display: flex;
  flex-direction: column;
  background: white;
  border-right: 1px solid var(--border-color);
}

.board-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
  transition: all 0.3s ease;
}

/* Board Maximization */
.app-container.board-maximized .editor-pane {
  display: none !important;
}

.app-container.board-maximized .board-pane {
  flex: 1;
  width: 100%;
}

/* Editor */
.editor-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  background: #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.editor-header-left {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.editor-tabs-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.editor-tabs {
  display: flex;
  gap: 0.25rem;
  background: #e2e8f0;
  padding: 0.25rem;
  border-radius: 0.5rem;
}

.btn-tab {
  border: none;
  padding: 0.25rem 0.75rem;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-tab.active {
  background: white;
  font-weight: bold;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  color: var(--text-main);
}

.btn-tab:not(.active) {
  background: transparent;
  color: #475569;
}

.node-author-info {
  font-size: 0.8rem;
  color: var(--secondary);
}

.btn-copy {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.textarea-container {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
}

.prompt-textarea {
  width: 100%;
  min-height: 300px;
  resize: vertical;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  font-family: monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  outline: none;
}

.prompt-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.editor-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-color);
  background: white;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  position: sticky;
  bottom: 0;
  z-index: 10;
}

/* Chat Board */
.board-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  background: white;
  font-weight: 600;
}

.comments-area {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-message {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.5rem;
  max-width: 85%;
}

.chat-mine {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-others {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-header {
  font-size: 0.7rem;
  color: var(--secondary);
  margin-bottom: 0.25rem;
  display: flex;
  gap: 0.5rem;
}

.chat-bubble {
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
  position: relative;
  word-wrap: break-word;
}

.chat-mine .chat-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 0.25rem;
}

.chat-others .chat-bubble {
  background: white;
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 0.25rem;
}

.chat-target-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
  margin-bottom: 0.4rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.2s;
}

.chat-target-badge:hover {
  background: #e2e8f0;
}

.chat-likes {
  transition: all 0.2s;
}

.chat-likes:hover {
  opacity: 0.7;
  transform: scale(1.05);
}

.chat-mine .chat-target-badge {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.chat-others .chat-target-badge {
  background: #f1f5f9;
  color: #475569;
}

.chat-reply-link {
  color: #2563eb;
  font-weight: 600;
  cursor: pointer;
}

.chat-reply-link:hover {
  text-decoration: underline;
  opacity: 0.8;
}

.chat-mine .chat-reply-link {
  color: #bfdbfe;
  /* Lighter blue on primary background */
}

/* コメントジャンプ時の強調表示 */
.highlight-comment .chat-bubble {
  animation: highlight-pulse 2s ease-out;
}

@keyframes highlight-pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.4); }
  30% { transform: scale(1.02); box-shadow: 0 0 0 10px rgba(37, 99, 235, 0); }
  100% { transform: scale(1); }
}

.comment-input-area {
  padding: 1rem;
  background: white;
  border-top: 1px solid var(--border-color);
}

.comment-input-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.comment-input-header {
  font-size: 0.75rem;
  color: var(--secondary);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.comment-input-row {
  display: flex;
  gap: 0.5rem;
}

.comment-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0.75rem;
  font-size: 0.875rem;
  outline: none;
  height: 60px;
}

.comment-textarea:focus {
  border-color: var(--primary);
}

.btn-send-comment {
  background: #94a3b8;
  color: white;
  border: none;
  border-radius: 0.5rem;
  width: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  font-size: 0.7rem;
  transition: background 0.2s;
}

.btn-send-comment:hover {
  background: #64748b;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: white;
  border-radius: 1rem;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Tree Modal Specific */
.tree-modal-content {
  max-width: 900px;
  width: 95%;
  height: 80vh;
}

.tree-container {
  flex: 1;
  background: #f1f5f9;
  overflow: auto;
  position: relative;
  padding: 2rem;
  background-image: radial-gradient(#cbd5e1 1px, transparent 0);
  background-size: 20px 20px;
}

/* Toast */
.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #1e293b;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 700;
}

.badge-major {
  background: #fef08a;
  color: #854d0e;
}

.badge-minor {
  background: #e2e8f0;
  color: #475569;
}

.badge-success {
  background: #dcfce7;
  color: #166534;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

/* Tree Node Styling for CSS Rendering */
.tree-node-wrapper {
  display: flex;
  align-items: stretch;
  position: relative;
}

.tree-node {
  position: relative;
  padding: 0.5rem 1rem;
  background: white;
  border: 2px solid var(--border-color);
  border-radius: 0.5rem;
  margin: 0.5rem 0;
  min-width: 120px;
  text-align: center;
  cursor: pointer;
  z-index: 10;
  transition: all 0.2s;
}

.tree-node.active {
  border-color: var(--primary);
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.tree-node.major {
  border-color: #fbbf24;
  box-shadow: 0 2px 4px rgba(251, 191, 36, 0.2);
}

.tree-node:hover {
  border-color: var(--secondary);
}

.tree-children {
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  padding-left: 2rem;
}

.tree-line-h {
  position: absolute;
  top: 50%;
  left: 100%;
  width: 2rem;
  height: 2px;
  background: var(--border-color);
}

.tree-line-v {
  position: absolute;
  left: 0;
  width: 2px;
  background: var(--border-color);
}

.tree-child-wrapper {
  position: relative;
}

.tree-child-line {
  position: absolute;
  left: 0;
  top: 50%;
  width: 2rem;
  height: 2px;
  background: var(--border-color);
}

/* --- Editor Format Buttons --- */
.btn-format {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  cursor: pointer;
  color: white;
  transition: transform 0.1s, opacity 0.2s;
}

.btn-format:hover {
  transform: scale(1.05);
}

.btn-format:active {
  transform: scale(0.95);
}

.format-primary {
  background-color: #3b82f6;
}

.format-secondary {
  background-color: #64748b;
}

.format-success {
  background-color: #22c55e;
}

.format-danger {
  background-color: #ef4444;
}

.format-warning {
  background-color: #f59e0b;
}

.format-info {
  background-color: #0ea5e9;
}

.format-light {
  background-color: #f8fafc;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.format-dark {
  background-color: #1e293b;
}

/* --- Search and Replace Panel --- */
.search-replace-panel {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.sr-inputs {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.sr-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sr-field input {
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  outline: none;
}

.sr-field input:focus {
  border-color: var(--primary);
}

.sr-count {
  background: #e0f2fe;
  color: #0369a1;
  padding: 0.4rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 0.5rem;
}

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

.sr-btn {
  flex: 1;
  padding: 0.4rem;
  font-size: 0.8rem;
}

.btn-success {
  background-color: #22c55e;
  color: white;
  border: none;
}

.btn-success:hover {
  background-color: #16a34a;
}

.btn-danger {
  background-color: #ef4444;
  color: white;
  border: none;
}

.btn-danger:hover {
  background-color: #dc2626;
}

.compare-controls {
  padding: 0.75rem 1rem;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem 0.5rem 0 0;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.compare-controls label {
  font-weight: bold;
  font-size: 0.875rem;
  color: #475569;
}

#compare-target-select {
  width: auto;
  padding: 0.3rem 1.5rem 0.3rem 0.5rem;
  height: 32px;
  font-size: 0.875rem;
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  background-color: white;
  max-width: 100%;
}

.diff-container {
  flex: 1;
  padding: 1rem;
  background: white;
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 0.5rem 0.5rem;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
  font-size: 0.875rem;
  line-height: 1.5;
}

/* --- Responsive (Mobile) --- */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
    overflow-y: auto;
  }

  .workspace {
    flex-direction: column;
    overflow: visible;
  }

  .editor-pane {
    flex: none;
    height: 85vh;
    display: flex;
    flex-direction: column;
    border-right: none;
    border-bottom: 2px solid var(--border-color);
  }

  .board-pane {
    flex: none;
    height: auto;
    min-height: 50vh;
  }

  /* Make containers scroll naturally on mobile */
  #edit-view,
  #compare-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .textarea-container {
    flex: 1;
    overflow-y: auto;
    height: auto;
  }

  .sr-inputs {
    flex-direction: column;
    gap: 0.5rem;
  }

  .sr-actions {
    flex-wrap: wrap;
  }

  .sr-btn {
    flex: 1 1 100%;
  }

  .modal-content {
    width: 95%;
    max-height: 95vh;
  }

  .editor-toolbar {
    flex-wrap: wrap;
  }

  .editor-footer {
    flex-wrap: wrap;
    justify-content: center;
    padding: 1rem;
    gap: 0.75rem;
    background: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  }

  .app-header {
    padding: 0.5rem;
  }

  .header-left,
  .header-right {
    gap: 0.5rem;
  }

  .header-title {
    font-size: 1.1rem;
  }

  .btn {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
  }

  .user-info {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
  }

  .editor-header {
    padding: 0.5rem;
  }

  .format-list {
    justify-content: flex-start;
  }

  .btn-format {
    padding: 0.3rem 0.6rem;
    font-size: 0.7rem;
  }

  .prompt-textarea {
    min-height: 300px;
  }
}

/* Diff Viewer Styles */
.diff-added {
  background-color: #dcfce7;
  color: #166534;
  display: block;
  padding: 0 0.25rem;
}

.diff-removed {
  background-color: #fee2e2;
  color: #991b1b;
  display: block;
  padding: 0 0.25rem;
  text-decoration: line-through;
}

.diff-equal {
  display: block;
  padding: 0 0.25rem;
  color: #334155;
}

/* --- Mobile View Toggle --- */
.mobile-view-toggle {
  display: none;
  background: white;
  border-bottom: 1px solid var(--border-color);
  padding: 0.5rem;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  z-index: 20;
}

.mobile-tab {
  flex: 1;
  padding: 0.6rem;
  border: none;
  background: #f1f5f9;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.mobile-tab.active {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

/* --- Project Description Area --- */
.project-description-area {
  padding: 1rem;
  background: white;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0.5rem;
}

.board-maximized .project-description-area {
  display: none;
}

@media (max-width: 768px) {
  .app-container.show-board .project-description-area {
    display: none;
  }
}

.description-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--secondary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.description-text {
  font-size: 0.9rem;
  color: var(--text-main);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
  .app-header {
    padding: 0.5rem;
  }

  .header-title {
    font-size: 1rem;
  }

  .mobile-view-toggle {
    display: flex;
  }

  .app-container {
    flex-direction: column;
  }

  .editor-pane,
  .board-pane {
    flex: none;
    width: 100%;
    height: calc(100vh - 110px);
    /* Adjust based on header/toggle height */
    border-right: none;
  }

  .app-container.show-editor .board-pane {
    display: none !important;
  }

  .app-container.show-board .editor-pane {
    display: none !important;
  }

  .app-container.show-editor .editor-pane {
    display: flex;
    flex: 1;
  }

  .app-container.show-board .board-pane {
    display: flex;
    flex: 1;
  }

  .editor-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  }

  .textarea-container {
    padding-bottom: 80px;
    /* Room for fixed footer */
  }

  .comment-input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
  }

  .comments-area {
    padding-bottom: 120px;
    /* Room for fixed comment input */
  }

  .btn-maximize {
    display: inline-flex !important;
  }
}

.list-search-input {
  height: 40px;
  padding: 0 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 0.9rem;
  background: white;
  color: var(--text-main);
  transition: border-color 0.2s;
}

.list-search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}