:root {
    --bg: #f5f1e8;
    --bg-strong: #ece4d4;
    --surface: rgba(255, 252, 246, 0.88);
    --surface-strong: #fffdfa;
    --surface-muted: rgba(117, 87, 53, 0.08);
    --text: #2d241b;
    --text-soft: #6f6253;
    --text-muted: #8c7d6c;
    --border: rgba(86, 60, 32, 0.14);
    --border-strong: rgba(86, 60, 32, 0.22);
    --primary: #6e4d35;
    --primary-strong: #593a26;
    --accent: #b9873f;
    --success: #56764f;
    --warning: #b97434;
    --error: #a24f44;
    --shadow-sm: 0 16px 40px rgba(59, 41, 20, 0.07);
    --shadow-lg: 0 32px 80px rgba(59, 41, 20, 0.12);
    --radius-sm: 12px;
    --radius-md: 20px;
    --radius-lg: 28px;
    --font-display: "Cormorant Garamond", Georgia, serif;
    --font-body: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --transition: 180ms ease;
}

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

html {
    color-scheme: light;
}

body {
    min-height: 100vh;
    font-family: var(--font-body);
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(185, 135, 63, 0.18), transparent 32%),
        radial-gradient(circle at top right, rgba(110, 77, 53, 0.16), transparent 34%),
        linear-gradient(180deg, #f7f3eb 0%, #f2ece0 52%, #eee4d4 100%);
    line-height: 1.55;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
    border: 0;
    transition:
        background-color var(--transition),
        color var(--transition),
        border-color var(--transition),
        box-shadow var(--transition),
        transform var(--transition);
}

button:hover {
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

a {
    color: inherit;
}

.hidden {
    display: none !important;
}

.page-shell {
    position: relative;
    overflow: hidden;
}

.page-glow {
    position: fixed;
    width: 28rem;
    height: 28rem;
    border-radius: 999px;
    filter: blur(18px);
    opacity: 0.6;
    pointer-events: none;
    z-index: 0;
}

.page-glow-left {
    top: -8rem;
    left: -8rem;
    background: rgba(185, 135, 63, 0.18);
}

.page-glow-right {
    top: 10rem;
    right: -10rem;
    background: rgba(110, 77, 53, 0.16);
}

.container {
    position: relative;
    z-index: 1;
    width: min(1280px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 1.25rem 0 3rem;
}

.surface-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(18px);
}

.surface-subtle {
    background: var(--surface-muted);
    border: 1px solid rgba(86, 60, 32, 0.09);
}

.eyebrow {
    margin-bottom: 0.4rem;
    color: var(--text-muted);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1.5rem;
}

.section-heading h2 {
    font-family: var(--font-display);
    font-size: clamp(1.85rem, 4vw, 2.4rem);
    font-weight: 600;
    line-height: 0.95;
}

.section-copy {
    max-width: 36rem;
    color: var(--text-soft);
    font-size: 0.96rem;
}

.hero,
.search-filters,
.books-section {
    border-radius: var(--radius-lg);
}

.hero {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(18rem, 0.9fr);
    gap: 2rem;
    padding: clamp(1.5rem, 4vw, 2.75rem);
    margin-bottom: 1.25rem;
}

.hero-copy h1 {
    max-width: 16ch;
    font-family: var(--font-display);
    font-size: clamp(2.25rem, 4.8vw, 3.6rem);
    font-weight: 600;
    line-height: 0.98;
    letter-spacing: -0.02em;
}

.hero-text {
    max-width: 34rem;
    margin-top: 0.75rem;
    color: var(--text-soft);
    font-size: 0.96rem;
}

.hero-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    justify-content: space-between;
}

.header-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: flex-end;
}

.header-controls button,
.button-group button,
.pagination button,
.remove-entry,
.edit-btn {
    min-height: 2.8rem;
    padding: 0.8rem 1.1rem;
    border-radius: 999px;
}

.header-controls button,
.button-group button:not(.secondary),
.btn-primary,
.auth-button,
.edit-btn {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 12px 24px rgba(89, 58, 38, 0.18);
}

.header-controls button:hover,
.button-group button:not(.secondary):hover,
.btn-primary:hover,
.auth-button:hover,
.edit-btn:hover {
    background: var(--primary-strong);
}

