: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;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-pill: 999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
}

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

/* Shared app controls */
.app-page {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 16px;
}

.app-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.app-page-header h1 {
  margin: 0;
  color: var(--green-700);
  font-size: 24px;
}

.app-page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ui-button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-md);
  padding: 6px 14px;
  color: var(--green-700);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.ui-button:disabled {
  background: #f4f6f7;
  color: #43515c;
  border-color: var(--line);
  cursor: not-allowed;
}

.ui-button--primary {
  border-color: var(--green-600);
  background: var(--green-600);
  color: #fff;
}

.ui-button--primary:hover:not(:disabled) {
  background: var(--green-700);
  border-color: var(--green-700);
}

.ui-button--danger {
  color: #c0392b;
}

.ui-button--danger:hover:not(:disabled) {
  background: #fdecea;
  border-color: #c0392b;
}

.ui-button:active:not(:disabled),
.workspace-toolbar button:active:not(:disabled),
.dialog-actions button:active:not(:disabled),
.process-step-actions button:active:not(:disabled) {
  filter: brightness(0.95);
}

.ui-button:focus-visible,
.workspace-toolbar button:focus-visible,
.dialog-actions button:focus-visible,
.process-step-actions button:focus-visible {
  outline: none;
  border-color: var(--green-600);
  box-shadow: 0 0 0 2px rgba(45, 122, 88, 0.16);
}

.ui-field,
.ui-select {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  background: #fff;
  color: #202a33;
}

.ui-field:focus,
.ui-select:focus {
  outline: none;
  border-color: var(--green-600);
  box-shadow: 0 0 0 2px rgba(45, 122, 88, 0.16);
}

.ui-field:disabled,
.ui-select:disabled {
  background: #f4f6f7;
  color: var(--muted);
  cursor: not-allowed;
}

.ui-error {
  color: #c0392b;
  font-size: 14px;
  margin: 8px 0 0;
}

.ui-success {
  color: var(--green-700);
  font-size: 14px;
  margin: 8px 0 0;
}

/* Tables */
.ui-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.ui-table th,
.ui-table td {
  text-align: left;
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--line);
}

.ui-table th {
  background: var(--green-100);
  color: var(--green-700);
  font-weight: 600;
}

.ui-table tr:last-child td {
  border-bottom: none;
}

.ui-table tbody tr:hover {
  background: #f8faf9;
}

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

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

/* 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: var(--radius-md);
  padding: 6px 14px;
  color: var(--green-700);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.workspace-toolbar button:disabled {
  background: #f4f6f7;
  color: #43515c;
  border-color: var(--line);
  cursor: not-allowed;
}

.toolbar-menu {
  position: relative;
  display: inline-flex;
}

.toolbar-menu-list {
  position: absolute;
  top: 100%;
  left: 0;
  margin: 4px 0 0;
  padding: 4px;
  min-width: 120px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  z-index: 10;
}

.toolbar-menu-list button {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  text-align: left;
  color: var(--green-700);
  cursor: pointer;
}

.toolbar-menu-list button:hover {
  background: var(--green-100);
}

.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: 360px;
  flex: 0 0 360px;
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.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;
  transition: background-color 0.15s ease;
}

.lesson-sidebar-item:not(.lesson-sidebar-item--active) .lesson-sidebar-select:hover {
  background: #f4f6f7;
}

.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: var(--radius-pill);
  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: 24px;
}

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

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

.page-subtitle {
  font-size: 13px;
  font-weight: 400;
  color: var(--green-600);
  margin-left: 10px;
  letter-spacing: 0.05em;
  vertical-align: middle;
}

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

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

.objective-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}

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

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

.process-step-actions button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-size: 12px;
  cursor: pointer;
  color: #c0392b;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.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: var(--radius-sm);
  padding: 8px;
  min-height: 6em;
}

.warning-summary {
  margin: 8px 0 0;
  padding: 8px 12px;
  border: 1px solid #e6c98b;
  background: #fbf3e1;
  border-radius: var(--radius-sm);
  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: var(--radius-sm);
  padding: 2px 4px;
  background: transparent;
  resize: none;
  overflow: hidden;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.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: var(--radius-sm);
  border: 1px solid transparent;
  cursor: text;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.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: var(--radius-sm);
  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: var(--radius-xl);
  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: var(--radius-md);
}

.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: var(--radius-lg);
  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: var(--radius-md);
  padding: 6px 14px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.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: var(--radius-sm);
  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;
  }
}

@media (max-width: 600px) {
  .workspace-toolbar {
    height: auto;
    flex: 0 0 auto;
    flex-wrap: wrap;
    padding: var(--space-2) var(--space-4);
    gap: var(--space-2);
  }

  .workspace-toolbar button {
    flex: 0 0 auto;
  }

  .workspace-toolbar .toolbar-menu {
    flex: 0 0 auto;
  }

  .workspace-toolbar-count {
    flex: 1 1 100%;
  }
}

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

.dialog input {
  flex: 1 1 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  width: 100%;
}

.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: var(--radius-lg);
}

.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: var(--radius-md);
  padding: 8px 12px;
  resize: vertical;
  margin-top: 8px;
}

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

.batch-count-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--muted);
}

.batch-count-field input {
  flex: 0 0 auto;
  width: 80px;
}

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