:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --ink: #1f2430;
    --muted: #6b7280;
    --line: #e5e7eb;
    --accent: #3b5bdb;
    --danger: #c92a2a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

.site-header {
    background: var(--card);
    border-bottom: 1px solid var(--line);
}
.site-header .container { padding-top: 16px; padding-bottom: 16px; }
.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header-row nav a { text-decoration: none; font-weight: 600; }

.logo {
    font-size: 20px;
    font-weight: 700;
    text-decoration: none;
    color: var(--ink);
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px;
}

h1, h2 { margin: 0 0 16px; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.center { text-align: center; }

.alert {
    background: #ffe3e3;
    color: var(--danger);
    border: 1px solid #ffc9c9;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 20px;
}

/* ---------- Карточки-контейнеры ---------- */

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
}

/* ---------- Сетка книг ---------- */

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 24px;
}

.book-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow .15s, transform .15s;
}
.book-card:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, .08);
    transform: translateY(-2px);
}

.cover-link { display: block; }
.cover, .cover-placeholder {
    width: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    background: #eef0f3;
    display: block;
}
.cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
    padding: 8px;
}

.book-card .body { padding: 10px 12px; }
.book-card .title {
    font-weight: 600; text-decoration: none; color: var(--ink);
}
.book-card .author { color: var(--muted); font-size: 14px; }

/* ---------- Бейджи статуса ---------- */

.badge {
    display: inline-block;
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 999px;
    margin-top: 6px;
}
.badge.read         { background: #d3f9d8; color: #2b8a3e; }
.badge.reading      { background: #d0ebff; color: #1971c2; }
.badge.want_to_read { background: #fff3bf; color: #e67700; }
.badge.abandoned    { background: #f1f3f5; color: #868e96; }

/* ---------- Теги ---------- */

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.tag {
    display: inline-block;
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 999px;
    background: #edf2ff;
    color: var(--accent);
    text-decoration: none;
}
a.tag:hover { background: #dbe4ff; }

/* Панель сортировки и фильтра на главной */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}
.tag-filter { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-pill {
    font-size: 13px;
    padding: 4px 14px;
    border-radius: 999px;
    background: #e9ecef;
    color: var(--ink);
    text-decoration: none;
}
.tag-pill:hover { background: #dee2e6; }
.tag-pill.active { background: var(--accent); color: #fff; }

.sort-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.sort-form label { margin: 0; white-space: nowrap; }
.sort-form select { width: auto; }

/* Редактор тегов-чипов (admin) */
.tag-editor {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px;
    display: grid;
    gap: 8px;
}
.tag-editor-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-editor-list:empty { display: none; }
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    padding: 3px 4px 3px 10px;
    border-radius: 999px;
    background: #edf2ff;
    color: var(--accent);
}
.tag-chip-x {
    background: transparent;
    color: var(--accent);
    border: 0;
    padding: 0;
    width: 18px;
    height: 18px;
    line-height: 1;
    font-size: 16px;
    border-radius: 999px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s, background .12s;
}
.tag-chip:hover .tag-chip-x,
.tag-chip-x:focus { opacity: 1; }
.tag-chip-x:hover { background: #dbe4ff; color: var(--danger); }
.tag-editor-add { display: flex; gap: 8px; }
.tag-editor-add .tag-editor-input { flex: 1; }
.tag-editor-btn { padding: 8px 14px; }

/* ---------- Формы ---------- */

form.stack { display: grid; gap: 12px; }
label { font-size: 14px; font-weight: 600; display: block; margin-bottom: 4px; }
input, select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
}
textarea { resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 120px; }
.rating-field { max-width: 160px; }

button {
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 9px 16px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
button.secondary { background: #e9ecef; color: var(--ink); }
/* Кнопка после успешного сохранения (ставит/снимает JS). */
button.saved { background: #2b8a3e; color: #fff; cursor: default; }
button.link-danger {
    background: transparent;
    color: var(--danger);
    padding: 4px 0;
    font-weight: 500;
}

/* ---------- Карточка книги ---------- */

.book-detail { display: flex; gap: 32px; flex-wrap: wrap; }
.cover-col { width: 280px; flex: none; }
.book-detail .cover, .book-detail .cover-placeholder {
    width: 280px;
    border-radius: 10px;
}
.cover-form { margin-top: 12px; }
.delete-book { margin-top: 16px; }
.meta { flex: 1; min-width: 240px; }

.review {
    border-top: 1px solid var(--line);
    padding: 14px 0;
    display: flex;
    justify-content: space-between;
    gap: 16px;
}
.review:first-of-type { border-top: 0; }
.review-body p { margin: 6px 0; }
.stars { color: #f08c00; letter-spacing: 2px; }

/* Чтобы якорь после сохранения не прилипал к верхнему краю экрана. */
#book-edit, .review-edit { scroll-margin-top: 20px; }

.review-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.review-header h2 { margin-bottom: 0; }

.review-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
button.review-tab {
    background: #e9ecef;
    color: var(--ink);
    font-weight: 500;
    font-size: 13px;
    padding: 4px 14px;
    border-radius: 999px;
}
button.review-tab.active {
    background: var(--accent);
    color: #fff;
}

/* В карусели показывается ровно один отзыв — разделитель не нужен. */
.review-carousel .review { border-top: 0; }

/* Отзыв в режиме редактирования (admin) */
.review-edit { flex-direction: column; align-items: stretch; gap: 8px; }
.review-edit > form:first-child { flex: 1; }
.review-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}
