/* =============================================================================
   Verleihmodul
   -----------------------------------------------------------------------------
   Setzt shared/css/tokens.css und shared/css/base.css voraus. Hier steht nur,
   was es sonst nirgends gibt: der Kalender, die Statusabzeichen und der
   Adminbereich.

   Farben der Gegenstaende kommen aus der Datenbank und werden als
   <style nonce="..."> in die Seite geschrieben (siehe itemColorCss()). Deshalb
   steht hier ueberall var(--item-color) statt einer festen Farbe - und deshalb
   kommt die Content-Security-Policy ohne 'unsafe-inline' aus.
   ========================================================================== */

/* --- Buchungseinstiege auf der Startseite ---------------------------------- */

.book-tiles {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

@media (min-width: 560px) {
    .book-tiles {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
}

.book-tile {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--tap);
    padding: var(--space-4);
    border: 1px solid var(--c-border);
    border-left: 6px solid var(--item-color, var(--c-action));
    border-radius: var(--radius-lg);
    background: var(--c-card);
    box-shadow: var(--shadow);
    color: var(--c-text);
    font-weight: 600;
    transition: transform .1s, box-shadow .2s;
}

.book-tile:active {
    transform: scale(.99);
}

@media (hover: hover) {
    .book-tile:hover {
        box-shadow: var(--shadow-lg);
    }
}

.book-tile .tile-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.book-tile .tile-sub {
    font-size: var(--font-size-small);
    font-weight: 400;
    color: var(--c-text-muted);
}

/* Der Pfeil rechts zeigt, dass die Kachel irgendwo hinfuehrt. */
.book-tile .tile-go {
    margin-left: auto;
    flex: none;
    color: var(--c-text-muted);
    font-size: 1.4rem;
    line-height: 1;
}

/* --- Kalender -------------------------------------------------------------- */

.cal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.cal-title {
    font-weight: 600;
    font-size: 1.1rem;
    text-align: center;
    flex: 1;
}

/* Pfeile: quadratisch und fingergross, damit sie am Handy sicher zu treffen
   sind. */
.cal-nav {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tap-small);
    height: var(--tap-small);
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    background: var(--c-card);
    color: var(--c-text);
    font-size: 1.2rem;
    text-decoration: none;
}

@media (hover: hover) {
    .cal-nav:hover {
        background: var(--c-action-soft);
    }
}

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}

.cal-dow {
    padding-bottom: var(--space-1);
    color: var(--c-text-muted);
    font-size: .75rem;
    font-weight: 600;
    text-align: center;
    text-transform: uppercase;
}

.cal-day {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 3px;
    /* Quadratische Zellen: der Kalender behaelt seine Form auf jedem Display. */
    aspect-ratio: 1;
    padding: 4px 2px;
    border-radius: var(--radius);
    background: var(--c-card-alt);
    font-size: .85rem;
}

.cal-day--outside {
    background: transparent;
    color: var(--c-text-muted);
    opacity: .45;
}

.cal-day--weekend .cal-num {
    color: var(--c-text-muted);
}

.cal-day--today {
    outline: 2px solid var(--c-action);
    outline-offset: -2px;
    font-weight: 700;
}

.cal-num {
    line-height: 1.1;
}

/* Ein Punkt je belegtem Gegenstand. Bewusst Punkte statt durchgehender
   Balken - die brechen am Monatsanfang und -ende um und sind auf schmalen
   Displays nicht mehr zuzuordnen. */
.cal-dots {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px;
}

.cal-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--item-color, var(--c-text-muted));
}

@media (min-width: 560px) {
    .cal-day {
        padding: var(--space-2);
        font-size: .95rem;
    }

    .cal-dot {
        width: 9px;
        height: 9px;
    }
}

/* --- Legende --------------------------------------------------------------- */

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    justify-content: center;
    margin-top: var(--space-3);
    font-size: var(--font-size-small);
    color: var(--c-text-muted);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--item-color, var(--c-text-muted));
}

