:root {
  --bg:            #f5f1ea;
  --sidebar-bg:    #252320;
  --sidebar-text:  #d9d3c7;
  --accent:        #8b5e3c;
  --accent-lt:     #c8a05a;
  --border:        #d4c5ad;
  --text:          #2c2010;
  --text-muted:    #7a6a55;
  --editor-bg:     #ffffff;
  --preview-bg:    #fdf8f0;
  --chip-bg:       #3a3730;
  --chip-text:     #bdb5a6;
  --header-bg:     #1a1815;
  --header-text:   #e8dfc8;
}

/* Ensure [hidden] works even when an element has an explicit display rule */
[hidden] { display: none !important; }

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

body {
  font-family: Georgia, 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Header ────────────────────────────────────────────────────────── */
header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 0.55rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 2px solid var(--accent);
}

header h1 {
  font-size: 1rem;
  font-weight: normal;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#stats-badge {
  font-size: 0.78rem;
  color: #9a8f7e;
  font-style: italic;
}

/* ── Main layout ───────────────────────────────────────────────────── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────── */
#sidebar {
  width: 250px;
  min-width: 200px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  border-right: 1px solid #3a3730;
}

#search-area {
  padding: 0.7rem;
  border-bottom: 1px solid #3a3730;
}

#search-input {
  width: 100%;
  background: #3a3730;
  border: 1px solid #504840;
  border-radius: 4px;
  color: var(--sidebar-text);
  padding: 0.4rem 0.7rem;
  font-size: 0.83rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent-lt); }
#search-input::placeholder { color: #6a5a48; }

#filter-area {
  padding: 0.5rem 0.7rem 0.4rem;
  border-bottom: 1px solid #3a3730;
}

.filter-group { margin-bottom: 0.45rem; }
.filter-group:last-child { margin-bottom: 0; }

.filter-label {
  display: block;
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #6a5a48;
  margin-bottom: 0.3rem;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.chip {
  background: var(--chip-bg);
  border: 1px solid #504840;
  color: var(--chip-text);
  padding: 0.18rem 0.5rem;
  font-size: 0.72rem;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}
.chip:hover { border-color: var(--accent-lt); color: var(--accent-lt); }
.chip.active { background: var(--accent-lt); border-color: var(--accent-lt); color: #1a1815; }

#list-count {
  padding: 0.3rem 0.7rem;
  font-size: 0.7rem;
  color: #6a5a48;
  border-bottom: 1px solid #3a3730;
}

#chant-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 0.2rem 0;
}
#chant-list::-webkit-scrollbar { width: 5px; }
#chant-list::-webkit-scrollbar-track { background: #1e1d1a; }
#chant-list::-webkit-scrollbar-thumb { background: #504840; border-radius: 3px; }

