:root {
    --bg: #fffaf1;
    --panel: #ffffff;
    --ink: #2f261f;
    --muted: #6e6258;
    --line: #eadfce;
    --accent: #4f8a5b;
    --accent-dark: #32633d;
    --honey: #f1b84b;
    --cedar: #8a5a34;
    --danger: #b8433f;
    --shadow: 0 10px 30px rgba(47, 38, 31, .08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: var(--accent-dark);
}

.site-header {
    align-items: center;
    background: #fff6e4;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 16px;
    justify-content: space-between;
    padding: 12px clamp(16px, 4vw, 40px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    align-items: center;
    color: var(--ink);
    display: inline-flex;
    font-size: 1.15rem;
    font-weight: 800;
    gap: 10px;
    text-decoration: none;
}

.brand-mark {
    align-items: center;
    background: var(--cedar);
    border-radius: 8px;
    color: white;
    display: inline-flex;
    font-size: .85rem;
    height: 34px;
    justify-content: center;
    width: 34px;
}

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

.page {
    margin: 0 auto;
    max-width: 1100px;
    padding: 24px clamp(16px, 4vw, 40px) 48px;
}

.hero {
    display: grid;
    gap: 16px;
    padding: 28px 0;
}

h1, h2, h3 {
    line-height: 1.15;
    margin: 0 0 12px;
}

p {
    margin: 0 0 14px;
}

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

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

.stat-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.stat-card {
    background: #fff8ec;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.stat-card strong {
    display: block;
    font-size: 2rem;
    line-height: 1;
}

.stat-card span {
    color: var(--muted);
}

.card, .form-panel, .detail-panel, .empty-state {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 18px;
}

.card {
    display: grid;
    gap: 8px;
}

.card h2, .card h3 {
    margin-bottom: 0;
}

.settings-section {
    margin: 28px 0;
}

.section-heading {
    margin-bottom: 12px;
}

.section-heading h2 {
    margin-bottom: 4px;
}

.admin-card {
    align-content: start;
}

.lookup-panel {
    margin-bottom: 18px;
}

.manual-entry-note {
    color: var(--ink);
    font-size: 1rem;
    margin: -4px 0 18px;
}

.lookup-result {
    align-content: start;
}

.list-tools {
    align-items: end;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(220px, 1fr) auto;
    margin-bottom: 14px;
}

.scanner-modal {
    align-items: center;
    background: rgba(32, 27, 24, 0.72);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 18px;
    position: fixed;
    z-index: 1000;
}

.scanner-dialog {
    background: var(--panel);
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-width: 560px;
    padding: 18px;
    width: min(100%, 560px);
}

.scanner-header {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
}

.scanner-video {
    aspect-ratio: 4 / 3;
    background: #201b18;
    border-radius: 8px;
    display: block;
    object-fit: cover;
    width: 100%;
}

.scanner-reader {
    background: #201b18;
    border-radius: 8px;
    min-height: 240px;
    overflow: hidden;
    width: 100%;
}

.scanner-reader video {
    object-fit: contain;
    width: 100%;
}

.scanner-reader img {
    display: block;
    max-height: 260px;
    object-fit: contain;
    width: 100%;
}

.scanner-reader:empty {
    align-items: center;
    display: flex;
    justify-content: center;
}

.scanner-status {
    margin-top: 12px;
}

.compact-form-row {
    align-items: end;
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(160px, 1fr) auto;
}

.item-card {
    align-items: center;
    display: grid;
    gap: 14px;
    grid-template-columns: 1fr;
}

.item-card.has-photo {
    grid-template-columns: auto 1fr;
}

.item-card-thumb {
    aspect-ratio: 1 / 1;
    background: #fff8ec;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: block;
    height: 78px;
    overflow: hidden;
    width: 78px;
}

.item-card-thumb img {
    display: block;
    height: 100%;
    object-fit: cover;
    width: 100%;
}

.item-card-body {
    min-width: 0;
}

.item-preview-section {
    margin-top: 18px;
}

.item-preview-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.member-card {
    min-height: 128px;
    position: relative;
}

.member-card-actions {
    align-items: flex-start;
    display: flex;
    gap: 8px;
    position: absolute;
    right: 16px;
    top: 14px;
    z-index: 3;
}

.member-card-actions details {
    position: relative;
}

.member-card-actions summary {
    color: var(--accent-dark);
    cursor: pointer;
    font-weight: 700;
    list-style: none;
    text-decoration: underline;
}

.member-card-actions summary::-webkit-details-marker {
    display: none;
}

.member-edit-popover {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 10px;
    min-width: 220px;
    padding: 12px;
    position: absolute;
    right: 0;
    top: 28px;
}

.danger-link {
    color: var(--danger);
    font-weight: 700;
    text-decoration: underline;
}

.actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 16px 0;
}

button, .button {
    background: var(--accent);
    border: 0;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 700;
    min-height: 42px;
    padding: 9px 14px;
    text-decoration: none;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

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

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

.danger-button {
    background: var(--danger);
}

.danger-button:hover {
    background: #8f302d;
}

.danger-zone .detail-panel {
    border-color: #e6b7b4;
}

.delete-dialog {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    color: var(--ink);
    max-width: 520px;
    padding: 22px;
    width: min(calc(100% - 32px), 520px);
}

.delete-dialog::backdrop {
    background: rgba(32, 27, 24, 0.72);
}

.delete-dialog-actions {
    align-items: center;
    display: flex;
    gap: 36px;
    justify-content: space-between;
    margin-top: 22px;
}

.delete-dialog-actions form {
    margin: 0;
}

.link-button {
    background: transparent;
    color: var(--accent-dark);
    min-height: 0;
    padding: 0;
}

.inline {
    display: inline;
}

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

input, select, textarea {
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    font: inherit;
    padding: 10px 12px;
    width: 100%;
}

[hidden] {
    display: none !important;
}

textarea {
    min-height: 110px;
    resize: vertical;
}

.form-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.form-subsection {
    border-top: 1px solid var(--line);
    margin-top: 18px;
    padding-top: 18px;
}

.form-full {
    grid-column: 1 / -1;
}

input[readonly] {
    background: #fff8ec;
    color: var(--muted);
}

.flash {
    border-radius: 8px;
    font-weight: 700;
    margin-bottom: 16px;
    padding: 12px 14px;
}

.notice {
    background: #e8f4e9;
    color: #244f2d;
}

.error {
    background: #fae7e4;
    color: #7e2a27;
}

.pill {
    background: #f7ecd7;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    display: inline-flex;
    font-size: .88rem;
    padding: 4px 9px;
}

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

.meta-list div {
    background: #fff8ec;
    border-radius: 8px;
    padding: 10px;
}

.meta-list dt {
    color: var(--muted);
    font-size: .82rem;
    font-weight: 800;
    text-transform: uppercase;
}

.meta-list dd {
    margin: 2px 0 0;
}

.section-heading {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.photo-panel {
    margin-top: 18px;
}

.photo-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    margin: 12px 0 16px;
}

.photo-tile {
    display: grid;
    gap: 8px;
    margin: 0;
}

.photo-tile form {
    display: flex;
    justify-content: flex-start;
}

.photo-tile .danger-button {
    font-size: .88rem;
    min-height: 34px;
    padding: 6px 10px;
}

.photo-thumb {
    aspect-ratio: 1 / 1;
    background: #fff8ec;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: block;
    overflow: hidden;
}

.photo-thumb img {
    display: block;
    height: 100%;
    object-fit: contain;
    width: 100%;
}

.photo-upload {
    border-top: 1px solid var(--line);
    display: grid;
    gap: 10px;
    margin-top: 14px;
    padding-top: 14px;
}

.photo-viewer {
    display: grid;
    gap: 16px;
}

.photo-viewer img {
    border-radius: 8px;
    display: block;
    height: auto;
    max-width: 100%;
}

.qr-label {
    align-items: center;
    aspect-ratio: 1 / 1;
    background: #fff;
    border: 10px solid #fff;
    box-sizing: border-box;
    box-shadow: inset 0 0 0 1px var(--line);
    display: flex;
    justify-content: center;
    max-width: 260px;
    width: 100%;
}

.qr-label img {
    display: block;
    height: auto;
    max-width: 100%;
    width: 100%;
}

.label-url {
    overflow-wrap: anywhere;
}

@media (max-width: 640px) {
    .site-header {
        align-items: flex-start;
        flex-direction: column;
    }

    nav {
        justify-content: flex-start;
    }

    .list-tools,
    .compact-form-row {
        grid-template-columns: 1fr;
    }

    button,
    .button,
    .actions > form,
    .actions > form button,
    .delete-dialog-actions form,
    .delete-dialog-actions button {
        justify-content: center;
        width: 100%;
    }

    .delete-dialog-actions {
        align-items: stretch;
        flex-direction: column;
        gap: 18px;
    }

    .member-card {
        padding-top: 48px;
    }
}

@media print {
    @page {
        margin: 0;
        size: 62mm auto;
    }

    :root {
        --ink: #000;
        --line: #000;
    }

    body {
        background: #fff;
        color: #000;
        margin: 0;
    }

    .site-header,
    .no-print {
        display: none !important;
    }

    .page {
        margin: 0;
        max-width: none;
        padding: 0;
    }

    .detail-panel {
        border: 0;
        border-radius: 0;
        box-shadow: none;
        padding: 3mm;
    }

    .print-label {
        align-items: center;
        display: grid;
        gap: 2mm;
        justify-items: center;
        width: 54mm;
    }

    .print-label h1 {
        font-size: 12pt;
        margin: 0;
        max-width: 54mm;
        overflow-wrap: anywhere;
        text-align: center;
    }

    .qr-label {
        border: 1mm solid #fff;
        box-shadow: inset 0 0 0 .2mm #000;
        max-width: none;
        width: 40mm;
    }

    .qr-label img {
        max-width: none;
        width: 100%;
    }

    .label-url {
        font-size: 7pt;
        line-height: 1.2;
        margin: 0;
        max-width: 54mm;
        text-align: center;
    }

    .label-url a {
        color: #000;
        text-decoration: none;
    }
}
