:root {
    --bg: #f5f7f4;
    --panel: #ffffff;
    --ink: #20231f;
    --muted: #687064;
    --line: #dfe4da;
    --green: #2f7d4f;
    --blue: #276b8f;
    --red: #b63e35;
    --amber: #b98322;
    --shadow: 0 10px 28px rgba(31, 38, 29, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", Arial, sans-serif;
}

body.is-modal-open {
    overflow: hidden;
}

.app-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: 18px 14px 88px;
}

.topbar,
.quick-links,
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topbar {
    align-items: flex-start;
    margin-bottom: 16px;
}

.quick-links {
    position: relative;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.quick-links a,
.btn {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-weight: 900;
    text-decoration: none;
}

.quick-links a {
    padding: 8px 11px;
    border: 1px solid var(--line);
    color: var(--green);
    background: var(--panel);
}

.page-close {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    font-size: 30px;
    font-weight: 850;
    line-height: 1;
    text-decoration: none;
}

.page-close:hover {
    border-color: var(--green);
    color: var(--green);
}

.more-menu {
    position: relative;
}

.more-menu summary {
    width: 48px;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    color: var(--green);
    font-size: 22px;
    font-weight: 950;
    line-height: 1;
    cursor: pointer;
    list-style: none;
}

.more-menu summary::-webkit-details-marker {
    display: none;
}

.more-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 20;
    width: 180px;
    display: grid;
    gap: 4px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.more-menu-panel a {
    width: 100%;
    justify-content: flex-start;
    border: 0;
    background: transparent;
    color: var(--ink);
}

.more-menu-panel a:hover {
    background: #f1f6ee;
    color: var(--green);
}

.eyebrow,
p {
    margin-top: 0;
}

.eyebrow {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 13px;
}

h1,
h2,
h3 {
    margin: 0;
}

h1 {
    font-size: 30px;
    line-height: 1.1;
}

h2 {
    font-size: 21px;
}

h3 {
    font-size: 18px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.summary-card,
.action-card,
.inventory-card,
.events-section {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.summary-card {
    min-height: 88px;
    padding: 14px;
    border-left: 5px solid var(--green);
}

.summary-card.warning {
    border-left-color: var(--amber);
}

.summary-card.alert {
    border-left-color: var(--red);
}

.summary-card span {
    display: block;
    margin-bottom: 6px;
    font-size: 28px;
    font-weight: 900;
}

.summary-card p {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 14px;
}

.action-grid,
.inventory-section {
    display: grid;
    gap: 12px;
    margin-bottom: 14px;
}

.action-card,
.events-section {
    display: grid;
    gap: 12px;
    padding: 14px;
}

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

.form-grid,
.filter-row,
.toolbar {
    display: grid;
    gap: 10px;
}

label,
.search-box {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

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

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 11px;
    border: 1px solid #cbd4c4;
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
}

textarea {
    resize: vertical;
}

.btn {
    border: 0;
    padding: 10px 12px;
    color: #ffffff;
    background: var(--green);
    cursor: pointer;
}

.btn-secondary {
    border: 1px solid var(--line);
    color: var(--ink);
    background: #f7f8f4;
}

.btn.danger {
    border: 1px solid #e5bdb7;
    background: #fff3f1;
    color: var(--red);
}

.btn.compact {
    min-height: 38px;
}

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

.inventory-grid,
.event-list {
    display: grid;
    gap: 10px;
}

.inventory-card {
    display: grid;
    gap: 12px;
    padding: 12px 14px;
    border-left: 5px solid var(--green);
    cursor: pointer;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.inventory-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 34px rgba(31, 38, 29, 0.12);
}

.inventory-card.status-low {
    border-left-color: var(--amber);
}

.inventory-card.status-zero {
    border-left-color: var(--red);
}

.card-head,
.metric-row,
.event-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.card-head {
    align-items: flex-start;
}

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

.meta-grid div {
    min-width: 0;
    padding: 8px 9px;
    border-radius: 8px;
    background: #f7f8f4;
}

.meta-grid dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.meta-grid dd {
    margin: 4px 0 0;
    overflow-wrap: anywhere;
    font-weight: 900;
}

.qty {
    font-size: 28px;
    font-weight: 900;
    line-height: 1;
}

.qty small {
    color: var(--muted);
    font-size: 14px;
}

.safety-control {
    display: grid;
    gap: 5px;
}

.safety-control label {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.2;
}

.safety-control input {
    min-height: 40px;
    padding: 8px 10px;
}

.adjust-card-btn {
    width: 100%;
}

.inventory-actions {
    display: grid;
    gap: 10px;
}

.qty-stack {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.inline-save-status {
    min-height: 17px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    opacity: 0;
    transition: opacity 0.16s ease;
}

.inline-save-field.is-editing .inline-save-status,
.inline-save-status.is-saving,
.inline-save-status.is-saved,
.inline-save-status.is-error {
    opacity: 1;
}

.inline-save-status.is-saving {
    color: var(--blue);
}

.inline-save-status.is-saved {
    color: var(--green);
}

.inline-save-status.is-error {
    color: var(--red);
}

.status-pill,
.metric-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 9px;
    border-radius: 8px;
    background: #e8f3ed;
    color: var(--green);
    font-size: 12px;
    font-weight: 900;
}

.status-pill.status-low {
    background: #fff2da;
    color: var(--amber);
}

.status-pill.status-zero {
    background: #f7e3df;
    color: var(--red);
}

.event-card {
    display: grid;
    gap: 6px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfa;
}

.event-card strong {
    overflow-wrap: anywhere;
}

.event-row span,
.event-meta {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.empty-state {
    padding: 14px;
    border: 1px dashed #c8d1c0;
    border-radius: 8px;
    color: var(--muted);
    background: #fbfcfa;
    text-align: center;
}

.cancel-receive-shell {
    width: min(960px, 100%);
}

.cancel-panel,
.cancel-card {
    display: grid;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

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

.camera-icon-btn {
    position: relative;
    width: 48px;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    cursor: pointer;
}

.camera-icon-btn::before {
    position: absolute;
    left: 11px;
    top: 15px;
    width: 26px;
    height: 17px;
    border: 3px solid currentColor;
    border-radius: 5px;
    color: var(--ink);
    content: "";
}

.camera-icon-btn::after {
    position: absolute;
    left: 21px;
    top: 19px;
    width: 8px;
    height: 8px;
    border: 3px solid currentColor;
    border-radius: 50%;
    color: var(--ink);
    content: "";
}

.camera-icon-btn span::before {
    position: absolute;
    left: 15px;
    top: 10px;
    width: 11px;
    height: 6px;
    border-radius: 3px 3px 0 0;
    background: currentColor;
    color: var(--ink);
    content: "";
}

.cancel-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.cancel-card-head p {
    margin-bottom: 0;
    color: var(--muted);
    font-weight: 800;
}

.cancel-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 0;
}

.cancel-facts div {
    padding: 10px;
    border-radius: 8px;
    background: #f7f8f4;
}

.cancel-facts dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.cancel-facts dd {
    margin: 4px 0 0;
    overflow-wrap: anywhere;
    font-size: 18px;
    font-weight: 950;
}

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

.camera-modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 14px;
    background: rgba(12, 19, 14, 0.82);
}

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

.camera-panel {
    width: min(760px, 100%);
    display: grid;
    gap: 12px;
    padding: 14px;
    border-radius: 8px;
    background: var(--panel);
}

.camera-head {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
}

.camera-close {
    width: 42px;
    min-height: 42px;
    border: 0;
    border-radius: 50%;
    background: #eef1ea;
    color: var(--ink);
    cursor: pointer;
    font-size: 25px;
    font-weight: 800;
}

.camera-view {
    position: relative;
    min-height: min(58vh, 480px);
    overflow: hidden;
    border-radius: 8px;
    background: #101712;
}

.camera-reader,
.camera-reader video,
.camera-reader canvas {
    width: 100%;
    min-height: min(58vh, 480px);
}

.camera-reader video {
    display: block;
    object-fit: cover;
}

.scan-frame {
    position: absolute;
    inset: 28%;
    border: 3px solid rgba(255, 255, 255, 0.92);
    border-radius: 8px;
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.28);
    pointer-events: none;
}

.camera-hint {
    margin-bottom: 0;
    color: var(--muted);
    font-weight: 800;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 18px;
    z-index: 30;
    transform: translate(-50%, 16px);
    max-width: min(460px, calc(100% - 28px));
    padding: 12px 14px;
    border-radius: 8px;
    background: #1f2a22;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    background: var(--bg);
}

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

.stock-editor {
    display: grid;
    grid-template-rows: auto 1fr;
    width: 100%;
    min-height: 100vh;
    background: var(--panel);
}

.editor-head {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 10px;
    padding: max(14px, env(safe-area-inset-top)) 14px 12px;
    border-bottom: 1px solid var(--line);
}

.icon-btn {
    width: 42px;
    min-height: 42px;
    border: 0;
    border-radius: 50%;
    background: #eef1ea;
    color: var(--ink);
    cursor: pointer;
    font-size: 25px;
    font-weight: 800;
    line-height: 1;
}

.editor-title {
    min-width: 0;
}

.editor-title small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-weight: 800;
    overflow-wrap: anywhere;
}

.editor-head-spacer {
    width: 42px;
}

.stock-adjust-form {
    align-content: start;
    padding: 14px;
    overflow: auto;
}

.current-stock-panel {
    display: grid;
    gap: 6px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f7f8f4;
}

.current-stock-panel span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.current-stock-panel strong {
    font-size: 32px;
    line-height: 1;
}

.modal-safety-control {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f7f8f4;
}

.editor-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 6px;
}

