/*
 * Application UI (not the printed program — that lives in layouts/).
 * Plain, roomy, and high contrast. The people using this are often doing it
 * once, under time pressure, on a laptop they don't love.
 */

:root {
    --ink:      #18181b;
    --ink-soft: #52525b;
    --muted:    #71717a;
    --line:     #e4e4e7;
    --bg:       #fafafa;
    --card:     #ffffff;
    --brand:    #2563eb;
    --brand-dk: #1d4ed8;
    --btn:      #475569;   /* slate — a plain button is still a visible shape */
    --btn-dk:   #334155;
    --go:       #15803d;   /* green — the payoff action: print it */
    --go-dk:    #166534;
    --danger:   #b91c1c;
    --danger-dk:#991b1b;
    --ok:       #15803d;
    --warn-bg:  #fef3c7;
    --warn-br:  #fcd34d;
    --warn-ink: #78350f;
    --radius:   8px;
    --shadow:   0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .3rem; }

a { color: var(--brand); }
a:hover { color: var(--brand-dk); }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.inline { display: inline; }
.grow  { flex: 1 1 auto; }
.dot   { color: var(--line); margin: 0 .4rem; }

/* ---- Layout ---- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
body.narrow .wrap { max-width: 560px; }
body.wide   .wrap { max-width: 1280px; }
body.editor-page .wrap { max-width: 1500px; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; padding: .7rem 1.25rem;
    background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.topnav { display: flex; align-items: center; gap: 1rem; }
.topnav a { color: var(--ink-soft); text-decoration: none; font-size: .93rem; }
.topnav a:hover { color: var(--ink); }
.topnav a.btn { color: #fff; }

.foot {
    padding: 2rem 1rem; text-align: center;
    color: var(--muted); font-size: .85rem;
    border-top: 1px solid var(--line);
}
.foot a { color: var(--muted); }

.page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.page-head p { margin: 0; }

/* ---- Cards ---- */
.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 1.25rem; margin-bottom: 1.25rem;
}
.card-form { margin-top: 2rem; }
.card-form h1 { margin-bottom: 1.25rem; }

