/* Matesův zpěvník — screen UI.
 *
 * The print stylesheet (songbook.css) is a separate, deliberately untouched file:
 * it defines how a song *renders*, and both the PDF and the on-screen previews
 * include it verbatim so what you see is what gets printed. Everything here is
 * the chrome around that — navigation, lists, forms, collections.
 *
 * Theming is token-driven. Light values live on :root, dark ones are overridden
 * in two places (the prefers-color-scheme media query and [data-theme="dark"])
 * so the OS setting and the manual toggle both work.
 */

/* ---------------------------------------------------------------- tokens -- */
:root {
    color-scheme: light;

    /* Ink & surfaces */
    --bg: #f6f5f3;
    --bg-elevated: #ffffff;
    --surface: #ffffff;
    --surface-2: #f2f1ee;
    --surface-3: #e9e7e3;
    --border: #e2dfd9;
    --border-strong: #cfcac1;

    --text: #191714;
    --text-muted: #6b665e;
    --text-faint: #97918a;

    /* Brand — the same crimson the chords are printed in. */
    --accent: #c00014;
    --accent-hover: #9d0010;
    --accent-soft: #fdeced;
    --accent-contrast: #ffffff;

    --ok: #1b7f4d;
    --ok-soft: #e6f5ec;
    --warn: #8a5a00;
    --warn-soft: #fdf3e0;
    --danger: #b3261e;
    --danger-soft: #fdecea;

    /* Shape & motion */
    --radius-sm: 7px;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(24, 20, 14, .06), 0 1px 3px rgba(24, 20, 14, .05);
    --shadow: 0 2px 4px rgba(24, 20, 14, .04), 0 8px 24px rgba(24, 20, 14, .07);
    --shadow-lg: 0 4px 8px rgba(24, 20, 14, .05), 0 18px 48px rgba(24, 20, 14, .12);
    --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);

    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, "Cascadia Mono", monospace;

    --header-h: 60px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #16151a;
        --bg-elevated: #1e1d23;
        --surface: #1e1d23;
        --surface-2: #26252c;
        --surface-3: #302f38;
        --border: #322f39;
        --border-strong: #46424f;

        --text: #ece9e4;
        --text-muted: #a29d97;
        --text-faint: #7b766f;

        --accent: #ff5c6b;
        --accent-hover: #ff8089;
        --accent-soft: #3a1a20;
        --accent-contrast: #1a0e10;

        --ok: #57cf92;
        --ok-soft: #16301f;
        --warn: #e3b667;
        --warn-soft: #33270f;
        --danger: #ff7b72;
        --danger-soft: #3a1a17;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow: 0 2px 4px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
        --shadow-lg: 0 4px 8px rgba(0, 0, 0, .35), 0 18px 48px rgba(0, 0, 0, .5);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #16151a;
    --bg-elevated: #1e1d23;
    --surface: #1e1d23;
    --surface-2: #26252c;
    --surface-3: #302f38;
    --border: #322f39;
    --border-strong: #46424f;

    --text: #ece9e4;
    --text-muted: #a29d97;
    --text-faint: #7b766f;

    --accent: #ff5c6b;
    --accent-hover: #ff8089;
    --accent-soft: #3a1a20;
    --accent-contrast: #1a0e10;

    --ok: #57cf92;
    --ok-soft: #16301f;
    --warn: #e3b667;
    --warn-soft: #33270f;
    --danger: #ff7b72;
    --danger-soft: #3a1a17;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 2px 4px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 4px 8px rgba(0, 0, 0, .35), 0 18px 48px rgba(0, 0, 0, .5);
}

