:root {
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #202a33;
  background: #edf0f2;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --green-700: #216447;
  --green-600: #2d7a58;
  --green-100: #dceee5;
  --line: #cfd5da;
  --muted: #68747f;
  --paper-width: 210mm;
  --paper-min-height: 297mm;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
}

button,
textarea,
input {
  font: inherit;
}

#app {
  min-height: 100vh;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Toolbar */
.workspace-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  flex: 0 0 56px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.workspace-toolbar button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 6px 14px;
  color: var(--green-700);
  cursor: pointer;
}

.workspace-toolbar button:hover:not(:disabled) {
  background: var(--green-100);
  border-color: var(--green-600);
}

.workspace-toolbar button:disabled {
  color: var(--muted);
  border-color: var(--line);
  cursor: not-allowed;
  opacity: 0.6;
}

.workspace-toolbar-count,
.workspace-toolbar-warning,
.workspace-toolbar-status {
  font-size: 14px;
  color: var(--muted);
}

.workspace-toolbar-warning {
  color: #b65c00;
}

.workspace-toolbar-status--error {
  color: #c0392b;
}

.workspace-toolbar-status--saved {
  color: var(--green-700);
}

/* Layout */
.workspace-layout {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

/* Sidebar */
.lesson-sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.lesson-sidebar-cover {
  border: none;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--green-700);
  cursor: pointer;
}

.lesson-sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.lesson-sidebar-item {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
}

.lesson-sidebar-item--active {
  background: var(--green-100);
  box-shadow: inset 3px 0 0 var(--green-600);
}

.lesson-sidebar-select {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  background: none;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  min-width: 0;
}

.lesson-sidebar-number {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.lesson-sidebar-topic {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lesson-sidebar-badge {
  flex: 0 0 auto;
  background: #e67e22;
  color: #fff;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.6;
  min-width: 1.6em;
  text-align: center;
  padding: 0 4px;
}

.lesson-sidebar-remove {
  flex: 0 0 auto;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 12px;
  font-size: 16px;
}

.lesson-sidebar-remove:hover {
  color: #c0392b;
}

/* Paper canvas */
.a4-workspace {
  flex: 1 1 auto;
  overflow: auto;
  padding: 16mm;
  display: flex;
  justify-content: center;
}

.a4-paper {
  flex: 0 0 auto;
}

/* A4 page */
.page {
  display: block;
  width: var(--paper-width);
  min-height: var(--paper-min-height);
  margin: 0 auto;
  padding: 16mm;
  background: #fff;
  box-shadow: 0 4px 18px rgba(32, 42, 51, 0.12);
}

.print-book .page {
  box-shadow: none;
}

/* Cover page */
.cover-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 24px;
}

.cover-title {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--green-700);
  margin: 0;
}

.cover-field {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
}

.cover-field-label {
  color: var(--muted);
}

.cover-field-value {
  min-width: 12em;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

/* Teaching design page */
.teaching-design-page {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.design-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--green-700);
}

.section-heading {
  margin: 12px 0 0;
  padding-left: 10px;
  border-left: 4px solid var(--green-600);
  font-size: 16px;
  color: var(--green-700);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.basic-info-table th,
.basic-info-table td,
.process-table th,
.process-table td,
.reflection-table th,
.reflection-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  vertical-align: top;
  text-align: left;
}

.basic-info-table th,
.process-table th,
.reflection-table th {
  background: var(--green-100);
  color: var(--green-700);
  font-weight: 600;
  width: 8em;
}

.process-table th {
  width: auto;
}

.objectives-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.objective-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.objective-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.process-step-name > * + * {
  margin-top: 4px;
}

.process-step-actions {
  width: 6em;
  text-align: center;
}

.process-step-actions button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  cursor: pointer;
  color: #c0392b;
}

.process-step-actions button:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.board-design {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px;
  min-height: 6em;
}

.warning-summary {
  margin: 8px 0 0;
  padding: 8px 12px;
  border: 1px solid #e6c98b;
  background: #fbf3e1;
  border-radius: 4px;
  color: #8a6116;
  font-size: 13px;
}

