/* listig — mobile-first styles */
:root {
    --ink: #1d2129;
    --muted: #6b7280;
    --line: #e5e7eb;
    --bg: #f4f6fa;
    --card: #ffffff;
    --accent: #2f6df0;
    --accent-soft: #eef3fe;
    --accent-ink: #ffffff;
    --danger: #d23b3b;
    --danger-soft: #fdeaea;
    --ok: #1a8a4f;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .07), 0 6px 20px rgba(16, 24, 40, .05);
}
@media (prefers-color-scheme: dark) {
    :root {
        --ink: #e7eaf0;
        --muted: #98a1b3;
        --line: #2c3240;
        --bg: #14161c;
        --card: #1d2129;
        --accent: #5b8cf5;
        --accent-soft: #233048;
        --accent-ink: #ffffff;
        --danger: #f07575;
        --danger-soft: #3a2326;
        --ok: #4cc98a;
        --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .25);
    }
}
* { box-sizing: border-box; }
/* The hidden attribute must always win, even over display:flex rules below. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}
a { color: var(--accent); }
button { font-family: inherit; }

/* Top bar */
.topbar {
    display: flex;
    align-items: baseline;
    gap: .6rem;
    padding: .85rem 1rem;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand {
    font-weight: 800; font-size: 1.25rem; text-decoration: none; color: var(--ink);
    letter-spacing: -.02em; display: inline-flex; align-items: center; gap: .4rem;
}
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.5rem; height: 1.5rem; border-radius: .45rem;
    background: var(--accent); color: var(--accent-ink);
    font-size: .95rem; font-weight: 800; transform: translateY(.1rem);
}
.tagline { color: var(--muted); font-size: .8rem; }

main { max-width: 680px; margin: 0 auto; padding: 1.1rem 1rem 6rem; }

/* Buttons */
.btn-add {
    background: var(--accent); color: var(--accent-ink); border: 0;
    padding: .6rem 1rem; border-radius: 10px; font-size: 1rem; font-weight: 600;
    cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-block;
    transition: filter .12s, transform .06s;
}
.btn-add:hover { filter: brightness(1.07); }
.btn-add:active { transform: translateY(1px); }
.btn-add.big { width: 100%; padding: .85rem; font-size: 1.05rem; margin-top: 1rem; }
.btn-ghost {
    background: transparent; border: 1px solid var(--line); color: var(--ink);
    padding: .45rem .75rem; border-radius: 9px; font-size: .85rem; cursor: pointer;
    transition: background .12s, border-color .12s;
}
.btn-ghost:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { background: var(--danger-soft); border-color: var(--danger); }

