:root {
    --bg: #f5f7f2;
    --panel: #ffffff;
    --ink: #20231f;
    --muted: #667064;
    --line: #dce4d6;
    --green: #2f7d4f;
    --green-dark: #245f3e;
    --blue: #2e6f91;
    --gold: #bd8b2c;
    --red: #b64037;
    --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;
}

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

.ship-shell {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 18px 14px 90px;
}

.ship-topbar,
.quick-links,
.tool-strip,
.filter-tabs,
.detail-head,
.scan-row,
.detail-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ship-topbar {
    justify-content: space-between;
    margin-bottom: 14px;
}

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

.quick-links a,
.btn,
.filter-tabs button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--green);
    text-decoration: none;
    font-weight: 900;
    cursor: pointer;
}

.quick-links a {
    padding: 8px 12px;
}

.btn {
    padding: 10px 14px;
}

.btn.primary,
.filter-tabs button.is-active {
    border-color: var(--green);
    background: var(--green);
    color: #fff;
}

.camera-icon-btn {
    width: 52px;
    min-width: 52px;
    min-height: 46px;
    display: inline-grid;
    place-items: center;
    border: 1px solid #d3b35c;
    border-radius: 8px;
    background: #fff8df;
    color: #6c4c0c;
    cursor: pointer;
}

.camera-icon-btn span {
    position: relative;
    width: 25px;
    height: 18px;
    display: block;
    border: 3px solid currentColor;
    border-radius: 5px;
}

.camera-icon-btn span::before {
    content: "";
    position: absolute;
    left: 4px;
    top: -8px;
    width: 10px;
    height: 5px;
    border: 3px solid currentColor;
    border-bottom: 0;
    border-radius: 4px 4px 0 0;
    background: #fff8df;
}

.camera-icon-btn span::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 7px;
    height: 7px;
    transform: translate(-50%, -50%);
    border: 2px solid currentColor;
    border-radius: 50%;
}

.camera-icon-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.btn.ghost {
    background: #f8faf5;
    color: var(--ink);
}

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

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

h1 {
    margin-bottom: 0;
    font-size: clamp(32px, 7vw, 56px);
    line-height: 1;
}

h2,
h3 {
    margin-bottom: 0;
}

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

.ship-summary article,
.tool-strip,
.order-queue,
.ship-detail,
.queue-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.ship-summary article {
    padding: 14px;
}

.ship-summary span {
    display: block;
    font-size: 30px;
    font-weight: 950;
}

.ship-summary p {
    margin-bottom: 0;
    color: var(--muted);
    font-weight: 800;
}

.tool-strip {
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 12px;
    padding: 12px;
}

.filter-tabs {
    flex-wrap: wrap;
}

.filter-tabs button {
    padding: 9px 13px;
}

.search-box {
    min-width: min(360px, 100%);
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

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

textarea {
    resize: vertical;
}

.ship-workspace {
    display: grid;
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}

.order-queue,
.ship-detail {
    min-height: 560px;
    padding: 12px;
}

.pane-head {
    margin-bottom: 10px;
}

.order-list,
.ship-items {
    display: grid;
    gap: 9px;
}

.queue-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 12px;
    border-left: 6px solid var(--line);
    cursor: pointer;
}

.queue-card.is-active {
    outline: 3px solid rgba(47, 125, 79, 0.24);
}

.queue-card.status-confirmed {
    border-left-color: var(--gold);
}

.queue-card.status-picking {
    border-left-color: var(--green);
}

.queue-card.status-delivering,
.queue-card.status-delivered {
    border-left-color: var(--blue);
}

.queue-main h3 {
    margin: 8px 0 4px;
    font-size: 22px;
}

.queue-main p,
.queue-side span,
.detail-head p,
.ship-item span,
.empty-panel span,
.note-text {
    color: var(--muted);
}

.queue-side {
    display: grid;
    align-content: center;
    justify-items: end;
    gap: 6px;
    text-align: right;
}

.queue-side strong,
.date-chip {
    border-radius: 8px;
    font-weight: 950;
}

.queue-side strong {
    padding: 6px 8px;
    background: #eef4ea;
    color: var(--green-dark);
}

