/* コザクラス → 85BUNE 発注システム（タブレット優先） */
:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --ink: #23201c;
  --muted: #7a746b;
  --line: #e2ddd5;
  --primary: #1f6f5c;
  --primary-ink: #ffffff;
  --primary-soft: #e3f1ec;
  --accent: #d9822b;
  --danger: #c0392b;
  --warn-bg: #fff4e0;
  --warn-ink: #8a5300;
  --err-bg: #fdecea;
  --ok-bg: #e6f4ea;
  --info-bg: #e8f1fb;
  --radius: 12px;
  --tap: 52px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 17px; line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: .2em 0 .6em; }
h2 { font-size: 1.15rem; margin: 1.2em 0 .6em; }
.card h2:first-child, .card h1:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.r { text-align: right; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; }
.warn-text { color: var(--warn-ink); }
.print-only { display: none; }
[hidden] { display: none !important; }

/* ---------- レイアウト ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--primary); color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand-tag { display: inline-block; padding: 2px 10px; border-radius: 999px; background: rgba(255,255,255,.18); margin-right: 4px; }
.nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-link {
  color: #fff; text-decoration: none; padding: 10px 14px; border-radius: 10px; white-space: nowrap;
  min-height: 44px; display: inline-flex; align-items: center; font-weight: 600; opacity: .85;
}
.nav-link.on { background: rgba(255,255,255,.2); opacity: 1; }
.nav-link.logout { opacity: .6; font-weight: 400; font-size: .9rem; }
.container { max-width: 1180px; margin: 0 auto; padding: 16px; padding-bottom: 40px; }

.card { background: var(--surface); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.narrow { max-width: 620px; margin: 24px auto; }
.page-head, .sub-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.sub-head h2 { margin: .6em 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- ボタン・フォーム ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 8px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none;
  cursor: pointer; touch-action: manipulation; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-outline { color: var(--danger); border-color: var(--danger); background: #fff; }
.btn-lg { min-height: 56px; padding: 10px 26px; font-size: 1.1rem; }
.btn-sm { min-height: 38px; padding: 4px 12px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; }

.form label { display: block; margin-bottom: 14px; font-weight: 600; font-size: .95rem; }
.form label.check, label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
input[type=text], input:not([type]), input[type=password], input[type=number], input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: 46px; padding: 8px 12px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); font: inherit; font-weight: 400;
  font-size: max(16px, 1em); /* iPhone で入力時に拡大されないように */
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--primary-soft); border-color: var(--primary); }
input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--primary); }
.input-lg { min-height: 56px; font-size: 1.15rem; }
.hint { display: block; font-size: .8rem; color: var(--muted); font-weight: 400; }
.field-label { font-weight: 600; font-size: .95rem; margin-bottom: 6px; }
.grid2, .grid3, .grid4 { display: grid; gap: 0 14px; }
.grid2 { grid-template-columns: repeat(2, 1fr); }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.grid4 { grid-template-columns: repeat(4, 1fr); }
.span2 { grid-column: span 2; }
.w-small { max-width: 200px; }
.w-num { width: 80px !important; }
.w-code { width: 90px !important; }
.w-tel { width: 140px !important; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; }
form.inline { display: inline; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; }
.flash-ok { background: var(--ok-bg); color: #1e6b34; }
.flash-err { background: var(--err-bg); color: var(--danger); }
.flash-warn { background: var(--warn-bg); color: var(--warn-ink); }
.flash-info { background: var(--info-bg); color: #1d4f86; font-weight: 400; }

/* ---------- バッジ ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; vertical-align: middle; }
.st-submitted { background: #fde8d4; color: #a14d00; }
.st-accepted  { background: #dbeafe; color: #1d4ed8; }
.st-producing { background: #ede9fe; color: #6d28d9; }
.st-shipped   { background: #dcfce7; color: #15803d; }
.st-cancelled { background: #eeeeee; color: #777; }
.st-none      { background: #eeeeee; color: #666; }
.st-warn      { background: var(--warn-bg); color: var(--warn-ink); }
.st-note      { background: #fef3c7; color: #92400e; }
.pill { display: inline-block; min-width: 24px; padding: 0 7px; border-radius: 999px; background: #eee; color: #555; font-size: .85rem; text-align: center; }
.pill-alert { background: var(--accent); color: #fff; }
.badge-btn { border: 0; border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .8rem; font-weight: 700; cursor: pointer; min-height: 34px; }
.badge-btn.on { background: var(--primary-soft); color: var(--primary); }
.badge-btn.off { background: #eee; color: #888; }

/* ---------- ログイン ---------- */
.login-page { background: linear-gradient(160deg, #1f6f5c 0%, #2c8b74 60%, #f4f2ee 60.2%); min-height: 100vh; }
.login-box { max-width: 440px; margin: 8vh auto 0; background: #fff; border-radius: 18px; padding: 30px 28px; box-shadow: 0 10px 40px rgba(0,0,0,.15); }
.login-title { text-align: center; margin-bottom: 18px; }
.login-title h1 { margin: 0; font-size: 1.7rem; }
.login-sub { color: var(--primary); font-weight: 700; letter-spacing: .05em; }

/* ---------- 日付チップ ---------- */
.date-strip { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.date-strip-label { font-weight: 700; color: var(--muted); white-space: nowrap; }
.date-chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: thin; -webkit-overflow-scrolling: touch; flex: 1; align-items: stretch; }
.date-chip {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 92px; min-height: 64px; padding: 6px 10px; border-radius: 12px; text-decoration: none;
  background: var(--surface); color: var(--ink); border: 2px solid var(--line); line-height: 1.25;
}
.date-chip .dc-date { font-weight: 700; font-size: 1.02rem; }
.date-chip .dc-state { font-size: .78rem; color: var(--muted); }
.date-chip .dc-deadline { font-size: .7rem; color: var(--muted); }
.date-chip.has-order { border-color: #9cc9bb; background: var(--primary-soft); }
.date-chip.has-order .dc-state { color: var(--primary); font-weight: 700; }
.date-chip.closed { opacity: .55; }
.date-chip.on { border-color: var(--primary); background: var(--primary); color: #fff; opacity: 1; }
.date-chip.on .dc-state, .date-chip.on .dc-deadline { color: #e3f1ec; }
.date-chip.today .dc-date::after { content: "今日"; font-size: .65rem; margin-left: 4px; background: var(--accent); color: #fff; padding: 0 5px; border-radius: 4px; vertical-align: 2px; }
.dot-new { font-style: normal; background: var(--accent); color: #fff; border-radius: 6px; padding: 0 5px; font-size: .7rem; }
.date-pick input { min-height: 64px; margin: 0; }

/* ---------- 発注画面 ---------- */
.order-page .container { padding-bottom: 130px; }
.order-head { margin-bottom: 8px; }
.order-title { margin: 0 0 4px; }
.order-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.deadline-note { color: var(--warn-ink); background: var(--warn-bg); padding: 2px 10px; border-radius: 8px; font-size: .9rem; }

.cat-tabs {
  position: sticky; top: 60px; z-index: 20; display: flex; gap: 8px; overflow-x: auto;
  padding: 10px 0; background: var(--bg); scrollbar-width: none;
}
.cat-tabs::-webkit-scrollbar { display: none; }
.cat-tab {
  flex: 0 0 auto; min-height: 46px; padding: 6px 18px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font: inherit; font-weight: 600; color: var(--ink); cursor: pointer; touch-action: manipulation;
}
.cat-tab.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.tab-count { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: .8rem; }

.cat-section { margin-bottom: 14px; }
.cat-heading { font-size: 1rem; color: var(--muted); margin: 10px 4px 6px; }
.p-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px 12px 18px; margin-bottom: 8px;
  border: 2px solid transparent; box-shadow: var(--shadow);
}
.p-row.has-qty { border-color: var(--primary); background: #f6fbf9; }
.p-info { min-width: 0; flex: 1; }
.p-name { font-weight: 700; font-size: 1.1rem; line-height: 1.3; }
.p-sub { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: .88rem; }
.p-last { color: var(--primary); }
.p-note { font-size: .8rem; color: var(--warn-ink); margin-top: 2px; }
.qty-ctrl { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.qty-btn {
  width: var(--tap); height: var(--tap); border-radius: 50%; border: 0; font-size: 1.7rem; font-weight: 700; line-height: 1;
  background: #ece8e1; color: var(--ink); cursor: pointer; touch-action: manipulation; user-select: none;
}
.qty-btn.plus { background: var(--primary); color: #fff; }
.qty-btn:active { filter: brightness(.9); transform: scale(.95); }
.qty-btn:disabled { opacity: .3; }
.qty-input {
  width: 78px !important; height: var(--tap); margin: 0 !important; text-align: center; font-size: 1.35rem !important; font-weight: 700 !important;
  border-radius: 10px; padding: 0 4px !important; -moz-appearance: textfield;
}
.qty-input::-webkit-outer-spin-button, .qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty-unit { width: 52px; font-size: .85rem; color: var(--muted); }
.readonly .qty-input { background: #f5f3ef; }
.note-box { background: var(--surface); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow); }
.note-box label { font-weight: 600; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: rgba(255,255,255,.97); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}
.bb-summary { display: flex; gap: 18px; align-items: baseline; flex-wrap: wrap; }
.bb-total strong { font-size: 1.5rem; }
.bb-actions { display: flex; gap: 8px; }

.modal { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-body { background: #fff; border-radius: 16px; width: 100%; max-width: 620px; max-height: 88vh; display: flex; flex-direction: column; padding: 22px; }
.modal-body h2 { margin: 0 0 10px; }
.confirm-list { overflow-y: auto; flex: 1; border-top: 1px solid var(--line); }
.cl-row { display: grid; grid-template-columns: 1fr auto 110px; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.cl-name { font-weight: 600; }
.cl-qty { font-weight: 700; font-size: 1.1rem; }
.cl-amt { text-align: right; color: var(--muted); }
.confirm-total { text-align: right; padding: 12px 0; font-size: 1.05rem; }
.confirm-total strong { font-size: 1.4rem; }
.cancel-warn { background: var(--err-bg); color: var(--danger); padding: 16px; border-radius: 10px; text-align: center; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions .btn { flex: 1; }
body.modal-open { overflow: hidden; }

/* ---------- 表 ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; background: var(--surface); }
.tbl th, .tbl td { padding: 10px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { font-size: .82rem; color: var(--muted); font-weight: 700; white-space: nowrap; background: #faf8f5; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl tfoot td { border-bottom: 0; }
.tbl .chk { width: 44px; text-align: center; }
.tbl input, .tbl select { min-height: 40px; margin: 0; }
.tbl-orders tbody tr:hover { background: #faf8f5; }
.row-new { background: #fff8f0; }
.row-cancel td { color: #aaa; }
.row-diff { background: var(--warn-bg); }
.cat-row td { background: #f1ede6; font-weight: 700; font-size: .9rem; color: #5b554c; }
.big-num { font-size: 1.25rem; font-weight: 800; white-space: nowrap; }
.qty-edit { width: 90px !important; text-align: right; display: inline-block !important; }
.bulk-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 12px 0; }
.add-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 14px 0 6px; }
.add-line select { width: auto; min-width: 240px; margin: 0; }
.filter-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.filter-bar label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.filter-bar input { width: auto; margin: 0; }

.status-steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 16px; align-items: center; }
.status-steps .step {
  min-height: 50px; padding: 6px 22px; border: 2px solid var(--line); background: #fff; border-radius: 10px;
  font: inherit; font-weight: 700; color: var(--muted); cursor: pointer;
}
.status-steps .step.on { border-color: var(--primary); background: var(--primary); color: #fff; }
.status-steps .btn-danger-outline { margin-left: auto; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-val { font-size: 1.4rem; font-weight: 800; }
.month-nav { display: flex; align-items: center; gap: 12px; }

.hist-card { padding: 0; overflow: hidden; }
.hist-card summary { display: flex; align-items: center; gap: 12px; padding: 16px 20px; cursor: pointer; list-style: none; min-height: 60px; flex-wrap: wrap; }
.hist-card summary::-webkit-details-marker { display: none; }
.hist-card summary::after { content: "▾"; margin-left: 8px; color: var(--muted); }
.hist-card[open] summary::after { content: "▴"; }
.hist-date { font-weight: 700; font-size: 1.1rem; }
.hist-count { color: var(--muted); margin-left: auto; }
.hist-amt { font-weight: 700; min-width: 90px; text-align: right; }
.hist-card .tbl, .hist-card .note-line, .hist-foot { margin: 0; padding-left: 20px; padding-right: 20px; }
.hist-card .tbl th:first-child, .hist-card .tbl td:first-child { padding-left: 20px; }
.note-line { padding-top: 10px; }
.hist-foot { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; padding-bottom: 16px; gap: 10px; flex-wrap: wrap; }

.wd-checks { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.check-chip input { position: absolute; opacity: 0; pointer-events: none; }
.check-chip span { display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--line); font-weight: 700; cursor: pointer; background: #fff; }
.check-chip input:checked + span { background: var(--danger); border-color: var(--danger); color: #fff; }
.edit-card { border: 2px solid var(--primary); }

/* 商品画像 */
.p-thumb { flex: 0 0 auto; width: 64px; height: 64px; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #f5f3ef; cursor: zoom-in; }
.p-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-modal-body { max-width: 560px; align-items: center; gap: 12px; }
.image-modal-body img { max-width: 100%; max-height: 64vh; border-radius: 10px; object-fit: contain; }
.image-modal-name { font-weight: 700; font-size: 1.15rem; }
.image-field { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 14px; flex-wrap: wrap; }
.image-field input[type=file] { min-height: 44px; margin-bottom: 4px; }
.image-preview { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.image-preview.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .85rem; background: #f5f3ef; }
.thumb-cell { width: 56px; padding-top: 4px !important; padding-bottom: 4px !important; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; display: block; }

/* ---------- 画面幅ごとの調整 ---------- */
@media (max-width: 820px) {
  .grid3, .grid4 { grid-template-columns: repeat(2, 1fr); }
  .stat-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  body { font-size: 16px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 4px; }
  .cat-tabs { top: 104px; }
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .p-row { flex-direction: column; align-items: stretch; }
  .p-thumb { width: 56px; height: 56px; }
  .qty-ctrl { justify-content: flex-end; }
  .bottom-bar { flex-direction: column; align-items: stretch; }
  .bb-actions .btn { flex: 1; }
  .stat-row { grid-template-columns: 1fr; }
}

/* ---------- 印刷（製造集計など） ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 11pt; }
  .no-print, .topbar, .nav, .flash, .bottom-bar { display: none !important; }
  .print-only { display: table-cell; }
  .container { max-width: none; padding: 0; }
  .card { box-shadow: none; padding: 0; }
  .tbl th, .tbl td { padding: 5px 6px; border-bottom: 1px solid #999; }
  .big-num { font-size: 13pt; }
  .badge { border: 1px solid #999; }
}
.log-box { background: #f5f3ef; border-radius: 8px; padding: 10px 12px; font-size: .78rem; white-space: pre-wrap; word-break: break-all; margin: 0; }
