/* ─── CSS Custom Properties ─────────────────────────────────── */
:root {
  --bg-color: #f5f0eb;
  --bg-image: none;
  --title-font: 'Dancing Script', cursive;
  --title-color: #5a7d6a;
  --body-font: 'Poppins', sans-serif;
  --body-color: #3a3a3a;
  --header-bg: #5a7d6a;
  --header-text: #ffffff;
  --cell-bg: #ffffff;
  --cell-border: #d4c9be;
  --sunday-tint: #eef5e9;
}

/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--body-font);
  color: var(--body-color);
  background-color: var(--bg-color);
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  min-height: 100vh;
}

/* ─── Toolbar ───────────────────────────────────────────────── */
#toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.5rem;
  background: var(--header-bg);
  color: var(--header-text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

#toolbar button {
  background: rgba(255,255,255,0.15);
  color: var(--header-text);
  border: 1px solid rgba(255,255,255,0.3);
  padding: 0.4rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--body-font);
  font-size: 0.85rem;
  transition: background 0.2s;
}

#toolbar button:hover {
  background: rgba(255,255,255,0.25);
}

#toolbar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#toolbar-left,
#toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#btn-select.active {
  background: rgba(255,255,255,0.35);
  border-color: rgba(255,255,255,0.7);
}

#selection-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

#selection-count {
  font-weight: 600;
}

#month-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#month-label {
  font-size: 1.1rem;
  font-weight: 500;
  min-width: 160px;
  text-align: center;
}

/* ─── Calendar Page ─────────────────────────────────────────── */
#calendar-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

#calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
  gap: 1rem;
}

#header-left {
  flex-shrink: 0;
}

#cal-year {
  font-family: var(--body-font);
  font-size: 1rem;
  color: var(--title-color);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  position: relative;
  z-index: 2;
}

#cal-month-title {
  font-family: var(--title-font);
  font-size: 3.5rem;
  color: var(--title-color);
  line-height: 1;
  margin-top: -0.1em;
}

#header-right {
  text-align: right;
  max-width: 50%;
}

#verse-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--title-color);
  margin-bottom: 0.25rem;
}

#verse-text {
  font-size: 0.85rem;
  line-height: 1.4;
  font-style: italic;
  color: var(--body-color);
}

/* ─── Calendar Grid ─────────────────────────────────────────── */
#calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--cell-border);
  border-radius: 8px;
  overflow: hidden;
}

.day-header {
  background: var(--header-bg);
  color: var(--header-text);
  text-align: center;
  padding: 0.4rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
}

.day-cell {
  background: var(--cell-bg);
  border: 1px solid var(--cell-border);
  min-height: 90px;
  padding: 0.3rem 0.4rem;
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}

.day-cell:hover {
  background: rgba(0,0,0,0.03);
}

.day-cell.sunday {
  background: var(--sunday-tint);
}

.day-cell.sunday:hover {
  filter: brightness(0.97);
}

.day-cell.empty {
  background: transparent;
  cursor: default;
  border-color: transparent;
}

.day-cell.empty:hover {
  background: transparent;
}

.day-cell.other-month {
  opacity: 0.45;
}

.day-cell.other-month .day-number {
  font-weight: 400;
}

.day-cell.selected {
  outline: 2px solid #3498db;
  outline-offset: -2px;
  background: rgba(52, 152, 219, 0.12) !important;
  z-index: 1;
}

body.select-mode .day-cell:not(.empty) {
  cursor: crosshair;
}

body.select-mode .day-cell:not(.empty):hover {
  background: rgba(52, 152, 219, 0.06);
}

body.select-mode .day-cell.sunday:hover {
  filter: none;
}

.day-number {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--title-color);
  margin-bottom: 0.15rem;
}

.day-content {
  font-size: 0.6rem;
  line-height: 1.35;
}

.day-content .lesson-title {
  font-weight: 600;
  font-size: 0.65rem;
  color: var(--title-color);
}

.day-content .lesson-verse {
  font-style: italic;
  font-size: 0.55rem;
  color: #777;
  margin-top: 0.1rem;
}

.day-content .q-label,
.day-content .e-label {
  font-weight: 600;
  color: var(--title-color);
}

.day-content .encouragement-text {
  margin-top: 0.2rem;
}

