/* China Purchase Portal — palette follows Synapse Commerce (violet primary, slate neutrals). No web fonts:
   Google Fonts and most CDNs are unreliable from mainland China, so only system fonts are used. */
:root {
  --primary: #7c3aed; --primary-2: #8b5cf6; --primary-soft: #f3efff; --primary-ink: #5b21b6;
  --bg: #f6f7fb; --surface: #ffffff; --surface-2: #f8fafc; --border: #e5e7eb; --border-2: #d1d5db;
  --text: #0f172a; --text-2: #475569; --muted: #64748b;
  --ok: #059669; --ok-soft: #ecfdf5; --warn: #b45309; --warn-soft: #fffbeb; --danger: #dc2626; --danger-soft: #fef2f2;
  --info: #2563eb; --info-soft: #eff6ff;
  --sidebar: #0f172a; --sidebar-2: #1e293b; --sidebar-text: #cbd5e1;
  --radius: 12px; --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px -8px rgba(15, 23, 42, .12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", Roboto, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #8b5cf6; --primary-2: #a78bfa; --primary-soft: rgba(139, 92, 246, .14); --primary-ink: #c4b5fd;
    --bg: #020617; --surface: #0f172a; --surface-2: #111c33; --border: rgba(255, 255, 255, .08); --border-2: rgba(255, 255, 255, .16);
    --text: #f1f5f9; --text-2: #cbd5e1; --muted: #94a3b8;
    --ok: #34d399; --ok-soft: rgba(16, 185, 129, .12); --warn: #fbbf24; --warn-soft: rgba(245, 158, 11, .12);
    --danger: #f87171; --danger-soft: rgba(239, 68, 68, .12); --info: #93c5fd; --info-soft: rgba(59, 130, 246, .14);
    --sidebar: #020617; --sidebar-2: #0f172a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h2, h3, h4 { margin: 0 0 .75rem; line-height: 1.25; }
h3 { font-size: 16px; }
h4 { font-size: 13px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; margin-top: 1rem; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: var(--mono); font-size: 12.5px; }
.pre { white-space: pre-wrap; } .nowrap { white-space: nowrap; } .center { text-align: center; justify-content: center; }
.text-ok { color: var(--ok); } .text-warn { color: var(--warn); } .text-danger { color: var(--danger); }

/* ---- shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex: none; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; color: #fff; text-decoration: none !important; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #d946ef); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text small { color: #94a3b8; font-size: 11px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 8px; flex: 1; overflow-y: auto; }
.sidebar nav a { color: var(--sidebar-text); padding: 9px 12px; border-radius: 9px; display: flex; gap: 10px; align-items: center; text-decoration: none; }
.sidebar nav a:hover { background: var(--sidebar-2); color: #fff; }
.sidebar nav a.active { background: rgba(139, 92, 246, .18); color: #fff; box-shadow: inset 2px 0 0 #8b5cf6; }
.ico { width: 18px; text-align: center; opacity: .8; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .06); display: flex; flex-direction: column; gap: 6px; }
.me { display: flex; gap: 10px; align-items: center; color: #e2e8f0; text-decoration: none !important; }
.me small { display: block; color: #94a3b8; font-size: 11px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #334155; display: grid; place-items: center; font-weight: 700; flex: none; }
.sidebar .link-btn { color: #94a3b8; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.page-title { font-size: 18px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; font-size: 18px; color: var(--text); cursor: pointer; }
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.lang-switch a { padding: 4px 12px; color: var(--muted); font-size: 12px; text-decoration: none; }
.lang-switch a.on { background: var(--primary); color: #fff; }
.content { padding: 20px 24px 48px; max-width: 1320px; width: 100%; }

/* ---- cards & layout ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.narrow { max-width: 560px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h3 { margin: 0; }
.table-card { padding: 0; overflow-x: auto; }
.table-card > h3 { padding: 16px 20px 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-2.tight { gap: 10px; }
.span-2 { grid-column: span 2; } .span-3 { grid-column: 1 / -1; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card, .grid-2 + .danger-zone, form > .grid-2 { margin-bottom: 16px; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-row { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.crumbs { margin-bottom: 10px; font-size: 13px; }
.spacer { flex: 1; }
.inline-right { display: flex; justify-content: flex-end; margin: -8px 0 12px; }

/* ---- stats ---- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-row.compact { margin: 14px 0 0; }
.content > .stat-row.compact { margin: 0 0 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: flex; flex-direction: column; color: var(--text); text-decoration: none !important; box-shadow: var(--shadow); }
.stat-row.compact .stat { box-shadow: none; background: var(--surface-2); }
.stat-n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-l { color: var(--muted); font-size: 12px; }
a.stat:hover { border-color: var(--primary-2); }
.stat.on { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ---- tables ---- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { border-top: 1px solid var(--border-2); border-bottom: 0; background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.card:not(.table-card) .table { margin: 0 -4px; width: calc(100% + 8px); }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--primary-soft); }
tr.inactive td { opacity: .5; }
.thumb { width: 52px; }
.thumb img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; background: var(--surface-2); }
.table-scroll { overflow-x: auto; }

/* ---- badges ---- */
.badge, .pill, .stage { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge-ok { background: var(--ok-soft); color: var(--ok); } .badge-info { background: var(--info-soft); color: var(--info); }
.badge-warn { background: var(--warn-soft); color: var(--warn); } .badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.pill-new { background: #fdf2f8; color: #be185d; margin-left: 6px; } .pill-ok { background: var(--ok-soft); color: var(--ok); }
.stage-new { background: #fdf2f8; color: #be185d; } .stage-confirmed { background: var(--info-soft); color: var(--info); }
.stage-packing, .stage-preparing { background: var(--warn-soft); color: var(--warn); } .stage-shipped { background: var(--primary-soft); color: var(--primary-ink); }
.stage-received { background: var(--ok-soft); color: var(--ok); }
@media (prefers-color-scheme: dark) { .pill-new, .stage-new { background: rgba(236, 72, 153, .14); color: #f9a8d4; } }

/* ---- forms ---- */
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); font-weight: 500; margin-bottom: 10px; }
.form fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-2); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-2); box-shadow: 0 0 0 3px var(--primary-soft); }
input:disabled, select:disabled, textarea:disabled, fieldset:disabled input, fieldset:disabled textarea { background: var(--surface-2); color: var(--text-2); }
input[type=checkbox] { width: auto; accent-color: var(--primary); }
input[type=file] { padding: 5px; }
textarea.mono { font-family: var(--mono); }
label.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; color: var(--text) !important; }
.check-row { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-bottom: 8px; }
.priv-list { display: grid; grid-template-columns: 1fr; gap: 0; }
.priv-list label.check { margin-bottom: 6px; }
.supplier-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 2px 16px; max-height: 360px; overflow-y: auto; padding: 8px 2px; }
.supplier-filter { max-width: 320px; margin-bottom: 6px; }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; }
.filters input[type=search] { flex: 1 1 240px; width: auto; }
.filters select { width: auto; }
.upload-row { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.upload-row input[type=file] { width: auto; flex: 1 1 260px; }
details.edit-box { margin-top: 14px; border-top: 1px dashed var(--border-2); padding-top: 12px; }
details > summary { cursor: pointer; color: var(--primary); font-weight: 600; margin-bottom: 10px; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 9px; border: 1px solid var(--border-2);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { border-color: var(--primary-2); color: var(--primary); }
.btn-primary { background: linear-gradient(135deg, #7c3aed, #8b5cf6); border-color: transparent; color: #fff; box-shadow: 0 6px 16px -8px rgba(124, 58, 237, .7); }
.btn-primary:hover { color: #fff; filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; padding: 10px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.link-btn.danger { color: var(--danger); }
.danger-zone { margin-top: 8px; }

/* ---- alerts & notes ---- */
.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid transparent; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: rgba(5, 150, 105, .25); }
.alert-err { background: var(--danger-soft); color: var(--danger); border-color: rgba(220, 38, 38, .25); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(180, 83, 9, .25); }
.note { background: var(--warn-soft); border-radius: 10px; padding: 10px 14px; margin-top: 12px; }
.empty { text-align: center; padding: 40px 20px; }

/* ---- PO page ---- */
.po-head-main { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.po-number { font-size: 22px; font-weight: 800; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.po-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 14px 0 0; }
.kv dt { color: var(--muted); font-size: 12.5px; } .kv dd { margin: 0; }
.kv-grid { grid-template-columns: repeat(4, max-content minmax(0, 1fr)); }
.tabs { display: flex; gap: 4px; margin: 16px -20px -18px; padding: 0 14px; border-top: 1px solid var(--border); overflow-x: auto; }
.tabs a { padding: 10px 10px; color: var(--text-2); font-weight: 600; font-size: 13px; white-space: nowrap; text-decoration: none; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--primary); border-bottom-color: var(--primary-2); }
.address { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.mark-preview { font-family: var(--mono); white-space: pre-wrap; border: 2px dashed var(--border-2); border-radius: 10px; padding: 14px 16px; font-weight: 700; line-height: 1.6; background: var(--surface-2); }
.files { list-style: none; padding: 0; margin: 10px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.files li { border: 1px solid var(--border); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 4px; background: var(--surface-2); }
.files a { display: flex; flex-direction: column; gap: 6px; color: var(--text); min-width: 0; }
.files img { width: 100%; height: 110px; object-fit: cover; border-radius: 6px; }
.file-ico { height: 110px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-ink); border-radius: 6px; font-weight: 800; }
.file-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px dashed var(--border); }

/* ---- totals + shipment picker ---- */
.table tr.totals-row td { background: var(--primary-soft); border-top: 2px solid var(--border-2); }
.ship-picker .pick-qty { width: 90px; text-align: right; padding: 5px 8px; }
.ship-picker .pick-qty.over { border-color: var(--warn); background: var(--warn-soft); }
.ship-picker input[type=checkbox] { width: 16px; height: 16px; }

/* ---- packing editor ---- */
.packing-table input { padding: 5px 6px; font-size: 13px; }
.packing-table select { padding: 5px 6px; font-size: 13px; min-width: 120px; }
.packing-table .pk-qpc, .packing-table .pk-cnt { width: 70px; }
.packing-table .pk-nw, .packing-table .pk-gw { width: 76px; }
.packing-table .pk-desc { min-width: 170px; }
.packing-table td { padding: 6px 6px; }
.packing-table input.num { text-align: right; }
.dims { display: flex; gap: 3px; }
.dims input { width: 54px; text-align: right; }
.cno { white-space: nowrap; color: var(--muted); }
.pk-check { margin: 10px 0; font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.pk-check span { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 3px 8px; }
.pk-check span.over { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pk-check span.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* ---- auth ---- */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, rgba(139, 92, 246, .25), transparent), radial-gradient(900px 500px at 110% 110%, rgba(217, 70, 239, .18), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px; box-shadow: 0 24px 60px -24px rgba(15, 23, 42, .35); }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.auth-brand small { display: block; color: var(--muted); font-size: 12px; }
.auth-card .lang-switch { margin-top: 18px; display: flex; width: max-content; margin-left: auto; margin-right: auto; }

/* ---- responsive ---- */
@media (max-width: 1100px) { .kv-grid { grid-template-columns: max-content 1fr max-content 1fr; } }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(2, 6, 23, .5); }
  .menu-btn { display: inline-block; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .kv-grid { grid-template-columns: max-content 1fr; }
  .content { padding: 14px 12px 40px; }
  .topbar { padding: 10px 12px; }
  .tabs { margin: 16px -20px -18px; }
}
