:root {
    --bg: #f5f7f8;
    --panel: #ffffff;
    --text: #192027;
    --muted: #65717d;
    --line: #d9e0e6;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --danger: #b42318;
    --warning-bg: #fff4d6;
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 28px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    font-weight: 700;
    text-decoration: none;
    font-size: 19px;
}

.nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
}

.nav a {
    text-decoration: none;
    color: var(--muted);
    border-radius: 6px;
    padding: 7px 9px;
}

.nav a.active {
    background: #e8f1f0;
    color: var(--brand-dark);
    font-weight: 700;
}

.nav a.icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 22px;
    line-height: 1;
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 6px;
    background: #e8f1f0;
    cursor: pointer;
}

.menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--brand-dark);
}

.menu-toggle {
    flex-direction: column;
    gap: 4px;
}

.page {
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px;
}

.title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 18px;
}

h1,
h2 {
    margin: 0 0 8px;
}

h1 {
    font-size: 30px;
}

h2 {
    font-size: 20px;
}

h3 {
    margin: 8px 0 0;
    font-size: 16px;
}

.muted,
.empty {
    color: var(--muted);
    margin: 0;
}

.grid {
    display: grid;
    gap: 18px;
}

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

.panel,
.login-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 20px;
}

.login-panel {
    max-width: 420px;
    margin: 70px auto;
}

.form {
    display: grid;
    gap: 14px;
}

.field-hint {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
}

.settings-section {
    margin-top: 18px;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #c9d2da;
    border-radius: 6px;
    padding: 10px 11px;
    font: inherit;
    background: #ffffff;
}

input[type="checkbox"] {
    width: auto;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
}

.inline-form,
.linked-address-list {
    display: grid;
    gap: 10px;
}

.linked-address {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: #ffffff;
}

.category-create-form {
    margin-bottom: 16px;
}

.category-sort-form,
.category-list {
    display: grid;
    gap: 10px;
}

.category-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: #ffffff;
}

.category-row.dragging {
    opacity: 0.55;
}

.item-sort-row.dragging {
    opacity: 0.55;
}

.item-sort-row.inactive {
    color: var(--danger);
    background: #fff1f0;
}

.item-sort-row.inactive a,
.item-sort-row.inactive .link-button {
    color: var(--danger);
}

.category-filter-form {
    margin-bottom: 14px;
}

.item-sort-form {
    margin-top: 12px;
}

.item-image-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
}

.item-image-card {
    position: relative;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
    background: #ffffff;
    cursor: grab;
}

.item-image-card.primary {
    border-color: var(--brand);
    box-shadow: 0 0 0 2px #bfd8d4;
}

.item-image-card.primary::before {
    content: "Standardbild";
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 1;
    border-radius: 4px;
    padding: 3px 6px;
    background: var(--brand-dark);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
}

.item-image-card.dragging {
    opacity: 0.55;
}

.item-image-card img {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.item-image-card figcaption {
    display: grid;
    gap: 5px;
    padding: 7px;
    font-size: 12px;
}

.item-image-card figcaption span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.danger-link {
    color: var(--danger);
}

.drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    background: #e8f1f0;
    color: var(--brand-dark);
    cursor: grab;
    font-weight: 700;
}

textarea {
    resize: vertical;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 6px;
    padding: 10px 14px;
    background: var(--brand);
    color: #ffffff;
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
    min-height: 40px;
}

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

.button.small {
    min-height: 34px;
    padding: 7px 11px;
    font-size: 14px;
}

.button.secondary {
    background: #e8f1f0;
    color: var(--brand-dark);
}

.button.danger-soft {
    background: #fff1f0;
    color: var(--danger);
}

.button.danger-soft:hover {
    background: #ffdeda;
}

.address-picker {
    display: grid;
    gap: 8px;
}

.address-picker label {
    max-width: 100%;
}

.address-selected {
    min-height: 42px;
    font-weight: 700;
}

.address-selected[readonly] {
    cursor: pointer;
}

.address-picker-trigger {
    cursor: pointer;
}

.address-picker-trigger:hover,
.address-picker-trigger:focus {
    border-color: var(--brand);
    outline: 2px solid #bfd8d4;
    outline-offset: 1px;
}

.address-picker-dialog {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    align-items: start;
    justify-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.42);
    overflow: auto;
}

.address-picker-dialog[hidden] {
    display: none;
}

.address-picker-box {
    width: min(800px, 100%);
    max-height: calc(100vh - 40px);
    display: grid;
    align-content: start;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: #ffffff;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
    overflow: auto;
}

.address-picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.address-results {
    display: grid;
    gap: 8px;
    max-height: min(260px, 32vh);
    overflow: auto;
    padding-right: 4px;
}

.address-option {
    display: grid;
    gap: 4px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    background: #ffffff;
    color: var(--text);
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.address-option[hidden] {
    display: none;
}

.address-option:hover,
.address-option:focus {
    border-color: var(--brand);
    outline: 0;
    background: #f0fdfa;
}

.address-option span {
    color: var(--muted);
    font-size: 14px;
}

.new-address-box {
    display: grid;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #f8fafc;
}

.new-address-box h3 {
    margin-top: 0;
    margin-bottom: 0;
}

.new-address-box .grid.two {
    gap: 12px 16px;
}

.new-address-box label {
    gap: 5px;
}

.new-address-box input {
    padding: 8px 10px;
    min-height: 38px;
}

.new-address-use {
    justify-self: start;
}

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

.link-button {
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--brand-dark);
    cursor: pointer;
    text-decoration: underline;
    font: inherit;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
}

