:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4c1d95;
  --primary-soft: #ede9fe;
  --red: #dc2626;
  --blue: #2563eb;
  --green: #15803d;
  --amber: #92400e;
  --orange-bg: #ffedd5;
  --purple-bg: #f3e8ff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .6; }

.app-shell { max-width: 1500px; margin: 0 auto; padding: 18px; }
.header, .panel, .calendar-shell, .editor, .summary { background: var(--panel); border: 1px solid #e2e8f0; border-radius: 16px; box-shadow: 0 8px 20px rgba(15, 23, 42, .05); }
.header { padding: 18px; margin-bottom: 14px; display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.eyebrow { margin: 0 0 4px; color: var(--primary); font-size: 13px; font-weight: 800; }
h1 { margin: 0; font-size: 27px; }
.help { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.input, select, textarea { border: 1px solid #cbd5e1; border-radius: 10px; background: white; padding: 8px 10px; min-height: 38px; }
textarea { width: 100%; resize: vertical; }
.btn { border: 1px solid #cbd5e1; border-radius: 10px; padding: 8px 12px; background: white; color: #334155; font-weight: 700; }
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn.primary:hover { background: #3b0764; }
.btn.soft { background: var(--primary-soft); border-color: #ddd6fe; color: var(--primary); }
.btn.danger { color: #b91c1c; border-color: #fecaca; }
.btn.small { padding: 5px 8px; font-size: 12px; border-radius: 8px; }

.calendar-shell { padding: 14px; margin-bottom: 14px; border-color: #94a3b8; }
.print-title { border-top: 4px solid black; border-bottom: 4px solid black; padding: 12px; text-align: center; margin-bottom: 10px; }
.print-title h2 { margin: 0; color: #2e1065; font-size: 26px; }
.notice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; color: #475569; font-size: 12px; padding: 0 0 10px; }
.calendar-scroll { overflow-x: auto; border: 1px solid #94a3b8; border-radius: 12px; }
.calendar { min-width: 980px; display: grid; grid-template-columns: repeat(7, 1fr); background: #cbd5e1; gap: 1px; }
.weekday { background: #e0e7ff; padding: 9px; text-align: center; font-size: 14px; font-weight: 900; }
.weekday.sun { color: var(--red); }
.weekday.sat { color: var(--blue); }
.day-cell { min-height: 148px; background: white; border: 0; padding: 8px; text-align: left; vertical-align: top; transition: .15s; }
.day-cell:hover { background: #fffbeb; }
.day-cell.out { background: #f1f5f9; color: #94a3b8; }
.day-cell.today { outline: 3px solid #8b5cf6; outline-offset: -3px; }
.day-head { display: flex; justify-content: space-between; align-items: center; gap: 4px; margin-bottom: 4px; }
.day-number { font-weight: 900; font-size: 14px; color: #0f172a; }
.day-number.sun { color: var(--red); }
.day-number.sat { color: var(--blue); }
.day-week { margin-left: 2px; font-size: 11px; font-weight: 600; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 2px 7px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.purple { background: #f3e8ff; color: #6b21a8; }
.badge.amber { background: #fef3c7; color: #92400e; }
.item { font-size: 12px; line-height: 1.28; margin: 3px 0; word-break: keep-all; overflow-wrap: anywhere; }
.item.auto { color: #1e293b; }
.item.manual { color: #6b21a8; font-weight: 800; }
.item.dawn { color: #0f172a; }
.item.assistant { color: #be185d; font-weight: 800; }
.item.midweek { color: #1d4ed8; }
.item.sunday { color: #334155; font-weight: 700; }
.item.period { background: var(--orange-bg); color: var(--amber); border: 1px solid #fdba74; padding: 4px 6px; border-radius: 8px; font-weight: 800; }

.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 14px; align-items: start; }
.panel, .summary, .editor { padding: 16px; }
.panel h2, .summary h2, .editor h2 { margin: 0 0 8px; font-size: 18px; }
.panel ul { margin: 8px 0 0; padding-left: 20px; color: #334155; font-size: 14px; }

.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.week-day { min-height: 110px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 8px; }
.week-day h4 { margin: 0 0 7px; display: flex; justify-content: space-between; font-size: 13px; }
.week-day ul { list-style: none; padding: 0; margin: 0; }
.week-day li { font-size: 12px; line-height: 1.25; margin: 4px 0; color: #334155; }

.editor-section { border-top: 1px solid #e2e8f0; padding-top: 14px; margin-top: 14px; }
.editor label { display: block; font-size: 12px; font-weight: 800; color: #475569; margin-bottom: 4px; }
.editor .row { display: grid; gap: 8px; margin-bottom: 10px; }
.editor .two { grid-template-columns: 1fr 1fr; }
.mode-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #f1f5f9; padding: 4px; border-radius: 12px; margin-bottom: 10px; }
.mode-tabs button { border: 0; border-radius: 9px; padding: 8px; font-weight: 800; background: transparent; color: #64748b; }
.mode-tabs button.active { background: white; color: var(--primary); box-shadow: 0 1px 4px rgba(15, 23, 42, .08); }
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 7px; }
.list-card { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 8px; display: flex; justify-content: space-between; gap: 8px; }
.list-card.manual { background: #faf5ff; border-color: #e9d5ff; }
.list-card.editing { outline: 2px solid #a855f7; }
.list-title { font-size: 13px; font-weight: 800; margin: 3px 0; }
.list-meta { font-size: 11px; color: #64748b; }
.actions { display: flex; flex-direction: column; gap: 4px; }
.warning { background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; color: #92400e; padding: 10px; font-size: 13px; }

.settings { display: none; margin-bottom: 14px; }
.settings.open { display: block; }
.settings-grid { display: grid; gap: 18px; }
.setting-block { border: 1px solid #e2e8f0; border-radius: 14px; padding: 14px; }
.setting-block h3 { margin: 0 0 10px; color: var(--primary); font-size: 15px; }
.form-grid { display: grid; gap: 8px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-4 { grid-template-columns: 1fr 100px 100px auto; }
.minister-row { display: grid; grid-template-columns: 1fr 80px 80px 90px; gap: 8px; border: 1px solid #e2e8f0; border-radius: 10px; padding: 8px; margin-bottom: 6px; }
.minister-row.inactive { background: #f1f5f9; opacity: .7; }
.rotation-card { border: 1px solid #e2e8f0; border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.rotation-card h4 { margin: 0 0 2px; }
.rotation-member { display: flex; justify-content: space-between; gap: 8px; align-items: center; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 7px; margin: 6px 0; }
.rotation-member.inactive { opacity: .55; }

.mobile-editor-toggle { display: none; }
.hidden { display: none !important; }

@media (max-width: 1024px) {
  .grid-main { grid-template-columns: 1fr; }
  .week-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .notice-grid { grid-template-columns: 1fr; }
  .cols-4, .minister-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .app-shell { padding: 10px; }
  h1 { font-size: 22px; }
  .header { align-items: stretch; }
  .toolbar { align-items: stretch; }
  .toolbar > * { flex: 1 1 45%; }
  .week-grid { grid-template-columns: 1fr; }
}

@page { size: A4 landscape; margin: 8mm; }
@media print {
  html, body { width: 297mm; min-height: 210mm; background: white; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .no-print { display: none !important; }
  .app-shell { max-width: none; padding: 0; }
  .calendar-shell { box-shadow: none; border: none; padding: 0; margin: 0; }
  .calendar-scroll { overflow: visible; border-radius: 0; }
  .calendar { min-width: 0; }
  .day-cell { min-height: 101px; padding: 5px; }
  .item { font-size: 9.6px; line-height: 1.15; margin: 2px 0; }
  .badge { font-size: 8px; padding: 1px 5px; }
  .day-number { font-size: 12px; }
  .weekday { padding: 6px; }
  .print-title h2 { font-size: 24px; }
  .notice-grid { font-size: 10px; padding-bottom: 6px; }
}

/* v0.4.0 upload-readiness additions */
.day-cell.selected { outline: 3px solid #f59e0b; outline-offset: -3px; background: #fffbeb; }
.badge.red { background: #fee2e2; color: #991b1b; }
.validation-panel { background: #ffffff; border: 1px solid #e2e8f0; border-radius: 16px; box-shadow: 0 8px 20px rgba(15, 23, 42, .05); padding: 14px 16px; margin-bottom: 14px; }
.validation-panel.ok { border-color: #bbf7d0; background: #f0fdf4; }
.validation-panel.warning { border-color: #fde68a; background: #fffbeb; }
.validation-panel.error { border-color: #fecaca; background: #fef2f2; }
.validation-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.validation-list { margin: 10px 0 0; padding-left: 18px; display: grid; gap: 7px; font-size: 13px; }
.validation-list li.warning { color: #92400e; }
.validation-list li.error { color: #991b1b; }
.validation-list div { margin-top: 2px; color: #475569; }

/* v0.4.0 publish/share refinements */
.print-church { text-align: center; margin: 0 0 4px; color: #475569; font-size: 14px; font-weight: 800; }
.monthly-notice { border: 1px solid #ddd6fe; background: #f5f3ff; color: #4c1d95; border-radius: 10px; padding: 8px 10px; margin: 0 0 10px; font-size: 12px; white-space: pre-wrap; }
.monthly-manuals { border-top: 1px solid #e2e8f0; margin-top: 18px; padding-top: 16px; }
.published-view .day-cell { cursor: default; }
.published-view .day-cell:hover { background: white; }
.published-view .day-cell.out:hover { background: #f1f5f9; }
.published-view .calendar-shell { border-color: #c4b5fd; }
@media print {
  .print-church { font-size: 12px; }
  .monthly-notice { font-size: 10px; padding: 5px 7px; margin-bottom: 6px; }
}

/* v0.8.0 holiday / liturgical manual controls */
.badge.white { background: #ffffff; color: #334155; border: 1px solid #cbd5e1; }
.badge.black { background: #111827; color: #f8fafc; }
.item.holiday { color: #b91c1c; font-weight: 900; }
.setting-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.setting-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 1px solid #e2e8f0; background: #f8fafc; border-radius: 10px; padding: 8px; font-size: 13px; }
@media (max-width: 1024px) {
  .setting-list li { align-items: flex-start; }
}

/* v0.9.0 lunar / preset controls */
.lunar-label { margin: -2px 0 4px; color: #64748b; font-size: 10px; font-weight: 700; }
@media print {
  .lunar-label { font-size: 8px; margin-bottom: 2px; }
}

/* v1.0.0 setup wizard and mobile editing refinements */
.setup-wizard {
  background: linear-gradient(135deg, #ffffff 0%, #faf5ff 100%);
  border: 1px solid #ddd6fe;
  border-radius: 16px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .05);
  padding: 16px;
  margin-bottom: 14px;
}
.setup-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.setup-head h2 { margin: 0; font-size: 20px; color: #2e1065; }
.setup-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.setup-step {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  border-radius: 12px;
  padding: 10px;
}
.setup-step.done { border-color: #bbf7d0; background: #f0fdf4; }
.setup-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  font-weight: 900;
  flex: 0 0 auto;
}
.setup-step.done .setup-check { background: #dcfce7; color: #166534; }
.setup-step strong { display: block; font-size: 13px; color: #0f172a; }
.setup-step p { margin: 2px 0 0; font-size: 12px; color: #64748b; line-height: 1.35; }
.setup-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
@media (max-width: 1024px) {
  .setup-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main .editor { order: -1; }
}
@media (max-width: 640px) {
  .setup-head { flex-direction: column; }
  .setup-steps { grid-template-columns: 1fr; }
  .setup-actions .btn { flex: 1 1 100%; }
  .editor { border-color: #c4b5fd; }
  .calendar-shell { padding: 10px; }
}
