/* css/project.css – Academic Project Maker (multi-project, rich editor, AI with cancel) */

:root {
  --project-accent: #009688;
  --project-accent-soft: rgba(0, 150, 136, 0.08);
  --project-accent-soft-hover: rgba(0, 150, 136, 0.15);
  --sidebar-width: 270px;
  --ai-panel-width: 340px;
  --toolbar-height: 42px;
  --editor-header-height: 56px;
}

[data-theme="dark"] {
  --project-accent: #14b8a6;
  --project-accent-soft: rgba(20, 184, 166, 0.12);
  --project-accent-soft-hover: rgba(20, 184, 166, 0.2);
}

/* ===== Layout ===== */
.project-main {
  padding: 0;
  background: var(--bg-page);
  height: calc(100vh - 56px); /* navbar height */
  overflow: hidden;
}

.mobile-toggles {
  display: none;
  padding: 0.5rem 0.8rem;
  gap: 0.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
}

.toggle-btn {
  flex: 1;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border-light);
  border-radius: 2rem;
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  transition: all 0.2s ease;
}

.toggle-btn:hover {
  background: var(--project-accent-soft);
  border-color: var(--project-accent);
  color: var(--project-accent);
}

.toggle-btn i {
  font-size: 0.9rem;
}

.project-workspace {
  display: flex;
  height: 100%;
}

/* ===== Left Sidebar: Chapters ===== */
.chapters-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform 0.3s ease, left 0.3s ease;
}

.sidebar-header {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  flex-shrink: 0;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-header h3 i {
  color: var(--project-accent);
  font-size: 0.9rem;
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0.25rem;
  border-radius: 0.5rem;
  transition: all 0.2s;
}

.sidebar-close:hover {
  background: var(--project-accent-soft);
  color: var(--project-accent);
}

/* Project Selector */
.project-selector {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  background: var(--surface);
  flex-shrink: 0;
}

.project-selector select {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border-light);
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
  max-width: calc(100% - 40px);
}

.project-selector select:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}

.project-selector .icon-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--project-accent);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.project-selector .icon-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 150, 136, 0.3);
}

/* Chapters List */
.chapters-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.chapters-list::-webkit-scrollbar {
  width: 4px;
}

.chapters-list::-webkit-scrollbar-track {
  background: transparent;
}

.chapters-list::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 4px;
}

.chapter-item {
  padding: 0.6rem 0.8rem;
  border-radius: 0.6rem;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.chapter-item i {
  font-size: 0.75rem;
  color: var(--text-secondary);
  width: 16px;
  text-align: center;
  transition: color 0.2s;
}

.chapter-item:hover {
  background: var(--project-accent-soft);
  color: var(--project-accent);
}

.chapter-item:hover i {
  color: var(--project-accent);
}

.chapter-item.active {
  background: var(--project-accent-soft);
  color: var(--project-accent);
  font-weight: 600;
  border-left: 3px solid var(--project-accent);
  border-radius: 0 0.6rem 0.6rem 0;
}

.chapter-item.active i {
  color: var(--project-accent);
}

.section-item {
  padding: 0.4rem 0.8rem 0.4rem 2.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.section-item i {
  font-size: 0.55rem;
  width: 12px;
  text-align: center;
  flex-shrink: 0;
}

.section-item:hover {
  background: var(--project-accent-soft);
  color: var(--project-accent);
}

.section-item.active {
  color: var(--project-accent);
  font-weight: 500;
  background: var(--project-accent-soft);
}

/* ===== Center Editor Area ===== */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
  min-width: 0;
}

.editor-header {
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  background: var(--surface);
  flex-shrink: 0;
}

.editor-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

.editor-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.action-btn {
  background: var(--surface);
  border: 1px solid var(--border-light);
  padding: 0.45rem 0.85rem;
  border-radius: 1.5rem;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s ease;
  font-family: inherit;
  white-space: nowrap;
}

.action-btn:hover {
  background: var(--project-accent-soft);
  border-color: var(--project-accent);
  color: var(--project-accent);
  transform: translateY(-1px);
}

.action-btn:active {
  transform: translateY(0);
}

/* ===== Formatting Toolbar ===== */
.formatting-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
}

