:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f172a;
  --accent: #2563eb;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--brand); color: #fff;
  display: flex; align-items: center; gap: 4px; padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.topbar .title { font-weight: 700; margin-right: auto; font-size: 17px; }
.topbar nav { display: flex; gap: 2px; flex-wrap: wrap; }
.topbar nav button {
  background: transparent; color: #cbd5e1; border: 0; padding: 8px 10px; border-radius: 8px;
  font-size: 14px; cursor: pointer;
}
.topbar nav button.active { background: rgba(255,255,255,.14); color: #fff; }
.wrap { max-width: 920px; margin: 0 auto; padding: 14px; padding-bottom: 60px; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2, .card h3 { margin: 0 0 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }

/* buttons & inputs */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 13px; border-radius: 10px;
}
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { border-color: transparent; background: transparent; }
button.danger { color: var(--bad); border-color: #fecaca; background: #fef2f2; }
button.icon { padding: 7px 9px; line-height: 1; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  color: var(--ink); width: 100%;
}
textarea { min-height: 120px; resize: vertical; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }

/* badges */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: #eef2ff; color: #3730a3; }
.badge.TAOBAO, .badge.TMALL { background: #fff1f0; color: #cf1322; }
.badge.WEIDIAN { background: #fff7e6; color: #ad6800; }
.badge.YUPOO { background: #f0f5ff; color: #1d39c4; }
.badge.UNKNOWN { background: #f1f5f9; color: #64748b; }
.badge.aperto { background: #dcfce7; color: #166534; }
.badge.chiuso { background: #e2e8f0; color: #475569; }
.o.closed { opacity: .55; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); }
.pill.paid { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.pill.due { background: #fef9c3; color: #854d0e; border-color: #fde68a; }

/* order list */
.olist { display: grid; gap: 10px; }
.olist .o { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.olist .o .n { font-weight: 600; }
.tot { font-variant-numeric: tabular-nums; font-weight: 700; }
.tot.big { font-size: 22px; }

/* person card */
.person > .phead { display: flex; align-items: center; gap: 8px; }
.person .pname { font-size: 18px; font-weight: 700; }
.adv { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.adv[hidden] { display: none; }

/* items table */
.items { display: grid; gap: 8px; margin-top: 6px; }
.item {
  display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #fcfdff;
  grid-template-columns: 1fr;
}
.item .line1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item .grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.item .grid .full { grid-column: 1 / -1; }
.item .itemeur { font-weight: 700; font-size: 14px; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.linkline { word-break: break-all; font-size: 13px; }

/* totals strip */
.totstrip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.totstrip .b { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 8px; text-align: center; }
.totstrip .b .k { font-size: 11px; color: var(--muted); }
.totstrip .b .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.totstrip .b.tot { background: #eff6ff; border-color: #bfdbfe; }
.totstrip .b.tot .v { font-size: 17px; }
.totstrip .b .split { margin-top: 2px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pay { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }

.toggle { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.toggle input { width: auto; }

.center { min-height: 70vh; display: grid; place-items: center; }
.login { width: 100%; max-width: 340px; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: .95; }

/* riga compatta persona + fisarmonica */
.prow { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.prow .pname { font-size: 17px; font-weight: 700; }
.prow .tot { font-size: 16px; }
.caret { width: 14px; color: var(--muted); }
.person.open { border-color: #c7d2fe; box-shadow: 0 1px 0 #c7d2fe inset; }
.pdetail { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.pdetail[hidden] { display: none; }
.addbar { display: flex; gap: 8px; margin-top: 10px; }
.addbar input { flex: 1; }

/* modale */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; padding: 16px; z-index: 100; }
.modal { background: #fff; border-radius: 14px; padding: 16px; width: 100%; max-width: 560px; max-height: 85vh; overflow: auto; }
.modal textarea { min-height: 240px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

@media (min-width: 620px) {
  .item { grid-template-columns: 1fr; }
  .item .grid { grid-template-columns: repeat(4, 1fr); }
}
