:root {
    --bg: #f7f5f0;
    --card-bg: #ffffff;
    --border: #ddd6c8;
    --text: #2b2620;
    --muted: #7a7266;
    --accent: #7a4f2b;
    --accent-hover: #5f3c20;
    --green: #3a7d44;
    --green-bg: #e6f4e8;
    --yellow: #8a6d1f;
    --yellow-bg: #faf1d7;
    --red: #b3432b;
    --red-bg: #fbe8e3;
    --accent-bg: #f1e6d8;
}

* {
    box-sizing: border-box;
}

body {
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
}

header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    row-gap: 0.5rem;
    padding: 1rem 2rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.3rem;
    margin: 0;
}

header h1 a {
    color: var(--text);
    text-decoration: none;
}

nav a {
    margin-left: 1rem;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

nav a:hover {
    text-decoration: underline;
}

.current-user {
    margin-left: 1rem;
    color: var(--muted);
    font-size: 0.9rem;
    text-decoration: none;
}

.current-user:hover {
    text-decoration: underline;
}

.nav-badge {
    display: inline-block;
    min-width: 1.1rem;
    padding: 0 0.3rem;
    margin-left: 0.3rem;
    border-radius: 999px;
    background: var(--red);
    color: #fff;
    font-size: 0.75rem;
    line-height: 1.1rem;
    text-align: center;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

.library-switcher {
    display: inline;
    margin-left: 1rem;
}

.library-switcher select {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--card-bg);
    color: var(--text);
}

.lang-toggle-form {
    display: inline;
    margin-left: 1rem;
}

.lang-toggle {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    line-height: 1;
    cursor: pointer;
    vertical-align: middle;
}

.lang-toggle:hover {
    background: none;
}

.lang-flag {
    display: block;
    width: 26px;
    height: 16px;
    border-radius: 2px;
    border: 1px solid var(--border);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.lang-toggle:hover .lang-flag {
    border-color: var(--accent);
}

.logout-form {
    display: inline;
    margin-left: 1rem;
}

.logout-form button {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    color: var(--accent);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
}

.logout-form button:hover {
    background: none;
    text-decoration: underline;
}

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 100%;
}

.login-card h2 {
    margin-top: 0;
    text-align: center;
}

.error {
    background: var(--red-bg);
    color: var(--red);
    padding: 0.5rem 0.8rem;
    border-radius: 4px;
    font-size: 0.9rem;
    margin: 0;
}

main {
    max-width: 900px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

main.library-page {
    max-width: none;
}

main.add-books-page {
    max-width: none;
}

.add-books-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: calc(100vh - 130px);
}

.add-books-browser {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
}

.add-books-search {
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    margin-bottom: 1rem;
}

.add-books-results {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.add-books-result-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}

.add-books-result-row:hover {
    background: var(--accent-bg);
}

.add-books-thumb {
    width: 40px;
    height: 56px;
    flex-shrink: 0;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
}

.add-books-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.add-books-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.add-books-title {
    font-weight: 600;
}

.add-books-author {
    color: var(--muted);
    font-size: 0.9rem;
}

.add-books-sticky-bar {
    position: sticky;
    bottom: 0;
    background: var(--card-bg);
    padding-top: 1rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.add-books-sticky-bar button {
    width: 100%;
    margin-top: 0;
}

.add-books-upload-panel {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 1.5rem;
}

.add-books-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    font-size: 1.4rem;
    font-weight: 600;
    text-decoration: none;
    margin: 0;
}

.add-books-upload-btn:hover {
    background: var(--accent-hover);
}

h2 {
    margin-top: 0;
}

.hint {
    color: var(--muted);
    margin-bottom: 1.5rem;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-width: 420px;
}

.danger-zone {
    background: var(--red-bg);
    border-color: var(--red);
    margin-top: 1.5rem;
}

.wide-card {
    max-width: 640px;
}

.wide-card + .wide-card {
    margin-top: 1.5rem;
}

.loan-request-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.loan-request-card {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.85rem 1rem;
}

.loan-request-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.loan-request-meta {
    color: var(--muted);
    font-size: 0.85rem;
}

.due-badge {
    display: inline-block;
    padding: 0.05rem 0.45rem;
    border-radius: 4px;
    font-weight: 600;
}

.due-badge.due-green {
    background: var(--green-bg);
    color: var(--green);
}

.due-badge.due-yellow {
    background: var(--yellow-bg);
    color: var(--yellow);
}

.due-badge.due-red {
    background: var(--red-bg);
    color: var(--red);
}

.queue-position-badge {
    display: inline-block;
    padding: 0.05rem 0.45rem;
    border-radius: 4px;
    font-weight: 600;
    background: var(--accent-bg);
    color: var(--accent-hover);
}

.loan-request-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.loan-approve-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.loan-approve-form label {
    font-size: 0.85rem;
    color: var(--muted);
}

.loan-approve-form input[type="date"] {
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.loan-approve-form button {
    margin-top: 0;
}

.notification-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.notification-item {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}

.notification-item:last-child {
    border-bottom: none;
}

.notification-link {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    color: inherit;
    text-decoration: none;
}

.notification-link:hover .notification-message {
    text-decoration: underline;
}

.notification-unread .notification-message {
    font-weight: 600;
}

.notification-time {
    color: var(--muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

.tour-banner {
    background: var(--accent-bg);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.tour-banner h3 {
    margin: 0 0 0.5rem;
    color: var(--accent-hover);
}

.tour-banner ul {
    margin: 0 0 0.75rem;
    padding-left: 1.25rem;
}

.tour-banner li {
    margin-bottom: 0.25rem;
}

.tour-banner form {
    margin: 0;
}

.tour-banner button {
    margin-top: 0;
}

.account-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.account-nav {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: 180px;
    gap: 0.25rem;
}

.account-nav-link {
    display: block;
    padding: 0.6rem 0.8rem;
    border-radius: 4px;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    text-align: left;
    background: none;
    border: none;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    width: 100%;
}

.account-nav-link:hover {
    background: var(--accent-bg);
}

.account-nav-active {
    background: var(--accent-bg);
    color: var(--accent);
}

.account-nav-logout-form {
    margin: 0;
}

.account-nav-logout {
    color: var(--red);
}

.account-content {
    flex: 1;
    min-width: 0;
}

.card label {
    font-weight: 600;
    font-size: 0.9rem;
    margin-top: 0.6rem;
}

.card input[readonly] {
    background: var(--bg);
    color: var(--muted);
}

.card input,
.card select,
.card textarea {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
}

button, .button {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.55rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    margin-top: 1rem;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    /* Wrap onto another line at a space/hyphen like normal text - never
       break a word mid-letter just to fit a longer (e.g. Dutch) label. */
    white-space: normal;
    max-width: 100%;
}

button:hover, .button:hover {
    background: var(--accent-hover);
}

.button-secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.button-secondary:hover {
    background: var(--bg);
}

.link-button {
    background: none;
    border: none;
    color: var(--red);
    padding: 0;
    margin: 0;
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.9rem;
}

.link-button:hover {
    background: none;
    color: #7c2e1c;
}

.link-button-accent {
    background: none;
    border: none;
    color: var(--accent);
    padding: 0;
    margin: 0;
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.9rem;
}

.link-button-accent:hover {
    background: none;
    color: var(--accent-hover);
}

.visibility-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
}

.visibility-form label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
    cursor: pointer;
}

.share-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.share-form label {
    font-size: 0.85rem;
    color: var(--muted);
}

.share-form input[type="text"] {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    flex: 1 1 160px;
}

.share-form select {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
}

.share-form button {
    margin: 0;
    padding: 0.35rem 0.6rem;
    font-size: 0.9rem;
}

.review-layout {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

/* Book detail page: photos left, info middle, actions right - its own
   class rather than reusing .review-layout, since that one's shared with
   the upload/edit/duplicate-review pages and doesn't have a third
   column. */
.detail-layout {
    display: flex;
    align-items: flex-start;
    gap: 2rem;
    flex-wrap: wrap;
}

.detail-actions-column {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-left: auto;
    min-width: 160px;
}

.detail-actions-column .button {
    width: 100%;
    margin-top: 0;
}

.photo-preview {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.photo-preview img {
    width: 220px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.photo-preview-large img {
    width: 320px;
}

.detail-fields {
    max-width: 480px;
}

.field-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.4rem 1rem;
    margin: 0.8rem 0 0;
}

.field-list dt {
    font-weight: 600;
    color: var(--muted);
    font-size: 0.85rem;
}

.field-list dd {
    margin: 0;
}

.detail-section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem 1.5rem;
    margin-top: 1.5rem;
    max-width: 700px;
}

.detail-section h3 {
    margin-top: 0;
}

.detail-section p {
    margin-bottom: 0;
    white-space: pre-wrap;
}

.detail-section-notes {
    background: var(--green-bg);
    border-color: var(--green);
}

.detail-meta {
    margin-top: 1.5rem;
}

.candidates {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.candidate-card {
    max-width: 260px;
}

.candidate-meta {
    color: var(--muted);
    font-size: 0.85rem;
}

.isbn-source {
    color: var(--muted);
    font-weight: normal;
    font-size: 0.8rem;
}

.added-meta {
    color: var(--muted);
    font-size: 0.8rem;
}

.duplicate-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.cancel-button {
    background: var(--red);
}

.cancel-button:hover {
    background: #7c2e1c;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    max-width: 100%;
}

.badge-yes {
    background: var(--green-bg);
    color: var(--green);
}

.badge-no {
    background: var(--red-bg);
    color: var(--red);
}

.matched-toggle {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
}

.matched-toggle:hover .badge {
    opacity: 0.8;
}

.cover-preview {
    position: fixed;
    display: none;
    width: 200px;
    height: 270px;
    z-index: 3000;
    pointer-events: none;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.12s ease, transform 0.12s ease;
}

.cover-preview.visible {
    opacity: 1;
    transform: scale(1);
}

.cover-preview img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.hourglass {
    font-size: 1.2rem;
    display: inline-block;
}

.badge-waiting {
    background: var(--bg);
    color: var(--muted);
}

.badge-processing {
    background: var(--accent-bg);
    color: var(--accent);
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.search-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-form input {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    min-width: 240px;
}

.search-form button {
    margin-top: 0;
}

.clear-link {
    color: var(--muted);
    font-size: 0.9rem;
}

.search-block {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.advanced-search-toggle {
    background: none;
    border: none;
    color: var(--accent);
    padding: 0;
    margin: 0;
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
}

.advanced-search-toggle:hover {
    color: var(--accent-hover, var(--accent));
}

.advanced-search-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.advanced-search-panel.hidden {
    display: none;
}

.advanced-search-fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem 1rem;
}

.advanced-search-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.advanced-search-field-wide {
    grid-column: span 2;
}

.advanced-search-field label {
    font-size: 0.85rem;
    color: var(--muted);
}

.advanced-search-field input,
.advanced-search-field select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
}

.advanced-search-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.dropzone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--muted);
    cursor: pointer;
    background: var(--card-bg);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover {
    border-color: var(--accent);
}

.dropzone-active {
    border-color: var(--accent);
    background: var(--bg);
}

.bulk-rows {
    margin-top: 1.5rem;
}

.bulk-thumb {
    width: 90px;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border);
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-drag: none;
}

.bulk-thumb:active {
    cursor: grabbing;
}

.bulk-thumb-dragging {
    opacity: 0.35;
}

.bulk-drag-floater {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
    transform: translate(-50%, -50%) scale(1.05);
    opacity: 0.95;
}

.bulk-dragging {
    cursor: grabbing;
    user-select: none;
}

.bulk-slot {
    min-width: 108px;
}

.bulk-slot-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 90px;
    height: 120px;
    border: 1px dashed var(--border);
    border-radius: 4px;
    color: var(--muted);
    font-size: 0.85rem;
}

.bulk-slot-target {
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
    background: var(--bg);
}

.bulk-row-incomplete {
    background: var(--red-bg);
}

.bulk-row-delete {
    background: none;
    color: var(--red);
    border: none;
    padding: 0.3rem 0.5rem;
    margin: 0;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
}

.bulk-row-delete:hover {
    background: var(--red-bg);
}

.bulk-status-detail {
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: var(--muted);
    max-width: 220px;
}

.bulk-status-error {
    color: var(--red);
}

.bulk-retry-btn {
    margin-top: 0.4rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
}

.bulk-detail-row td {
    background: var(--bg);
    padding: 1.2rem;
}

.bulk-detail-panel {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.bulk-detail-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
    gap: 0.6rem;
}

.bulk-detail-field label {
    display: block;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.bulk-detail-field input,
.bulk-detail-field textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
}

.bulk-detail-actions {
    display: flex;
    gap: 0.8rem;
}

.bulk-decline-btn {
    background: var(--red);
}

.bulk-decline-btn:hover {
    background: #7c2e1c;
}

.bulk-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1.5rem;
}

.bulk-modal-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 1.5rem;
    max-width: 420px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.bulk-modal-card h3 {
    margin: 0;
}

.bulk-modal-overlay.hidden {
    display: none;
}

.bulk-modal-card label {
    font-size: 0.85rem;
    color: var(--muted);
}

.bulk-modal-card input,
.bulk-modal-card select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
}

