:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --ink: #152033;
    --muted: #697386;
    --line: #dfe5ef;
    --teal: #0f8b8d;
    --teal-dark: #0a6466;
    --blue: #2563eb;
    --red: #d93838;
    --red-soft: #fff1f1;
    --amber: #c77700;
    --amber-soft: #fff8e6;
    --green: #16815f;
    --green-soft: #ecfdf5;
    --gray-soft: #f1f3f7;
    --shadow: 0 18px 45px rgba(24, 35, 52, 0.10);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(180deg, #eef7f7 0, rgba(246, 247, 251, 0) 340px),
        var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

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

.app-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 26px 0 48px;
}

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

.eyebrow {
    margin: 0 0 4px;
    color: var(--teal-dark);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

h1 {
    margin-bottom: 0;
    font-size: clamp(2rem, 5vw, 3.4rem);
    line-height: 1;
}

h2 {
    margin-bottom: 4px;
    font-size: 1.25rem;
}

h3 {
    margin-bottom: 6px;
    font-size: 1.04rem;
}

.primary-action,
.secondary-action,
.submit-button,
.filter-bar button {
    border: 0;
    border-radius: 8px;
    background: var(--teal);
    color: #fff;
    cursor: pointer;
    font-weight: 800;
}

.primary-action {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    white-space: nowrap;
    box-shadow: 0 10px 24px rgba(15, 139, 141, 0.22);
}

.secondary-action {
    min-height: 44px;
    padding: 0 16px;
    align-self: end;
    background: var(--blue);
}

.flash,
.setup-panel,
.list-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.flash {
    margin-bottom: 16px;
    padding: 12px 14px;
    color: var(--green);
    font-weight: 750;
}

.flash.error {
    color: var(--red);
}

.setup-panel {
    padding: 22px;
}

.setup-panel pre {
    overflow: auto;
    margin: 16px 0 0;
    padding: 14px;
    border-radius: 8px;
    background: #101828;
    color: #e6edf7;
    white-space: pre-wrap;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat {
    min-height: 96px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.stat span {
    display: block;
    font-size: 2rem;
    font-weight: 900;
    line-height: 1;
}

.stat small {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-weight: 750;
}

.stat.danger span,
.badge.danger {
    color: var(--red);
}

.stat.hot span {
    color: #b42318;
}

.stat.warning span,
.badge.warning {
    color: var(--amber);
}

.stat.success span,
.badge.success {
    color: var(--green);
}

.list-panel {
    padding: 18px;
}

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

.panel-heading p {
    margin-bottom: 0;
    color: var(--muted);
}

.panel-heading a {
    color: var(--blue);
    font-weight: 800;
}

.filter-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 170px 86px;
    gap: 10px;
    margin-bottom: 14px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    outline: 0;
    padding: 10px 12px;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.14);
}

.item-list {
    display: grid;
    gap: 12px;
}

.item-card {
    display: grid;
    gap: 14px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 10px 26px rgba(24, 35, 52, 0.06);
}

.item-card.danger {
    border-color: rgba(217, 56, 56, 0.28);
    background: linear-gradient(180deg, var(--red-soft), #fff 110px);
}

.item-card.warning {
    border-color: rgba(199, 119, 0, 0.30);
    background: linear-gradient(180deg, var(--amber-soft), #fff 110px);
}

.item-card.success {
    border-color: rgba(22, 129, 95, 0.24);
}

.item-card.muted {
    opacity: 0.72;
    background: var(--gray-soft);
}

.item-card-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    align-items: start;
}

.item-title-group {
    min-width: 0;
}

.item-title-group h3 {
    margin-bottom: 5px;
    font-size: 1.18rem;
    line-height: 1.2;
}

.item-title-group p {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.35;
}

.badge {
    display: inline-flex;
    min-height: 24px;
    align-items: center;
    margin-bottom: 8px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    font-size: 0.76rem;
    font-weight: 900;
}

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

.days-pill {
    display: grid;
    min-width: 104px;
    justify-items: center;
    gap: 2px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    text-align: center;
}

.days-pill small {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 850;
    text-transform: uppercase;
}

.days-pill strong {
    color: var(--ink);
    font-size: 1.05rem;
    line-height: 1.1;
}

.days-pill.danger {
    border-color: rgba(217, 56, 56, 0.26);
    background: #fff7f7;
}

.days-pill.danger strong {
    color: var(--red);
}

.days-pill.warning {
    border-color: rgba(199, 119, 0, 0.28);
    background: #fffaf0;
}

.days-pill.warning strong {
    color: var(--amber);
}

.days-pill.success {
    border-color: rgba(22, 129, 95, 0.22);
    background: var(--green-soft);
}

.days-pill.success strong {
    color: var(--green);
}

.days-pill.muted {
    background: #fff;
}

.notes,
.item-details small,
.item-codes {
    color: var(--muted);
}

.notes {
    margin-bottom: 0;
}

.item-details {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.item-details div {
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
}

.item-details strong,
.item-details small {
    display: block;
}

.item-details small {
    margin-bottom: 4px;
    font-size: 0.74rem;
    font-weight: 850;
    text-transform: uppercase;
}

.item-details strong {
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ink);
    font-size: 0.95rem;
    line-height: 1.25;
    white-space: nowrap;
}

.item-codes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.84rem;
}

.item-codes span {
    min-height: 26px;
    padding: 4px 8px;
    border-radius: 8px;
    background: var(--gray-soft);
}

.notes {
    padding: 11px 12px;
    border-radius: 8px;
    background: var(--gray-soft);
    font-size: 0.9rem;
    line-height: 1.45;
}

.item-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 4px;
}

