:root {
    color-scheme: light;
    font-family: system-ui, "PingFang TC", "Microsoft JhengHei", sans-serif;
    background: #f3f6fa;
    color: #192536;
    font-size: 100%;
    line-height: 1.55;
    --navy: #14243d;
    --accent: #254e85;
    --border: #d8e0ea;
    --muted: #526477;
}

*, *::before, *::after { box-sizing: border-box; }
body { min-height: 100vh; margin: 0; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: .35rem; font-size: clamp(1.65rem, 3vw, 2.15rem); line-height: 1.24; }
h2 { margin-bottom: 1rem; font-size: 1.15rem; }
p { margin-bottom: 1rem; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #3775be; outline-offset: 3px; }

.skip-link {
    position: fixed;
    z-index: 5;
    top: .75rem;
    left: .75rem;
    padding: .5rem .8rem;
    transform: translateY(-220%);
    border-radius: .4rem;
    background: var(--navy);
    color: #fff;
}
.skip-link:focus { transform: translateY(0); }

.workspace {
    display: grid;
    grid-template-columns: 15.25rem minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 2.35rem;
    padding: 1.7rem 1.25rem;
    background: var(--navy);
    color: #f5f8fd;
}

.brand, .auth-brand { display: flex; align-items: center; gap: .75rem; }
.brand { color: inherit; text-decoration: none; }
.brand-mark {
    display: grid;
    flex: 0 0 2.35rem;
    height: 2.35rem;
    place-items: center;
    border-radius: .55rem;
    background: #cde0f8;
    color: var(--navy);
    font-size: 1.18rem;
    font-weight: 800;
}

.brand-name { font-size: .96rem; font-weight: 750; line-height: 1.2; }
.brand-caption { display: block; margin-top: .3rem; font-size: .85rem; font-weight: 500; opacity: .86; }
.nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .64rem .75rem;
    border-radius: .42rem;
    background: #263e60;
    color: #fff;
    font-size: .95rem;
    text-decoration: none;
}

.nav-icon { width: .8rem; height: .8rem; border: 1.5px solid currentColor; border-radius: .18rem; }
.logout { margin-top: auto; }
.workspace-main { width: 100%; max-width: 88rem; margin-inline: auto; padding: 2.5rem clamp(1rem, 3.4vw, 3rem); }
.page-header { margin-bottom: 1.65rem; }
.page-header > p { margin-bottom: 0; }
.muted, .hint { color: var(--muted); }
.hint { margin: -.35rem 0 0; font-size: .9rem; }

.panel {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: .7rem;
    background: #fff;
    box-shadow: 0 1px 2px #2037580d;
}

.section { padding: clamp(1rem, 2vw, 1.6rem); }
.stack { display: grid; gap: 1rem; }
.filters {
    display: flex;
    align-items: end;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.15rem 1.25rem;
}

.filters label:first-child { flex: 1 1 14rem; }
.filters label:nth-child(2) { flex: 0 1 11rem; }
label { display: grid; gap: .38rem; font-size: .92rem; font-weight: 620; }
input:not([type="hidden"]), textarea, select {
    width: 100%;
    min-height: 2.75rem;
    padding: .48rem .64rem;
    border: 1px solid #c5d0de;
    border-radius: .39rem;
    background: #fff;
    color: #192536;
    font-size: 1rem;
    font-weight: 400;
}

