/* ============================================
   Thème espace privé — tokens shadcn/ui (neutral)
   Source : https://ui.shadcn.com/docs/theming
   Pas de React : mapping CSS vers les classes existantes.
   Ne s’applique qu’à /espace (index.php) — pas à /publique.
   ============================================ */

:root {
    /* Tokens shadcn (neutral light) */
    --radius: 0.625rem;
    --background: oklch(1 0 0);
    --foreground: oklch(0.145 0 0);
    --card: oklch(1 0 0);
    --card-foreground: oklch(0.145 0 0);
    --popover: oklch(1 0 0);
    --popover-foreground: oklch(0.145 0 0);
    --primary: oklch(0.205 0 0);
    --primary-foreground: oklch(0.985 0 0);
    --secondary: oklch(0.97 0 0);
    --secondary-foreground: oklch(0.205 0 0);
    --muted: oklch(0.97 0 0);
    --muted-foreground: oklch(0.556 0 0);
    --accent: oklch(0.97 0 0);
    --accent-foreground: oklch(0.205 0 0);
    --destructive: oklch(0.577 0.245 27.325);
    --border: oklch(0.922 0 0);
    --input: oklch(0.922 0 0);
    --ring: oklch(0.708 0 0);
    --sidebar: oklch(0.985 0 0);
    --sidebar-foreground: oklch(0.145 0 0);
    --sidebar-primary: oklch(0.205 0 0);
    --sidebar-primary-foreground: oklch(0.985 0 0);
    --sidebar-accent: oklch(0.97 0 0);
    --sidebar-accent-foreground: oklch(0.205 0 0);
    --sidebar-border: oklch(0.922 0 0);
    --sidebar-ring: oklch(0.708 0 0);

    /* Alias app existante → tokens shadcn */
    --color-bg: var(--background);
    --color-bg-light: var(--muted);
    --color-bg-card: var(--card);
    --color-bg-hover: var(--accent);

    --color-primary: var(--primary);
    --color-primary-light: oklch(0.269 0 0);
    --color-primary-dark: oklch(0.145 0 0);

    --color-accent: var(--accent-foreground);
    --color-accent-light: var(--muted-foreground);

    --color-success: oklch(0.55 0.15 145);
    --color-error: var(--destructive);
    --color-warning: oklch(0.7 0.15 85);

    --color-text: var(--foreground);
    --color-text-muted: var(--muted-foreground);
    --color-text-dim: oklch(0.65 0 0);

    --color-border: var(--border);
    --color-border-light: var(--muted);

    --font-display: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    --radius-sm: calc(var(--radius) * 0.6);
    --radius-md: calc(var(--radius) * 0.8);
    --radius-lg: var(--radius);
    --radius-xl: calc(var(--radius) * 1.4);

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.06);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.06);

    --sidebar-width: 260px;
    --focus-ring: 0 0 0 2px var(--background), 0 0 0 4px var(--ring);
}

/* ---------- Base ---------- */
body {
    font-family: var(--font-body);
    background-color: var(--background);
    color: var(--foreground);
    background-image: none;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Sidebar (shadcn Sidebar) ---------- */
.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-foreground);
    border-right: 1px solid var(--sidebar-border);
    box-shadow: none;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.logo-text {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: var(--sidebar-foreground);
    letter-spacing: -0.025em;
}

.logo-icon {
    filter: none;
    font-size: 1.25rem;
}

.sidebar-nav {
    padding: 0.5rem;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.nav-section {
    margin: 0.75rem 0 0.25rem;
    padding: 0 0.5rem;
}

.nav-section-label {
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted-foreground);
}

