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

:root {
  --bg: #F4F5F7;
  --surface: #ffffff;
  --border: #E6E6E8;
  --text: #23343B;
  --muted: #4B575E;
  --accent: #E4003A;
  --accent-light: #fff0f2;
  --success: #3CBC6E;
  --success-bg: #e6f7ed;
  --error: #E4003A;
  --error-bg: #fff0f2;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'IBM Plex Sans', sans-serif;
  --shadow-sm: 0 1px 2px 0 rgba(35, 52, 59, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(35, 52, 59, 0.08), 0 2px 4px -2px rgba(35, 52, 59, 0.08);
  --shadow-lg: 0 10px 15px -3px rgba(35, 52, 59, 0.08), 0 4px 6px -4px rgba(35, 52, 59, 0.08);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* LOGO INTEGRATION */
.logo-container {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  height: 28px;
  width: auto;
  object-fit: contain;
}

.logo-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.login-logo-container {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.login-logo {
  max-width: 100%;
  height: auto;
  max-height: 48px;
  display: block;
  object-fit: contain;
}

/* LOGIN SCREEN */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 50%, var(--surface) 0%, var(--bg) 100%);
}

.login-box {
  width: 380px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.login-box h1 {
  font-family: var(--sans);
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  text-align: center;
}

.login-box p {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 32px;
  text-align: center;
  font-weight: 500;
}

.field {
  margin-bottom: 20px;
}

.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
  font-family: var(--sans);
}

.field input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
  transition: background-color 0.2s, transform 0.1s;
}

.btn:hover {
  background: #c20030; /* Darker brand red */
}

.btn:active {
  transform: scale(0.98);
}

.login-error {
  font-size: 12px;
  color: var(--error);
  margin-top: 12px;
  font-family: var(--sans);
  display: none;
  background: var(--error-bg);
  padding: 10px;
  border-radius: 6px;
  border: 1px solid rgba(228, 0, 58, 0.15);
}

/* DASHBOARD LAYOUT */
#dashboard {
  display: none;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 40px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

header span {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--sans);
  font-weight: 500;
}

.logout-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: all 0.2s;
}

.logout-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* STATS */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 24px;
  padding: 32px 40px 16px 40px;
  background: var(--bg);
}

.stat {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  font-family: var(--sans);
  margin-bottom: 8px;
}

.stat-value {
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 600;
  color: var(--text);
}

.stat-value.accent {
  color: var(--accent);
}

/* MAIN */
main {
  padding: 16px 40px 40px 40px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.refresh-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.refresh-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* TABLE CARD WRAPPER */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--sans);
  font-size: 13px;
}

th {
  text-align: left;
  padding: 14px 24px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

td {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: #f8fafc;
}

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 12px;
  font-family: var(--sans);
}

.badge-success {
  background: var(--success-bg);
  color: var(--success);
}

.badge-error {
  background: var(--error-bg);
  color: var(--error);
}

.badge-warning {
  background: #fef3c7;
  color: #d97706;
}

.badge-info {
  background: #e0f2fe;
  color: #0284c7;
}

/* ACTION BUTTONS */
.expand-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.expand-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* Warn/Yellow Badge variant for Attachments */
.expand-btn-warning {
  border-color: #d97706 !important;
  color: #d97706 !important;
}

.expand-btn-warning:hover {
  background: #fef3c7 !important;
  border-color: #b45309 !important;
  color: #b45309 !important;
}

/* Notes/Orange variant — high visibility for copyright warnings etc. */
.expand-btn-notes {
  border-color: #ea580c !important;
  color: #ea580c !important;
  font-weight: 600 !important;
}

.expand-btn-notes:hover {
  background: #fff7ed !important;
  border-color: #c2410c !important;
  color: #c2410c !important;
}

/* Info/Blue variant for Instructions */
.expand-btn-info {
  border-color: #0284c7 !important;
  color: #0284c7 !important;
}

.expand-btn-info:hover {
  background: #f0f9ff !important;
  border-color: #0369a1 !important;
  color: #0369a1 !important;
}

/* EXPANDABLE DETAILS ROW */
.xml-row td {
  background: #f8fafc;
  padding: 0 24px 20px 24px;
  border-bottom: 1px solid var(--border);
}

.xml-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 10px;
}

.xml-box, .json-box {
  background: #0f172a;
  border-radius: 8px;
  border: 1px solid #1e293b;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.xml-box h3, .json-box h3 {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 12px 16px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  margin-bottom: 0;
}

.xml-box .xml-content, .json-box .json-content {
  border-left: none !important;
  margin: 0 !important;
  padding: 16px !important;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
}

.xml-content {
  color: #a7f3d0; /* Soft green */
}

.json-content {
  color: #bae6fd; /* Soft blue */
}

.empty-state {
  text-align: center;
  padding: 64px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 14px;
}

.input-summary {
  color: var(--muted);
  font-size: 12px;
}