.date-chip {
    display: inline-flex;
    padding: 7px 9px;
    background: #fff3cf;
    color: #5d4511;
}

.empty-state,
.empty-panel {
    display: grid;
    gap: 8px;
    padding: 18px;
    border: 1px dashed #cdd7c7;
    border-radius: 8px;
    background: #f9fbf6;
    color: var(--muted);
    font-weight: 800;
}

.empty-state.small {
    padding: 12px;
}

.empty-panel {
    min-height: 420px;
    place-content: center;
    text-align: center;
}

.empty-panel strong {
    color: var(--ink);
    font-size: 26px;
}

.detail-head {
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.detail-head h2 {
    margin: 8px 0 4px;
    font-size: clamp(28px, 5vw, 44px);
}

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

.order-facts div {
    padding: 12px;
    border-radius: 8px;
    background: #f5f7f1;
}

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

.order-facts dd {
    margin: 5px 0 0;
    font-size: 18px;
    font-weight: 950;
}

.scan-panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 8px;
    background: #eef3eb;
}

.scan-panel label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.scan-panel .wide {
    grid-column: 1 / -1;
}

.scan-row {
    align-items: stretch;
}

.scan-row .btn {
    min-width: 96px;
}

.stepper-control {
    display: grid;
    grid-template-columns: 52px minmax(74px, 1fr) 52px;
    gap: 8px;
    align-items: stretch;
}

.stepper-btn {
    min-height: 46px;
    border: 1px solid var(--green);
    border-radius: 8px;
    background: #eef7ef;
    color: var(--green);
    font-size: 26px;
    font-weight: 950;
    cursor: pointer;
}

.stepper-control input {
    text-align: center;
    font-size: 18px;
    font-weight: 950;
}

.freight-expense-panel {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf7;
}

.shipping-box-panel {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fbf6;
}

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

.box-panel-head p {
    margin: 5px 0 0;
    color: var(--muted);
    font-weight: 800;
    line-height: 1.45;
}

.box-control-grid {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(260px, .9fr);
    gap: 10px;
    align-items: end;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #eef3eb;
}

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

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