.button-group button.secondary,
.btn-secondary,
.duplicates-filter-secondary {
    background: rgba(255, 252, 246, 0.85);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
}

.button-group button.secondary:hover,
.btn-secondary:hover,
.duplicates-filter-secondary:hover {
    border-color: var(--border-strong);
    background: var(--surface-strong);
}

.duplicates-filter-secondary.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.auth-button {
    min-height: 2.35rem;
    padding: 0.58rem 0.95rem;
    border: 1px solid rgba(86, 60, 32, 0.14);
    background: rgba(255, 252, 246, 0.96);
    color: var(--text);
    box-shadow: none;
    font-size: 0.84rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.auth-button:hover {
    background: var(--surface-strong);
    border-color: var(--border-strong);
}

.auth-button.logout,
.btn-delete-user,
.remove-entry {
    background: var(--error);
    color: #fff;
    border-color: transparent;
}

.auth-button.logout:hover,
.btn-delete-user:hover,
.remove-entry:hover {
    background: #863d34;
}

.search-filters,
.books-section {
    padding: clamp(1.35rem, 3.5vw, 2rem);
    margin-bottom: 1.25rem;
}

.search-filters {
    padding: 0.95rem 1rem;
}

.search-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) auto repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.form-row {
    display: grid;
    gap: 1rem;
}

.form-row-two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-row-three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.search-row {
    display: grid;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.form-group label {
    color: var(--text-soft);
    font-size: 0.85rem;
    font-weight: 600;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.85rem 0.95rem;
    border: 1px solid rgba(86, 60, 32, 0.12);
    border-radius: 16px;
    background: rgba(255, 252, 246, 0.9);
    color: var(--text);
    transition:
        border-color var(--transition),
        box-shadow var(--transition),
        background-color var(--transition);
}

.form-group textarea {
    min-height: 7rem;
    resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: rgba(110, 77, 53, 0.45);
    box-shadow: 0 0 0 4px rgba(110, 77, 53, 0.1);
    background: #fff;
}

.filter-fieldset {
    min-width: 0;
    padding: 0.8rem 0.95rem;
    border: 1px solid rgba(86, 60, 32, 0.12);
    border-radius: var(--radius-md);
    background: rgba(255, 252, 246, 0.62);
}

.filter-fieldset legend {
    padding-right: 0.5rem;
    color: var(--text-soft);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.filter-fieldset-search input {
    background: transparent;
}

.search-input-group {
    justify-content: center;
}

.search-input-group input {
    min-height: 100%;
    min-height: 3rem;
    padding-inline: 1rem;
    border-radius: var(--radius-md);
    background: rgba(255, 252, 246, 0.72);
}

.filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 2rem;
    padding: 0;
    color: var(--text);
    font-size: 0.86rem;
    font-weight: 600;
    white-space: nowrap;
}

.filter-fieldset-toggle {
    display: flex;
    justify-content: center;
}

.filter-toggle input {
    width: auto;
    accent-color: var(--primary);
}

.filter-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem 1rem;
}

.filter-option,
.checkbox-group {
    display: inline-flex;
    gap: 0.5rem;
    align-items: center;
}

.filter-option {
    color: var(--text);
    font-size: 0.9rem;
}

.filter-option input,
.checkbox-group input {
    width: auto;
    accent-color: var(--primary);
}

.button-group {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.books-heading {
    align-items: center;
}

.books-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 3rem;
    padding: 0.75rem 1rem;
    border-radius: 999px;
    background: rgba(255, 252, 246, 0.85);
    border: 1px solid var(--border);
    color: var(--text-soft);
    font-size: 0.92rem;
    font-weight: 700;
}

.books-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.books-table thead th {
    padding: 0 0.8rem 0.7rem;
    text-align: left;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    white-space: nowrap;
}

.books-table thead th[data-sort],
.books-table thead th[data-action] {
    cursor: pointer;
}

.sort-indicator {
    display: inline-block;
    width: 1rem;
    margin-left: 0.2rem;
    text-align: center;
    color: var(--text-muted);
}

.sort-indicator.is-active {
    color: var(--text);
}

.books-table tbody td {
    padding: 0.72rem 0.8rem;
    border-top: 1px solid rgba(86, 60, 32, 0.08);
    background: rgba(255, 252, 246, 0.42);
    vertical-align: top;
    font-size: 0.92rem;
    line-height: 1.35;
}

