/* ==========================================================================
   WritRight — base styles
   A quiet, document-literate look: paper background, a library serif for
   headings, and a navy/brass pairing borrowed from old book bindings.
   Functionality first — the styling exists to make structure legible.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,600;8..60,700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
    --ink: #23241f;
    --muted: #6b6558;
    --paper: #f7f5ef;
    --surface: #ffffff;
    --line: #ddd7c8;
    --navy: #1f3a5f;
    --navy-dark: #16293f;
    --brass: #a1752f;
    --danger: #8b3a3a;
    --danger-dark: #6f2e2e;

    --font-display: 'Source Serif 4', Georgia, serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;

    --radius: 4px;
    --shadow-card: 0 1px 2px rgba(35, 36, 31, 0.06), 0 1px 1px rgba(35, 36, 31, 0.04);
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.55;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 1.2;
    margin: 0 0 0.5em;
    color: var(--navy-dark);
}

h1 { font-size: 2.1rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }

p {
    margin: 0 0 1em;
    color: var(--ink);
}

a {
    color: var(--navy);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ---- layout shell -------------------------------------------------- */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.75rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.3rem;
    color: var(--navy-dark);
    letter-spacing: 0.01em;
}

.brand:hover {
    text-decoration: none;
    color: var(--navy);
}

.auth-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.95rem;
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--navy);
    color: #fff;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1;
    user-select: none;
}

main {
    flex: 1;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 2.5rem 1.75rem 4rem;
}

footer {
    padding: 1.5rem 1.75rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--line);
}

/* ---- buttons & links-as-buttons ------------------------------------ */

button,
.btn {
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 500;
    padding: 0.55rem 1.1rem;
    border: 1px solid var(--navy);
    border-radius: var(--radius);
    background: var(--navy);
    color: #fff;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}

button:hover,
.btn:hover {
    background: var(--navy-dark);
    border-color: var(--navy-dark);
    text-decoration: none;
}

button:focus-visible,
.btn:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 2px solid var(--brass);
    outline-offset: 2px;
}

.btn-secondary {
    background: transparent;
    color: var(--navy);
}

.btn-secondary:hover {
    background: rgba(31, 58, 95, 0.08);
    color: var(--navy-dark);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-dark);
    border-color: var(--danger-dark);
}

.link-button {
    background: none;
    border: none;
    color: var(--navy);
    padding: 0;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: underline;
}

.link-button:hover {
    background: none;
    color: var(--navy-dark);
}

.inline-form {
    display: inline;
}

/* ---- forms ----------------------------------------------------------- */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"] {
    font-family: var(--font-body);
    font-size: 0.95rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    width: 100%;
}

input:focus {
    border-color: var(--navy);
}

form {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

form.form-inline {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
}

form.form-inline input {
    width: auto;
    flex: 1 1 160px;
}

/* ---- cards / sections ------------------------------------------------ */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 3px solid var(--navy);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 1.5rem;
}

.section {
    margin-bottom: 2.5rem;
}

.error-text {
    color: var(--danger);
    font-size: 0.9rem;
}

.success-text {
    color: #2f6e50;
    font-size: 0.9rem;
}

.badge {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    margin-top: 0.35rem;
}

.badge-confirmed {
    background: rgba(31, 58, 95, 0.1);
    color: var(--navy-dark);
}

.badge-unverified {
    background: rgba(161, 117, 47, 0.14);
    color: var(--brass);
}

/* ---- catalog list ------------------------------------------------------ */

.catalog-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.catalog-list li {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--line);
}

.catalog-list li:last-child {
    border-bottom: none;
}

.catalog-empty {
    color: var(--muted);
    font-style: italic;
}

/* ---- data tables (admin) --------------------------------------------- */

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    border: 1px solid var(--line);
}

th, td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

th {
    font-family: var(--font-body);
    font-weight: 600;
    background: var(--paper);
    color: var(--navy-dark);
    border-bottom: 1px solid var(--line);
}

tbody tr:hover {
    background: rgba(31, 58, 95, 0.04);
}

.admin-nav {
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    font-size: 0.9rem;
}

.admin-nav a {
    color: var(--navy);
}

/* ---- responsive -------------------------------------------------------- */

@media (max-width: 720px) {
    main {
        padding: 1.75rem 1.1rem 3rem;
    }

    header {
        flex-wrap: wrap;
        padding: 1rem;
    }

    .hero-row,
    .index-row {
        flex-direction: column !important;
    }
}

/* ---- work search page -------------------------------------------------- */

.muted-text {
    color: var(--muted);
    font-size: 0.9rem;
}