.package-detail-body {
    display: grid;
    align-content: start;
    gap: 12px;
    padding: 14px;
    overflow: auto;
}

.package-summary {
    display: grid;
    gap: 8px;
}

.package-summary div,
.package-row {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f7f8f4;
}

.package-summary div {
    display: grid;
    gap: 6px;
    padding: 12px;
}

.package-summary span,
.package-row span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.package-summary strong {
    font-size: 22px;
    line-height: 1.1;
}

.package-list {
    display: grid;
    gap: 8px;
}

.package-row {
    display: grid;
    gap: 10px;
    padding: 12px;
    border-left: 5px solid var(--green);
}

.package-row.status-reserved {
    border-left-color: var(--amber);
}

.package-row.status-shipped {
    border-left-color: var(--blue);
}

.package-barcode,
.package-weight {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.barcode-line {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.barcode-line strong,
.package-weight strong {
    overflow-wrap: anywhere;
    font-size: 17px;
}

.icon-copy-btn {
    position: relative;
    flex: 0 0 auto;
    width: 38px;
    min-height: 38px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    cursor: pointer;
}

.icon-copy-btn::before,
.icon-copy-btn span {
    position: absolute;
    width: 16px;
    height: 20px;
    border: 2px solid currentColor;
    border-radius: 3px;
    background: #ffffff;
    content: "";
}

.icon-copy-btn::before {
    left: 9px;
    top: 8px;
}

.icon-copy-btn span {
    left: 14px;
    top: 12px;
}

.icon-copy-btn span::before,
.icon-copy-btn span::after {
    position: absolute;
    left: 3px;
    right: 3px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    content: "";
}

.icon-copy-btn span::before {
    top: 6px;
}

.icon-copy-btn span::after {
    top: 12px;
}

.icon-copy-btn:hover {
    border-color: var(--green);
    color: var(--green);
}

.package-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.package-meta span {
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 8px;
    background: #eef1ea;
}

@media (min-width: 760px) {
    .app-shell {
        padding: 26px 24px 96px;
    }

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

    .action-grid {
        grid-template-columns: minmax(0, 1fr);
        align-items: start;
    }

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

    .toolbar {
        grid-template-columns: minmax(260px, 1fr) minmax(420px, auto);
        align-items: end;
    }
}

@media (max-width: 620px) {
    .scan-row,
    .cancel-facts {
        grid-template-columns: 1fr;
    }

    .camera-icon-btn {
        width: 100%;
    }
}

@media (min-width: 1080px) {
    .inventory-card {
        grid-template-columns: minmax(210px, 0.85fr) minmax(460px, 1.7fr) minmax(220px, 0.65fr);
        align-items: center;
        min-height: 110px;
        gap: 12px;
    }

    .inventory-card .meta-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: stretch;
    }

    .inventory-main h3 {
        font-size: 17px;
        line-height: 1.25;
    }

    .inventory-actions {
        display: grid;
        grid-template-columns: minmax(92px, auto) minmax(112px, 0.8fr);
        align-items: center;
        gap: 10px;
    }

    .qty-stack {
        display: grid;
        justify-items: end;
        align-content: center;
    }

    .adjust-card-btn {
        min-height: 40px;
        padding: 8px 10px;
        white-space: nowrap;
    }

    .stock-adjust-form {
        width: min(760px, 100%);
        margin: 0 auto;
        padding: 24px;
    }

    .package-detail-body {
        width: min(980px, 100%);
        margin: 0 auto;
        padding: 24px;
    }

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

    .package-row {
        grid-template-columns: minmax(260px, 1.2fr) minmax(120px, 0.45fr) minmax(320px, 1fr);
        align-items: center;
    }
}
