:root {
    --bg: #f4f7fb;
    --card: #ffffff;
    --line: #d8e1ec;
    --text: #1f2937;
    --muted: #64748b;
    --primary: #1d4ed8;
    --primary-dark: #1e40af;
    --secondary: #e2e8f0;
    --success: #15803d;
    --warning: #b45309;
    --danger: #b91c1c;
    --info: #0369a1;
    --radius: 14px;
    --shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
    text-decoration: none;
}

.layout {
    min-height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: #0f172a;
    color: #fff;
    flex-wrap: wrap;
}

.brand-row {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.brand {
    font-size: 1.125rem;
    font-weight: 700;
}

.version {
    font-size: .8rem;
    opacity: .7;
    padding: .2rem .5rem;
    border: 1px solid rgba(255, 255, 255, .15);
    border-radius: 999px;
}

.nav {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.nav a {
    padding: .6rem .8rem;
    border-radius: 10px;
    color: rgba(255, 255, 255, .85);
}

.nav a.active,
.nav a:hover {
    background: rgba(255, 255, 255, .12);
    color: #fff;
}

.user-meta {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.user-meta small {
    color: rgba(255, 255, 255, .72);
}

.content {
    max-width: 1360px;
    margin: 0 auto;
    padding: 1.5rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.page-header.compact {
    margin-bottom: 1.5rem;
}

.page-header h1,
.section-head h2,
.section-title {
    margin: 0 0 .25rem;
}

.page-header p,
.muted {
    color: var(--muted);
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

.card.narrow {
    max-width: 520px;
    margin: 3rem auto;
}

.card.wide {
    max-width: 980px;
    margin: 1rem auto;
}

.stats-grid,
.grid-two {
    display: grid;
    gap: 1rem;
    margin-bottom: 1rem;
}

.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.small-gap {
    margin-bottom: 1rem;
}

.grid-two {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow);
}

.stat-card .label {
    display: block;
    color: var(--muted);
    margin-bottom: .4rem;
}

.stat-card strong {
    font-size: 1.35rem;
    line-height: 1.2;
}

.button,
button,
input,
select,
textarea {
    font: inherit;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: 40px;
    padding: .7rem 1rem;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
    background: var(--primary);
    color: #fff;
    transition: background .15s ease;
}

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

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

.button-secondary:hover {
    background: #cfd8e3;
}

.button-small {
    min-height: 34px;
    padding: .4rem .7rem;
    font-size: .9rem;
}

.button-group {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    align-items: center;
}

.button-group.inline {
    gap: .4rem;
}

.toolbar {
    display: flex;
    gap: .75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.toolbar input[type="search"] {
    min-width: min(420px, 100%);
    flex: 1 1 280px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.form-grid.single-column {
    grid-template-columns: 1fr;
}

.form-grid label {
    display: flex;
    flex-direction: column;
    gap: .45rem;
}

.form-grid label span {
    font-weight: 600;
}

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

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: .75rem .85rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
}

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

.form-actions {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
}

.alert {
    padding: .95rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.alert-success {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}

.alert-error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

.alert-info {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1d4ed8;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    padding: .8rem .7rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

thead th {
    color: var(--muted);
    font-size: .92rem;
    font-weight: 700;
    background: #f8fafc;
}

.center {
    text-align: center;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .25rem .55rem;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 600;
}

.badge-warning { background: #fff7ed; color: var(--warning); }
.badge-success { background: #f0fdf4; color: var(--success); }
.badge-danger { background: #fef2f2; color: var(--danger); }
.badge-info { background: #eff6ff; color: var(--info); }
.badge-neutral { background: #f1f5f9; color: #334155; }

.meta-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: .9rem 1rem;
}

.meta-list dt {
    color: var(--muted);
    margin-bottom: .25rem;
    font-size: .95rem;
}

.meta-list dd {
    margin: 0;
    font-weight: 600;
}

.code-block {
    display: block;
    padding: .85rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #0f172a;
    color: #e2e8f0;
    overflow-x: auto;
    white-space: nowrap;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .9rem;
    flex-wrap: wrap;
}

.simple-list {
    margin: 0;
    padding-left: 1.2rem;
}

.top-gap {
    margin-top: 1rem;
}

@media (max-width: 840px) {
    .form-grid,
    .grid-two {
        grid-template-columns: 1fr;
    }

    .topbar,
    .page-header {
        align-items: flex-start;
    }

    .user-meta {
        justify-content: flex-start;
    }
}


.topbar {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
}

.topbar-main,
.topbar-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.topbar-panel {
    padding-top: .25rem;
}

.user-meta-details {
    display: flex;
    flex-direction: column;
    gap: .15rem;
}

.nav-toggle {
    display: none;
    min-height: 40px;
    padding: .6rem .9rem;
    border: 1px solid rgba(255, 255, 255, .18);
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

.nav-toggle:hover {
    background: rgba(255, 255, 255, .16);
}

table.responsive-table {
    min-width: 760px;
}

.mobile-sticky-actions {
    margin-top: 1rem;
}

@media (max-width: 840px) {
    .topbar {
        position: sticky;
        top: 0;
        z-index: 40;
        padding: 1rem;
    }

    .topbar-main {
        width: 100%;
        justify-content: space-between;
    }

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

    .has-js .topbar-panel {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: .9rem;
        border-top: 1px solid rgba(255, 255, 255, .12);
        padding-top: .9rem;
    }

    .has-js .topbar-panel.is-open {
        display: flex;
    }

    .nav {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .nav a {
        width: 100%;
    }

    .user-meta {
        width: 100%;
        justify-content: space-between;
        align-items: center;
        padding-top: .8rem;
        border-top: 1px solid rgba(255, 255, 255, .08);
    }

    .user-meta .button {
        width: auto;
    }

    .page-header,
    .topbar {
        align-items: stretch;
    }

    .page-header .button-group,
    .page-header .button-group form,
    .form-actions form {
        width: 100%;
    }

    .page-header .button-group > *,
    .form-actions > * {
        flex: 1 1 100%;
    }

    .page-header .button,
    .page-header button,
    .form-actions .button,
    .form-actions button {
        width: 100%;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar input[type="search"] {
        min-width: 100%;
    }
}

@media (max-width: 760px) {
    body {
        font-size: 15px;
    }

    .content {
        padding: 1rem;
    }

    .card,
    .stat-card {
        padding: 1rem;
    }

    input,
    select,
    textarea {
        font-size: 16px;
    }

    .button-group {
        width: 100%;
    }

    .button-group > * {
        flex: 1 1 100%;
    }

    .button-group.inline {
        width: 100%;
        justify-content: stretch;
    }

    .button-group.inline > * {
        flex: 1 1 100%;
    }

    .table-wrap {
        overflow: visible;
    }

    .table-wrap table.responsive-table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    .table-wrap table.responsive-table,
    .table-wrap table.responsive-table tbody,
    .table-wrap table.responsive-table tr,
    .table-wrap table.responsive-table td {
        display: block;
        width: 100%;
    }

    .table-wrap table.responsive-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        border: 0;
        white-space: nowrap;
    }

    .table-wrap table.responsive-table tbody {
        display: grid;
        gap: .85rem;
    }

    .table-wrap table.responsive-table tr {
        background: var(--card);
        border: 1px solid var(--line);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        overflow: hidden;
    }

    .table-wrap table.responsive-table td {
        display: grid;
        grid-template-columns: minmax(110px, 42%) 1fr;
        gap: .8rem;
        align-items: start;
        padding: .8rem 1rem;
        border-bottom: 1px solid var(--line);
        min-width: 0;
    }

    .table-wrap table.responsive-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: .87rem;
        font-weight: 700;
        line-height: 1.4;
    }

    .table-wrap table.responsive-table td:last-child {
        border-bottom: 0;
    }

    .table-wrap table.responsive-table td .button,
    .table-wrap table.responsive-table td button,
    .table-wrap table.responsive-table td .button-group,
    .table-wrap table.responsive-table td input,
    .table-wrap table.responsive-table td select,
    .table-wrap table.responsive-table td textarea {
        width: 100%;
        min-width: 0;
    }

    .table-wrap table.responsive-table td .button-group.inline {
        gap: .5rem;
    }

    .table-wrap table.responsive-table tr.empty-row td {
        display: block;
        text-align: center;
    }

    .table-wrap table.responsive-table tr.empty-row td::before {
        content: none;
    }

    .code-block {
        white-space: pre-wrap;
        word-break: break-all;
    }

    .mobile-sticky-actions {
        position: sticky;
        bottom: .5rem;
        z-index: 5;
        padding-top: .9rem;
        background: linear-gradient(to top, rgba(244, 247, 251, .98), rgba(244, 247, 251, .9) 68%, rgba(244, 247, 251, 0));
    }
}

.top-gap {
    margin-top: 1rem;
}

.quick-receive-layout {
    align-items: start;
}

.quick-scan-card,
.quick-form-card {
    min-width: 0;
}

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

.scanner-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: .9rem;
}

.scanner-panel {
    position: relative;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    background: #0f172a;
    min-height: 240px;
    overflow: hidden;
}

.scanner-video,
.scanner-placeholder {
    width: 100%;
    min-height: 240px;
}

.scanner-video {
    display: none;
    object-fit: cover;
    background: #000;
}

.scanner-video.is-active {
    display: block;
}

.scanner-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: rgba(255,255,255,.78);
    padding: 1rem;
}

.callout {
    border-radius: 12px;
    padding: .9rem 1rem;
    border: 1px solid var(--line);
}

.callout-info {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.callout-warning {
    background: #fff7ed;
    border-color: #fed7aa;
}

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
    margin-top: .2rem;
}

.stacked-mobile {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
}

@media (max-width: 760px) {
    .compact-grid {
        grid-template-columns: 1fr;
    }

    .scanner-panel,
    .scanner-video,
    .scanner-placeholder {
        min-height: 280px;
    }

    .stacked-mobile > * {
        flex: 1 1 100%;
    }
}

.stack-list {
    display: flex;
    flex-direction: column;
    gap: .85rem;
}

.stack-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem 0;
    border-bottom: 1px solid var(--line);
}

.stack-item:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.stack-item-actions {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}

.inventory-layout {
    align-items: start;
}

@media (max-width: 760px) {
    .stack-item {
        flex-direction: column;
        align-items: flex-start;
    }
}

body.installer-page .content {
    max-width: 1280px;
    padding-top: 2rem;
    padding-bottom: 2rem;
}

body.installer-page .topbar {
    padding: .9rem 1.25rem;
}

body.installer-page .topbar-panel {
    display: none;
}

.installer-shell {
    width: 100%;
}

.installer-grid {
    display: grid;
    grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.installer-sidebar {
    position: sticky;
    top: 1rem;
    min-width: 0;
    width: 100%;
    overflow: hidden;
}

.installer-sidebar .page-header,
.installer-sidebar .installer-checklist,
.installer-sidebar .installer-help {
    max-width: 100%;
}

.installer-main {
    max-width: 100%;
}

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-section {
    margin: 0;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    min-width: 0;
}

.form-section legend {
    padding: 0 .5rem;
    font-weight: 700;
}

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

.check-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: .85rem;
}

.check-list li {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: .75rem;
    align-items: start;
    padding-bottom: .85rem;
    border-bottom: 1px solid var(--line);
}

.check-list li:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.small-text {
    font-size: .92rem;
}

.installer-actions {
    justify-content: flex-start;
}

.installer-main .alert ul,
.installer-sidebar .simple-list {
    margin-bottom: 0;
}

.installer-sidebar,
.installer-sidebar * {
    min-width: 0;
}

.installer-sidebar .check-list li > div {
    min-width: 0;
}

.installer-sidebar .small-text,
.installer-sidebar code,
.installer-sidebar .muted {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.installer-sidebar code {
    white-space: normal;
}

@media (max-width: 980px) {
    .installer-grid {
        grid-template-columns: 1fr;
    }

    .installer-sidebar {
        position: static;
    }
}

@media (max-width: 760px) {
    .form-grid-balanced {
        grid-template-columns: 1fr;
    }

    body.installer-page .content {
        padding: 1rem;
    }

    .form-section {
        padding: .85rem;
    }
}


.installer-sidebar .check-list li {
    gap: .65rem;
}

.installer-sidebar .check-list li > div,
.installer-sidebar .check-list li strong,
.installer-sidebar .check-list li .muted {
    display: block;
    max-width: 100%;
}

.installer-sidebar .badge {
    justify-self: start;
    white-space: nowrap;
}

.installer-sidebar .muted.small-text {
    margin-top: .2rem;
    line-height: 1.4;
}

.installer-sidebar .simple-list li {
    overflow-wrap: anywhere;
    word-break: break-word;
}


.field-error {
    margin-top: .35rem;
    color: #b42318;
    font-size: .92rem;
    font-weight: 600;
}

.installer-intro p + p {
    margin-top: .5rem;
}