.nav-item,
.nav-group-toggle {
    color: var(--sidebar-foreground);
    opacity: 0.85;
    border-left: none;
    border-radius: var(--radius-md);
    margin: 0 0 1px;
    padding: 0.5rem 0.65rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.nav-item:hover,
.nav-group-toggle:hover {
    background-color: var(--sidebar-accent);
    color: var(--sidebar-accent-foreground);
    opacity: 1;
}

.nav-item.active,
.nav-group-toggle.active {
    background-color: var(--sidebar-accent);
    color: var(--sidebar-accent-foreground);
    border-left-color: transparent;
    font-weight: 600;
    opacity: 1;
}

.nav-group-toggle--section,
.nav-group-toggle--section:hover,
.nav-group-toggle--section.active {
    background: transparent;
    color: var(--muted-foreground);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 1;
    padding: 0.65rem 0.5rem 0.3rem;
}

.nav-group-toggle--section:hover,
.nav-group-toggle--section.active {
    color: var(--sidebar-foreground);
}

.nav-group.open > .nav-group-items {
    display: block;
}

.nav-subitem {
    padding-left: 2rem;
    font-size: 0.8125rem;
}

.sidebar-footer {
    border-top: 1px solid var(--sidebar-border);
    padding: 0.75rem;
    background: var(--sidebar);
}

.sidebar-user {
    color: var(--sidebar-foreground);
}

.stat-mini .stat-value {
    color: var(--sidebar-foreground);
    font-weight: 600;
}

.stat-mini .stat-label {
    color: var(--muted-foreground);
}

/* ---------- Main ---------- */
.main-content {
    background: var(--background);
}

.view-header {
    border-bottom: 1px solid var(--border);
    background: var(--card);
    padding: 1rem 1.5rem;
    margin: 0 0 1.25rem;
    border-radius: 0;
}

.view-header h1 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    color: var(--foreground);
}

.view-subtitle {
    color: var(--muted-foreground);
    font-size: 0.875rem;
}

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    color: var(--card-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
}

.card-title {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--card-foreground);
    margin-bottom: 0.75rem;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: none;
    border-color: var(--border);
}

.stat-number {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--foreground);
}

.stat-text {
    color: var(--muted-foreground);
}

/* ---------- Forms ---------- */
.form-group label,
label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--foreground);
}

.form-control,
select.form-control,
textarea.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="file"],
select,
textarea {
    background: var(--background);
    border: 1px solid var(--input);
    border-radius: var(--radius-md);
    color: var(--foreground);
    font-size: 0.875rem;
    min-height: 2.5rem;
    padding: 0.5rem 0.75rem;
    box-shadow: var(--shadow-sm);
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.form-control:focus,
select.form-control:focus,
textarea.form-control:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--ring);
    box-shadow: var(--focus-ring);
}

.form-control::placeholder {
    color: var(--muted-foreground);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    padding: 0.5rem 1rem;
    min-height: 2.5rem;
    border: 1px solid transparent;
    box-shadow: var(--shadow-sm);
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease, opacity 150ms ease;
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-foreground);
    border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
    background: oklch(0.269 0 0);
    border-color: oklch(0.269 0 0);
    color: var(--primary-foreground);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--secondary-foreground);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--accent);
    color: var(--accent-foreground);
}

.btn-success {
    background: var(--color-success);
    color: #fff;
    border-color: var(--color-success);
}

.btn-danger {
    background: var(--destructive);
    color: #fff;
    border-color: var(--destructive);
}

.btn-danger:hover:not(:disabled) {
    filter: brightness(0.92);
}

.btn-warning {
    background: var(--secondary);
    color: oklch(0.45 0.1 70);
    border-color: var(--border);
}

.btn-warning:hover {
    background: var(--muted);
}

.btn-small,
.btn-tiny {
    min-height: 2rem;
    padding: 0.35rem 0.7rem;
    font-size: 0.8125rem;
}

.btn-large {
    min-height: 2.75rem;
    padding: 0.65rem 1.25rem;
}

.btn-link {
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--muted-foreground);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.btn-link:hover {
    color: var(--foreground);
}

.btn-search-isbn {
    background: var(--primary);
    color: var(--primary-foreground);
}

/* ---------- Admin tabs ---------- */
.admin-section-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 1.25rem;
}

.admin-section-tab {
    box-shadow: none !important;
    border: 1px solid transparent !important;
    background: transparent !important;
    color: var(--muted-foreground) !important;
}

.admin-section-tab:hover:not(:disabled) {
    background: var(--background) !important;
    color: var(--foreground) !important;
}

