/* Ministry Scheduler: warm paper, deep ink, one oxblood accent. Series supply the colour. */

:root {
  --bg: #f5f0e6;
  --surface: #fffdf8;
  --surface-2: #efe8db;
  --ink: #1f1a14;
  --muted: #6b6155;
  --line: #e2d9c9;
  --line-strong: #c9bca6;
  --accent: #8a3b32;
  --accent-ink: #fffdf8;
  --accent-soft: #f1e1dc;
  --warn: #9a5b00;
  --warn-soft: #fbedd3;
  --danger: #a1352b;
  --focus: #2f6a57;
  --focus-soft: #dcefe6;
  --shadow: 0 1px 2px rgb(60 40 20 / .06), 0 6px 20px rgb(60 40 20 / .06);
  --radius: 10px;
  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16130f; --surface: #1f1b16; --surface-2: #29231d; --ink: #f1eadf; --muted: #a89d8e;
    --line: #342d25; --line-strong: #4a4035; --accent: #e08a7d; --accent-ink: #1f1410; --accent-soft: #3a2420;
    --warn: #e9b35a; --warn-soft: #3a2c12; --danger: #f08b7f; --focus: #7cc9ab; --focus-soft: #1d3a30;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16130f; --surface: #1f1b16; --surface-2: #29231d; --ink: #f1eadf; --muted: #a89d8e;
  --line: #342d25; --line-strong: #4a4035; --accent: #e08a7d; --accent-ink: #1f1410; --accent-soft: #3a2420;
  --warn: #e9b35a; --warn-soft: #3a2c12; --danger: #f08b7f; --focus: #7cc9ab; --focus-soft: #1d3a30;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--body); min-height: 100vh;
}
h1, h2, h3 { font-family: var(--display); font-weight: 650; letter-spacing: -.01em; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark { width: 30px; height: 30px; color: var(--accent); flex: none; }
.eyebrow { display: block; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.church { display: block; font-family: var(--display); font-size: 19px; font-weight: 650; line-height: 1.2; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  padding: 8px 14px; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); background: var(--surface-2); }
.tabs a[aria-current="page"] { color: var(--accent-ink); background: var(--accent); }

.month-nav { display: flex; align-items: center; gap: 8px; padding: 22px 24px 4px; max-width: 1280px; margin: 0 auto; }
.month-nav h1 { font-size: clamp(26px, 4vw, 36px); min-width: 0; margin-right: 4px; order: -1; flex: 1; }

.view { max-width: 1280px; margin: 0 auto; padding: 12px 24px 64px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px;
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface);
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 14px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-size: 22px; line-height: 1; display: inline-grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.small { width: 28px; height: 28px; font-size: 16px; }

label { display: grid; gap: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); font-size: 15px; color: var(--ink); font-weight: 400;
}
textarea { resize: vertical; }
input[type="color"] { padding: 2px; width: 52px; flex: none; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.inline-field { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.inline-field select, .inline-field input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; display: grid; gap: 12px; }
legend { padding: 0 6px; font-family: var(--display); font-weight: 650; font-size: 16px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0 16px; }
.toolbar-group, .row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.section-title { font-size: 22px; margin: 36px 0 12px; }

.chip {
  display: inline-block; padding: 2px 10px; margin: 2px 4px 2px 0; border-radius: 999px;
  background: var(--surface-2); font-size: 13.5px; white-space: nowrap;
}
.chip.focus { background: var(--focus-soft); color: var(--focus); font-weight: 600; box-shadow: inset 0 0 0 1px var(--focus); }
.chip.conflict { background: var(--warn-soft); color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.need { display: inline-block; font-size: 12.5px; color: var(--warn); font-weight: 600; margin: 2px 0; }
.flag {
  display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--warn-soft); color: var(--warn);
}
.series-tag {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 4px;
}
.series-tag::before { content: ''; width: 8px; height: 8px; border-radius: 2px; background: var(--series); }

.empty { text-align: center; padding: 56px 16px; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.empty h2 { font-size: 22px; margin-bottom: 6px; }
.empty p { color: var(--muted); margin: 0; }

/* ---------- schedule matrix ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; vertical-align: top; padding: 12px 14px; border-bottom: 1px solid var(--line); }
thead th {
  font-family: var(--body); font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); background: var(--surface-2); white-space: nowrap;
}
tbody tr:last-child > * { border-bottom: 0; }
tbody tr[data-action] { cursor: pointer; }
tbody tr[data-action]:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.matrix .when { min-width: 150px; font-weight: 400; }
.when .date { display: block; font-family: var(--display); font-size: 17px; font-weight: 650; }
.when .meta { display: block; font-size: 13px; color: var(--muted); }
.when .series-tag, .when .flag { display: flex; width: fit-content; }

/* ---------- preaching ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 18px; }
.legend-item {
  display: flex; align-items: center; gap: 12px; text-align: left; cursor: pointer;
  padding: 10px 16px 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  border-left: 6px solid var(--series);
}
.legend-item:hover { background: var(--surface-2); }
.legend-item strong { display: block; font-family: var(--display); font-size: 17px; }
.legend-item small { color: var(--muted); font-size: 13px; }
.legend-item .swatch { display: none; }
.swatch { width: 14px; height: 14px; border-radius: 4px; background: var(--series); flex: none; }

.calendar {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px;
  box-shadow: var(--shadow);
}
.cal-head {
  background: var(--surface-2); padding: 8px 10px; font-size: 12px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.cal-cell { background: var(--surface); min-height: 108px; padding: 6px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cal-cell.out { background: var(--bg); }
.cal-day { font-size: 13px; color: var(--muted); padding: 0 4px; font-variant-numeric: tabular-nums; }
.cal-cell.today .cal-day {
  color: var(--accent-ink); background: var(--accent); border-radius: 999px; width: fit-content; padding: 0 8px; font-weight: 600;
}
.sermon {
  display: grid; gap: 3px; text-align: left; cursor: pointer; width: 100%; min-width: 0;
  padding: 10px 10px 10px 12px; border: 0; border-radius: 8px;
  background: color-mix(in srgb, var(--series) 12%, var(--surface)); border-top: 5px solid var(--series);
}
.sermon:hover { background: color-mix(in srgb, var(--series) 20%, var(--surface)); }
.sermon-series { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; color: color-mix(in srgb, var(--series) 75%, var(--ink)); overflow-wrap: anywhere; }
.sermon-title { font-family: var(--display); font-size: 16px; font-weight: 650; line-height: 1.2; overflow-wrap: anywhere; }
.sermon-scripture { font-size: 13px; font-style: italic; overflow-wrap: anywhere; }
.sermon-preacher { font-size: 13px; color: var(--muted); }
.sermon em { font-style: normal; color: var(--muted); font-weight: 400; }

.plan td.band { box-shadow: inset 5px 0 0 var(--series); white-space: nowrap; }

/* ---------- ministers ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.person {
  display: grid; gap: 8px; align-content: start; text-align: left; cursor: pointer;
  padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
}
.person:hover { border-color: var(--line-strong); }
.person-name { font-family: var(--display); font-size: 19px; font-weight: 650; }
.person-meta { display: grid; gap: 2px; font-size: 13px; color: var(--muted); }
.person-meta strong { color: var(--ink); }

/* ---------- series ---------- */
.series-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.series-card {
  padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  border-top: 6px solid var(--series); box-shadow: var(--shadow);
}
.series-card header { display: flex; gap: 12px; align-items: flex-start; }
.series-card header > div { flex: 1; min-width: 0; }
.series-card header .swatch { margin-top: 6px; }
.series-card h2 { font-size: 21px; }
.series-card p { margin: 4px 0 0; }
.series-card > p { margin-top: 12px; }
.sermon-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; font-size: 14px; }
.sermon-list li { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 6px; border-top: 1px solid var(--line); }

/* ---------- settings ---------- */
.settings { display: grid; gap: 16px; max-width: 780px; }
.panel { padding: 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); display: grid; gap: 14px; justify-items: start; }
.panel > label, .panel > .row3, .panel > div { width: 100%; }
.panel h2 { font-size: 20px; }
.panel p { margin: 0; }
.role-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; flex-wrap: wrap; }
.role-row > input { flex: 1 1 200px; width: auto; }
.role-row .inline-field input { width: 72px; }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; width: auto !important; }
.seg { border: 0; background: var(--surface); padding: 8px 16px; cursor: pointer; min-height: 40px; }
.seg + .seg { border-left: 1px solid var(--line-strong); }
.seg.on { background: var(--accent); color: var(--accent-ink); }