/* Editable fields */
.editable-field {
  font: inherit;
  color: inherit;
  line-height: 1.6;
}

.editable-text {
  display: block;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 2px 4px;
  background: transparent;
  resize: none;
  overflow: hidden;
}

.editable-text--multiline {
  white-space: pre-wrap;
}

.editable-text--static {
  display: block;
  width: 100%;
  white-space: pre-wrap;
  padding: 2px 4px;
}

.editable-text:hover {
  background: var(--green-100);
}

.editable-text:focus {
  background: #fff;
  border-color: var(--green-600);
  outline: none;
}

.editable-markdown {
  width: 100%;
}

.markdown-preview {
  min-height: 1.6em;
  padding: 2px 4px;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: text;
}

.markdown-preview--empty {
  color: var(--muted);
}

.markdown-preview :first-child {
  margin-top: 0;
}

.markdown-preview :last-child {
  margin-bottom: 0;
}

.markdown-preview:hover {
  background: var(--green-100);
}

.markdown-source {
  display: block;
  width: 100%;
  border: 1px solid var(--green-600);
  border-radius: 4px;
  padding: 2px 4px;
  background: #fff;
  resize: none;
  overflow: hidden;
  outline: none;
}

/* Upload dropzone */
.upload-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 16mm auto;
  max-width: 480px;
  min-height: 200px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--muted);
  text-align: center;
  padding: 24px;
  cursor: pointer;
}

.upload-dropzone--drag-over {
  border-color: var(--green-600);
  background: var(--green-100);
}

.upload-dropzone--compact {
  flex-direction: row;
  min-height: 0;
  margin: 0;
  padding: 6px 14px;
  border-radius: 6px;
}

.upload-dropzone-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload-dropzone-title {
  font-size: 16px;
  color: #202a33;
  margin: 0;
}

.upload-dropzone-hint {
  font-size: 13px;
  margin: 0;
}

/* Dialogs and notices */
.dialog-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(32, 42, 51, 0.4);
  z-index: 10;
}

.dialog {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  max-width: 420px;
  box-shadow: 0 12px 32px rgba(32, 42, 51, 0.25);
}

.dialog-filenames {
  margin: 8px 0;
  padding-left: 20px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.dialog-actions button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
}

.app-notice {
  margin: 0;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-notice--error {
  background: #fdecea;
  color: #c0392b;
  border-bottom: 1px solid #f5c6c0;
}

.app-notice button {
  border: 1px solid currentcolor;
  background: none;
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  color: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* Responsive */
@media (max-width: 900px) {
  .workspace-layout {
    flex-direction: column;
  }

  .lesson-sidebar {
    width: auto;
    flex: 0 0 auto;
    max-height: 180px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .a4-workspace {
    padding: 6mm;
  }

  .page {
    width: 100%;
    min-height: auto;
  }
}

/* Book list */
.book-list-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 16px;
}

.book-list-create {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.dialog input,
.book-list-create input,
.book-list-item input {
  flex: 1 1 auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
}

.book-list-create button,
.book-list-item button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 6px 14px;
  color: var(--green-700);
  cursor: pointer;
  white-space: nowrap;
}

.book-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.book-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.book-list-name {
  font-weight: 600;
  flex: 0 0 auto;
}

.book-list-meta {
  flex: 1 1 auto;
  color: var(--muted);
  font-size: 14px;
}

/* Batch generate dialog */
.batch-dialog {
  width: 480px;
}

.batch-topics-input {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  resize: vertical;
  margin-top: 8px;
}

.batch-topics-input:focus {
  outline: none;
  border-color: var(--green-600);
}

.batch-topics-count {
  font-size: 13px;
  color: var(--muted);
  margin: 6px 0 0;
}

.batch-progress-label {
  font-size: 16px;
  margin: 8px 0 4px;
}

.batch-current-topic {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.batch-progress-bar {
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}

.batch-progress-fill {
  height: 100%;
  background: var(--green-600);
  border-radius: 3px;
  transition: width 0.3s ease;
}