th,
td {
    padding: 11px 9px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
}

.loan-list {
    display: grid;
    gap: 10px;
}

.loan-card {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.loan-card p {
    margin: 5px 0;
}

.loan-card span,
.item-row small {
    color: var(--muted);
}

.loan-card.overdue,
.row-overdue {
    background: var(--warning-bg);
}

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.tabs a {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 12px;
    background: #ffffff;
    text-decoration: none;
    color: var(--muted);
}

.tabs a.active {
    border-color: var(--brand);
    color: var(--brand-dark);
    font-weight: 700;
}

.stock-picker th,
.stock-picker td {
    text-align: center;
}

.stock-picker th:first-child,
.stock-picker td:first-child {
    text-align: left;
}

.stock-picker input[type="number"] {
    max-width: 86px;
    font-weight: 700;
    text-align: center;
}

.external-items-toggle {
    justify-content: flex-start;
}

.stock-picker .stock-category-heading th {
    background: #eef2f7;
    color: var(--text);
    font-size: 14px;
    text-transform: none;
    letter-spacing: 0;
    padding: 8px 9px;
}

.stock-picker .external-loan-item[hidden],
.stock-picker .external-loan-group[hidden] {
    display: none;
}

.stock-picker .has-reserved {
    background: #fff7ed;
}

.stock-picker .has-loaned {
    background: #fff1f0;
}

.stock-picker .unavailable {
    outline: 2px solid #d92d20;
    outline-offset: -2px;
}

.stock-picker .unavailable td:first-child::after {
    content: " - Auswahl zu hoch";
    color: var(--danger);
    font-weight: 700;
}

.dashboard-stock th:not(:first-child),
.dashboard-stock td:not(:first-child) {
    text-align: center;
}

.dashboard-stock .muted-number {
    color: var(--muted);
    font-weight: 700;
}

.stock-date-controls,
.calendar-controls {
    display: grid;
    grid-template-columns: 40px minmax(150px, 180px) 40px;
    align-items: center;
    gap: 10px;
    margin: 10px 0 16px;
}

.stock-date-controls .date-jump,
.calendar-controls .date-jump {
    margin: 0;
    display: block;
}

.stock-date-controls .button,
.calendar-controls .button {
    min-width: 40px;
    padding-left: 0;
    padding-right: 0;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 13px;
    font-weight: 700;
    background: #e8f1f0;
    color: var(--brand-dark);
}

.status-pill.reserved {
    background: #fff4d6;
    color: #92400e;
}

.status-pill.returned {
    background: #eef2f7;
    color: #475569;
}

.status-pill.cancelled {
    background: #fff1f0;
    color: var(--danger);
}

.date-jump,
.legend {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.date-jump input {
    min-width: 160px;
}

.legend {
    margin-bottom: 14px;
    color: var(--muted);
}

.legend-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 92px;
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 13px;
    font-weight: 700;
}

.legend-pill.free,
.calendar-day-stock.free {
    background: #22c55e;
    color: #ffffff;
}

.legend-pill.loaned {
    background: #ff1f1f;
    color: #ffffff;
}

.legend-pill.reserved,
.calendar-day-stock.reserved {
    background: #f5b400;
    color: #ffffff;
}

.calendar-table {
    min-width: 980px;
    border: 1px solid #202020;
    table-layout: fixed;
}

.calendar-table th:first-child {
    width: 190px;
}

.calendar-table small {
    color: var(--muted);
    text-transform: none;
    font-size: 12px;
}

.calendar-table th,
.calendar-table td {
    border: 1px solid #202020;
    padding: 0;
}

.calendar-table th {
    background: #ffffff;
    color: #111827;
    text-align: center;
    vertical-align: bottom;
}

.calendar-table tbody th {
    text-align: left;
    padding: 8px 7px;
    vertical-align: middle;
}

.calendar-day-stock {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    width: 100%;
    padding: 5px 3px;
    font-size: 13px;
    font-weight: 700;
    color: #ffffff;
}

.calendar-day-stock.empty {
    background: #f8fafc;
    color: transparent;
}

.flash {
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 16px;
    background: #e8f1f0;
    color: var(--brand-dark);
    border: 1px solid #bfd8d4;
}

.flash.error {
    background: #fff1f0;
    color: var(--danger);
    border-color: #f0b8b3;
}

pre {
    white-space: pre-wrap;
    background: #eef2f7;
    padding: 12px;
    border-radius: 6px;
}

@media (max-width: 820px) {
    .topbar {
        display: grid;
        grid-template-columns: 1fr auto;
    }

    .title-row {
        display: grid;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .nav {
        display: none;
        grid-column: 1 / -1;
        align-items: stretch;
        gap: 6px;
        border-top: 1px solid var(--line);
        padding-top: 10px;
    }

    .nav.open {
        display: grid;
    }

    .nav a {
        display: flex;
        align-items: center;
        min-height: 40px;
    }

    .nav a.icon-link {
        width: auto;
        justify-content: flex-start;
        padding: 7px 9px;
    }

    .page {
        padding: 18px;
    }

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

    .loan-card {
        display: grid;
    }

}