.admin-section-tab.active {
    background: var(--background) !important;
    color: var(--foreground) !important;
    border-color: var(--border) !important;
    box-shadow: var(--shadow-sm) !important;
}

.admin-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border);
}

.admin-badge--ok {
    background: oklch(0.96 0.03 145);
    color: oklch(0.4 0.1 145);
    border-color: oklch(0.9 0.05 145);
}

.admin-badge--ko {
    background: oklch(0.96 0.02 25);
    color: var(--destructive);
    border-color: oklch(0.9 0.04 25);
}

.admin-backups-table th,
.admin-backups-table td {
    border-bottom: 1px solid var(--border);
}

.admin-content .card {
    margin-bottom: 1rem;
}

/* ---------- Tables ---------- */
.table-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--card);
    overflow: auto;
}

table {
    border-collapse: collapse;
    width: 100%;
}

th {
    background: var(--muted);
    color: var(--muted-foreground);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

td {
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

tr:hover td {
    background: var(--muted);
}

/* ---------- Modals / popovers ---------- */
.modal-backdrop {
    background: rgb(9 9 11 / 0.45);
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--popover);
    color: var(--popover-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
}

.modal-close,
.modal-close--book {
    border-radius: var(--radius-md);
    color: var(--muted-foreground);
}

.modal-close:hover,
.modal-close--book:hover {
    background: var(--accent);
    color: var(--accent-foreground);
}

.modal-book-title {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.02em;
}

/* (layout modal livre détaillé plus bas) */

/* ---------- Toasts ---------- */
.toast {
    background: var(--popover);
    color: var(--popover-foreground);
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.toast.success { border-left-color: var(--color-success); }
.toast.error { border-left-color: var(--destructive); }
.toast.warning { border-left-color: var(--color-warning); }

/* ---------- Auth gate ---------- */
.auth-gate {
    background: var(--background);
}

.auth-gate-card {
    background: var(--card);
    color: var(--card-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    padding: 1.75rem;
    max-width: 24rem;
}

.auth-gate-brand h1 {
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    color: var(--foreground);
}

.auth-gate-logo {
    font-size: 1.5rem;
}

.auth-gate-back a {
    color: var(--muted-foreground);
    text-decoration: none;
    font-size: 0.875rem;
}

.auth-gate-back a:hover {
    color: var(--foreground);
    text-decoration: underline;
}

.auth-remember {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    margin: 0.15rem 0 1rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.875rem;
    color: var(--foreground);
    line-height: 1.35;
}

.auth-remember input {
    margin-top: 0.15rem;
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.auth-remember small {
    display: block;
    color: var(--muted-foreground);
    font-size: 0.75rem;
    font-weight: 400;
}

.app-lock-overlay {
    background: color-mix(in oklch, var(--background) 92%, transparent);
}

.app-lock-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    background: var(--card);
}

/* ---------- Misc ---------- */
.text-muted {
    color: var(--muted-foreground) !important;
}

.badge,
.stock-badge,
.status-badge {
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.sidebar-backdrop {
    background: rgb(9 9 11 / 0.4);
}

.search-bar,
.toolbar,
.filters-bar {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
}

/* Champ recherche inventaire — une seule bordure, icône hors du texte */
.search-box {
    position: relative;
    width: 100%;
}

.search-box input[type="text"],
.search-box input {
    width: 100% !important;
    max-width: 100%;
    min-height: 2.5rem;
    margin: 0;
    padding: 0.55rem 0.85rem 0.55rem 2.55rem !important;
    background: var(--background);
    border: 1px solid var(--input) !important;
    border-radius: var(--radius-md);
    box-shadow: none !important;
    outline: none;
    color: var(--foreground);
    font-size: 0.875rem;
    line-height: 1.35;
    transition: border-color 150ms ease, box-shadow 150ms ease;
    -webkit-appearance: none;
    appearance: none;
}

.search-box input[type="text"]:focus,
.search-box input:focus {
    width: 100% !important;
    border-color: var(--ring) !important;
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 25%, transparent) !important;
    outline: none;
}

.search-box .search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
    pointer-events: none;
    opacity: 0.45;
    font-size: 0.9rem;
    line-height: 1;
}

.inventory-table,
.books-grid .book-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}

code {
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.1rem 0.35rem;
    font-size: 0.8125rem;
}

.mobile-topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.mobile-topbar-brand strong {
    font-weight: 600;
    letter-spacing: -0.02em;
}

.btn-toggle-sidebar {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--background);
}

.isbn-input-shell {
    background: var(--background);
    border: 1px solid var(--input);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.isbn-input-shell:focus-within {
    border-color: var(--ring);
    box-shadow: var(--focus-ring);
}

.import-status--pending,
.import-status--searching {
    background: var(--muted);
    color: var(--muted-foreground);
}

.import-status--ok {
    background: oklch(0.96 0.03 145);
    color: oklch(0.4 0.1 145);
}

.import-status--exists {
    background: oklch(0.97 0.03 95);
    color: oklch(0.45 0.1 70);
}

.import-status--notfound,
.import-status--timeout,
.import-status--error {
    background: oklch(0.96 0.02 25);
    color: var(--destructive);
}

.import-status--added {
    background: oklch(0.96 0.02 250);
    color: oklch(0.4 0.1 250);
}

.transfer-scan-feedback--ok { color: oklch(0.4 0.1 145); }
.transfer-scan-feedback--warn { color: oklch(0.45 0.1 70); }
.transfer-scan-feedback--error { color: var(--destructive); }

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
}

/* ---------- Job progress overlay ---------- */
.job-progress-card {
    background: var(--popover) !important;
    color: var(--popover-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    min-width: min(22rem, 92vw);
    max-width: 28rem;
    padding: 1.5rem !important;
}

.loading-overlay-backdrop {
    background: rgb(9 9 11 / 0.45);
    backdrop-filter: blur(2px);
}

.job-progress-track {
    margin-top: 1rem;
    height: 0.5rem;
    width: 100%;
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.job-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 999px;
    transition: width 0.35s ease;
}

.job-progress-track.is-indeterminate .job-progress-bar {
    width: 40% !important;
    animation: job-progress-slide 1.1s ease-in-out infinite;
}

@keyframes job-progress-slide {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(280%); }
}

.job-progress-meta {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.65rem;
    font-size: 0.8rem;
    color: var(--muted-foreground);
}

.job-progress-cancel {
    margin-top: 1rem;
}

.loading-spinner {
    border-color: var(--border);
    border-top-color: var(--primary);
}

/* ============================================
   Modal livre — layout shadcn (refonte)
   ============================================ */

.modal.modal--book {
    padding: 0.75rem;
    align-items: center;
    justify-content: center;
}

.modal-content.modal-content--book {
    max-width: min(980px, 100%);
    width: 100%;
    height: min(94dvh, 94vh);
    max-height: min(94dvh, 94vh);
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--card);
    color: var(--card-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    animation: modalBookIn 0.22s ease-out;
}

@keyframes modalBookIn {
    from { opacity: 0; transform: translateY(10px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-content--book .modal-book-root {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.modal-book-shell {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
    height: 100%;
}

.modal-book-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 1.25rem 1.5rem 1rem;
}

.modal-book-loading {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 1.5rem;
    padding: 1.25rem 1.5rem;
    align-items: start;
}

.modal-book-skeleton-cover {
    width: 100%;
    aspect-ratio: 2 / 3;
    border-radius: var(--radius-lg);
    background: linear-gradient(90deg, var(--muted) 25%, var(--accent) 50%, var(--muted) 75%);
    background-size: 200% 100%;
    animation: modalSkeleton 1.2s ease-in-out infinite;
}

.modal-book-skeleton-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-top: 0.35rem;
}

.modal-book-skeleton-line {
    height: 0.9rem;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--muted) 25%, var(--accent) 50%, var(--muted) 75%);
    background-size: 200% 100%;
    animation: modalSkeleton 1.2s ease-in-out infinite;
    width: 100%;
}

.modal-book-skeleton-line--sm { width: 28%; height: 0.7rem; }
.modal-book-skeleton-line--lg { width: 72%; height: 1.35rem; }

.modal-book-skeleton-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin: 0.35rem 0;
}