.formatting-toolbar::-webkit-scrollbar {
  height: 3px;
}

.formatting-toolbar::-webkit-scrollbar-track {
  background: transparent;
}

.formatting-toolbar::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

.format-group {
  display: flex;
  gap: 0.2rem;
  align-items: center;
  flex-shrink: 0;
}

.divider {
  width: 1px;
  height: 20px;
  background: var(--border-light);
  margin: 0 0.4rem;
  flex-shrink: 0;
}

.format-btn {
  background: transparent;
  border: none;
  padding: 0.4rem 0.55rem;
  border-radius: 0.35rem;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.82rem;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.format-btn:hover {
  background: var(--project-accent-soft);
  color: var(--project-accent);
}

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

.format-select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border-light);
  border-radius: 0.35rem;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.format-select:hover {
  border-color: var(--project-accent);
}

.format-select:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}

/* ===== Editor ===== */
.editor-wrapper {
  flex: 1;
  padding: 2rem 2.5rem;
  overflow-y: auto;
  background: var(--surface);
}

.editor-wrapper::-webkit-scrollbar {
  width: 6px;
}

.editor-wrapper::-webkit-scrollbar-track {
  background: transparent;
}

.editor-wrapper::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 6px;
}

.section-editor {
  min-height: 400px;
  max-width: 850px;
  margin: 0 auto;
  outline: none;
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text-primary);
}

.section-editor:empty:before {
  content: "Start writing or use AI to generate content for this section...";
  color: var(--text-secondary);
  opacity: 0.5;
  font-style: italic;
}

.section-editor:focus {
  outline: none;
}

/* Editor Typography */
.section-editor h1 {
  font-size: 1.8rem;
  border-bottom: 2px solid var(--project-accent);
  padding-bottom: 0.5rem;
  margin: 1.5rem 0 1rem;
  color: var(--project-accent);
}

.section-editor h2 {
  font-size: 1.4rem;
  margin: 1.2rem 0 0.8rem;
  color: var(--text-primary);
}

.section-editor h3 {
  font-size: 1.15rem;
  margin: 1rem 0 0.6rem;
}

.section-editor p {
  margin: 0.75rem 0;
}

.section-editor ul,
.section-editor ol {
  margin: 0.75rem 0;
  padding-left: 1.8rem;
}

.section-editor li {
  margin: 0.3rem 0;
}

.section-editor blockquote {
  border-left: 4px solid var(--project-accent);
  background: var(--project-accent-soft);
  padding: 0.75rem 1.2rem;
  margin: 1rem 0;
  border-radius: 0 0.5rem 0.5rem 0;
}

.section-editor a {
  color: var(--project-accent);
  text-decoration: underline;
}

.section-editor table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
}

.section-editor th,
.section-editor td {
  border: 1px solid var(--border-light);
  padding: 0.6rem 0.8rem;
  text-align: left;
}

.section-editor th {
  background: var(--project-accent-soft);
  font-weight: 600;
}

.section-editor img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
}

.section-editor pre {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  font-size: 0.9em;
}

.section-editor code {
  font-family: 'Courier New', monospace;
  background: var(--project-accent-soft);
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  font-size: 0.9em;
}

/* ===== AI Generate Button ===== */
.ai-section-generate {
  padding: 1rem 2rem;
  border-top: 1px solid var(--border-light);
  text-align: center;
  background: var(--surface);
  flex-shrink: 0;
}

.generate-btn {
  background: linear-gradient(135deg, var(--project-accent), #26a69a);
  color: white;
  border: none;
  padding: 0.75rem 2.5rem;
  border-radius: 2.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 16px rgba(0, 150, 136, 0.25);
}

.generate-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 150, 136, 0.35);
  filter: brightness(1.05);
}

