:root {
    --bg: #121212;
    --surface: #1c1c1c;
    --border: #3d3d3d;
    --text: #ebebeb;
    --muted: #9a9a9a;
    --accent: #c6c6c6;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, sans-serif;
}
a { color: var(--accent); text-decoration: none; }

.portal-topbar {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem;
    align-items: center;
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.portal-hamburger, .btn {
    min-width: 44px; min-height: 44px; border: 0; border-radius: 8px;
    background: var(--border); color: var(--text); padding: 0.55rem 0.9rem;
}
.portal-title { font-weight: 700; }
.portal-search { grid-column: 1 / -1; }
.portal-search input {
    width: 100%; min-height: 44px; border: 1px solid var(--border);
    border-radius: 8px; background: #101010; color: var(--text); padding: 0.45rem 0.6rem;
}
.portal-user { grid-column: 1 / -1; display: flex; justify-content: space-between; color: var(--muted); }

.portal-layout { display: grid; grid-template-columns: 1fr; min-height: calc(100vh - 130px); }
.portal-col { border-right: 1px solid var(--border); background: var(--surface); }
.portal-col-main { border-right: 0; background: var(--bg); }
.portal-col-title {
    padding: 0.75rem; font-size: 0.8rem; color: var(--muted); text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}
.portal-item { display: block; min-height: 44px; padding: 0.65rem 0.75rem; color: var(--text); border-bottom: 1px solid rgba(255,255,255,0.04); }
.portal-item.active { border-left: 3px solid var(--accent); background: rgba(255,255,255,0.08); padding-left: calc(0.75rem - 3px); }
.portal-muted { color: var(--muted); padding: 0.75rem; }
.portal-actions { padding: 0.65rem 0.75rem 0.4rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.portal-row {
    display: grid; grid-template-columns: auto 1fr auto; gap: 0.6rem; align-items: center;
    margin: 0.35rem 0.5rem; padding: 0.55rem; border: 1px solid var(--border);
    border-radius: 10px; background: var(--surface); color: var(--text);
}
.portal-thumb {
    width: 58px; height: 58px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border);
}
.portal-thumb-fallback {
    display: inline-flex; align-items: center; justify-content: center; background: #101010;
}
.portal-row-title { font-weight: 600; }
.portal-row-meta { font-size: 0.82rem; color: var(--muted); margin-top: 0.2rem; }
.portal-row-aside {
    display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem;
}
.portal-row-date { font-size: 0.76rem; color: var(--muted); white-space: nowrap; }

.portal-row--text {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
    align-items: flex-start;
    padding: 0.4rem 0.55rem;
    margin: 0.2rem 0.5rem;
}
.portal-row--text .portal-row-title {
    font-size: 0.88rem;
    font-weight: 500;
    line-height: 1.3;
    word-break: break-word;
}
.portal-row--text .portal-row-body {
    font-size: 0.88rem;
    line-height: 1.35;
    word-break: break-word;
}
.portal-row--text .portal-row-date {
    padding-top: 0.1rem;
}

.portal-row--status-aktiv { border-left: 3px solid #22c55e; padding-left: calc(0.55rem - 1px); }
.portal-row--status-geschlossen { border-left: 3px solid #eab308; padding-left: calc(0.55rem - 1px); }
.portal-row--status-verliehen { border-left: 3px solid #f97316; padding-left: calc(0.55rem - 1px); }
.portal-row--status-entsorgt { border-left: 3px solid #ef4444; padding-left: calc(0.55rem - 1px); }
.portal-row--status-verkauft { border-left: 3px solid #3b82f6; padding-left: calc(0.55rem - 1px); }

.portal-row-link {
    display: contents;
    color: inherit;
    text-decoration: none;
}

.inventory-status-form {
    margin: 0;
}
.inventory-status-select {
    appearance: none;
    -webkit-appearance: none;
    display: inline-block;
    font: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.18rem 1.35rem 0.18rem 0.5rem;
    border-radius: 999px;
    border: 1px solid;
    line-height: 1.2;
    cursor: pointer;
    min-height: auto;
    margin: 0;
    background-repeat: no-repeat;
    background-position: right 0.35rem center;
    background-size: 0.65rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239a9a9a' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
.inventory-status-select:focus {
    outline: 1px solid var(--accent);
    outline-offset: 1px;
}
.inventory-status-select--aktiv {
    color: #86efac;
    background-color: rgba(34, 197, 94, 0.14);
    border-color: rgba(34, 197, 94, 0.45);
}
.inventory-status-select--geschlossen {
    color: #fde047;
    background-color: rgba(234, 179, 8, 0.14);
    border-color: rgba(234, 179, 8, 0.45);
}
.inventory-status-select--verliehen {
    color: #fdba74;
    background-color: rgba(249, 115, 22, 0.14);
    border-color: rgba(249, 115, 22, 0.45);
}
.inventory-status-select--entsorgt {
    color: #fca5a5;
    background-color: rgba(239, 68, 68, 0.14);
    border-color: rgba(239, 68, 68, 0.45);
}
.inventory-status-select--verkauft {
    color: #93c5fd;
    background-color: rgba(59, 130, 246, 0.14);
    border-color: rgba(59, 130, 246, 0.45);
}

.inventory-status {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.18rem 0.5rem;
    border-radius: 999px;
    border: 1px solid;
    white-space: nowrap;
    line-height: 1.2;
}
.inventory-status--aktiv {
    color: #86efac;
    background: rgba(34, 197, 94, 0.14);
    border-color: rgba(34, 197, 94, 0.45);
}
.inventory-status--geschlossen {
    color: #fde047;
    background: rgba(234, 179, 8, 0.14);
    border-color: rgba(234, 179, 8, 0.45);
}
.inventory-status--verliehen {
    color: #fdba74;
    background: rgba(249, 115, 22, 0.14);
    border-color: rgba(249, 115, 22, 0.45);
}
.inventory-status--entsorgt {
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.14);
    border-color: rgba(239, 68, 68, 0.45);
}
.inventory-status--verkauft {
    color: #93c5fd;
    background: rgba(59, 130, 246, 0.14);
    border-color: rgba(59, 130, 246, 0.45);
}

.portal-col-left, .portal-col-mid { display: none; }
.portal-layout.menu-open .portal-col-left, .portal-layout.menu-open .portal-col-mid { display: block; }

.flash { padding: 0.6rem 0.8rem; margin: 0.5rem; border-radius: 8px; border: 1px solid var(--border); }
.flash-err { color: #f2b7b7; border-color: #996a6a; }
.flash-ok { color: #cde0cd; border-color: #678267; }

.form-box {
    max-width: 400px; margin: 2rem auto; background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 1rem;
}
label { display: block; margin: 0.2rem 0; color: var(--muted); font-size: 0.9rem; }
input[type="text"], input[type="password"], input[type="date"], input[type="file"], select, textarea {
    width: 100%; min-height: 44px; border: 1px solid var(--border); border-radius: 8px;
    background: #101010; color: var(--text); padding: 0.45rem 0.6rem; margin-bottom: 0.6rem;
}
textarea { min-height: 96px; }

@media (min-width: 900px) {
    .portal-topbar { grid-template-columns: auto auto 1fr auto; }
    .portal-search, .portal-user { grid-column: auto; }
    .portal-layout { grid-template-columns: 220px 260px 1fr; min-height: calc(100vh - 72px); }
    .portal-col-left, .portal-col-mid { display: block; }
    .portal-hamburger { display: none; }
}

.wrap { max-width: 1100px; margin: 0 auto; }
.muted { color: var(--muted); font-size: 0.9rem; }

.form-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.15rem;
    margin-bottom: 1rem;
}
.form-block h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.form-block h3 { margin: 1rem 0 0.5rem; font-size: 1rem; }

.checkbox-row { display: flex; gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.checkbox-row label { display: flex; align-items: center; gap: 0.35rem; color: var(--text); }

.pair-inline {
    display: grid;
    grid-template-columns: minmax(0, 9rem) minmax(0, 1fr);
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 0.75rem;
}
@media (max-width: 520px) { .pair-inline { grid-template-columns: 1fr; } }

.field-rows .pair {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    align-items: end;
}
@media (max-width: 600px) { .field-rows .pair { grid-template-columns: 1fr; } }
.field-rows input { margin-bottom: 0; }

button, .btn {
    cursor: pointer;
    font: inherit;
}
button[type="submit"], button:not([type]) {
    min-height: 44px;
    padding: 0.55rem 0.95rem;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: var(--bg);
    margin-right: 0.35rem;
    margin-bottom: 0.35rem;
}
button.secondary, .btn.secondary {
    background: var(--border);
    color: var(--text);
}
button.danger {
    background: rgba(201, 163, 163, 0.2);
    color: #e8d8d8;
}

.accordion-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin: 0.75rem 0;
    overflow: hidden;
}
.accordion-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    cursor: pointer;
}
.accordion-card-header-title { font-size: 0.95rem; font-weight: 500; }
.accordion-panel { padding: 0.75rem 0.85rem 0.9rem; }
.accordion-panel[hidden] { display: none; }

.detail-head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.detail-head h1 { margin: 0; font-size: 1.35rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: flex-end; }
.btn-head-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--accent);
}
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

body.modal-open { overflow: hidden; }
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.modal.is-open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.modal-box {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 400px;
    max-height: min(90vh, 520px);
    overflow: auto;
    padding: 1.1rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.modal-form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

textarea.letter-copy {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.4;
    min-height: 6.5rem;
    resize: vertical;
    width: 100%;
}

.kv-grid {
    display: grid;
    grid-template-columns: minmax(0, 9rem) minmax(0, 1fr);
    gap: 0.4rem 0.75rem;
    align-items: flex-start;
    margin: 0.35rem 0;
}
.kv-value-stack { display: grid; gap: 0.35rem; }
.codefield {
    display: block;
    padding: 0.25rem 0.4rem;
    border-radius: 6px;
    border: 1px dashed var(--border);
    background: rgba(0,0,0,0.25);
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.notes-list { list-style: none; padding: 0; margin: 0; }
.notes-list li { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.notes-list time { font-size: 0.8rem; color: var(--muted); }

.files { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.tickets-panel {
    margin: 1.25rem 0 0.5rem;
    padding: 0.65rem 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #161616;
}
.tickets-panel-head .section-heading {
    margin: 0 0 0.5rem;
}
.tickets-panel-empty {
    margin: 0;
    padding: 0.25rem 0.35rem 0.5rem;
}
.tickets-panel-body {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.ticket-block {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
}
.ticket-block-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.45rem 0.55rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.ticket-block-summary::-webkit-details-marker {
    display: none;
}
.ticket-block-summary::before {
    content: '›';
    flex-shrink: 0;
    width: 1rem;
    color: var(--muted);
    font-size: 1.1rem;
    line-height: 1;
    transition: transform 0.15s ease;
}
.ticket-block[open] > .ticket-block-summary::before {
    transform: rotate(90deg);
}
.ticket-block-summary-title {
    flex: 1;
    min-width: 0;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.3;
}
.ticket-block-body {
    padding: 0 0.55rem 0.55rem 1.55rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.ticket-block-desc {
    margin: 0.45rem 0 0;
    font-size: 0.84rem;
    color: var(--muted);
    line-height: 1.35;
}

.inventory-detail-box {
    max-width: 980px;
    margin: 0 auto 2rem;
}
.inventory-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.75rem 1rem;
    align-items: start;
    margin-bottom: 1rem;
}
.inventory-header-photo {
    display: block;
    flex-shrink: 0;
}
.inventory-title-image {
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #101010;
    display: block;
}
.inventory-header-info h2 {
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
    line-height: 1.25;
}
.inventory-header-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.45rem;
    margin-bottom: 0.2rem;
}
.inventory-header-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
}
.inventory-header-actions-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.35rem;
}
.inventory-head-btn-form {
    margin: 0;
    display: inline-flex;
}
.inventory-head-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.12rem;
    min-width: 54px;
    padding: 0.35rem 0.45rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.65rem;
    line-height: 1.1;
    text-decoration: none;
    cursor: pointer;
    margin: 0;
}
button.inventory-head-btn {
    min-height: auto;
    padding: 0.35rem 0.45rem;
    margin: 0;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}
button.inventory-head-btn.inventory-head-btn--danger {
    background: var(--surface);
    color: #fca5a5;
}
.inventory-head-btn .material-symbols-outlined {
    font-size: 1.35rem;
    line-height: 1;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
.inventory-head-btn-label {
    white-space: nowrap;
}
.inventory-head-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.inventory-head-btn--danger {
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.35);
}
.inventory-head-btn--danger:hover {
    color: #fecaca;
    border-color: rgba(239, 68, 68, 0.55);
}
.inventory-section-title {
    margin: 1rem 0 0.45rem;
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
}

@media (max-width: 720px) {
    .inventory-header {
        grid-template-columns: auto 1fr;
    }
    .inventory-header-actions {
        grid-column: 1 / -1;
        align-items: stretch;
    }
    .inventory-header-actions-row {
        justify-content: flex-start;
    }
}

.section-heading--nested {
    margin: 0.55rem 0 0.3rem;
}
.section-heading--nested h3 {
    font-size: 0.78rem;
}
.photo-grid--nested {
    margin-bottom: 0.35rem;
}
.portal-row--nested {
    margin: 0.15rem 0;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin: 1rem 0 0.45rem;
}
.section-heading__inner {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
}
.section-heading .btn-head-icon {
    min-width: 32px;
    min-height: 32px;
    border-radius: 6px;
    flex-shrink: 0;
}
.section-heading .btn-head-icon svg {
    width: 16px;
    height: 16px;
}
.section-heading h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
    gap: 0.35rem;
    margin-bottom: 0.85rem;
}
.photo-grid-item {
    aspect-ratio: 1;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: #101010;
    color: inherit;
}
.photo-grid-item:hover { border-color: var(--accent); }
.photo-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.photo-viewer {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 3000;
    align-items: center;
    justify-content: center;
    padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right)) max(0.5rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
}
.photo-viewer.is-open {
    display: flex;
}
.photo-viewer:not(.is-open) {
    display: none;
}
.photo-viewer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
}
.photo-viewer-panel {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.25rem;
    width: 100%;
    height: 100%;
    max-width: 100vw;
}
.photo-viewer-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    max-height: 100%;
}
.photo-viewer-image {
    max-width: min(100%, 88vw);
    max-height: min(calc(100vh - 4.5rem), calc(100dvh - 4.5rem));
    object-fit: contain;
    border-radius: 6px;
}
.photo-viewer-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(28, 28, 28, 0.9);
    color: var(--text);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}
