/* Taobao Sourcing Assistant — Legion palette:
   near-black + cream + gold, Fraunces serif display, Helvetica/Neue-Haas body,
   sharp corners, editorial restraint. Mobile-first; built for a phone in the field. */
:root {
  --bg: #0d0d0d;
  --bg-2: #111110;
  --panel: #171614;
  --panel-2: #1d1b18;
  --line: #2b2824;
  --cream: #ece9e2;
  --muted: #a8a59d;
  --gold: #c8a25c;
  --gold-bright: #d8b06a;
  --gold-dim: #8f7440;
  --red: #e0342a;
  --ok: #6fb56f;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Neue Haas Grotesk Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: radial-gradient(140% 60% at 50% -10%, #1a1814 0%, var(--bg) 55%);
}

.hidden { display: none !important; }

/* Visually hidden but still rendered — file inputs must NOT be display:none or
   some mobile browsers won't open the picker on a programmatic click. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 13, 13, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 34px; height: 34px; color: var(--gold); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name {
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 5px;
  color: var(--gold);
  text-transform: uppercase;
}
.brand-sub {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 3px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 10px var(--gold);
}

/* ---- Main ---- */
.main { flex: 1; padding: 18px 16px 8px; }
.intro {
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
  margin: 0 0 16px;
}
.intro strong { color: var(--cream); font-weight: 600; }

/* ---- How-to-use panel ---- */
.help {
  border: 1px solid var(--line);
  background: var(--panel);
  margin-bottom: 16px;
}
.help summary {
  cursor: pointer;
  list-style: none;
  padding: 13px 15px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.help summary::-webkit-details-marker { display: none; }
.help summary::after { content: "+"; font-size: 19px; color: var(--muted); line-height: 1; }
.help[open] summary::after { content: "\2013"; }
.help-body { padding: 2px 16px 16px; }
.help-steps { margin: 0 0 14px; padding-left: 22px; }
.help-steps li {
  font-size: 14px;
  line-height: 1.6;
  color: var(--cream);
  margin-bottom: 9px;
}
.help-steps strong,
.help-notes strong { color: var(--cream); }
.help .cn { font-size: 15px; color: var(--gold-bright); }
.help-tip {
  border-left: 2px solid var(--gold);
  background: var(--panel-2);
  padding: 11px 14px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
  margin-bottom: 14px;
}
.help-tip-label {
  display: block;
  color: var(--gold-bright);
  font-weight: 600;
  margin-bottom: 3px;
}
.help-tip em { color: var(--cream); font-style: italic; }
.help-notes { margin: 0; padding-left: 22px; }
.help-notes li {
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  margin-bottom: 6px;
}

/* ---- Password gate ---- */
.gate { display: flex; flex-direction: column; gap: 10px; padding: 24px 0; }
.gate-input {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 0;
}
.gate-input:focus { outline: none; border-color: var(--gold-dim); }
.gate-msg { font-size: 13px; color: var(--red); min-height: 18px; }

/* ---- Composer ---- */
.input {
  width: 100%;
  padding: 14px;
  font-size: 16px; /* >=16px stops iOS zoom-on-focus */
  line-height: 1.5;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 0;
  resize: vertical;
  font-family: var(--sans);
}
.input:focus { outline: none; border-color: var(--gold-dim); }
.input::placeholder { color: #6d6a63; }

.actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.primary-btn {
  flex: 1;
  min-width: 160px;
  padding: 14px 18px;
  background: var(--gold);
  color: #16130d;
  border: none;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
}
.primary-btn:active { background: var(--gold-bright); }
.primary-btn:disabled { opacity: 0.5; cursor: default; }
.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 14px 16px;
  background: transparent;
  color: var(--cream);
  border: 1px solid var(--line);
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn svg { width: 18px; height: 18px; }
.ghost-btn:active { border-color: var(--gold-dim); }

/* Voice button while listening */
.ghost-btn.recording {
  border-color: var(--red);
  color: var(--red);
}
.ghost-btn.recording svg { animation: micpulse 1s ease-in-out infinite; }
@keyframes micpulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---- Attachments ---- */
.attachments {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.attach {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 8px 10px;
}
.attach-thumb {
  width: 38px; height: 38px;
  object-fit: cover;
  border: 1px solid var(--line);
  flex: none;
}
.attach-icon {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2);
  color: var(--gold);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  flex: none;
}
.attach-meta { flex: 1; min-width: 0; }
.attach-name {
  font-size: 13px;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.attach-sub.working { color: var(--gold-bright); }
.attach-sub.err { color: var(--red); }
.attach-clear {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.attach-clear:active { color: var(--red); border-color: var(--red); }

/* ---- Results ---- */
/* ---- Results toolbar (export) ---- */
.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}
.results-count {
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}
.results-bar .ghost-btn { padding: 11px 14px; font-size: 13px; }
.results-bar .ghost-btn .spinner { margin-right: 6px; }

.results { margin-top: 16px; display: flex; flex-direction: column; gap: 16px; }

/* Mobile-first: big image on top (full width), content below — keeps the large
   Chinese text on one line. On wider screens it flips to an image-left column. */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--gold);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.card-body {
  min-width: 0;
  padding: 16px 16px 18px;
}

/* Product image — taps through to full image results */
.card-thumb {
  display: block;
  text-decoration: none;
  width: 100%;
  height: 220px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  overflow: hidden;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-thumb.thumb-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 220px;
}
.thumb-fb {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--gold-bright);
  text-align: center;
  line-height: 1.5;
}

@media (min-width: 560px) {
  .card { flex-direction: row; align-items: stretch; }
  .card-body { flex: 1; }
  .card-thumb {
    flex: none;
    width: 38%;
    max-width: 230px;
    min-width: 160px;
    height: auto;
    align-self: stretch;
    border-bottom: none;
    border-right: 1px solid var(--line);
  }
  .card-thumb img { min-height: 188px; }
  .card-thumb.thumb-fallback { height: auto; min-height: 188px; }
}
/* Card header: number badge + part name */
.card-head {
  display: flex;
  align-items: baseline;
  gap: 11px;
  margin: 0 0 16px;
}
.card-num {
  flex: none;
  align-self: flex-start;
  min-width: 28px;
  height: 28px;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gold);
  color: #16130d;
  font-weight: 700;
  font-size: 14px;
  border-radius: 999px;
}
.card-part {
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.35;
  color: var(--cream);
}