.generate-btn:active:not(:disabled) {
  transform: translateY(0);
}

.generate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

/* ===== Right AI Supervisor Panel ===== */
.ai-panel {
  width: var(--ai-panel-width);
  min-width: var(--ai-panel-width);
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-left: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform 0.3s ease, right 0.3s ease;
}

.ai-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ai-chat-messages {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 4px;
}

.ai-empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 2rem 1rem;
  margin: auto;
}

.ai-empty-state i {
  font-size: 2.5rem;
  opacity: 0.4;
  margin-bottom: 0.8rem;
  color: var(--project-accent);
}

.ai-empty-state p {
  margin: 0.3rem 0;
  font-size: 0.9rem;
  font-weight: 500;
}

.ai-empty-state small {
  font-size: 0.78rem;
  opacity: 0.7;
}

.ai-message {
  max-width: 90%;
  padding: 0.65rem 1rem;
  border-radius: 1rem;
  font-size: 0.88rem;
  line-height: 1.5;
  word-wrap: break-word;
  animation: messageSlide 0.25s ease;
}

.ai-message.user {
  align-self: flex-end;
  background: var(--project-accent-soft);
  color: var(--text-primary);
  border: 1px solid rgba(0, 150, 136, 0.2);
  border-bottom-right-radius: 0.3rem;
}

.ai-message.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 0.3rem;
}

.ai-message p {
  margin: 0.3rem 0;
}

.ai-message ul,
.ai-message ol {
  padding-left: 1.2rem;
  margin: 0.3rem 0;
}

.ai-chat-input {
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  background: var(--surface);
  flex-shrink: 0;
}

.ai-chat-input textarea {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border-light);
  border-radius: 1rem;
  background: var(--bg-page);
  color: var(--text-primary);
  resize: none;
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  min-height: 40px;
  max-height: 120px;
  transition: border-color 0.2s;
}

.ai-chat-input textarea:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}

.ai-chat-input button {
  background: var(--project-accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.ai-chat-input button:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(0, 150, 136, 0.3);
}

.ai-chat-input button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Modals ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.25s ease;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 1.5rem;
  padding: 2rem;
  max-width: 550px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  animation: slideUp 0.3s ease;
  border: 1px solid var(--border-light);
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-header h2 i {
  color: var(--project-accent);
}

.modal-close {
  background: var(--bg-page);
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover {
  background: #fee2e2;
  color: #dc2626;
}

.modal-body {
  color: var(--text-primary);
}

/* Form elements inside modals */
.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.form-group {
  flex: 1;
  min-width: 200px;
  margin-bottom: 1.2rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
  color: var(--text-secondary);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border-light);
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}

.text-center {
  text-align: center;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-light);
  border-top-color: var(--project-accent);
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 0.8s linear infinite;
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border-light);
  padding: 0.6rem 1.5rem;
  border-radius: 2rem;
  cursor: pointer;
  color: var(--text-primary);
  font-weight: 500;
  font-size: 0.9rem;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-secondary:hover {
  background: #fee2e2;
  border-color: #dc2626;
  color: #dc2626;
}

/* ===== History Drawer ===== */
.history-drawer {
  position: fixed;
  top: 0;
  left: -420px;
  width: 420px;
  height: 100vh;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-light);
  z-index: 900;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
}

.history-drawer.active {
  left: 0;
}

.drawer-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  background: var(--surface);
}

.drawer-header h3 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.drawer-header h3 i {
  color: var(--project-accent);
}

.drawer-header .icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--project-accent);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.drawer-header .icon-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 150, 136, 0.3);
}

.drawer-close-btn {
  background: var(--bg-page);
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.drawer-close-btn:hover {
  background: var(--project-accent-soft);
  color: var(--project-accent);
}

.history-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.2rem;
}

.history-content::-webkit-scrollbar {
  width: 4px;
}

.history-content::-webkit-scrollbar-track {
  background: transparent;
}

.history-content::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 4px;
}