.chant-item {
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.chant-item:hover { background: #2e2c28; }
.chant-item.active { background: #2e2c28; border-left-color: var(--accent-lt); }

.item-name {
  font-size: 0.82rem;
  color: #d4c9b8;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-meta {
  font-size: 0.68rem;
  color: #6a5a48;
  margin-top: 0.12rem;
  font-family: 'Courier New', monospace;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.item-part {
  display: inline-block;
  padding: 0.08rem 0.3rem;
  border-radius: 2px;
  font-size: 0.63rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.item-part.in { background: #3a2e1a; color: #c8a05a; }
.item-part.gr { background: #1a2e3a; color: #5a90c8; }
.item-part.al { background: #1a3a1a; color: #5ac85a; }
.item-part.of { background: #3a1a2e; color: #c85aa0; }
.item-part.co { background: #1a2a3a; color: #5aaac8; }

.item-status { font-size: 0.63rem; }
.item-status.draft    { color: #9a8050; }
.item-status.approved { color: #5a9a50; }
.item-status.rejected { color: #9a5050; }

/* ── Editor panel ──────────────────────────────────────────────────── */
#editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#empty-state {
  padding: 3rem 2rem;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.9rem;
}

#chant-editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* ── Chant header ──────────────────────────────────────────────────── */
#chant-header {
  padding: 0.65rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--editor-bg);
  flex-shrink: 0;
}

#chant-title {
  font-size: 1.05rem;
  color: var(--text);
  line-height: 1.3;
}
#chant-title .part-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-right: 0.5rem;
}

#chant-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  font-family: 'Courier New', monospace;
}

/* ── Controls bar ──────────────────────────────────────────────────── */
#chant-controls {
  padding: 0.45rem 1rem;
  background: var(--editor-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.control-row > label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.checkbox-label { cursor: pointer; }
.checkbox-label input { cursor: pointer; accent-color: var(--accent); }

select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.22rem 0.5rem;
  font-size: 0.78rem;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color 0.12s;
}
select:focus { border-color: var(--accent-lt); }

.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 0.32rem 1rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s;
}
.btn-primary:hover:not(:disabled) { background: #a07040; }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.32rem 0.8rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

#save-status {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-style: italic;
}
#save-status.saved   { color: #5a9a50; font-style: normal; }
#save-status.unsaved { color: #c8a05a; font-style: normal; }
#save-status.error   { color: #c85a5a; font-style: normal; }
#save-status.pending { color: #5a90c8; font-style: normal; }

/* A proposed edit queued for review on the read-only server (edit-queue.js). */
.pending-badge {
  font-size: 0.6rem;
  flex-shrink: 0;
  padding: 0 0.3rem;
  border: 1px solid #5a90c8;
  border-radius: 3px;
  color: #5a90c8;
}

/* ── Edit / Preview area ───────────────────────────────────────────── */
#edit-area {
  display: flex;
  flex: 1;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  min-height: 0;
}

#gabc-editor-pane {
  display: flex;
  flex-direction: column;
  flex: 0 0 45%;
  border-right: 1px solid var(--border);
  min-width: 0;
}

#preview-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  background: var(--preview-bg);
  min-width: 0;
}

.pane-label {
  padding: 0.28rem 0.75rem;
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  background: var(--editor-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#gabc-textarea {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  padding: 0.75rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  line-height: 1.55;
  resize: none;
  background: var(--editor-bg);
  color: var(--text);
  tab-size: 2;
}

#preview-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem 0.5rem;
}
#preview-container svg { max-width: 100%; height: auto; display: block; }
#preview-container::-webkit-scrollbar { width: 6px; }
#preview-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Latin reference section ───────────────────────────────────────── */
#latin-section {
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 38%;
}

#latin-summary {
  padding: 0.38rem 1rem;
  background: var(--editor-bg);
  cursor: pointer;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-top: 1px solid var(--border);
  list-style: none;
  user-select: none;
  flex-shrink: 0;
}
#latin-summary::-webkit-details-marker { display: none; }
#latin-summary::before { content: '▶  '; font-size: 0.6rem; }
#latin-section[open] > summary::before { content: '▼  '; }

#latin-refs {
  overflow-y: auto;
  padding: 0.5rem 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
}
#latin-refs::-webkit-scrollbar { width: 6px; }
#latin-refs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.latin-ref {
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.latin-ref-header {
  padding: 0.35rem 0.75rem;
  background: var(--editor-bg);
  font-size: 0.73rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.latin-ref-header strong { color: var(--text); }
.latin-ref-id { margin-left: auto; color: #b0a090; font-size: 0.65rem; font-family: 'Courier New', monospace; }

.latin-ref-preview {
  padding: 0.75rem 1rem;
  background: var(--preview-bg);
  overflow-x: auto;
}
.latin-ref-preview svg { max-width: 100%; height: auto; display: block; }

/* ── Assignments section ───────────────────────────────────────────── */
#assignments-section {
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 35%;
  border-top: 1px solid var(--border);
}

#assignments-summary {
  padding: 0.38rem 1rem;
  background: var(--editor-bg);
  cursor: pointer;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  list-style: none;
  user-select: none;
  flex-shrink: 0;
}
#assignments-summary::-webkit-details-marker { display: none; }
#assignments-summary::before { content: '▶  '; font-size: 0.6rem; }
#assignments-section[open] > summary::before { content: '▼  '; }

