*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  background: var(--background-color, #FDF6E3);
  color: #1a1a1a;
  line-height: 1.5;
}

/* Layout */
.admin-header {
  background: #1a1a2e;
  color: #fff;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin: -24px -16px 24px; /* break out of admin-body padding to span full width */
}
.admin-header h1 { font-size: 16px; font-weight: 600; letter-spacing: 0.03em; }
.admin-header .subtitle { color: #888; font-size: 13px; }
.admin-header a { color: #aac; text-decoration: none; font-size: 13px; }
.admin-header a:hover { color: #fff; }
.admin-header a.btn-secondary { color: #333; }
.admin-header a.btn-secondary:hover { color: #333; }
.admin-nav-select {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.02em;
}
.admin-nav-select option { color: #1a1a1a; background: #fff; }
.admin-nav-select:focus { outline: none; border-color: rgba(255,255,255,0.6); }

.admin-back-link {
  display: inline-block;
  font-size: 13px;
  color: #666;
  text-decoration: none;
  margin-bottom: 12px;
}
.admin-back-link:hover { color: #333; }

.day-footer-actions {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e0e4ec;
  display: flex;
  justify-content: flex-end;
}

.admin-body { max-width: 960px; margin: 0 auto; padding: 24px 16px; }

/* Flash messages */
.flash-list { list-style: none; margin-bottom: 16px; }
.flash-list li {
  padding: 10px 14px;
  border-radius: 4px;
  margin-bottom: 8px;
  font-size: 13px;
}
.flash-success { background: var(--color-success-light); color: var(--color-success-text); border: 1px solid #c3e6cb; }
.flash-error   { background: var(--color-error-light); color: var(--color-error-text); border: 1px solid #f5c6cb; }
.flash-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }

/* Cards */
.card {
  background: #fff;
  border: 1px solid #dde;
  border-radius: 6px;
  padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  color: #333;
}

/* Generate form */
.gen-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.gen-form input[type="date"] {
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
}

/* Table */
.days-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.days-table th {
  text-align: left;
  padding: 8px 12px;
  background: #f7f8fa;
  border-bottom: 2px solid #dde;
  color: #555;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.days-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}
.days-table tr:last-child td { border-bottom: none; }
.days-table tr:hover td { background: #fafbff; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.badge-published  { background: var(--color-success-light); color: var(--color-success-text); }
.badge-draft      { background: #fff3cd; color: #856404; }
.badge-generating { background: var(--color-info); color: var(--color-info-text); }
.badge-failed     { background: var(--color-error-light); color: var(--color-error-text); }
.badge-easy      { background: var(--color-success-light); color: var(--color-success-text); }
.badge-medium    { background: var(--color-info); color: var(--color-info-text); }
.badge-hard      { background: var(--color-error-light); color: var(--color-error-text); }
.badge-connects  { background: #e2e3e5; color: #383d41; }
.badge-place     { background: #e8d5f0; color: #4b0082; }
.badge-reviewer-grounded { background: #d1ecf1; color: #0c5460; }
.badge-reviewer-bare     { background: #fff3cd; color: #856404; }
.badge-reviewer-unknown  { background: #f0f0f0; color: #555; }

.reviewer-summary {
  font-size: 0.85em;
  color: var(--ink-soft, #4A3B30);
  margin-left: 8px;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.4;
}
.btn + .btn { margin-left: 6px; }
.btn-primary   { background: #1a1a2e; color: #fff; }
.btn-primary:hover { background: #2a2a4e; }
.btn-secondary { background: #e9ecef; color: #333; }
.btn-secondary:hover { background: #dde; }
.btn-success   { background: var(--color-success); color: #fff; }
.btn-success:hover { background: #218838; }
.btn-warning   { background: #ffc107; color: #333; }
.btn-warning:hover { background: #e0a800; }
.btn-danger    { background: var(--color-error); color: #fff; }
.btn-danger:hover { background: #c82333; }
.btn-slate     { background: #5b7ea8; color: #fff; }
.btn-slate:hover { background: #4a6a92; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
#batch-clear-history-btn { border: 1px solid #000; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Question cards */
.q-card {
  background: #fff;
  border: 1px solid #dde;
  border-radius: 6px;
  margin-bottom: 20px;
  overflow: hidden;
}
.q-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #f7f8fa;
  border-bottom: 1px solid #dde;
}
.q-num {
  font-weight: 700;
  font-size: 16px;
  color: #333;
  min-width: 28px;
}
.q-header-spacer { flex: 1; }
.star-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: #ccc;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.1s;
}
.star-btn:hover { color: #E0A02F; }
.star-btn.starred { color: #E0A02F; }
.q-entity-rows { border-bottom: 1px solid #dde; background: #f0f2f7; }
.q-entity-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 16px;
  border-bottom: 1px solid #e4e7ef;
}
.q-entity-row:last-child { border-bottom: none; }
.q-entity-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #aaa;
  min-width: 44px;
}
.q-entity-name { font-size: 13px; color: #333; flex: 1; }
.q-card-body { padding: 16px; }

.q-section { margin-bottom: 14px; }
.q-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}
.q-section-header label { margin-bottom: 0; }
.q-section label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin-bottom: 5px;
}
.btn-xs { padding: 1px 7px; font-size: 11px; }
.q-section textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 56px;
  line-height: 1.5;
}
.q-section textarea:focus {
  outline: none;
  border-color: #7090cc;
  box-shadow: 0 0 0 2px rgba(112,144,204,0.2);
}

/* Answer choices */
.answers-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.answer-item {
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid #eee;
  background: #fafafa;
}
.answer-item.correct {
  background: #edfaed;
  border-color: var(--color-success);
}
.answer-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.distractor-editable .answer-row {
  cursor: pointer;
  border-radius: 3px;
  margin: -2px -4px;
  padding: 2px 4px;
}
.distractor-editable .answer-row:hover {
  background: #f0f0f8;
}
.answer-pos {
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  flex-shrink: 0;
  border-radius: 3px;
  background: #e9ecef;
  color: #666;
}
.answer-pos--correct {
  background: var(--color-success);
  color: #fff;
}
.answer-text { flex: 1; font-size: 13px; }
.answer-meta { font-size: 11px; color: #999; }
.correct-answer-input {
  flex: 1;
  padding: 2px 7px;
  border: 1px solid #7090cc;
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(112,144,204,0.15);
}

/* Block topic / place buttons */
.block-conn-btn,
.block-place-btn {
  padding: 2px 7px;
  font-size: 11px;
  border-radius: 3px;
  border: 1px solid #ddd;
  background: #f5f5f5;
  color: #999;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
  line-height: 1.4;
}
.block-conn-btn:hover,
.block-place-btn:hover {
  border-color: var(--color-error);
  color: var(--color-error);
  background: #fff5f5;
}
.block-conn-btn.blocked,
.block-place-btn.blocked {
  background: #fff3cd;
  border-color: #e0a800;
  color: #856404;
}
.block-conn-btn.blocked:hover,
.block-place-btn.blocked:hover {
  background: var(--color-error-light);
  border-color: var(--color-error);
  color: var(--color-error);
}

/* Correct answer click-to-edit */
.correct-editable .answer-row {
  cursor: pointer;
  border-radius: 3px;
  margin: -2px -4px;
  padding: 2px 4px;
}
.correct-editable .answer-row:hover {
  background: #daf5da;
}
.correct-editor {
  position: relative;
  margin-top: 6px;
  display: none;
}
.correct-editable.correct-editor-open .correct-editor {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Distractor inline editor */
.distractor-editor {
  position: relative;
  margin-top: 6px;
  display: none;
}
.distractor-editable.editor-open .distractor-editor {
  display: block;
}
.distractor-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #7090cc;
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  box-shadow: 0 0 0 2px rgba(112,144,204,0.2);
}
.distractor-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ccc;
  border-top: none;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
}
.distractor-sug-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}
.distractor-sug-item:last-child { border-bottom: none; }
.distractor-sug-item:hover { background: #f0f4ff; }
.distractor-sug-item.active { background: #e0e8ff; }
.sug-name { font-size: 13px; flex: 1; }
.sug-meta { font-size: 11px; color: #999; flex-shrink: 0; }

.q-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #eee;
  background: #fafafa;
  flex-wrap: wrap;
}
.save-status {
  font-size: 12px;
  color: #888;
  margin-left: 4px;
}
.save-status.ok  { color: var(--color-success); }
.save-status.err { color: var(--color-error); }

.q-notify {
  font-size: 12px;
  font-weight: 500;
  color: transparent;
  flex-shrink: 0;
}
.q-notify.ok  { color: var(--color-success); }
.q-notify.err { color: var(--color-error); }

/* Day header bar */
.day-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.day-header h2 { font-size: 18px; font-weight: 700; }
.day-header .spacer { flex: 1; }

/* Inline form helper */
.inline-form { display: inline; }

/* Wait note */
.wait-note {
  font-size: 12px;
  color: #888;
  font-style: italic;
}

/* Source sentences panel */
.q-source {
  background: #f8f9ff;
  border: 1px solid #e0e4f0;
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.q-source-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.q-source-place {
  font-weight: 600;
  font-size: 13px;
  color: #1a1a2e;
}
.q-source-sep {
  color: #aaa;
  font-size: 12px;
}
.q-source-topic {
  font-size: 12px;
  color: #3a3a90;
  background: #e6e6fa;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 2px;
}
.q-source-sents {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.q-source-sents li {
  font-size: 12px;
  color: #555;
  line-height: 1.5;
}
.q-source-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #666;
  background: #dde;
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: middle;
  white-space: nowrap;
}

/* Generation progress bar */
.progress-wrap {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #eee;
}
.progress-label {
  font-size: 13px;
  color: #444;
  margin-bottom: 8px;
}
.progress-bar-track {
  background: #e9ecef;
  border-radius: 4px;
  height: 8px;
  overflow: hidden;
}
.progress-bar-fill {
  background: var(--color-info-text);
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* Quick generate buttons */
.gen-quick-btns {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* List filters */
.list-filters {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.filter-btn {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  text-decoration: none;
  color: #555;
  background: #f0f0f0;
  border: 1px solid transparent;
  transition: background 0.1s;
}
.filter-btn:hover { background: #e0e4ff; color: #333; }
.filter-btn.active {
  background: #1a1a2e;
  color: #fff;
  border-color: #1a1a2e;
}

/* Batch action bar */
.batch-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #eef2ff;
  border: 1px solid #c5cff5;
  border-radius: 4px;
  margin-bottom: 10px;
  font-size: 13px;
}
.batch-bar.visible { display: flex; }
#batch-count { font-weight: 600; color: #333; margin-right: 4px; }

/* Checkbox column */
.chk-col { width: 36px; text-align: center; }
.days-table tr.selected td { background: #f4f6ff; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-size: 13px;
}
.page-btn {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
  background: #f0f0f0;
  color: #333;
  text-decoration: none;
  border: 1px solid #ddd;
}
.page-btn:hover:not(.disabled) { background: #e0e4ff; }
.page-btn.disabled { color: #bbb; cursor: default; }
.page-info { color: #666; font-size: 12px; }

/* Inline styles lifted to CSS so media queries can override */
.admin-header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.admin-empty-note { color: #888; font-size: 13px; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #888; padding: 6px 8px; border-bottom: 2px solid #e0d8c8; }
.admin-table td { padding: 7px 8px; border-bottom: 1px solid #f0e8d8; vertical-align: middle; }
.admin-table tbody tr:hover { background: #fdf8f0; }
.q-card-places { font-size: 12px; color: #888; margin-left: 4px; }
.gen-overwrite-label { display: flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 640px) {

  .admin-body { padding: 14px 10px; }

  /* Header: compensate for smaller admin-body padding, allow wrapping */
  .admin-header {
    margin: -14px -10px 16px;
    flex-wrap: wrap;
    padding: 10px 14px;
    row-gap: 6px;
  }
  .admin-header-actions { margin-left: 0; }

  /* Generate card: stack vertically, button stays natural width */
  .gen-form { flex-direction: column; align-items: flex-start; gap: 10px; }
  .gen-form input[type="date"] { width: 100%; }
  .gen-quick-btns { flex-wrap: wrap; }

  /* Days table → card list */
  .days-table-wrap { overflow-x: visible; margin: 0; padding: 0; }
  .days-table { min-width: 0; width: 100%; }
  .days-table thead { display: none; }
  .days-table,
  .days-table tbody { display: block; }
  .days-table tr {
    display: block;
    border: 1px solid #e0e4ec;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
    background: #fff;
  }
  .days-table tr:hover td { background: transparent; }
  .days-table td { display: block; padding: 2px 0; border: none; }

  /* First row: checkbox + date + status + count all inline.
     Use td.col-* to beat .days-table td specificity (0,1,1). */
  .days-table td.chk-col { display: inline-block; vertical-align: middle; padding-right: 4px; }
  .days-table td.col-date { display: inline-block; vertical-align: middle; font-size: 15px; }
  .days-table td.col-status { display: inline-block; vertical-align: middle; margin-left: 6px; }
  .days-table td.col-count {
    display: inline-block;
    vertical-align: middle;
    font-size: 12px;
    color: #666;
    margin-left: 6px;
  }
  /* Published date sits on its own row below; hidden when no date exists */
  .days-table td.col-published { display: block; font-size: 12px; color: #999; margin-top: 4px; }
  .days-table tr.no-pub td.col-published { display: none; }
  .days-table td.col-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eee;
  }
  .col-actions .btn { margin-left: 0; }

  /* Batch bar: wrap when visible */
  .batch-bar { flex-wrap: wrap; }

  /* Card padding */
  .card { padding: 14px 12px; }
  .q-card-body { padding: 12px; }

  /* Question card header: q-num + badges on row 1, places on row 2 */
  .q-card-header { flex-wrap: wrap; padding: 10px 12px; }
  .q-card-places { width: 100%; margin-left: 0; margin-top: 2px; }

  /* Disable manual textarea resize on mobile so auto-fit stays clean */
  .q-section textarea { resize: none; }

  /* Larger tap targets in the action bar */
  .q-actions { padding: 10px 12px; }
  .q-actions .btn-sm { padding: 7px 12px; }

  /* Day header publish/unpublish button */
  .day-header .spacer { display: none; }
  .day-header .btn { padding: 8px 18px; }
}
