:root {
    --bg: #f6f7f4;
    --panel: #ffffff;
    --ink: #20231f;
    --muted: #687064;
    --line: #dfe4da;
    --green: #2f7d4f;
    --orange: #b86125;
    --blue: #276b8f;
    --red: #b63e35;
    --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,
.entry-head,
.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.topbar {
    margin-bottom: 16px;
}

.quick-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

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

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

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

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

.nav-link {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--green);
    background: var(--panel);
    text-decoration: none;
    font-weight: 800;
}

.notice-card,
.entry-card,
.order-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.notice-card {
    display: grid;
    gap: 6px;
    margin-bottom: 14px;
    padding: 14px;
    border-left: 5px solid var(--blue);
}

.notice-card span {
    color: var(--muted);
    line-height: 1.5;
}

.entry-grid {
    display: grid;
    gap: 14px;
}

.entry-card {
    padding: 16px;
}

.entry-head {
    align-items: flex-start;
    margin-bottom: 14px;
}

.tag {
    padding: 6px 9px;
    border-radius: 8px;
    background: #eef2ea;
    color: var(--green);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

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

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

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

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

textarea {
    resize: vertical;
}

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

.form-grid > .wide {
    grid-column: 1 / -1;
}

.item-editor {
    display: grid;
    gap: 10px;
    padding: 12px;
    border-radius: 8px;
    background: #f7f8f4;
}

.recipient-panel {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid #e3d9bd;
    border-radius: 8px;
    background: #fffaf0;
}

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

.item-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.item-pill button {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: #f3e4df;
    color: var(--red);
    font-weight: 900;
    cursor: pointer;
}

.order-item-edit {
    display: grid;
    grid-template-columns: 1.1fr 1.4fr .7fr .6fr .8fr .7fr 38px;
    gap: 8px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.order-item-edit input {
    min-height: 38px;
    padding: 8px;
}

.order-item-edit strong {
    text-align: right;
    font-size: 14px;
}

.order-item-edit button,
.btn-secondary.danger {
    color: var(--red);
    border-color: #e5c8c4;
    background: #fff8f7;
}

.order-total-line {
    padding: 8px 10px;
    border-radius: 8px;
    background: #f7f8f4;
    text-align: right;
    font-weight: 900;
}

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

.edit-add-row {
    grid-template-columns: 1fr 1.3fr .7fr .7fr .8fr;
}

.btn {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    padding: 10px 12px;
    color: #ffffff;
    background: var(--green);
    font-weight: 900;
    cursor: pointer;
}

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

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

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.orders-section {
    margin-top: 24px;
}

.section-title {
    margin-bottom: 10px;
}

.order-grid {
    display: grid;
    gap: 12px;
}

.order-card {
    display: grid;
    gap: 12px;
    padding: 16px;
    border-top: 4px solid var(--green);
}

.order-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.share-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.share-chip {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8faf6;
}

.share-chip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: start;
    justify-content: space-between;
    padding: 8px;
    width: 100%;
}

.share-main {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.share-main span,
.share-token {
    color: var(--muted);
    font-size: 12px;
}

.share-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px;
}

.share-actions a,
.share-actions button {
    min-height: 30px;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 5px 8px;
    color: var(--ink);
    background: #fff;
    font: inherit;
    font-size: 12px;
    font-weight: 900;
    cursor: pointer;
    flex: 0 1 auto;
    text-decoration: none;
}

.share-actions .danger {
    color: #a33129;
    border-color: #efcac5;
    background: #fff7f6;
}

.card-head-actions {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.order-more-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--ink);
    background: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
}

.order-more-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 10;
    display: grid;
    gap: 4px;
    width: 190px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 12px 32px rgba(20, 26, 19, 0.18);
}

.order-more-menu[hidden] {
    display: none;
}

.order-more-menu button {
    min-height: 38px;
    border: 0;
    border-radius: 7px;
    padding: 8px 10px;
    color: var(--ink);
    background: transparent;
    font: inherit;
    font-size: 14px;
    font-weight: 900;
    text-align: left;
    cursor: pointer;
}

.order-more-menu button:hover {
    background: #f6f8f3;
}

.order-card.source-line {
    border-top-color: var(--blue);
}

.order-card.needs-review {
    border-color: #e5b84c;
    border-top-color: #d3941f;
}

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

.session-no {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.status-pill {
    padding: 6px 9px;
    border-radius: 8px;
    color: var(--orange);
    background: #fff3e8;
    font-size: 12px;
    font-weight: 900;
}

.match-alert {
    padding: 10px 11px;
    border: 1px solid #f0cf76;
    border-radius: 8px;
    color: #7a4b00;
    background: #fff8df;
    font-size: 14px;
    font-weight: 900;
    line-height: 1.45;
}

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

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

.meta-grid dt {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
}

.meta-grid dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 14px;
    font-weight: 800;
}

