:root {
    --background: #f4f6f8;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #172033;
    --text-muted: #6b7280;
    --border: #dfe4ea;

    --primary: #8b1a1a;
    --primary-dark: #6b1212;

    --available: #18794e;
    --available-background: #e8f7ef;

    --borrowed: #b42318;
    --borrowed-background: #feeceb;

    --shadow: 0 12px 30px rgba(25, 40, 60, 0.09);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family:
        Inter,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    color: var(--text);
    background: var(--background);
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.site-header {
    padding: 34px 20px;
    color: white;
    background:
        linear-gradient(
            135deg,
            #6b1212,
            #a83232
        );
}

.header-content {
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: 1100px;
    margin: 0 auto;
}

.engolpio-image {
    width: 90px;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
    margin: 0 auto 15px;
}

.logo {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 16px;
    font-size: 30px;
    background: rgba(255, 255, 255, 0.12);
}

.site-header h1 {
    margin: 0;
    font-size: clamp(28px, 5vw, 42px);
}

.site-header p {
    margin: 5px 0 0;
    color: rgba(255, 255, 255, 0.82);
}

.container {
    width: min(1100px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 60px;
}

.toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px;
    gap: 14px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 15px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
}

.search-icon {
    opacity: 0.65;
}

.search-box input,
.toolbar select {
    width: 100%;
    min-height: 52px;
    border: none;
    outline: none;
    color: var(--text);
    background: transparent;
}

.toolbar select {
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
}

.summary {
    margin: 22px 0 14px;
    color: var(--text-muted);
}

.summary p {
    margin: 0;
}

.engolpia-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fill, minmax(250px, 1fr));
    gap: 18px;
}

.engolpio-card {
    display: flex;
    flex-direction: column;
    min-height: 335px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.engolpio-cover {
    display: grid;
    place-items: center;
    min-height: 150px;
    padding: 24px;
    color: white;
    font-size: 52px;
    background:
        linear-gradient(
            135deg,
            #8b1a1a,
            #c0392b
        );
}

.engolpio-content {
    display: flex;
    flex: 1;
    flex-direction: column;
    padding: 20px;
}

.engolpio-number {
    margin: 0 0 7px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.engolpio-title {
    margin: 0;
    font-size: 21px;
    line-height: 1.25;
}

.engolpio-category {
    margin: 8px 0 18px;
    color: var(--text-muted);
    font-size: 14px;
}

.status-badge {
    align-self: flex-start;
    margin-bottom: 18px;
    padding: 7px 11px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
}

.status-available {
    color: var(--available);
    background: var(--available-background);
}

.status-borrowed {
    color: var(--borrowed);
    background: var(--borrowed-background);
}

.borrow-button,
.primary-button {
    width: 100%;
    min-height: 47px;
    margin-top: auto;
    border: none;
    border-radius: 12px;
    color: white;
    font-weight: 700;
    background: var(--primary);
    transition:
        transform 150ms ease,
        background 150ms ease;
}

.borrow-button:hover,
.primary-button:hover {
    background: var(--primary-dark);
}

.borrow-button:active,
.primary-button:active {
    transform: scale(0.98);
}

.borrow-button:disabled {
    cursor: not-allowed;
    color: var(--text-muted);
    background: #e7e9ed;
}

.secondary-button {
    width: 100%;
    min-height: 47px;
    margin-top: 8px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    color: var(--text-muted);
    font-weight: 700;
    background: transparent;
    transition:
        border-color 150ms ease,
        color 150ms ease,
        background 150ms ease,
        transform 150ms ease;
}

.secondary-button:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(139, 26, 26, 0.05);
}

.secondary-button:active {
    transform: scale(0.98);
}

.empty-state {
    padding: 65px 20px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state h2 {
    margin: 12px 0 5px;
    color: var(--text);
}

.empty-state p {
    margin: 0;
}

.empty-icon {
    font-size: 48px;
}

.hidden {
    display: none;
}

.borrow-dialog {
    width: min(470px, calc(100% - 28px));
    padding: 0;
    border: none;
    border-radius: 20px;
    color: var(--text);
    background: var(--surface);
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.25);
}

.borrow-dialog::backdrop {
    background: rgba(10, 20, 35, 0.65);
    backdrop-filter: blur(3px);
}

.borrow-dialog form {
    position: relative;
    padding: 28px;
}

.close-button {
    position: absolute;
    top: 14px;
    right: 15px;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    color: var(--text-muted);
    font-size: 27px;
    line-height: 1;
    background: var(--surface-soft);
}

.dialog-heading {
    padding-right: 35px;
    margin-bottom: 24px;
}

.dialog-label {
    margin: 0 0 5px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.dialog-heading h2 {
    margin: 0;
}

.form-field {
    display: block;
    margin-bottom: 17px;
}

.form-field span {
    display: block;
    margin-bottom: 7px;
    font-size: 14px;
    font-weight: 700;
}

.form-field input {
    width: 100%;
    min-height: 49px;
    padding: 0 13px;
    border: 1px solid var(--border);
    border-radius: 11px;
    outline: none;
    background: white;
}

.form-field input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 26, 26, 0.12);
}

.form-message {
    min-height: 22px;
    margin: 0 0 10px;
    color: var(--borrowed);
    font-size: 14px;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 100;
    max-width: min(360px, calc(100% - 40px));
    padding: 14px 18px;
    border-radius: 12px;
    color: white;
    background: #172033;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition:
        opacity 200ms ease,
        transform 200ms ease;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 650px) {
    .site-header {
        padding: 25px 18px;
    }

    .container {
        width: min(100% - 24px, 1100px);
        padding-top: 20px;
    }

    .toolbar {
        grid-template-columns: 1fr;
    }

    .engolpia-grid {
        grid-template-columns: 1fr;
    }

    .engolpio-card {
        min-height: 0;
    }

    .engolpio-cover {
        min-height: 120px;
    }

    .borrow-dialog form {
        padding: 24px 19px;
    }
}

.load-error {
    grid-column: 1 / -1;
    padding: 45px 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
    background: var(--surface);
}

.load-error h2 {
    margin: 0 0 8px;
}

.load-error p {
    margin: 0 0 22px;
    color: var(--text-muted);
}

.retry-button {
    width: auto;
    min-width: 150px;
    padding: 0 22px;
}