.row2, .row3 { display: grid; gap: 12px; }
.row2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* ---------- dialog ---------- */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgb(0 0 0 / .25);
}
dialog.wide { width: min(820px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(20 14 8 / .45); }
.dialog-form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dialog-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 18px 20px 12px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 22px; }
.dialog-head p { margin: 2px 0 0; }
.dialog-body { padding: 16px 20px; overflow-y: auto; display: grid; gap: 14px; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }
.dialog-actions .spacer { flex: 1; }

.sermon-fields { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.roles { display: grid; gap: 10px; }
.role-field { display: grid; grid-template-columns: 170px 1fr; gap: 10px; align-items: start; }
.role-label { font-weight: 600; font-size: 14px; padding-top: 9px; }
.role-selects { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.conflicts:empty { display: none; }
.conflicts { padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.conflicts ul { margin: 4px 0 0; padding-left: 18px; }

.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--ink); font-weight: 400; cursor: pointer; }
.add-date { display: flex; gap: 8px; }
.mini-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 14px; }
.mini-list li { display: flex; align-items: center; gap: 10px; }
.mini-list li > span:first-child { min-width: 110px; color: var(--muted); }
.color-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.swatch-btn { width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line-strong); background: var(--series); cursor: pointer; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(560px, calc(100vw - 32px)); padding: 12px 18px; border-radius: 10px;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow); transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: var(--warn); color: #fff; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .app-header { padding: 12px 16px; position: static; }
  .tabs { width: 100%; margin: 0 -4px; }
  .month-nav { padding: 18px 16px 0; }
  .view { padding: 8px 16px 48px; }
  .row2, .row3 { grid-template-columns: 1fr; }
  .role-field { grid-template-columns: 1fr; gap: 4px; }
  .role-label { padding-top: 0; }

  /* tables become stacked cards */
  .table-wrap { border: 0; background: none; box-shadow: none; overflow: visible; }
  table, tbody, tr, th, td { display: block; }
  thead { display: none; }
  tbody tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; box-shadow: var(--shadow); }
  th, td { border: 0; padding: 6px 14px; }
  .matrix .when { padding-top: 12px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
  td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
  tbody tr > :last-child { padding-bottom: 12px; }
  .plan tr { border-left: 6px solid var(--series); }
  .plan td.band { box-shadow: none; padding-top: 12px; }

  /* the calendar would be too cramped; the plan list below carries the month */
  .calendar { display: none; }
}

@media print {
  .app-header .tabs, .month-nav button, .toolbar, .hint, .toast, dialog { display: none !important; }
  body { background: #fff; }
  .table-wrap, .calendar { box-shadow: none; }
}

/* Invisible first button so Enter in a dialog saves (see openDialog in app.js) */
.enter-saves { position: absolute; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; pointer-events: none; overflow: hidden; }
