/* =====================================================================
   Book detail page (Selected.php). Everything is scoped under
   .book-detail-page; nav, footer and base styles come from common.css.
   ===================================================================== */

.book-detail-page {
    --panel-bg: #a9a9a9; /* "darkgray" book panel of the original design */
    --panel-text: #111;
    --star-on: #e8a200;
    --star-off: #c9c9c9;
    display: grid;
    gap: 24px;
}

.book-detail-page h2 {
    color: var(--color-chrome);
}

/* Fragment targets (PRG redirects) keep a little context above them. */
.book-detail-page [id] {
    scroll-margin-top: 16px;
}

.book-detail-page #book {
    scroll-margin-top: 140px;
}

/* ---------------------------------------------------------------------
   Book panel: cover first, details next (mirrored in right-to-left pages)
   --------------------------------------------------------------------- */

.book-panel {
    display: grid;
    grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
    gap: 24px 32px;
    align-items: start;
    padding: 24px;
    border-radius: var(--radius);
    background-color: var(--panel-bg);
    color: var(--panel-text);
}

.book-cover .pic {
    display: block;
    width: 100%;
    height: auto;
    border-radius: var(--radius);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    background-color: #fff;
}

.cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 380 / 605;
    background: linear-gradient(160deg, #e9e9e9, #cfcfcf);
    color: #5c5c5c;
    font-size: 3rem;
}

