:root {
  --bg: #eef2f2;
  --surface: #fff;
  --ink: #1c2c30;
  --muted: #617276;
  --border: #d5e0e2;
  --primary: #0f6d73;
  --primary-soft: #e4f2f3;
  --ok: #2a6b45;
  --warn: #8a5a12;
  --danger: #b54a52;
  --sale: #0f6d73;
  --use: #6b4f2a;
  --shadow: 0 10px 28px rgba(20, 42, 48, 0.08);
  --font: "IBM Plex Sans JP", "DM Sans", sans-serif;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: clip;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(15, 109, 115, 0.09), transparent 42%),
    linear-gradient(180deg, #f4f7f7, var(--bg));
}
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code {
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: #eef4f4;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  display: grid;
  gap: 14px;
}

.app-header {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
  align-items: stretch;
}
.brand {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.kicker {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--primary);
}
.brand h1 {
  margin: 0 0 8px;
  font-size: clamp(1.45rem, 1.2rem + 1vw, 1.9rem);
  line-height: 1.2;
}
.sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}
.header-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  min-width: min(520px, 100%);
}
.meta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
}
.meta-card.company-pick {
  grid-column: span 1;
  align-content: start;
}
.meta-card.company-pick select {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
  color: inherit;
  width: 100%;
  max-width: 240px;
}
.meta-card span {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}
.meta-card strong {
  font-size: 1.05rem;
}

.note-banner {
  background: #fff8e8;
  border: 1px solid #ecd9a8;
  color: #6a4e16;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.88rem;
  line-height: 1.5;
}