.history-item {
  background: var(--surface);
  border-radius: 1rem;
  padding: 1rem 1.1rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border-light);
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
}

.history-item:hover {
  border-color: var(--project-accent);
  transform: translateX(-4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.history-item .delete-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 0.4rem;
  transition: all 0.2s;
  font-size: 0.85rem;
  z-index: 1;
}

.history-item .delete-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

.history-title {
  font-weight: 600;
  display: block;
  margin-bottom: 0.35rem;
  margin-right: 2rem;
  color: var(--text-primary);
  font-size: 0.93rem;
  line-height: 1.3;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.history-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* Mini progress bar in history */
.progress-bar-mini {
  width: 100%;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  overflow: hidden;
  margin: 0.5rem 0 0.25rem;
}

.progress-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--project-accent);
  transition: width 0.5s ease;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.5rem;
  opacity: 0.4;
}

.empty-state p {
  margin: 0.3rem 0;
  font-size: 0.95rem;
  font-weight: 500;
}

.empty-state small {
  font-size: 0.8rem;
  opacity: 0.7;
}

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--surface);
  border-left: 4px solid var(--project-accent);
  padding: 0.75rem 1.2rem;
  border-radius: 0.8rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: slideUp 0.3s ease;
  font-size: 0.88rem;
  font-weight: 500;
  max-width: 350px;
}