/* ─── BPQ Section ───────────────────────────────────────────── */
#bpq-section {
  margin-top: 1rem;
  text-align: center;
  padding: 0.75rem;
  background: var(--sunday-tint);
  border-radius: 8px;
  border: 1px solid var(--cell-border);
}

#bpq-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--title-color);
  margin-bottom: 0.25rem;
}

#bpq-text {
  font-size: 0.9rem;
  line-height: 1.4;
}

/* ─── Editable text fields ──────────────────────────────────── */
.editable-text {
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background 0.15s;
}

.editable-text:hover {
  background: rgba(0,0,0,0.05);
}

.editable-text.placeholder::before {
  content: attr(data-placeholder);
  color: #aaa;
  font-style: italic;
}

.editable-text:focus {
  outline: 2px solid var(--title-color);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ─── Rich Text Toolbar ──────────────────────────────────── */
#rt-toolbar {
  position: fixed;
  z-index: 150;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.5rem;
  background: #333;
  color: #fff;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  font-size: 0.75rem;
}

#rt-toolbar button {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

#rt-toolbar button:hover {
  background: rgba(255,255,255,0.3);
}

#rt-size-label {
  min-width: 2em;
  text-align: center;
  font-size: 0.7rem;
}

/* ─── Additional Context ────────────────────────────────────── */
#additional-context-section {
  margin-top: 1rem;
  padding: 0.75rem;
  background: rgba(255,255,255,0.5);
  border-radius: 8px;
  border: 1px dashed var(--cell-border);
}

#additional-context-section label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: #666;
}

#additional-context {
  width: 100%;
  font-family: var(--body-font);
  font-size: 0.8rem;
  padding: 0.5rem;
  border: 1px solid var(--cell-border);
  border-radius: 4px;
  resize: vertical;
}

/* ─── Settings Panel ────────────────────────────────────────── */
#settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 200;
}

#settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  height: 100vh;
  background: #fff;
  z-index: 201;
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

#settings-panel.visible {
  transform: translateX(0);
}

#settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #eee;
}

#settings-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

#settings-header button {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #666;
  padding: 0 0.25rem;
}

#settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}

#settings-body fieldset {
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 1rem;
}

#settings-body legend {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--title-color);
  padding: 0 0.4rem;
}

#settings-body label {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  font-weight: 500;
  color: #555;
  margin-bottom: 0.6rem;
  gap: 0.2rem;
}

#settings-body input[type="text"],
#settings-body input[type="password"],
#settings-body select {
  padding: 0.4rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: var(--body-font);
}

#settings-body input[type="color"] {
  width: 100%;
  height: 32px;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 2px;
  cursor: pointer;
}

#settings-body input[type="file"] {
  font-size: 0.75rem;
}

.font-select {
  font-size: 0.8rem;
}

.small-btn {
  background: #eee;
  border: 1px solid #ccc;
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: var(--body-font);
}

.small-btn:hover {
  background: #ddd;
}

.action-btn {
  background: var(--header-bg);
  color: white;
  border: none;
  padding: 0.5rem 1.25rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: var(--body-font);
  width: 100%;
}

.action-btn:hover {
  filter: brightness(1.1);
}

/* ─── Modals ────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 300;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  padding: 1.5rem;
  z-index: 301;
  width: 90%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--title-color);
}

.modal label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  font-weight: 500;
  color: #555;
  margin-bottom: 0.75rem;
  gap: 0.25rem;
}

.modal label .hint {
  font-weight: 400;
  font-size: 0.7rem;
  color: #999;
}

.modal input[type="text"],
.modal textarea {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: var(--body-font);
  resize: vertical;
}

.modal-buttons {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-buttons .action-btn {
  flex: 1;
  width: auto;
}

/* ─── Help Modal ───────────────────────────────────────────── */
#help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 300;
}

#help-modal {
  max-width: 620px;
  width: 92%;
  max-height: 85vh;
}

#help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

#help-header h3 {
  font-size: 1.1rem;
  color: var(--title-color);
  margin: 0;
}

#help-header button {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #666;
  padding: 0 0.25rem;
  line-height: 1;
}

#help-header button:hover {
  color: #333;
}

#help-content {
  overflow-y: auto;
  max-height: calc(85vh - 5rem);
  padding-right: 0.5rem;
}

#help-content section {
  margin-bottom: 1.25rem;
}