textarea { resize: vertical; }
select {
    appearance: none;
    padding-right: 2rem;
    background-image: linear-gradient(45deg, transparent 50%, #526477 50%), linear-gradient(135deg, #526477 50%, transparent 50%);
    background-position: calc(100% - .93rem) 54%, calc(100% - .67rem) 54%;
    background-repeat: no-repeat;
    background-size: .26rem .26rem;
}

.filter-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.button {
    display: inline-flex;
    min-height: 2.75rem;
    align-items: center;
    justify-content: center;
    padding: .4rem .88rem;
    border: 1px solid transparent;
    border-radius: .39rem;
    font-size: .94rem;
    font-weight: 670;
    line-height: 1.25;
    text-decoration: none;
    cursor: pointer;
}

.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover { background: #183960; }
.button-secondary { border-color: #bfccdc; background: #fff; color: #223a58; }
.button-secondary:hover { background: #edf3fa; }
.button-sidebar { width: 100%; border-color: #577190; background: transparent; color: #fff; }
.button-sidebar:hover { background: #263e60; }

.table-summary {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    padding: .7rem 1.25rem;
    border-top: 1px solid #edf0f5;
    color: var(--muted);
    font-size: .87rem;
}
.table-summary strong { color: var(--navy); font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; border-top: 1px solid var(--border); }
table { width: 100%; min-width: 50rem; border-collapse: collapse; text-align: left; }
thead { background: #f5f7fa; color: #46586e; }
th, td { padding: .85rem 1rem; font-size: .93rem; white-space: nowrap; }
thead th { font-weight: 680; }
tbody tr + tr { border-top: 1px solid #e7edf3; }
tbody tr:hover { background: #f9fbfe; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.order-number, .date { font-variant-numeric: tabular-nums; }
.order-number, .review-table td[data-label="商戶"] { white-space: normal; overflow-wrap: anywhere; }
.date { color: var(--muted); font-size: .9rem; }
.detail-link { font-weight: 700; text-underline-offset: .22em; }
.empty-state { padding: 2.65rem 1rem; border-top: 1px solid var(--border); color: var(--muted); text-align: center; }

.status {
    display: inline-block;
    padding: .2rem .52rem;
    border: 1px solid #d9e3ee;
    border-radius: .35rem;
    background: #f0f4fa;
    color: #3d526d;
    font-size: .86rem;
    line-height: 1.35;
    font-weight: 650;
    white-space: nowrap;
}
.status-pending_review, .status-awaiting_sms { border-color: #efd99a; background: #fffae6; color: #745018; }
.status-approved, .status-submitting { border-color: #c4d5ed; background: #eef4fe; color: #2a528a; }
.status-submitted { border-color: #cbd2f0; background: #f0f1ff; color: #414e86; }
.status-delivery_unknown { border-color: #d3c1e2; background: #f7efff; color: #663983; }
.status-completed { border-color: #bcded0; background: #eaf8f1; color: #255d49; }
.status-failed, .status-rejected { border-color: #ebc3c9; background: #fdecf0; color: #853540; }
.status-actions { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .55rem; }
.status-actions form { margin: 0; }
.status-actions .button { min-height: 2.75rem; padding: .3rem .7rem; white-space: nowrap; }
.result-pending { color: var(--muted); font-size: .9rem; }
.queue-progress { min-width: 10rem; max-width: 18rem; white-space: normal; }
.queue-failure { margin: .38rem 0 0; color: #853540; font-size: .86rem; overflow-wrap: anywhere; }

.back-link { display: inline-block; margin-bottom: .62rem; font-size: .94rem; font-weight: 650; text-underline-offset: .22em; }
.title-row { display: flex; align-items: center; flex-wrap: wrap; gap: .65rem; }
.title-row h1 { overflow-wrap: anywhere; margin: 0; }
.details-layout { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: 1rem; align-items: start; }
.amount { display: grid; gap: .12rem; padding: .85rem 1rem; border-radius: .5rem; background: #eff4fb; }
.amount span { color: #485c75; font-size: .91rem; }
.amount strong { color: var(--navy); font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.details { display: grid; gap: 0; margin: .65rem 0 0; }
.details > div { display: grid; grid-template-columns: minmax(6rem, 1fr) minmax(min-content, 1.5fr); gap: .5rem; padding: .54rem 0; border-bottom: 1px solid #edf0f5; }
.details > div:last-child { border-bottom: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.progress { display: grid; gap: 0; margin: 0; }
.progress > div {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: .4rem .75rem;
    padding: .68rem 0;
    border-bottom: 1px solid #e7edf3;
}
.progress > div:first-child { padding-top: 0; }
.progress dd { font-weight: 650; }
.receipt { margin-top: 1rem; }
.progress-note { margin: .9rem 0 0; color: var(--muted); font-size: .92rem; }
.dispatch-notice { margin: .9rem 0 0; }
.follow-up-actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: .9rem; }
.follow-up-actions form { margin: 0; }
.activity-panel { margin-top: 1rem; }
.activity-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .4rem; }
.activity { margin: 0; padding: 0; list-style: none; }
.activity li { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem .8rem; padding: .62rem 0; }
.activity li + li { border-top: 1px solid #e7edf3; }
.activity p { width: 100%; margin: 0; overflow-wrap: anywhere; }
.section > p:last-child { margin-bottom: 0; }

.notice {
    padding: .65rem .85rem;
    border: 1px solid #c4d6ee;
    border-radius: .42rem;
    background: #edf4fd;
    color: #263f61;
    overflow-wrap: anywhere;
}
.notice-error { border-color: #e8bdc3; background: #fdecf0; color: #853540; }
.auth-layout {
    display: grid;
    min-height: 100vh;
    align-items: start;
    justify-items: center;
    padding: clamp(2rem, 12vh, 7rem) 1rem 2rem;
    background: linear-gradient(155deg, #e9f0fa, #f3f6fa 58%);
}
.auth-shell { width: min(100%, 27rem); }
.auth-brand { margin-bottom: 1.05rem; color: var(--navy); }
.auth-panel { display: grid; gap: .85rem; padding: clamp(1.25rem, 5vw, 1.85rem); }
.auth-panel > * { margin-bottom: 0; }
.auth-panel h1 { font-size: 1.5rem; }
.auth-panel form .button { width: 100%; }

@media (max-width: 51rem) {
    .workspace { grid-template-columns: minmax(0, 1fr); }
    .sidebar { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .85rem; padding: .85rem 1rem; }
    .sidebar nav { order: 3; flex-basis: 100%; }
    .logout { margin-top: 0; }
    .workspace-main { padding-top: 1.5rem; }
}

@media (max-width: 44rem) {
    .table-wrap { overflow: visible; }
    .review-table, .review-table tbody { display: block; min-width: 0; }
    .review-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
    .review-table tbody tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .7rem .85rem;
        padding: 1rem 1.15rem;
    }
    .review-table tbody :is(th, td) { padding: 0; text-align: left; white-space: normal; }
    .review-table [data-label]::before {
        display: block;
        margin-bottom: .2rem;
        color: var(--muted);
        content: attr(data-label);
        font-size: .76rem;
        font-weight: 550;
    }
    .review-table :is(.order-number, .queue-progress, .queue-detail) { grid-column: 1 / -1; }
    .review-table .queue-progress { min-width: 0; max-width: none; }
    .queue-detail .detail-link { display: inline-flex; min-height: 2.75rem; align-items: center; }
}

@media (max-width: 32rem) {
    .filters label:nth-child(2) { flex: 1 1 100%; }
    .filters { padding-inline: 1rem; }
    .table-summary { padding-inline: 1rem; }
}