/* ---- Forms ---- */
label { display: block; }
label > span, .f-label {
    display: block; font-size: .82rem; font-weight: 600;
    color: var(--ink-soft); margin-bottom: .25rem;
}

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=time], input[type=number], input[type=search], select, textarea {
    width: 100%; padding: .5rem .6rem;
    border: 1px solid #d4d4d8; border-radius: 6px;
    font: inherit; font-size: .95rem; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand);
}
input:disabled { background: #f4f4f5; color: var(--muted); }
textarea { resize: vertical; }
.narrow-input { max-width: 100px; }

.stack > * + * { margin-top: 1rem; }
.stack small { display: block; margin-top: .25rem; }

.check { display: flex; align-items: center; gap: .5rem; }
.check input { width: auto; }
.check span { margin: 0; font-weight: 400; color: var(--ink); font-size: .92rem; }

.row-form { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.row-form button { margin-bottom: 1px; }

.filters {
    display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap;
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 1rem; margin-bottom: 1.5rem;
}

/* ---- Buttons ----
 *
 * Rule: a button is a filled, coloured shape. Never white on white.
 *
 * The old default was #f4f4f5 on a #fff card with a 1px grey border — which is
 * to say, invisible. "Change design" and "Full preview" were the two controls
 * people needed most and the two hardest to find on the page. A control that
 * has to be hunted for is broken however tidy it looks.
 *
 * Three jobs, three colours, and nothing else:
 *   btn          slate   — do a thing
 *   btn-primary  blue    — do the main thing here
 *   btn-go       green   — the payoff (print it)
 *   btn-danger   red     — destroy something
 */
.btn {
    display: inline-block; font: inherit; font-size: .9rem; font-weight: 600;
    padding: .5rem .95rem; border: 1px solid transparent; border-radius: 6px;
    background: var(--btn); color: #fff; cursor: pointer;
    text-decoration: none; text-align: center; white-space: nowrap;
}
.btn:hover  { background: var(--btn-dk); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }

.btn-primary { background: var(--brand); }
.btn-primary:hover { background: var(--brand-dk); color: #fff; }

.btn-go { background: var(--go); }
.btn-go:hover { background: var(--go-dk); color: #fff; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dk); color: #fff; }

.btn-sm { font-size: .82rem; padding: .35rem .7rem; }
.btn-lg { font-size: 1rem; padding: .7rem 1.4rem; }
.btn-block { display: block; width: 100%; }

.linklike {
    background: none; border: 0; padding: 0; cursor: pointer;
    font: inherit; font-size: .93rem; color: var(--ink-soft);
}
.linklike:hover { color: var(--ink); text-decoration: underline; }

/* The little ↑ ↓ × on a block. Small, but still a shape you can see.
   A pale chip on a white card measures 1.5:1 against its background — which
   is the same invisibility as the old white buttons, just smaller. */
.icon-btn {
    background: #64748b; border: 1px solid #475569; border-radius: 5px;
    width: 26px; height: 26px; line-height: 1; cursor: pointer;
    color: #fff; font-size: 1rem; font-weight: 700; padding: 0;
}
.icon-btn:hover { background: #334155; color: #fff; }
.icon-danger { background: #dc2626; border-color: #b91c1c; color: #fff; }
.icon-danger:hover { background: #991b1b; color: #fff; }

/* ---- Messages ---- */
.flash {
    padding: .7rem 1.25rem; font-size: .92rem;
    border-bottom: 1px solid var(--line);
}
.flash-ok    { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-info  { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

.alert { padding: .7rem .9rem; border-radius: 6px; font-size: .9rem; margin-bottom: 1rem; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warn  { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-br); }

.chip {
    display: inline-block; font-size: .75rem; font-weight: 600;
    padding: .15rem .5rem; border-radius: 999px;
    background: #f4f4f5; color: var(--ink-soft); border: 1px solid var(--line);
}
.chip-ok   { background: #ecfdf5; color: var(--ok); border-color: #a7f3d0; }
.chip-warn { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-br); }

/* ---- Program list ---- */
.prog-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.prog-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; padding: .9rem 1.1rem; flex-wrap: wrap;
}
.prog-row + .prog-row { border-top: 1px solid var(--line); }
.prog-row:hover { background: #fafafa; }
.prog-title { font-weight: 600; color: var(--ink); text-decoration: none; font-size: 1.02rem; }
.prog-title:hover { color: var(--brand); }
.prog-meta { font-size: .82rem; color: var(--muted); margin-top: .15rem; }
.prog-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

/* ---- Gallery ---- */
.gallery {
    display: grid; gap: 1.25rem;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
.lay-card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
    display: flex; flex-direction: column;
}
.lay-card.is-current { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.lay-thumb { position: relative; background: #f4f4f5; border-bottom: 1px solid var(--line); }
.lay-thumb img { display: block; width: 100%; height: auto; }
.lay-thumb-empty {
    display: flex; align-items: center; justify-content: center;
    height: 150px; color: var(--muted); font-size: .85rem;
}
.lay-badge {
    position: absolute; top: .5rem; right: .5rem;
    background: var(--brand); color: #fff; font-size: .7rem; font-weight: 600;
    padding: .15rem .5rem; border-radius: 999px;
}
.lay-body { padding: .9rem; display: flex; flex-direction: column; gap: .5rem; flex: 1 1 auto; }
.lay-body p { margin: 0; flex: 1 1 auto; }
.lay-form { display: flex; flex-direction: column; gap: .5rem; }
.lay-paper span { font-size: .75rem; }

/* ---- Landing ---- */
.hero { text-align: center; padding: 2.5rem 0 2rem; }
.hero h1 { font-size: 2.2rem; letter-spacing: -.02em; }
.lead { font-size: 1.1rem; color: var(--ink-soft); max-width: 46ch; margin: 0 auto 1.5rem; }
.hero-cta { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; }

.how { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin: 2.5rem 0; }
.how-step { text-align: center; }
.how-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand); color: #fff; font-weight: 700; margin-bottom: .6rem;
}
.showcase { margin-top: 3rem; }
.showcase h2 { text-align: center; margin-bottom: 1.25rem; }
.gallery-sm { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

/* ---- Editor ----
 *
 * Two columns:
 *   left  — every form card, one column, all the same width
 *   right — the preview in a sticky rail, its actions across the top, always
 *           in view while you fill in the form
 *
 * The preview used to live in the page flow. Because a booklet preview is
 * ~1500px tall, every reload after adding or moving a section jumped the
 * whole window down to it — Geoffrey's "flashes and bounces to the bottom".
 * A sticky rail sitting outside the flow removes the cause: the form scrolls,
 * the preview stays put.
 */
.editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 560px);
    gap: 1.25rem;
    align-items: start;
}
@media (max-width: 1150px) { .editor { grid-template-columns: 1fr; } }

.ed-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-width: 0;          /* let the order-of-service card's fields shrink to fit */
}
.ed-form > .card { margin-bottom: 0; }

/* Each region card gets its own soft tint so the sections are easy to tell
   apart at a glance. Kept pale — the white input fields and blocks inside
   still stand out against it. The settings card stays plain white.
   Region cards are the <section> elements, so nth-of-type cycles through
   them without counting the settings <div>. */
.ed-form > section.card:nth-of-type(6n+1) { background: #eef4fb; }  /* blue   */
.ed-form > section.card:nth-of-type(6n+2) { background: #eef8f0; }  /* green  */
.ed-form > section.card:nth-of-type(6n+3) { background: #fdf6ec; }  /* amber  */
.ed-form > section.card:nth-of-type(6n+4) { background: #f6eefa; }  /* violet */
.ed-form > section.card:nth-of-type(6n+5) { background: #fdeef0; }  /* rose   */
.ed-form > section.card:nth-of-type(6n+6) { background: #ecf7f8; }  /* teal   */

/* The sticky preview rail.
 *
 * It needs a real HEIGHT, not just a max-height: with only a cap it shrinks to
 * its content (the short action bar) and the preview has nothing to fill, so
 * the whole program renders in a 150px sliver. A viewport-tall rail gives the
 * preview the room, and sticky keeps it there as the form scrolls past. */
.ed-rail {
    position: sticky;
    top: 1rem;
    align-self: start;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    height: calc(100vh - 2rem);
}
@media (max-width: 1150px) {
    /* Stacked: preview first, and not sticky — there is nothing to stick to. */
    .ed-rail { position: static; height: auto; order: -1; }
}

.ed-titlerow { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }

/* Left-justified, and the button sits right against the design name it
   changes — not pushed to the far edge by space-between. */
.ed-designrow {
    display: flex; align-items: center; justify-content: flex-start;
    gap: .6rem; padding-top: .9rem; border-top: 1px solid var(--line); flex-wrap: wrap;
}
.ed-designrow strong { font-size: 1.02rem; }
.ed-designrow .ed-paper { margin-left: .2rem; }
.ed-options {
    display: flex; gap: .75rem; flex-wrap: wrap;
    padding-top: .9rem; margin-top: .9rem; border-top: 1px solid var(--line);
}
.ed-options label { min-width: 150px; flex: 1 1 auto; }

.region-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.region-head p { margin: 0; }

.block { border: 1px solid var(--line); border-radius: 6px; margin-bottom: .8rem; background: #fff; }
.block-over { opacity: .6; border-style: dashed; }
.block-head {
    display: flex; align-items: center; gap: .5rem;
    padding: .45rem .7rem; background: #fafafa;
    border-bottom: 1px solid var(--line); border-radius: 6px 6px 0 0;
}
.block-name { font-size: .82rem; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.block-tools { margin-left: auto; display: flex; gap: .2rem; }
.block-body { padding: .8rem; display: flex; flex-direction: column; gap: .7rem; }

.region-add { display: flex; gap: .5rem; align-items: center; margin-top: .3rem; }
.region-add select { max-width: 260px; }

/* ---- Repeating rows ----
 *
 * The header names every column once. Without it the only clue is a
 * placeholder, and a placeholder in a narrow box truncates — "Number" reading
 * as "Numt" is how hymn numbers ended up typed into hymn titles.
 *
 * min-width on every field is the other half: a row must wrap rather than
 * crush. Six unreadable boxes on one line is worse than six readable boxes on
 * two.
 */
.f-list .list-rows { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .5rem; }

.list-head {
    display: flex; gap: .35rem; align-items: end;
    padding-bottom: .25rem; margin-bottom: .35rem;
    border-bottom: 1px solid var(--line);
}
.list-head .col {
    font-size: .72rem; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--muted);
    line-height: 1.2;
}
.list-head .row-grip, .list-head .row-del { visibility: hidden; }

.list-row { display: flex; gap: .35rem; align-items: center; }
.row-grip { flex: 0 0 auto; width: 10px; color: #d4d4d8; cursor: grab; font-size: .8rem; user-select: none; letter-spacing: -2px; }

.list-row .col, .list-head .col { flex: 1 1 auto; min-width: 0; }
.list-row .col-sm, .list-head .col-sm { flex: 0 1 96px;  min-width: 72px; }
.list-row .col-md, .list-head .col-md { flex: 1 1 150px; min-width: 110px; }
.list-row .col-lg, .list-head .col-lg { flex: 2 1 200px; min-width: 130px; }

.list-row input, .list-row select, .list-row textarea { font-size: .88rem; padding: .35rem .45rem; }

/* Narrow screens: let the row wrap onto a second line rather than crush every
   field into uselessness. The header only makes sense while they line up. */
@media (max-width: 900px) {
    .list-head { display: none; }
    .list-row  { flex-wrap: wrap; padding: .4rem; border: 1px solid var(--line); border-radius: 6px; }
    .list-row .col-sm, .list-row .col-md, .list-row .col-lg { flex: 1 1 140px; }
}
/* Slate until you reach for it, red when you do — visible either way. Twelve
   red squares down a schedule would shout; twelve invisible ones would hide. */
.row-del {
    flex: 0 0 auto; width: 24px; height: 24px; padding: 0;
    border: 1px solid #475569; background: #64748b; border-radius: 4px;
    color: #fff; cursor: pointer; font-size: 1rem; font-weight: 700; line-height: 1;
}
.row-del:hover { background: #dc2626; border-color: #b91c1c; color: #fff; }

/* Photo field */
.f-image { display: flex; flex-direction: column; gap: .4rem; }
.img-current { max-width: 190px; }
.img-current img { display: block; width: 100%; height: auto; border-radius: 4px; border: 1px solid var(--line); }
.img-empty {
    display: flex; align-items: center; justify-content: center;
    height: 80px; border: 1px dashed #d4d4d8; border-radius: 4px;
    color: var(--muted); font-size: .8rem;
}
.img-actions { display: flex; gap: .4rem; }

/* The actions sit across the top of the rail, above the preview. Because the
   whole rail is sticky, they ride along and stay in reach. */
.ed-actions {
    flex: 0 0 auto;
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); padding: .55rem .7rem;
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.ed-actions #saveBtn { flex: 0 0 auto; }
.ed-actions #saveHint { flex: 1 1 100%; margin: .1rem 0 0 .1rem; }
#saveHint.is-unsaved { color: var(--warn-ink); font-weight: 600; }

/* The preview fills the rest of the rail's height and never scrolls itself —
   the program inside scales to fit both directions (see preview.php). */
.ed-preview {
    flex: 1 1 auto;
    min-height: 0;
    background: #f4f4f5;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.ed-preview iframe {
    display: block; width: 100%; height: 100%;
    border: 0; background: #f4f4f5;
}
@media (max-width: 1150px) {
    /* No viewport-height rail to fill when stacked; give it a sensible box. */
    .ed-preview { height: 70vh; }
}

/* ---- Modal ---- */
.modal {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(24,24,27,.55);
    display: flex; align-items: center; justify-content: center; padding: 1rem;
}
body.modal-open { overflow: hidden; }
.modal-box {
    background: #fff; border-radius: var(--radius);
    width: 100%; max-width: 680px; max-height: 85vh;
    display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: .8rem 1rem; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; }
.modal-body { padding: 1rem; overflow-y: auto; }
.upload-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.upload-row input[type=file] { flex: 1 1 auto; font-size: .85rem; }

.photo-grid { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.photo-item {
    padding: 0; border: 2px solid var(--line); border-radius: 6px;
    background: none; cursor: pointer; overflow: hidden; aspect-ratio: 1;
}
.photo-item:hover { border-color: var(--brand); }
.photo-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
