body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  margin: 0;
  padding: 20px;
  background: #f6f7f9;
  color: #222;
}
.container {
  max-width: 1100px;
  margin: 0 auto;
  background: #fff;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  border-bottom: 1px solid #e1e4e8;
  padding-bottom: 16px;
  margin-bottom: 16px;
}
h1 { margin: 0; font-size: 1.6rem; }

/* Tabs */
#top-tabs, .sub-tabs {
  display: flex;
  gap: 4px;
}
.tab-btn, .sub-tab-btn {
  padding: 8px 16px;
  border: 1px solid #d0d7de;
  background: #f6f8fa;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
}
.tab-btn.active, .sub-tab-btn.active {
  background: #fff;
  border-bottom-color: #fff;
  font-weight: 600;
}
.tab-panel { padding-top: 8px; }
.hidden { display: none !important; }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.session-title { font-weight: 600; font-size: 1.1rem; }

/* Task 253cf: search boxes in the Sessions and Study tabs. */
.search-input {
  flex: 1;
  min-width: 160px;
  max-width: 320px;
  padding: 8px 10px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 0.95rem;
}

/* Cards / lists */
.session-card, .source-card, .deck-card, .upload-card, .card {
  border: 1px solid #d0d7de;
  border-radius: 8px;
  padding: 14px;
  margin: 10px 0;
  background: #fff;
}

