:root {
  --ink: #25221f;
  --muted: #7c7771;
  --line: #e7e2dc;
  --surface: #fff;
  --canvas: #f6f4f1;
  --brand: #766a5d;
  --brand-dark: #5f554b;
  --brand-soft: #eee9e3;
  --danger: #b44b49;
}

* { box-sizing: border-box; }
html { background: var(--canvas); }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 110.25%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang HK", "Microsoft JhengHei", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.app-shell { min-height: 100vh; }

.topbar { min-height: 84px; padding: 16px clamp(20px,4vw,64px); display: flex; align-items: center; justify-content: space-between; gap: 24px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 16.54px; font-weight: 800; letter-spacing: -.05em; flex: 0 0 auto; }
.brand-logo { width: 46px; height: 46px; padding: 2px; object-fit: contain; flex: 0 0 auto; }
.brand h1 { margin: 0; font-size: 19.84px; line-height: 1.35; letter-spacing: -.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13.23px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.logout-button { min-height: 40px; color: #655e57; background: #fff; border-color: #ddd7d0; text-decoration: none; box-shadow: 0 4px 12px rgba(60,52,45,.045); }
.logout-button:hover { color: var(--danger); background: #fff8f7; border-color: #ead2cf; }
.country-nav { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 15px clamp(20px,4vw,64px); background: linear-gradient(180deg,#fff 0%,#faf8f5 100%); border-bottom: 1px solid var(--line); }
.country-nav a { position: relative; width: min(210px,32vw); min-width: 170px; min-height: 58px; padding: 8px 16px; display: inline-flex; align-items: center; gap: 12px; color: #716a63; border: 1px solid #e5dfd9; border-radius: 16px; background: rgba(255,255,255,.72); box-shadow: 0 5px 18px rgba(61,53,46,.035); text-decoration: none; transition: transform .18s,background .18s,border .18s,color .18s,box-shadow .18s; }
.country-nav a:hover { transform: translateY(-1px); background: #fff; color: var(--ink); border-color: #d7cec5; box-shadow: 0 8px 22px rgba(61,53,46,.07); }
.country-nav a.active { color: var(--brand-dark); background: #fff; border-color: #b9aa9b; box-shadow: 0 8px 24px rgba(93,78,65,.11),inset 0 -3px 0 var(--brand); }
.country-flag { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 12px; background: #f5f1ec; font-size: 24.26px; box-shadow: inset 0 0 0 1px rgba(113,98,84,.07); }
.country-copy { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.country-copy strong { font-size: 17.64px; line-height: 1.2; letter-spacing: .02em; }
.country-copy small { color: #a0978e; font-size: 9.92px; font-weight: 750; letter-spacing: .13em; }
.country-indicator { width: 21px; height: 21px; margin-left: auto; display: grid; place-items: center; color: transparent; border-radius: 50%; background: transparent; font-size: 12.13px; font-weight: 800; }
.country-nav a.active .country-indicator { color: #fff; background: var(--brand); }
.workspace { width: min(1480px,calc(100% - 40px)); margin: 0 auto; padding: 28px 0 64px; }

.button { min-height: 40px; padding: 0 15px; border-radius: 10px; border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 14.33px; font-weight: 650; transition: background .18s,border .18s,transform .18s; }
.button:active { transform: translateY(1px); }
.button-primary { background: var(--brand); color: #fff; box-shadow: 0 7px 18px rgba(90,78,67,.12); }
.button-primary:hover { background: var(--brand-dark); }
.button-secondary { background: #fff; color: #504b46; border-color: var(--line); }
.button-secondary:hover { background: #faf9f7; border-color: #d6cfc7; }
.button-ghost { background: transparent; color: var(--muted); }

.summary-grid { display: grid; grid-template-columns: 1.3fr repeat(3,1fr); gap: 12px; margin-bottom: 18px; }
.summary-card { min-height: 92px; padding: 20px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; gap: 14px; }
.summary-card > div { display: flex; flex-direction: column; gap: 3px; }
.summary-card strong { font-size: 26.46px; line-height: 1; letter-spacing: -.04em; }
.summary-card span { color: var(--muted); font-size: 13.23px; }
.summary-main { background: var(--ink); border-color: var(--ink); color: #fff; display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; }
.summary-main span { color: #cdc8c2; font-size: 13.23px; }
.summary-main strong { grid-row: 1/3; grid-column: 2; font-size: 39.69px; align-self: center; }
.summary-main small { color: #8f8982; font-size: 12.13px; }
.metric-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.dot-blue { background: #77a8d9; box-shadow: 0 0 0 5px #eaf3fb; }
.dot-purple { background: #9b83bd; box-shadow: 0 0 0 5px #f0ebf7; }
.dot-orange { background: #d99e64; box-shadow: 0 0 0 5px #fbf0e5; }

.integration-note { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; margin-bottom: 14px; background: #fbf7ed; border: 1px solid #eee2c6; border-radius: 12px; color: #6c5934; }
.integration-icon { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: #f0e5c8; flex: 0 0 auto; }
.integration-note strong { display: block; font-size: 14.33px; margin-bottom: 2px; }
.integration-note p { margin: 0; font-size: 13.23px; color: #8a7650; line-height: 1.5; }

.records-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: 0 8px 30px rgba(56,50,45,.035); }
.records-heading { padding: 20px 22px 16px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.records-heading h2 { margin: 0; font-size: 18.74px; letter-spacing: -.02em; }
.records-heading p { margin: 3px 0 0; color: var(--muted); font-size: 13.23px; }
.heading-actions { display: flex; gap: 8px; }
.toolbar { padding: 0 22px 16px; display: flex; gap: 10px; justify-content: space-between; }
.search-field { flex: 1; max-width: 390px; height: 40px; padding: 0 12px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 10px; color: #aaa39b; background: #fbfaf9; }
.search-field:focus-within { background: #fff; color: var(--brand); border-color: #bcb1a6; box-shadow: 0 0 0 3px rgba(118,106,93,.09); }
.search-field input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 14.33px; }
.search-field input::placeholder { color: #aaa49d; }
.filter-row { display: flex; gap: 8px; }
.filter-row select,.quick-status { height: 40px; min-width: 132px; padding: 0 32px 0 11px; color: #5f5953; background: #fff; border: 1px solid var(--line); border-radius: 10px; outline: 0; font-size: 13.23px; }
.mobile-date-sort { display: none; }
.archive-toggle { height: 40px; padding: 0 12px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: #68615b; font-size: 13.23px; font-weight: 600; }
.archive-toggle.active { color: var(--brand-dark); background: var(--brand-soft); border-color: #d7cdc3; }

.desktop-table { overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 1120px; table-layout: fixed; }
th { padding: 11px 14px; background: #faf9f7; color: #88817a; font-size: 12.13px; font-weight: 600; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
.date-sort-button { width: 100%; padding: 0; display: inline-flex; align-items: center; gap: 5px; color: inherit; border: 0; background: transparent; font-weight: inherit; text-align: left; }
.date-sort-button:hover,.date-sort-button:focus-visible { color: var(--brand-dark); outline: 0; }
.sort-arrow { width: 18px; height: 18px; display: inline-grid; place-items: center; color: var(--brand-dark); background: var(--brand-soft); border-radius: 6px; font-size: 11.55px; line-height: 1; }
td { padding: 16px 14px; border-bottom: 1px solid #efebe7; vertical-align: middle; font-size: 14.33px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfbfa; }
th:nth-child(1) { width: 16%; } th:nth-child(2) { width: 9%; } th:nth-child(3) { width: 7%; } th:nth-child(4) { width: 18%; } th:nth-child(5) { width: 20%; } th:nth-child(6) { width: 22%; } th:nth-child(7) { width: 8%; }
.store-name { display: block; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.33px; }
.muted { color: var(--muted); }
.order-number { display: block; margin-top: 4px; font-size: 12.13px; }
.date-text { color: #5f5953; white-space: nowrap; }
.forwarder { display: inline-flex; padding: 4px 7px; border-radius: 6px; font-size: 11.03px; font-weight: 750; letter-spacing: .05em; }
.forwarder-ido { color: #5e6b9b; background: #eef0f8; }
.forwarder-cm { color: #9a6540; background: #f8eee7; }
.forwarder-jinyue { color: #477760; background: #eaf5ef; letter-spacing: 0; }
.tracking-number { display: flex; align-items: center; gap: 6px; color: #38332f; font-family: ui-monospace,SFMono-Regular,Menlo,monospace; font-size: 13.23px; }
.tracking-number span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tracking-number .tracking-empty { color: #99928a; font-family: inherit; }
.tracking-number button { padding: 3px; color: #a19991; border: 0; background: transparent; display: grid; place-items: center; }
td small { display: block; margin-top: 4px; color: #99928a; font-size: 11.03px; }
.tracking-state { display: flex; align-items: center; gap: 7px; min-width: 0; }
.tracking-state strong { font-size: 13.23px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tracking-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; background: #a9a39c; }
.tracking-in_transit .tracking-dot { background: #67a0d2; }
.tracking-out_for_delivery .tracking-dot { background: #9a7abb; }
.tracking-delivered .tracking-dot { background: #66a176; }
.tracking-exception .tracking-dot { background: #cb6762; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px; font-size: 11.03px; font-weight: 650; white-space: nowrap; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-kr_transit { color: #517da8; background: #edf4fa; }
.status-at_forwarder { color: #725998; background: #f1edf6; }
.status-to_hk { color: #a56836; background: #fbf0e6; }
.status-received { color: #4d8460; background: #ebf5ee; }
.quick-status { display: block; margin-top: 7px; width: 156px; height: 28px; font-size: 11.03px; border-radius: 7px; color: #7d756e; }
.row-actions { display: flex; justify-content: flex-end; gap: 3px; }
.row-actions button,.icon-button { width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: #8b847c; display: grid; place-items: center; }
.row-actions button:hover,.icon-button:hover { background: var(--brand-soft); color: var(--brand-dark); }
.row-actions .danger:hover { color: var(--danger); background: #faeeee; }

.mobile-list { display: none; }
.state-box { min-height: 330px; display: flex; align-items: center; justify-content: center; flex-direction: column; text-align: center; padding: 40px 20px; border-top: 1px solid var(--line); }
.state-box strong { font-size: 16.54px; }
.state-box p { margin: 7px 0 18px; color: var(--muted); font-size: 13.23px; }
.state-box#errorState { color: var(--danger); }
.empty-icon { width: 54px; height: 54px; display: grid; place-items: center; color: #8c8177; background: var(--brand-soft); border-radius: 17px; margin-bottom: 14px; }
.loading-list { min-height: 330px; display: grid; align-content: start; gap: 1px; border-top: 1px solid var(--line); background: #eeeae6; }
.loading-list span { display: block; height: 70px; background: linear-gradient(90deg,#fff,#faf8f6,#fff); background-size: 200% 100%; animation: shimmer 1.3s infinite; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; padding: 20px; display: grid; place-items: center; background: rgba(28,25,22,.45); backdrop-filter: blur(4px); }
.modal { width: min(600px,100%); max-height: calc(100vh - 40px); overflow-y: auto; background: #fff; border-radius: 18px; box-shadow: 0 30px 90px rgba(30,25,20,.2); }
.modal-header { padding: 22px 24px 17px; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 2px 0 0; font-size: 20.95px; }
.eyebrow { color: #a09890; font-size: 9.92px; letter-spacing: .16em; font-weight: 750; }
.form-grid { padding: 22px 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field-wide { grid-column: 1/-1; }
.field > span { font-size: 13.23px; font-weight: 650; color: #5f5953; }
.field b { color: #b75d55; }
.field em { margin-left: 5px; color: #99918a; font-size: .88em; font-style: normal; font-weight: 500; }
.field input,.field select { width: 100%; height: 43px; padding: 0 12px; border: 1px solid #ded8d2; border-radius: 9px; background: #fff; color: var(--ink); outline: 0; font-size: 14.33px; }
.field input:focus,.field select:focus { border-color: #9f9387; box-shadow: 0 0 0 3px rgba(118,106,93,.09); }
.field input::placeholder { color: #b4aea7; }
.field small { color: #99918a; font-size: 11.03px; }
.modal-actions { padding: 16px 24px 22px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }
.toast { position: fixed; left: 50%; bottom: 30px; z-index: 200; transform: translateX(-50%); padding: 10px 14px; display: flex; align-items: center; gap: 9px; color: #fff; background: #34302c; border-radius: 10px; box-shadow: 0 14px 40px rgba(28,24,20,.18); font-size: 13.23px; font-weight: 650; animation: toast-in .2s ease-out; }
.toast > span:first-child { width: 20px; height: 20px; display: grid; place-items: center; color: #395f44; background: #bfe0c8; border-radius: 50%; }
.fab { display: none; }
.is-syncing [data-icon],.is-syncing > span:first-child { display: inline-flex; animation: spin .8s linear infinite; }

.login-shell { min-height: 100vh; padding: 24px; display: grid; place-items: center; }
.login-card { width: min(390px,100%); padding: 34px; background: #fff; border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 20px 70px rgba(52,45,39,.08); }
.login-card .brand-mark { margin-bottom: 22px; }
.login-logo { width: 78px; height: 78px; object-fit: contain; display: block; margin: 0 0 20px; }
.login-card h1 { margin: 6px 0 7px; font-size: 25.36px; }
.login-card > p:not(.eyebrow) { margin: 0 0 22px; color: var(--muted); font-size: 14.33px; }
.login-card form { display: grid; gap: 15px; }
.login-button { width: 100%; margin-top: 2px; }
.login-error { padding: 10px 12px; margin: 0 0 16px; color: #984943; background: #fbefee; border-radius: 9px; font-size: 13.23px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%,8px); } }

@media (max-width:1050px) {
  .summary-grid { grid-template-columns: 1.25fr repeat(3,1fr); }
  .summary-card { padding: 16px; }
  .toolbar { flex-direction: column; }
  .search-field { max-width: none; }
  .filter-row { overflow-x: auto; padding-bottom: 1px; }
}

@media (max-width:760px) {
  .topbar { min-height: 70px; padding: 12px 16px; gap: 8px; position: relative; }
  .brand { gap: 9px; }
  .brand > div { min-width: 0; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
  .brand-logo { width: 42px; height: 42px; }
  .brand h1 { font-size: 17.64px; }
  .brand p { font-size: 11.03px; }
  .desktop-add { display: none; }
  .logout-button { width: 42px; min-height: 42px; padding: 0; border-radius: 11px; }
  .logout-button span:last-child { display: none; }
  .country-nav { gap: 8px; padding: 10px 12px; }
  .country-nav a { flex: 1; width: auto; min-width: 0; min-height: 55px; padding: 7px 10px; gap: 8px; border-radius: 14px; }
  .country-flag { width: 35px; height: 35px; font-size: 22.05px; }
  .country-copy strong { font-size: 16.54px; }
  .country-copy small { font-size: 8.82px; }
  .country-indicator { width: 19px; height: 19px; font-size: 11.03px; }
  .workspace { width: 100%; padding: 14px 12px 88px; }
  .summary-grid { grid-template-columns: repeat(3,1fr); gap: 7px; overflow: hidden; }
  .summary-card { min-height: 72px; padding: 12px; border-radius: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
  .summary-card strong { font-size: 22.05px; }
  .summary-card span { font-size: 9.92px; }
  .summary-card > div { gap: 4px; }
  .summary-card .metric-dot { width: 7px; height: 7px; }
  .summary-main { grid-column: 1/-1; min-height: 72px; display: grid; padding: 15px 17px; }
  .summary-main strong { font-size: 34.18px; }
  .integration-note { margin-bottom: 10px; }
  .records-panel { border-radius: 14px; overflow: visible; border: 0; box-shadow: none; background: transparent; }
  .records-heading { padding: 10px 3px 12px; }
  .records-heading h2 { font-size: 17.64px; }
  .heading-actions .button { width: 40px; padding: 0; }
  .heading-actions .button-label { display: none; }
  .toolbar { padding: 0 0 12px; gap: 8px; }
  .search-field { background: #fff; }
  .filter-row { gap: 6px; }
  .filter-row select { min-width: 118px; flex: 0 0 auto; }
  .mobile-date-sort { height: 40px; padding: 0 11px; display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; color: var(--brand-dark); background: var(--brand-soft); border: 1px solid #d7cdc3; border-radius: 10px; font-size: 12.13px; font-weight: 650; }
  .mobile-date-sort span { font-size: 14.70px; line-height: 1; }
  .archive-toggle { flex: 0 0 auto; }
  .desktop-table { display: none !important; }
  .mobile-list:not(.hidden) { display: grid; gap: 9px; }
  .package-card { padding: 15px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 5px 20px rgba(56,50,45,.025); }
  .card-top { display: flex; justify-content: space-between; gap: 14px; }
  .card-store { display: flex; align-items: center; gap: 7px; }
  .card-store strong { font-size: 15.44px; }
  .card-top p { margin: 4px 0 0; color: var(--muted); font-size: 11.03px; }
  .card-tracking { margin-top: 13px; padding: 11px 12px; display: flex; justify-content: space-between; align-items: center; background: #f8f6f3; border-radius: 10px; }
  .card-tracking > div { min-width: 0; }
  .card-tracking span,.field-label { display: block; margin-bottom: 4px; color: #918a83; font-size: 9.92px; font-weight: 650; }
  .card-tracking button:not(.sync-one) { padding: 0; display: flex; align-items: center; gap: 6px; border: 0; background: transparent; color: #3d3834; font-family: ui-monospace,SFMono-Regular,Menlo,monospace; font-size: 12.13px; }
  .card-tracking small { display: block; margin-top: 4px; color: #9d958e; font-size: 9.92px; }
  .sync-one { width: 32px; height: 32px; flex: 0 0 auto; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: #857c73; }
  .mobile-status-row { display: grid; grid-template-columns: 1fr 1.3fr; gap: 14px; padding: 14px 2px 12px; }
  .mobile-status-row .tracking-state strong { white-space: normal; font-size: 12.13px; }
  .mobile-status-row small { display: block; margin: 4px 0 0 14px; color: #a09890; font-size: 8.82px; }
  .card-actions { padding-top: 11px; border-top: 1px solid #eeeae6; display: flex; gap: 7px; }
  .card-actions select { flex: 1; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: #625b55; font-size: 12.13px; }
  .delete-mobile { padding: 0 9px; display: flex; align-items: center; gap: 4px; color: #a95b56; background: #fbf2f1; border: 0; border-radius: 9px; font-size: 11.03px; }
  .state-box,.loading-list { min-height: 300px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
  .fab { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 40; width: 52px; height: 52px; display: grid; place-items: center; color: #fff; background: var(--brand); border: 0; border-radius: 17px; box-shadow: 0 12px 30px rgba(72,62,53,.28); }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { width: 100%; max-height: 91vh; border-radius: 20px 20px 0 0; }
  .modal-header { padding: 19px 18px 15px; }
  .form-grid { padding: 18px; grid-template-columns: 1fr; gap: 14px; }
  .field-wide { grid-column: auto; }
  .modal-actions { position: sticky; bottom: 0; padding: 13px 18px calc(13px + env(safe-area-inset-bottom)); background: #fff; }
  .modal-actions .button-primary { flex: 1; }
  .toast { bottom: 82px; max-width: calc(100% - 32px); white-space: nowrap; }
  .login-card { padding: 27px 22px; }
}

@media (prefers-reduced-motion:reduce) {
  *,*::before,*::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