.modal-book-skeleton-stats span {
    height: 3.2rem;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, var(--muted) 25%, var(--accent) 50%, var(--muted) 75%);
    background-size: 200% 100%;
    animation: modalSkeleton 1.2s ease-in-out infinite;
}

@keyframes modalSkeleton {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.modal-close--book {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 999px;
    background: var(--background);
    border: 1px solid var(--border);
    color: var(--muted-foreground);
    font-size: 1.35rem;
    box-shadow: var(--shadow-sm);
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close--book:hover {
    background: var(--accent);
    color: var(--accent-foreground);
}

.modal-content--book {
    position: relative;
}

.modal-book {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 1.75rem;
    align-items: start;
}

.modal-book-media {
    position: sticky;
    top: 0;
    width: 220px;
    max-width: 100%;
}

.modal-book-cover-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 2 / 3;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--muted);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.modal-book-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    display: block;
    border-radius: 0;
    box-shadow: none;
}

.modal-book-cover--form {
    width: 100%;
    height: 100%;
    margin: 0;
}

.modal-cover-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: color-mix(in oklch, var(--background) 92%, transparent);
    color: var(--foreground);
    border: 1px solid var(--border);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.modal-cover-nav:hover {
    background: var(--background);
    color: var(--foreground);
}

.modal-cover-prev { left: 0.45rem; }
.modal-cover-next { right: 0.45rem; }

