:root {
    color-scheme: dark;
    --bg: #11110f;
    --bg-soft: #171714;
    --surface: #1e1e1a;
    --surface-2: #27261f;
    --border: #38362d;
    --text: #f4f1e8;
    --muted: #a9a293;
    --accent: #78dcca;
    --accent-2: #8fb3ff;
    --warning: #e4b93a;
    --danger: #ff6961;
    --success: #7ac77d;
    --shadow: 0 24px 70px rgba(0, 0, 0, .28);
    --control-height: 46px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

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

img {
    display: block;
    max-width: 100%;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: 2rem;
    line-height: 1.1;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 1rem;
    font-size: 1.05rem;
    letter-spacing: 0;
}

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

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem;
    background: linear-gradient(150deg, #11110f 0%, #171714 48%, #121817 100%);
}

.auth-card {
    width: min(440px, 100%);
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(30, 30, 26, .92);
    box-shadow: var(--shadow);
}

.setup-card {
    width: min(520px, 100%);
}

.brand-mark {
    width: fit-content;
    min-width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 8px;
    background: var(--accent);
    color: #10201d;
    font-size: .92rem;
    font-weight: 800;
    padding: 0 .9rem;
    white-space: nowrap;
}

.stack {
    display: grid;
    gap: 1rem;
}

label {
    display: grid;
    gap: .45rem;
}

label > span,
.eyebrow {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    min-height: var(--control-height);
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #141411;
    color: var(--text);
    font: inherit;
    padding: .65rem .75rem;
    outline: none;
}

select {
    appearance: none;
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23f4f1e8' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"),
        linear-gradient(var(--surface-2), var(--surface-2));
    background-position: right 11px center, right top;
    background-repeat: no-repeat;
    background-size: 18px 18px, 40px 100%;
    padding-right: 3.2rem;
}

select::-ms-expand {
    display: none;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(120, 220, 202, .12);
}

input[type="color"] {
    padding: .25rem;
}

.button {
    min-height: var(--control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 750;
    padding: .62rem .9rem;
    cursor: pointer;
}

.button:hover {
    border-color: #555044;
    background: #302f27;
}

.button-primary {
    border-color: transparent;
    background: var(--accent);
    color: #10201d;
}

.button-primary:hover {
    background: #8cead9;
}

.button-danger {
    border-color: rgba(255, 105, 97, .45);
    color: #ffd6d3;
}

.button-small {
    min-height: var(--control-height);
    padding: .42rem .62rem;
    font-size: .88rem;
}

.full {
    width: 100%;
}

.mobile-header,
.menu-backdrop {
    display: none;
}

.menu-toggle {
    width: 46px;
    height: 46px;
    display: inline-grid;
    place-items: center;
    gap: 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    padding: .7rem;
    cursor: pointer;
}

.menu-toggle span {
    width: 20px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.25rem;
    border-right: 1px solid var(--border);
    background: #151512;
}

.app-brand {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    gap: .55rem;
}

.app-brand strong {
    display: block;
}

.nav {
    display: grid;
    gap: .3rem;
}

.nav a,
.sidebar-footer a {
    min-height: 40px;
    display: flex;
    align-items: center;
    border-radius: 8px;
    color: var(--muted);
    padding: .55rem .7rem;
}

.nav a:hover,
.sidebar-footer a:hover,
.nav a.active {
    background: var(--surface-2);
    color: var(--text);
}

.nav a.active {
    box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-footer {
    display: grid;
    gap: .2rem;
    margin-top: auto;
}

.main {
    width: min(1480px, 100%);
    display: grid;
    align-content: start;
    gap: 1.25rem;
    padding: 1.5rem;
    overflow-x: hidden;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: .4rem;
}

.eyebrow {
    margin-bottom: .35rem;
}

.flash {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .85rem 1rem;
    background: var(--surface);
}

.flash-success {
    border-color: rgba(122, 199, 125, .45);
    color: #d8f7da;
}

.flash-error {
    border-color: rgba(255, 105, 97, .5);
    color: #ffd6d3;
}

.flash-warning {
    border-color: rgba(228, 185, 58, .5);
    color: #ffe7a3;
}

.install-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border: 1px solid rgba(120, 220, 202, .38);
    border-radius: 8px;
    padding: .85rem 1rem;
    background: rgba(120, 220, 202, .08);
}

.install-card[hidden] {
    display: none;
}

.install-card strong,
.install-card p {
    margin: 0;
}

.install-card p {
    color: var(--muted);
}

.install-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.panel,
.stat-card,
.item-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 14px 34px rgba(0, 0, 0, .16);
}

.panel {
    min-width: 0;
    padding: 1.1rem;
}

.content-grid > * {
    min-width: 0;
}

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

.panel-head h2 {
    margin: 0;
}

.panel-head a {
    color: var(--accent);
    font-weight: 750;
}

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

.stat-card {
    padding: 1rem;
}

.stat-card span,
.stat-card small {
    display: block;
}

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

.stat-card.danger strong {
    color: var(--danger);
}

.stat-card.warning strong {
    color: var(--warning);
}

.content-grid {
    display: grid;
    gap: 1rem;
}

.page-stack {
    display: grid;
    gap: 1rem;
}

.management-form {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(180px, 260px) minmax(150px, 190px);
    align-items: end;
    gap: .75rem;
}

.management-form > h2,
.management-form > .muted,
.management-form > .field-full {
    grid-column: 1 / -1;
}

.management-form > h2,
.management-form > .muted {
    margin-bottom: 0;
}

.management-form textarea {
    min-height: 78px;
}

.management-form .button {
    justify-self: start;
    min-width: 220px;
}

.user-create-form {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: .85rem;
}

.user-create-form > h2 {
    grid-column: 1 / -1;
    margin-bottom: 0;
}

.user-create-form .button {
    justify-self: start;
    min-width: 220px;
}

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

.account-layout {
    max-width: 760px;
}

.mini-list {
    display: grid;
    gap: .6rem;
}

.mini-row {
    min-height: 56px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: .75rem;
    padding: .65rem;
    border: 1px solid rgba(255, 255, 255, .04);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
}

.mini-row strong,
.mini-row small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    width: max-content;
    max-width: 100%;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: .78rem;
    font-style: normal;
    font-weight: 800;
    padding: .25rem .6rem;
}