#assignments-list {
  overflow-y: auto;
  padding: 0.4rem 1rem 0.6rem;
  flex: 1;
}
#assignments-list::-webkit-scrollbar { width: 6px; }
#assignments-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.assignment-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.28rem 0;
  border-bottom: 1px solid #ede5d8;
  font-size: 0.78rem;
  line-height: 1.4;
}
.assignment-row:last-child { border-bottom: none; }

.assign-part {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  min-width: 5rem;
  flex-shrink: 0;
}

.assign-day { color: var(--text); flex: 1; }
.assign-day .general { color: var(--text-muted); font-style: italic; }

.assign-badges {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}
.assign-badge {
  font-size: 0.62rem;
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
  background: #ede5d8;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
}
.assign-badge.authority { background: #e8dfc8; color: var(--accent); }
.assign-badge.alt { background: #dde8f0; color: #4a7090; }

/* ── Assignment toolbar & form ─────────────────────────────────────── */
#assign-toolbar {
  padding: 0.3rem 1rem;
  border-bottom: 1px solid #ede5d8;
}

.btn-add-assign {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 0.18rem 0.6rem;
  border-radius: 3px;
  font-size: 0.7rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s;
}
.btn-add-assign:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

#assignment-form {
  padding: 0.5rem 1rem 0.6rem;
  background: #faf5eb;
  border-bottom: 1px solid var(--border);
}

.assign-form-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
}
.assign-form-row:last-child { margin-bottom: 0; }

.assign-form-row > label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.73rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.assign-form-row select,
.assign-form-row input[type="text"] {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.2rem 0.4rem;
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--text);
}
.assign-form-row select.wide { min-width: 14rem; }
.assign-form-row input[type="text"] { width: 10rem; }

.btn-sm { padding: 0.22rem 0.7rem; font-size: 0.73rem; }

#af-status {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Delete button on assignment rows ─────────────────────────────── */
.assign-delete {
  background: none;
  border: none;
  color: #c0a090;
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0.1rem 0.3rem;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
}
.assignment-row:hover .assign-delete { opacity: 1; }
.assign-delete:hover { color: #c05050; }

.render-note { color: #b0a090; font-size: 0.78rem; }
.render-note.error { color: #c05050; }

/* ══════════════════════════════════════════════════════════════════════════
   Source Review page (sources.html / sources.js)
   ══════════════════════════════════════════════════════════════════════════ */

#page-nav { display: flex; gap: 0.9rem; font-size: 0.78rem; }
#page-nav a {
  color: #9a8f7e;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-bottom: 2px;
  border-bottom: 2px solid transparent;
}
#page-nav a:hover { color: var(--header-text); }
#page-nav a.active { color: var(--accent-lt); border-bottom-color: var(--accent-lt); }

/* ── Signed-in user badge (auth.js, every page header) ─────────────── */
#auth-badge {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.75rem;
  color: #9a8f7e;
  white-space: nowrap;
}
#auth-badge .auth-role {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.68rem;
  color: var(--accent-lt);
}
#auth-badge .auth-name { color: inherit; text-decoration: none; }
#auth-badge .auth-name:hover { color: var(--header-text); text-decoration: underline; }
#auth-badge button {
  font: inherit;
  background: none;
  border: 1px solid #504840;
  border-radius: 3px;
  color: #9a8f7e;
  padding: 0.1rem 0.5rem;
  cursor: pointer;
}
#auth-badge .auth-menu-toggle { display: none; padding: 0; min-height: 0; border: none; border-radius: 50%; align-items: center; line-height: 0; }
#auth-badge .auth-menu {
  position: absolute; right: 0.6rem; top: 100%; z-index: 100; min-width: 11rem;
  background: var(--header-bg); border: 1px solid #504840; border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35); padding: 0.25rem 0; white-space: normal;
}
#auth-badge .auth-menu[hidden] { display: none; }
#auth-badge .auth-menu-who { display: flex; flex-direction: column; padding: 0.4rem 0.8rem; border-bottom: 1px solid #504840; color: var(--header-text); font-size: 0.8rem; }
#auth-badge .auth-menu-who span { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.65rem; color: var(--accent-lt); }
#auth-badge .auth-menu-item { display: block; width: 100%; text-align: left; box-sizing: border-box; border: none; border-radius: 0; padding: 0.5rem 0.8rem; font-size: 0.8rem; color: #9a8f7e; text-decoration: none; background: none; }
#auth-badge .auth-menu-item:hover { color: var(--header-text); background: #3a3730; }
#auth-badge button:hover { color: var(--header-text); border-color: var(--accent-lt); }

