:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --ink: #2f2a25;
  --ink-soft: #6b6259;
  --border: #e8ddd0;
  --accent-betamek: #3d7ea6;
  --accent-betamek-bg: #e7f1f7;
  --accent-ichikoh: #d97b3f;
  --accent-ichikoh-bg: #fbeee1;
  --accent-other: #7a7367;
  --accent-other-bg: #ece8e1;
  --ok: #4f9f6e;
  --ok-bg: #e7f5ec;
  --low: #d3a325;
  --low-bg: #fbf3dc;
  --used: #b0a89c;
  --used-bg: #eeeae3;
  --danger: #c2483b;
  --radius: 18px;
  --shadow: 0 2px 10px rgba(60, 45, 25, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --surface: #262320;
    --ink: #f1ece4;
    --ink-soft: #b8afa2;
    --border: #3a352e;
    --accent-betamek-bg: #1f3240;
    --accent-ichikoh-bg: #3a2a1c;
    --ok-bg: #1e3327;
    --low-bg: #362d15;
    --used-bg: #2c2924;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 18px;
  line-height: 1.4;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 1.3rem;
  margin: 0;
}

.btn-back {
  border: none;
  background: var(--accent-other-bg);
  color: var(--ink);
  font-size: 1rem;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px;
}

.hint {
  color: var(--ink-soft);
  font-size: 1.1rem;
  margin: 4px 0 20px;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.tile {
  border: none;
  border-radius: var(--radius);
  padding: 28px 20px;
  font-size: 1.25rem;
  font-weight: 600;
  min-height: 88px;
  cursor: pointer;
  box-shadow: var(--shadow);
  text-align: left;
  color: var(--ink);
}

.tile.customer-betamek { background: var(--accent-betamek-bg); border-left: 8px solid var(--accent-betamek); }
.tile.customer-ichikoh { background: var(--accent-ichikoh-bg); border-left: 8px solid var(--accent-ichikoh); }
.tile.customer-other   { background: var(--accent-other-bg);   border-left: 8px solid var(--accent-other); }
.tile.part-name        { background: var(--surface); border: 1px solid var(--border); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.stock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stock-card[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.stock-card .batch-id {
  font-weight: 700;
  font-size: 1.1rem;
}

.stock-card .field-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.stock-card .field-row b { color: var(--ink); font-weight: 600; }

.status-badge {
  align-self: flex-start;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 6px;
}

.status-ok   { background: var(--ok-bg);   color: var(--ok); }
.status-low  { background: var(--low-bg);  color: var(--low); }
.status-used { background: var(--used-bg); color: var(--ink-soft); }

.form-card, .confirm-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 28px;
  max-width: 520px;
  margin: 0 auto;
}

.form-card-summary {
  background: var(--accent-other-bg);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 20px;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.field {
  display: block;
  margin-bottom: 18px;
}

.field span {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

.field select, .field input {
  width: 100%;
  font-size: 1.1rem;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  min-height: 48px;
}

.btn-primary {
  background: var(--accent-betamek);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}

.btn-large { min-height: 56px; }

.form-error {
  color: var(--danger);
  font-weight: 600;
  margin-bottom: 14px;
}

.confirm-card { text-align: center; }

.confirm-label {
  font-size: 1.1rem;
  color: var(--ink-soft);
  margin-bottom: 18px;
}

.confirm-code {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  background: var(--ok-bg);
  color: var(--ok);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.error-text { color: var(--danger); }

.view[hidden] { display: none; }
