:root {
    --black: #111;
    --dark: #222;
    --button-dark: #333;
    --red: #ff1f1f;
    --red-button: #ff2b2b;
    --border: #222;
    --bg: #f4f4f4;
    --date-col: 140px;
    --item-col: 64px;
    --head-height: 240px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: #111;
}

/* Topbar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 14px 18px;
    background: var(--black);
    color: #fff;
    box-shadow: 0 2px 12px rgba(0,0,0,.18);
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.1;
}

.topbar p {
    margin: 4px 0 0;
    color: #bbb;
}

.topbar nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
}

.button,
.submit-button {
    display: inline-block;
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    background: var(--red-button);
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
}

.button.secondary {
    background: var(--button-dark);
}

.user-badge {
    display: inline-flex;
    align-items: center;
    padding: 9px 12px;
    border-radius: 999px;
    background: var(--dark);
    color: #ddd;
    font-size: 13px;
    font-weight: 700;
}

/* Table */

.tablewrap {
    height: calc(100vh - 78px);
    overflow: auto;
    background: #fff;
}

.gear-table {
    border-collapse: separate;
    border-spacing: 0;
    width: max-content;
    min-width: 100%;
}

.gear-table th,
.gear-table td {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.gear-table thead th {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--head-height);
    background: #fff;
    vertical-align: middle;
}

.sticky-col {
    position: sticky;
    left: 0;
    z-index: 25;
    background: #fff;
    border-left: 1px solid var(--border);
}

.gear-table thead .sticky-col {
    z-index: 50;
    background: var(--black);
    color: #fff;
}

.date-head,
.date-cell,
.usage-label,
.month-cell {
    width: var(--date-col);
    min-width: var(--date-col);
}

.date-head {
    height: var(--head-height);
    padding: 10px;
    text-align: left;
    vertical-align: bottom !important;
}

.date-cell {
    padding: 5px 8px;
    background: #fff;
}

.date-cell strong {
    display: inline-block;
    min-width: 62px;
}

.date-cell span {
    color: #666;
}

.item-head {
    width: var(--item-col);
    min-width: var(--item-col);
    max-width: var(--item-col);
    padding: 0;
    overflow: visible;
    position: relative;
}

.item-head span {
    position: absolute;
    top: 50%;
    left: 50%;
    display: block;
    width: 220px;
    transform: translate(-50%, -50%) rotate(-90deg);
    transform-origin: center center;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.1;
}

.booking-cell {
    width: var(--item-col);
    min-width: var(--item-col);
    height: 30px;
    padding: 4px;
    text-align: center;
    vertical-align: middle;
    background: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 700;
}

tr.weekend td {
    background: #e9e9e9;
}

.booking-cell.booked {
    color: #000;
    cursor: pointer;
}

.booking-cell.open-booking {
    background: var(--red) !important;
}

.booking-cell.invoiced-booking {
    background: #4ade80 !important;
}

.booking-cell.free {
    cursor: pointer;
}

.booking-cell.free:hover {
    background: #f1f1f1;
}

.today-highlight td {
    outline: 3px solid var(--red);
    outline-offset: -3px;
}

/* Month rows */

.month-toggle {
    cursor: pointer;
}

.month-toggle .month-cell {
    position: sticky;
    left: 0;
    z-index: 45;
    height: 34px;
    padding: 8px 10px;
    background: var(--black) !important;
    color: #fff;
    font-size: 15px;
    border-top: 3px solid var(--black);
    border-bottom: 3px solid var(--black) !important;
}

.month-arrow {
    display: inline-block;
    width: 20px;
    margin-right: 4px;
}

.month-fill {
    background: var(--black) !important;
    border-bottom: 3px solid var(--black) !important;
    border-right: 1px solid #222 !important;
}

.day-row.is-collapsed {
    display: none;
}

/* Footer counter */

.gear-table tfoot th {
    position: sticky;
    bottom: 0;
    z-index: 30;
    background: var(--black);
    color: #fff;
    border-top: 3px solid var(--black);
    border-right: 1px solid #333;
}

.gear-table tfoot .usage-label {
    left: 0;
    z-index: 55;
    padding: 8px;
    text-align: left;
}

