/* ================================================================
   MechForge Admin Layer — matches the gold/paper/steel palette
   ================================================================ */

/* ==============================================================
   NAV BAR — only rendered on problems pages (no .topbar present)
   All other pages inject nav items directly into the existing .topbar
   ============================================================== */
#mfNavBar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 38px;
  background: #1e2d3e;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 14px;
  z-index: 1100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.28);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.70rem;
  flex-wrap: nowrap;
  overflow: hidden;
}

/* Chapter nav group inside .topbar (reading / index / hub pages) */
#mfChapterNav {
  display: flex;
  align-items: center;
  gap: 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.69rem;
  flex-shrink: 1;
  overflow: hidden;
  margin-left: 6px;
}

/* Shared link styles for nav bar and chapter nav */
#mfNavBar a,
#mfChapterNav a {
  color: #b8c5d3;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  transition: background 0.14s, color 0.14s;
  font-size: 0.68rem;
  letter-spacing: 0.15px;
}
#mfNavBar a:hover,
#mfChapterNav a:hover {
  background: rgba(184,134,11,0.22);
  color: #e0c067;
}

/* Separators */
#mfNavBar .mf-sep,
#mfChapterNav .mf-sep {
  color: #3d556a;
  padding: 0 1px;
  user-select: none;
  font-size: 0.65rem;
}

/* Chapter prev/next accent */
#mfNavBar .mf-nav-prev,
#mfNavBar .mf-nav-next,
#mfChapterNav .mf-nav-prev,
#mfChapterNav .mf-nav-next {
  color: #c9a83a;
  font-weight: 600;
}

/* Reading ↔ Problems toggle pill */
#mfNavBar .mf-nav-toggle,
#mfChapterNav .mf-nav-toggle {
  background: rgba(184,134,11,0.14);
  color: #c9a415;
  border: 1px solid rgba(184,134,11,0.28);
  border-radius: 4px;
}
#mfNavBar .mf-nav-toggle:hover,
#mfChapterNav .mf-nav-toggle:hover {
  background: rgba(184,134,11,0.28);
  color: #e0c067;
}

/* ==============================================================
   ADMIN SLOT — the owner controls container, always inside
   either #mfNavBar or .topbar
   ============================================================== */
#mfAdminSlot {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
/* Problems page: push slot to the far right of #mfNavBar */
#mfNavBar #mfAdminSlot {
  margin-left: auto;
}
/* Topbar pages: slot flows naturally at the end */
.topbar #mfAdminSlot {
  margin-left: 8px;
}

/* ==============================================================
   ADMIN LOGIN BUTTON
   ============================================================== */
.mf-admin-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #888;
  padding: 3px 11px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.67rem;
  transition: all 0.14s;
}
.mf-admin-btn:hover {
  background: rgba(255,255,255,0.16);
  color: #ccc;
}

/* ==============================================================
   LOGIN MODAL
   ============================================================== */
.mf-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,14,13,0.58);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
}

.mf-modal {
  background: #f7f4ef;
  border: 1px solid #d4cec5;
  border-radius: 12px;
  padding: 32px 36px;
  min-width: 340px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.22);
}

.mf-modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: #0f0e0d;
  margin: 0 0 6px;
}

.mf-modal-sub {
  font-size: 0.84rem;
  color: #6b6560;
  margin-bottom: 20px;
  font-family: 'Source Serif 4', serif;
}

.mf-pw-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d4cec5;
  border-radius: 6px;
  font-size: 0.95rem;
  background: #fff;
  color: #0f0e0d;
  box-sizing: border-box;
  font-family: 'Source Serif 4', serif;
  outline: none;
  transition: border-color 0.14s, box-shadow 0.14s;
}
.mf-pw-input:focus {
  border-color: #b8860b;
  box-shadow: 0 0 0 3px rgba(184,134,11,0.14);
}

.mf-login-err {
  color: #c0392b;
  font-size: 0.81rem;
  min-height: 20px;
  margin: 8px 0 4px;
  font-family: 'IBM Plex Mono', monospace;
}