/* ------------------------------------------------------------- baseline -- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 650; letter-spacing: -.011em; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* --------------------------------------------------------------- header -- */
.app-header {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 1rem;
    height: var(--header-h);
    padding: 0 clamp(.85rem, 3vw, 1.75rem);
    background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
    backdrop-filter: saturate(1.6) blur(12px);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: inline-flex; align-items: center; gap: .55rem;
    font-family: var(--font-display);
    font-size: 1.12rem; font-weight: 700; letter-spacing: -.015em;
    color: var(--text); white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    display: grid; place-items: center;
    width: 30px; height: 30px; border-radius: 9px;
    background: linear-gradient(150deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #6b1020));
    color: var(--accent-contrast); font-size: .95rem;
    box-shadow: var(--shadow-sm);
}
@media (max-width: 560px) { .brand-text { display: none; } }

.nav { display: flex; align-items: center; gap: .15rem; margin-left: .5rem; }
.nav a {
    padding: .4rem .7rem; border-radius: var(--radius-sm);
    color: var(--text-muted); font-weight: 550; font-size: .9rem;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 720px) { .nav a { padding: .4rem .5rem; font-size: .85rem; } }

.header-end { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.avatar {
    display: grid; place-items: center;
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--surface-3); color: var(--text);
    font-size: .78rem; font-weight: 700; text-transform: uppercase;
}

/* --------------------------------------------------------------- layout -- */
.page { max-width: 1180px; margin: 0 auto; padding: clamp(1rem, 3vw, 2rem) clamp(.85rem, 3vw, 1.75rem) 6rem; }
.page.narrow { max-width: 720px; }
.page.wide { max-width: 1400px; }

.page-head { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head .subtitle { margin: .2rem 0 0; color: var(--text-muted); font-size: .93rem; }
.page-head .spacer { margin-left: auto; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: clamp(1rem, 2.5vw, 1.4rem); }
.card + .card { margin-top: 1rem; }
.card-title {
    font-size: .74rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
    color: var(--text-faint); margin: 0 0 .75rem;
}

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------- buttons -- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .5rem .9rem;
    font: inherit; font-size: .9rem; font-weight: 600; line-height: 1.2;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    background: var(--surface-2); color: var(--text);
    cursor: pointer; white-space: nowrap;
    transition: background .13s ease, border-color .13s ease, transform .06s ease, box-shadow .13s ease;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--accent-contrast); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); }

.btn-outline { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: transparent; border-color: var(--border-strong); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-lg { padding: .65rem 1.2rem; font-size: .98rem; }
.btn-icon { padding: .42rem; width: 32px; height: 32px; }

/* ------------------------------------------------------------- controls -- */
input[type=text], input[type=url], input[type=email], input[type=password],
input[type=search], input[type=number], textarea, select {
    width: 100%;
    padding: .5rem .7rem;
    font: inherit; font-size: .93rem;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    transition: border-color .13s ease, box-shadow .13s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--accent); box-shadow: var(--ring);
}
input[type=file] {
    width: 100%; font-size: .88rem; color: var(--text-muted);
    padding: .45rem; border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm); background: var(--surface-2);
}
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 1.05em; height: 1.05em; }

/* A select that sits in a toolbar rather than in a stacked form. */
.inline-select { width: auto; max-width: 14rem; font-size: .87rem; padding: .35rem 1.6rem .35rem .55rem; }

.field { display: block; margin-bottom: 1rem; }
.field > .label, .field > label {
    display: block; margin-bottom: .3rem;
    font-size: .82rem; font-weight: 650; color: var(--text-muted);
}
.field .help { margin: .35rem 0 0; font-size: .82rem; color: var(--text-faint); }
.field-errors { margin: .35rem 0 0; padding: 0; list-style: none; color: var(--danger); font-size: .84rem; }

.checkline { display: flex; align-items: center; gap: .5rem; font-size: .9rem; cursor: pointer; }

.body-input {
    font-family: var(--font-mono); font-size: .82rem; line-height: 1.35;
    white-space: pre; overflow-x: auto; tab-size: 4;
}

/* ---------------------------------------------------------------- notes -- */
.note { padding: .6rem .85rem; border-radius: var(--radius-sm); font-size: .89rem; border: 1px solid transparent; }
.note + .note { margin-top: .5rem; }
.note-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.note-err, .note-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.note-warn, .note-warning { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.note-info { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }

.messages { position: fixed; top: calc(var(--header-h) + .6rem); right: 1rem; z-index: 60; display: grid; gap: .5rem; max-width: min(26rem, calc(100vw - 2rem)); }
.messages .note { background: var(--bg-elevated); box-shadow: var(--shadow-lg); animation: slide-in .22s ease both; }
@keyframes slide-in { from { opacity: 0; transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .001ms !important; transition-duration: .001ms !important; } }

.empty-state {
    display: grid; place-items: center; gap: .5rem; text-align: center;
    padding: 3.5rem 1.5rem; color: var(--text-muted);
    border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface);
}
.empty-state .big { font-size: 2rem; }

/* ------------------------------------------------------- search toolbar -- */
.toolbar { display: grid; gap: .75rem; margin-bottom: 1rem; }

.searchbar { display: flex; gap: .5rem; flex-wrap: wrap; }
.search-field { position: relative; flex: 1 1 18rem; min-width: 0; }
.search-field input {
    padding-left: 2.2rem; height: 42px; border-radius: 999px;
    background: var(--surface); box-shadow: var(--shadow-sm);
}
.search-field .search-icon {
    position: absolute; left: .75rem; top: 50%; transform: translateY(-50%);
    width: 17px; height: 17px; color: var(--text-faint); pointer-events: none;
}
.search-field .clear-search {
    position: absolute; right: .45rem; top: 50%; transform: translateY(-50%);
    border: 0; background: transparent; color: var(--text-faint);
    cursor: pointer; font-size: 1.1rem; line-height: 1; padding: .25rem .4rem; border-radius: 50%;
}
.search-field .clear-search:hover { background: var(--surface-3); color: var(--text); }