.bulk-modal-existing {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.bulk-modal-existing img {
    width: 70px;
    height: 95px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border);
}

.bulk-modal-actions {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.bulk-process-btn {
    margin-top: 1.5rem;
}

.bulk-process-btn:disabled {
    background: var(--border);
    color: var(--muted);
    cursor: not-allowed;
}

.bulk-process-btn:disabled:hover {
    background: var(--border);
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
}

th, td {
    text-align: left;
    padding: 0.55rem 0.65rem;
    border-bottom: 1px solid var(--border);
}

th {
    background: #f0ece2;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--muted);
}

tr:last-child td {
    border-bottom: none;
}

.library-table {
    table-layout: fixed;
    font-size: 0.85rem;
}

.library-table th,
.library-table td {
    padding: 0.5rem 0.65rem;
}

.library-table .col-title { width: 11%; }
.library-table .col-author { width: 11%; }
.library-table .col-isbn { width: 8%; }
.library-table .col-genre { width: 9%; }
.library-table .col-language { width: 8%; }
.library-table .col-year { width: 5%; }
.library-table .col-pages { width: 8%; }
.library-table .col-location { width: 8%; }
.library-table .col-matched { width: 9%; }
.library-table .col-added-by { width: 12%; }
.library-table .col-actions { width: 11%; }

.sort-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: inherit;
    text-decoration: none;
}