.toast.success { border-left-color: #10b981; }
.toast.error { border-left-color: #dc2626; }
.toast.warning { border-left-color: #f59e0b; }
.toast.info { border-left-color: #3b82f6; }

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  :root {
    --ai-panel-width: 300px;
    --sidebar-width: 240px;
  }
}

@media (max-width: 992px) {
  .mobile-toggles {
    display: flex;
  }

  .chapters-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    z-index: 200;
    width: 85%;
    max-width: 320px;
    height: 100vh;
    transition: left 0.3s ease;
  }

  .chapters-sidebar.open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  .sidebar-close {
    display: block;
  }

  .ai-panel {
    position: fixed;
    top: 0;
    right: -100%;
    z-index: 200;
    width: 85%;
    max-width: 340px;
    height: 100vh;
    transition: right 0.3s ease;
  }

  .ai-panel.open {
    right: 0;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  }

  .editor-wrapper {
    padding: 1.5rem;
  }

  .formatting-toolbar {
    padding: 0.5rem 1rem;
    gap: 0.15rem;
  }

  .format-btn {
    padding: 0.35rem 0.5rem;
    font-size: 0.78rem;
  }

  .history-drawer {
    width: 340px;
    left: -340px;
  }
}

@media (max-width: 768px) {
  .editor-header {
    padding: 0.6rem 1rem;
  }

  .editor-header h2 {
    font-size: 1rem;
  }

  .action-btn span {
    display: none;
  }

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

  .editor-wrapper {
    padding: 1rem;
  }

  .section-editor {
    font-size: 0.95rem;
    line-height: 1.6;
  }

  .ai-section-generate {
    padding: 0.75rem 1rem;
  }

  .generate-btn {
    padding: 0.65rem 1.5rem;
    font-size: 0.9rem;
    width: 100%;
    justify-content: center;
  }

  .modal-content {
    padding: 1.5rem;
    border-radius: 1.2rem;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .form-group {
    min-width: 100%;
  }

  .toast {
    left: 1rem;
    right: 1rem;
    max-width: none;
  }
}

@media (max-width: 480px) {
  .formatting-toolbar {
    padding: 0.4rem 0.75rem;
    gap: 0.1rem;
  }

  .format-btn {
    padding: 0.3rem 0.45rem;
    font-size: 0.75rem;
  }

  .format-select {
    padding: 0.3rem 0.4rem;
    font-size: 0.72rem;
  }

  .divider {
    margin: 0 0.2rem;
  }

  .sidebar-header {
    padding: 0.8rem 1rem;
  }

  .drawer-header {
    padding: 1rem;
  }

  .history-drawer {
    width: 100%;
    left: -100%;
  }

  .history-item {
    padding: 0.8rem;
  }

  .ai-chat-input {
    padding: 0.6rem 0.8rem;
  }

  .ai-chat-input textarea {
    font-size: 0.82rem;
  }

  .ai-chat-input button {
    width: 36px;
    height: 36px;
  }
}

/* ===== Print Styles ===== */
@media print {
  .navbar,
  .chapters-sidebar,
  .ai-panel,
  .formatting-toolbar,
  .ai-section-generate,
  .mobile-toggles,
  .editor-header,
  .editor-actions,
  .history-drawer,
  #toast-container,
  .modal {
    display: none !important;
  }

  .project-main {
    height: auto;
    overflow: visible;
  }

  .project-workspace {
    display: block;
  }

  .editor-area {
    overflow: visible;
    background: white;
  }

  .editor-wrapper {
    overflow: visible;
    padding: 0;
    background: white;
  }

  .section-editor {
    color: #000;
    max-width: 100%;
    font-size: 12pt;
    line-height: 1.5;
  }
}



/* ===== AI Controls (tone + modification) ===== */
.ai-controls {
  padding: 0.75rem 2rem;
  border-top: 1px solid var(--border-light);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ai-tone-selector {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.ai-tone-selector label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.ai-tone-selector select {
  flex: 1;
  min-width: 180px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-light);
  border-radius: 0.6rem;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.ai-tone-selector select:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}

.ai-modification-area {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ai-modification-area label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.ai-modification-area textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-light);
  border-radius: 0.75rem;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  resize: vertical;
  min-height: 50px;
  max-height: 120px;
  outline: none;
  transition: border-color 0.2s;
}

.ai-modification-area textarea:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}

/* Responsive for AI controls */
@media (max-width: 768px) {
  .ai-controls {
    padding: 0.6rem 1rem;
  }
  .ai-tone-selector {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }
  .ai-tone-selector select {
    width: 100%;
  }
}


/* ===== AI Detection Score Display ===== */
.ai-score-display {
  padding: 0.6rem 2rem;
  border-top: 1px solid var(--border-light);
  background: var(--surface);
  flex-shrink: 0;
}

.score-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.score-header span:last-child {
  font-weight: 700;
  font-size: 1rem;
  color: var(--project-accent);
}

.score-bar {
  width: 100%;
  height: 5px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.score-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease, background 0.5s ease;
}

.score-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

/* ===== Writing Profile Selector ===== */
.ai-profile-selector {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.ai-profile-selector label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.ai-profile-selector select {
  flex: 1;
  min-width: 160px;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border-light);
  border-radius: 0.55rem;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.ai-profile-selector select:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}

/* ===== Version History Panel ===== */
.version-panel {
  padding: 0.4rem 0;
  border-top: 1px solid var(--border-light);
  margin-top: 0.2rem;
}

.version-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.version-save-btn {
  background: var(--project-accent-soft);
  border: 1px solid var(--project-accent);
  color: var(--project-accent);
  padding: 0.2rem 0.7rem;
  border-radius: 1rem;
  cursor: pointer;
  font-size: 0.72rem;
  font-family: inherit;
  transition: all 0.2s;
}

.version-save-btn:hover {
  background: var(--project-accent);
  color: white;
}

.version-list {
  max-height: 120px;
  overflow-y: auto;
}

.version-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0.3rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  border-radius: 0.3rem;
}

.version-item:hover {
  background: var(--project-accent-soft);
}

.restore-version-btn {
  background: none;
  border: 1px solid var(--border-light);
  padding: 0.15rem 0.5rem;
  border-radius: 0.4rem;
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--text-primary);
  font-family: inherit;
  transition: all 0.2s;
}

.restore-version-btn:hover {
  background: var(--project-accent);
  color: white;
  border-color: var(--project-accent);
}

/* ===== Progress Stage Text ===== */
#progressStage {
  font-weight: 500;
  color: var(--project-accent);
}