.field { margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 7px;
}

/* Copyable Chinese chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 12px 15px;
  margin: 0 7px 7px 0;
  max-width: 100%;
  font-size: 21px;
  line-height: 1.3;
  color: var(--cream);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}
.chip:active { border-color: var(--gold); }
.chip.copied { border-color: var(--ok); }
/* The term stays long-press-selectable so native iOS "Copy" always works as a
   fallback, even though the chip itself is a button. */
.chip .chip-text {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
.chip .copy-ic { width: 16px; height: 16px; color: var(--muted); flex: none; }
.chip.copied .copy-ic { color: var(--ok); }
.chip .alt-tag {
  font-size: 10px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted); align-self: center;
}

.specs-line { font-size: 19px; line-height: 1.7; color: var(--cream); }

.img-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  justify-content: center;
  padding: 13px;
  background: transparent;
  border: 1px solid var(--gold-dim);
  color: var(--gold-bright);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.img-btn:active { background: rgba(200, 162, 92, 0.1); }
.img-btn svg { width: 16px; height: 16px; }

.notes {
  font-size: 15px;
  line-height: 1.6;
  color: var(--muted);
}
.notes strong { color: var(--cream); }

/* Raw-markdown fallback (if a part block doesn't parse cleanly) */
.raw { font-size: 16px; line-height: 1.65; color: var(--cream); }
.raw a { color: var(--gold-bright); }

/* ---- Skeleton (loading) cards ---- */
.card.skeleton { pointer-events: none; }
.skeleton .card-thumb { min-height: 188px; border-right-color: var(--line); }
.skeleton .card-thumb,
.sk-line,
.sk-chip {
  background: linear-gradient(90deg, var(--panel-2) 25%, #2a2823 37%, var(--panel-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}
.sk-line { height: 14px; border-radius: 3px; margin-bottom: 13px; }
.sk-line.lg { height: 22px; width: 70%; margin-bottom: 18px; }
.sk-line.w35 { width: 35%; }
.sk-line.w55 { width: 55%; }
.sk-line.w40 { width: 40%; }
.sk-chip { height: 46px; width: 62%; border-radius: 2px; margin-bottom: 16px; }

/* Status / spinner */
.status {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 14px;
}
.status.err { color: var(--red); }
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--gold);
  color: #16130d;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Footer ---- */
.foot {
  text-align: center;
  font-size: 11px;
  color: #6d6a63;
  padding: 16px;
  line-height: 1.5;
}