.shipping-box-row {
    display: grid;
    grid-template-columns: 86px minmax(160px, 1fr) minmax(190px, 1.1fr) minmax(170px, .9fr) 86px;
    gap: 8px;
    align-items: end;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.shipping-box-row > strong {
    align-self: center;
    font-size: 16px;
}

.box-choice {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.box-choice legend {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.choice-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}

.choice-pill {
    display: block;
}

.choice-pill input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.choice-pill span {
    min-height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-weight: 950;
    cursor: pointer;
}

.choice-pill input:checked + span {
    border-color: var(--green);
    background: var(--green);
    color: #fff;
}

.choice-pill input:focus-visible + span {
    outline: 3px solid rgba(47, 125, 79, .24);
    outline-offset: 2px;
}

.box-fee {
    min-height: 46px;
    display: grid;
    align-content: center;
    justify-items: end;
    padding: 8px;
    border-radius: 8px;
    background: #f5f7f1;
}

.box-fee span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.box-fee b {
    font-size: 18px;
}

.block-head,
.freight-actions {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.block-head p {
    margin: 5px 0 0;
    color: var(--muted);
    font-weight: 800;
    line-height: 1.45;
}

.expense-status {
    flex: 0 0 auto;
    max-width: 280px;
    padding: 8px 10px;
    border-radius: 8px;
    background: #fff2da;
    color: #9b5d12;
    font-size: 13px;
    font-weight: 900;
    line-height: 1.35;
}

.expense-status.is-done {
    background: #eaf6ed;
    color: var(--green);
}

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

.freight-compare > div,
.freight-compare > label {
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.freight-compare span,
.freight-compare small {
    display: block;
    color: var(--muted);
    font-weight: 800;
    line-height: 1.35;
}

.freight-compare strong {
    display: block;
    margin: 4px 0;
    font-size: 24px;
}

.freight-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
}

.detail-block {
    margin-bottom: 12px;
}

.detail-block h3 {
    margin-bottom: 8px;
}

.ship-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto 42px;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.ship-item strong,
.ship-item span {
    display: block;
}

.ship-item strong {
    font-size: 18px;
}

.item-money {
    font-weight: 950;
}

.qty-stepper {
    display: inline-grid;
    grid-template-columns: 36px minmax(34px, auto) 36px;
    align-items: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8faf5;
}

.qty-stepper button {
    width: 36px;
    height: 36px;
    border: 0;
    background: transparent;
    color: var(--green);
    font-size: 22px;
    font-weight: 950;
    cursor: pointer;
}

.qty-stepper b {
    min-width: 34px;
    text-align: center;
    font-weight: 950;
}

.icon-remove {
    width: 38px;
    height: 38px;
    border: 1px solid #ecd1cb;
    border-radius: 8px;
    background: #fff4f2;
    color: var(--red);
    font-size: 24px;
    font-weight: 950;
    cursor: pointer;
}

.detail-actions {
    position: sticky;
    bottom: 0;
    justify-content: flex-end;
    margin: 0 -12px -12px;
    padding: 12px;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(8px);
}

.detail-actions .btn {
    min-height: 54px;
    font-size: 18px;
}

.locked-hint {
    color: var(--muted);
    font-weight: 900;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    z-index: 20;
    transform: translateX(-50%) translateY(20px);
    max-width: min(520px, calc(100% - 28px));
    padding: 12px 16px;
    border-radius: 8px;
    background: #20231f;
    color: #fff;
    font-weight: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}

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

.camera-modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: stretch;
    background: rgba(12, 18, 13, 0.88);
}

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

.camera-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: 100dvh;
    background: #101710;
    color: #fff;
}

.camera-head {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
}

.camera-close {
    width: 54px;
    height: 54px;
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: 8px;
    background: rgba(255, 255, 255, .08);
    color: #fff;
    font-size: 38px;
    line-height: 1;
    cursor: pointer;
}

.camera-view {
    position: relative;
    overflow: hidden;
    background: #000;
}

.camera-reader,
.camera-reader video,
.camera-reader canvas {
    width: 100%;
    height: 100%;
}

.camera-reader video,
.camera-reader canvas {
    object-fit: cover;
}

.camera-reader {
    min-height: 100%;
}

.camera-reader canvas.drawingBuffer {
    position: absolute;
    inset: 0;
}

.scan-frame {
    position: absolute;
    left: 50%;
    top: 50%;
    width: min(78vw, 520px);
    height: min(32vh, 220px);
    transform: translate(-50%, -50%);
    border: 4px solid #f5c542;
    border-radius: 8px;
    box-shadow: 0 0 0 999px rgba(0, 0, 0, .28);
}

.camera-hint {
    margin: 0;
    padding: 14px;
    color: #eef2ea;
    font-weight: 900;
    text-align: center;
}

@media (max-width: 980px) {
    .ship-topbar,
    .tool-strip {
        align-items: stretch;
        flex-direction: column;
    }

    .quick-links {
        justify-content: flex-start;
    }

    .ship-workspace {
        grid-template-columns: 1fr;
    }

    .order-queue,
    .ship-detail {
        min-height: auto;
    }

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

    .scan-panel,
    .box-control-grid,
    .order-facts,
    .freight-compare {
        grid-template-columns: 1fr;
    }

    .shipping-box-row {
        grid-template-columns: 1fr 1fr;
    }

    .shipping-box-row > strong,
    .shipping-box-row > label:first-of-type {
        grid-column: 1 / -1;
    }

    .block-head {
        display: grid;
    }

    .expense-status {
        max-width: none;
    }
}

@media (max-width: 640px) {
    .ship-shell {
        padding: 14px 10px 84px;
    }

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

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

    .queue-side {
        justify-items: start;
        text-align: left;
    }

    .detail-head,
    .scan-row,
    .detail-actions,
    .box-panel-head {
        align-items: stretch;
        flex-direction: column;
    }

    .shipping-box-row {
        grid-template-columns: 1fr;
    }

    .box-fee {
        justify-items: start;
    }

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

    .qty-stepper {
        grid-column: 1 / -1;
        width: max-content;
    }
}