.badge.danger,
.badge.expired {
    border-color: rgba(255, 105, 97, .5);
    color: #ffd6d3;
    background: rgba(255, 105, 97, .1);
}

.badge.warning {
    border-color: rgba(228, 185, 58, .5);
    color: #ffe7a3;
    background: rgba(228, 185, 58, .1);
}

.badge.ok {
    border-color: rgba(122, 199, 125, .45);
    color: #d8f7da;
    background: rgba(122, 199, 125, .08);
}

.category-bars {
    display: grid;
    gap: .75rem;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) 2fr auto;
    align-items: center;
    gap: .7rem;
}

.bar-row div {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #141411;
}

.bar-row i {
    display: block;
    height: 100%;
    min-width: 3px;
}

.filters {
    display: grid;
    grid-template-columns: 1.4fr repeat(4, minmax(150px, 1fr)) auto;
    align-items: end;
    gap: .8rem;
}

.items-tools {
    display: grid;
    gap: 1rem;
}

.view-toggle {
    display: flex;
    align-items: end;
    justify-content: flex-end;
    gap: .7rem;
}

.view-toggle > span {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .08em;
    line-height: var(--control-height);
    text-transform: uppercase;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-width: 230px;
    min-height: var(--control-height);
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #141411;
}

.segmented button {
    min-height: var(--control-height);
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.segmented button + button {
    border-left: 1px solid var(--border);
}

.segmented button.active {
    background: var(--accent);
    color: #10201d;
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(286px, 1fr));
    gap: 1rem;
}

.inventory-list {
    display: grid;
    gap: .85rem;
}

.item-card {
    display: grid;
    overflow: hidden;
}

