/* LEGO Sorteerhulp styles. Design tokens on :root, in the style of lego.com (docs/design.md). */
:root {
  --yellow: #FFCF00;
  --red: #D01012;
  --blue: #006DB7;
  --blue-dark: #00548C;
  --green: #00852B;
  --green-bg: #E6F4EA;
  --red-bg: #FDECEC;
  --ink: #141414;
  --muted: #5F5F5F;
  --line: #E0E0E0;
  --bg: #F4F4F4;
  --card: #FFFFFF;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.06);
  --tap: 44px; /* minimum touch target */
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--blue); }
img { display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 600; }
.txt-red { color: var(--red); }
.offscreen { position: fixed; left: -9999px; opacity: 0; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 16px; border-radius: 4px; border: 2px solid transparent;
  font-weight: 800; cursor: pointer; background: var(--blue); color: #fff; text-decoration: none;
  white-space: nowrap; user-select: none;
}
.btn:hover { background: var(--blue-dark); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--ink); }
.btn.secondary:hover { background: #f0f0f0; }
.btn.ghost { background: transparent; color: var(--blue); border-color: transparent; }
.btn.ghost:hover { background: rgba(0,109,183,.08); }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }

/* ===== Header ===== */
header.top {
  position: sticky; top: 0; z-index: 20; background: var(--yellow);
  padding: 0 16px; padding-top: env(safe-area-inset-top);
}
.top-inner { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -.01em; }
.brand svg { width: 34px; height: 34px; flex: none; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav button {
  background: transparent; border: 0; min-height: var(--tap); padding: 0 12px; font-weight: 800;
  border-radius: 4px; cursor: pointer; position: relative;
}
.nav button { white-space: nowrap; }
.nav button[aria-current="true"] { background: rgba(0,0,0,.1); }
.badge {
  display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 11px; background: var(--red);
  color: #fff; font-size: 13px; line-height: 22px; text-align: center; margin-left: 4px;
}
.user { display: flex; align-items: center; gap: 8px; font-size: 14px; }
#logoutBtn .ico { display: none; }
.headbar { height: 4px; margin: 0 -16px; background: rgba(0,0,0,.12); }
.headbar span { display: block; height: 100%; background: var(--green); transition: width .3s; }
.live { width: 10px; height: 10px; border-radius: 50%; background: #999; flex: none; }
.live.on { background: var(--green); box-shadow: 0 0 0 3px rgba(0,133,43,.2); }

main { max-width: 1280px; margin: 0 auto; padding: 16px; padding-bottom: 80px; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 28px; font-weight: 800; }
h2 { font-size: 22px; font-weight: 800; }

/* ===== Login ===== */
.login { max-width: 400px; margin: 10vh auto 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; }
.login h1 { margin-bottom: 4px; }
.login p { color: var(--muted); margin: 0 0 20px; }
label { display: block; font-weight: 600; font-size: 14px; margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=search], select {
  width: 100%; min-height: var(--tap); padding: 8px 12px; border: 2px solid #BDBDBD; border-radius: 4px; background: #fff;
}
input:focus, select:focus { outline: none; border-color: var(--blue); }
.login .btn { width: 100%; margin-top: 20px; }
.error { color: var(--red); font-weight: 600; margin-top: 12px; }

/* ===== Add set + set tabs ===== */
.addset { display: flex; gap: 8px; margin-bottom: 12px; }
.addset input { flex: 1; }
.settabs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: thin; }
.settab {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; min-height: 56px;
  background: var(--card); border: 2px solid transparent; border-radius: var(--radius); box-shadow: var(--shadow);
  cursor: pointer; text-align: left; max-width: 260px;
}
.settab[aria-selected="true"] { border-color: var(--ink); }
.settab img { width: 48px; height: 40px; object-fit: contain; }
.settab .t1 { font-weight: 800; font-size: 14px; }
.settab .t2 { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.minibar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.minibar span { display: block; height: 100%; background: var(--green); }

/* ===== Set header ===== */
.sethead { display: grid; grid-template-columns: 160px 1fr; gap: 20px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-top: 4px; }
.sethead .img { background: #fff; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.sethead .img img { max-width: 100%; max-height: 130px; object-fit: contain; }
.meta { color: var(--muted); margin: 4px 0 12px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.meta b { color: var(--ink); }
.progress { height: 14px; background: var(--line); border-radius: 7px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--green); transition: width .3s; }
.progress-txt { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-top: 6px; flex-wrap: wrap; }
.progress-txt b { font-size: 16px; }
.sethead .actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ===== Toolbar (filter/sort), sticky on desktop ===== */
.toolbar {
  position: sticky; top: calc(60px + env(safe-area-inset-top)); z-index: 10; background: var(--bg);
  padding: 10px 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.seg { display: flex; background: #fff; border: 2px solid var(--ink); border-radius: 4px; overflow: hidden; }
.seg button { border: 0; background: transparent; min-height: 40px; padding: 0 12px; font-weight: 600; cursor: pointer; font-size: 14px; white-space: nowrap; }
.seg button + button { border-left: 1px solid #ccc; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg small { opacity: .7; margin-left: 3px; }
.toolbar .search { flex: 1 1 200px; min-width: 160px; }
.toolbar select { width: auto; min-height: 44px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; min-height: var(--tap); margin: 0; }
.switch input { width: 20px; height: 20px; accent-color: var(--blue); }

/* ===== Parts ===== */
.parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 10px; }
.group-h { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-weight: 800; margin: 14px 0 0; font-size: 15px; }
.group-h small { color: var(--muted); font-weight: 600; }
.part {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px;
  display: grid; grid-template-columns: 76px 1fr; grid-template-rows: auto auto; gap: 8px 12px;
  border-left: 6px solid transparent; position: relative;
}
.pimg { width: 76px; height: 76px; background: #fff; border-radius: 6px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.pimg img { max-width: 92%; max-height: 92%; object-fit: contain; }
.pnum { font-weight: 800; font-size: 15px; }
.pname { font-size: 14px; color: var(--muted); line-height: 1.25; }
.pcolor { display: flex; align-items: center; gap: 6px; font-size: 14px; margin-top: 3px; }
.swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); flex: none; }
.swatch.trans { background-image: linear-gradient(135deg, rgba(255,255,255,.75) 0 35%, transparent 35% 65%, rgba(255,255,255,.75) 65%) !important; }
.who { font-size: 12px; color: var(--muted); margin-top: 3px; }
.tag { display: inline-block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; padding: 1px 6px; border-radius: 3px; margin-left: 6px; vertical-align: 2px; }
.tag.spare { background: #EEE; color: var(--muted); }
.tag.miss { background: var(--red); color: #fff; }
.tag.ok { background: var(--green); color: #fff; }
.pctrl { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.counter { display: flex; align-items: center; border: 2px solid var(--ink); border-radius: 4px; overflow: hidden; background: #fff; }
.counter button { width: 52px; height: 48px; border: 0; background: #fff; font-size: 26px; font-weight: 800; cursor: pointer; line-height: 1; }
.counter button:active { background: #e8e8e8; }
.counter button:disabled { color: #bbb; cursor: default; }
.count { min-width: 72px; text-align: center; font-size: 20px; font-weight: 800; border-left: 2px solid var(--ink); border-right: 2px solid var(--ink); line-height: 48px; font-variant-numeric: tabular-nums; }
.count small { font-size: 15px; color: var(--muted); font-weight: 600; }
.pctrl .btn { min-height: 48px; padding: 0 12px; font-size: 14px; }
.spacer { flex: 1; }
/* done style */
.part.done { background: var(--green-bg); border-left-color: var(--green); }
.part.done .pnum, .part.done .pname { text-decoration: line-through; text-decoration-thickness: 2px; }
.part.done .count { color: var(--green); }
/* missing style */
.part.missing { background: var(--red-bg); border-left-color: var(--red); }
.btn.miss-on { background: var(--red); color: #fff; border-color: var(--red); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 8px; }
.empty.full { grid-column: 1 / -1; }

/* ===== Order list ===== */
.order-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.order-head h1 { margin-right: auto; }
.order-intro { margin: -6px 0 14px; color: var(--muted); }
.page-title { margin-bottom: 14px; }
#logoutBtn { color: var(--ink); }
.orders { display: grid; gap: 10px; }
.order {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px;
  display: grid; grid-template-columns: 76px 1fr auto; gap: 8px 14px; align-items: center;
}
.order .qty { font-size: 26px; font-weight: 800; text-align: right; }
.order .qty small { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.order .links { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; }
.order .sets { font-size: 13px; color: var(--muted); margin-top: 3px; }
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.panel p { color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
textarea.out { width: 100%; min-height: 160px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; border: 2px solid #BDBDBD; border-radius: 4px; padding: 8px; margin-top: 10px; }

/* ===== Toasts ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 6px; font-weight: 600;
  z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast.err { background: var(--red); }
.busy { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
footer { text-align: center; font-size: 13px; color: var(--muted); padding: 24px 16px; }

/* ===== Phone ===== */
@media (max-width: 700px) {
  .brand span { display: none; }
  .brand svg { width: 28px; height: 28px; }
  .top-inner { gap: 6px; }
  .nav { margin-left: 0; flex: 1; justify-content: center; gap: 0; }
  .nav button { padding: 0 8px; font-size: 15px; }
  .user .name, #logoutBtn .lbl { display: none; }
  #logoutBtn { padding: 0 6px; }
  #logoutBtn .ico { display: block; }
  h1 { font-size: 22px; }
  .sethead { grid-template-columns: 90px 1fr; gap: 12px; padding: 12px; }
  .sethead .img img { max-height: 80px; }
  .parts { grid-template-columns: 1fr; }
  .toolbar { position: static; }                 /* not sticky on a phone: saves a lot of room */
  .seg { width: 100%; }
  .seg button { flex: 1; padding: 4px 2px; font-size: 13px; white-space: normal; line-height: 1.15; }
  .seg small { display: block; margin: 0; }
  .toolbar select { flex: 1; }
  .toolbar .search { flex-basis: 100%; }
  .order { grid-template-columns: 60px 1fr auto; }
  .order .pimg { width: 60px; height: 60px; }
}