.modal-cover-counter {
    position: absolute;
    bottom: 0.45rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    background: rgb(9 9 11 / 0.72);
    color: #fff;
    border-radius: 999px;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    padding: 0.28rem 0.65rem;
}

.modal-book-cover-wrap--zoomable .modal-book-cover {
    cursor: zoom-in;
}

.modal-cover-zoom {
    position: absolute;
    top: 0.45rem;
    right: 0.45rem;
    z-index: 3;
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: color-mix(in oklch, var(--background) 92%, transparent);
    color: var(--foreground);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.modal-cover-zoom:hover {
    background: var(--background);
}

.modal-photo-bg-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.65rem;
    justify-content: center;
}

.modal-photo-bg-tools .btn {
    font-size: 0.78rem;
}

/* Lightbox photos (agrandissement) — au-dessus de .modal (1000) et loading (9999) */
.photo-lightbox {
    position: fixed !important;
    inset: 0;
    z-index: 10050 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(9, 9, 11, 0.92);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 1.25rem;
}

.photo-lightbox.hidden,
.photo-lightbox[hidden] {
    display: none !important;
}

body.photo-lightbox-open #book-modal {
    /* Évite que le panneau livre reste peint au-dessus du lightbox */
    z-index: 1000;
    pointer-events: none;
}

.photo-lightbox-img {
    max-width: min(96vw, 1200px);
    max-height: min(86vh, 900px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    background: rgb(0 0 0 / 0.25);
}

.photo-lightbox-close {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    z-index: 2;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid rgb(255 255 255 / 0.2);
    border-radius: 999px;
    background: rgb(9 9 11 / 0.55);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.photo-lightbox-close:hover {
    background: rgb(9 9 11 / 0.8);
}

.photo-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 2.75rem;
    height: 2.75rem;
    border: 1px solid rgb(255 255 255 / 0.2);
    border-radius: 999px;
    background: rgb(9 9 11 / 0.55);
    color: #fff;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.photo-lightbox-nav:hover {
    background: rgb(9 9 11 / 0.8);
}

.photo-lightbox-nav.hidden {
    display: none !important;
}

.photo-lightbox-prev { left: 0.85rem; }
.photo-lightbox-next { right: 0.85rem; }

.photo-lightbox-footer {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
}

.photo-lightbox-counter {
    display: inline-block;
    background: rgb(9 9 11 / 0.7);
    color: #fff;
    border-radius: 999px;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    padding: 0.4rem 0.85rem;
}

body.photo-lightbox-open {
    overflow: hidden;
}

@media (max-width: 640px) {
    .photo-lightbox-nav {
        width: 2.35rem;
        height: 2.35rem;
        font-size: 1.4rem;
    }
    .photo-lightbox-prev { left: 0.4rem; }
    .photo-lightbox-next { right: 0.4rem; }
    .photo-lightbox-img {
        max-height: 78vh;
    }
}

.modal-book-hero {
    margin: 0 0 1.25rem;
    padding: 0 2.25rem 1.1rem 0;
    border-bottom: 1px solid var(--border);
}

.modal-book-hero-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.55rem;
}

