:root {
  color-scheme: light;
  --brand: #111;
  --brand-hover: #000;
  --brand-soft: #eee;
  --canvas: #f6f6f6;
  --ink: #202020;
  --muted: #666;
  --line: #d8d8d8;
  --field: #fff;
  --good: #333;
  --error: #222;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
#mode:empty { display: none; }
html, body { min-width: 320px; margin: 0; }
body { background: var(--canvas); }
header { position: sticky; top: 0; z-index: 20; min-height: 62px; padding: 9px clamp(12px, 2.5vw, 34px); display: flex; align-items: center; gap: 14px; background: #fff; border-bottom: 1px solid var(--line); }
.brand-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand { color: var(--brand); font-size: 19px; font-weight: 760; text-decoration: none; }
.preview-label, .pill { display: inline-flex; align-items: center; min-height: 32px; padding: 6px 10px; border: 1px solid #e5e5e5; border-radius: 999px; background: #f7f7f7; color: #333; font-size: 11px; font-weight: 650; line-height: 1.4; }
#identity { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
#identity button { min-height: 34px; padding: 6px 10px; }

main { width: min(100%, 1920px); margin: 0 auto; padding: 16px clamp(10px, 1.8vw, 24px) 32px; }
.panel { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 2px 9px #00000008; }
h1, h2, h3, p { margin: 0; }
h1, h2 { color: #111; font-size: 19px; font-weight: 740; line-height: 1.35; }
h3 { color: #222; font-size: 13px; font-weight: 720; }
p { color: var(--muted); font-size: 12px; line-height: 1.55; }
small, .muted { color: var(--muted); font-size: 11px; line-height: 1.45; }

input, select, textarea { min-width: 0; max-width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); color: var(--ink); font: inherit; font-size: 12px; }
input::placeholder, textarea::placeholder { color: #858585; opacity: 1; }
input:focus, select:focus, textarea:focus { outline: 2px solid #333; outline-offset: 1px; }
input[readonly], input:disabled, select:disabled, textarea:disabled { color: #555; background: #f1f1f1; }
button { min-height: 38px; padding: 8px 13px; border: 1px solid var(--brand); border-radius: 8px; background: var(--brand); color: #fff; font: inherit; font-size: 12px; font-weight: 680; cursor: pointer; white-space: nowrap; transition: background-color .12s ease, border-color .12s ease, transform .12s ease; }
button:not(:disabled):hover { background: var(--brand-hover); }
button:not(:disabled):active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, a:focus-visible { outline: 2px solid #333; outline-offset: 3px; }
.secondary { border-color: var(--line); background: #fff; color: #222; }
.secondary:not(:disabled):hover { background: #eee; }

#notice { margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #f0f0f0; color: #333; font-size: 12px; line-height: 1.55; white-space: pre-line; }
#notice:empty { display: none; }
.workbench-shell { display: grid; grid-template-columns: clamp(200px, 17vw, 224px) minmax(0, 1fr); align-items: start; gap: 12px; }
.account-rail { position: sticky; top: 74px; max-height: calc(100vh - 88px); overflow: auto; padding: 13px 11px; }
.rail-heading, .account-group-heading, .section-heading, .account-action-row, .account-banner, .order-toolbar, .summary, .quick-picks, .sync-controls, .account-actions, .sync-feedback-row, .pager { display: flex; align-items: center; }
.rail-heading { justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.rail-heading small { display: block; margin-top: 2px; }
.rail-heading button { min-height: 30px; padding: 5px 8px; font-size: 11px; }
.account-search-label { display: grid; gap: 5px; margin-bottom: 11px; color: #555; font-size: 11px; font-weight: 650; }
.account-search-label input { width: 100%; min-height: 35px; }
.account-list-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: 0 0 10px; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: #f5f5f5; }
.account-list-tab { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 34px; padding: 5px 7px; border-color: transparent; background: transparent; color: #333; }
.account-list-tab.secondary { border-color: transparent; background: transparent; color: #444; }
.account-list-tab[aria-selected="true"] { border-color: #aaa; background: #fff; color: #111; box-shadow: 0 1px 2px #00000010; }
.account-list-tab span { min-width: 19px; padding: 1px 5px; border-radius: 999px; background: #eee; font-size: 10px; text-align: center; }
.account-list-tab[aria-selected="true"] span { background: #222; color: #fff; }
.account-group { margin-top: 12px; }
.account-group-heading { justify-content: space-between; margin-bottom: 6px; padding: 0 2px; }
.account-group-heading span { min-width: 22px; padding: 2px 6px; border-radius: 999px; background: #eee; color: #555; font-size: 10px; text-align: center; }
.account-list { display: grid; gap: 6px; }
.account-list-empty { padding: 9px 7px; border: 1px dashed #ddd; border-radius: 7px; color: #777; font-size: 10px; line-height: 1.45; }
.account-list-status { margin-top: 9px; min-height: 0; color: #555; font-size: 10px; }
.account-card { display: grid; gap: 6px; width: 100%; min-width: 0; padding: 9px; border: 1px solid #ddd; border-radius: 8px; background: #fff; color: #222; text-align: left; white-space: normal; }
.account-card:hover:not(:disabled), .account-card.selected { background: #f0f0f0; border-color: #888; }
.account-card.selected { box-shadow: inset 3px 0 #111; }
.account-card-top, .account-card-meta, .account-card-actions { display: flex; align-items: baseline; justify-content: space-between; gap: 7px; min-width: 0; }
.account-card-top strong { overflow-wrap: anywhere; font-size: 12px; }
.account-card-top span { flex: 0 0 auto; color: #333; font-size: 11px; font-variant-numeric: tabular-nums; }
.account-card-username, .account-card-meta { color: #666; font-size: 10px; line-height: 1.4; overflow-wrap: anywhere; }
.account-card-actions { align-items: center; margin-top: 1px; }
.account-card-actions small { flex: 1; }
.account-card-actions button { min-height: 30px; padding: 5px 8px; font-size: 10px; }
.account-observation-conflict { color: #333; font-weight: 700; }

.work-area { display: grid; min-width: 0; gap: 12px; }
.finance-status-panel { border-left: 3px solid #333; }
.finance-status-panel > p { margin-top: 6px; }
.finance-test-actions { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0; }
.finance-status-panel details { font-size: 11px; color: #555; }
.finance-status-panel summary { cursor: pointer; }
.finance-request { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 7px; padding: 7px 0; border-top: 1px solid #eee; }
.finance-request button { min-height: 28px; padding: 4px 7px; font-size: 10px; }
.account-panel { padding: 14px 16px; }
.account-banner { justify-content: space-between; flex-wrap: wrap; gap: 12px 18px; min-width: 0; }
.account-identity { min-width: 0; flex: 1 1 240px; }
.account-title-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
#account-name { overflow-wrap: anywhere; }
.account-state { flex: 0 0 auto; padding: 3px 7px; border: 1px solid #ccc; border-radius: 5px; color: #555; font-size: 10px; }
.current-account-label { display: block; margin-top: 3px; color: #666; font-size: 11px; overflow-wrap: anywhere; }
.summary { flex-wrap: wrap; gap: 6px; min-width: 0; }
.summary .pill { white-space: normal; }
.balance-observation { border-color: #bbb; background: #ededed; color: #111; }
.balance-pending { border-style: dashed; }
.account-action-row { justify-content: space-between; flex-wrap: wrap; gap: 10px 14px; margin-top: 12px; }
.account-actions, .sync-controls { flex-wrap: wrap; gap: 7px; }
.sync-controls select { min-width: 138px; }
#sync { min-width: 112px; }
.sync-feedback-row { justify-content: space-between; flex-wrap: wrap; gap: 5px 12px; margin-top: 9px; padding-top: 8px; border-top: 1px solid #eee; }
#plugin { max-width: 65ch; }
#sync-status { min-width: 0; color: #444; font-size: 11px; line-height: 1.45; }
.dates { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.dates label { display: flex; align-items: center; gap: 7px; margin: 8px 0; font-size: 11px; }
.dates input { min-height: 34px; padding: 6px 8px; }
.section-heading { justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.section-heading p { margin-top: 3px; }
.exchange-action { min-height: 36px; padding: 7px 12px; background: #111; color: #fff; }
.order-toolbar { justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.order-counts { flex-wrap: wrap; }
.quick-picks { justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
.quick-picks button { min-height: 32px; padding: 5px 9px; border-radius: 999px; font-size: 11px; }
.quick-picks button[aria-pressed="true"] { background: #ededed; border-color: #999; }
.order-panel { container-name: orders; container-type: inline-size; }
.table-wrap { position: relative; width: 100%; max-width: 100%; max-height: min(70vh, 820px); overflow: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: 9px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; text-align: left; font-size: 11px; line-height: 1.45; }
#sync-table { width: 100%; min-width: 0; table-layout: fixed; }
thead th { position: sticky; top: 0; z-index: 2; padding: 9px 8px; border-bottom: 1px solid #cfcfcf; background: #ededed; color: #333; font-size: 10px; font-weight: 720; white-space: normal; }
tbody td { min-width: 0; padding: 8px 7px; border-bottom: 1px solid #e5e5e5; vertical-align: middle; overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafafa; }
td > input, td > select, td > div > input, td > div > select { width: 100%; }
#sync-table input, #sync-table select { width: 100%; min-width: 0; min-height: 36px; padding: 7px; border-radius: 7px; font-size: 11px; }
#sync-table tbody td:first-child { font-size: 10px; white-space: nowrap; }
#sync-table select[name="fulfillment_method"] { padding-inline: 5px; font-size: 10px; }
.date-col { width: 8%; }
.product-col { width: 18%; }
.cost-col { width: 6%; }
.rmb-col { width: 6%; }
.handler-col { width: 5%; }
.fulfill-col { width: 12%; }
.payment-col { width: 8%; }
.price-col { width: 9%; }
.remark-col { width: 17%; }
.state-col { width: 11%; }
.currency-table .date-col { width: 16%; }
.currency-table .product-col { width: 22%; }
.currency-table .cost-col { width: 15%; }
.currency-table .rmb-col { width: 13%; }
.currency-table .handler-col { width: 12%; }
.currency-table .state-col { width: 22%; }
.order-product-name { font-weight: 700; }
.order-source { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.order-date, .order-date .order-source { white-space: normal; overflow-wrap: anywhere; }
.order-sale-date { display: block; }
.remark-stack, .sync-order-actions { display: flex; min-width: 0; flex-direction: column; align-items: stretch; gap: 5px; }
.sync-order-actions { width: 100%; align-items: flex-start; }
.sync-order-actions button { max-width: 100%; min-height: 34px; padding: 6px 8px; white-space: normal; overflow-wrap: anywhere; }
.status-pill { display: inline-flex; align-items: center; min-height: 23px; padding: 4px 7px; border: 1px solid #ddd; border-radius: 999px; background: #f4f4f4; color: #333; font-size: 10px; font-weight: 680; line-height: 1.35; }
.status-pill.success { border-color: #ccc; background: #e9e9e9; color: #111; }
.status-pill.error { border-color: #777; background: #eee; color: #111; }
.row-feedback, .field-hint, .edit-conflict-hint { display: block; max-width: 100%; color: #555; font-size: 10px; line-height: 1.45; overflow-wrap: anywhere; }
.row-feedback.error, .field-hint { color: #333; }
.field-hint[hidden] { display: none; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: #555; box-shadow: 0 0 0 1px #555; }
.edit-conflict-hint { margin-top: 3px; padding: 4px 6px; border-left: 2px solid #777; background: #f3f3f3; }
.row-currency { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.clear-draft { min-height: 24px !important; padding: 2px 0 !important; border: 0; background: transparent !important; color: #555 !important; font-size: 10px !important; font-weight: 500; text-align: left; text-decoration: underline; }
.pending { background: #fff; }
.done { background: #f7f7f7; }
.restricted { background: #f4f4f4; }
.pager { justify-content: center; gap: 14px; padding: 12px 4px 0; color: #555; font-size: 11px; }
.pager button { min-height: 34px; padding: 5px 10px; }

#login { width: min(420px, 100%); margin: clamp(36px, 10vh, 90px) auto; padding: 22px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
#login h1 { margin-bottom: 14px; }
#login form label { display: grid; gap: 6px; margin: 12px 0; color: #444; font-size: 12px; font-weight: 650; }
#login input, #login button { width: 100%; }
#login button { margin-top: 5px; }
label { min-width: 0; }
dialog { width: min(540px, calc(100vw - 24px)); max-height: 86vh; padding: 18px; border: 1px solid #bbb; border-radius: 12px; box-shadow: 0 18px 60px #0003; }
dialog::backdrop { background: #1119; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.dialog-heading button { min-height: 34px; padding: 6px 10px; }
#credentials-dialog > p { margin: 8px 0 12px; }
#credentials-dialog > label { display: grid; gap: 5px; margin: 10px 0; font-size: 11px; font-weight: 650; }
.credential-line { display: flex; align-items: center; gap: 6px; }
.credential-line input { flex: 1; }
.credential-line button { min-height: 36px; padding: 6px 9px; }
#credential-feedback { min-height: 18px; }
.token-code-value { display: block; min-height: 68px; margin: 18px 0 6px; text-align: center; font-size: 36px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: .16em; }
#token-code-dialog > p { margin: 8px 0; }
.token-code-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
#token-code-status { min-height: 20px; }
footer { padding: 14px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }

@media (max-width: 620px) {
  main { padding: 12px 10px 24px; }
  .workbench-shell { grid-template-columns: 1fr; }
  .account-rail { position: static; max-height: none; overflow: visible; }
  .work-area { gap: 9px; }
  .order-toolbar { align-items: flex-start; }
}
@media (max-width: 540px) {
  header { min-height: 52px; gap: 7px; padding-inline: 10px; }
  .brand { font-size: 16px; }
  .preview-label { display: none; }
  #identity { gap: 6px; font-size: 11px; }
  #identity button { min-height: 32px; padding: 5px 8px; }
  main { padding: 9px 8px 18px; }
  .panel { padding: 11px; border-radius: 10px; }
  h1, h2 { font-size: 17px; }
  .account-rail { padding: 10px; }
  .rail-heading { margin-bottom: 8px; }
  .account-search-label { margin-bottom: 8px; }
  .account-search-label input { min-height: 34px; }
  .account-rail { display: grid; grid-template-columns: 1fr; gap: 0; }
  .rail-heading, .account-search-label, .account-list-switch, .account-group, .account-list-status { grid-column: 1 / -1; }
  .account-group { min-width: 0; margin-top: 8px; }
  .account-card { min-height: 73px; gap: 4px; padding: 7px; }
  .account-card-top { align-items: flex-start; flex-direction: column; gap: 2px; }
  .account-card-top strong { font-size: 11px; }
  .account-card-top span { font-size: 10px; }
  .account-card-meta, .account-card-username { font-size: 9px; }
  .account-card-actions { align-items: flex-start; flex-direction: column; gap: 4px; }
  .account-card-actions button { width: 100%; }
  .account-banner { gap: 9px; }
  .account-identity { flex-basis: 100%; }
  #account-summary { width: 100%; }
  .account-panel { padding: 11px; }
  .account-action-row { align-items: stretch; flex-direction: column; gap: 8px; margin-top: 9px; }
  .account-actions, .sync-controls { width: 100%; }
  .account-actions button { flex: 1; }
  .sync-controls { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .sync-controls select { grid-column: 1 / -1; width: 100%; }
  .sync-controls button { width: 100%; }
  .sync-feedback-row { align-items: flex-start; flex-direction: column; }
  .section-heading { align-items: flex-start; }
  .exchange-action { padding-inline: 9px; }
  .order-toolbar { flex-direction: column; gap: 6px; }
  .quick-picks { width: 100%; justify-content: flex-start; gap: 4px; }
  .quick-picks button { min-height: 31px; padding: 4px 7px; font-size: 10px; }
  .table-wrap { max-height: 68vh; border-radius: 8px; }
  #sync-table th { padding: 8px 6px; font-size: 10px; }
  #sync-table td { padding: 7px 6px; }
  #sync-table input, #sync-table select { min-height: 36px; padding: 6px; font-size: 10px; }
  .credential-line { flex-wrap: wrap; }
  .credential-line input { flex-basis: 100%; }
  .credential-line button { flex: 1; }
}
@container orders (max-width: 860px) {
  .table-wrap { max-height: none; overflow: visible; border: 0; border-radius: 0; }
  #sync-table, #sync-table tbody { display: block; width: 100%; min-width: 0; }
  #sync-table colgroup { display: none; }
  #sync-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  #sync-table tbody { display: grid; gap: 10px; }
  #sync-table tbody tr { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px 10px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; }
  #sync-table tbody td { display: block; min-width: 0; grid-column: span 2; padding: 0; border: 0; }
  #sync-table tbody td:first-child { font-size: 11px; white-space: normal; }
  #sync-table select[name="fulfillment_method"] { padding-inline: 7px; font-size: 11px; }
  #sync-table tbody td::before { display: block; margin-bottom: 5px; color: #666; font-size: 10px; font-weight: 650; content: attr(data-label); }
  #sync-table tbody td:nth-child(2) { grid-column: 1 / 5; grid-row: 1; }
  #sync-table tbody td:nth-child(1) { grid-column: 5 / -1; grid-row: 1; }
  #sync-table:not(.currency-table) tbody td:nth-child(9) { grid-column: span 4; }
  #sync-table.currency-table tbody td:nth-child(6) { grid-column: 1 / -1; }
  #sync-table tbody td[colspan] { grid-column: 1 / -1; grid-row: auto; }
  #sync-table tbody td[colspan]::before { display: none; }
  .sync-order-actions { align-items: stretch; }
  .sync-order-actions .status-pill { align-self: flex-start; }
}
@container orders (max-width: 440px) {
  #sync-table tbody tr { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #sync-table tbody td { grid-column: span 1; grid-row: auto; }
  #sync-table tbody td:nth-child(1) { grid-column: auto; grid-row: auto; }
  #sync-table tbody td:nth-child(2) { grid-column: 1 / -1; grid-row: 1; }
  #sync-table:not(.currency-table) tbody td:nth-child(9),
  #sync-table:not(.currency-table) tbody td:nth-child(10),
  #sync-table.currency-table tbody td:nth-child(6) { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; } }

.finance-status-panel { padding: 9px 13px; border-left: 1px solid var(--line); }
#finance-maintenance > summary { color: #666; font-size: 11px; }
#finance-maintenance[open] > button { margin: 10px 0; }
.conversion-guidance { margin: 9px 0; padding: 11px 12px; border: 1px solid #aaa; border-left: 3px solid #333; border-radius: 7px; background: #f5f5f5; }
.conversion-guidance strong { font-size: 13px; }
.conversion-guidance p { margin-top: 5px; font-size: 11px; }
.account-card-context { color: #333; font-size: 10px; overflow-wrap: anywhere; }
.workbench-actions,.gift-business-actions { display:flex;flex-wrap:wrap;gap:7px;align-items:center; }
.gift-panel > summary { font-size:13px;font-weight:700;cursor:pointer; }
.gift-business-row { display:grid;grid-template-columns:minmax(0,1.2fr) minmax(0,1fr) minmax(0,1.5fr);gap:10px;padding:12px 0;border-bottom:1px solid var(--line);font-size:12px; }
.gift-business-row > div { min-width:0;overflow-wrap:anywhere; }
.gift-business-row small { display:block;margin-top:4px; }
.gift-business-actions button { min-height:32px;padding:5px 8px;font-size:11px;white-space:normal; }
.gift-form { display:grid;gap:10px;margin-top:12px; }
.gift-form label { display:grid;gap:5px;font-size:12px; }
.gift-form-pair { display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px; }
.gift-form input,.gift-form select { width:100%; }
#gift-feedback:empty { display:none; }
@media(max-width:620px){.gift-business-row{grid-template-columns:repeat(2,minmax(0,1fr))}.gift-business-actions{grid-column:1/-1}.workbench-actions{justify-content:flex-end}}
