:root {
    --primary: #4353ff;
    --bg: #f5f7fb;
    --text: #222;
    --border: #d4d9e2;
}

* {
    box-sizing: border-box;
}

body {
    font-family: "Segoe UI", Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

header {
    background: #fff;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 2;
}

header h1 {
    margin: 0 0 1rem;
    font-size: 1.5rem;
}

nav {
    display: flex;
    gap: 0.5rem;
}

.nav-link {
    border: 1px solid var(--border);
    background: #fff;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    color: #d4d9e2;
}

.nav-link.active,
.nav-link:hover {
    border-color: var(--primary);
    color: var(--primary);
}

main {
    padding: 1.5rem;
}

.panel {
    display: none;
    animation: fade 0.2s ease-in;
}

.panel.active {
    display: block;
}

@keyframes fade {
    from {opacity: 0;}
    to {opacity: 1;}
}

.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.grid.two-cols {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.95rem;
}

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

input,
select,
textarea {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.45rem 0.6rem;
    background: #fff;
}

textarea {
    resize: vertical;
}

button {
    margin-top: 1rem;
    border: none;
    background: var(--primary);
    color: #fff;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
}

button:hover {
    opacity: 0.9;
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
}

table th,
table td {
    padding: 0.65rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

table thead {
    background: #f0f2f8;
}

table tbody tr:nth-child(every 2) {
    background: transparent;
}

table tbody tr:hover {
    background: rgba(67, 83, 255, 0.05);
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.flash.success {
    background: #ecfdf3;
    border: 1px solid #15c15d;
}

.flash.error {
    background: #fff2f0;
    border: 1px solid #f36c6c;
}

.reports form {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.reports h3 {
    margin-top: 0;
}

.filter-bar .filters {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-bar label {
    flex: 1 1 220px;
    max-width: 320px;
}

.filter-bar button {
    margin-top: 0;
    height: fit-content;
}

.reset-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.radio-group {
    margin-top: 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.radio-group span {
    font-weight: 600;
}

.radio-group label {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    font-weight: 500;
}

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

.inline-return {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.inline-return input[type="date"] {
    padding: 0.25rem 0.4rem;
}

.inline-return button {
    margin-top: 0;
    padding: 0.35rem 0.8rem;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.inline-delete {
    margin: 0;
}

.inline-delete button.link {
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    font-weight: 600;
    color: var(--primary);
    text-decoration: underline;
}

.inline-delete button.danger {
    color: #d9534f;
}

.muted {
    color: #777;
    font-size: 0.9rem;
}

.print-actions {
    margin-bottom: 1rem;
    display: flex;
    justify-content: flex-end;
}

.print-actions button {
    margin-top: 0;
}

.print-meta {
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 1rem;
    text-align: right;
}

.auth-body {
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 2rem;
}

.login-card {
    max-width: 420px;
    width: 100%;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}

.login-card h1 {
    margin-top: 0;
}

.login-subtitle {
    margin-top: -0.5rem;
    margin-bottom: 1.5rem;
    color: #666;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-bar {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: space-between;
}

.auth-bar form {
    margin: 0;
}

.text-link {
    border: none;
    background: none;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.reader-meta {
    margin-bottom: 0.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.95rem;
}

.reader-meta span {
    min-width: 200px;
}

.open-loans-form {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.open-loans-form label {
    min-width: 200px;
}

.school-year-card {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.school-year-card strong {
    margin-right: 0.4rem;
}

.school-year-warning {
    padding: 0.75rem;
    border: 1px solid #f1c40f;
    border-radius: 6px;
    background: #fff9e6;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

.school-year-warning p {
    margin: 0;
    font-weight: 600;
}

.approve-form {
    margin: 0;
}

.archive-warning {
    padding: 1rem;
    border: 1px solid #f0b429;
    border-radius: 8px;
    background: #fff7dd;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.archive-warning small {
    color: #665d1e;
}

.ack-archive {
    margin-top: 0;
    border: none;
    background: #f0b429;
    color: #222;
    padding: 0.5rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

@media (max-width: 720px) {
    header h1 {
        font-size: 1.2rem;
    }

    nav {
        flex-wrap: wrap;
    }

    table {
        min-width: 100%;
    }
}

@media print {
    body {
        background: #fff;
    }

    header,
    nav,
    #books,
    #readers,
    #loans,
    .flash,
    .filter-bar,
    .print-actions,
    form,
    button,
    .nav-link {
        display: none !important;
    }

    .panel {
        display: none !important;
    }

    #reports.panel {
        display: block !important;
        padding: 0;
        box-shadow: none;
    }

    #reports table {
        min-width: auto;
    }

    #reports .table-wrapper {
        border: none;
    }

    .print-meta {
        display: block !important;
        text-align: left;
        margin-bottom: 1rem;
    }
}
