/* css/project.css – Academic Project Maker v3.2 */

: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;
  --warning-color: #f59e0b;
  --danger-color: #dc2626;
}

[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);
}

/* ===== Unsaved Changes Overlay ===== */
.unsaved-overlay {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  z-index: 500;
  pointer-events: none;
}

.unsaved-banner {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 1px solid #f59e0b;
  border-radius: 0 0 1rem 1rem;
  padding: 0.5rem 1.5rem;
  margin: 0 auto;
  max-width: 500px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  box-shadow: 0 4px 16px rgba(245, 158, 11, 0.2);
  pointer-events: all;
  animation: slideDown 0.3s ease;
  font-size: 0.85rem;
  color: #92400e;
}

.unsaved-banner i {
  color: #f59e0b;
  font-size: 1rem;
}

.save-now-btn {
  margin-left: auto;
  padding: 0.35rem 1rem;
  border-radius: 1.5rem;
  background: #f59e0b;
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.8rem;
  font-family: inherit;
  transition: all 0.2s;
}

.save-now-btn:hover {
  background: #d97706;
  transform: translateY(-1px);
}

/* ===== Layout =====
   REDESIGN fix: .project-main used to be a fixed-height, overflow:hidden
   app-shell wrapper — correct for the OLD single 3-column Workspace layout
   (each column scrolls independently), but it also clipped every new
   screen's content (Dashboard/Setup/Review/Export/Tools), which is normal
   flowing page content and needs the page itself to scroll. The fixed-
   height/overflow-hidden behavior now lives on .project-workspace alone,
   which is the only screen that still wants it. */
.project-main {
  padding: 0;
  background:
    radial-gradient(circle at 15% 0%, var(--project-accent-soft) 0%, transparent 45%),
    radial-gradient(circle at 100% 20%, var(--project-accent-soft) 0%, transparent 40%),
    var(--bg-page);
  min-height: calc(100vh - 56px);
  position: relative;
}

.proj-screen {
  padding: 1.2rem 1.5rem 2rem;
  max-width: 1100px;
  margin: 0 auto;
}

.proj-screen#projScreenWorkspace {
  max-width: none;
  padding: 0;
}

.proj-screen#projScreenTools {
  max-width: 1200px;
}

/* REDESIGN (Round 3): the mobile-only chapter-drawer toggle is now an
   always-visible top bar (the global tab layout it used to sit below is
   gone) carrying Setup/Review shortcuts alongside it. */
.workspace-topbar {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.8rem;
  gap: 0.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
}

.workspace-topbar-spacer {
  flex: 1;
}

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

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

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

@media (max-width: 480px) {
  .workspace-topbar-btn span {
    display: none;
  }

  .workspace-topbar-btn {
    padding: 0.5rem 0.6rem;
  }
}

/* Collapse-header icon (Round 4 item 2) — mobile only, hidden on desktop
   where there's no scroll-space pressure to solve. */
.workspace-topbar-btn-mobile-only {
  display: none;
}
@media (max-width: 768px) {
  .workspace-topbar-btn-mobile-only {
    display: flex;
  }
}
/* Collapsing hides the section title/progress row + editor-actions + the
   formatting toolbar, leaving just the text itself scrollable — manual-only
   (Round 5 item 1 removed the old auto scroll-collapse behavior); discovered
   via the one-time tutorial pulse/tooltip below instead. */
.editor-header-collapsed .editor-header,
.editor-header-collapsed .formatting-toolbar {
  display: none;
}

/* .section-editor's normal min-height:400px (below) exists to give a nearly
   empty section a comfortable click target — but once the header is
   collapsed specifically to free up scrolling/writing space, that same
   fixed floor instead reads as a large dead area below short content,
   fighting the whole point of collapsing. Let it hug its real content
   height in this state instead. */
.editor-header-collapsed .section-editor {
  min-height: 0;
}

/* The min-height fix above wasn't the dominant cause of the leftover blank
   area — .project-workspace/.editor-area are pinned to a fixed
   calc(100vh - 101px) "independent scrolling pane" height (see below) so
   .editor-wrapper's flex:1 always stretches to fill that full height
   regardless of content, no matter how short the section is. On mobile,
   .chapters-sidebar/.ai-panel are already position:fixed drawers (not part
   of this flex row — see the max-width:992px rules), so nothing else
   depends on .project-workspace's height there; once collapsed, let the
   whole chain size to its actual content instead of the viewport, so short
   sections don't leave a dead area below them. Only the collapsed+mobile
   combination is touched — normal (expanded, or desktop) behavior, and
   long sections that still need to scroll within the collapsed view, are
   unaffected since document/page scrolling takes over instead.

   Selector note: .editor-header-collapsed is toggled on #editorArea
   itself, not on some wrapping element — so .project-workspace (editorArea's
   own PARENT) has to be reached with :has() rather than a descendant
   combinator (".editor-header-collapsed .project-workspace" would never
   match anything, since that asks for a .project-workspace INSIDE a
   .editor-header-collapsed element, the reverse of the real nesting).
   .editor-area itself needs the compound-class form for the same reason
   (".editor-header-collapsed .editor-area" looks for a descendant, but
   editor-area IS the .editor-header-collapsed element). Only
   .editor-wrapper is genuinely a descendant of #editorArea, so the
   descendant form was already correct for it.
*/
@media (max-width: 768px) {
  .project-workspace:has(.editor-header-collapsed) {
    height: auto;
    overflow: visible;
    align-items: flex-start;
  }
  .editor-area.editor-header-collapsed {
    height: auto;
    overflow: visible;
  }
  .editor-header-collapsed .editor-wrapper {
    flex: 0 1 auto;
    overflow: visible;
    /* js/result.js and js/docresult.js's UNRELATED editors (css/result.css,
       css/docresult.css — both globally loaded) also style a
       ".editor-wrapper", pinning min-height:60vh for their own layout;
       that leaked in here too and was the actual source of the remaining
       ~487px floor (60vh at a ~812px-tall phone) even after flex:1 was
       overridden above. */
    min-height: 0;
  }
}

/* One-time tutorial (Round 5 item 1): a pulsing ring around the collapse
   icon + a small tooltip bubble, shown once until dismissed (click, tap
   elsewhere, or an 8s timeout — see maybeShowCollapseTutorial() in JS). */