/* --- Statusabzeichen -------------------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 3px 10px;
    border: 1px solid var(--c-border);
    border-radius: 999px;
    background: var(--c-card-alt);
    color: var(--c-text-muted);
    font-size: .8rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge--ok {
    border-color: var(--status-ok);
    background: var(--status-ok-bg);
    color: var(--status-ok);
}

.badge--soon {
    border-color: var(--status-soon);
    background: var(--status-soon-bg);
    color: var(--status-soon);
}

.badge--expired {
    border-color: var(--status-expired);
    background: var(--status-expired-bg);
    color: var(--status-expired);
}

/* --- Filterleiste ----------------------------------------------------------- */

/* Waagerecht scrollbar statt umbrechend: auf dem Handy bleibt die Leiste
   dadurch eine Zeile hoch. */
.chips {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-1);
    overflow-x: auto;
    scrollbar-width: none;
}

.chips::-webkit-scrollbar {
    display: none;
}

.chip {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--tap-small);
    padding: 8px 16px;
    border: 1px solid var(--c-border-strong);
    border-radius: 999px;
    background: var(--c-card);
    color: var(--c-text);
    font-size: .95rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.chip--active {
    border-color: var(--c-action);
    background: var(--c-action);
    color: var(--c-on-action);
}

.chip-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--c-danger);
    color: var(--c-on-danger);
    font-size: .75rem;
}

.chip--active .chip-count {
    background: var(--c-on-action);
    color: var(--c-action);
}

/* --- Buchungskarten im Servicebereich --------------------------------------- */

.booking {
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
    border: 1px solid var(--c-border);
    border-left: 5px solid var(--item-color, var(--c-border-strong));
    border-radius: var(--radius);
    background: var(--c-card);
}

.booking-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.booking-name {
    font-weight: 600;
    font-size: 1.05rem;
    overflow-wrap: anywhere;
}

.booking-meta {
    margin-top: 2px;
    font-size: var(--font-size-small);
    color: var(--c-text-muted);
}

.booking-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

/* Auf dem Handy fuellen die Schnellaktionen die Zeile, ab Tablet stehen sie
   nebeneinander. */
.booking-actions form,
.booking-actions .btn {
    flex: 1 1 100%;
}

@media (min-width: 560px) {

    .booking-actions form,
    .booking-actions .btn {
        flex: 0 1 auto;
    }
}

.booking-actions form {
    margin: 0;
}

.booking-actions .btn {
    width: 100%;
}

/* --- Verlauf ---------------------------------------------------------------- */

.log {
    margin: 0;
    padding: 0;
    list-style: none;
    border-left: 2px solid var(--c-border);
}

.log li {
    position: relative;
    padding: 0 0 var(--space-3) var(--space-4);
    font-size: var(--font-size-small);
    color: var(--c-text-muted);
}

.log li::before {
    content: "";
    position: absolute;
    left: -5px;
    top: .45em;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--c-border-strong);
}

.log li:last-child {
    padding-bottom: 0;
}

.log-when {
    font-weight: 600;
    color: var(--c-text);
}

/* --- Adminbereich ------------------------------------------------------------ */

.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.admin-section {
    scroll-margin-top: var(--space-4);
}

.admin-section > h2 {
    margin-left: 0;
    margin-right: 0;
}

/* Zeile fuer einen Gegenstand: Farbfeld, Name, Aktionen. */
.item-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
    align-items: end;
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-card-alt);
}

@media (min-width: 640px) {
    .item-row {
        grid-template-columns: 1fr 90px 110px auto;
    }
}

.item-row .field {
    margin-bottom: 0;
}

/* Kennzeichnet, dass der Schluessel unveraenderlich ist. */
.item-key {
    font-family: var(--font-mono);
    font-size: .8rem;
    color: var(--c-text-muted);
}

/* --- Kleinkram --------------------------------------------------------------- */

.muted {
    color: var(--c-text-muted);
}

.nowrap {
    white-space: nowrap;
}

.stack-sm {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* Zwei Buttons nebeneinander, auf dem Handy untereinander. */
.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.btn-row > * {
    flex: 1 1 200px;
}

/* Abstand zum unteren Rand, damit auf dem Handy nichts hinter der
   Systemleiste klebt. */
.page,
.page-narrow {
    padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
}