.book-info {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.book-heading {
    display: grid;
    gap: 4px;
}

.book-title {
    margin: 0;
    font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem);
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.book-author {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.book-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 20px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 1.05rem;
}

.book-meta li {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 6px;
}

.meta-label {
    font-weight: 700;
}

.book-panel a {
    color: #0d2a2e;
    font-weight: 700;
}

.book-panel a:hover {
    color: #000;
}

.genre-link {
    display: inline-block;
    padding: 2px 12px;
    border-radius: var(--radius-lg);
    background-color: var(--color-primary);
    text-decoration: none;
}

.book-panel .genre-link,
.book-panel .genre-link:hover {
    color: #fff;
}

.book-panel .genre-link:hover {
    background-color: var(--color-primary-hover);
}

/* Shared star graphic: grey stars with a gold overlay clipped to the rating. */
.stars {
    position: relative;
    display: inline-block;
    color: var(--star-off);
    font-size: 1.15rem;
    line-height: 1;
    letter-spacing: 2px;
    white-space: nowrap;
}

.stars-fill {
    position: absolute;
    top: 0;
    inset-inline-start: 0;
    bottom: 0;
    overflow: hidden;
    color: var(--star-on);
}

.book-panel .stars {
    color: #e2e2e2;
    text-shadow: 0 0 1px rgba(0, 0, 0, 0.5);
}

/* Bordered add-to-cart box */
.add-to-cart-box {
    display: grid;
    gap: 10px;
    max-width: 520px;
    padding: 16px 20px;
    border: 1px solid #000;
    border-radius: var(--radius-sm);
}

.book-price {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.add-to-cart-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
}

.quantity-field {
    display: grid;
    gap: 4px;
}

.quantity-field label {
    font-weight: 700;
}

.quantity-field .form-control {
    width: 96px;
    border-color: #444;
}

.btn-danger.cart-button {
    flex: 1 1 200px;
    max-width: 260px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Letter spacing pulls joined Arabic letters apart. */
[dir="rtl"] .btn-danger.cart-button {
    letter-spacing: normal;
}

.btn-danger.cart-button:disabled,
.btn-danger.cart-button:disabled:hover {
    background-color: #6b6b6b;
    cursor: not-allowed;
}

/* Availability: "In stock", "Only N left" or "Out of stock". */
.book-detail-page .stock-badge {
    justify-self: start;
    margin: 0;
    padding: 2px 12px;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    font-weight: 700;
    background: var(--color-success-bg);
    color: var(--color-success-text);
}

.book-detail-page .stock-badge.stock-low {
    background: #fff4e5;
    color: #7a4100;
}

.book-detail-page .stock-badge.stock-out {
    background: var(--color-error-bg);
    color: var(--color-error-text);
}

.book-item .stock-badge {
    display: inline-block;
    margin-top: 6px;
    font-size: 0.8rem;
}

.stock-note {
    margin: 0;
    font-weight: 600;
}

.add-to-cart-box .field-error,
.cart-note {
    margin: 0;
}

/* Guests: a sign-in link takes the place of the quantity and the cart button. */
.guest-actions {
    display: flex;
    margin: 0;
}

/* Sign-in links styled as buttons keep the buttons' white text. */
.book-panel a.btn,
.book-panel a.btn:hover {
    color: #fff;
}

.book-panel .field-error {
    color: #6d0f0f;
}

.cart-note {
    font-size: 0.95rem;
}

.favorite-form {
    margin: 0;
}

.favorite-button {
    border-radius: 5px;
}

.favorite-button.is-favorite {
    background-color: var(--color-chrome);
}

.favorite-button.is-favorite:hover {
    background-color: #555;
}

.favorite-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.book-description h2 {
    margin: 0 0 8px;
    font-size: 1.15rem;
    color: var(--panel-text);
}

.description-box {
    padding: 12px 14px;
    border: 1px solid #000;
    border-radius: var(--radius-sm);
}

.description-box p {
    margin: 0;
    overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------------
   Rating form and reviews
   --------------------------------------------------------------------- */

.rating-comments-section,
.similar-books {
    padding: 20px 24px;
    border: 1px solid #ddd;
    border-radius: var(--radius);
    background-color: var(--color-surface);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.rating-comments-section {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
}

.rating-comments-section h2,
.similar-books h2 {
    margin: 0 0 14px;
    font-size: 1.5rem;
}

.review-note {
    margin: 0;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background-color: var(--color-surface-muted);
    font-weight: 600;
}

.form-alert {
    margin: 0 0 16px;
    padding: 10px 14px;
    border: 1px solid #f5c2c0;
    border-radius: var(--radius-sm);
    background-color: var(--color-error-bg);
    color: var(--color-error-text);
    font-weight: 600;
}

/* Star rating input: five radios styled as stars (works without JS). */
.star-rating {
    min-width: 0;
    margin: 0 0 16px;
    padding: 0;
    border: 0;
}

.star-rating legend {
    padding: 0;
    margin-bottom: 4px;
    font-weight: 700;
}

.star-options {
    position: relative;
    display: inline-flex;
    gap: 2px;
}

.star-options .star {
    display: inline-block;
    padding: 0 3px;
    border-radius: var(--radius-sm);
    color: var(--star-off);
    font-size: 2.2rem;
    line-height: 1.1;
    cursor: pointer;
    transition: color 0.15s, transform 0.15s;
}

.star-options input:checked + .star {
    color: var(--star-on);
}

.star-options:has(input:checked) .star {
    color: var(--star-on);
}

.star-options input:checked + .star ~ .star {
    color: var(--star-off);
}

/* Hover preview (more specific than the checked state so it can override it) */
.star-rating .star-options:has(.star:hover) .star {
    color: var(--star-on);
}

.star-rating .star-options .star:hover ~ .star {
    color: var(--star-off);
}

.star-options .star:hover {
    transform: scale(1.1);
}

.star-options input:focus-visible + .star {
    outline: 3px solid var(--color-focus-ink);
    outline-offset: 2px;
    box-shadow: 0 0 0 5px var(--color-focus);
}

.star-rating[aria-invalid="true"] .star-options {
    border-bottom: 2px solid var(--color-accent);
}

.star-rating-value {
    margin: 2px 0 0;
    font-weight: 600;
    color: var(--color-text-muted);
}

.star-rating-value:empty {
    display: none;
}

.star-rating .field-error {
    margin: 4px 0 0;
}

.review-form .form-field p {
    margin: 0;
}

.review-form textarea.form-control:focus {
    border-color: var(--color-accent);
}

.btn-danger.review-submit {
    min-width: 180px;
}

.reviews-empty {
    padding: 24px 12px;
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-sm);
}

.review-total {
    font-weight: 400;
    color: var(--color-text-muted);
}

.review-list {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.review {
    padding: 14px 16px;
    border: 1px solid #e3e3e3;
    border-radius: var(--radius-sm);
    background-color: #fafafa;
}

.review:target {
    border-color: var(--color-primary);
}

.review-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 2px 12px;
}

.review-author {
    margin: 0;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.review-date {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.review-rating {
    margin: 4px 0 6px;
}

.review-text {
    margin: 0 0 10px;
    overflow-wrap: anywhere;
}

.review-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
}

.reaction-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 4px 14px;
    border: 1px solid #bdbdbd;
    border-radius: var(--radius-lg);
    background-color: #fff;
    color: var(--color-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.reaction-button:hover {
    border-color: var(--color-primary);
    background-color: #eef3f3;
}

.reaction-button[aria-pressed="true"] {
    border-color: var(--color-primary);
    background-color: var(--color-primary);
    color: #fff;
}

/* Guests see the reactions as plain counts (only customers can react). */
.reaction-tally {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding-block: 4px;
    padding-inline-end: 14px;
    font-weight: 600;
}

/* ---------------------------------------------------------------------
   Similar books
   --------------------------------------------------------------------- */

.similar-books {
    text-align: center;
}

.similar-books-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.book-item {
    width: 150px;
}

.book-link {
    display: block;
    height: 100%;
    padding: 4px;
    border-radius: var(--radius-sm);
    color: inherit;
    text-decoration: none;
}

.book-link:hover,
.book-link:visited {
    color: inherit;
}

.book-link .book-cover {
    display: block;
    width: 100%;
    height: auto;
    margin-bottom: 10px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.book-link .cover-placeholder {
    font-size: 2rem;
}

.book-link:hover .book-cover,
.book-link:focus-visible .book-cover {
    transform: scale(1.05);
}

.book-item h3 {
    margin: 10px 0 4px;
    font-size: 1rem;
    overflow-wrap: anywhere;
}

.book-item p {
    margin: 0;
    font-size: 0.9rem;
    color: #555;
    overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------------
   Responsive layout
   --------------------------------------------------------------------- */

@media (min-width: 960px) {
    .rating-comments-section {
        grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
        gap: 24px 40px;
    }
}

@media (max-width: 720px) {
    .book-panel {
        grid-template-columns: minmax(0, 1fr);
        padding: 20px 16px;
    }

    .book-cover {
        justify-self: center;
        width: min(220px, 70%);
    }

    .add-to-cart-box {
        max-width: none;
    }

    .btn-danger.cart-button {
        max-width: none;
    }

    .favorite-button {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .book-detail-page {
        gap: 18px;
    }

    .page-container.book-detail-page {
        padding-inline: 12px;
    }

    .rating-comments-section,
    .similar-books {
        padding: 16px 14px;
    }

    .add-to-cart-box {
        padding: 14px;
    }

    .add-to-cart-form .quantity-field,
    .btn-danger.cart-button {
        flex: 1 1 100%;
    }

    .quantity-field .form-control {
        width: 100%;
    }

    .similar-books-container {
        gap: 14px;
    }

    .book-item {
        width: calc(50% - 7px);
    }

    .btn-danger.review-submit {
        width: 100%;
    }
}