.item-list-row {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr) auto minmax(250px, auto);
    align-items: center;
    gap: 1rem;
    padding: .85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 14px 34px rgba(0, 0, 0, .16);
}

.list-image {
    width: 92px;
    height: 92px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 8px;
    background: #151512;
}

.list-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.list-image span {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--accent);
    font-size: 1.35rem;
    font-weight: 850;
}

.list-main {
    display: grid;
    gap: .45rem;
    min-width: 0;
}

.list-main p {
    margin: 0;
    color: var(--muted);
}

.list-status {
    display: flex;
    justify-content: flex-end;
}

.list-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .7rem;
}

.item-image {
    aspect-ratio: 16 / 9;
    display: grid;
    place-items: center;
    background: #151512;
}

.item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.item-image span {
    display: grid;
    place-items: center;
    width: 76px;
    height: 76px;
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--accent);
    font-size: 2rem;
    font-weight: 850;
}

.item-body {
    display: grid;
    gap: .55rem;
    padding: 1rem;
}

.item-title {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: .5rem;
}

.item-title h2 {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-body p {
    margin: 0;
    color: var(--muted);
}

.item-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem .75rem;
    color: var(--muted);
    font-size: .9rem;
}

.item-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .7rem;
    padding: 0 1rem 1rem;
}

.consume-form {
    display: grid;
    grid-template-columns: 58px auto;
    gap: .45rem;
}

.consume-form input {
    min-height: 34px;
    padding: .35rem .45rem;
}

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

.wide-form {
    width: 100%;
}

.span-2 {
    grid-column: span 2;
}

.image-upload {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 1rem;
    align-items: center;
}

.image-preview {
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px dashed var(--border);
    border-radius: 8px;
    background: #141411;
    color: var(--muted);
}

.image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.checkline {
    display: flex;
    align-items: center;
    gap: .55rem;
}

.checkline input {
    width: 18px;
    min-height: 18px;
}

.checkline span {
    letter-spacing: 0;
    text-transform: none;
}

.checkline.compact {
    justify-content: center;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: .7rem;
}

.editable-list {
    display: grid;
    gap: .85rem;
}

.editable-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    align-items: end;
    gap: .75rem;
    min-width: 0;
    padding: .85rem;
    border: 1px solid rgba(255, 255, 255, .05);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
}

.editable-row label {
    min-width: 0;
}

.editable-row input,
.editable-row select,
.editable-row .button {
    min-height: var(--control-height);
}

.location-row {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.user-row {
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
    align-items: end;
}

.edit-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: .5rem;
    align-items: end;
}

.edit-actions .button {
    height: var(--control-height);
    width: 100%;
}

.editable-row .checkline.compact {
    align-self: end;
    min-height: var(--control-height);
    justify-content: flex-start;
}

.location-groups {
    display: grid;
    gap: 1rem;
}

.location-group {
    display: grid;
    gap: .75rem;
    padding: 1rem;
    border: 1px solid rgba(255, 255, 255, .05);
    border-radius: 8px;
    background: rgba(255, 255, 255, .02);
}

.location-group h3 {
    margin: 0;
    font-size: 1rem;
}

.child-location-list {
    display: grid;
    gap: .75rem;
    padding-left: 1rem;
    border-left: 2px solid var(--border);
}

.large {
    padding: 2rem;
    text-align: center;
}