#src-search-area { padding: 0.6rem 0.7rem; border-bottom: 1px solid #3a3730; }
#src-search {
  width: 100%;
  background: #3a3730;
  border: 1px solid #504840;
  border-radius: 4px;
  color: var(--sidebar-text);
  padding: 0.4rem 0.7rem;
  font-size: 0.83rem;
  font-family: inherit;
  outline: none;
}
#src-search:focus { border-color: var(--accent-lt); }
#src-search::placeholder { color: #6a5a48; }

#src-list-count {
  padding: 0.3rem 0.7rem;
  font-size: 0.7rem;
  color: #6a5a48;
  border-bottom: 1px solid #3a3730;
}

#src-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 0.2rem 0;
}
#src-list::-webkit-scrollbar { width: 5px; }
#src-list::-webkit-scrollbar-thumb { background: #504840; border-radius: 3px; }

.src-page-hdr {
  padding: 0.35rem 0.7rem 0.2rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6a5a48;
  font-family: 'Courier New', monospace;
}

.src-item {
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  transition: background 0.1s;
}
.src-item:hover { background: #2e2c28; }
.src-item.selected { background: #2e2c28; border-left-color: var(--accent-lt); }

.src-part {
  display: inline-block;
  min-width: 1.7rem;
  text-align: center;
  padding: 0.08rem 0.3rem;
  border-radius: 2px;
  font-size: 0.63rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
.src-part.part-in { background: #3a2e1a; color: #c8a05a; }
.src-part.part-gr { background: #1a2e3a; color: #5a90c8; }
.src-part.part-al { background: #1a3a1a; color: #5ac85a; }
.src-part.part-tr { background: #2e1a3a; color: #a05ac8; }
.src-part.part-of { background: #3a1a2e; color: #c85aa0; }
.src-part.part-co { background: #1a2a3a; color: #5aaac8; }

.src-incipit {
  flex: 1;
  font-size: 0.78rem;
  color: #d4c9b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.src-status { font-size: 0.62rem; flex-shrink: 0; }
.src-status.status-draft     { color: #9a8050; }
.src-status.status-reviewed  { color: #5a9a50; }
.src-status.status-published { color: #5a90c8; }

.src-error { padding: 0.7rem; color: #c87a7a; font-size: 0.8rem; }

/* ── Right panel ───────────────────────────────────────────────────── */
#src-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#src-empty-state {
  padding: 3rem 2rem;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.9rem;
}

#src-editor { display: flex; flex: 1; overflow: hidden; }

#src-edit-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--editor-bg);
}
#src-edit-col::-webkit-scrollbar { width: 6px; }
#src-edit-col::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

#src-header {
  padding: 0.65rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#src-title { font-size: 1.05rem; color: var(--text); }
#src-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  font-family: 'Courier New', monospace;
}

.src-controls {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.src-controls label { flex-direction: column; align-items: flex-start; gap: 0.18rem; }
.src-controls label.wide { flex: 1; }

.src-controls input[type="text"],
.src-controls input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
}
.src-controls input.wide { width: 100%; }
.src-controls input[type="text"] { min-width: 12rem; }
.src-controls input[type="text"]:focus,
.src-controls input[type="number"]:focus { border-color: var(--accent-lt); }

.src-field { padding: 0.5rem 1rem; }
.src-field .pane-label {
  padding: 0 0 0.25rem 0;
  background: none;
  border: none;
}
.src-field textarea,
.src-field input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem 0.6rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  resize: vertical;
  background: var(--preview-bg);
  color: var(--text);
  outline: none;
}
.src-field textarea:focus,
.src-field input[type="text"]:focus { border-color: var(--accent-lt); }

.src-actions {
  padding: 0.7rem 1rem 1rem;
  border-top: 1px solid var(--border);
}
#se-status-msg { font-size: 0.76rem; color: var(--text-muted); font-style: italic; }

#src-bbox-filter-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.75rem;
  background: rgba(58, 125, 208, 0.12);
  border-bottom: 1px solid rgba(58, 125, 208, 0.3);
  font-size: 0.76rem;
  color: var(--text-muted);
}
#src-bbox-filter-banner span { flex: 1; }
#src-bbox-filter-clear {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0 0.2rem;
  line-height: 1;
}
#src-bbox-filter-clear:hover { color: var(--text); }

#src-chant-section {
  margin: 0.5rem 1rem 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
#src-chant-section > summary {
  cursor: pointer;
  padding: 0.3rem 0.75rem;
  background: var(--sidebar-bg);
  user-select: none;
}
.src-chant-meta {
  padding: 0.3rem 0.75rem;
  font-size: 0.76rem;
  color: var(--text-muted);
  font-style: italic;
}
#src-chant-preview {
  padding: 0.5rem 0.75rem 0.75rem;
  overflow-x: auto;
}

/* ── Page image column ─────────────────────────────────────────────── */
#src-image-col {
  flex: 0 0 440px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  background: var(--preview-bg);
  border-left: 1px solid var(--border);
  overflow: hidden;
}
#src-image-label {
  flex-shrink: 0;
  font-family: 'Courier New', monospace;
  text-transform: none;
  letter-spacing: 0;
}
#src-image-wrap {
  position: relative;
  overflow: auto;
  flex: 1;
  padding: 0.5rem;
}
#src-image-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
#src-image-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

#src-page-img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  background: #fff;
}
#next-image-label {
  flex-shrink: 0;
  font-family: 'Courier New', monospace;
  text-transform: none;
  letter-spacing: 0;
}
#next-image-wrap {
  flex-shrink: 0;
  height: 260px;
  overflow: auto;
  padding: 0.5rem;
}
#next-image-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
#next-image-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#next-page-img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  background: #fff;
}
#ref-image-label {
  flex-shrink: 0;
  font-family: 'Courier New', monospace;
  text-transform: none;
  letter-spacing: 0;
}
#ref-image-wrap {
  flex-shrink: 0;
  height: 260px;
  overflow: auto;
  padding: 0.5rem;
}
#ref-image-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
#ref-image-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#ref-page-img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  background: #fff;
}
#src-bbox-overlay {
  position: absolute;
  border: 2px solid #c8a800;
  background: rgba(200, 168, 0, 0.18);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.5);
  display: none;
  cursor: move;
  touch-action: none;
}