/* ---------------- Home ---------------- */
.home h1 { font-size: 2rem; line-height: 1.15; letter-spacing: -.025em; margin: .8rem 0 .4rem; }
.home h1 em { color: var(--accent); font-style: normal; }
.lead { color: var(--muted); margin-top: 0; font-size: 1.02rem; }
.create-box {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 1.2rem; box-shadow: var(--shadow); margin-top: 1.2rem;
}
.field span { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .95rem; }
.field input, .add-box input, .edit-row input, .edit-row textarea, #filter-input {
    width: 100%; padding: .7rem .8rem; border: 1px solid var(--line);
    border-radius: 10px; font-size: 1rem; font-family: inherit;
    background: var(--card); color: var(--ink);
}
.field input:focus, .add-box input:focus, .edit-row input:focus,
.edit-row textarea:focus, #filter-input:focus {
    outline: 2px solid var(--accent); border-color: var(--accent);
}
.cat-picker { border: 0; padding: 0; margin: 1rem 0 0; }
.cat-picker legend { font-weight: 600; font-size: .95rem; padding: 0; margin-bottom: .35rem; }
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
@media (min-width: 560px) { .cat-grid { grid-template-columns: repeat(3, 1fr); } }
.cat-opt input { position: absolute; opacity: 0; }
.cat-card {
    display: flex; flex-direction: column; align-items: center; gap: .15rem;
    padding: .8rem .5rem; border: 1.5px solid var(--line); border-radius: 12px;
    cursor: pointer; text-align: center; transition: border-color .12s, background .12s, transform .12s;
}
.cat-card:hover { transform: translateY(-1px); }
.cat-icon { font-size: 1.7rem; }
.cat-label { font-size: .85rem; font-weight: 600; }
.cat-hint { font-size: .68rem; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.cat-opt input:checked + .cat-card { border-color: var(--accent); background: var(--accent-soft); }
.cat-opt input:focus-visible + .cat-card { outline: 2px solid var(--accent); }

.group-toggle { display: block; margin-top: 1rem; cursor: pointer; }
.group-toggle input { position: absolute; opacity: 0; }
.gt-card {
    display: block; padding: .75rem .9rem; border: 1.5px solid var(--line);
    border-radius: 12px; transition: border-color .12s, background .12s;
}
.gt-title { display: block; font-weight: 600; font-size: .92rem; }
.gt-sub { display: block; color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.group-toggle input:checked + .gt-card { border-color: var(--accent); background: var(--accent-soft); }
.group-toggle input:focus-visible + .gt-card { outline: 2px solid var(--accent); }
#group-name-field { margin-top: .8rem; }

.my-lists { margin-top: 2.2rem; }
.my-lists h2 { font-size: 1.05rem; }
.my-lists ul { list-style: none; padding: 0; margin: 0; }
.ml-row { display: flex; align-items: stretch; gap: .4rem; margin-bottom: .5rem; }
.my-lists a {
    flex: 1; min-width: 0;
    display: flex; align-items: center; gap: .65rem; text-decoration: none; color: var(--ink);
    background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: .7rem .85rem;
    transition: border-color .12s, transform .12s;
}
.my-lists a:hover { border-color: var(--accent); transform: translateY(-1px); }
.my-lists .ml-icon { font-size: 1.3rem; }
.my-lists .ml-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.my-lists .ml-badges { flex: none; display: flex; }
.ml-view {
    background: var(--accent-soft); color: var(--accent); border-radius: 999px;
    font-size: .68rem; font-weight: 700; padding: .1rem .5rem; white-space: nowrap;
}
.my-lists .ml-cat { color: var(--muted); font-size: .8rem; margin-left: auto; flex: none; }
.ml-actions { display: flex; gap: .35rem; flex: none; align-items: center; }
.ml-btn {
    border: 1px solid var(--line); background: var(--card); border-radius: 9px;
    width: 38px; cursor: pointer; font-size: .95rem; color: var(--muted);
    display: flex; align-items: center; justify-content: center; align-self: stretch;
    transition: border-color .12s, background .12s; filter: grayscale(1); padding: 0;
}
.ml-btn:hover { border-color: var(--accent); background: var(--accent-soft); filter: none; }
.ml-btn.active { border-color: var(--accent); background: var(--accent-soft); filter: none; }
.archived { margin-top: 1rem; }
.archived summary {
    cursor: pointer; color: var(--muted); font-size: .9rem; font-weight: 600;
    padding: .3rem 0; user-select: none;
}
.archived ul { margin-top: .5rem; }
.archived .my-lists a, .archived a { opacity: .75; }

/* ---------------- List view ---------------- */
.list-head { margin-bottom: 1rem; }
.list-meta { display: flex; align-items: center; gap: .6rem; }
.cat-badge {
    display: inline-block; background: var(--accent-soft); color: var(--accent);
    padding: .2rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
}
.item-count { color: var(--muted); font-size: .8rem; }
.ro-badge {
    display: inline-block; background: var(--line); color: var(--muted);
    padding: .2rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
}
#list-name {
    font-size: 1.7rem; margin: .45rem 0 .4rem; letter-spacing: -.02em; cursor: text;
    border-radius: 6px; padding: 0 .15rem;
}
#list-name:hover { background: var(--accent-soft); }
#list-name:focus { outline: 2px solid var(--accent); background: none; }
.list-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.list-actions .btn-add { padding: .45rem .85rem; font-size: .9rem; }

.add-box { position: relative; margin-bottom: .9rem; }
.search-wrap { display: flex; gap: .5rem; position: relative; }
.search-wrap input { flex: 1; }
.search-note { font-size: .8rem; color: var(--muted); margin: .4rem 0 0; min-height: 1em; }

.suggestions {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
    list-style: none; margin: 0; padding: .25rem; background: var(--card);
    border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
    max-height: 60vh; overflow-y: auto;
}
.suggestions li {
    display: flex; align-items: center; gap: .6rem; padding: .5rem; border-radius: 8px; cursor: pointer;
}
.suggestions li:hover, .suggestions li.active { background: var(--accent-soft); }
.suggestions img, .sug-thumb {
    width: 36px; height: 48px; object-fit: cover; border-radius: 4px;
    background: var(--line); flex: none;
}
.sug-text { min-width: 0; display: flex; flex-direction: column; }
.sug-title { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sug-sub { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tools row (filter + sort) */
.list-tools { display: flex; gap: .5rem; margin-bottom: .9rem; }
.list-tools #filter-input { flex: 1; padding: .5rem .7rem; font-size: .92rem; }
.list-tools .btn-ghost { flex: none; }
.filter-miss { color: var(--muted); text-align: center; padding: 1rem; list-style: none; }

/* Items */
.items { list-style: none; padding: 0; margin: 0; }
.item {
    display: flex; gap: .75rem; align-items: flex-start; background: var(--card);
    border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem;
    margin-bottom: .6rem; box-shadow: var(--shadow);
    animation: item-in .18s ease-out;
}
@keyframes item-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .item { animation: none; }
    .cat-card:hover, .my-lists a:hover { transform: none; }
}
.item.dragging { opacity: .5; }
.item.drag-over { border-color: var(--accent); }
.item.done { opacity: .72; }
.item.done .item-title, .item.done .item-title a {
    text-decoration: line-through; color: var(--muted);
}
.item.done .item-thumb { filter: grayscale(.8); }

/* Check-off circle */
.check {
    width: 26px; height: 26px; flex: none; border-radius: 50%;
    border: 2px solid var(--line); background: var(--card); color: transparent;
    cursor: pointer; font-size: .85rem; line-height: 1; font-weight: 800;
    display: flex; align-items: center; justify-content: center; padding: 0;
    margin-top: .9rem; transition: border-color .12s, background .12s, color .12s;
}
.check:hover:not(:disabled) { border-color: var(--ok); color: var(--ok); }
.check.is-done { background: var(--ok); border-color: var(--ok); color: #fff; }
.check:disabled { cursor: default; }
.check:disabled:not(.is-done) { color: transparent; }
.item-thumb {
    width: 46px; height: 60px; flex: none; border-radius: 6px; object-fit: cover;
    background: var(--accent-soft); display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem; color: var(--muted); overflow: hidden;
}
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-body { flex: 1; min-width: 0; padding-top: .1rem; }
.item-title { font-weight: 600; overflow-wrap: anywhere; }
.item-title a { text-decoration: none; }
.item-title a:hover { text-decoration: underline; }
.item-sub { color: var(--muted); font-size: .85rem; }
.item-note { font-size: .85rem; margin-top: .25rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.item-tools { display: flex; flex-direction: column; gap: .25rem; flex: none; }
.icon-btn {
    border: 1px solid var(--line); background: var(--card); border-radius: 7px;
    width: 34px; height: 30px; cursor: pointer; font-size: .9rem; line-height: 1; color: var(--ink);
    display: flex; align-items: center; justify-content: center; padding: 0;
    transition: background .12s, border-color .12s;
}
.icon-btn:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.del { color: var(--danger); }
.icon-btn.del:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
.drag-handle { cursor: grab; touch-action: none; }

/* Inline edit */
.edit-row { flex: 1; display: flex; flex-direction: column; gap: .4rem; }
.edit-row textarea { min-height: 56px; resize: vertical; }
.edit-actions { display: flex; gap: .5rem; }
.edit-actions .btn-add { padding: .45rem .9rem; font-size: .9rem; }

/* ---------------- Group lists ---------------- */
.group-badge {
    display: inline-block; background: var(--accent-soft); color: var(--accent);
    padding: .2rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
}
.member-hint { color: var(--muted); font-size: .82rem; margin: 0 0 .5rem; }
.item-meta { color: var(--muted); font-size: .78rem; margin-top: .1rem; }

.mode-bar { display: flex; gap: .4rem; margin-bottom: .6rem; }
.mode-btn {
    flex: 1; padding: .5rem .6rem; border-radius: 10px; border: 1.5px solid var(--line);
    background: var(--card); color: var(--muted); font-size: .9rem; font-weight: 600; cursor: pointer;
    transition: border-color .12s, background .12s, color .12s;
}
.mode-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.rank-banner {
    display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between;
    background: var(--accent-soft); border: 1.5px solid var(--accent); border-radius: 11px;
    padding: .6rem .8rem; font-size: .85rem; margin-bottom: .8rem;
}
.rank-actions { display: flex; gap: .5rem; }
.rank-actions .btn-add { padding: .4rem .8rem; font-size: .85rem; }

.items.personal-mode .item { border-color: var(--accent); cursor: grab; }
.rank-pos {
    flex: none; width: 1.6rem; text-align: center; font-weight: 800; color: var(--accent);
    font-size: .95rem; margin-top: 1rem;
}
.rank-new {
    flex: none; align-self: center; background: var(--accent); color: var(--accent-ink);
    border-radius: 999px; font-size: .68rem; font-weight: 700; padding: .15rem .5rem;
    text-transform: uppercase; letter-spacing: .04em;
}

.members-panel {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem;
}
.members-panel h2 { margin: 0 0 .6rem; font-size: 1.05rem; }
.members-panel h3 { margin: 1rem 0 .4rem; font-size: .9rem; }
.members-panel .muted { color: var(--muted); font-weight: 400; font-size: .8rem; }
.members-list, .invites-list { list-style: none; padding: 0; margin: 0; }
.member-row, .invite-row {
    display: flex; align-items: center; gap: .5rem; padding: .45rem 0;
    border-bottom: 1px solid var(--line); font-size: .92rem;
}
.member-row:last-child, .invite-row:last-child { border-bottom: 0; }
.member-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.admin-badge {
    background: var(--accent-soft); color: var(--accent); border-radius: 999px;
    font-size: .68rem; font-weight: 700; padding: .12rem .5rem; flex: none;
}
.member-acts { margin-left: auto; display: flex; gap: .35rem; flex: none; }
.invite-url {
    color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; min-width: 0; flex: 1;
}
.btn-ghost.mini { padding: .25rem .55rem; font-size: .75rem; border-radius: 7px; flex: none; }
.panel-actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.invites-list .muted { padding: .4rem 0; }

.join h1 { font-size: 1.8rem; letter-spacing: -.02em; margin: .8rem 0 .4rem; }

.empty, .notfound { color: var(--muted); text-align: center; padding: 2.2rem 1rem; }
.empty-icon { font-size: 2.2rem; }
.notfound h1 { color: var(--ink); }

/* Toasts */
.toast-zone {
    position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
    display: flex; flex-direction: column; gap: .5rem; z-index: 9990;
    width: min(92vw, 420px); pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex; align-items: center; gap: .8rem; justify-content: space-between;
    background: var(--ink); color: var(--bg);
    padding: .65rem .9rem; border-radius: 11px; box-shadow: var(--shadow);
    font-size: .9rem; animation: toast-in .18s ease-out;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}
.toast-out { opacity: 0; transition: opacity .2s; }
.toast-error { background: var(--danger); color: #fff; }
.toast-msg { min-width: 0; }
.toast-action {
    background: none; border: 0; color: inherit; font-weight: 700; cursor: pointer;
    font-size: .9rem; text-transform: uppercase; letter-spacing: .03em; padding: .2rem .3rem;
    flex: none;
}
.toast-action:hover { text-decoration: underline; }

@media (min-width: 560px) {
    .item-tools { flex-direction: row; align-items: center; }
}