.item-actions a,
.item-actions button {
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    padding: 7px 11px;
    font-weight: 800;
}

.item-actions button:disabled,
.submit-button:disabled {
    cursor: wait;
    opacity: 0.62;
}

.item-actions .danger-button {
    color: var(--red);
}

.item-actions .use-button {
    border-color: rgba(15, 139, 141, 0.24);
    background: #eefafa;
    color: var(--teal-dark);
}

.empty-state {
    padding: 28px 16px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    text-align: center;
}

.empty-state p {
    margin-bottom: 0;
    color: var(--muted);
}

.item-form {
    display: grid;
    gap: 12px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 800;
}

.two-col {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
}

.submit-button {
    min-height: 48px;
    margin-top: 2px;
}

.scan-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 92px;
    gap: 10px;
}

.inline-hint {
    margin: -4px 0 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.modal-open {
    overflow: hidden;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.48);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-card {
    width: min(640px, 100%);
    max-height: min(92vh, 760px);
    overflow: auto;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.modal-card.compact {
    width: min(460px, 100%);
}

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

.modal-heading h2 {
    margin-bottom: 0;
}

.icon-button {
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: 900;
    line-height: 1;
}

.usage-summary {
    display: grid;
    gap: 4px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--gray-soft);
}

.usage-summary span {
    color: var(--muted);
}

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

.toast-stack {
    position: fixed;
    z-index: 40;
    top: 18px;
    right: 18px;
    display: grid;
    gap: 10px;
    width: min(360px, calc(100vw - 28px));
    pointer-events: none;
}

.toast {
    transform: translateY(-8px);
    opacity: 0;
    padding: 13px 14px;
    border: 1px solid rgba(22, 129, 95, 0.20);
    border-radius: 8px;
    background: #fff;
    color: var(--green);
    box-shadow: 0 16px 38px rgba(15, 23, 42, 0.16);
    font-size: 0.92rem;
    font-weight: 850;
    line-height: 1.35;
    transition: transform 180ms ease, opacity 180ms ease;
}

.toast.error {
    border-color: rgba(217, 56, 56, 0.22);
    color: var(--red);
}

.toast.is-visible {
    transform: translateY(0);
    opacity: 1;
}

@media (max-width: 680px) {
    .app-shell {
        width: min(100% - 22px, 1180px);
        padding-top: 18px;
    }

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

    .primary-action {
        width: 100%;
    }

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

    .filter-bar,
    .scan-row,
    .two-col {
        grid-template-columns: 1fr;
    }

    .item-card {
        padding: 14px;
    }

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

    .days-pill {
        justify-items: start;
        min-width: 0;
        text-align: left;
    }

    .list-panel,
    .modal-card {
        padding: 14px;
    }

    .modal-backdrop {
        align-items: end;
        padding: 10px;
    }

    .modal-card {
        max-height: 92vh;
    }

    .toast-stack {
        top: 10px;
        right: 10px;
        left: 10px;
        width: auto;
    }
}