.mf-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.mf-btn-secondary {
  flex: 1;
  padding: 9px;
  border: 1px solid #d4cec5;
  background: #ede8df;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.87rem;
  color: #6b6560;
  font-family: 'Source Serif 4', serif;
  transition: background 0.14s;
}
.mf-btn-secondary:hover { background: #d4cec5; }

.mf-btn-primary {
  flex: 1;
  padding: 9px;
  background: #2c3e50;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.87rem;
  color: #fff;
  font-weight: 600;
  font-family: 'Source Serif 4', serif;
  transition: background 0.14s;
}
.mf-btn-primary:hover { background: #b8860b; }

/* ==============================================================
   OWNER BAR (inside admin slot)
   ============================================================== */
.mf-owner-bar {
  display: flex;
  align-items: center;
  gap: 7px;
}

.mf-edit-label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #b8c5d3;
  font-size: 0.68rem;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.mf-edit-label input[type="checkbox"] {
  accent-color: #b8860b;
  cursor: pointer;
  width: 14px;
  height: 14px;
}

.mf-bar-btn {
  padding: 3px 11px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.67rem;
  border: 1px solid transparent;
  transition: all 0.14s;
  white-space: nowrap;
  line-height: 1.5;
}

.mf-bar-btn-save {
  background: #b8860b;
  color: #fff;
  border-color: #906809;
}
.mf-bar-btn-save:hover { background: #906809; }
.mf-bar-btn-save:disabled { background: #888; border-color: #666; cursor: wait; }

.mf-bar-btn-revert {
  background: rgba(255,255,255,0.08);
  color: #aaa;
  border-color: rgba(255,255,255,0.14);
}
.mf-bar-btn-revert:hover { background: rgba(255,255,255,0.16); color: #fff; }

.mf-bar-btn-logout {
  background: transparent;
  color: #566677;
  border-color: rgba(255,255,255,0.08);
  font-size: 0.63rem;
}
.mf-bar-btn-logout:hover {
  background: rgba(192,57,43,0.18);
  color: #c0392b;
  border-color: rgba(192,57,43,0.3);
}

/* ==============================================================
   EDIT MODE — contenteditable visual feedback
   ============================================================== */
body.mf-edit-mode .mf-editable {
  outline: 1px dashed rgba(184,134,11,0.45) !important;
  border-radius: 3px;
  min-height: 1em;
  cursor: text;
  transition: outline 0.1s;
}
body.mf-edit-mode .mf-editable:hover {
  outline: 1px dashed rgba(184,134,11,0.75) !important;
  background: rgba(255,243,205,0.12);
}
body.mf-edit-mode .mf-editable:focus {
  outline: 2px solid #b8860b !important;
  background: rgba(255,243,205,0.28);
}

/* ==============================================================
   DELETE BUTTONS
   ============================================================== */
.mf-del-btn {
  background: rgba(192,57,43,0.82);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.7rem;
  font-family: 'IBM Plex Mono', monospace;
  padding: 2px 7px;
  z-index: 200;
  transition: background 0.13s;
  line-height: 1.4;
}
.mf-del-btn:hover { background: #c0392b; }

.mf-del-blk-wrap {
  position: relative;
}
.mf-del-blk {
  position: absolute;
  top: 6px;
  right: 6px;
}
.mf-del-sec-btn {
  float: right;
  margin-top: 4px;
  clear: right;
}

/* ==============================================================
   INSERT ROWS — appear between blocks in edit mode
   ============================================================== */
.mf-insert-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 0;
  opacity: 0;
  transition: opacity 0.18s;
  min-height: 24px;
}
body.mf-edit-mode .mf-insert-row { opacity: 1; }

.mf-insert-row button {
  background: rgba(44,62,80,0.07);
  border: 1px dashed #d4cec5;
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 0.69rem;
  font-family: 'IBM Plex Mono', monospace;
  color: #2c3e50;
  cursor: pointer;
  transition: all 0.14s;
  white-space: nowrap;
}
.mf-insert-row button:hover {
  background: rgba(184,134,11,0.12);
  border-color: #b8860b;
  color: #b8860b;
}

/* ==============================================================
   DELETED BADGE
   ============================================================== */
.mf-deleted-badge {
  background: rgba(192,57,43,0.09);
  border: 1px solid rgba(192,57,43,0.3);
  color: #c0392b;
  font-size: 0.7rem;
  font-family: 'IBM Plex Mono', monospace;
  padding: 2px 8px;
  border-radius: 3px;
  display: inline-block;
  margin-bottom: 4px;
}

/* ==============================================================
   IMAGE UPLOAD LABEL (edit mode)
   ============================================================== */
.mf-img-upload-label {
  transition: background 0.14s, border-color 0.14s;
}
.mf-img-upload-label:hover {
  background: #f0ece4 !important;
  border-color: #b8860b !important;
  color: #b8860b !important;
}

/* ==============================================================
   SYMBOL KEYBOARD
   ============================================================== */
/* Migrate uploads — floating button, owner-only, bottom-right above Σ */
#mfMigrateBtn {
  position: fixed;
  bottom: 62px;
  right: 18px;
  background: #7c3aed;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.82rem;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  z-index: 3000;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  transition: background 0.14s;
  white-space: nowrap;
}
#mfMigrateBtn:hover { background: #5b21b6; }
#mfMigrateBtn:disabled { background: #888; cursor: wait; }

#mfSymBtn {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: #2c3e50;
  color: #e0c067;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.82rem;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  z-index: 3000;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  transition: background 0.14s;
}
#mfSymBtn:hover { background: #b8860b; }

#mfSymKeyboard {
  position: fixed;
  bottom: 68px;
  right: 18px;
  width: 420px;
  max-height: 320px;
  background: #f7f4ef;
  border: 1px solid #d4cec5;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#mfSymSearch {
  padding: 9px 13px;
  border: none;
  border-bottom: 1px solid #d4cec5;
  background: #ede8df;
  font-size: 0.83rem;
  font-family: 'IBM Plex Mono', monospace;
  outline: none;
  color: #0f0e0d;
  width: 100%;
  box-sizing: border-box;
}

#mfSymGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 9px;
  overflow-y: auto;
  flex: 1;
}

.mf-sym-item {
  background: #fff;
  border: 1px solid #d4cec5;
  border-radius: 4px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 0.95rem;
  min-width: 36px;
  text-align: center;
  transition: all 0.1s;
  color: #0f0e0d;
  font-family: 'Source Serif 4', serif;
  line-height: 1.2;
}
.mf-sym-item:hover {
  background: #fff3cd;
  border-color: #b8860b;
}

/* ==============================================================
   INSTRUCTOR NOTES
   ============================================================== */
body.mf-edit-mode .admin-note {
  display: block !important;
}

.an-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #b8860b;
  display: block;
  margin-bottom: 4px;
}