.main-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
}
.nav-btn {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--muted);
}
.nav-btn:hover { background: #f3f7f7; color: var(--ink); }
.nav-btn.is-on {
  background: var(--primary);
  color: #fff;
}

.view-root { display: grid; gap: 14px; min-width: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}
.panel-head h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
}
.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.stat-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #f8fbfb;
  display: grid;
  gap: 4px;
}
.stat-card.is-warn { background: #fff8e8; border-color: #ecd9a8; }
.stat-card.is-danger { background: #fff1f1; border-color: #efc4c7; }
.stat-card.is-ok { background: #eef8f1; border-color: #c5e2cf; }
.stat-label { font-size: 0.78rem; color: var(--muted); font-weight: 700; }
.stat-value { font-size: 1.45rem; font-weight: 800; line-height: 1.1; }
.stat-note { font-size: 0.78rem; color: var(--muted); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.toolbar input,
.toolbar select,
.form-grid input:not([type="radio"]):not([type="checkbox"]),
.form-grid select,
.form-grid textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  background: #fff;
}
.toolbar input { min-width: 10rem; flex: 1; }
.toolbar select { min-width: 8rem; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  align-items: start;
}
.form-grid .full { grid-column: 1 / -1; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}
.field label.inline-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
  cursor: pointer;
}
.field label.inline-check input {
  width: auto;
  margin: 0.15em 0 0;
  flex: 0 0 auto;
}

.btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.88rem;
}
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn.ghost { background: transparent; }
.btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
table.data th,
table.data td {
  text-align: left;
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}
table.data tr:hover td { background: #f7fafa; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: #eef2f2;
  color: var(--muted);
}
.badge.sale { background: var(--primary-soft); color: var(--primary); }
.badge.ingredient { background: #fff1e4; color: #9a5410; }
.badge.consumable { background: #eef0ff; color: #3d4ea8; }
.badge.equipment { background: #eef4ea; color: #3e6b35; }
.badge.dual { background: #f3eaf6; color: #6e3d7d; }
.badge.low { background: #fff1f1; color: var(--danger); }
.badge.out { background: #5c1f24; color: #fff; }
.badge.ok { background: #eef8f1; color: var(--ok); }
.badge.expiring { background: #fff8e8; color: var(--warn); }
table.data tr.row-out td { background: #fff5f5; }
table.data tr.row-low td { background: #fffaf0; }
.badge.draft { background: #eef2f2; color: #5a6a6a; }
.badge.merch { background: var(--primary-soft); color: var(--primary); }
.badge.nonmerch { background: #eef0f2; color: #5a6670; }

/* 在庫履歴の区分 */
.badge.move-receive { background: #e7f6ec; color: #1f6b3a; }
.badge.move-sale { background: #e4f2f3; color: #0b5c61; }
.badge.move-use { background: #f3eee6; color: #6b4f2a; }
.badge.move-waste { background: #fdecee; color: #a33a45; }
.badge.move-adjust { background: #eef0f5; color: #4a5568; }
table.data tr.row-move-receive td { background: #f4fbf6; }
table.data tr.row-move-sale td { background: #f3fafb; }
table.data tr.row-move-use td { background: #faf7f2; }
table.data tr.row-move-waste td { background: #fff6f7; }
table.data tr.row-move-adjust td { background: #f7f8fb; }
table.data tr.row-move-receive:hover td,
table.data tr.row-move-sale:hover td,
table.data tr.row-move-use:hover td,
table.data tr.row-move-waste:hover td,
table.data tr.row-move-adjust:hover td { filter: brightness(0.985); }

.seg-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}
.seg-toggle .seg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f7fafa;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
  cursor: pointer;
  margin: 0;
  line-height: 1.3;
  text-align: center;
  user-select: none;
}
.seg-toggle .seg input[type="radio"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--primary);
}
.seg-toggle .seg.is-on {
  background: var(--primary-soft);
  border-color: #9bc6c9;
  color: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(15, 109, 115, 0.12);
}
@media (max-width: 520px) {
  .seg-toggle { grid-template-columns: 1fr; }
}

.sell-hero .panel-head { margin-bottom: 12px; }
.sell-product-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 14px;
}
.product-chip {
  display: grid;
  gap: 2px;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.product-chip strong { font-size: 0.86rem; line-height: 1.3; }
.product-chip span { color: var(--primary); font-weight: 700; font-size: 0.9rem; }
.product-chip small { color: var(--muted); font-size: 0.72rem; }
.product-chip:hover:not(:disabled) { border-color: #9bc6c9; background: var(--primary-soft); }
.product-chip.is-disabled,
.product-chip:disabled { opacity: 0.45; cursor: not-allowed; }

.sell-total-box {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 14px 16px;
  border-radius: 14px;
  background: linear-gradient(180deg, #f3fafb, #e8f4f5);
  border: 1px solid #9bc6c9;
}
.sell-total-box span { font-weight: 700; color: var(--muted); }
.sell-total-box strong { font-size: 1.45rem; color: var(--primary); }
.sell-confirm {
  width: 100%;
  min-height: 48px;
  font-size: 1rem;
}
.sell-checkout { margin-top: 12px; }
.badge.confirmed { background: #e8f2ff; color: #2a5f9e; }
.badge.preparing { background: #fff4e5; color: #9a5b12; }
table.data tr.row-order-today td { background: #f3fafb; }
table.data tr.row-order-new td {
  background: #e8f6f7;
  box-shadow: inset 3px 0 0 var(--primary);
}
table.data tr.row-order-new:hover td,
table.data tr.row-order-today:hover td { filter: brightness(0.985); }

.order-actions {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line, #dfe7e7);
  display: grid;
  gap: 10px;
}

/* 受注の作成・保存ボタンを画面内に残す（収録・ノートPC向け） */
.so-sticky-actions {
  position: sticky;
  bottom: 8px;
  z-index: 25;
  margin-top: 8px;
}
.so-sticky-actions-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid #9bc6c9;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 10px 28px rgba(20, 42, 48, 0.14);
  backdrop-filter: blur(6px);
}
.so-sticky-actions-inner strong {
  font-size: 0.92rem;
  color: var(--primary);
}
.so-draft-btn {
  min-height: 44px;
  min-width: 9.5rem;
  font-weight: 700;
}
.next-step-card .so-draft-btn {
  min-height: 40px;
}

.flow-panel .panel-head { margin-bottom: 12px; }
.flow-footnote {
  margin: 12px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}

.policy-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.policy-grid > div {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f7fafa;
}
.policy-grid strong {
  display: block;
  font-size: 0.86rem;
  margin-bottom: 4px;
}
.policy-grid p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}
.money-block-title {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
  margin-top: 4px;
}
.doc-actions {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f7fafa;
}
.doc-viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(16, 32, 36, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
}
.doc-viewer-panel {
  width: min(920px, 100%);
  height: min(92vh, 100%);
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto 1fr;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.doc-viewer-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--primary);
  color: #fff;
}
.doc-viewer-bar .btn {
  background: #fff;
  color: var(--primary);
  border-color: #fff;
}
.doc-viewer-bar .btn.ghost {
  background: transparent;
  color: #fff;
  border-color: rgba(255,255,255,.45);
}
.doc-viewer-bar a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.doc-viewer-note {
  margin: 0;
  padding: 8px 14px;
  font-size: 0.78rem;
  color: var(--muted);
  background: #f3f8f8;
  border-bottom: 1px solid var(--border);
  line-height: 1.45;
}
.doc-viewer-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
@media (max-width: 720px) {
  .doc-viewer { padding: 8px; }
  .doc-viewer-bar { flex-direction: column; align-items: stretch; }
}
.quick-money {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.channel-hint { margin-top: -4px; }

.order-flow {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.order-flow li {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f7fafa;
  min-width: 0;
}
.order-flow li.is-current {
  background: var(--primary-soft);
  border-color: #9bc6c9;
  box-shadow: inset 0 0 0 1px rgba(15, 109, 115, 0.12);
}
.order-flow li.is-done {
  background: #eef8f1;
  border-color: #c5ddcb;
}
.order-flow li.is-muted { opacity: 0.55; }
.order-flow .step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
}
.order-flow li.is-current .step-num {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.order-flow li.is-done .step-num {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}
.order-flow .step-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.order-flow .step-text strong {
  font-size: 0.88rem;
  line-height: 1.3;
}
.order-flow .step-text small {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}
.order-flow.is-compact {
  margin-bottom: 12px;
}
.order-flow.is-compact li { padding: 10px; }

.next-step-card {
  margin: 0 0 14px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid #9bc6c9;
  background: linear-gradient(180deg, #f3fafb, #e8f4f5);
  display: grid;
  gap: 6px;
}
.next-step-card.is-final {
  border-color: #c5a15a;
  background: linear-gradient(180deg, #fffaf0, #fff4e0);
}
.next-step-card.is-done-card {
  border-color: #c5ddcb;
  background: #f3faf5;
}
.next-step-kicker {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--primary);
}
.next-step-card strong {
  font-size: 1rem;
  line-height: 1.35;
}
.next-step-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}
.next-step-card .row-actions { margin-top: 6px; }

@media (max-width: 960px) {
  .order-flow { grid-template-columns: 1fr 1fr; }
  .policy-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .order-flow { grid-template-columns: 1fr; }
}

.split-2 {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 14px;
  min-width: 0;
}
.list-plain {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.list-plain li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fbfb;
}
.list-plain strong { font-size: 0.92rem; }
.list-plain span { color: var(--muted); font-size: 0.82rem; }

.supplier-block {
  margin-bottom: 16px;
}
.supplier-po-btn {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  text-align: left;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #f4fbfb 0%, #eef6f4 100%);
  color: inherit;
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.supplier-po-btn:hover {
  border-color: var(--primary);
  box-shadow: 0 6px 18px rgba(20, 80, 80, .08);
  transform: translateY(-1px);
}
.supplier-po-btn.is-online {
  background: linear-gradient(135deg, #f3f8ff 0%, #eef6f4 100%);
}
.po-meta-grid {
  margin-bottom: 14px;
}
.po-online-fields {
  display: contents;
}
.po-online-fields.is-hidden {
  display: none;
}
.po-composer-body .seg-toggle {
  margin-top: 4px;
}
#poMethodSeg.seg-toggle {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 720px) {
  #poMethodSeg.seg-toggle {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
.supplier-po-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.supplier-po-main strong {
  font-size: 1.02rem;
}
.supplier-po-meta {
  display: grid;
  gap: 2px;
  justify-items: end;
  font-size: 0.82rem;
  color: var(--muted);
}
.supplier-po-cta {
  color: var(--primary);
  font-weight: 600;
}

.po-composer-panel {
  grid-template-rows: auto auto minmax(0, 1fr);
}
.po-composer-body {
  overflow: auto;
  padding: 14px 16px 18px;
  background: #fff;
}
.po-composer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}
.po-line-table .po-qty {
  width: 6.5rem;
  max-width: 100%;
}
.po-line-table .po-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
}
.po-line-table tr.is-candidate td:first-child {
  box-shadow: inset 3px 0 0 var(--primary);
}
@media (max-width: 720px) {
  .supplier-po-meta { justify-items: start; width: 100%; }
}

.muted { color: var(--muted); }
.tiny { font-size: 0.78rem; }
.right { text-align: right; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.empty {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
  font-size: 0.82rem;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  max-width: min(22rem, calc(100vw - 2rem));
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 180ms ease;
}
.toast.show {
  opacity: 1;
  transform: none;
}

@media (max-width: 960px) {
  .app-header,
  .split-2,
  .grid-cards,
  .header-meta,
  .form-grid {
    grid-template-columns: 1fr;
  }
  .header-meta { grid-template-columns: 1fr 1fr; }
  .grid-cards { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .app { padding: 12px 12px 32px; }
  .header-meta,
  .grid-cards { grid-template-columns: 1fr; }
  .nav-btn { font-size: 0.8rem; padding: 7px 11px; }
}