@media (max-width: 1120px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

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

    .sidebar-footer {
        grid-template-columns: repeat(2, auto);
        justify-content: start;
    }

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

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

    .item-list-row {
        grid-template-columns: 76px minmax(0, 1fr);
    }

    .list-status,
    .list-actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .editable-row,
    .location-row,
    .user-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

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

    h1 {
        font-size: 1.55rem;
    }

    .main,
    .sidebar,
    .auth-body {
        padding: 1rem;
    }

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

    .topbar .button {
        width: 100%;
    }

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

    .stats-grid,
    .content-grid.two,
    .filters,
    .form-grid,
    .user-create-form,
    .editable-row,
    .location-row,
    .user-row {
        grid-template-columns: 1fr;
    }

    .user-create-form .button {
        width: 100%;
        min-width: 0;
        justify-self: stretch;
    }

    .child-location-list {
        padding-left: 0;
        border-left: 0;
    }

    .span-2 {
        grid-column: span 1;
    }

    .image-upload {
        grid-template-columns: 1fr;
    }

    .item-actions,
    .form-actions {
        align-items: stretch;
        flex-direction: column;
    }

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

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

    .view-toggle > span {
        line-height: 1.2;
    }

    .segmented {
        min-width: 0;
        width: 100%;
    }

    .item-list-row {
        grid-template-columns: 1fr;
    }

    .list-image {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 9;
    }

    .mini-row,
    .bar-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1120px) {
    body.menu-open {
        overflow: hidden;
    }

    .mobile-header {
        position: sticky;
        top: 0;
        z-index: 40;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        padding: .85rem 1rem;
        border-bottom: 1px solid var(--border);
        background: rgba(17, 17, 15, .96);
        backdrop-filter: blur(14px);
    }

    .app-shell {
        display: block;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 60;
        width: min(320px, calc(100vw - 2rem));
        height: 100dvh;
        overflow-y: auto;
        border-right: 1px solid var(--border);
        border-bottom: 0;
        box-shadow: var(--shadow);
        transform: translateX(-105%);
        transition: transform .18s ease;
    }

    body.menu-open .sidebar {
        transform: translateX(0);
    }

    .menu-backdrop {
        position: fixed;
        inset: 0;
        z-index: 50;
        background: rgba(0, 0, 0, .62);
    }

    body.menu-open .menu-backdrop {
        display: block;
    }

    .nav,
    .sidebar-footer {
        grid-template-columns: 1fr;
    }

    .main {
        padding: 1rem;
    }

    .management-form {
        width: 100%;
        grid-template-columns: 1fr;
    }

    .management-form .button {
        width: 100%;
        min-width: 0;
        justify-self: stretch;
    }

    .items-tools {
        gap: .8rem;
    }

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

    .filters button {
        width: 100%;
    }

    .view-toggle {
        justify-content: flex-start;
    }

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

    .item-card {
        grid-template-columns: 104px minmax(0, 1fr);
        align-items: stretch;
    }

    .item-card .item-image {
        aspect-ratio: auto;
        min-height: 104px;
        height: 100%;
    }

    .item-card .item-image span {
        width: 54px;
        height: 54px;
        font-size: 1.35rem;
    }

    .item-body {
        gap: .42rem;
        padding: .8rem;
    }

    .item-title h2 {
        font-size: 1rem;
    }

    .item-meta {
        gap: .25rem .55rem;
        font-size: .84rem;
    }

    .item-actions {
        grid-column: 1 / -1;
        padding: 0 .8rem .8rem;
    }

    .item-actions > .button,
    .item-actions > .consume-form {
        flex: 1 1 0;
    }

    .item-list-row {
        grid-template-columns: 76px minmax(0, 1fr);
        gap: .75rem;
        padding: .75rem;
    }

    .list-image {
        width: 76px;
        height: 76px;
        aspect-ratio: auto;
    }

    .list-image span {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }

    .list-main {
        gap: .35rem;
    }

    .list-status,
    .list-actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }
}

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

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

    .item-card .item-image {
        aspect-ratio: 2 / 1;
        min-height: 0;
        max-height: 150px;
    }

    .item-body {
        gap: .45rem;
        padding: .75rem;
    }

    .item-meta {
        font-size: .8rem;
    }

    .item-actions,
    .list-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .item-actions > .button,
    .item-actions > .consume-form,
    .list-actions > .button,
    .list-actions > .consume-form {
        width: 100%;
    }

    .item-actions {
        padding: 0 .75rem .75rem;
    }

    .item-list-row {
        grid-template-columns: 64px minmax(0, 1fr);
    }

    .list-image {
        width: 64px;
        height: 64px;
    }

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

    .install-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}