#help-content section:last-child {
  margin-bottom: 0;
}

#help-content h4 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--title-color);
  margin-bottom: 0.4rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--cell-border);
}

#help-content p {
  font-size: 0.8rem;
  line-height: 1.55;
  margin-bottom: 0.5rem;
}

#help-content ul,
#help-content ol {
  font-size: 0.8rem;
  line-height: 1.55;
  margin-bottom: 0.5rem;
  padding-left: 1.5rem;
}

#help-content li {
  margin-bottom: 0.3rem;
}

#btn-help {
  font-weight: 700;
  min-width: 2rem;
}

/* ─── Regenerate Button ────────────────────────────────────── */
.regenerate-btn {
  margin-top: 0.25rem;
}

/* ─── Color Picker Modal ──────────────────────────────────── */
#color-picker-modal {
  position: fixed;
  z-index: 500;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  min-width: 220px;
  top: 100px;
  left: 100px;
}

#color-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background: #444;
  color: #fff;
  border-radius: 8px 8px 0 0;
  cursor: grab;
  user-select: none;
}

#color-picker-header:active {
  cursor: grabbing;
}

#color-picker-label {
  font-size: 0.8rem;
  font-weight: 500;
}

#btn-close-color-picker {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.2rem;
  line-height: 1;
}

#btn-close-color-picker:hover {
  color: #ccc;
}

#color-picker-body {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#color-picker-input {
  width: 100%;
  height: 40px;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 2px;
  cursor: pointer;
}

#color-picker-only-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: #555;
  cursor: pointer;
}

#color-picker-only-label input[type="checkbox"] {
  margin: 0;
}

body.color-mode *:not(#toolbar):not(#toolbar *):not(#color-picker-modal):not(#color-picker-modal *):not(.no-print):not(.no-print *) {
  cursor: crosshair !important;
}

body.color-mode .day-cell:not(.empty):hover,
body.color-mode .editable-text:hover {
  outline: 2px dashed var(--title-color);
  outline-offset: -1px;
}

#btn-color-mode.active {
  background: rgba(255,255,255,0.35);
  border-color: rgba(255,255,255,0.7);
}

/* ─── Clear Confirm Modal ──────────────────────────────────── */
#clear-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 400;
}

#clear-confirm-modal {
  z-index: 401;
  max-width: 420px;
}

#clear-confirm-modal h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
  color: var(--title-color);
}

#clear-confirm-modal p {
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 1rem;
  color: #555;
}

.hidden {
  display: none !important;
}

/* ─── Print Styles ──────────────────────────────────────────── */
@media print {
  @page {
    size: 11in 8.5in;
    margin: 0.2in;
  }

  body {
    background-image: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  #toolbar,
  #settings-overlay,
  #settings-panel,
  #modal-overlay,
  #help-overlay,
  #clear-confirm-overlay,
  .modal,
  #additional-context-section,
  .no-print {
    display: none !important;
  }

  #calendar-page {
    padding: 0;
    max-width: none;
    width: 10.6in;
    height: 8.1in;
    display: flex;
    flex-direction: column;
  }

  #calendar-header {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  #cal-year {
    font-size: 0.7rem;
  }

  #cal-month-title {
    font-size: 2rem;
  }

  #verse-label {
    font-size: 0.55rem;
  }

  #calendar-grid {
    border-radius: 0;
  }

  .day-header {
    padding: 0.15rem 0.15rem;
    font-size: 0.55rem;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .day-cell {
    min-height: 0;
    padding: 0.1rem 0.2rem;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .day-number {
    font-size: 0.55rem;
    margin-bottom: 0.05rem;
  }

  .day-content {
    font-size: 0.5rem;
    line-height: 1.25;
  }

  .day-content .lesson-title {
    font-size: 0.55rem;
  }

  .day-content .lesson-verse {
    font-size: 0.45rem;
  }

  .day-cell.sunday {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  #bpq-section {
    margin-top: 0.1in;
    padding: 0.15rem 0.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  #bpq-label {
    font-size: 0.55rem;
    margin-bottom: 0.1rem;
  }

  .day-cell.other-month {
    opacity: 0.45;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .editable-text:hover {
    background: transparent;
  }

  .editable-text:focus {
    outline: none;
  }

  .editable-text.placeholder::before {
    display: none;
  }
}