.sort-select { flex: 0 0 auto; width: auto; height: 42px; border-radius: 999px; background: var(--surface); padding-right: 2rem; }

/* Alphabet index — a horizontal scroller on narrow screens rather than a wrap. */
.alphabet { display: flex; gap: .15rem; overflow-x: auto; padding-bottom: .2rem; scrollbar-width: thin; }
.alphabet a {
    flex: 0 0 auto; min-width: 1.7rem; padding: .22rem .3rem;
    text-align: center; font-size: .84rem; font-weight: 600;
    color: var(--text-muted); border-radius: var(--radius-sm);
}
.alphabet a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.alphabet a[aria-current="true"] { background: var(--accent); color: var(--accent-contrast); }
.alphabet a.is-empty { opacity: .32; pointer-events: none; }

.result-line { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; font-size: .87rem; color: var(--text-muted); }
.result-line .spacer { margin-left: auto; }

/* ------------------------------------------------------------ song list -- */
/* No `overflow: hidden` here, however tempting for the rounded corners: it would
   make the list its own scrollport and the sticky letter heads below would pin
   against *it* rather than the page, pushing each heading a header's height down
   into the rows it labels. The corners are rounded on the edge children instead. */
.song-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.song-list > :first-child { border-radius: var(--radius) var(--radius) 0 0; }
.song-list > :last-child { border-radius: 0 0 var(--radius) var(--radius); }

.song-row { display: flex; align-items: center; gap: .75rem; padding: .1rem .35rem .1rem .85rem; border-top: 1px solid var(--border); transition: background .1s ease; }
.song-row:first-child { border-top: 0; }
.song-row:hover { background: var(--surface-2); }
.song-row.is-selected { background: var(--accent-soft); }
.song-row.is-selected:hover { background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent) 6%); }

/* The label carries the row's whole hit area so a click anywhere toggles it. */
.song-row .pick { display: flex; align-items: center; gap: .75rem; flex: 1 1 auto; min-width: 0; padding: .55rem 0; cursor: pointer; }
.song-row .names { display: flex; align-items: baseline; gap: .5rem; min-width: 0; flex-wrap: wrap; }
.song-row .title { font-weight: 600; color: var(--text); }
.song-row .author { font-size: .86rem; color: var(--text-faint); }
.song-row .flags { display: inline-flex; gap: .3rem; font-size: .8rem; color: var(--text-faint); }

.song-row .row-actions { display: inline-flex; gap: .15rem; margin-left: auto; opacity: 0; transition: opacity .12s ease; }
/* Destructive action reads as destructive, but only once you reach for it — a
   permanently red word in every row would shout over the song titles. */
.song-row .row-delete:hover { background: var(--danger-soft); color: var(--danger); }
.song-row:hover .row-actions, .song-row:focus-within .row-actions { opacity: 1; }
@media (hover: none) { .song-row .row-actions { opacity: 1; } }

/* Sticky letter separators keep your place while scrolling a long list. */
.letter-head {
    position: sticky; top: var(--header-h); z-index: 5;
    padding: .3rem .85rem; font-size: .74rem; font-weight: 700; letter-spacing: .09em;
    color: var(--text-faint); text-transform: uppercase;
    background: var(--surface-2); border-top: 1px solid var(--border);
}
.song-list .letter-head:first-child { border-top: 0; }

/* ----------------------------------------------------------- pagination -- */
.pagination { display: flex; align-items: center; justify-content: center; gap: .35rem; margin-top: 1.25rem; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 2.1rem; padding: .35rem .55rem; text-align: center;
    font-size: .87rem; font-weight: 600; border-radius: var(--radius-sm); color: var(--text-muted);
}
.pagination a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.pagination .current { background: var(--accent); color: var(--accent-contrast); }
.pagination .gap { color: var(--text-faint); font-weight: 400; }

/* ------------------------------------------------------- selection tray -- */
/* Fixed bottom bar summarising the cross-page selection. Hidden (and inert)
   while nothing is picked, so an empty list is not crowded by it. */
