:root {
    color-scheme: light;
    --bg: #f6f5f1;
    --surface: #ffffff;
    --surface-muted: #ece7df;
    --line: #d8d1c4;
    --line-strong: #b8ad9d;
    --ink: #1f2725;
    --muted: #65716e;
    --green: #204b45;
    --green-soft: #dcebe6;
    --blue: #284f7a;
    --blue-soft: #dfeaf5;
    --red: #8b2d2d;
    --red-soft: #f4dfdd;
    --gold: #77611f;
    --gold-soft: #f1e8c8;
    --shadow: 0 18px 45px rgba(35, 38, 34, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100%;
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    letter-spacing: 0;
}

a {
    color: inherit;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1:focus {
    outline: none;
}

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

button {
    cursor: pointer;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    padding: 0.62rem 0.72rem;
    outline: none;
}

textarea {
    min-height: 96px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(32, 75, 69, 0.14);
}

label span {
    display: block;
    margin-bottom: 0.34rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.app-shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 68px;
    padding: 0.75rem clamp(1rem, 4vw, 2rem);
    border-bottom: 1px solid var(--line);
    background: rgba(246, 245, 241, 0.94);
    backdrop-filter: blur(12px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    color: var(--ink);
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 8px;
    background: var(--green);
    color: #fff;
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
    line-height: 1.15;
}

.brand small {
    color: var(--muted);
    font-size: 0.78rem;
}

.content {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 1.35rem clamp(1rem, 4vw, 2rem) 2rem;
}

.page-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.page-heading h1 {
    font-size: 2rem;
    line-height: 1.1;
}

.eyebrow {
    color: var(--green);
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.text-button {
    min-height: 40px;
    border-radius: 6px;
    border: 1px solid transparent;
    padding: 0.56rem 0.85rem;
    font-weight: 800;
    line-height: 1.1;
}

.primary-button {
    background: var(--green);
    color: #fff;
}

.secondary-button {
    border-color: var(--line);
    background: #fff;
    color: var(--ink);
}

.danger-button {
    border-color: #d8b8b6;
    background: var(--red-soft);
    color: var(--red);
}

.ghost-button {
    border-color: var(--line);
    background: transparent;
    color: var(--ink);
}

.text-button {
    min-height: auto;
    border: 0;
    background: transparent;
    color: var(--green);
    padding: 0.2rem 0;
}

.metrics-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.metrics-strip div {
    min-width: 0;
    padding: 1rem;
    border-right: 1px solid var(--line);
}

.metrics-strip div:last-child {
    border-right: 0;
}

.metrics-strip span,
.metrics-strip small {
    display: block;
}

.metrics-strip span {
    font-size: 1.55rem;
    font-weight: 850;
    line-height: 1;
}

.metrics-strip small {
    margin-top: 0.3rem;
    color: var(--muted);
    font-weight: 700;
}

.filters-band {
    display: grid;
    grid-template-columns: minmax(240px, 1.5fr) minmax(160px, 0.7fr) minmax(180px, 0.8fr) auto;
    gap: 0.8rem;
    align-items: end;
    margin-bottom: 1rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.check-filter {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 42px;
    padding: 0.55rem 0.2rem;
    white-space: nowrap;
}

.check-filter input {
    width: 18px;
    min-height: 18px;
}

.check-filter span {
    margin: 0;
    color: var(--ink);
}

.library-grid {
    display: grid;
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
}

.editor-panel,
.list-panel,
.login-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.editor-panel {
    position: sticky;
    top: 84px;
    padding: 1rem;
}

.panel-title,
.list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.9rem;
}

.panel-title h2,
.list-head h2 {
    font-size: 1.05rem;
}

.list-head {
    padding: 1rem 1rem 0;
}

.list-head span {
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
}

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

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

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 1rem;
}

.validation-box {
    margin: 0 0 0.8rem;
    border: 1px solid #d8b8b6;
    border-radius: 6px;
    background: var(--red-soft);
    color: var(--red);
    padding: 0.7rem 0.9rem;
}

.validation-message,
.invalid {
    color: var(--red);
}

.invalid {
    border-color: var(--red);
}

.valid.modified:not([type=checkbox]) {
    border-color: var(--green);
}

.book-list {
    display: grid;
    gap: 0.8rem;
    padding: 0 1rem 1rem;
}

.book-row {
    display: grid;
    gap: 0.75rem;
    min-width: 0;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.book-main {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 0.8rem;
}

.book-main h3 {
    overflow-wrap: anywhere;
    font-size: 1.05rem;
}

.book-main p {
    margin-top: 0.2rem;
    color: var(--muted);
}

.status-pill {
    flex: 0 0 auto;
    max-width: 140px;
    border-radius: 999px;
    padding: 0.34rem 0.58rem;
    font-size: 0.76rem;
    font-weight: 850;
    line-height: 1;
    text-align: center;
}

.status-muted {
    background: var(--surface-muted);
    color: #57534b;
}

.status-active {
    background: var(--blue-soft);
    color: var(--blue);
}

.status-done {
    background: var(--green-soft);
    color: var(--green);
}

.status-reference {
    background: var(--gold-soft);
    color: var(--gold);
}

.status-loaned {
    background: var(--red-soft);
    color: var(--red);
}

.book-meta {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.5rem;
    margin: 0;
}

.book-meta div {
    min-width: 0;
    padding: 0.58rem;
    border-radius: 6px;
    background: #f7f5f0;
}

.book-meta dt {
    margin: 0 0 0.14rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
}

.book-meta dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 0.9rem;
}

.book-notes {
    display: grid;
    gap: 0.35rem;
    color: var(--muted);
    font-size: 0.92rem;
}

.book-notes span {
    color: var(--red);
    font-weight: 800;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.empty-state {
    margin: 0 1rem 1rem;
    padding: 2rem;
    border: 1px dashed var(--line-strong);
    border-radius: 8px;
    text-align: center;
}

.empty-state p {
    margin-top: 0.35rem;
    color: var(--muted);
}

.login-shell {
    display: grid;
    min-height: calc(100vh - 118px);
    place-items: center;
    padding: 2rem 1rem;
}

.login-panel {
    width: min(420px, 100%);
    padding: 1.4rem;
}

.login-panel h1 {
    margin-bottom: 1rem;
    font-size: 1.8rem;
}

.login-form {
    display: grid;
    gap: 0.9rem;
}

.login-error {
    margin-bottom: 0.8rem;
    border: 1px solid #d8b8b6;
    border-radius: 6px;
    background: var(--red-soft);
    color: var(--red);
    padding: 0.65rem 0.75rem;
    font-weight: 700;
}

.blazor-error-boundary {
    border-radius: 6px;
    background: var(--red-soft);
    color: var(--red);
    padding: 1rem;
}

.blazor-error-boundary::after {
    content: "Ha ocurrido un error.";
}

@media (max-width: 1100px) {
    .library-grid {
        grid-template-columns: 1fr;
    }

    .editor-panel {
        position: static;
    }
}

@media (max-width: 760px) {
    .content {
        padding-inline: 0.85rem;
    }

    .page-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .page-heading .primary-button {
        width: 100%;
    }

    .metrics-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metrics-strip div:nth-child(2) {
        border-right: 0;
    }

    .metrics-strip div:nth-child(-n+2) {
        border-bottom: 1px solid var(--line);
    }

    .filters-band {
        grid-template-columns: 1fr;
    }

    .check-filter {
        white-space: normal;
    }

    .book-main {
        flex-direction: column;
    }

    .status-pill {
        max-width: none;
    }

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

@media (max-width: 520px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar form,
    .topbar .ghost-button {
        width: 100%;
    }

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

    .row-actions button {
        flex: 1 1 130px;
    }
}