.modal-book-id {
    font-family: ui-monospace, "Cascadia Mono", monospace;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted-foreground);
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.2rem 0.5rem;
}

.modal-status {
    display: inline-flex;
    align-items: center;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-radius: var(--radius-sm);
    padding: 0.22rem 0.55rem;
    border: 1px solid var(--border);
}

.modal-status--sold {
    background: oklch(0.96 0.02 25);
    color: var(--destructive);
    border-color: oklch(0.9 0.04 25);
}

.modal-status--retired {
    background: var(--muted);
    color: var(--muted-foreground);
}

.modal-status--discarded {
    background: oklch(0.97 0.03 95);
    color: oklch(0.45 0.1 70);
    border-color: oklch(0.9 0.05 95);
}

.modal-status--edit {
    background: var(--secondary);
    color: var(--secondary-foreground);
}

.modal-book-title {
    font-family: var(--font-display);
    font-size: clamp(1.35rem, 2.2vw, 1.85rem);
    font-weight: 600;
    letter-spacing: -0.025em;
    line-height: 1.2;
    color: var(--foreground);
    margin: 0 0 0.35rem;
}

.modal-book-author {
    font-size: 1rem;
    font-weight: 500;
    color: var(--muted-foreground);
    margin: 0 0 0.85rem;
}

.modal-copy-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin: 0;
}

.modal-copy-btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--background);
    color: var(--muted-foreground);
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 500;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.modal-copy-btn:hover {
    background: var(--accent);
    color: var(--accent-foreground);
}

.modal-copy-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.modal-copy-btn.is-copied {
    background: oklch(0.96 0.03 145);
    border-color: oklch(0.9 0.05 145);
    color: oklch(0.4 0.1 145);
}

.modal-book-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    margin: 0 0 1.35rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--background);
    overflow: hidden;
}

.modal-stat {
    margin: 0;
    padding: 0.85rem 1rem;
    border-right: 1px solid var(--border);
    border: none;
    border-right: 1px solid var(--border);
    background: transparent;
    border-radius: 0;
    min-width: 0;
}

.modal-stat:last-child {
    border-right: none;
}

.modal-stat dt {
    margin: 0 0 0.25rem;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted-foreground);
}

.modal-stat dd {
    margin: 0;
}

.modal-stat-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--foreground);
    word-break: break-word;
}

.modal-stat-value--accent {
    color: var(--foreground);
    font-size: 1.15rem;
    font-weight: 700;
}

.modal-book-block {
    margin: 0 0 1.25rem;
}

.modal-book-block-title {
    display: block;
    margin: 0 0 0.7rem;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted-foreground);
}

.modal-book-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem 1.5rem;
    margin: 0;
    padding: 0;
}

.modal-fact {
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr);
    gap: 0.5rem;
    align-items: baseline;
    margin: 0;
    padding: 0.35rem 0;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
}

.modal-fact dt {
    margin: 0;
    font-size: 0.78rem;
    color: var(--muted-foreground);
}

.modal-fact dd {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--foreground);
    word-break: break-word;
}

.modal-book-notes {
    margin: 0;
    padding: 0.9rem 1rem;
    font-size: 0.95rem;
    line-height: 1.55;
    color: var(--muted-foreground);
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    white-space: pre-wrap;
}

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

.modal-meta-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
}

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

.modal-meta-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted-foreground);
}

.modal-book--edit .form-control {
    background: var(--background);
    border-color: var(--input);
}

.modal-book-notes-input {
    margin-top: 0;
    min-height: 5rem;
    resize: vertical;
}

.modal-ai-panel {
    margin: 0 0 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--muted);
    box-shadow: none;
    overflow: hidden;
}