.tray {
    position: fixed; left: 50%; bottom: 1rem; z-index: 50;
    transform: translate(-50%, calc(100% + 2rem));
    display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
    max-width: min(64rem, calc(100vw - 1.5rem));
    padding: .6rem .6rem .6rem 1rem;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: 999px; box-shadow: var(--shadow-lg);
    transition: transform .22s cubic-bezier(.2, .8, .3, 1);
}
.tray.is-open { transform: translate(-50%, 0); }
/* The tray hosts several small forms side by side; each lays out inline. */
.tray form { display: flex; align-items: center; gap: .5rem; }
.tray .count { font-weight: 700; font-size: .93rem; white-space: nowrap; }
.tray .count b { color: var(--accent); }
.tray .divider { width: 1px; align-self: stretch; background: var(--border); }
@media (max-width: 620px) {
    .tray { border-radius: var(--radius-lg); left: .75rem; right: .75rem; transform: translateY(calc(100% + 2rem)); max-width: none; }
    .tray.is-open { transform: translateY(0); }
    .tray .count { width: 100%; }
}

/* ---------------------------------------------------------- collections -- */
.collection-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; }

.collection-card {
    display: flex; flex-direction: column; gap: .35rem;
    padding: 1.05rem 1.1rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
    transition: transform .13s ease, box-shadow .13s ease, border-color .13s ease;
}
.collection-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); text-decoration: none; }
.collection-card .name { font-family: var(--font-display); font-size: 1.12rem; font-weight: 700; color: var(--text); }
.collection-card .desc { font-size: .87rem; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.collection-card .meta { margin-top: auto; padding-top: .5rem; font-size: .81rem; color: var(--text-faint); }

.collection-card.is-new { border-style: dashed; align-items: center; justify-content: center; text-align: center; color: var(--text-muted); min-height: 8rem; }

.pill {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .12rem .5rem; border-radius: 999px;
    font-size: .76rem; font-weight: 650;
    background: var(--surface-3); color: var(--text-muted);
}
.pill-accent { background: var(--accent-soft); color: var(--accent); }

/* Ordered member list of one collection, with move/remove controls. */
.member-list { list-style: none; margin: 0; padding: 0; }
.member { display: flex; align-items: center; gap: .7rem; padding: .45rem .5rem .45rem .75rem; border-top: 1px solid var(--border); }
.member:first-child { border-top: 0; }
.member:hover { background: var(--surface-2); }
.member .pos { min-width: 1.9rem; font-variant-numeric: tabular-nums; font-size: .82rem; color: var(--text-faint); text-align: right; }
.member .names { min-width: 0; flex: 1 1 auto; }
/* Titles read as list content, not as a wall of links — the accent is saved for
   hover, matching how the library list renders the same songs. */
.member .title { font-weight: 600; color: var(--text); }
.member .title:hover { color: var(--accent); }
.member .author { font-size: .85rem; color: var(--text-faint); }
.member .member-actions { display: inline-flex; gap: .1rem; margin-left: auto; }

/* ------------------------------------------------------- paper / detail -- */
/* A sheet that hosts the print stylesheet's markup, one column on screen. */
.paper {
    background: #fff; color: #000;
    padding: clamp(1rem, 4vw, 12mm);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow-x: auto;
}
.paper .songs { column-count: 1; }
/* The songbook markup is black-on-white by design — keep it that way in dark
   mode too, so the preview still shows what will come out of the printer. */
.paper :is(.song-title, .song-author, .txt, .verse-num, .chorus-label, .toc-entry) { color: #000; }

.preview-sticky { position: sticky; top: calc(var(--header-h) + 1rem); }

.detail-toolbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.detail-toolbar .spacer { margin-left: auto; }

/* ------------------------------------------------------------- auth box -- */
.auth-wrap { display: grid; place-items: center; min-height: calc(100vh - var(--header-h)); padding: 2rem 1rem 4rem; }
.auth-card { width: min(24rem, 100%); padding: 1.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.auth-card h1 { font-family: var(--font-display); font-size: 1.5rem; margin-bottom: .3rem; }
.auth-card .lede { color: var(--text-muted); font-size: .9rem; margin: 0 0 1.35rem; }
.auth-card .btn { width: 100%; }
.auth-alt { margin: 1.1rem 0 0; text-align: center; font-size: .88rem; color: var(--text-muted); }

/* Django's password-validator help text is a nested <ul>; make it readable. */
.field .help ul { margin: .25rem 0 0; padding-left: 1.1rem; }

/* ------------------------------------------------------------- printing -- */
@media print {
    .app-header, .tray, .messages, .toolbar, .pagination, .detail-toolbar { display: none !important; }
    body { background: #fff; }
    .paper { border: 0; box-shadow: none; padding: 0; }
}