.books-table tbody tr td:first-child {
    border-top-left-radius: 14px;
    border-bottom-left-radius: 14px;
}

.books-table tbody tr td:last-child {
    border-top-right-radius: 14px;
    border-bottom-right-radius: 14px;
}

.books-table tbody tr {
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
}

.books-table tbody tr:hover td {
    background: rgba(255, 252, 246, 0.86);
}

@media (min-width: 781px) {
    .books-table {
        table-layout: fixed;
    }

    .books-table th:nth-child(1),
    .books-table td:nth-child(1) {
        width: 40%;
    }

    .books-table th:nth-child(2),
    .books-table td:nth-child(2) {
        width: 24%;
    }

    .books-table th:nth-child(3),
    .books-table td:nth-child(3) {
        width: 22%;
    }

    .books-table th:nth-child(4),
    .books-table td:nth-child(4) {
        width: 14%;
    }
}

.winner-badge,
.user-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 1.9rem;
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.winner-badge {
    background: rgba(86, 118, 79, 0.14);
    color: var(--success);
    min-height: auto;
    min-width: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    font-size: 0.8rem;
    letter-spacing: 0;
    line-height: 1;
}

.title-cell {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
}

.title-text {
    min-width: 0;
}

.title-cell .winner-badge {
    flex: 0 0 auto;
}

.pagination-info {
    margin-top: 1.4rem;
    color: var(--text-muted);
    text-align: center;
    font-size: 0.88rem;
}

.pagination {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-top: 1rem;
}

.pagination button {
    background: rgba(255, 252, 246, 0.82);
    color: var(--text);
    border: 1px solid var(--border);
    min-width: 2.8rem;
}

.pagination button.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.pagination button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    padding: 1.25rem;
    background: rgba(40, 28, 16, 0.38);
    backdrop-filter: blur(10px);
    overflow-y: auto;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    width: min(100%, 680px);
    max-height: calc(100vh - 2.5rem);
    overflow-y: auto;
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
}

.modal-content.modal-small {
    width: min(100%, 450px);
}

.modal-content.modal-large {
    width: min(100%, 980px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.35rem 1.45rem;
    border-bottom: 1px solid rgba(86, 60, 32, 0.1);
}

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 600;
}

.close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 999px;
    background: rgba(110, 77, 53, 0.08);
    color: var(--text-soft);
}

.close:hover {
    background: rgba(110, 77, 53, 0.14);
    color: var(--text);
}

.modal-form,
.modal-body {
    padding: 1.4rem;
}

.modal-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.4rem;
}

.modal-buttons.space-between {
    justify-content: space-between;
}

.modal-buttons-right {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-left: auto;
}

.modal-link-footer {
    margin-top: 1rem;
    text-align: center;
}

.modal-link {
    color: var(--primary);
    font-size: 0.92rem;
    font-weight: 700;
    text-decoration: none;
}

.modal-link:hover {
    text-decoration: underline;
}

.btn-primary,
.btn-secondary,
.btn-reset,
.btn-delete-user {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.8rem;
    padding: 0.8rem 1.15rem;
    border-radius: 999px;
}

.btn-reset {
    background: var(--warning);
    color: #fff;
}

.btn-reset:hover {
    background: #9e622b;
}

.detail-section {
    margin-bottom: 1.35rem;
    padding-bottom: 1.35rem;
    border-bottom: 1px solid rgba(86, 60, 32, 0.1);
}

.detail-section:last-of-type {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: 0;
}

.detail-section h3,
.batch-section-title {
    margin-bottom: 0.8rem;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.detail-row {
    display: grid;
    grid-template-columns: 8rem minmax(0, 1fr);
    gap: 0.8rem;
    margin-bottom: 0.8rem;
}

.detail-label {
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.detail-text {
    padding: 1rem;
    border-radius: 18px;
    background: rgba(110, 77, 53, 0.05);
    border: 1px solid rgba(86, 60, 32, 0.08);
    white-space: pre-wrap;
}

.batch-common-info,
.batch-entry {
    border-radius: 18px;
    border: 1px solid rgba(86, 60, 32, 0.1);
    background: rgba(110, 77, 53, 0.04);
}

.batch-common-info {
    padding: 1rem;
    margin-bottom: 1.25rem;
}

#batchEntries {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    margin-bottom: 1rem;
}

.batch-entry {
    padding: 1rem;
}

.batch-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.85rem;
}

