:root {
    --alfred-ebene: #282420;
    --alfred-cacao: #4A3E34;
    --alfred-moka: #6E5E4E;
    --alfred-taupe: #988C7A;
    --alfred-sable: #D5C9AB;
    --alfred-avoine: #E6DCC4;
    --alfred-parchemin: #F2ECCF;
    --alfred-creme: #F2ECE2;
    --alfred-olive: #6A7458;
    --alfred-terracotta: #B86656;

    --surface-main: #F2ECE2;
    --surface-soft: #EDE3D3;
    --surface-card: #F6F0E5;

    --text-main: #282420;
    --text-secondary: #6E5E4E;
    --text-muted: #988C7A;

    --border: rgba(74, 62, 52, 0.15);

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --shadow-soft:
        0 2px 8px rgba(40, 36, 32, 0.05);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Inter", sans-serif;
    background: var(--surface-main);
    color: var(--text-main);
}

a {
    color: inherit;
    text-decoration: none;
}

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

button {
    cursor: pointer;
}

h1,
h2,
h3 {
    margin: 0;
    font-family: "Lora", serif;
    color: var(--alfred-cacao);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px 1fr;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 28px 16px 24px;
    background: var(--alfred-ebene);
    color: var(--alfred-parchemin);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 0 10px 34px;
}

.brand-logo {
    display: block;

    width: 155px;
    height: 30px;

    background-color: var(--alfred-parchemin);

    -webkit-mask-image: url("/static/img/alfred-logo.svg");
    mask-image: url("/static/img/alfred-logo.svg");

    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;

    -webkit-mask-position: left center;
    mask-position: left center;

    -webkit-mask-size: contain;
    mask-size: contain;

    transition:
        background-color 160ms ease,
        opacity 160ms ease;
}

.brand-logo:hover {
    background-color: #FFF8E5;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;

    min-height: 44px;

    padding: 0 12px;

    border-radius: var(--radius-md);

    color: rgba(242, 236, 207, 0.82);

    transition:
        background 160ms ease,
        color 160ms ease,
        opacity 160ms ease;
}

.nav-item svg {
    width: 18px;
    height: 18px;

    stroke-width: 1.8;
}

.nav-item:hover {
    background: rgba(242, 236, 207, 0.08);
    color: var(--alfred-parchemin);
}

.nav-item.active {
    background: rgba(152, 140, 122, 0.18);
    color: var(--alfred-parchemin);
}

.nav-item.disabled {
    opacity: 0.42;
    cursor: default;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 24px;
}

.profile {
    display: flex;
    align-items: center;
    gap: 10px;

    margin-top: 18px;

    padding: 16px 10px 0;

    border-top: 1px solid rgba(242, 236, 207, 0.12);
}

.profile-avatar {
    width: 34px;
    height: 34px;

    display: grid;
    place-items: center;

    flex: 0 0 auto;

    border-radius: 50%;

    background: var(--alfred-moka);

    font-size: 13px;
    font-weight: 700;
}

.profile-content {
    display: flex;
    flex-direction: column;
    gap: 2px;

    min-width: 0;

    font-size: 13px;
}

.profile-content span {
    color: rgba(242, 236, 207, 0.55);
    font-size: 11px;
}

.main-content {
    min-width: 0;
    padding: 38px 42px 60px;
}

.auth-base {
    background: var(--surface-main);
}

.auth-base .main-content {
    padding: 0;
}

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
}

.auth-logo {
    margin: 0 auto 30px;
}

.sidebar-footer .logout-button {
    width: 100%;
    margin-top: 8px;
    background: transparent;
    border: 1px solid rgba(213, 201, 171, 0.18);
    color: rgba(242, 236, 207, 0.68);
    font-size: 12px;
}

.sidebar-footer .logout-button:hover {
    border-color: rgba(213, 201, 171, 0.32);
    background: rgba(213, 201, 171, 0.08);
    color: var(--alfred-parchemin);
}

.auth-card {
    width: min(100%, 390px);
    padding: 42px 38px 38px;
    border-radius: 16px;
    background: var(--alfred-cacao);
    box-shadow: 0 18px 45px rgba(40, 36, 32, 0.16);
}