.search-query-block {
    margin-bottom: 1.5rem;
}

.search-query-block h3 {
    margin-bottom: 0.25rem;
}

.search-result-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.search-result-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
}

.search-result-cover {
    width: 42px;
    height: 60px;
    object-fit: cover;
    border-radius: 2px;
    background: var(--line);
    flex-shrink: 0;
}

.search-result-info {
    flex: 1;
    min-width: 0;
}

.search-result-title {
    font-weight: 600;
}

.search-result-meta {
    margin-top: 0.15rem;
}

.search-result-action {
    flex-shrink: 0;
}

/* ---- catalog page -------------------------------------------------- */

.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.catalog-item-info h3 {
    font-size: 1.05rem;
    margin-bottom: 0.15rem;
}

/* ---- catalog controls (search / sort / pagination) ------------------ */

.catalog-controls-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.catalog-controls-row select {
    font-family: var(--font-body);
    font-size: 0.95rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
}

.catalog-pagination {
    justify-content: center;
    margin-top: 1.5rem;
}

.catalog-item-cover {
    width: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    border-radius: 2px;
    background: var(--line);
    margin-bottom: 0.6rem;
}

.catalog-item-cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 1.8rem;
    color: var(--muted);
}

/* ---- work detail page ------------------------------------------------ */

.edition-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.edition-card {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 0.85rem;
}

.edition-card p {
    margin: 0;
    font-size: 0.9rem;
}

.edition-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.edition-cover {
    width: 64px;
    height: 92px;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 2px;
    background: var(--line);
}

.edition-cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.7rem;
    text-align: center;
}

.edition-copyright {
    border-top: 1px solid var(--line);
    padding-top: 0.5rem;
    margin-top: 0.25rem;
}

.edition-card p {
    overflow-wrap: anywhere;
}

/* Reduce columns before content has a chance to squeeze — a wider minimum
   than the catalog grid, since each edition card has more text packed in. */
@media (max-width: 640px) {
    .edition-grid {
        grid-template-columns: 1fr;
    }
}

/* ---- instant filter inputs (catalog search, edition filter) --------- */

/* An input+button pair sharing one bordered box, rather than an
   absolutely-positioned button overlaid on the input — avoids depending on
   precise positioning math (and any parent stacking-context surprises) to
   keep the button visually inside the field. */
