:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --success: #22c55e;
    --danger: #ef4444;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
}

/* ── Auth ─────────────────────────────────────────────────────────────────── */

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.auth-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.auth-logo {
    width: 56px; height: 56px;
    background: var(--primary);
    color: white;
    border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.75rem;
    margin: 0 auto 1rem;
}

.auth-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.5rem; }

.auth-form { display: flex; flex-direction: column; gap: 1rem; text-align: left; }

.field label {
    display: block;
    font-size: .875rem;
    font-weight: 500;
    color: var(--muted);
    margin-bottom: .375rem;
}

.field input {
    width: 100%;
    padding: .625rem .875rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .9375rem;
    color: var(--text);
    background: var(--card);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.error-msg { color: var(--danger); font-size: .875rem; text-align: center; }

/* ── Page layout ──────────────────────────────────────────────────────────── */

.page { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 60px;
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 10;
    box-shadow: var(--shadow);
}

.topbar-left { display: flex; align-items: center; gap: .75rem; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }

.topbar-title { font-size: 1.125rem; font-weight: 700; }

.username { font-size: .875rem; color: var(--muted); font-weight: 500; }

.content {
    max-width: 920px;
    margin: 0 auto;
    width: 100%;
    padding: 1.5rem 1rem;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
    padding: .625rem 1.25rem;
    border-radius: 8px;
    font-size: .9375rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all .15s;
    white-space: nowrap;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); }

.btn-back {
    background: none; border: none;
    font-size: 1.25rem; cursor: pointer;
    color: var(--muted);
    padding: .25rem .5rem;
    border-radius: 6px; line-height: 1;
    transition: all .15s;
}
.btn-back:hover { background: var(--bg); color: var(--text); }

.btn-del {
    background: none; border: none;
    color: var(--muted);
    font-size: 1.25rem; cursor: pointer;
    width: 28px; height: 28px;
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: all .15s;
    line-height: 1;
}
.btn-del:hover { background: #fef2f2; color: var(--danger); }

/* ── Add row ──────────────────────────────────────────────────────────────── */

.add-row {
    display: flex; gap: .75rem;
    margin-bottom: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.add-input {
    flex: 1; min-width: 160px;
    padding: .625rem .875rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .9375rem;
    color: var(--text);
    background: var(--card);
    outline: none;
    box-shadow: var(--shadow);
    transition: border-color .15s, box-shadow .15s;
}
.add-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12), var(--shadow);
}

.add-select {
    padding: .625rem .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .875rem;
    color: var(--text);
    background: var(--card);
    outline: none;
    box-shadow: var(--shadow);
    cursor: pointer;
}
.add-select:focus { border-color: var(--primary); }

/* ── Lists grid ───────────────────────────────────────────────────────────── */

.lists-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.list-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all .15s;
    border: 1px solid var(--border);
}
.list-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    border-color: #a5b4fc;
}

.list-card-top {
    display: flex; align-items: flex-start;
    justify-content: space-between;
    gap: .5rem;
    margin-bottom: .625rem;
}
.list-card-top .drag-handle {
    margin-top: 2px;
    font-size: 1.3rem;
}

.list-card-title-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

.list-name { font-size: 1rem; font-weight: 600; word-break: break-word; }

.badge-shared {
    font-size: .7rem; font-weight: 500;
    background: #ede9fe; color: #7c3aed;
    padding: .125rem .4rem;
    border-radius: 20px;
    white-space: nowrap;
}

.list-meta {
    display: flex; justify-content: space-between;
    align-items: center;
    margin-bottom: .75rem;
}

.progress-text { font-size: .8125rem; color: var(--muted); }

.creator {
    font-size: .75rem; color: var(--muted);
    background: var(--bg);
    padding: .125rem .5rem;
    border-radius: 20px;
}

.progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 2px;
    transition: width .3s ease;
}

/* ── Items list ───────────────────────────────────────────────────────────── */

.items-list { display: flex; flex-direction: column; gap: .5rem; }

.item-row {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .75rem 1rem;
    display: flex; align-items: center; gap: .75rem;
    box-shadow: var(--shadow);
    transition: all .15s;
}
.item-row:hover { border-color: #c7d2fe; }

.item-check {
    width: 18px; height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.item-text {
    flex: 1;
    font-size: .9375rem;
    word-break: break-word;
    transition: all .2s;
}

.item-row.item-done { opacity: .65; }
.item-row.item-done .item-text {
    text-decoration: line-through;
    color: var(--muted);
}

.resp-select {
    padding: .25rem .5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .8125rem;
    color: var(--muted);
    background: var(--bg);
    outline: none;
    cursor: pointer;
    max-width: 140px;
    flex-shrink: 0;
}
.resp-select:focus { border-color: var(--primary); }

/* ── Empty state ──────────────────────────────────────────────────────────── */

.empty {
    text-align: center;
    color: var(--muted);
    padding: 3rem;
    font-size: .9375rem;
}

/* ── Access section ───────────────────────────────────────────────────────── */

.access-section {
    margin-top: 2rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.section-title {
    font-size: .8125rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 1rem;
}

.access-list {
    display: flex;
    flex-direction: column;
    margin-bottom: 1rem;
}

.access-row {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: .5rem 0;
    border-bottom: 1px solid var(--border);
}
.access-row:last-child { border-bottom: none; }

.access-name { font-size: .9375rem; }

.badge-owner {
    font-size: .75rem; font-weight: 500;
    background: #e0e7ff; color: var(--primary);
    padding: .125rem .5rem;
    border-radius: 20px;
}

.btn-revoke {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: .8125rem;
    padding: .25rem .625rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all .15s;
}
.btn-revoke:hover { background: #fef2f2; color: var(--danger); border-color: var(--danger); }

.access-add { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }

.access-only-owner { font-size: .875rem; color: var(--muted); padding: .25rem 0; }

/* ── Drag handles ─────────────────────────────────────────────────────────── */

.drag-handle {
    cursor: grab;
    color: var(--border);
    font-size: 1.1rem;
    line-height: 1;
    flex-shrink: 0;
    user-select: none;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color .15s;
    touch-action: none;
}
.drag-handle:hover { color: var(--muted); }
.drag-handle:active { cursor: grabbing; }

.drag-ghost {
    opacity: .4;
    background: #e0e7ff !important;
    border-color: var(--primary) !important;
    border-radius: var(--radius);
}

.drag-chosen {
    box-shadow: 0 8px 24px rgba(99,102,241,.2) !important;
    transform: scale(1.02);
}

/* ── WS status dot ────────────────────────────────────────────────────────── */

.ws-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.ws-dot.online  { background: var(--success); }
.ws-dot.offline { background: var(--danger); }