.auth-card h1 {
    margin-bottom: 28px;
    color: var(--alfred-parchemin);
    font-size: 30px;
    line-height: 1.15;
    text-align: center;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-field label {
    color: rgba(242, 236, 207, 0.82);
    font-size: 13px;
    font-weight: 600;
}

.auth-field input {
    width: 100%;
    min-height: 48px;
    padding: 0 14px;
    border: 1px solid rgba(242, 236, 207, 0.28);
    border-radius: 8px;
    outline: none;
    background: rgba(40, 36, 32, 0.28);
    color: var(--alfred-parchemin);
    transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.auth-field input:focus {
    border-color: var(--alfred-sable);
    background: rgba(40, 36, 32, 0.42);
    box-shadow: 0 0 0 3px rgba(213, 201, 171, 0.14);
}

.auth-submit {
    width: 100%;
    min-height: 48px;
    margin-top: 6px;
    border: 0;
    border-radius: 8px;
    background: var(--alfred-sable);
    color: var(--alfred-cacao);
    font-weight: 700;
    letter-spacing: 0.01em;
    transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.auth-submit:hover {
    background: #e6d9b9;
    box-shadow: 0 6px 16px rgba(40, 36, 32, 0.18);
    transform: translateY(-1px);
}

.auth-card .form-error {
    margin: -12px 0 20px;
    color: #f2b2a4;
    text-align: center;
}

@media (max-width: 480px) {
    .auth-page {
        padding: 24px 16px;
    }

    .auth-card {
        padding: 34px 24px 28px;
    }
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;

    gap: 24px;

    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 38px;
    line-height: 1.15;
}

.page-header p {
    margin: 8px 0 0;
    color: var(--text-secondary);
}

.button {
    min-height: 42px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    gap: 8px;

    padding: 0 16px;

    border: 1px solid transparent;
    border-radius: var(--radius-md);

    transition:
        background 160ms ease,
        color 160ms ease,
        border-color 160ms ease;
}

.button svg {
    width: 17px;
    height: 17px;
}

.button-primary {
    background: var(--alfred-cacao);
    color: var(--alfred-parchemin);
}

.button-primary:hover {
    background: var(--alfred-ebene);
}

.button-secondary {
    border-color: var(--alfred-sable);

    background: transparent;

    color: var(--alfred-cacao);
}

.button-secondary:hover {
    background: var(--alfred-avoine);
}

.filters {
    display: flex;
    gap: 10px;

    margin-bottom: 28px;
}

.input,
.select {
    height: 44px;

    border: 1px solid var(--border);
    border-radius: var(--radius-md);

    background: rgba(246, 240, 229, 0.72);

    color: var(--text-main);

    outline: none;
}

.input {
    width: 100%;
    padding: 0 14px;
}

.select {
    padding: 0 34px 0 12px;
}

.input:focus,
.select:focus {
    border-color: var(--alfred-moka);
}

.search-field {
    position: relative;
    flex: 1;
}

.search-field svg {
    position: absolute;

    left: 14px;
    top: 50%;

    width: 18px;
    height: 18px;

    transform: translateY(-50%);

    color: var(--alfred-taupe);
}

.search-field .input {
    padding-left: 42px;
}

.section-title {
    display: flex;
    align-items: baseline;

    gap: 10px;

    margin-bottom: 18px;
}

.section-title h2 {
    font-size: 24px;
}

.section-count {
    color: var(--text-muted);
    font-size: 13px;
}

.book-grid {
    display: grid;

    grid-template-columns:
        repeat(auto-fill, minmax(150px, 1fr));

    gap: 26px 20px;
}

.book-card {
    min-width: 0;
}

.book-cover {
    aspect-ratio: 2 / 3;

    overflow: hidden;

    border-radius: var(--radius-sm);

    background: var(--alfred-avoine);

    box-shadow: var(--shadow-soft);
}

.book-cover img {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}

.book-cover-placeholder {
    width: 100%;
    height: 100%;

    display: grid;
    place-items: center;

    padding: 18px;

    background: var(--alfred-sable);

    color: var(--alfred-cacao);

    text-align: center;

    font-family: "Lora", serif;
}

.book-info {
    padding-top: 10px;
}

.book-title {
    margin-bottom: 3px;

    color: var(--alfred-ebene);

    font-family: "Lora", serif;
    font-size: 15px;
    font-weight: 600;

    line-height: 1.35;
}

.book-author {
    margin-bottom: 8px;

    color: var(--text-muted);

    font-size: 12px;
    line-height: 1.35;
}

.book-meta {
    display: flex;
    flex-wrap: wrap;

    gap: 6px;
}

.badge {
    display: inline-flex;
    align-items: center;

    min-height: 25px;

    padding: 0 9px;

    border-radius: 999px;

    background: var(--alfred-avoine);

    color: var(--alfred-cacao);

    font-size: 11px;
}

.badge-owner {
    background: rgba(106, 116, 88, 0.12);
    color: var(--alfred-olive);
}

.empty-state {
    padding: 70px 20px;

    text-align: center;

    color: var(--text-secondary);
}

.empty-state h2 {
    margin-bottom: 10px;
}

.scan-panel {
    max-width: 860px;

    margin-bottom: 28px;

    padding: 28px;

    border: 1px solid var(--border);
    border-radius: var(--radius-lg);

    background: var(--surface-soft);
}

.scan-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: 20px;

    margin-bottom: 24px;
}

.scan-panel-header h2 {
    margin-top: 5px;

    font-size: 27px;
}

.eyebrow {
    display: block;

    color: var(--alfred-moka);

    font-size: 11px;
    font-weight: 700;

    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.scan-icon {
    width: 48px;
    height: 48px;

    display: grid;
    place-items: center;

    border-radius: 50%;

    background: var(--alfred-cacao);

    color: var(--alfred-parchemin);
}

.scan-icon svg {
    width: 22px;
    height: 22px;
}

.scan-input-row {
    display: grid;

    grid-template-columns: 1fr auto;

    gap: 10px;
}

.scan-input {
    height: 54px;

    font-size: 19px;

    letter-spacing: 0.04em;
}

.field-label {
    display: block;

    margin-bottom: 7px;

    color: var(--alfred-cacao);

    font-size: 13px;
    font-weight: 600;
}

.field-help {
    margin: 10px 0 0;

    color: var(--text-muted);

    font-size: 12px;
    line-height: 1.5;
}

.notice {
    max-width: 860px;

    display: flex;
    align-items: flex-start;

    gap: 12px;

    margin-bottom: 20px;

    padding: 14px 16px;

    border-radius: var(--radius-md);
}

.notice svg {
    width: 19px;
    height: 19px;

    flex: 0 0 auto;

    margin-top: 1px;
}

.notice div {
    display: flex;
    flex-direction: column;

    gap: 2px;
}

.notice span {
    font-size: 13px;
}

.notice-success {
    background: rgba(106, 116, 88, 0.14);
    color: #4D5940;
}

.notice-error {
    background: rgba(184, 102, 86, 0.13);
    color: #8F473B;
}

.book-duplicate-alert {
    max-width: 860px;
    align-items: center;
    padding: 28px;
    border: 1px solid #D8A79C;
    border-radius: var(--radius-lg);
    background: #F5E7E3;
}

.book-duplicate-alert svg {
    color: var(--alfred-terracotta);
}

.book-duplicate-alert div {
    gap: 5px;
}

.book-duplicate-alert strong {
    color: #8A4A3B;
    font-family: "Lora", serif;
    font-size: 17px;
}

.book-duplicate-alert span {
    color: var(--text-secondary);
}

.book-duplicate-alert .button {
    align-self: flex-start;
    margin-top: 7px;
}

.lookup-result {
    max-width: 980px;

    display: grid;

    grid-template-columns: 210px 1fr;

    gap: 32px;

    padding-top: 12px;
}

.lookup-cover {
    width: 100%;

    aspect-ratio: 2 / 3;

    overflow: hidden;

    border-radius: var(--radius-md);

    background: var(--alfred-avoine);

    box-shadow: var(--shadow-soft);
}

.lookup-cover img {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}

.lookup-content h2 {
    margin-top: 6px;

    font-size: 31px;

    line-height: 1.2;
}

.lookup-author {
    margin: 6px 0 24px;

    color: var(--text-secondary);
}

.manual-enrich-form {
    margin-bottom: 18px;
}

.manual-enrich-form + .book-form {
    margin-top: 18px;
}

.book-form .book-description {
    margin-top: 18px;
}

.book-form {
    padding-top: 22px;

    border-top: 1px solid var(--border);
}

.form-grid {
    display: grid;

    grid-template-columns:
        repeat(2, minmax(0, 1fr));

    gap: 18px;
}

.form-field-wide {
    grid-column: 1 / -1;
}

.form-select {
    width: 100%;
}

.form-actions {
    display: flex;
    justify-content: flex-end;

    gap: 10px;

    margin-top: 24px;
}

@media (max-width: 900px) {

    .app-shell {
        display: block;
    }

    .sidebar {
        position: static;

        width: 100%;
        height: auto;

        padding: 18px;
    }

    .sidebar-brand {
        padding: 0 4px 18px;
    }

    .brand-logo {
        width: 135px;
        height: 26px;
    }

    .sidebar-nav {
        flex-direction: row;

        overflow-x: auto;
    }

    .sidebar-footer {
        display: none;
    }

    .main-content {
        padding: 28px 20px 50px;
    }

    .page-header {
        flex-direction: column;
    }

    .filters {
        flex-direction: column;
    }
}

@media (max-width: 700px) {

    .scan-input-row {
        grid-template-columns: 1fr;
    }

    .lookup-result {
        grid-template-columns: 110px 1fr;

        gap: 18px;
    }

    .lookup-content h2 {
        font-size: 23px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-field-wide {
        grid-column: auto;
    }

    .lookup-cover {
        align-self: start;
    }
}

.choice-group {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.status-choice-group {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.choice-card {
    position: relative;
    cursor: pointer;
}

.choice-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.choice-card span {
    min-height: 46px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0 14px;

    border: 1px solid var(--alfred-sable);
    border-radius: var(--radius-md);

    background: rgba(246, 240, 229, 0.55);

    color: var(--alfred-cacao);

    font-size: 14px;
    font-weight: 500;

    transition:
        background 160ms ease,
        border-color 160ms ease,
        color 160ms ease;
}

.choice-card:hover span {
    background: var(--alfred-avoine);
}

.choice-card input:checked + span {
    border-color: var(--alfred-cacao);

    background: var(--alfred-cacao);

    color: var(--alfred-parchemin);
}

.readonly-value {
    min-height: 44px;

    display: flex;
    align-items: center;

    padding: 0 14px;

    border: 1px solid var(--border);
    border-radius: var(--radius-md);

    background: rgba(213, 201, 171, 0.22);

    color: var(--text-secondary);

    font-family: monospace;
    font-size: 14px;
}

.book-card-link {
    display: block;
}

.book-card-link .book-cover {
    transition:
        transform 160ms ease,
        box-shadow 160ms ease;
}

.book-card-link:hover .book-cover {
    transform: translateY(-3px);

    box-shadow:
        0 7px 18px rgba(40, 36, 32, 0.12);
}

.book-card-link:hover .book-title {
    color: var(--alfred-moka);
}

@media (max-width: 700px) {
    .choice-group,
    .status-choice-group {
        grid-template-columns: 1fr 1fr;
    }
}

.profile-switcher {
    display: flex;
    flex-direction: column;
    gap: 6px;

    margin-top: 18px;
    padding-top: 16px;

    border-top: 1px solid rgba(242, 236, 207, 0.12);
}

.profile-switcher-item {
    display: flex;
    align-items: center;
    gap: 10px;

    padding: 8px 10px;

    border-radius: var(--radius-md);

    color: rgba(242, 236, 207, 0.68);
}

.profile-switcher-item:hover {
    background: rgba(242, 236, 207, 0.06);
    color: var(--alfred-parchemin);
}

.profile-switcher-item.active {
    background: rgba(152, 140, 122, 0.16);
    color: var(--alfred-parchemin);
}

.profile-switcher-item .profile-avatar {
    width: 30px;
    height: 30px;

    display: grid;
    place-items: center;

    flex: 0 0 auto;

    border-radius: 50%;

    background: var(--alfred-moka);

    font-size: 12px;
    font-weight: 700;
}

.profile-switcher-item .profile-content {
    display: flex;
    flex-direction: column;
    gap: 1px;

    min-width: 0;
}

.profile-switcher-item .profile-content strong {
    font-size: 12px;
}

.profile-switcher-item .profile-content span {
    font-size: 10px;
    color: rgba(242, 236, 207, 0.48);
}

.book-progress {
    margin-top: 10px;
}

.book-progress-track {
    height: 4px;

    overflow: hidden;

    border-radius: 999px;

    background: var(--alfred-sable);
}

.book-progress-bar {
    height: 100%;

    border-radius: 999px;

    background: var(--alfred-moka);
}

.book-progress > span {
    display: block;

    margin-top: 5px;

    color: var(--text-muted);

    font-size: 10px;
}

/* ---------------------------------------------------------
   COVER PICKER
--------------------------------------------------------- */

.alfred-cover-picker {
    width: 100%;
    padding-top: 6px;
    padding-bottom: 12px;
}

.alfred-cover-picker__header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 20px;
}

.alfred-cover-picker__header h3 {
    margin: 4px 0 0;
    font-family: "Lora", serif;
    font-size: 22px;
    line-height: 1.2;
    color: var(--alfred-cacao);
}

.alfred-cover-picker__header p {
    margin: 6px 0 0;
    max-width: 560px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.alfred-cover-picker__count {
    flex-shrink: 0;
    padding-bottom: 2px;
    font-size: 11px;
    color: var(--text-muted);
}

.alfred-cover-picker__grid {
    display: grid;
    grid-template-columns: repeat(
        auto-fill,
        minmax(130px, 150px)
    );
    gap: 20px;
    align-items: start;
}

.alfred-cover-option {
    display: block;
    min-width: 0;
    cursor: pointer;
}

.alfred-cover-option__input {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.alfred-cover-option__card {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 10px;
}

.alfred-cover-option__preview {
    position: relative;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    aspect-ratio: 2 / 3;

    overflow: hidden;

    box-sizing: border-box;

    border: 2px solid transparent;
    border-radius: var(--radius-md);

    background: var(--alfred-avoine);

    transition:
        border-color 150ms ease,
        box-shadow 150ms ease,
        transform 150ms ease;
}

.alfred-cover-option__preview img {
    display: block !important;

    width: 100% !important;
    height: 100% !important;

    max-width: none !important;
    max-height: none !important;

    margin: 0 !important;

    object-fit: contain !important;

    background: var(--alfred-avoine);
}

.alfred-cover-option:hover
.alfred-cover-option__preview {
    transform: translateY(-2px);
    border-color: var(--alfred-taupe);
}

.alfred-cover-option__input:checked
+ .alfred-cover-option__card
.alfred-cover-option__preview {
    border-color: var(--alfred-cacao);

    box-shadow:
        0 0 0 3px var(--alfred-creme),
        0 0 0 5px var(--alfred-cacao);
}

.alfred-cover-option__check {
    position: absolute;
    top: 8px;
    right: 8px;

    display: none;
    align-items: center;
    justify-content: center;

    width: 26px;
    height: 26px;

    border-radius: 50%;

    background: var(--alfred-cacao);
    color: var(--alfred-parchemin);

    box-shadow:
        0 2px 8px rgba(40, 36, 32, 0.22);
}

.alfred-cover-option__check svg {
    width: 14px;
    height: 14px;
    stroke-width: 2.5;
}

.alfred-cover-option__input:checked
+ .alfred-cover-option__card
.alfred-cover-option__check {
    display: flex;
}

.alfred-cover-option__source {
    display: block;

    width: 100%;

    color: var(--alfred-cacao);

    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;

    text-align: center;
}

.alfred-cover-option__preview--empty {
    flex-direction: column;
    gap: 8px;

    border: 1px dashed var(--alfred-taupe);

    background: rgba(230, 220, 196, 0.4);

    color: var(--alfred-taupe);

    font-size: 11px;
    font-weight: 600;
}

.alfred-cover-option__preview--empty svg {
    width: 26px;
    height: 26px;
    stroke-width: 1.5;
}

.alfred-cover-option__input:checked
+ .alfred-cover-option__card
.alfred-cover-option__preview--empty {
    border: 2px solid var(--alfred-cacao);
    color: var(--alfred-cacao);
}

@media (max-width: 700px) {

    .alfred-cover-picker__header {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    .alfred-cover-picker__grid {
        grid-template-columns:
            repeat(
                2,
                minmax(0, 1fr)
            );

        gap: 16px;
    }

}

.reading-section-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;

    margin-bottom: 16px;
    padding-top: 8px;
}

.reading-section-header h3 {
    margin-top: 4px;

    font-size: 21px;
}

.reading-profile-state {
    color: var(--text-muted);

    font-size: 11px;
}

.reading-page-row {
    display: flex;
    align-items: center;

    gap: 12px;
}

.reading-page-row .input {
    max-width: 150px;
}

.reading-page-total {
    color: var(--text-secondary);

    font-size: 13px;
}

@media (max-width: 700px) {
    .reading-section-header {
        flex-direction: column;
        align-items: flex-start;

        gap: 4px;
    }

    .reading-page-row {
        align-items: flex-start;
        flex-direction: column;
    }
}

.badge-muted {
    background: rgba(152, 140, 122, 0.12);
    color: var(--alfred-taupe);
}