.search-input-wrap {
    display: flex;
    align-items: stretch;
    flex: 2 1 320px;
    min-width: 260px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.search-input-wrap input[type="text"] {
    flex: 1;
    min-width: 0;
    border: none;
    border-radius: 0;
}

.search-input-wrap input[type="text"]:focus {
    outline: none;
}

.search-input-wrap:focus-within {
    outline: 2px solid var(--brass);
    outline-offset: 1px;
}

/* Shown/hidden purely by CSS based on whether the input has a value —
   :placeholder-shown only matches an empty input, so this can't drift out
   of sync with the field the way a JS-toggled `hidden` attribute can (and
   it stays correct even when JS sets .value directly, e.g. the Clear
   button itself, with no extra code needed to keep it in sync). */
.search-clear-btn {
    display: none;
    flex-shrink: 0;
    background: none;
    border: none;
    border-left: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0 0.85rem;
    cursor: pointer;
    white-space: nowrap;
}

.search-input-wrap input[type="text"]:not(:placeholder-shown) ~ .search-clear-btn {
    display: inline-flex;
    align-items: center;
}

.search-clear-btn:hover {
    color: var(--ink);
    background: rgba(31, 58, 95, 0.05);
}

/* Sits in the same controls row as a .search-input-wrap and pushes to the
   far right of it, e.g. the sort dropdown next to a search/filter box. */
.controls-row-right {
    margin-left: auto;
}

/* ---- small buttons (per-card actions) -------------------------------- */

.btn-small {
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
}

/* ---- catalog card restructure: link region + compact meta row -------- */

.catalog-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.catalog-item-link {
    color: inherit;
    text-decoration: none;
    flex: 1;
}

.catalog-item-link:hover {
    text-decoration: none;
}

.catalog-item-link:hover .catalog-item-info h3 {
    text-decoration: underline;
}

/* Everything in the info block sits inside a link, and the global `p`
   margin (1em bottom) was making every card much taller than it needed to
   be — tighten it here specifically. */
.catalog-item-info p {
    margin: 0.15rem 0 0;
}

.catalog-item-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.catalog-item-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.catalog-item-meta .badge {
    margin-top: 0;
}

/* ---- confirmation modal (e.g. remove-from-catalog) --------------------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(35, 36, 31, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1000;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 1.5rem;
    width: 100%;
    max-width: 400px;
}

.modal-card h3 {
    margin-bottom: 0.5rem;
}

.modal-card p {
    margin-bottom: 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

/* ---- public domain status (work detail page) -------------------------- */

.pd-status {
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 4px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-top: 1rem;
    max-width: 640px;
}

.pd-status-label {
    display: block;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 0.35rem;
}

.pd-status p {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.pd-status-definitely-pd {
    border-left-color: #2f6e50;
}

.pd-status-definitely-pd .pd-status-label {
    color: #2f6e50;
}

.pd-status-probably-pd {
    border-left-color: #6a9c82;
}

.pd-status-probably-pd .pd-status-label {
    color: #4c8267;
}

.pd-status-probably-not-pd {
    border-left-color: var(--brass);
}

.pd-status-probably-not-pd .pd-status-label {
    color: var(--brass);
}

.pd-status-definitely-not-pd {
    border-left-color: var(--danger);
}

.pd-status-definitely-not-pd .pd-status-label {
    color: var(--danger-dark);
}

/* ---- pd status badge (condensed catalog table) ------------------------ */

.pd-badge {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--line);
}

.pd-status-definitely-pd.pd-badge {
    border-color: #2f6e50;
    color: #2f6e50;
}

.pd-status-probably-pd.pd-badge {
    border-color: #6a9c82;
    color: #4c8267;
}

.pd-status-probably-not-pd.pd-badge {
    border-color: var(--brass);
    color: var(--brass);
}

.pd-status-definitely-not-pd.pd-badge {
    border-color: var(--danger);
    color: var(--danger-dark);
}

/* ---- condensed catalog table view --------------------------------------- */

.catalog-table-wrap {
    overflow-x: auto;
    margin-top: 1rem;
}

.btn-active {
    background: var(--line);
}

.js-sort-header {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.js-sort-header:hover {
    background: var(--line);
}

.sort-arrow {
    color: var(--muted);
    font-size: 0.75em;
}

.author-cell {
    min-width: 12rem;
}

.author-line {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.author-line + .author-line {
    margin-top: 0.15rem;
}

.author-dates {
    color: var(--muted);
    white-space: nowrap;
}

/* ---- header author search ------------------------------------------- */

.nav-search {
    margin: 0;
}

.nav-search input {
    width: 11rem;
    max-width: 40vw;
    padding: 0.35rem 0.6rem;
    font-size: 0.9rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
}

/* ---- add-works hub ------------------------------------------------- */

.catalog-title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.add-methods {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin-top: 0.75rem;
}

.add-method {
    display: block;
}

.add-method:hover {
    text-decoration: none;
    border-color: var(--navy);
}

.add-method h3 {
    margin-bottom: 0.25rem;
}

/* ---- import by ISBN --------------------------------------------------- */

.import-methods {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.5rem;
    margin: 1rem 0;
}

.import-method h3 {
    margin-bottom: 0.15rem;
}

.import-method textarea {
    width: 100%;
}

.file-drop {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    text-align: center;
    padding: 1.5rem 1rem;
    min-height: 8.6rem;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    color: var(--muted);
    cursor: pointer;
    transition: border-color 0.12s ease, background 0.12s ease;
}

.file-drop:hover,
.file-drop.is-dragover {
    border-color: var(--navy);
    background: var(--surface);
}

.file-drop input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.file-drop-icon {
    font-size: 1.4rem;
    line-height: 1;
    color: var(--navy);
}

.file-drop-text {
    font-size: 0.9rem;
    word-break: break-all;
}

.unmatched-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.unmatched-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem 1rem;
}

.unmatched-tools {
    display: inline-flex;
    gap: 1rem;
    font-size: 0.9rem;
}

.unmatched-copy {
    margin-top: 0.75rem;
}

.unmatched-copy textarea {
    width: 100%;
    margin-top: 0.5rem;
}

/* ---- missing-work author rows -------------------------------------- */

.author-row {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: var(--paper);
}

.author-row-main {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.author-name-input {
    flex: 1;
    min-width: 0;
}

.author-suggestions {
    margin-top: 0.4rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.author-suggestion {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.45rem 0.6rem;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--ink);
    font-size: 0.9rem;
    cursor: pointer;
}

.author-suggestion:hover {
    background: var(--paper);
}

.author-suggestion-new {
    border-top: 1px solid var(--line);
    color: var(--navy);
}

.author-linked {
    margin-top: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.author-new-fields {
    margin-top: 0.5rem;
}
