:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #64748b;
    --line: #d9e0e8;
    --primary: #176b5f;
    --primary-dark: #0f4f46;
    --danger: #b42318;
    --shadow: 0 14px 36px rgba(25, 35, 45, 0.08);
}

* {
    box-sizing: border-box;
}

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

body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    z-index: 1000;
    transition: opacity 180ms ease;
}

body.scan-feedback-success::after {
    background: rgba(24, 128, 78, 0.28);
    opacity: 1;
}

body.scan-feedback-error::after {
    background: rgba(180, 35, 24, 0.28);
    opacity: 1;
}

a {
    color: inherit;
}

input,
select,
button,
fieldset {
    min-height: 44px;
    border-radius: 8px;
    font: inherit;
}

input {
    width: 100%;
    border: 1px solid var(--line);
    padding: 0 12px;
    background: #fff;
}

select {
    width: 100%;
    border: 1px solid var(--line);
    padding: 0 12px;
    background: #fff;
}

input[type="checkbox"] {
    width: 20px;
    min-height: 20px;
    accent-color: var(--primary);
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    padding: 0 16px;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
}

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

button:disabled,
.button:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

.button.secondary {
    background: #e8edf2;
    color: var(--text);
}

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

.button.danger:hover {
    background: #8f1c13;
}

.button.compact {
    min-height: 36px;
    padding: 0 12px;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-panel {
    width: min(100%, 420px);
    padding: 28px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.auth-panel h1,
.topbar h1 {
    margin: 0 0 8px;
}

.auth-panel p,
.eyebrow {
    margin: 0 0 20px;
    color: var(--muted);
}

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

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

.text-link {
    display: inline-block;
    margin-top: 18px;
    color: var(--primary-dark);
    font-weight: 700;
}

.text-link.no-margin {
    margin-top: 0;
    margin-bottom: 8px;
}

.auth-secondary-link {
    margin-left: 14px;
}

.form-message {
    min-height: 22px;
    margin: 0;
    color: var(--danger);
}

.form-message.neutral {
    color: var(--muted);
}

.app-shell {
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: 20px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.topbar-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.eyebrow {
    margin-bottom: 4px;
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
}

.toolbar,
.table-wrap {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 18px;
}

.toolbar.vertical {
    display: grid;
    gap: 12px;
}

.inline-form,
.stock-form {
    display: grid;
    gap: 10px;
}

.scanner-actions {
    display: grid;
    gap: 8px;
}

.scanner-actions .button {
    width: fit-content;
}

.scanner-status {
    margin: 0;
}

.barcode-scanner {
    display: grid;
    gap: 10px;
}

.barcode-scanner[hidden] {
    display: none;
}

.barcode-viewport {
    position: relative;
    overflow: hidden;
    width: 100%;
    min-height: 240px;
    aspect-ratio: 4 / 3;
    background: #0f172a;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.barcode-viewport video,
.barcode-viewport canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.inventory-card {
    min-height: 132px;
    display: grid;
    align-content: space-between;
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    text-decoration: none;
}

.inventory-card.is-selected {
    border-color: var(--primary);
    box-shadow: 0 14px 36px rgba(23, 107, 95, 0.14);
}

.inventory-card strong {
    color: var(--primary-dark);
}

.inventory-card h2 {
    margin: 0 0 8px;
    font-size: 1.2rem;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 0.86rem;
}

.table-actions {
    text-align: right;
    white-space: nowrap;
}

.stock-table {
    table-layout: fixed;
}

.stock-table th:first-child,
.stock-table td:first-child {
    width: 48%;
}

.stock-quantity {
    font-weight: 800;
}

.stock-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.stock-actions .button {
    min-width: 48px;
}

.stock-state-actions {
    display: inline-flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.admin-shell {
    width: min(1360px, 100%);
}

.settings-shell {
    width: min(900px, 100%);
}

.settings-grid,
.shopping-list {
    display: grid;
    gap: 18px;
}

.settings-panel {
    padding: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.settings-panel h2 {
    margin: 0 0 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-options {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 14px;
    border: 1px solid var(--line);
}

.settings-options:disabled {
    opacity: 0.58;
}

.shopping-list-items {
    display: grid;
}

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

.shopping-list-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.shopping-list-product {
    overflow-wrap: anywhere;
}

.shopping-list-quantity {
    font-weight: 800;
}

.shopping-list-actions {
    display: flex;
    gap: 6px;
}

.admin-layout {
    display: grid;
    grid-template-columns: minmax(260px, 340px) 1fr;
    gap: 18px;
    align-items: start;
}

.admin-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 18px;
}

.admin-workspace {
    min-height: 360px;
}

.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}

.panel-heading h2,
.panel-heading p {
    margin: 0;
}

.panel-heading.split {
    align-items: center;
}

.inventory-admin-list {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.inventory-list-button {
    min-height: 58px;
    display: grid;
    justify-items: start;
    gap: 2px;
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    text-align: left;
}

.inventory-list-button:hover,
.inventory-list-button.is-active {
    border-color: var(--primary);
    background: #eef7f5;
}

.admin-detail {
    display: grid;
    gap: 14px;
}

.admin-stock-form {
    padding-top: 4px;
}

.member-admin {
    display: grid;
    gap: 12px;
    padding: 14px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.member-admin h3,
.member-admin p {
    margin: 0;
}

.inline-table {
    padding: 0;
    margin: 0;
    border: 0;
    background: transparent;
}

.quantity-input {
    width: 96px;
}

.upload-form {
    display: grid;
    gap: 10px;
}

.import-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 32px;
    margin-top: 12px;
    color: var(--primary-dark);
    font-weight: 700;
}

.import-progress[hidden] {
    display: none;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid #c9d7d4;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (min-width: 720px) {
    .inline-form {
        grid-template-columns: 1fr auto;
    }

    .stock-form {
        grid-template-columns: 1fr 2fr 110px auto;
    }

    .shopping-list-form {
        grid-template-columns: minmax(160px, auto) 1fr auto;
    }

    .upload-form {
        grid-template-columns: 1fr auto;
        align-items: center;
    }
}

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

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

    table {
        min-width: 640px;
    }

    .stock-table-wrap {
        overflow-x: visible;
    }

    .stock-table {
        min-width: 0;
        table-layout: auto;
    }

    .stock-table thead {
        display: none;
    }

    .stock-table tbody,
    .stock-table tr,
    .stock-table td {
        display: block;
    }

    .stock-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 4px 10px;
        padding: 12px 0;
        border-bottom: 1px solid var(--line);
    }

    .stock-table td {
        padding: 0;
        border-bottom: 0;
    }

    .stock-table th:first-child,
    .stock-table td:first-child {
        width: auto;
    }

    .stock-product {
        grid-column: 1 / -1;
        font-weight: 750;
        overflow-wrap: anywhere;
    }

    .stock-quantity {
        align-self: center;
        font-size: 1.15rem;
    }

    .stock-updated {
        color: var(--muted);
        font-size: 0.86rem;
    }

    .stock-actions {
        grid-column: 1 / -1;
        grid-row: auto;
        align-self: start;
        justify-content: flex-start;
        margin-top: 8px;
        white-space: normal;
    }

    .stock-state-actions {
        justify-content: flex-start;
    }

    .shopping-list-item {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .shopping-list-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 900px) {
    .admin-layout {
        grid-template-columns: 1fr;
    }
}
