:root {
  --page-gutter: 18px;
}

body {
  margin: 0;
  padding: var(--page-gutter);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--app-bg, #f5f7f6);
  color: var(--app-fg, #333);
}

.checklist-shell {
  max-width: 1240px;
  margin: 0 auto;
}

.checklist-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line, #eee);
  margin: calc(-1 * var(--page-gutter)) calc(-1 * var(--page-gutter)) 14px;
  z-index: 100;
}

.checklist-toolbar .tb-action-group {
  margin-left: auto;
}

.tbtn {
  border: none;
  cursor: pointer;
  border-radius: 18px;
  padding: 6px 12px;
  font-size: 13px;
  background: var(--btn, #ff8fb1);
  color: var(--btn-fg, #fff);
  font-weight: 600;
  transition: transform 0.12s;
}

.tbtn:hover { transform: translateY(-1px); }
.tbtn.ghost {
  background: #fff;
  color: var(--accent, #ff5c8a);
  border: 1.5px solid var(--accent, #ff5c8a);
}

.tb-label { font-size: 13px; color: var(--teacher, #666); }

.checklist-workspace {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.checklist-library {
  width: 210px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--line, #eee);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.lib-head { display: flex; gap: 6px; margin-bottom: 6px; }
.lib-head .tbtn { flex: 1; padding: 6px 8px; font-size: 12px; }
.lib-io { display: flex; gap: 6px; margin-bottom: 8px; }
.lib-io .tbtn { flex: 1; padding: 5px 6px; font-size: 11px; }
.lib-count { font-size: 10px; color: var(--teacher, #666); margin-bottom: 8px; }
.lib-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 420px;
  overflow: auto;
}
.lib-item {
  border: 1.5px solid var(--line, #eee);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.lib-item:hover { border-color: var(--accent, #ff5c8a); }
.lib-item.active {
  border-color: var(--accent, #ff5c8a);
  box-shadow: 0 0 0 2px var(--accent, #ff5c8a);
}
.lib-item-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--title, #333);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-item-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  min-height: 14px;
}
.save-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.save-status.idle { display: none; }
.save-status.saving::before {
  content: "";
  width: 11px;
  height: 11px;
  border: 2px solid var(--checklist-spinner-border, var(--spinner-border, rgba(0, 0, 0, 0.15)));
  border-top-color: var(--app-fg, #ff5c8a);
  border-radius: 50%;
  animation: save-spin 0.65s linear infinite;
}
.save-status.saved::before {
  content: "✓";
  font-size: 12px;
  font-weight: 800;
  color: #43a047;
  line-height: 1;
}
@keyframes save-spin { to { transform: rotate(360deg); } }
.lib-item-date { font-size: 10px; color: var(--teacher, #666); }
.lib-item-date.is-saving { color: var(--app-fg, #333); font-weight: 600; }
.lib-item-date.is-saved { color: #5d6b63; }
.lib-item-actions { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.lib-item-actions .lib-btn {
  border: 1px solid var(--line, #eee);
  background: #fafafa;
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  color: var(--teacher, #666);
}
.lib-item-actions .lib-btn:hover { background: var(--line, #eee); color: var(--title, #333); }
.lib-item-actions .lib-btn.danger:hover {
  background: #ffe8ec;
  color: #c62828;
  border-color: #ffcdd2;
}
.lib-empty { font-size: 12px; color: var(--teacher, #666); text-align: center; padding: 12px 4px; }

.library-toggle-btn { display: none; }
.library-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 199;
}
.library-backdrop.open { display: block; }

.checklist-sheet-wrap {
  flex: 1;
  min-width: 0;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.checklist-sheet {
  background: var(--sheet-bg, #fff);
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  width: 100%;
  box-sizing: border-box;
}

.checklist-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--title, #333);
  letter-spacing: 4px;
  text-align: center;
  margin-bottom: 14px;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 8px;
  outline: none;
}
.checklist-title:hover,
.checklist-title:focus {
  background: var(--checklist-title-hover-bg, rgba(255, 92, 138, 0.08));
}

.checklist-table {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  --checklist-cell: 48px;
  --checklist-rowhead-w: var(--checklist-cell);
  margin: 0 auto;
}

.checklist-table th,
.checklist-table td {
  border: 1.5px solid var(--line, #ddd);
  box-sizing: border-box;
  padding: 4px 3px;
  text-align: center;
  vertical-align: middle;
  font-size: 13px;
  line-height: 1.25;
  width: var(--checklist-cell);
  height: var(--checklist-cell);
  min-width: var(--checklist-cell);
  min-height: var(--checklist-cell);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow: hidden;
}

.checklist-table thead th {
  background: var(--checklist-thead-bg, #f5f5f5);
  font-weight: 700;
  color: var(--hd-fg, var(--title, #333));
  position: sticky;
  top: 0;
  z-index: 2;
}

.checklist-corner {
  background: var(--checklist-corner-bg, #eee);
  font-weight: 700;
  color: var(--sec-fg, var(--title, #333));
  position: sticky;
  left: 0;
  z-index: 3;
  width: var(--checklist-rowhead-w);
  min-width: var(--checklist-rowhead-w);
}

.checklist-rowhead {
  background: var(--checklist-rowhead-bg, #fafafa);
  font-weight: 700;
  color: var(--time-fg, var(--title, #333));
  position: sticky;
  left: 0;
  z-index: 1;
  width: var(--checklist-rowhead-w);
  min-width: var(--checklist-rowhead-w);
}

.checklist-cell {
  cursor: pointer;
  background: #fff;
  color: var(--title, #333);
}
.checklist-cell:hover,
.checklist-colhead:hover,
.checklist-rowhead:hover,
.checklist-corner:hover {
  background: var(--checklist-hover-bg, #f9f9f9);
}

.checklist-colhead {
  cursor: pointer;
  position: relative;
  line-height: 1.25;
}

.col-del-btn,
.row-del-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
  padding: 2px 6px;
  font-size: 11px;
  border: 1px solid var(--line, #ddd);
  border-radius: 6px;
  background: #fff;
  color: #c62828;
  cursor: pointer;
  vertical-align: middle;
}
.col-del-btn:hover,
.row-del-btn:hover {
  background: #ffe8ec;
}

.checklist-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* Export modal (shared pattern) */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.modal-box {
  background: #fff;
  border-radius: 16px;
  width: min(96vw, 960px);
  height: min(94vh, 880px);
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  font-weight: 700;
}
.modal-head button {
  border: none;
  background: none;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}
.modal-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid #eee;
}
.orient-btn {
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 14px;
  padding: 5px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #444;
}
.orient-btn.active {
  border-color: var(--accent, #ff5c8a);
  background: var(--accent, #ff5c8a);
  color: #fff;
}
.export-select {
  max-width: 180px;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 5px 8px;
  font-size: 12px;
  background: #fff;
  color: #333;
}
.export-multi {
  position: relative;
  display: inline-block;
  vertical-align: middle;
}
.export-multi-toggle {
  cursor: pointer;
  min-width: 120px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.export-multi-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 40;
  min-width: 200px;
  max-height: 240px;
  overflow: auto;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 6px 0;
}
.export-multi-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: #333;
  cursor: pointer;
  user-select: none;
}
.export-multi-item:hover {
  background: #f5f6f8;
}
.export-multi-item input {
  margin: 0;
  flex: none;
}
.export-multi-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.export-titles {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.export-title-input {
  width: 120px;
  max-width: 28vw;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 5px 8px;
  font-size: 12px;
  background: #fff;
  color: #333;
}
.zoom-group { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.zbtn {
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 14px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #444;
  min-width: 30px;
}
.modal-body {
  padding: 14px;
  overflow: auto;
  background: #f4f5f7;
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.modal-body canvas {
  display: block;
  flex-shrink: 0;
  margin: 0 auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  background: #fff;
}
.modal-foot {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 12px;
  border-top: 1px solid #eee;
  flex: none;
}

body.modal-open { overflow: hidden; }
body.library-open { overflow: hidden; }
body.exporting .checklist-library,
body.exporting .checklist-toolbar,
body.exporting .exp-hide,
body.exporting .site-footer { display: none !important; }

/* html2canvas 无法正确绘制 sticky；导出宿主与 body.exporting 都恢复为正常表格流 */
body.exporting .checklist-table thead th,
body.exporting .checklist-corner,
body.exporting .checklist-rowhead,
.export-capture-host .checklist-table thead th,
.export-capture-host .checklist-corner,
.export-capture-host .checklist-rowhead {
  position: static !important;
  left: auto !important;
  top: auto !important;
  z-index: auto !important;
}

body.exporting .checklist-sheet,
.export-capture-host .checklist-sheet {
  overflow: visible;
  padding-bottom: 4px;
}

body.exporting .checklist-table,
.export-capture-host .checklist-table {
  margin-bottom: 2px;
}

.site-footer {
  text-align: center;
  font-size: 11px;
  color: var(--teacher, #888);
  margin-top: 24px;
  padding: 8px;
}
.ft-sep { margin: 0 6px; opacity: 0.5; }

@media (max-width: 960px) {
  .checklist-workspace { flex-direction: column; }
  .checklist-library { width: 100%; }
  .lib-list { max-height: 200px; }
}

@media (max-width: 768px) {
  .checklist-toolbar { flex-direction: column; align-items: stretch; }
  .checklist-toolbar .tb-action-group {
    margin-left: 0;
    flex-wrap: wrap;
  }
  .checklist-toolbar .tbtn { min-height: 44px; }
}

@media (max-width: 640px) {
  :root { --page-gutter: 12px; }
  .library-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
  }
  .checklist-library {
    position: fixed;
    left: var(--page-gutter);
    top: 56px;
    bottom: var(--page-gutter);
    width: min(300px, calc(100vw - var(--page-gutter) * 2));
    z-index: 200;
    transform: translateX(calc(-100% - 24px));
    transition: transform 0.25s ease;
    max-height: none;
  }
  .checklist-library.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  }
  .lib-list { max-height: 45vh; }
  .lib-head .tbtn,
  .lib-io .tbtn { min-height: 44px; }
  .col-del-btn,
  .row-del-btn { min-width: 32px; min-height: 32px; padding: 4px 8px; }
  .modal-foot .tbtn { min-height: 44px; padding: 10px 20px; font-size: 14px; }
}

@media (max-width: 520px) {
  .checklist-title { font-size: 22px; letter-spacing: 2px; }
  .checklist-table th,
  .checklist-table td { font-size: 13px; }
  .checklist-actions .tbtn { min-height: 44px; flex: 1; }
}

@media print {
  .checklist-toolbar,
  .checklist-library,
  .checklist-actions { display: none; }
}