.photo-viewer-nav:disabled {
    opacity: 0.35;
    cursor: default;
}
.photo-viewer-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    margin-top: 0.65rem;
    padding: 0 0.25rem;
    color: var(--text);
    font-size: 0.82rem;
}
.photo-viewer-counter { color: var(--muted); min-width: 3rem; text-align: center; }
.photo-viewer-toolbar .btn,
.photo-viewer-toolbar a.btn {
    min-width: auto;
    min-height: 36px;
    padding: 0.35rem 0.65rem;
    font-size: 0.82rem;
}
.photo-viewer-close {
    position: absolute;
    top: max(0.35rem, env(safe-area-inset-top));
    right: max(0.35rem, env(safe-area-inset-right));
    z-index: 2;
}

@media (max-width: 520px) {
    .photo-viewer-panel {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
        gap: 0.5rem;
    }
    .photo-viewer-nav--prev,
    .photo-viewer-nav--next {
        display: none;
    }
    .photo-viewer-toolbar { font-size: 0.78rem; }
}

.contact-export-wrap {
    display: flex;
    gap: 0.45rem;
    align-items: flex-start;
    margin: 0.35rem 0.5rem;
}
.contact-export-wrap .export-checkbox {
    width: auto;
    min-height: 44px;
    margin-top: 0.35rem;
    display: none;
    flex-shrink: 0;
}
.contact-export-link {
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: inherit;
}
.contact-export-body { min-width: 0; }

.btn.secondary.active {
    outline: 2px solid var(--accent);
}

.timeline-row {
    border-left: 4px solid var(--timeline-color, #64748b);
}
.timeline-dot {
    border-color: var(--timeline-color, #64748b);
    color: var(--timeline-color, #93c5fd);
}
.timeline-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.25rem;
}
.timeline-chip {
    display: inline-block;
    border-radius: 999px;
    padding: 0.1rem 0.45rem;
    font-size: 0.72rem;
    border: 1px solid var(--chip-color, #64748b);
    color: #e2e8f0;
    background: rgba(2, 6, 23, 0.45);
}
.timeline-chip.muted-chip {
    border-color: #475569;
    color: #cbd5e1;
}