.usage-cell {
    width: var(--item-col);
    min-width: var(--item-col);
    height: 34px;
    padding: 6px;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

/* Lists */

.booking-list {
    margin: 18px;
    padding: 18px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

.booking-list h2 {
    margin: 0 0 12px;
    font-size: 18px;
}

.booking-row,
.item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.booking-row:last-child,
.item-row:last-child {
    border-bottom: 0;
}

.booking-row span,
.booking-row small {
    display: block;
    color: #666;
    margin-top: 3px;
}

.booking-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* Modal */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200;
}

.modal.show {
    display: flex;
}

.modal-box {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,.2);
}

.modal-box h3 {
    margin-top: 0;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 18px;
}

/* Forms */

.card-form {
    max-width: 760px;
    margin: 18px auto;
    padding: 18px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

.card-form.compact {
    max-width: 520px;
}

.card-form label {
    display: block;
    font-weight: 700;
    margin-bottom: 14px;
}

.card-form input[type="text"],
.card-form input[type="date"],
.card-form input:not([type]) {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 10px;
    font-size: 16px;
}

.date-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.card-form h2 {
    margin: 20px 0 12px;
    font-size: 18px;
}

.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
}

.check-card {
    display: flex !important;
    align-items: center;
    gap: 8px;
    margin: 0 !important;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 10px;
    background: #fafafa;
}

.check-card input {
    width: 20px;
    height: 20px;
}

.submit-button {
    margin-top: 18px;
    width: 100%;
    font-size: 16px;
}

.danger-button {
    border: 0;
    border-radius: 8px;
    padding: 8px 10px;
    background: var(--dark);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.item-list {
    max-width: 520px;
    margin: 18px auto;
    padding: 0 18px 24px;
}

.item-list .item-row {
    padding: 10px 12px;
    margin-bottom: 6px;
    background: #fff;
    border-radius: 10px;
}

/* Login */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--black);
}

.login-box {
    width: 100%;
    max-width: 380px;
    margin: 20px;
    padding: 24px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 10px 40px rgba(0,0,0,.35);
}

.login-box h1 {
    margin: 0;
    font-size: 26px;
}

.login-box p {
    margin: 6px 0 22px;
    color: #666;
}

.login-box label {
    display: block;
    margin-bottom: 14px;
    font-weight: 700;
}

.login-box input {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 10px;
    font-size: 16px;
}

.login-error {
    margin-bottom: 14px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #ffdddd;
    color: #900;
    font-weight: 700;
}

/* Mobile */

@media (max-width: 700px) {
    :root {
        --date-col: 100px;
        --item-col: 52px;
        --head-height: 178px;
    }

    body {
        font-size: 13px;
    }

    .topbar {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 10px;
    }

    .topbar h1 {
        font-size: 16px;
        line-height: 1.05;
    }

    .topbar p {
        font-size: 12px;
        margin-top: 2px;
    }

    .topbar nav {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 6px;
        padding-bottom: 2px;
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
    }

    .topbar nav::-webkit-scrollbar {
        display: none;
    }

    .user-badge,
    .button,
    button.button {
        flex: 0 0 auto;
        white-space: nowrap;
        padding: 8px 10px;
        font-size: 12px;
    }

    .tablewrap {
        height: calc(100dvh - 94px);
    }

    .item-head span {
        width: 165px;
        font-size: 11px;
    }

    .date-cell {
        padding: 4px 6px;
    }

    .date-cell strong {
        display: block;
        min-width: 0;
    }

    .booking-cell {
        height: 30px;
        padding: 3px;
        font-size: 12px;
    }

	.month-sticky {
	    height: 32px;
	    font-size: 14px;
	    padding: 7px 8px;
	}

    .date-grid {
        grid-template-columns: 1fr;
    }

    .card-form {
        margin: 12px;
        padding: 14px;
    }

    .booking-row,
    .item-row {
        align-items: flex-start;
    }

    .booking-actions {
        justify-content: flex-end;
    }

    .danger-button {
        padding: 8px 9px;
        font-size: 12px;
    }
}

.invoice-status {
    display: inline-block !important;
    margin-top: 8px;
    padding: 5px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.invoice-status.open {
    background: #ffe1e1;
    color: #9b0000;
}

.invoice-status.invoiced {
    background: #dff5e1;
    color: #176b26;
}

.invoice-check {
    margin: 16px 0 !important;
}