/* Knigi Shelves: окно «В мои книги», полки в профиле, на странице книги и страницы полок.
   Только переменные тем из knigi2.css (в читалке те же имена в fb2reader/style.css), своих цветов нет.
   Файл: templates/knigi2/style/k-shelves.css, подключается в main.tpl; в читалке его подключает knigi-mybooks.js сам. */
:root { --kmb-css: 1; }

/* ---------- кнопка на странице книги ---------- */
.kb-mybooks.is-set { background: var(--accent-soft, var(--hover)); border-color: var(--ribbon); }
.kb-mybooks svg { flex: 0 0 auto; }
.kb-mybooks.is-set svg { fill: currentColor; }

/* ---------- окно ---------- */
html.kmb-open { overflow: hidden; }
.kmb { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.kmb[hidden] { display: none; }
.kmb__backdrop { position: absolute; inset: 0; background: var(--overlay, color-mix(in srgb, var(--bg) 70%, transparent)); }
.kmb__dialog {
	position: relative; display: flex; flex-direction: column;
	width: 100%; max-width: 440px; max-height: min(640px, calc(100vh - 32px)); max-height: min(640px, calc(100dvh - 32px));
	border: 1px solid var(--border); border-radius: var(--radius-lg, 12px);
	background: var(--surface); color: var(--text); box-shadow: var(--shadow);
	font-family: var(--font, inherit); font-size: 16px; line-height: 1.4;
	opacity: 0; transform: translateY(8px);
	transition: opacity 140ms ease, transform 140ms var(--ease, ease);
}
.kmb.is-open .kmb__dialog { opacity: 1; transform: none; }
.kmb__dialog:focus { outline: none; }
.kmb__dialog:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.kmb__head { display: flex; align-items: flex-start; gap: 8px; padding: 16px 12px 8px 20px; }
.kmb__heading { flex: 1; min-width: 0; padding-top: 8px; }
.kmb__title { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.kmb__book { margin: 4px 0 0; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kmb__x {
	flex: 0 0 44px; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
	border: 0; border-radius: var(--radius, 8px); background: transparent; color: var(--text); cursor: pointer;
	transition: background-color 140ms ease;
}
.kmb__x:hover { background: var(--hover); }

.kmb__body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 4px 20px 8px; display: flex; flex-direction: column; gap: 16px; }
.kmb__group { margin: 0; padding: 0; border: 0; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.kmb__legend { padding: 0; margin: 0 0 6px; font-size: 13px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* статусы: радиокнопки строкой-сеткой */
.kmb__statuses { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.kmb__status { position: relative; }
.kmb__status input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.kmb__status label {
	display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 12px;
	border: 1px solid var(--line); border-radius: var(--radius, 8px); cursor: pointer; font-weight: 500;
	transition: background-color 140ms ease, border-color 140ms ease;
}
.kmb__status label::before {
	content: ""; flex: 0 0 auto; width: 16px; height: 16px; border-radius: 50%;
	border: 2px solid var(--ctl, var(--muted)); box-sizing: border-box;
}
.kmb__status label:hover { background: var(--hover); }
.kmb__status input:checked + label { border-color: var(--ribbon); background: var(--accent-soft, var(--hover)); }
.kmb__status input:checked + label::before { border-color: var(--ribbon); background: var(--ribbon); box-shadow: inset 0 0 0 3px var(--surface); }
.kmb__status input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 2px; }
.kmb__status input:disabled + label { opacity: .6; cursor: default; }

.kmb__clear, .kmb__add {
	align-self: flex-start; min-height: 44px; padding: 0 4px; border: 0; background: transparent;
	color: var(--accent-text); font: inherit; font-size: 15px; font-weight: 500; cursor: pointer;
	text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
}
.kmb__clear:hover, .kmb__add:hover { text-decoration-thickness: 2px; }
.kmb__clear[hidden], .kmb__add[hidden] { display: none; }

/* полки: галочки */
.kmb__shelves { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.kmb__shelf { position: relative; display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.kmb__shelf:last-child { border-bottom: 0; }
.kmb__check { position: absolute; left: 4px; top: 50%; margin: -9px 0 0; width: 18px; height: 18px; accent-color: var(--ribbon); }
.kmb__shelf label { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; min-height: 52px; padding: 6px 4px 6px 34px; cursor: pointer; }
.kmb__shelf label:hover .kmb__name { text-decoration: underline; text-underline-offset: 3px; }
.kmb__name { font-weight: 500; overflow-wrap: anywhere; }
.kmb__meta { font-size: 13px; color: var(--muted); }
.kmb__empty, .kmb__hint { margin: 0; color: var(--muted); font-size: 14px; }

.kmb__new { display: flex; flex-direction: column; gap: 6px; }
.kmb__new[hidden] { display: none; }
.kmb__label { font-size: 14px; font-weight: 500; }
.kmb__newrow { display: flex; gap: 8px; }
.kmb__newrow input { flex: 1; min-width: 0; min-height: 44px; }
.kmb__newrow input[aria-invalid="true"] { border-color: var(--danger, var(--accent-text)); }

.kmb__live { margin: 0; padding: 0 20px; min-height: 0; font-size: 14px; color: var(--muted); }
.kmb__live:not(:empty) { padding-top: 4px; padding-bottom: 4px; }
.kmb__live.is-error { color: var(--danger, var(--accent-text)); }

.kmb__foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px 16px; flex-wrap: wrap; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
.kmb__foot:empty { display: none; }
.kmb__all { margin-right: auto; display: inline-flex; align-items: center; min-height: 44px; color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

.kmb__state { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 8px 0; }
.kmb__state p { margin: 0; }

.kmb__skel { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.kmb__skel span { display: block; height: 44px; border-radius: var(--radius, 8px); background: var(--hover); animation: kmb-pulse 1.2s ease-in-out infinite; }
.kmb__skel span:nth-child(2) { width: 80%; }
.kmb__skel span:nth-child(4) { width: 60%; }
@keyframes kmb-pulse { 50% { opacity: .5; } }

@media (max-width: 519px) {
	.kmb { align-items: flex-end; padding: 0; }
	.kmb__dialog { max-width: none; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); border-radius: var(--radius-lg, 12px) var(--radius-lg, 12px) 0 0; border-bottom: 0; }
	.kmb__body { padding-left: 16px; padding-right: 16px; }
	.kmb__head { padding-left: 16px; }
	.kmb__foot { padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: reduce) {
	.kmb__dialog { transition: none; transform: none; }
	.kmb__skel span { animation: none; }
}

/* ---------- страница книги: «Лежит на полках читателей» ---------- */
.ks-onshelves { margin: 12px 0 0; font-size: 15px; color: var(--muted); }
.ks-onshelves a { color: var(--accent-text); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.ks-onshelves a:hover { text-decoration-thickness: 2px; }

/* ---------- карточки полок (профиль, список полок) ---------- */
.ks-profile { display: flex; flex-direction: column; gap: 16px; margin-top: 32px; }
.ks-profile__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; }
.ks-profile__title { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.ks-profile__n { color: var(--muted); font-weight: 500; }
.ks-profile__all { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent-text); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.ks-hint { margin: 0; color: var(--muted); }

.ks-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.ks-card__link {
	display: flex; flex-direction: column; gap: 6px; height: 100%; padding: 16px;
	border: 1px solid var(--border); border-radius: var(--radius-lg, 12px); background: var(--surface); color: var(--text);
	transition: border-color 140ms ease, background-color 140ms ease;
}
.ks-card__link:hover { border-color: var(--line); background: var(--hover); }
.ks-card__covers { display: flex; align-items: flex-end; gap: 6px; height: 96px; margin-bottom: 6px; border-bottom: 3px solid var(--line); }
.ks-card__cover { width: 56px; flex: 0 0 56px; border-radius: 4px 4px 0 0; }
.ks-card__cover--empty { height: 84px; border: 1px dashed var(--line); border-bottom: 0; }
.ks-card__cover .k-cover__t { padding: 4px; font-size: 10px; }
.ks-card__name { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.ks-card__link:hover .ks-card__name { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.ks-card__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 14px; color: var(--muted); }

.ks-badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: var(--radius, 8px); background: var(--chip, var(--hover)); color: var(--text); font-size: 13px; }
.ks-badge[hidden] { display: none; }

/* ---------- страницы полок ---------- */
.ks-page { display: flex; flex-direction: column; gap: 24px; }
.ks-head { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.ks-eyebrow { margin: 0; font-size: 14px; color: var(--muted); }
.ks-eyebrow a, .ks-meta a { color: var(--accent-text); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.ks-title { margin: 0; overflow-wrap: anywhere; }
.ks-meta { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; color: var(--muted); }
.ks-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.ks-danger { color: var(--danger, var(--accent-text)); border-color: var(--danger, var(--accent-text)); }
.ks-form { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 560px; }
.ks-form[hidden] { display: none; }
.ks-form label { font-size: 14px; font-weight: 500; }
.ks-form__row { display: flex; flex-wrap: wrap; gap: 8px; }
.ks-form__row input { flex: 1 1 220px; min-width: 0; }
.ks-form input[aria-invalid="true"] { border-color: var(--danger, var(--accent-text)); }
.ks-live { margin: 0; min-height: 1.4em; font-size: 14px; color: var(--muted); }
.ks-live.is-error { color: var(--danger, var(--accent-text)); }

.ks-shelfwrap { overflow: hidden; }
.ks-shelf { list-style: none; }
.ks-book .k-cover { position: relative; overflow: visible; }
.ks-book .k-cover img { border-radius: 6px; }
.ks-book__ribbon { left: auto; right: 14px; bottom: auto; top: -2px; height: 26px; }
.ks-book__remove {
	align-self: flex-start; min-height: 44px; padding: 0; border: 0; background: transparent;
	color: var(--muted); font: inherit; font-size: 14px; cursor: pointer;
	text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
}
.ks-book__remove:hover { color: var(--text); }
.ks-book .k-card__body { display: flex; flex-direction: column; gap: 4px; }
.ks-empty { display: flex; flex-direction: column; gap: 6px; }
.ks-empty p { margin: 0; }
.ks-empty__t { font-weight: 600; }

@media (max-width: 719px) {
	.ks-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
	.ks-card__link { padding: 12px; }
	.ks-card__cover { width: 40px; flex-basis: 40px; }
	.ks-card__covers { height: 72px; }
	.ks-card__cover--empty { height: 60px; }
}