.order-items {
    display: grid;
    gap: 8px;
}

.order-item {
    padding: 10px;
    border-radius: 8px;
    background: #eef2ea;
    color: var(--ink);
    font-size: 14px;
    font-weight: 800;
}

.order-note {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.empty-state {
    padding: 18px;
    border: 1px dashed #c9d1c2;
    border-radius: 8px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.72);
    text-align: center;
}

.toast {
    position: fixed;
    right: 14px;
    bottom: 18px;
    left: 14px;
    z-index: 20;
    transform: translateY(16px);
    opacity: 0;
    pointer-events: none;
    padding: 13px 16px;
    border-radius: 8px;
    color: #ffffff;
    background: #263126;
    text-align: center;
    transition: opacity 160ms ease, transform 160ms ease;
}

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

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    align-items: end;
    padding: 18px 12px;
    background: rgba(25, 30, 24, 0.46);
}

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

.order-editor {
    width: min(760px, 100%);
    max-height: min(780px, calc(100vh - 36px));
    margin: 0 auto;
    overflow: auto;
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 22px 60px rgba(20, 26, 19, 0.28);
}

.editor-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f7f8f4;
    color: var(--ink);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.editor-form {
    padding: 18px;
}

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

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

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

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

    .item-row {
        grid-template-columns: 1.4fr 0.8fr 0.8fr;
    }

    .edit-add-row {
        grid-template-columns: 1fr 1.3fr .7fr .7fr .8fr;
    }

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

    .modal-backdrop {
        align-items: center;
    }
}

@media (min-width: 1080px) {
    .order-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Full-screen editor, Trello-style: close left, title center area, spacer right. */
.modal-backdrop {
    display: block;
    padding: 0;
}

.order-editor {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
}

.editor-head {
    z-index: 2;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    min-height: 68px;
    padding: 10px 12px;
}

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

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

.editor-head .icon-btn {
    width: 42px;
    height: 42px;
}

.editor-menu-wrap {
    position: relative;
    justify-self: end;
}

.icon-btn.dots {
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 1px;
}

.editor-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 5;
    width: 170px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 12px 32px rgba(20, 26, 19, 0.18);
}

.editor-menu[hidden] {
    display: none;
}

.editor-menu button {
    width: 100%;
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--ink);
    background: transparent;
    font: inherit;
    font-size: 14px;
    font-weight: 900;
    text-align: left;
    cursor: pointer;
}

.editor-menu button:hover {
    background: #f9e8e5;
}

.editor-menu button[data-action="order-delete-current"] {
    color: #a33129;
}

.editor-form {
    width: min(920px, 100%);
    margin: 0 auto;
    padding: 18px 14px 28px;
}

.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;
}

.order-box-panel {
    display: grid;
    gap: 10px;
    width: 100%;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fbf6;
}

.shipping-grid {
    align-items: start;
}

.shipping-grid > label,
.shipping-grid > section {
    min-width: 0;
}

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

.order-box-list {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.order-box-row {
    display: grid;
    grid-template-columns: minmax(56px, auto) minmax(150px, 1fr);
    gap: 8px;
    align-items: end;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    min-width: 0;
}

.order-box-row > strong {
    align-self: center;
}

.order-box-row label {
    min-width: 0;
}

.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;
}

.order-freight-expense-panel {
    display: grid;
    gap: 10px;
    width: 100%;
    min-width: 0;
    padding: 12px;
    border: 1px solid #d7dfd2;
    border-radius: 8px;
    background: #f7faf5;
}

.order-freight-expense-panel[hidden] {
    display: none;
}

.order-freight-expense-panel p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

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

.freight-expense-grid > div {
    display: grid;
    gap: 6px;
    min-width: 0;
    padding: 10px;
    border-radius: 8px;
    background: #fff;
}

.freight-expense-grid span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.freight-expense-grid strong {
    overflow-wrap: anywhere;
}

@media (min-width: 1180px) {
    .order-box-row {
        grid-template-columns: minmax(56px, auto) minmax(160px, 1fr) minmax(230px, 1.25fr) minmax(210px, 1fr);
    }
}

@media (min-width: 720px) and (max-width: 1179px) {
    .order-box-row {
        grid-template-columns: minmax(56px, auto) minmax(180px, 1fr);
    }

    .order-box-row .box-choice {
        grid-column: span 1;
    }
}

@media (max-width: 719px) {
    .money-grid,
    .edit-add-row,
    .order-item-edit,
    .order-box-row {
        grid-template-columns: 1fr;
    }

    .order-item-edit strong {
        text-align: left;
    }

    .freight-expense-grid {
        grid-template-columns: 1fr;
    }
}