/* ===== Responsive additions ===== */
@media (max-width: 768px) {
  .ai-profile-selector {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }
  .ai-profile-selector select {
    width: 100%;
  }
  .score-details {
    flex-direction: column;
    gap: 0.2rem;
  }
}


/* ===== AI Controls Row (Profile + Word Count + Reference Style) ===== */
.ai-controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

/* Make existing profile selector, gen-option, and tone selector consistent */
.ai-profile-selector,
.ai-tone-selector {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.ai-profile-selector label,
.ai-tone-selector label,
.gen-option label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: fit-content;
}

.ai-profile-selector select,
.ai-tone-selector select,
.gen-option select,
.gen-option input {
  flex: 1;
  min-width: 160px;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border-light);
  border-radius: 0.55rem;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.ai-profile-selector select:focus,
.ai-tone-selector select:focus,
.gen-option select:focus,
.gen-option input:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}

/* Gen option wrapper */
.gen-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 180px;
}

.gen-option select {
  flex: 1;
  min-width: 140px;
}

.custom-word-count {
  width: 90px !important;
  min-width: 90px !important;
  flex: 0 0 auto;
  margin-left: 0.25rem;
}

/* AI controls container spacing */
.ai-controls {
  padding: 0.75rem 2rem;
  border-top: 1px solid var(--border-light);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* Tone selector (row 2) */
.ai-tone-selector {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Export scope selector */
.export-scope-select {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border-light);
  border-radius: 1.5rem;
  background: var(--surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  height: 36px;
  line-height: 1;
}

.export-scope-select:hover {
  border-color: var(--project-accent);
  background: var(--project-accent-soft);
}

.export-scope-select:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}

/* Responsive for AI controls */
@media (max-width: 768px) {
  .ai-controls {
    padding: 0.6rem 1rem;
  }
  
  .ai-controls-row {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .ai-profile-selector,
  .ai-tone-selector,
  .gen-option {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }
  
  .ai-profile-selector select,
  .ai-tone-selector select,
  .gen-option select,
  .gen-option input {
    width: 100%;
  }
  
  .custom-word-count {
    width: 100% !important;
  }
}


/* ===== Export scope selector ===== */
.export-scope-select {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border-light);
  border-radius: 1.5rem;   /* match .action-btn rounding */
  background: var(--surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  height: 36px;            /* align with buttons */
  line-height: 1;
}

.export-scope-select:hover {
  border-color: var(--project-accent);
  background: var(--project-accent-soft);
}

.export-scope-select:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}


/* ----- Sticky mobile toggles ----- */
.mobile-toggles {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  padding: 0.5rem 0.8rem;
  gap: 0.5rem;
}

/* ----- Floating Modify Button ----- */
.floating-modify-btn {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--project-accent);
  color: white;
  padding: 0.7rem 1.5rem;
  border-radius: 3rem;
  border: none;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 150, 136, 0.35);
  transition: transform 0.2s, opacity 0.3s;
  opacity: 1;
  pointer-events: auto;
}

.floating-modify-btn:hover {
  transform: translateX(-50%) translateY(-3px);
  box-shadow: 0 12px 28px rgba(0, 150, 136, 0.45);
}

.floating-modify-btn .btn-text {
  display: inline;
}

.floating-modify-btn .btn-icon {
  font-size: 1.1rem;
}

@media (max-width: 768px) {
  .floating-modify-btn .btn-text {
    display: none;   /* only icon on mobile */
  }
  .floating-modify-btn {
    padding: 0.6rem 0.8rem;
  }
}

/* Suggested prompts inside AI chat */
.suggested-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 0;
}

.suggested-prompt-chip {
  background: var(--project-accent-soft);
  border: 1px solid var(--project-accent);
  color: var(--project-accent);
  padding: 0.3rem 0.8rem;
  border-radius: 2rem;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
  transition: all 0.2s;
}

.suggested-prompt-chip:hover {
  background: var(--project-accent);
  color: white;
}