.batch-entry-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
}

.batch-entry-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.users-list {
    overflow: hidden;
    border-radius: 20px;
    border: 1px solid rgba(86, 60, 32, 0.1);
}

.users-list-loading,
.empty-state {
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--text-soft);
}

.empty-state h3 {
    margin-bottom: 0.55rem;
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 600;
}

.status-message {
    padding: 1.2rem;
    text-align: center;
    color: var(--text-soft);
}

.status-message.error {
    color: var(--error);
}

.status-message.empty {
    color: var(--text-muted);
}

.user-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid rgba(86, 60, 32, 0.08);
    background: rgba(255, 252, 246, 0.85);
}

.user-item:last-child {
    border-bottom: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.user-headline {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.user-info strong {
    font-size: 1rem;
}

.user-info small,
.reset-password-username {
    color: var(--text-soft);
}

.user-badge {
    background: rgba(86, 118, 79, 0.14);
    color: var(--success);
}

.user-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.auth-info {
    display: none;
    margin-bottom: 1rem;
    padding: 0.95rem 1rem;
    border-radius: 16px;
    border: 1px solid rgba(86, 118, 79, 0.18);
    background: rgba(86, 118, 79, 0.08);
    color: var(--success);
}

.alert-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.alert {
    min-width: min(24rem, calc(100vw - 2rem));
    max-width: min(28rem, calc(100vw - 2rem));
    padding: 0.95rem 1.05rem;
    border-radius: 18px;
    border: 1px solid transparent;
    box-shadow: var(--shadow-sm);
    color: #fff;
    font-size: 0.92rem;
    font-weight: 700;
    animation: slide-in 180ms ease;
}

.alert.success {
    background: var(--success);
}

.alert.error {
    background: var(--error);
}

@keyframes slide-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 3000;
    align-items: center;
    justify-content: center;
    background: rgba(245, 241, 232, 0.8);
    backdrop-filter: blur(6px);
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 3rem;
    height: 3rem;
    border: 3px solid rgba(110, 77, 53, 0.14);
    border-top-color: var(--primary);
    border-radius: 999px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1080px) {
    .hero,
    .search-layout {
        grid-template-columns: 1fr;
    }

    .hero-copy h1 {
        max-width: 20ch;
    }

    .hero-actions {
        align-items: stretch;
    }

    .header-controls {
        justify-content: flex-start;
    }

    .section-heading {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 780px) {
    .container {
        width: min(100% - 1rem, 100%);
        padding-top: 0.75rem;
    }

    .hero,
    .search-filters,
    .books-section {
        border-radius: 22px;
    }

    .form-row-two,
    .form-row-three,
    .batch-entry-grid,
    .detail-row {
        grid-template-columns: 1fr;
    }

    .button-group {
        justify-content: stretch;
    }

    .button-group button,
    .header-controls button,
    .auth-button {
        width: 100%;
    }

    .books-table,
    .books-table tbody,
    .books-table tr,
    .books-table td {
        display: block;
        width: 100%;
    }

    .books-table thead {
        display: none;
    }

    .books-table tbody {
        display: grid;
        gap: 0.9rem;
    }

    .books-table tbody tr {
        border-radius: 20px;
        overflow: hidden;
        border: 1px solid rgba(86, 60, 32, 0.1);
    }

    .books-table tbody td {
        border-top: 0;
        border-radius: 0 !important;
        padding: 0.8rem 1rem;
    }

    .books-table tbody td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 0.22rem;
        color: var(--text-muted);
        font-size: 0.74rem;
        font-weight: 800;
        letter-spacing: 0.12em;
        text-transform: uppercase;
    }

    .user-item,
    .batch-entry-header,
    .modal-buttons.space-between {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-buttons-right,
    .user-actions {
        margin-left: 0;
    }
}

@media (max-width: 560px) {
    .modal {
        padding: 0.5rem;
    }

    .modal-content {
        max-height: calc(100vh - 1rem);
        border-radius: 20px;
    }

    .hero-copy h1 {
        font-size: clamp(2rem, 11vw, 2.7rem);
    }
}