.workspace-topbar-btn-pulse {
  position: relative;
  z-index: 60;
  box-shadow: 0 0 0 0 var(--project-accent);
  animation: workspaceTutorialPulse 1.6s ease-out infinite;
}
@keyframes workspaceTutorialPulse {
  0% { box-shadow: 0 0 0 0 rgba(0, 150, 136, 0.55); }
  70% { box-shadow: 0 0 0 10px rgba(0, 150, 136, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 150, 136, 0); }
}
.workspace-collapse-tutorial {
  position: absolute;
  top: calc(100% + 0.6rem);
  right: 0;
  z-index: 60;
  max-width: 200px;
  background: var(--project-accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.35;
  padding: 0.55rem 0.75rem;
  border-radius: 0.6rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  animation: fadeIn 0.2s ease;
}
.workspace-collapse-tutorial::before {
  content: '';
  position: absolute;
  top: -5px;
  right: 14px;
  width: 10px;
  height: 10px;
  background: var(--project-accent);
  transform: rotate(45deg);
}
.workspace-collapse-tutorial[hidden] { display: none; }

/* ===== Independent Scrolling Workspace ===== */
.project-workspace {
  display: flex;
  height: calc(100vh - 56px - 45px); height: calc(100dvh - 56px - 45px);
  overflow: hidden;
}

.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-y: auto;
  overflow-x: hidden;
  height: 100%;
  transition: transform 0.3s ease, left 0.3s ease;
}

.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  height: 100%;
}

.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;
  height: 100%;
  transition: transform 0.3s ease, right 0.3s ease;
}

/* ===== Chapters Sidebar ===== */
.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-header-actions {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}

.resource-toggle-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

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

.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;
  position: relative;
}

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

.chapter-item .chapter-title-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.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);
}

/* Edit controls */
.chapter-item .edit-controls,
.section-item .edit-controls {
  display: none;
  gap: 2px;
  flex-shrink: 0;
}

.chapter-item:hover .edit-controls,
.section-item:hover .edit-controls,
.chapter-item.active .edit-controls,
.section-item.active .edit-controls {
  display: flex;
}

.edit-controls button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.65rem;
  transition: all 0.15s;
}

.edit-controls button:hover {
  background: var(--project-accent-soft);
  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;
  position: relative;
}

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

.section-item .section-title-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.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);
}

/* Add section item */
.add-section-item {
  padding: 0.35rem 0.8rem 0.35rem 2.5rem;
  font-size: 0.78rem;
  color: var(--project-accent);
  cursor: pointer;
  border: 1px dashed var(--border-light);
  border-radius: 0.5rem;
  margin-top: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

/* ===== Resources Panel inside sidebar ===== */
.resources-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.resources-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border-light);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  flex-shrink: 0;
}

.resources-panel-header span {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.resources-panel-header span i {
  color: var(--project-accent);
}

.back-to-chapters-btn {
  background: none;
  border: 1px solid var(--border-light);
  color: var(--project-accent);
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  padding: 0.3rem 0.7rem;
  border-radius: 1.5rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.back-to-chapters-btn:hover {
  background: var(--project-accent-soft);
}

.resource-upload-area {
  padding: 1rem;
  border-bottom: 1px solid var(--border-light);
  text-align: center;
  flex-shrink: 0;
}

.upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.5rem;
  border: 2px dashed var(--border-light);
  border-radius: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
}

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

.upload-label i {
  font-size: 1.8rem;
}

.resource-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

.resource-item {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 0.75rem;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: all 0.2s;
}

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

.resource-item .file-icon {
  font-size: 1.2rem;
  color: var(--project-accent);
  flex-shrink: 0;
}

.resource-item .file-info {
  flex: 1;
  min-width: 0;
}

.resource-item .file-name {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resource-item .file-date {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.resource-item .delete-resource-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 0.3rem;
  transition: all 0.2s;
  flex-shrink: 0;
}

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

#uploadStatus {
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
}

/* ===== Center Editor Area ===== */
.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: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 2px; /* keeps the scrollbar from clipping button focus rings */
}
.editor-actions::-webkit-scrollbar { height: 4px; }
.editor-actions::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
.editor-actions > * { flex-shrink: 0; }
/* On a phone the row scrolls sideways: Generate, the main action, comes first so it is never off-screen. */
@media (max-width: 600px) { .editor-actions > #genDropdownWrap { order: -1; } }

.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);
}

/* Round 5 item 2: the "Generate" trigger is a filled accent button, not the
   default bordered/transparent action-btn — the two-class selector below
   beats plain .action-btn(:hover) on specificity regardless of source order. */
.action-btn.action-btn-accent {
  background: var(--project-accent);
  border-color: var(--project-accent);
  color: #fff;
}
.action-btn.action-btn-accent:hover {
  background: var(--project-accent);
  filter: brightness(1.08);
  color: #fff;
  border-color: var(--project-accent);
  transform: translateY(-1px);
}

/* ----- Tools icon dropdown (REDESIGN Round 3) ----- */
.tools-dropdown-wrap {
  position: relative;
}

.tools-dropdown-menu {
  display: none;
  flex-direction: column;
  gap: 0.2rem;
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-light);
  border-radius: 0.75rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 0.4rem;
  min-width: 180px;
  z-index: 60;
}

.tools-dropdown-wrap.open .tools-dropdown-menu {
  display: flex;
}

.tools-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  border-radius: 0.5rem;
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  width: 100%;
}

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

/* ===== 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 SI 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;
}

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

.generate-buttons-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.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);
  white-space: nowrap;
}

.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;
}

.chapter-gen-btn {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.25);
}

.chapter-gen-btn:hover:not(:disabled) {
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.35);
}

/* ===== AI Supervisor Panel ===== */
.ai-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

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

.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;
}

/* ===== Default Prompts Bar ===== */
.default-prompts-bar {
  border-top: 1px solid var(--border-light);
  background: var(--surface);
  flex-shrink: 0;
}

.default-prompts-scroll {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.8rem;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: thin;
}

.default-prompts-scroll::-webkit-scrollbar {
  height: 3px;
}

