:root {
  --navy: #174a78;
  --line: #cfd8e3;
  --bg: #f4f7fb;
  --panel: #fff;
  --blue: #2f6fa5;
  --red: #d62828;
  --green: #237a4b;
  --amber: #a47a15;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: #1f2937;
  font-family: "Meiryo", "Yu Gothic", Arial, sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 22px;
  color: white;
  background: var(--navy);
  box-shadow: 0 2px 8px rgba(15, 23, 42, .18);
}

.topbar h1 { margin: 0; font-size: 22px; }
.topbar p { margin: 4px 0 0; color: #dbeafe; }
.topbar a { color: white; font-weight: 700; text-decoration: none; }

.app {
  width: min(1500px, calc(100vw - 24px));
  margin: 18px auto 40px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .06);
}

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

label { display: block; font-weight: 700; margin-bottom: 6px; }
input[type="file"], input[type="number"], input[type="text"], select {
  width: 100%;
  padding: 10px;
  border: 1px solid #b8c5d6;
  border-radius: 6px;
  background: white;
  font-size: 16px;
}

button, .button {
  border: 0;
  border-radius: 6px;
  padding: 10px 16px;
  background: var(--navy);
  color: white;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

button.secondary { background: #64748b; }
button.warn { background: #b77900; }
button.green { background: #19784d; }
button:disabled { opacity: .55; cursor: not-allowed; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

.status {
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f8fafc;
  white-space: pre-wrap;
}

.factory-card {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.factory-title {
  position: sticky;
  top: 62px;
  z-index: 12;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  padding: 12px 16px;
  background: var(--navy);
  color: white;
  font-weight: 800;
}

.factory-title div:nth-child(2) { text-align: center; }
.factory-title div:nth-child(3) { text-align: right; }

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: white;
}

th, td {
  border: 1px solid var(--line);
  padding: 8px;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 110px;
  z-index: 10;
  background: #28577f;
  color: white;
  text-align: center;
}

.code { width: 160px; font-weight: 700; }
.code .tail { font-size: 28px; }
.name { width: 360px; font-weight: 700; }
.small { width: 58px; text-align: center; }
.qty { width: 150px; text-align: center; background: #f8fafc; }
.qty.has-value { background: #d8ebfc; }
.qty.alt1.has-value { background: #f8d5e2; }
.qty.alt2.has-value { background: #fff0bd; }
.total { width: 150px; text-align: center; }
.entry { width: 150px; text-align: center; background: #fffbe8; }

.ctn-box {
  display: inline-block;
  min-width: 54px;
  padding: 3px 10px;
  border: 3px solid var(--blue);
  border-radius: 6px;
  background: #fffef3;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.1;
}

.total .ctn-box { border-color: #ef4444; color: #c52525; }
.entry input {
  width: 96px;
  text-align: center;
  border: 3px solid var(--green);
  color: #087044;
  font-size: 22px;
  font-weight: 900;
  background: #f0fff7;
}

.entry.short input {
  border-color: #e11d48;
  color: #be123c;
  background: #fff1f2;
}

.sub {
  margin-top: 4px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
}

.empty { color: #cbd5e1; }

@media (max-width: 900px) and (orientation: landscape) {
  .topbar {
    position: static;
    padding: 8px 10px;
  }
  .topbar h1 { font-size: 17px; }
  .topbar p { display: none; }
  .app {
    width: max-content;
    min-width: 100vw;
    margin: 8px auto 28px;
    display: flex;
    justify-content: center;
  }
  .factory-card {
    width: max-content;
    max-width: none;
  }
  .factory-title {
    top: 0;
    grid-template-columns: 1fr 1.2fr 1fr;
    font-size: 16px;
  }
  th {
    top: 45px;
    font-size: 13px;
  }
  .small { display: none; }
  .code { width: 150px; }
  .name { width: 360px; }
  .qty, .total, .entry { width: 122px; }
}