.sort-link:hover {
    color: var(--accent);
}

.sort-link.sort-active {
    color: var(--accent);
}

.sort-arrow {
    font-size: 0.7rem;
}

.cell-truncate {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.8rem;
    align-items: center;
}

.actions a {
    color: var(--accent);
}

.actions form {
    display: inline;
}

.elsewhere-section {
    margin-top: 2rem;
}

.elsewhere-section h3 {
    margin-bottom: 0.25rem;
}

.elsewhere-hint {
    margin-top: 0;
}

.elsewhere-results {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.elsewhere-card {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    width: 280px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.9rem;
}

.elsewhere-card:hover {
    border-color: var(--accent);
}

.elsewhere-card-link {
    display: flex;
    gap: 0.75rem;
    color: inherit;
    text-decoration: none;
}

.borrow-request-form {
    margin: 0;
}

.borrow-request-button {
    width: 100%;
    margin-top: 0;
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
}

.elsewhere-card-media {
    flex-shrink: 0;
    width: 48px;
    height: 68px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.elsewhere-card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.elsewhere-card-media-placeholder {
    font-size: 1.2rem;
}

.elsewhere-card-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.elsewhere-card-title {
    font-weight: 600;
}

.elsewhere-card-author {
    color: var(--muted);
    font-size: 0.9rem;
}

.elsewhere-card-library {
    margin-top: 0.35rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
}

.elsewhere-card-owner {
    font-size: 0.8rem;
    color: var(--muted);
}

/* ==========================================================================
   Responsive layout - phone & tablet screens (max-width: 900px). The
   desktop table (library.html) and the desktop upload form spacing stay
   exactly as they are above this breakpoint; the @media block below is
   what applies only under it. The two rules just above it are the
   exceptions - both intentionally unconditional (same at every width):
   the mobile card view stays hidden until the breakpoint's own override
   below turns it on, and the cover-preview sizing needs to hold at any
   width while still yielding to the img's own `hidden` attribute.
   ========================================================================== */

.upload-photo-preview:not([hidden]) {
    display: block;
    max-width: 220px;
    max-height: 220px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    margin-top: 0.4rem;
}

.book-cards,
.mobile-sort {
    display: none;
}

@media (max-width: 900px) {
    /* --- Account settings: stacked nav above content, touch-sized --- */
    .account-layout {
        flex-direction: column;
        gap: 1rem;
    }

    .account-nav {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .account-nav-link {
        width: auto;
        flex: 1 1 auto;
        min-height: 2.75rem;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .account-nav-logout-form {
        flex: 1 1 auto;
        display: flex;
    }

    /* --- Upload page: generous stacking + finger-sized targets --- */
    .upload-form {
        gap: 1rem;
        padding: 1.5rem 1.1rem;
    }

    .upload-form input[type="file"] {
        padding: 0.9rem 0.7rem;
        min-height: 3rem;
    }

    .upload-form button[type="submit"] {
        min-height: 3rem;
        font-size: 1.05rem;
    }

    .upload-photo-preview {
        max-width: 100%;
        width: 100%;
        max-height: 280px;
    }

    /* --- Toolbar / search: full-width, tappable --- */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-form {
        flex-wrap: wrap;
    }

    .search-form input {
        flex: 1 1 100%;
        min-width: 0;
        min-height: 2.75rem;
    }

    .search-form button {
        min-height: 2.75rem;
        flex: 1 1 auto;
    }

    .toolbar > a.button {
        min-height: 2.75rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .search-block {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .advanced-search-fields {
        grid-template-columns: 1fr;
    }

    .advanced-search-field-wide {
        grid-column: span 1;
    }

    .advanced-search-field input,
    .advanced-search-field select {
        min-height: 2.75rem;
    }

    .advanced-search-actions button {
        min-height: 2.75rem;
    }

    /* --- Library page: cards instead of the table, sort dropdown instead
       of clickable column headers. Scoped to the library page specifically
       (main.library-page) - .table-scroll is also used on the share
       screen's user-access table, which should keep its horizontal-scroll
       fallback instead of disappearing. --- */
    .library-page .table-scroll {
        display: none;
    }

    .mobile-sort {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        margin-bottom: 1rem;
        flex-wrap: wrap;
    }

    .mobile-sort-select {
        flex: 1 1 auto;
        min-height: 2.75rem;
        padding: 0.5rem 0.6rem;
        border: 1px solid var(--border);
        border-radius: 4px;
        font-size: 1rem;
        font-family: inherit;
        background: var(--card-bg);
        color: var(--text);
    }

    .book-cards {
        display: flex;
        flex-direction: column;
        gap: 0.9rem;
    }

    .book-card {
        display: flex;
        gap: 0.9rem;
        background: var(--card-bg);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 0.9rem;
    }

    .book-card-media {
        flex-shrink: 0;
        width: 64px;
        height: 90px;
        border-radius: 4px;
        overflow: hidden;
        background: var(--bg);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .book-card-media img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .book-card-media-placeholder {
        font-size: 1.6rem;
    }

    .book-card-body {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 0.3rem;
    }

    .book-card-title {
        font-weight: 600;
        color: var(--text);
        text-decoration: none;
        font-size: 1.05rem;
    }

    .book-card-title:hover {
        text-decoration: underline;
    }

    .book-card-author {
        color: var(--muted);
    }

    .book-card-meta {
        color: var(--muted);
        font-size: 0.9rem;
    }

    .book-card-matched {
        margin-top: 0.1rem;
    }

    .book-card-actions {
        display: flex;
        gap: 0.6rem;
        margin-top: 0.5rem;
    }

    .book-card-delete-form {
        flex: 1;
        display: flex;
    }

    .book-card-action {
        flex: 1;
        margin: 0;
        min-height: 2.75rem;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.95rem;
    }

    .book-card-action-delete {
        background: var(--red-bg);
        color: var(--red);
        border: 1px solid var(--red);
    }

    .book-card-action-delete:hover {
        background: var(--red);
        color: #fff;
    }

    .elsewhere-card {
        width: 100%;
    }

    .borrow-request-button {
        min-height: 2.5rem;
    }

    /* --- Notifications: full-width card, stacked loan-request rows --- */
    .wide-card {
        max-width: none;
    }

    .loan-request-card {
        flex-direction: column;
        align-items: stretch;
    }

    .loan-request-actions {
        justify-content: space-between;
    }

    .loan-approve-form {
        flex-wrap: wrap;
    }

    .loan-approve-form input[type="date"] {
        min-height: 2.5rem;
        flex: 1 1 auto;
    }

    .loan-approve-form button {
        min-height: 2.5rem;
    }

    /* --- Shared full-width, touch-sized form treatment: login/signup
       (.login-card), edit book (.edit-form), new library
       (.newlibrary-form), share visibility (.share-visibility-card) --- */
    .login-card,
    .edit-form,
    .newlibrary-form,
    .share-visibility-card {
        max-width: none;
        width: 100%;
        gap: 1rem;
        padding: 1.5rem 1.1rem;
    }

    .login-card input,
    .edit-form input,
    .edit-form select,
    .edit-form textarea,
    .newlibrary-form input {
        min-height: 2.75rem;
        padding: 0.65rem 0.7rem;
        font-size: 1rem;
    }

    .login-card button[type="submit"],
    .login-card > a.button,
    .edit-form button[type="submit"],
    .newlibrary-form button[type="submit"] {
        min-height: 3rem;
        font-size: 1.05rem;
    }

    /* --- Book detail / edit: photo(s) then fields, stacked full width in
       reading order, instead of the desktop side-by-side layout --- */
    .review-layout,
    .detail-layout {
        flex-direction: column;
        gap: 1.25rem;
    }

    .review-layout .photo-preview,
    .detail-layout .photo-preview {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .photo-preview img,
    .photo-preview-large img {
        width: calc(50% - 0.4rem);
        max-width: 220px;
    }

    .detail-fields {
        max-width: none;
        width: 100%;
    }

    .detail-actions-column {
        width: 100%;
        margin-left: 0;
    }

    .detail-actions-column .button {
        min-height: 2.75rem;
    }

    /* --- Add-books picker: search+results and the two upload buttons
       stack instead of sitting in a fixed two-column grid (which is what
       squeezed the upload buttons off to the right at narrow widths) --- */
    .add-books-layout {
        display: flex;
        flex-direction: column;
        height: auto;
        gap: 1.25rem;
    }

    .add-books-browser {
        height: auto;
        padding: 1.1rem;
    }

    .add-books-results {
        max-height: 45vh;
    }

    .add-books-search {
        min-height: 2.75rem;
        font-size: 1rem;
    }

    .add-books-result-row {
        padding: 0.7rem 0.6rem;
        gap: 1rem;
    }

    .add-books-result-row input[type="checkbox"] {
        width: 1.3rem;
        height: 1.3rem;
        flex-shrink: 0;
    }

    .add-books-sticky-bar button {
        min-height: 2.75rem;
        font-size: 1rem;
    }

    .add-books-upload-panel {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .add-books-upload-btn {
        min-height: 4rem;
        padding: 1rem;
    }

    /* --- Share screen: per-user row controls and the visibility radios,
       sized for a finger rather than a mouse --- */
    .visibility-form label {
        min-height: 2.75rem;
        padding: 0.3rem 0.5rem;
    }

    .share-form {
        flex-wrap: wrap;
    }

    .share-form input[type="text"] {
        min-height: 2.5rem;
        flex: 1 1 100%;
    }

    .share-form select {
        min-height: 2.5rem;
        flex: 1 1 auto;
    }

    .share-form button {
        min-height: 2.5rem;
        padding: 0.5rem 0.8rem;
    }

    /* --- Duplicate / delete-confirmation actions (shared by
       duplicate.html and delete_confirm.html): stacked, full-width --- */
    .duplicate-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .duplicate-actions .card {
        max-width: none;
    }

    .duplicate-actions button[type="submit"],
    .duplicate-actions > a.button {
        min-height: 2.75rem;
    }
}