/* ==============================================================
   TOAST NOTIFICATION
   ============================================================== */
#mfToast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #2c3e50;
  color: #e0c067;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  padding: 10px 22px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
#mfToast.mf-toast-show { opacity: 1; }

/* ==============================================================
   MOBILE
   ============================================================== */
@media (max-width: 900px) {
  #mfNavBar { font-size: 0.63rem; padding: 0 8px; }
  #mfNavBar a { padding: 3px 5px; font-size: 0.62rem; }
  #mfChapterNav { font-size: 0.62rem; }
  #mfChapterNav a { padding: 3px 5px; font-size: 0.62rem; }
  #mfSymKeyboard { width: calc(100vw - 36px); right: 8px; }
}

/* ==============================================================
   BULK FIGURE UPLOAD MODAL
   ============================================================== */
.mf-bulk-fig-modal {
  max-width: 720px;
  width: 92vw;
  padding: 26px 28px 28px;
}

.mf-bulk-fig-head {
  margin-bottom: 18px;
}

.mf-bulk-fig-drop {
  border: 2px dashed #d4cec5;
  border-radius: 10px;
  padding: 28px 24px;
  text-align: center;
  background: #faf8f4;
  transition: background 0.14s, border-color 0.14s;
  cursor: pointer;
  margin-bottom: 16px;
}
.mf-bulk-fig-drop.dragover {
  border-color: #b8860b;
  background: #fff8e6;
}