/* Edit XML button variant */
.expand-btn-edit {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

.expand-btn-edit:hover {
  background: var(--accent-light) !important;
  border-color: #c20030 !important;
  color: #c20030 !important;
}

/* ── XML EDIT MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 960px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  flex-shrink: 0;
}

.modal-header h2 {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.modal-record-info {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-close-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.modal-close-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.modal-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  min-height: 0;
}

#xml-edit-textarea {
  flex: 1;
  width: 100%;
  background: #0f172a;
  color: #a7f3d0;
  border: none;
  padding: 16px 18px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  resize: none;
  outline: none;
  min-height: 52vh;
  tab-size: 2;
  caret-color: #ffffff;
}

#xml-edit-textarea::placeholder {
  color: #334155;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  flex-shrink: 0;
}

.modal-status {
  flex: 1;
  font-size: 12px;
  font-family: var(--sans);
  font-weight: 500;
}

.modal-status-success { color: var(--success); }
.modal-status-error   { color: var(--error); }

.modal-cancel-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 18px;
  border-radius: 7px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.modal-cancel-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

.modal-save-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 8px 22px;
  border-radius: 7px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-save-btn:hover:not(:disabled) { background: #c20030; }

.modal-save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── HEADER ACCENT BUTTON ── */
.header-btn-accent {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

.header-btn-accent:hover {
  background: var(--accent) !important;
  color: #fff !important;
  border-color: var(--accent) !important;
}

/* ── CONTENT MANAGER MODAL ── */
.cm-modal-box {
  max-width: 1180px !important;
}

/* LIST VIEW */
.cm-list-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.cm-filter-bar {
  display: flex;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  flex-shrink: 0;
}

.cm-search-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 7px;
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.cm-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.cm-type-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 7px;
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  min-width: 140px;
  transition: border-color 0.2s;
}

.cm-type-select:focus {
  border-color: var(--accent);
}

.cm-table-wrap {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.cm-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--sans);
  font-size: 13px;
}

.cm-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
}

/* Sortable column headers */
.cm-table th.cm-th-sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.cm-table th.cm-th-sortable:hover {
  background: #edf0f3;
}
/* Sort indicator appended via CSS ::after — no extra DOM needed */
.cm-table th.cm-th-sortable::after {
  content: "⇅";
  font-size: 9px;
  color: #c6cdd3;
  margin-left: 5px;
  vertical-align: middle;
}
.cm-table th.cm-th-sortable[data-sort="asc"]::after {
  content: "↑";
  color: var(--accent);
}
.cm-table th.cm-th-sortable[data-sort="desc"]::after {
  content: "↓";
  color: var(--accent);
}

.cm-table td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

.cm-table tr:last-child td {
  border-bottom: none;
}

.cm-table tr:hover td {
  background: #f8fafc;
}

/* Type badges */
.cm-type-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: 10px;
  font-family: var(--sans);
}

.cm-type-hymn    { background: #dcfce7; color: #166534; }
.cm-type-prayer  { background: #e0f2fe; color: #075985; }
.cm-type-psalm   { background: #f0fdf4; color: #14532d; border: 1px solid #bbf7d0; }
.cm-type-poem    { background: #f3e8ff; color: #6b21a8; }
.cm-type-reading { background: #fef3c7; color: #92400e; }

.cm-default-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 8px;
  background: #dcfce7;
  color: #166534;
  margin-left: 6px;
  font-family: var(--sans);
}

/* Add button in modal header */
.cm-add-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 7px 16px;
  border-radius: 7px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.cm-add-btn:hover { background: #c20030; }

/* FORM VIEW */
.cm-form-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.cm-form-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  flex-shrink: 0;
}

.cm-back-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 7px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.cm-back-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

.cm-form-heading {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.cm-form-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.cm-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.cm-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cm-group-grow { flex: 1; }

.cm-group-fixed { width: 200px; flex-shrink: 0; }

.cm-group-check {
  justify-content: flex-end;
  padding-bottom: 4px;
}

.cm-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-family: var(--sans);
}

.cm-req {
  color: var(--accent);
}

.cm-input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 7px;
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.cm-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* ── Quill rich-text editors ── */

/* Toolbar */
.ql-toolbar.ql-snow {
  border: 1px solid var(--border);
  border-radius: 7px 7px 0 0;
  background: #f8fafc;
  font-family: var(--sans);
  padding: 7px 10px;
}

/* Editor container */
.ql-container.ql-snow {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 7px 7px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
  background: #fff;
}

/* Placeholder */
.ql-editor.ql-blank::before {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
  opacity: 0.8;
}

/* Focus ring */
.cm-quill-body .ql-container.ql-snow:focus-within,
.cm-quill-author .ql-container.ql-snow:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* Active toolbar buttons — use brand accent */
.ql-snow.ql-toolbar button:hover,
.ql-snow.ql-toolbar button.ql-active,
.ql-snow .ql-toolbar button:hover,
.ql-snow .ql-toolbar button.ql-active {
  color: var(--accent);
}

.ql-snow.ql-toolbar button:hover .ql-stroke,
.ql-snow.ql-toolbar button.ql-active .ql-stroke,
.ql-snow .ql-toolbar button:hover .ql-stroke,
.ql-snow .ql-toolbar button.ql-active .ql-stroke {
  stroke: var(--accent);
}

.ql-snow.ql-toolbar button:hover .ql-fill,
.ql-snow.ql-toolbar button.ql-active .ql-fill,
.ql-snow .ql-toolbar button:hover .ql-fill,
.ql-snow .ql-toolbar button.ql-active .ql-fill {
  fill: var(--accent);
}

/* Body editor — generous height for hymn text */
.cm-quill-body .ql-editor {
  min-height: 240px;
  line-height: 1.8;
  padding: 14px 16px;
}

/* Author editor — compact single/few-line height */
.cm-quill-author .ql-editor {
  min-height: 46px;
  line-height: 1.6;
  padding: 9px 14px;
}

.cm-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  padding: 9px 0;
}

.cm-checkbox-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}