.bbox-label {
  position: absolute;
  top: 0;
  left: 0;
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1;
  padding: 1px 3px;
  background: rgba(0,0,0,0.45);
  color: #fff;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

.sibling-bbox {
  position: absolute;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.4);
  pointer-events: none;
}
.sibling-bbox.status-draft {
  border: 2px solid #d04a3a;
  background: rgba(208, 74, 58, 0.12);
}
.sibling-bbox.status-reviewed {
  border: 2px solid #3a9e50;
  background: rgba(58, 158, 80, 0.12);
}
.sibling-bbox.status-published {
  border: 2px solid #3a9e50;
  background: rgba(58, 158, 80, 0.12);
}

.bbox-handle {
  position: absolute;
  width: 11px;
  height: 11px;
  background: #d04a3a;
  border: 1px solid #fff;
  border-radius: 2px;
  touch-action: none;
}
.bbox-nw { top: -6px;    left: -6px;  cursor: nwse-resize; }
.bbox-ne { top: -6px;    right: -6px; cursor: nesw-resize; }
.bbox-se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.bbox-sw { bottom: -6px; left: -6px;  cursor: nesw-resize; }
.bbox-n  { top: -6px;    left: 50%; margin-left: -6px; cursor: ns-resize; }
.bbox-s  { bottom: -6px; left: 50%; margin-left: -6px; cursor: ns-resize; }
.bbox-w  { left: -6px;   top: 50%;  margin-top: -6px;  cursor: ew-resize; }
.bbox-e  { right: -6px;  top: 50%;  margin-top: -6px;  cursor: ew-resize; }