/* Swipe-to-delete container for session cards */
.swipe-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  margin: 10px 0;
  touch-action: pan-y;
}
.swipe-actions {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 14px;
  background: #cf222e;
  border-radius: 8px;
}
.swipe-actions button {
  background: transparent;
  color: #fff;
  border: 1px solid #fff;
  border-radius: 6px;
  padding: 8px 16px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.swipe-actions button:hover { background: rgba(255,255,255,0.15); }
.session-card {
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: transform 0.2s ease;
  margin: 0;
}
.session-card:hover { background: #f6f8fa; }
.session-card .meta, .source-card .meta, .deck-card .meta {
  display: block;
  color: #666;
  font-size: 0.9rem;
  margin-top: 4px;
}
.session-card.swiping { transition: none; }
.session-card.snapping { transition: transform 0.2s ease; }

/* Prevent the actions layer from stealing pointer events during an active swipe. */
.swipe-wrap:has(.swiping) .swipe-actions {
  pointer-events: none;
}

/* Deck cards inside swipe containers use the same swipe behaviour as sessions. */
.swipe-wrap .deck-card {
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: transform 0.2s ease;
  margin: 0;
}
.swipe-wrap .deck-card.swiping { transition: none; }
.swipe-wrap .deck-card.snapping { transition: transform 0.2s ease; }
.source-card.status-accepted { border-left: 4px solid #2da44e; }
.source-card.status-preview { border-left: 4px solid #d29922; }
.source-card.status-rejected { border-left: 4px solid #cf222e; }
.source-card.status-pending { border-left: 4px solid #57606a; }
.source-card.status-pending.active { background: #f6f8fa; border-left-color: #0969da; }
.source-card .source-status-line { margin: 6px 0 4px; }
.plus-cards { color: #2da44e; font-weight: 600; margin-left: 8px; }
#layout-tree .plus-cards { font-size: 0.8rem; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  background: #eef1f4;
  font-size: 0.8rem;
  margin-left: 8px;
}

/* Layout */
.session-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
}
#session-sidebar {
  border-right: 1px solid #e1e4e8;
  padding-right: 16px;
}
#layout-tree .layout-chapter { margin: 6px 0; }
#layout-tree .layout-header { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
#layout-tree .layout-arrow { cursor: pointer; width: 18px; text-align: center; user-select: none; font-size: 1.1rem; }
#layout-tree .layout-toggle { cursor: pointer; }
#layout-tree .layout-title { font-weight: 600; }
#layout-tree .layout-lesson .layout-title { font-weight: 400; color: #444; }
#layout-tree .layout-point { display: flex; align-items: center; gap: 4px; margin: 2px 0 2px 20px; }
#layout-tree .layout-point .layout-title { color: #555; font-size: 0.95rem; font-weight: 400; }
#layout-tree .layout-children { margin-left: 18px; }
#layout-tree .layout-children.collapsed { display: none; }
#layout-tree .layout-cb { margin: 0 4px; }
#layout-tree .layout-lesson { margin: 4px 0; }
#layout-tree button.small { font-size: 0.75rem; padding: 2px 6px; }
#layout-tree .delete-node-btn {
  font-size: 0.85rem;
  padding: 0 4px;
  line-height: 1;
  color: #cf222e;
  background: transparent;
  border: none;
  margin-left: auto;
}
#layout-tree .delete-node-btn:hover { background: #ffebe9; border-radius: 4px; }

/* Sub-panels */
.sub-panel { padding-top: 12px; }

/* Upload */
.upload-card h4 { margin-top: 0; }
.upload-card label { display: block; margin: 8px 0; }
.upload-card select, .upload-card input[type="file"] { margin-top: 4px; }
.upload-method-panel { margin-top: 12px; }
.upload-method-panel textarea { width: 100%; max-width: 600px; }
#upload-result { white-space: pre-wrap; background: #f6f8fa; padding: 8px; border-radius: 6px; }

/* Preview */
#preview-text {
  width: 100%;
  font-family: monospace;
  font-size: 0.95rem;
  padding: 12px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
}
#preview-cutouts { margin-top: 12px; }
.cutout { padding: 8px; background: #f6f8fa; border-radius: 6px; margin: 6px 0; }
.cutout .label { font-weight: 600; }
.cutouts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.cutout-thumb {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin-top: 6px;
  border: 1px solid #d0d7de;
}
.cutout-caption {
  color: #444;
  font-size: 0.9rem;
  margin-top: 4px;
}
.cutout-code {
  margin-top: 8px;
  font-size: 0.85rem;
}
.cutout-code pre {
  margin-top: 6px;
  max-height: 200px;
  overflow-y: auto;
}

/* Study */
#study-card {
  background: #f6f8fa;
  padding: 24px;
  border-radius: 6px;
  min-height: 160px;
  margin-bottom: 12px;
  cursor: pointer;
}
#study-card .front { font-size: 1.4rem; font-weight: 600; }
#study-card .back { margin-top: 16px; font-size: 1.2rem; color: #222; }
#study-buttons button { margin-right: 8px; }

/* Full-screen study overlay */
#study-overlay {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 200;
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow-y: auto;
}
.study-overlay-content {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  flex: 1;
}
#study-overlay-card {
  background: #f6f8fa;
  padding: 40px;
  border-radius: 8px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  margin: 16px 0;
  cursor: pointer;
}
#study-overlay-card .front { font-size: 2rem; font-weight: 600; }
#study-overlay-card .back { margin-top: 24px; font-size: 1.5rem; color: #222; }
#study-show-answer {
  padding: 14px 24px;
  font-size: 1.1rem;
  margin-bottom: 12px;
}
#study-overlay-buttons button { margin-right: 8px; }
#study-overlay-buttons.hidden { display: none; }
.hint { color: #666; font-size: 0.9rem; }
.loading-status { color: #666; font-size: 0.9rem; margin-left: 8px; }
.field-error { color: #d32f2f; font-size: 0.85rem; margin-left: 8px; }
.import-deck-label { display: inline-block; }
.import-deck-label input[type="file"] { display: none; }
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #d0d7de;
  border-top-color: #0969da;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
button:disabled, button.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Buttons */
button {
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #f6f8fa;
}
button:hover { background: #eef1f4; }
button.primary { background: #2da44e; color: #fff; border-color: #2da44e; }
button.primary:hover { background: #2c974b; }
button.danger { background: #cf222e; color: #fff; border-color: #cf222e; }
button.danger:hover { background: #b91c27; }
button.secondary { background: transparent; }

input[type="file"], input[type="text"], select, textarea {
  padding: 6px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  margin-right: 8px;
}
.choice-group { margin: 12px 0; }
.choice-group label { display: block; margin: 6px 0; }

pre {
  background: #f6f8fa;
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
}

@media (max-width: 800px) {
  .session-layout { grid-template-columns: 1fr; }
  #session-sidebar { border-right: none; border-bottom: 1px solid #e1e4e8; padding-bottom: 16px; }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-content {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  max-width: 520px;
  width: 90%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.modal-content h3 { margin-top: 0; }
.overlap-list {
  background: #f6f8fa;
  padding: 12px;
  border-radius: 6px;
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.9rem;
}
.overlap-list li { margin: 6px 0; }
#conflict-options label { display: block; margin: 8px 0; }
#conflict-options input { margin-right: 6px; }

/* Review popup */
.review-modal-content { max-width: 700px; max-height: 90vh; overflow-y: auto; }
#review-text { width: 100%; font-family: monospace; font-size: 0.95rem; padding: 12px; border: 1px solid #d0d7de; border-radius: 6px; }
#review-cutouts { margin-top: 12px; }
#review-resolution { margin-top: 12px; padding: 12px; background: #f6f8fa; border-radius: 6px; }
#review-resolution label { display: block; margin: 8px 0; }
#review-resolution input { margin-right: 6px; }
.layout-state-badges { display: inline-flex; gap: 4px; margin-left: 6px; }
.layout-state-badges .badge { font-size: 0.75rem; padding: 1px 6px; }

/* Review tabs */
.review-tabs { display: flex; gap: 4px; margin: 12px 0; border-bottom: 1px solid #d0d7de; }
.review-tab-btn {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
}
.review-tab-btn.active {
  background: #fff;
  border-color: #d0d7de;
  font-weight: 600;
  margin-bottom: -1px;
}
.review-panel { margin-bottom: 12px; }

/* Transcription preview + uncertain-word highlighting */
.transcription-preview {
  white-space: pre-wrap;
  background: #f6f8fa;
  padding: 12px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  margin-top: 8px;
  min-height: 60px;
  max-height: 240px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 0.95rem;
}
.uncertain {
  background: #fff8c5;
  padding: 1px 3px;
  border-radius: 4px;
  font-weight: 600;
}

/* Audit table */
.audit-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 0.9rem; }
.audit-table th, .audit-table td {
  border: 1px solid #d0d7de;
  padding: 8px;
  text-align: left;
  vertical-align: top;
}
.audit-table th { background: #f6f8fa; }
.audit-answer {
  min-width: 120px;
  background: #fff;
  border: 1px dashed #d0d7de;
  border-radius: 4px;
  padding: 4px;
}
.audit-answer:focus { outline: 2px solid #0969da; background: #f6f8fa; }
.audit-gap {
  margin-top: 6px;
  padding: 6px;
  background: #fff8c5;
  border-radius: 4px;
  font-size: 0.85rem;
}

/* Coverage checklist + preview cards */
.coverage-checklist { margin: 8px 0; }
.coverage-checklist h4, .boundary-variants h4, .preview-cards h4 { margin: 12px 0 6px; }
.coverage-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 4px 0;
  border-bottom: 1px solid #eef1f4;
}
.coverage-item input { margin-top: 4px; }
.coverage-type {
  font-size: 0.75rem;
  text-transform: uppercase;
  background: #ddf4ff;
  color: #0969da;
  padding: 1px 5px;
  border-radius: 10px;
  margin-left: auto;
  white-space: nowrap;
}
.boundary-variants { margin: 12px 0; padding: 10px; background: #f6f8fa; border-radius: 6px; }
.variant-item { display: flex; align-items: flex-start; gap: 6px; margin: 6px 0; }
.variant-item input { margin-top: 3px; }
.preview-cards { margin-top: 12px; }
.preview-card {
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 10px;
  margin: 8px 0;
  background: #fff;
}
.preview-card .front { font-weight: 600; margin-bottom: 6px; }
.preview-card .back { color: #444; }
.preview-card .meta { font-size: 0.8rem; color: #666; margin-top: 4px; }

.deck-editor-content {
  max-width: 640px;
  max-height: 80vh;
  padding: 0;
  /* Task 253ba: header and footer stay stationary at the top/bottom; only the
     card list scrolls. Buttons are not sticky/floating and do not scroll away. */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.deck-editor-header {
  background: #fff;
  padding: 20px 20px 0;
  flex-shrink: 0;
}
.deck-editor-header h3 { margin-top: 0; }
.deck-editor-body {
  padding: 0 20px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  /* Task 253cm: iOS Safari does not scroll a fixed-position flex child without
     momentum scrolling + an explicit pan-y touch action. */
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.deck-editor-footer {
  background: #fff;
  padding: 20px 20px 20px;
  flex-shrink: 0;
  border-top: 1px solid #e1e4e8;
}
.deck-editor-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: start;
  margin: 8px 0;
  padding: 10px;
  background: #f6f8fa;
  border-radius: 6px;
}
.deck-editor-row textarea {
  width: 100%;
  min-height: 60px;
  resize: vertical;
  overflow-y: auto;
}
.deck-editor-row.new-row { background: #fff8c5; }

/* Uniform per-card Delete button inside the deck editor (Task 253ar). */
.deck-delete-btn {
  width: 72px;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  background: #cf222e;
  color: #fff;
  border: 1px solid #cf222e;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.deck-delete-btn:hover { background: #b91c27; border-color: #b91c27; }
.deck-delete-btn:active { background: #9e1b23; border-color: #9e1b23; }
.deck-delete-btn:focus-visible { outline: 2px solid #0969da; outline-offset: 2px; }

/* Language selector (Task 253bk): searchable filter above the dropdown. */
.language-filter {
  display: block;
  width: 100%;
  margin: 4px 0;
  padding: 6px 8px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 0.9rem;
}
.new-textbook-dialog select,
.session-language-control select {
  max-height: 220px;
  overflow-y: auto;
}

/* Multiple staged create dialogs (Task 253df) */
.new-textbook-dialog { margin-bottom: 16px; }
#new-textbook-dialogs .new-textbook-dialog { display: block; }

/* Background jobs (Task 253bb) */
.jobs-panel { margin-top: 16px; padding: 12px; background: #f6f8fa; border: 1px solid #e1e4e8; border-radius: 6px; }
.jobs-panel h4 { margin-top: 0; }
.job-row { margin: 8px 0; }
.job-row .job-meta { font-size: 0.85rem; color: #444; }
.job-progress-track { background: #e1e4e8; border-radius: 10px; height: 10px; overflow: hidden; margin-top: 4px; }
.job-progress-fill { background: #0969da; height: 100%; border-radius: 10px; transition: width 0.3s ease; }
.job-row.status-done .job-progress-fill { background: #1a7f37; }
.job-row.status-failed .job-progress-fill { background: #cf222e; }
.job-row.status-interrupted .job-progress-fill { background: #9a6700; }
.job-row.status-cancelled .job-progress-fill { background: #9a6700; }
.deck-importing { opacity: 0.85; }
.job-cancel-btn { margin-left: 8px; font-size: 0.75rem; }

/* Session-card job progress (Task 253bs) */
.session-job-progress { margin-top: 8px; padding-top: 6px; border-top: 1px solid #e1e4e8; }
.session-job-row { margin: 4px 0; }
.session-job-row .job-meta { font-size: 0.8rem; color: #444; }

/* Subtype + transcript pairing in upload flow */
#typed-transcript-wrap, #handwritten-transcript-wrap {
  margin: 8px 0;
  padding: 10px;
  background: #f6f8fa;
  border-radius: 6px;
}
#typed-transcript-wrap label, #handwritten-transcript-wrap label { display: block; }

/* Auth: login screen, user area, admin modal (Task 253ch) */
.login-screen {
  position: fixed;
  inset: 0;
  background: #f6f7f9;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.login-card {
  background: #fff;
  padding: 32px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  width: 320px;
}
.login-card h1 { margin-bottom: 8px; }
.login-card form label { display: block; margin: 12px 0; }
.login-card form input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px;
  margin-top: 4px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
}
.login-error {
  color: #cf222e;
  margin: 8px 0;
}
.user-area {
  display: flex;
  align-items: center;
  gap: 8px;
}
.logged-in-user {
  font-weight: 600;
  color: #0969da;
}
.admin-modal-content {
  width: 460px;
  max-width: 92vw;
}
.admin-create {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.admin-create input[type="text"], .admin-create input[type="password"] {
  flex: 1;
  min-width: 120px;
  padding: 6px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
}
.inline-label { display: inline-flex; align-items: center; gap: 4px; }
#admin-users-list { max-height: 320px; overflow-y: auto; }
.admin-user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  padding: 8px;
  border-bottom: 1px solid #e1e4e8;
}
.admin-user-row .admin-user-name { font-weight: 600; }
.admin-user-row .admin-user-meta { font-size: 0.8rem; color: #666; }
.admin-user-row .admin-user-actions { display: flex; gap: 6px; }