.default-prompts-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.default-prompts-scroll::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

.default-prompts-scroll .suggested-prompt-chip {
  flex-shrink: 0;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.5rem 1rem;
  align-self: flex-start;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ===== AI Chat Input ===== */
.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;
}

/* ===== Supervisor Personality ===== */
.supervisor-personality {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border-light);
  background: var(--surface);
  flex-shrink: 0;
}

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

.form-group-compact {
  flex: 1;
}

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

.form-group-compact select,
.form-group-compact input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border-light);
  border-radius: 0.4rem;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  outline: none;
}

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

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

.ai-controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

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

.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 {
  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;
}

/* Humanize Option */
.humanize-option {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--project-accent);
  cursor: pointer;
}

.humanize-note {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-left: 1.6rem;
}

.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);
}

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

.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);
  margin-bottom: 0.3rem;
}

.score-plan-badge {
  font-size: 0.7rem;
  text-align: center;
}

.badge-free {
  background: #f3f4f6;
  color: #6b7280;
  padding: 0.15rem 0.6rem;
  border-radius: 1rem;
  display: inline-block;
}

.badge-premium {
  background: #dbeafe;
  color: #1d4ed8;
  padding: 0.15rem 0.6rem;
  border-radius: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

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

.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);
}

/* ===== 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);
}

/* ===== Suggested prompts ===== */
.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;
}

/* ===== Floating Scroll Button ===== */
.floating-scroll-btn {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 950;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--project-accent);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 150, 136, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all 0.3s ease;
}

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

/* ===== 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; max-height: 85dvh;
  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,
.form-group textarea {
  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,
.form-group textarea:focus {
  border-color: var(--project-accent);
  box-shadow: 0 0 0 3px var(--project-accent-soft);
}

.form-group textarea {
  resize: vertical;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Monospace only makes sense for the structured chapter/section outline
   syntax — REDESIGN: previously applied to every textarea site-wide,
   including prose fields like Research Setup's Problem/Aim, which just
   looked like a code editor for no reason. */
#customOutlineInput {
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
}

.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;
}

.progress-bar-container {
  width: 100%;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--project-accent), #26a69a);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.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;
}

/* ===== Humanize Warning Modal ===== */
.warning-content {
  text-align: center;
}

.warning-icon {
  font-size: 3rem;
  color: #f59e0b;
  margin-bottom: 1rem;
}

.warning-box {
  background: #fef2f2;
  border: 2px solid #fecaca;
  border-radius: 0.75rem;
  padding: 1rem;
  margin: 1rem 0;
}

/* ===== History Drawer ===== */
.history-drawer {
  position: fixed;
  top: 0;
  left: -420px;
  width: 420px;
  height: 100vh; height: 100dvh;
  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; }

/* =========================================================================
   REDESIGN — Project Maker guided workspace: Dashboard / Setup / Chapter
   Workspace / Review / Export / Project Tools. Screen switching, Dashboard
   cards, Research Setup lists, Review findings, Export preview, the Project
   Tools grid, and Project AI's action buttons. Reuses css/doc.css's
   .glass-card/.card-header/.card-title/.card-body/.emr-tab-bar/.emr-tab
   directly (loaded globally already) rather than redefining them.
   ========================================================================= */
/* ----- All Projects (REDESIGN item 3: new landing screen) ----- */
.projects-list-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.projects-list-title { margin: 0; font-size: 1.4rem; color: var(--text-primary); display: flex; align-items: center; gap: 0.5rem; }
.projects-list-title i { color: var(--project-accent); }
.projects-search-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  margin-bottom: 1.2rem;
  border: 1px solid var(--border-light, #e2e8f0);
  border-radius: 2rem;
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  max-width: 420px;
}
.projects-search-row i { color: var(--text-secondary); font-size: 0.85rem; }
.projects-search-row input {
  flex: 1;
  border: none;
  outline: none;
  background: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
}

.projects-list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }

