:root {
  --bg: #f3f4f6; --card: #ffffff; --ink: #1f2937; --muted: #6b7280; --line: #d1d5db;
  --accent: #0070c0; --accent-ink: #ffffff; --danger: #b91c1c; --soft: #eef3fa;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 15px/1.45 "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); }

header.top { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header.top h1 { font-size: 17px; margin: 0; flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top .actions { display: flex; gap: 6px; }
h1 .t-short { display: none; }
main { max-width: 1100px; margin: 0 auto; padding: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.card h3 { margin: 0; font-size: 16px; }
.card h3.sub { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }
.card h4 { margin: 8px 0 4px; font-size: 13px; }
.card.tab { border-top: 3px solid var(--accent); border-top-left-radius: 0; border-top-right-radius: 0; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.fields.days { grid-template-columns: repeat(auto-fit, minmax(108px, 1fr)); }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.f.inline { flex-direction: row; align-items: center; gap: 6px; }
input[type=text], input[type=date], input[type=time], input[type=number], input[type=search], select, textarea {
  font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); min-width: 0; width: 100%;
}
textarea { resize: vertical; }
.pickrow { display: flex; gap: 6px; }

.tabs { display: flex; gap: 4px; align-items: flex-end; overflow-x: auto; }
.tabs button { flex: 1 0 auto; display: flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 14px; font-weight: 700; padding: 10px 12px; border: 1px solid var(--line); border-bottom: none; border-radius: 10px 10px 0 0; background: #e9ecf1; color: #4b5563; cursor: pointer; white-space: nowrap; }
.tabs button:hover { background: #dde2ea; color: var(--ink); }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabs .ico { display: none; }
.tabs .ico svg { display: block; width: 24px; height: 24px; }

.btn { font: inherit; text-decoration: none; display: inline-block; line-height: normal; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; white-space: nowrap; }
.btn.ghost { background: #fff; color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon { border: none; background: transparent; font-size: 18px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; flex: 0 0 auto; }
.icon.del:hover { color: var(--danger); }

.docbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.docbar .spacer { flex: 1 1 auto; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.row.line { flex-wrap: nowrap; margin-top: 4px; }
.row.line input { flex: 1 1 auto; width: auto; }
.row.search { gap: 6px; }
.row.search input[type=search] { flex: 2 1 220px; }
.row.search select { flex: 1 1 130px; width: auto; }
.grow { flex: 1 1 auto; }
.muted { color: var(--muted); margin: 6px 0; }
.small { font-size: 12px; }

.section { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin: 10px 0; background: #fcfdff; }
.section-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.section-head .section-label { font-weight: 700; color: var(--accent); flex: 1 1 160px; width: auto; }
.section-head select { flex: 0 1 190px; width: auto; }
.section-head input[type=date], .section-head input[type=time] { flex: 0 1 150px; width: auto; }
.section.practice .section-head input[type=text] { flex: 1 1 150px; width: auto; }
.prow .ability { flex: 0 0 66px; }
/* zero flex-basis so the columns line up down the list whatever the title length */
.prow .grow { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .note { flex: 1 1 0; }
#add-section { flex: 1 1 220px; width: auto; max-width: 320px; }
.rows { margin-top: 6px; }
.prow { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 4px 0; border-top: 1px solid #eef0f3; }
.prow:first-child { border-top: none; }
.prow.on { background: var(--soft); border-radius: 6px; }
.prow.done .r-ref, .prow.done .grow { opacity: .55; text-decoration: line-through; }
.prow .num { width: 18px; text-align: right; color: var(--muted); font-size: 12px; }
.prow .time { width: 46px; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }
.prow select { flex: 0 1 150px; width: auto; }
.prow .note { flex: 1 1 130px; width: auto; }
.prow .mins { width: 62px; flex: 0 0 auto; }
.prow .slotlabel { width: 70px; flex: 0 0 auto; }
.prow .unit { font-size: 12px; color: var(--muted); }
.prow .tick { width: auto; }
.prow.silence { color: var(--muted); font-size: 13px; }

.reffield { display: flex; gap: 6px; align-items: center; flex: 2 1 260px; min-width: 0; }
.reffield .ref { width: 86px; flex: 0 0 auto; font-weight: 700; }
.reffield .find { flex: 0 0 auto; }
.hymn-title { flex: 1 1 auto; min-width: 0; font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hymn-title.warn { color: var(--danger); }

.crew { display: grid; gap: 6px; }
.crow { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(100px, 1.2fr) minmax(100px, 1.2fr); gap: 6px; align-items: center; }
.crow .crole { font-size: 13px; font-weight: 600; }
.pblock { margin-bottom: 10px; }
.grid7 { display: grid; grid-template-columns: 58px repeat(7, minmax(0, 1fr)); gap: 4px; align-items: center; }
.grid7 .glabel { font-size: 12px; color: var(--muted); }
.grid7 input { padding: 4px 5px; font-size: 13px; }

.results { margin-top: 8px; max-height: 62vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.result { display: flex; gap: 8px; align-items: baseline; width: 100%; text-align: left; font: inherit; background: #fff; border: none; border-bottom: 1px solid #eef0f3; padding: 8px 10px; cursor: pointer; }
.result:hover { background: var(--soft); }
.result.open { background: var(--soft); }
.result .r-ref { flex: 0 0 62px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.result .r-title { flex: 1 1 auto; }
.results .editor { padding: 10px; background: #f8fafc; border-bottom: 1px solid #eef0f3; }

.pills { display: flex; gap: 4px; flex-wrap: wrap; }
.pill { font-size: 11px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--muted); white-space: nowrap; }
.pill.slot { border-color: #b9d4ef; color: #1d5c8f; }
.pill.season { border-color: #cdbfe8; color: #5b3fa0; }
.pill.organ { border-color: #cbd5e1; }
.pill.note { border-color: #f0d9a8; color: #8a5a00; }
/* an ability pill takes its colour from the rating itself, which the
   conductor sets in the Hymns tab */
.pill.ability.missing { font-style: italic; }
.btn.on { background: var(--accent); color: var(--accent-ink); }
#ability-editor { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 8px; }
#ability-editor input[type=color] { flex: 0 0 auto; width: 42px; height: 30px; padding: 0 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
#ability-editor .count { flex: 0 0 78px; text-align: right; }

.chips { gap: 5px; }
.chip { font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--muted); cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 20px 12px; z-index: 20; }
.picker-card { background: #fff; border-radius: 12px; width: min(680px, 100%); max-height: 90vh; display: flex; flex-direction: column; padding: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.28); }
.picker-head { display: flex; gap: 8px; align-items: center; }
.picker-card .results { flex: 1 1 auto; max-height: none; }

.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #14532d; background: #dcfce7; border: 1px solid #86efac; border-radius: 999px; padding: 2px 8px; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 20px); background: #111827; color: #fff; padding: 9px 14px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 30; max-width: 92vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---------------------------------------------------------------- phone
   The phone is a first-class device here, not a fallback: the tabs become a
   bar under the thumb, every target is big enough to hit while standing, and
   the hymn picker rises from the bottom like a native sheet. */
@media (max-width: 700px) {
  main { padding: 10px; padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  h1 .t-long { display: none; }
  h1 .t-short { display: inline; }
  header.top { padding: 8px 10px; }
  header.top .btn { padding: 13px 13px; }

  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; gap: 0;
    background: #fff; border-top: 1px solid var(--line); overflow: visible;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .1); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabs button {
    flex: 1 1 0; flex-direction: column; gap: 2px; min-width: 0; min-height: 58px;
    padding: 7px 2px 6px; font-size: 10.5px; font-weight: 600; white-space: nowrap;
    border: none; border-radius: 0; background: transparent; color: var(--muted);
  }
  .tabs button:hover { background: transparent; }
  .tabs button.active { background: transparent; color: var(--accent); }
  .tabs .ico { display: block; padding: 2px 12px; border-radius: 999px; line-height: 0; }
  .tabs button.active .ico { background: #dceafa; }
  .card.tab { border-top: 1px solid var(--line); border-radius: 10px; }
  .toast { bottom: calc(78px + env(safe-area-inset-bottom)); }

  /* 16px stops a phone browser zooming the page when a field is focused */
  input[type=text], input[type=date], input[type=time], input[type=number],
  input[type=search], select, textarea { font-size: 16px; padding: 9px 10px; }
  /* 44px tall, so a button can be hit while standing at a music stand */
  .btn, .btn.small { padding: 13px 15px; font-size: 14px; line-height: 1.25; }
  .chip { padding: 9px 14px; font-size: 14px; }
  .icon { padding: 8px 12px; font-size: 22px; min-width: 44px; min-height: 44px; }
  .prow .tick { width: 22px; height: 22px; }

  /* the hymn picker as a sheet off the bottom edge */
  .overlay { align-items: flex-end; padding: 0; }
  .picker-card {
    width: 100%; max-height: 88vh; border-radius: 14px 14px 0 0; padding: 12px 12px 0;
    padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -6px 24px rgba(0, 0, 0, .28);
  }
  .picker-card .results { border-left: none; border-right: none; border-radius: 0; }
  .result { padding: 12px 10px; }

  .crow { grid-template-columns: 1fr; gap: 3px; }
  .crow .crole { margin-top: 8px; }
  .grid7 { grid-template-columns: 52px repeat(3, minmax(0, 1fr)); }
  #ability-editor .count { flex: 0 0 auto; }

  /* a section's delete is pinned beside its name rather than wrapping below */
  .section-head { position: relative; padding-right: 46px; }
  .section-head > .del { position: absolute; right: -6px; top: 0; }
  .section-head select { flex: 1 1 auto; }
  .section.practice .section-head input[type=text] { flex: 1 1 100%; }

  /* each hymn gets three tidy lines, with the delete pinned to the top right
     instead of taking a line of its own */
  .prow { position: relative; padding: 7px 30px 7px 0; }
  .prow .del { position: absolute; right: -8px; top: 0; }
  .prow > select { flex: 1 1 auto; }
  .reffield { flex: 1 1 100%; flex-wrap: wrap; }
  .reffield .ref { width: 82px; }
  .hymn-title { flex: 1 1 120px; white-space: normal; }
  .prow .note { flex: 1 1 100%; }
  .prow .ability { flex: 0 0 auto; }
  .prow .grow { white-space: normal; }
  .results { max-height: 60vh; }
  .row.search select { flex: 1 1 45%; }
}