.mf-bulk-fig-drop-text {
  font-family: 'Source Serif 4', serif;
  font-size: 1.05rem;
  color: #0f0e0d;
  margin-bottom: 14px;
  line-height: 1.5;
}
.mf-bulk-fig-drop-text strong { color: #2c3e50; }

.mf-bulk-fig-hint {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  color: #6b6560;
  margin-top: 6px;
}

.mf-bulk-fig-status {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  min-height: 20px;
}

.mf-bulk-fig-ok { color: #27ae60; }
.mf-bulk-fig-warn { color: #c0392b; }

.mf-bulk-fig-list {
  max-height: 44vh;
  overflow-y: auto;
  border: 1px solid #d4cec5;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  margin-bottom: 18px;
}

.mf-bulk-fig-empty {
  text-align: center;
  color: #6b6560;
  font-family: 'Source Serif 4', serif;
  padding: 24px 0;
  margin: 0;
}

.mf-bulk-fig-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid #ede8df;
  font-family: 'Source Serif 4', serif;
  font-size: 0.88rem;
}
.mf-bulk-fig-row:last-child { border-bottom: none; }
.mf-bulk-fig-row.unmatched { background: #fff8f8; }

.mf-bulk-fig-thumb {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 5px;
  overflow: hidden;
  background: #f4f1ea;
  border: 1px solid #d4cec5;
}
.mf-bulk-fig-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mf-bulk-fig-info { flex: 1; min-width: 0; }
.mf-bulk-fig-name {
  font-weight: 600;
  color: #0f0e0d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mf-bulk-fig-match {
  font-size: 0.78rem;
  color: #6b6560;
  font-family: 'IBM Plex Mono', monospace;
  margin-top: 2px;
}
.mf-bulk-fig-match code {
  font-size: 0.72rem;
  background: #f4f1ea;
  padding: 1px 4px;
  border-radius: 3px;
}

.mf-bulk-fig-state {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  padding: 4px 9px;
  border-radius: 4px;
  white-space: nowrap;
}
.mf-bulk-fig-state.ready { background: #e8f4fd; color: #2980b9; }
.mf-bulk-fig-state.uploading { background: #fff8e6; color: #b8860b; }
.mf-bulk-fig-state.done { background: #e8f9ee; color: #27ae60; }
.mf-bulk-fig-state.failed,
.mf-bulk-fig-state.warn { background: #fdeaea; color: #c0392b; }

.mf-bulk-fig-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.mf-bulk-fig-actions .mf-btn-secondary,
.mf-bulk-fig-actions .mf-btn-primary {
  flex: 0 0 auto;
  padding: 9px 20px;
}

/* ==============================================================
   PROBLEM FIGURE — upload button (edit mode) + image display (all visitors)
   ============================================================== */

/* Upload / replace button shown next to the figflag text */
.mf-pfig-btn {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 9px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  background: #2c3e50;
  color: #e0c067;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  vertical-align: middle;
  transition: background 0.14s;
  white-space: nowrap;
}
.mf-pfig-btn:hover { background: #b8860b; }
.mf-pfig-btn:disabled { opacity: 0.55; cursor: default; }

/* Figure wrapper — spans across both grid columns of the problem list item */
.mf-pfig-wrap {
  grid-column: 1 / -1;
  margin: 10px 0 6px 0;
}

/* The uploaded figure image */
.mf-pfig-img {
  display: block;
  max-width: min(520px, 100%);
  height: auto;
  border-radius: 7px;
  border: 1px solid var(--rule-soft, #e8e2d6);
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  background: #fff;
}

/* ==============================================================
   REPLACE-IMAGE BUTTON — appears on .fig-img / .fig-container in edit mode
   ============================================================== */
.mf-img-replace-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #2c3e50;
  color: #f4f1ea;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  cursor: pointer;
  z-index: 20;
  opacity: 0.88;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}
.mf-img-replace-btn:hover {
  opacity: 1;
  background: #c0392b;
}