/* ══════════════════════════════════════════════════════════════════════════
   Assignment Review page (assignments.html / assignments.js)
   ══════════════════════════════════════════════════════════════════════════ */

#asgn-stats-badge { font-size: 0.78rem; color: #9a8f7e; font-style: italic; }

.asgn-item {
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.1s;
}
.asgn-item:hover   { background: #2e2c28; }
.asgn-item.selected { background: #2e2c28; border-left-color: var(--accent-lt); }

.asgn-body { flex: 1; min-width: 0; }
.asgn-name {
  display: block;
  font-size: 0.78rem;
  color: #d4c9b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.asgn-epoch {
  display: block;
  font-size: 0.67rem;
  color: #6a5a48;
  font-family: 'Courier New', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.1rem;
}

.asgn-status { font-size: 0.72rem; flex-shrink: 0; }
.asgn-status.status-review { color: #c8a05a; }
.asgn-status.status-ok     { color: #5a9a50; }

.asgn-month-header,
.asgn-group-header {
  padding: 0.5rem 0.7rem 0.2rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #9a8f7e;
}

/* Commons that hang off a container node (see renderCommonList). */
.asgn-item.asgn-child { padding-left: 1.5rem; }

.src-controls input[readonly],
.src-controls input:disabled { opacity: 0.55; cursor: default; }

#ae-chant-preview {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 2rem;
}

.btn-delete {
  background: transparent;
  border: 1px solid #c05050;
  color: #c05050;
  padding: 0.32rem 0.8rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s;
}
.btn-delete:hover { background: #c05050; color: #fff; }

/* ══════════════════════════════════════════════════════════════════════════
   Assignment Review v2 — epoch-based (assignments.html v2)
   ══════════════════════════════════════════════════════════════════════════ */

#week-select, #month-select {
  width: 100%;
  background: #3a3730;
  border: 1px solid #504840;
  border-radius: 4px;
  color: var(--sidebar-text);
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
#week-select:focus, #month-select:focus { border-color: var(--accent-lt); }
#week-select option, #month-select option { background: #3a3730; }

.review-section-header {
  padding: 0.38rem 1rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  background: #f0ebe0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.part-section { margin-bottom: 0; }

.part-section-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #e8e1d4;
}

.asgn-review-row {
  border-bottom: 1px solid #ede5d8;
  padding: 0.45rem 1rem;
}
.asgn-review-row:last-child { border-bottom: none; }
.asgn-review-row.needs-review { background: #fdf8f0; }
.asgn-review-row.reviewed { background: #fff; }

.arr-main {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.arr-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
}

.arr-epoch-label {
  font-size: 0.64rem;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
  font-style: italic;
}

.arr-chant {
  font-size: 0.82rem;
  color: var(--text);
}

.arr-meta {
  font-size: 0.67rem;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
}

.arr-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.arr-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s;
}
.asgn-review-row:hover .arr-actions,
.asgn-review-row:focus-within .arr-actions { opacity: 1; }

.btn-arr {
  padding: 0.16rem 0.5rem;
  border-radius: 3px;
  font-size: 0.71rem;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all 0.12s;
}
.btn-accept:hover   { border-color: #5a9a50; color: #5a9a50; background: #f0faf0; }
.btn-edit-row:hover { border-color: var(--accent); color: var(--accent); }
.btn-reject:hover   { border-color: #c05050; color: #c05050; background: #fdf0f0; }
.btn-save-edit  { border-color: var(--accent); color: var(--accent); }
.btn-save-edit:hover { background: var(--accent); color: #fff; }
.btn-cancel-edit:hover { border-color: var(--border); color: var(--text); }

.arr-edit-form {
  margin-top: 0.45rem;
  padding: 0.5rem 0.6rem;
  background: #f5f0e8;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.aef-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}
.aef-row > label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.73rem;
  color: var(--text-muted);
}
.aef-row input[type="text"],
.aef-row input[type="number"],
.aef-row select {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.2rem 0.4rem;
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
}
.aef-row input:focus,
.aef-row select:focus { border-color: var(--accent-lt); }

.arr-msg {
  font-size: 0.71rem;
  color: var(--text-muted);
  font-style: italic;
}

.review-empty {
  padding: 1rem 1rem;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.82rem;
}

/* ══════════════════════════════════════════════════════════════════════════
   Merge Manager page (mergers.html / mergers.js)
   ══════════════════════════════════════════════════════════════════════════ */

#merge-main {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
#merge-main::-webkit-scrollbar { width: 8px; }
#merge-main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Section headers ─────────────────────────────────────────────────────── */
.section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-family: Georgia, serif;
}

#manual-bar,
#queue-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

#manual-inputs {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}
#manual-inputs label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
#manual-inputs input[type="number"] {
  width: 8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
}
#manual-inputs input[type="number"]:focus { border-color: var(--accent-lt); }

#manual-msg {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

#queue-status-msg {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

#queue-loading, #queue-empty {
  padding: 1.5rem 0;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
}

#queue-footer { padding: 0.5rem 0 1rem; }

.mc-api-error {
  padding: 0.75rem;
  color: #c05050;
  font-size: 0.82rem;
  background: #fff5f5;
  border: 1px solid #f0c0c0;
  border-radius: 4px;
}

/* ── Pair cards ──────────────────────────────────────────────────────────── */
.merge-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--editor-bg);
  margin-bottom: 1rem;
  overflow: hidden;
  transition: opacity 0.15s, transform 0.15s;
}
.merge-card.mc-done {
  opacity: 0.35;
  transform: scale(0.99);
  pointer-events: none;
}
.manual-card { border-color: var(--accent-lt); }

/* Card header */
.mc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.85rem;
  background: #f0ebe0;
  border-bottom: 1px solid var(--border);
}
.mc-context {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.mc-sim {
  font-size: 0.75rem;
  font-family: 'Courier New', monospace;
  color: var(--accent);
  font-weight: bold;
}

/* Card body: two panels side by side */
.mc-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
}

/* Group panel */
.mgp {
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}
.mgp + .mgp {
  border-left: 1px solid var(--border);
  background: var(--preview-bg);
}

.mgp-topline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.mgp-side-label {
  font-size: 0.65rem;
  font-weight: bold;
  background: var(--accent-lt);
  color: #1a1815;
  border-radius: 2px;
  padding: 0.1rem 0.35rem;
  line-height: 1.2;
}
.mgp-id {
  font-size: 0.65rem;
  color: #b0a090;
  font-family: 'Courier New', monospace;
}
.mgp-count {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-left: auto;
}
.mgp-name {
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.3;
  font-weight: 500;
  cursor: text;
  border-radius: 3px;
  padding: 1px 3px;
  margin: -1px -3px;
  transition: background 0.1s;
}
.mgp-name:hover:not(.editing) { background: #f0e8d8; }
.mgp-name.editing { cursor: default; display: flex; align-items: center; gap: 0.25rem; }

.mgp-name-input {
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  font-family: Georgia, serif;
  font-weight: 500;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--accent-lt);
  border-radius: 3px;
  padding: 0.12rem 0.35rem;
  outline: none;
}

.mgp-name-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.15rem 0.3rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.1s;
}
.mgp-name-btn.save  { color: #5a9a50; border-color: #5a9a50; }
.mgp-name-btn.save:hover  { background: #5a9a50; color: #fff; }
.mgp-name-btn.cancel { color: #c05050; border-color: #c05050; }
.mgp-name-btn.cancel:hover { background: #c05050; color: #fff; }
.mgp-badges {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.mgp-badge {
  font-size: 0.62rem;
  padding: 0.1rem 0.4rem;
  border-radius: 2px;
  background: #ede5d8;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
}
.mgp-badge.part-b { background: #e8dfc8; color: var(--accent); }

.mgp-incipit {
  font-size: 0.8rem;
  color: var(--text);
  font-style: italic;
}
.mgp-clean {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
}
.mgp-gabc {
  margin-top: 0.35rem;
  overflow-x: auto;
}
.mgp-gabc svg { max-width: 100%; height: auto; display: block; }

/* Card footer */
.mc-footer {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 0.55rem 1rem;
  background: #faf7f2;
  flex-wrap: wrap;
}
.mc-keep {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.mc-keep label {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  cursor: pointer;
}
.mc-keep input[type="radio"] { accent-color: var(--accent); cursor: pointer; }

.mc-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.mc-msg {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}
.mc-msg.ok  { color: #5a9a50; font-style: normal; }
.mc-msg.err { color: #c05050; font-style: normal; }

.btn-related-style {
  background: transparent;
  border: 1px solid #7a6a9a;
  color: #7a6a9a;
  padding: 0.32rem 0.8rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s;
}
.btn-related-style:hover { background: #7a6a9a; color: #fff; }

/* tex_verses: text verses typeset below the score (as on GregoBase) */
.tex-verses {
  margin: 0.75rem 1rem 0.5rem;
  font-family: 'Libertinus Serif', Georgia, 'Times New Roman', serif;
  font-size: 0.95rem;
  line-height: 1.45;
}
.tex-verses .tv-red   { color: #b3261e; }
.tex-verses .tv-gap   { display: block; height: 0.6em; }
.tex-verses .tv-table { border-collapse: collapse; }
.tex-verses .tv-table td { padding: 0 1.5em 0 0; vertical-align: top; }
.tex-verses .tv-gaprow td { height: 0.6em; }

/* ══════════════════════════════════════════════════════════════════════════
   Phone width (all pages share this header / sidebar / main shell)
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  body, #app { height: 100vh; height: 100dvh; }

  header { flex-wrap: nowrap; gap: 0.6rem; padding: 0.4rem 0.8rem; position: relative; }
  header h1 { font-size: 0.85rem; letter-spacing: 0.06em; white-space: nowrap; flex-shrink: 0; }
  header h1 .h1-sub { display: none; }
  #auth-badge { position: static; flex-shrink: 0; }
  #auth-badge .auth-name, #auth-badge .auth-role, #auth-badge .auth-signout { display: none; }
  #auth-badge .auth-menu-toggle { display: inline-flex; }
  #page-nav {
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    gap: 1rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #page-nav a { flex-shrink: 0; padding: 0.3rem 0; }

  #main { flex-direction: column; }
  #sidebar {
    width: 100%;
    min-width: 0;
    max-height: 38vh;
    border-right: none;
    border-bottom: 1px solid #3a3730;
  }
  #editor-panel, #day-content { min-width: 0; }

  /* Comfortable tap targets and no iOS zoom-on-focus */
  input, select, textarea { font-size: 16px !important; }
  button, .chip { min-height: 32px; }

  /* Day view */
  #observance-tabs { padding: 0.5rem 0.8rem; overflow-x: auto; flex-wrap: nowrap; }
  .observance-tab { flex-shrink: 0; }
}
