:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --info: #06b6d4;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
  flex-shrink: 0;
}
.sidebar .brand {
  padding: 0 1.25rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.sidebar .brand h1 { font-size: 1.1rem; font-weight: 700; }
.sidebar .brand span { color: var(--muted); font-size: 0.75rem; }
.sidebar nav a {
  display: block;
  padding: 0.55rem 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: var(--surface2); color: var(--text); }
.sidebar nav a.active {
  color: var(--text);
  background: var(--surface2);
  border-left-color: var(--accent);
}
.sidebar .foot {
  margin-top: auto;
  padding: 1rem 1.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.main { flex: 1; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar h2 { font-size: 1.15rem; }
.content { padding: 1.5rem; flex: 1; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}
.card .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.card .value { font-size: 1.75rem; font-weight: 700; margin-top: 0.25rem; }
.card .value.ok { color: var(--ok); }
.card .value.warn { color: var(--warn); }
.card .value.bad { color: var(--bad); }
.card .value.info { color: var(--info); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.panel h3 {
  font-size: 0.95rem;
  margin-bottom: 1rem;
  color: var(--muted);
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
th, td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: var(--surface2); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge.returned, .badge.expected, .badge.pending { background: #334155; color: #cbd5e1; }
.badge.received, .badge.inspecting { background: #1e3a5f; color: #93c5fd; }
.badge.available, .badge.pass, .badge.done, .badge.processed, .badge.closed { background: #14532d; color: #86efac; }
.badge.quarantine, .badge.fail, .badge.repair { background: #7f1d1d; color: #fca5a5; }
.badge.shipped { background: #164e63; color: #67e8f9; }

.btn {
  display: inline-block;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:disabled, .btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.btn.sm { padding: 0.25rem 0.55rem; font-size: 0.75rem; }
.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn.ok { background: var(--ok); }
.btn.warn { background: var(--warn); color: #111; }
.btn.bad { background: var(--bad); }
.btn.ghost.bad {
  background: transparent;
  border-color: var(--bad);
  color: var(--bad);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  align-items: end;
}
label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}
input, select, textarea {
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* native date/month picker (dropship day filters + month filters) */
html { color-scheme: dark; }
input[type="date"].date-input,
input[type="date"],
input[type="month"].date-input,
input[type="month"] {
  min-width: 11.5rem;
  color-scheme: dark;
  cursor: pointer;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 1;
  filter: invert(0.85);
}
.filters { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: end; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1a2740 0%, var(--bg) 60%);
}
.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
}
.login-box h1 { font-size: 1.4rem; margin-bottom: 0.25rem; }
.login-box .sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 1.5rem; }
.login-box label { margin-bottom: 0.85rem; }
.login-box .btn { width: 100%; padding: 0.65rem; margin-top: 0.5rem; }
.error {
  background: #7f1d1d;
  color: #fecaca;
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.hint { color: var(--muted); font-size: 0.75rem; margin-top: 1rem; text-align: center; }

.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.muted { color: var(--muted); }
.zh { color: var(--muted); font-size: 0.8em; }

@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar nav { display: flex; flex-wrap: wrap; }
  .sidebar nav a { border-left: none; border-bottom: 2px solid transparent; }
  .sidebar nav a.active { border-bottom-color: var(--accent); }
}

.card .n { font-size: 1.75rem; font-weight: 700; margin-top: 0.25rem; }
.card .l { font-size: 0.75rem; color: var(--muted); }
.badge.disposed, .badge.qc_done { background: #7f1d1d; color: #fca5a5; }
.badge.open, .badge.qc_ready, .badge.draft { background: #1e3a5f; color: #93c5fd; }
.badge.submitted { background: #14532d; color: #86efac; }

/* QC batch form: inbound select needs full panel width for long option text */
.qc-inbound-field {
  grid-column: 1 / -1;
}
.qc-inbound-select {
  width: 100%;
  min-width: 28rem;
  box-sizing: border-box;
}

/* Inventory photo links */
.photo-cell { min-width: 9rem; }
.photo-links { display: flex; flex-wrap: wrap; gap: 0.35rem 0.5rem; align-items: center; }
.photo-item { display: inline-flex; align-items: center; gap: 0.15rem; }
.photo-upload { margin-top: 0.35rem; display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.photo-upload input[type=file] { font-size: 0.7rem; max-width: 10rem; }

/* QC piece photo drop zone (drag / paste / click) */
.piece-photo-field {
  grid-column: 1 / -1;
}
.piece-photo-label {
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
}
.piece-photo-drop {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 0.65rem 0.75rem;
  min-height: 4.5rem;
  cursor: pointer;
  position: relative;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.piece-photo-drop:hover,
.piece-photo-drop.is-active {
  border-color: var(--accent);
}
.piece-photo-drop.is-dragover {
  border-color: var(--ok);
  background: rgba(34, 197, 94, 0.08);
}
.piece-photo-drop:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}
.piece-photo-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}
.piece-photo-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.35rem;
}
.piece-photo-thumbs:empty {
  display: none;
  margin: 0;
}
.piece-photo-thumb {
  position: relative;
  width: 64px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  text-align: center;
}
.piece-photo-thumb img {
  display: block;
  width: 64px;
  height: 48px;
  object-fit: cover;
  background: #111;
}
.piece-photo-name {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
  padding: 0.15rem 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.piece-photo-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.piece-photo-remove:hover {
  background: var(--bad);
}
.piece-photo-hint {
  font-size: 0.8rem;
  line-height: 1.35;
}


/* Dropship flash messages */
.flash { padding: 0.65rem 0.9rem; border-radius: 6px; margin-bottom: 0.75rem; }
.flash.ok { background: rgba(34,197,94,0.15); color: var(--ok, #16a34a); border: 1px solid rgba(34,197,94,0.35); }
.flash.err { background: rgba(239,68,68,0.12); color: var(--bad, #dc2626); border: 1px solid rgba(239,68,68,0.35); }
.btn.danger { background: var(--bad, #dc2626); }

/* Scan-to-label: vertical remaining SKU box (0.4.13) */
.scan-remaining-panel h3 { margin-bottom: 0.35rem; }
.scan-remaining-meta { margin-bottom: 0.65rem; font-size: 0.9rem; }
.scan-remaining-box {
  border: 2px solid var(--accent, #3b82f6);
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.08);
  padding: 0.85rem 1.1rem;
  max-width: 28rem;
}
.scan-remaining-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.scan-remaining-list li {
  display: block;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.scan-remaining-list li:last-child { border-bottom: none; padding-bottom: 0; }
.scan-remaining-list li:first-child { padding-top: 0; }

/* Portal dropship: paste recipient block parser */
.paste-block {
  margin-bottom: 0.25rem;
  padding: 0.85rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
}
.paste-block textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 5.5rem;
  resize: vertical;
  margin-top: 0.35rem;
}
.paste-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-top: 0.55rem;
}
.parse-hint {
  margin: 0.55rem 0 0;
  font-size: 0.8rem;
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
}
.parse-hint-ok {
  background: rgba(34,197,94,0.12);
  color: var(--ok, #16a34a);
  border: 1px solid rgba(34,197,94,0.3);
}
.parse-hint-warn {
  background: rgba(234,179,8,0.12);
  color: var(--warn, #ca8a04);
  border: 1px solid rgba(234,179,8,0.35);
}

/* Portal dropship: bilingual help + stock search */
.help-bilingual p { margin: 0.35rem 0; font-size: 0.9rem; line-height: 1.45; }
.stock-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}
.stock-search-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  flex: 1 1 220px;
  max-width: 420px;
}
.stock-search-label input[type=search] {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
.stock-table-wrap {
  max-height: 28rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.stock-table-wrap table { margin: 0; }
.stock-table-wrap thead th {
  position: sticky;
  top: 0;
  background: var(--surface2);
  z-index: 1;
}

/* Customers page (0.4.17) */
.flash-ok {
  border-left: 3px solid var(--ok);
}
.flash-err {
  border-left: 3px solid var(--bad);
}
.sec-zh { color: var(--text); font-weight: 600; }
.sec-en { color: var(--muted); font-weight: 500; font-size: 0.9em; }
.sec-sep { color: var(--border); margin: 0 0.25rem; }
.hint-quiet {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
  font-weight: 400;
}
.hint-quiet .hint-label {
  display: inline;
  font-weight: 600;
  color: var(--muted);
  margin-right: 0.25rem;
}
.hint-quiet p { margin: 0 0 0.35rem; }
.hint-quiet p:last-child { margin-bottom: 0; }
.customers-rules {
  margin: 0 0 1rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
}
.customers-add-form .form-actions {
  display: flex;
  align-items: flex-end;
  padding-bottom: 0.1rem;
}
.customers-footer { margin-top: 1rem; }

.customer-cards {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.customer-card {
  display: grid;
  grid-template-columns: minmax(12rem, 1.1fr) minmax(16rem, 1.6fr) auto;
  gap: 1rem 1.25rem;
  align-items: start;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.customer-card:hover {
  border-color: #3d4f6a;
}
.customer-id {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.25rem;
}
.customer-code {
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}
.warehouse-badge {
  background: #1e3a5f;
  color: #93c5fd;
  text-transform: uppercase;
  font-size: 0.65rem;
}
.customer-name {
  font-size: 0.95rem;
  margin-bottom: 0.2rem;
}
.customer-meta { margin-bottom: 0.45rem; }
.customer-login-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
}
.customer-login-status code {
  font-size: 0.85rem;
  padding: 0.1rem 0.35rem;
  background: var(--surface2);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.customer-login-panel {
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.customer-login-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.55rem;
}
.login-reset-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.55rem 0.65rem;
  align-items: end;
}
.login-reset-form label { margin: 0; }
.pw-wrap {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.pw-wrap .pw-input {
  flex: 1;
  min-width: 0;
}
.login-reset-actions {
  display: flex;
  align-items: flex-end;
  padding-bottom: 0.05rem;
}
.login-hint { margin: 0.45rem 0 0; }

.customer-card-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-start;
  padding-top: 0.15rem;
}

@media (max-width: 960px) {
  .customer-card {
    grid-template-columns: 1fr;
  }
  .customer-card-actions {
    align-items: stretch;
  }
  .customer-card-actions .btn {
    width: 100%;
  }
  .login-reset-form {
    grid-template-columns: 1fr;
  }
}


/* ── Account / profile (0.4.18) ─────────────────────── */
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.1rem;
  align-items: start;
}
.account-card h3 { margin-bottom: 0.75rem; }
.account-meta { display: flex; flex-direction: column; gap: 0.55rem; }
.account-row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
}
.account-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.account-value { font-size: 0.95rem; }
.account-value code {
  font-size: 0.95rem;
  padding: 0.1rem 0.35rem;
  background: var(--surface2);
  border-radius: 4px;
  border: 1px solid var(--border);
}
.account-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.account-form label { margin: 0; }
.account-pw-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}
.account-form .form-actions {
  display: flex;
  align-items: flex-end;
  padding-top: 0.15rem;
}
.sec-zh { font-weight: 600; }
.sec-en { color: var(--muted); font-weight: 500; font-size: 0.9em; margin-left: 0.25rem; }