/* ----- Projects list loading shimmer (Round 3) ----- */
.project-card-shimmer { cursor: default; display: flex; flex-direction: column; gap: 0.6rem; }
.project-card-shimmer:hover { transform: none; box-shadow: 0 4px 16px rgba(0,0,0,0.04); border-color: var(--border-light, #e2e8f0); }
.shimmer-line {
  height: 0.9rem;
  border-radius: 0.4rem;
  background: linear-gradient(90deg, var(--border-light, #e2e8f0) 25%, var(--project-accent-soft) 50%, var(--border-light, #e2e8f0) 75%);
  background-size: 200% 100%;
  animation: shimmerSweep 1.4s ease-in-out infinite;
}
.shimmer-title { width: 85%; height: 1.1rem; }
.shimmer-title-2 { width: 60%; height: 1.1rem; }
.shimmer-meta { width: 70%; height: 0.75rem; margin-top: 0.3rem; }
.shimmer-bar { width: 100%; height: 4px; margin-top: 0.3rem; }
.shimmer-footer { width: 45%; height: 0.7rem; }

@keyframes shimmerSweep {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.project-card-item {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-light, #e2e8f0);
  border-radius: 1.1rem;
  padding: 1.2rem;
  cursor: pointer;
  position: relative;
  box-shadow: 0 4px 16px rgba(0,0,0,0.04);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.project-card-item:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(0,0,0,0.1); border-color: var(--project-accent); }
.project-card-current { border-color: var(--project-accent); }
.project-card-badge { position: absolute; top: -0.5rem; right: 1rem; font-size: 0.6rem; font-weight: 700; text-transform: uppercase; background: var(--project-accent); color: #fff; padding: 0.15rem 0.6rem; border-radius: 1rem; }
.project-card-title { font-weight: 700; font-size: 1rem; color: var(--text-primary); margin-bottom: 0.3rem; padding-right: 1rem; }
.project-card-meta { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 0.6rem; }
.project-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 0.5rem; }
.project-card-footer small { font-size: 0.7rem; color: var(--text-secondary); }

.proj-screen { display: none; }
.proj-screen.active { display: block; animation: fadeIn 0.25s ease; }

/* ----- Dashboard ----- */
.dash-hero-card { margin-bottom: 1rem; }
.dash-project-title { margin: 0 0 0.6rem; font-size: 1.4rem; color: var(--text-primary); }
.dash-progress-row { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.6rem; }
.dash-progress-row .progress-bar-mini { flex: 1; }
.dash-progress-label { font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; }
.dash-next-step { font-size: 0.9rem; color: var(--text-primary); margin-bottom: 1rem; }
.dash-next-step i { color: var(--project-accent); margin-right: 0.3rem; }
.dash-actions-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.dash-chapter-rail { display: flex; flex-direction: column; gap: 0.5rem; }
.dash-rail-chapter { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.9rem; border-radius: 0.7rem; font-size: 0.85rem; background: var(--surface, rgba(0,0,0,0.02)); border: 1px solid transparent; transition: border-color 0.15s ease; }
.dash-rail-chapter:hover { border-color: var(--border-light, #e2e8f0); }
.dash-rail-completed { color: #10b981; }
.dash-rail-completed i { color: #10b981; }
.dash-rail-current { color: var(--project-accent); font-weight: 600; }
.dash-rail-current i { color: var(--project-accent); }
.dash-rail-upcoming { color: var(--text-secondary); }
.dash-activity-list { display: flex; flex-direction: column; gap: 0.4rem; }
.dash-activity-item { font-size: 0.82rem; color: var(--text-primary); display: flex; align-items: center; gap: 0.4rem; }
.dash-activity-item i { color: var(--project-accent); font-size: 0.85rem; }

/* ----- Setup: Research Setup dynamic lists ----- */
.rs-list-row { display: flex; gap: 0.4rem; margin-bottom: 0.4rem; }
.rs-list-input { flex: 1; padding: 0.5rem 0.7rem; border: 1px solid var(--border-light, #e2e8f0); border-radius: 0.5rem; background: var(--card-bg); color: var(--text-primary); font-size: 0.88rem; }
.rs-list-remove { background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 0 0.4rem; }
.rs-list-remove:hover { color: var(--danger-color); }
.rs-list-add { background: none; border: 1px dashed var(--project-accent); color: var(--project-accent); border-radius: 0.5rem; padding: 0.35rem 0.8rem; font-size: 0.8rem; cursor: pointer; }

.setup-tab-pane { display: none; }
.setup-tab-pane.active { display: block; }

/* ----- Chapter Workspace additions ----- */
.workspace-progress-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.3rem; }
.workspace-progress-row span { font-size: 0.72rem; color: var(--text-secondary); }

/* ----- Project AI contextual actions ----- */
.proj-ai-context { font-size: 0.75rem; color: var(--text-secondary); padding: 0.5rem 0.8rem 0; display: flex; align-items: center; gap: 0.35rem; }
.proj-ai-context i { color: var(--project-accent); }
.proj-ai-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border-light, #e2e8f0); }
.proj-ai-action-btn { display: flex; align-items: center; gap: 0.3rem; font-size: 0.72rem; padding: 0.3rem 0.6rem; border-radius: 1rem; border: 1px solid var(--project-accent); background: var(--project-accent-soft); color: var(--project-accent); cursor: pointer; white-space: nowrap; transition: all 0.15s; }
.proj-ai-action-btn:hover { background: var(--project-accent-soft-hover); }

/* ----- Reference Manager ----- */
.reference-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; padding: 0.7rem 0.9rem; background: var(--project-accent-soft); border: 1px solid var(--border-light, #e2e8f0); border-radius: 0.7rem; margin-bottom: 0.5rem; transition: background 0.15s ease; }
.reference-item:hover { background: var(--project-accent-soft-hover); }
.reference-text { font-size: 0.85rem; color: var(--text-primary); flex: 1; min-width: 0; }
.reference-actions { display: flex; gap: 0.3rem; flex-shrink: 0; }
.reference-status { font-size: 0.72rem; color: var(--text-secondary); margin-top: 0.25rem; }
.reference-status i { color: var(--project-accent); }
.ref-format-btn { background: none; border: none; color: var(--project-accent); font-size: 0.72rem; cursor: pointer; padding: 0; text-decoration: underline; font-family: inherit; }

/* ----- Review (REDESIGN Round 3: single-panel toggle, like Lixa; Round 5
   item 5: the AI panel now fills the whole screen height — not just its
   width — so the prompt input stays pinned at the base of the page instead
   of requiring a page-level scroll to reach it. #projScreenReview is a
   fixed-height flex column (viewport height minus the navbar); the header
   bar is fixed-size and whichever of the AI panel / findings panel is
   visible takes the rest via flex:1, scrolling its OWN content internally
   rather than growing the page. */
#projScreenReview {
  max-width: 1100px;
}
/* BUG FIX: an ID selector like #projScreenReview{display:flex} would always
   beat .proj-screen{display:none} on specificity (ID > any number of
   classes) regardless of whether .active is present — silently un-hiding
   this screen even while another screen is the one meant to be showing.
   Scoping the layout rules to #projScreenReview.active keeps the same
   override power ONLY while this screen is genuinely the active one. */
#projScreenReview.active {
  height: calc(100vh - 56px); height: calc(100dvh - 56px);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: 1.2rem 1.5rem 1rem;
  overflow: hidden;
}

/* Persistent header bar (title + toggle) above both panels — kept outside
   #aiPanel/#reviewFindingsPanel specifically so it never disappears when
   one of those two is hidden by the toggle. */
.review-header-bar {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.2rem;
  border: 1px solid var(--border-light, #e2e8f0);
  border-bottom: none;
  border-radius: 1rem 1rem 0 0;
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.review-header-bar h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.review-header-bar h3 i { color: var(--project-accent); font-size: 0.9rem; }
.review-ai-panel.ai-panel,
.review-findings-panel {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  flex: 1;
  min-height: 0;
}
.review-findings-panel {
  border: 1px solid var(--border-light, #e2e8f0);
  border-top: none;
  border-radius: 0 0 1rem 1rem;
  padding: 1rem;
  overflow-y: auto;
}

.review-ai-panel.ai-panel {
  /* .ai-panel's base rule is written for Workspace's fixed-height 3-column
     shell (width:var(--ai-panel-width), height:100%) — override width for
     this full-width context; height now comes from flex:1 (above) with
     internal scrolling (overflow:hidden here + the chat-messages region's
     own overflow-y:auto, both from .ai-chat-area/.ai-chat-messages' base
     rules) so the composer at the bottom never scrolls off-screen. */
  width: 100%;
  min-width: 0;
  max-height: none;
  overflow: hidden;
  border: 1px solid var(--border-light, #e2e8f0);
  border-radius: 1rem;
}
.review-ai-panel .proj-ai-context,
.review-ai-panel .proj-ai-actions,
.review-ai-panel .supervisor-personality { flex-shrink: 0; }
.review-ai-panel .ai-chat-area { min-height: 0; }
.review-ai-panel .ai-chat-messages { max-height: none; }

.review-toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--project-accent-soft);
  border: 1px solid var(--project-accent);
  color: var(--project-accent);
  border-radius: 1.5rem;
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s ease;
}
.review-toggle-btn:hover { background: var(--project-accent-soft-hover); }

@media (max-width: 640px) {
  .review-toggle-btn span { display: none; }
  .review-toggle-btn { padding: 0.4rem 0.55rem; }
}

/* .ai-panel's base mobile rule (below, in the 992px block) turns it into a
   fixed off-canvas drawer that only appears with an .open class — correct
   for Workspace's old slide-in overlay, wrong here since Review's panel is
   always-visible, normal-flowing content. Override with higher specificity
   so it stays in normal document flow at every width. */
@media (max-width: 992px) {
  .review-ai-panel.ai-panel {
    position: static;
    width: 100%;
    max-width: none;
    right: auto;
    box-shadow: none;
  }
}

@media (max-width: 640px) {
  #projScreenReview { padding: 0.8rem 0.8rem 0.6rem; }
}


.review-finding { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.65rem 0.9rem; border-radius: 0.6rem; border-left: 3px solid transparent; margin-bottom: 0.5rem; font-size: 0.85rem; }
.review-finding.review-high, .review-finding.review-inconsistent { background: rgba(220, 38, 38, 0.08); color: #dc2626; border-left-color: #dc2626; }
.review-finding.review-medium, .review-finding.review-missing, .review-finding.review-weak { background: rgba(245, 158, 11, 0.1); color: #92400e; border-left-color: #f59e0b; }
.review-finding.review-low, .review-finding.review-unsupported { background: rgba(59, 130, 246, 0.08); color: #1d4ed8; border-left-color: #3b82f6; }
.review-finding.review-ok, .review-finding.review-empty { background: var(--project-accent-soft); color: var(--project-accent); border-left-color: var(--project-accent); }
.review-tag { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; padding: 0.1rem 0.4rem; border-radius: 0.3rem; background: rgba(0,0,0,0.08); margin-right: 0.3rem; }

/* ----- Export ----- */
.export-preview { border: 1px dashed var(--border-light, #e2e8f0); border-radius: 0.6rem; padding: 1rem; text-align: center; }
.export-preview-title { font-weight: 700; font-size: 1.1rem; color: var(--text-primary); }
.export-preview-meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.3rem; }
.export-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1rem; }

/* ----- Project Tools ----- */
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.tool-card-item { background: var(--card-bg); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--border-light, #e2e8f0); border-radius: 1.1rem; padding: 1.2rem; position: relative; display: flex; flex-direction: column; gap: 0.5rem; box-shadow: 0 4px 16px rgba(0,0,0,0.04); transition: transform 0.2s ease, box-shadow 0.2s ease; }
.tool-card-item:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(0,0,0,0.1); }
.tool-card-icon { width: 40px; height: 40px; border-radius: 0.7rem; background: var(--project-accent-soft); color: var(--project-accent); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; }
.tool-card-name { font-weight: 700; font-size: 0.95rem; color: var(--text-primary); position: relative; padding-right: 3.5rem; }
.tool-card-badge { position: absolute; top: 0; right: 0; font-size: 0.6rem; font-weight: 700; text-transform: uppercase; background: var(--project-accent-soft); color: var(--project-accent); padding: 0.15rem 0.5rem; border-radius: 1rem; }
.tool-card-desc { font-size: 0.8rem; color: var(--text-secondary); flex: 1; }
.tool-card-deferred { opacity: 0.9; }
.tool-pane { margin-top: 0.8rem; }

@media (max-width: 640px) {
  .dash-actions-row { flex-direction: column; }
  .dash-actions-row .btn { width: 100%; justify-content: center; }
  /* Setup / Review / Export: stacked, full width (side by side they squeezed their labels) */
  .dash-shortcuts { flex-direction: column; }
  .dash-shortcuts .btn { width: 100%; flex: 0 0 auto !important; justify-content: center; }
  .tools-grid { grid-template-columns: 1fr; }
  .export-actions { flex-direction: column; }
  .export-actions .btn { width: 100%; justify-content: center; }
}

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

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

@keyframes slideDown {
  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) {

  .chapters-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    z-index: 200;
    width: 85%;
    max-width: 320px;
    height: 100vh; height: 100dvh;
    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; height: 100dvh;
    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;
  }

  .ai-controls {
    padding: 0.6rem 1rem;
  }

  .ai-controls-row {
    flex-direction: column;
    gap: 0.5rem;
  }

  .ai-tone-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;
  }
  
  .generate-buttons-row {
    flex-direction: column;
    align-items: stretch;
  }
  
  .generate-btn {
    width: 100%;
    justify-content: center;
    padding: 0.65rem 1.5rem;
    font-size: 0.9rem;
  }
}

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

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

  .action-btn span {
    display: none;
  }

  /* Generate shares Humanize's fa-magic icon, so hiding its label like the
     other icon-only buttons above left the two indistinguishable at a
     glance on mobile (the accent background alone wasn't enough) — keep
     its text, just fitted down to a size that still fits the pill. Also
     overrides js/ask.js's UNRELATED chat message ".action-btn" (Copy/Word/
     Regenerate) mobile rule (css/ask.css) — that generic class name is
     shared, globally loaded, and pins width/height to a fixed 34px circle
     for its own icon-only buttons, which otherwise clips this one's label
     down to "Ge" since nothing here had overridden the width back to auto.
  */
  .action-btn.action-btn-accent {
    width: auto;
    height: auto;
  }
  .action-btn.action-btn-accent span {
    display: inline;
    font-size: 0.72rem;
  }

  .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;
  }

  .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;
  }

  .floating-scroll-btn {
    width: 42px;
    height: 42px;
    bottom: 1.5rem;
    font-size: 1rem;
  }
  
  /* Show edit controls always on touch */
  .chapter-item .edit-controls,
  .section-item .edit-controls {
    display: flex;
  }
}

@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;
  }

  .floating-scroll-btn {
    width: 38px;
    height: 38px;
    bottom: 1rem;
  }
}

/* ===== Print Styles ===== */
@media print {
  .navbar,
  .chapters-sidebar,
  .ai-panel,
  .formatting-toolbar,
  .ai-section-generate,
  .ai-controls,
  .workspace-topbar,
  .editor-header,
  .editor-actions,
  .history-drawer,
  #toast-container,
  .modal,
  .unsaved-overlay,
  .floating-scroll-btn,
  .supervisor-personality,
  .edit-controls,
  .add-section-item,
  .resources-panel,
  .resource-toggle-btn,
  .default-prompts-bar {
    display: none !important;
  }

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

  .project-workspace {
    display: block;
    overflow: visible;
  }

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

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

  .section-editor {
    color: #000;
    max-width: 100%;
    font-size: 12pt;
    line-height: 1.5;
  }
}
/* ===== Review: specific findings + AI fix flow ===== */
.review-finding-rich { flex-direction: column; align-items: stretch; gap: 0.45rem; }
.review-finding-head { display: flex; align-items: flex-start; gap: 0.45rem; font-weight: 600; }
.review-finding-head > i { flex-shrink: 0; margin-top: 0.15rem; }
.review-finding-head > span:not(.review-tag):not(.review-sev):not(.review-fixed-badge):not(.review-sev-dot) { flex: 1; min-width: 0; }
.review-sev { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; opacity: 0.75; }
.review-fixed { opacity: 0.6; }
.review-fixed-badge { margin-left: auto; font-size: 0.7rem; font-weight: 700; color: #10b981; display: inline-flex; align-items: center; gap: 0.15rem; }
.review-occurrences { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.review-occurrences li { display: flex; flex-direction: column; gap: 0.25rem; }
.review-value { font-size: 0.72rem; font-weight: 700; font-family: monospace; }
.review-goto { align-self: flex-start; background: none; border: none; padding: 0; cursor: pointer; font: inherit; font-size: 0.78rem; font-weight: 600; color: var(--project-accent); text-decoration: underline; text-underline-offset: 2px; display: inline-flex; align-items: center; gap: 0.25rem; text-align: left; }
.review-quote { margin: 0; padding: 0.4rem 0.65rem; border-left: 2px solid currentColor; background: rgba(0, 0, 0, 0.04); border-radius: 0 0.4rem 0.4rem 0; font-size: 0.8rem; font-style: italic; color: var(--text-primary); }
.review-note { color: var(--text-primary); font-size: 0.84rem; }
.review-suggestion { font-size: 0.8rem; color: var(--text-secondary); display: flex; gap: 0.3rem; }
.review-finding-actions { display: flex; justify-content: flex-end; }
.review-fix-btn { display: inline-flex; align-items: center; gap: 0.3rem; background: var(--project-accent); color: #fff; border: none; border-radius: 2rem; padding: 0.35rem 0.9rem; font-size: 0.75rem; font-weight: 600; cursor: pointer; font-family: inherit; }
.review-fix-btn:hover { filter: brightness(1.08); }
.proj-fix-modal .modal-content { max-width: 640px; }
.proj-fix-loading { text-align: center; padding: 1.5rem 0.5rem; color: var(--text-secondary); }
.proj-fix-loading p { color: var(--text-primary); font-weight: 500; margin: 0.25rem 0; }
.proj-fix-summary { font-size: 0.88rem; color: var(--text-primary); margin: 0 0 1rem; }
.proj-fix-edit { border: 1px solid var(--border-light); border-radius: 0.8rem; padding: 0.8rem; margin-bottom: 0.8rem; background: var(--surface); }
.proj-fix-edit-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; font-size: 0.8rem; }
.proj-fix-edit-head label { display: inline-flex; align-items: center; gap: 0.3rem; font-weight: 600; cursor: pointer; }
.proj-fix-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; color: var(--text-secondary); margin: 0.5rem 0 0.25rem; }
.proj-fix-label small { text-transform: none; font-weight: 400; }
.proj-fix-original { margin: 0; padding: 0.5rem 0.7rem; border-left: 3px solid #dc2626; background: rgba(220, 38, 38, 0.06); border-radius: 0 0.5rem 0.5rem 0; font-size: 0.82rem; color: var(--text-primary); }
.proj-fix-replacement { width: 100%; box-sizing: border-box; border: 1px solid #10b981; background: rgba(16, 185, 129, 0.06); border-radius: 0.5rem; padding: 0.5rem 0.7rem; font: inherit; font-size: 0.85rem; color: var(--text-primary); resize: vertical; }
.proj-fix-reason { font-size: 0.76rem; color: var(--text-secondary); margin-top: 0.4rem; display: flex; gap: 0.3rem; }
.proj-fix-footer { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
[data-theme="dark"] .review-quote { background: rgba(255, 255, 255, 0.05); }
/* ===== Review / Project AI — Lixa-consistent chat (mobile-first) ===== */
.review-header-bar { position: relative; gap: 0.5rem; }
.review-header-actions { display: flex; align-items: center; gap: 0.4rem; }
.review-icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border-light); background: var(--surface); color: var(--text-secondary); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 1.05rem; }
.review-icon-btn[aria-expanded="true"], .review-icon-btn:hover { color: var(--project-accent); border-color: var(--project-accent); background: var(--project-accent-soft); }
.proj-ai-settings-pop { position: absolute; top: calc(100% + 0.4rem); right: 0.6rem; z-index: 40; width: min(320px, calc(100vw - 2rem)); background: var(--surface); border: 1px solid var(--border-light); border-radius: 0.9rem; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14); padding: 0.8rem 0.9rem; border-bottom: 1px solid var(--border-light); }
.proj-ai-settings-pop[hidden] { display: none; }
.proj-ai-settings-pop .personality-row { flex-direction: column; gap: 0.6rem; }
.review-ai-panel .ai-chat-area { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.review-ai-panel .ai-chat-messages.chat-messages { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 1rem 1.1rem; gap: 1rem; background: transparent; }
.review-ai-panel .message.user .message-bubble { font-size: 0.92rem; }
.review-ai-panel .message.assistant .message-bubble { font-size: 0.92rem; }
.review-ai-panel .typing-indicator { padding: 0.4rem 0.2rem; }
.proj-ai-strip { flex-shrink: 0; display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 0.45rem; padding: 0.45rem 0.9rem; border-bottom: none; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.proj-ai-strip::-webkit-scrollbar { display: none; }
.proj-ai-strip .proj-ai-action-btn { flex-shrink: 0; white-space: nowrap; min-height: 34px; }
.proj-ai-strip .proj-ai-prompt-chip { background: var(--surface); border-color: var(--border-light); color: var(--text-primary); }
.proj-chat-input { margin: 0; padding: 0.35rem 0.75rem 0.6rem; background: transparent; }
.proj-composer { flex-direction: row; align-items: flex-end; gap: 0.5rem; padding: 0.35rem 0.4rem 0.35rem 0.9rem; }
.proj-composer textarea { flex: 1; border: none; background: transparent; resize: none; outline: none; font: inherit; font-size: 0.95rem; color: var(--text-primary); padding: 0.45rem 0; max-height: 120px; min-height: 24px; line-height: 1.4; }
.proj-send-btn { width: 38px; height: 38px; border-radius: 50%; border: none; background: var(--project-accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.proj-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.proj-anon-note { margin: 0.35rem 0.4rem 0; font-size: 0.7rem; color: var(--text-secondary); display: flex; gap: 0.3rem; align-items: center; }
.proj-open-findings { display: inline-flex; align-items: center; gap: 0.3rem; margin-top: 0.5rem; padding: 0.35rem 0.8rem; border-radius: 1.5rem; border: 1px solid var(--project-accent); background: var(--project-accent-soft); color: var(--project-accent); font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer; }

/* Findings: filters, compact expandable items, sticky review button */
.review-findings-panel { display: flex; flex-direction: column; padding: 0; }
.review-filter-bar { position: sticky; top: 0; z-index: 5; display: flex; gap: 0.4rem; overflow-x: auto; padding: 0.7rem 0.9rem; background: var(--card-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--border-light); scrollbar-width: none; }
.review-filter { flex-shrink: 0; border: 1px solid var(--border-light); background: var(--surface); color: var(--text-secondary); border-radius: 2rem; padding: 0.35rem 0.85rem; font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer; min-height: 34px; }
.review-filter.active { background: var(--project-accent); border-color: var(--project-accent); color: #fff; }
.review-filter-count:not(:empty)::before { content: '· '; }
.review-section { padding: 0.8rem 0.9rem 0.2rem; }
.review-section-title { margin: 0 0 0.6rem; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-secondary); display: flex; gap: 0.4rem; align-items: center; }
.review-section-title i { color: var(--project-accent); font-size: 1rem; }
details.review-finding-rich { display: block; padding: 0; }
details.review-finding-rich[hidden] { display: none; }
details.review-finding-rich > summary { list-style: none; cursor: pointer; padding: 0.65rem 0.8rem; display: flex; align-items: center; gap: 0.5rem; }
details.review-finding-rich > summary::-webkit-details-marker { display: none; }
.review-summary-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
details[open] .review-summary-text { white-space: normal; }
.review-chevron { transition: transform 0.2s ease; flex-shrink: 0; }
details[open] .review-chevron { transform: rotate(180deg); }
.review-sev-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.review-finding-body { padding: 0 0.8rem 0.75rem; display: flex; flex-direction: column; gap: 0.45rem; }
.review-finding-actions { gap: 0.45rem; flex-wrap: wrap; }
.review-discuss-btn { display: inline-flex; align-items: center; gap: 0.3rem; background: var(--surface); color: var(--text-primary); border: 1px solid var(--border-light); border-radius: 2rem; padding: 0.35rem 0.9rem; font: inherit; font-size: 0.75rem; font-weight: 600; cursor: pointer; min-height: 32px; }
.review-sticky-bar { position: sticky; bottom: 0; margin-top: auto; padding: 0.7rem 0.9rem calc(0.7rem + env(safe-area-inset-bottom, 0px)); background: var(--card-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border-light); }
.review-sticky-bar .btn { width: 100%; justify-content: center; min-height: 40px; }

/* Phones: Review goes edge-to-edge and the chat owns the screen */
@media (max-width: 640px) {
  #projScreenReview, #projScreenReview.active { padding: 0; }
  #projScreenReview .review-header-bar { border-radius: 0; border-left: none; border-right: none; padding: 0.6rem 0.9rem; }
  #projScreenReview .review-ai-panel.ai-panel, #projScreenReview .review-findings-panel { border-radius: 0; border-left: none; border-right: none; border-bottom: none; }
  #projScreenReview .proj-ai-context { padding: 0.45rem 0.9rem 0; }
}
/* Lixa bubbles inside Review: neutralise the pre-redesign .ai-message card styles */
.review-ai-panel .ai-message.message { background: none; border: none; padding: 0; box-shadow: none; max-width: 100%; }
.review-ai-panel .ai-message.message.user { max-width: 85%; align-self: flex-end; }
.review-ai-panel .ai-message.message.assistant { align-self: flex-start; width: 100%; }
.review-ai-panel .ai-chat-input.proj-chat-input { display: block; border-top: none; background: transparent; }
.review-ai-panel .proj-composer { width: 100%; box-sizing: border-box; }
.review-ai-panel .proj-composer textarea { border: none; background: transparent; box-shadow: none; }
/* Project AI preferences — modal (was a popover that got hidden behind panels) */
.proj-settings-overlay { position: fixed; inset: 0; z-index: 10050; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 30, 0.45); backdrop-filter: blur(3px); }
.proj-settings-overlay[hidden] { display: none; }
.proj-settings-modal { width: min(420px, 100%); background: var(--surface); color: var(--text-primary); border: 1px solid var(--border-light); border-radius: 1.1rem; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25); padding: 1.1rem 1.2rem 1rem; animation: projSettingsIn 0.18s ease; }
@keyframes projSettingsIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.proj-settings-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.proj-settings-head h3 { margin: 0; font-size: 1.02rem; display: flex; align-items: center; gap: 0.4rem; }
.proj-settings-head h3 i { color: var(--accent); }
.proj-settings-close { border: 0; background: transparent; color: var(--text-secondary); font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 0.1rem 0.4rem; border-radius: 0.5rem; }
.proj-settings-sub { margin: 0.35rem 0 0.9rem; font-size: 0.82rem; color: var(--text-secondary); }
.proj-settings-body .supervisor-personality { display: block !important; position: static; box-shadow: none; border: 0; padding: 0; background: transparent; width: auto; }
.proj-settings-body .personality-row { display: flex; flex-direction: column; gap: 0.75rem; }
.proj-settings-body select, .proj-settings-body input { width: 100%; }
.proj-settings-foot { display: flex; justify-content: flex-end; margin-top: 1rem; }
.proj-settings-foot .generate-btn { padding: 0.55rem 1.4rem; }
body.proj-settings-open { overflow: hidden; }
/* ---- Project Tools (Phase 1: search, history, sample size, statistics, alignment, citations) ---- */
#toolPanePlaceholder .card-body { display: flex; flex-direction: column; gap: 0.6rem; }
.pt-input { width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border-light); border-radius: 0.7rem; background: var(--surface); color: var(--text-primary); font: inherit; font-size: 0.92rem; box-sizing: border-box; }
textarea.pt-input { resize: vertical; line-height: 1.5; }
.pt-label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 0.25rem; }
.pt-muted { color: var(--text-secondary); font-size: 0.84rem; }
.pt-note { background: color-mix(in srgb, var(--accent) 9%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); border-radius: 0.8rem; padding: 0.7rem 0.9rem; font-size: 0.9rem; margin: 0; }
.pt-note p { margin: 0.2rem 0; }
.pt-good { color: #1f9d55; } .pt-bad { color: #d64545; } .pt-warn { color: #c98a00; }
.pt-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.pt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0.7rem; }
.pt-field small { display: block; margin-top: 0.2rem; }
.pt-small { padding: 0.3rem 0.65rem !important; font-size: 0.8rem !important; }
.pt-h { margin: 0.9rem 0 0.3rem; font-size: 0.95rem; }
.pt-list { margin: 0.2rem 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: 0.35rem; }
.pt-link { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; text-align: left; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.pt-hit { display: flex; flex-direction: column; gap: 0.2rem; width: 100%; text-align: left; border: 1px solid var(--border-light); background: var(--surface); color: var(--text-primary); border-radius: 0.7rem; padding: 0.6rem 0.75rem; margin-bottom: 0.45rem; cursor: pointer; font: inherit; }
.pt-hit:hover { border-color: var(--accent); }
.pt-hit-where { font-size: 0.76rem; font-weight: 600; color: var(--accent); }
.pt-hit-text { font-size: 0.88rem; line-height: 1.45; }
.pt-hit mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.pt-day { font-weight: 700; font-size: 0.85rem; margin: 0.9rem 0 0.2rem; }
.pt-event { display: flex; gap: 0.8rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border-light); font-size: 0.9rem; }
.pt-event-time { flex: 0 0 auto; min-width: 5.2rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; font-size: 0.82rem; }
.pt-event-main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pt-big { font-size: 2.2rem; font-weight: 800; margin-top: 0.8rem; line-height: 1.1; }
.pt-big span { font-size: 1rem; font-weight: 600; color: var(--text-secondary); }
.pt-formula { font-family: ui-monospace, Consolas, monospace; font-size: 0.82rem; background: color-mix(in srgb, var(--text-primary) 5%, transparent); padding: 0.6rem 0.75rem; border-radius: 0.6rem; overflow-x: auto; }
.pt-output { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.8rem; padding-top: 0.8rem; border-top: 1px solid var(--border-light); }
.pt-analysis { border: 1px solid var(--border-light); border-radius: 0.9rem; padding: 0.8rem 0.9rem; }
.pt-plan { margin-top: 0.7rem; display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; }
.pt-plan .pt-label { display: inline; margin-right: 0.3rem; }
.pt-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.6rem; }
.pt-stats > div { border: 1px solid var(--border-light); border-radius: 0.8rem; padding: 0.6rem 0.75rem; display: flex; flex-direction: column; }
.pt-stats strong { font-size: 1.5rem; } .pt-stats span { font-size: 0.78rem; color: var(--text-secondary); }
.pt-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pt-table { border-collapse: collapse; width: 100%; min-width: 680px; font-size: 0.84rem; }
.pt-table th, .pt-table td { border: 1px solid var(--border-light); padding: 0.45rem 0.55rem; vertical-align: top; text-align: left; }
.pt-table th { font-size: 0.76rem; color: var(--text-secondary); }

/* ---- Project Tools, Phase 2 ---- */
.pt-preview { border: 1px solid var(--border-light); border-radius: 0.8rem; padding: 0.9rem 1rem; background: #fff; color: #111; font-family: "Times New Roman", Georgia, serif; font-size: 0.9rem; max-height: 420px; overflow: auto; }
.pt-preview table { border-collapse: collapse; width: 100%; margin: 0.4rem 0; font-size: 0.82rem; }
.pt-preview th, .pt-preview td { border: 1px solid #888; padding: 0.25rem 0.4rem; text-align: left; }
.pt-preview h2, .pt-preview h3 { color: #111; margin: 0.6rem 0 0.3rem; font-size: 1rem; }
.pt-page { position: relative; width: min(100%, 280px); aspect-ratio: 210 / 297; background: #fff; color: #111; border: 1px solid #d0d5da; box-shadow: 0 6px 18px rgba(0,0,0,0.12); overflow: hidden; box-sizing: border-box; margin: 0 auto; }
.pt-page-num { position: absolute; font-size: 7px; color: #444; }
.pt-score { font-weight: 800; font-size: 1.05rem; white-space: nowrap; }
details.pt-analysis > summary { cursor: pointer; list-style-position: inside; }
.pt-page p, .pt-page div, .pt-preview p { color: #111; }