.modal-ai-panel--empty {
    background: var(--background);
    border-style: dashed;
}

.modal-ai-panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid var(--border);
}

.modal-ai-panel-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--foreground);
}

.modal-ai-panel-desc {
    margin: 0.2rem 0 0;
    font-size: 0.82rem;
    color: var(--muted-foreground);
}

.modal-ai-panel-body {
    padding: 0.9rem 1.1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.modal-ai-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted-foreground);
}

.modal-ai-value {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--foreground);
}

.modal-ai-panel.is-ai-loading {
    position: relative;
    pointer-events: none;
}

.modal-ai-panel.is-ai-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: color-mix(in oklch, var(--card) 72%, transparent);
    backdrop-filter: blur(1px);
    z-index: 1;
}

.modal-ai-panel.is-ai-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 2;
    width: 2rem;
    height: 2rem;
    margin: -1rem 0 0 -1rem;
    border-radius: 999px;
    border: 2px solid var(--border);
    border-top-color: var(--foreground);
    animation: modalAiSpin 0.75s linear infinite;
}

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

.modal-book-footer {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex-shrink: 0;
    margin: 0;
    padding: 0.9rem 1.5rem 1.15rem;
    border-top: 1px solid var(--border);
    background: var(--card);
    box-shadow: 0 -4px 16px rgb(0 0 0 / 0.04);
}

.modal-book-footer--edit {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
}

.modal-btn-primary {
    width: 100%;
    justify-content: center;
    min-height: 2.75rem;
    font-weight: 600;
    background: var(--primary);
    color: var(--primary-foreground);
    border-radius: var(--radius-md);
}

.modal-footer-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.modal-footer-danger {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.85rem;
    padding-top: 0.35rem;
}

.btn-ghost-danger {
    appearance: none;
    background: transparent;
    border: none;
    padding: 0.25rem 0;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--muted-foreground);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: transparent;
}

.btn-ghost-danger:hover {
    color: var(--destructive);
    text-decoration-color: currentColor;
}

.modal--confirm {
    z-index: 1100;
}

.modal-content--confirm {
    max-width: 420px;
    width: calc(100% - 2rem);
    padding: 1.35rem 1.4rem 1.25rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
}

.app-confirm-title {
    margin: 0 0 0.55rem;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--foreground);
}

.app-confirm-message {
    margin: 0 0 1.25rem;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--muted-foreground);
}

.app-confirm-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.55rem;
}

@media (max-width: 820px) {
    .modal-book {
        grid-template-columns: 1fr;
        gap: 1.15rem;
    }

    .modal-book-media {
        position: static;
        max-width: 180px;
        margin: 0 auto;
    }

    .modal-book-loading {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .modal-book-skeleton-cover { max-width: 160px; }
    .modal-book-skeleton-body { width: 100%; }

    .modal-book-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .modal-stat:nth-child(2) { border-right: none; }
    .modal-stat:nth-child(1),
    .modal-stat:nth-child(2) {
        border-bottom: 1px solid var(--border);
    }

    .modal-book-facts,
    .modal-edit-grid {
        grid-template-columns: 1fr;
    }

    .modal-fact {
        grid-template-columns: 6.5rem minmax(0, 1fr);
    }

    .modal-footer-tools { flex-direction: column; }
    .modal-footer-tools .btn {
        width: 100%;
        justify-content: center;
    }

    .modal-book-footer--edit { flex-direction: column; }
    .modal-book-footer--edit .btn {
        width: 100%;
        justify-content: center;
    }

    .modal-ai-panel-head { flex-direction: column; }
    .modal-ai-panel-head .btn { align-self: stretch; }

    .app-confirm-actions { flex-direction: column-reverse; }
    .app-confirm-actions .btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .modal-book-scroll {
        padding: 1rem 1rem 0.85rem;
    }

    .modal-book-footer {
        padding: 0.8rem 1rem 1rem;
    }

    .modal-book-hero {
        padding-right: 1.75rem;
    }

    .modal-fact {
        grid-template-columns: 1fr;
        gap: 0.15rem;
    }

    .modal-book-skeleton-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

