/* ========== ベース ========== */
:root {
  --color-primary: #2f7d4f;
  --color-primary-dark: #1e5a37;
  --color-accent: #f59e0b;
  --color-danger: #dc2626;
  --color-bg: #f5f7f5;
  --color-card: #ffffff;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --tap: 56px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
input, select {
  font-family: inherit;
  font-size: 16px; /* iOSのズーム防止 */
}

.hidden { display: none !important; }

/* ========== ヘッダー ========== */
#app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 8px;
  background: var(--color-primary);
  color: white;
  padding-top: env(safe-area-inset-top);
  height: calc(56px + env(safe-area-inset-top));
}
#app-header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
  flex: 1;
  text-align: center;
}
#app-header button {
  color: white;
  font-size: 28px;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  line-height: 1;
}
#app-header button:active { background: rgba(255,255,255,.15); }

/* ========== ユーザーバー ========== */
#user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #e8f3ec;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
}
#user-bar strong { color: var(--color-primary-dark); font-size: 16px; }
#btn-change-user {
  font-size: 13px;
  color: var(--color-primary-dark);
  text-decoration: underline;
}

/* ========== メイン ========== */
main {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: 100px;
}

.screen-title {
  font-size: 18px;
  font-weight: 600;
  margin: 8px 0 16px;
}

.hint {
  color: var(--color-text-muted);
  font-size: 14px;
  margin: 0 0 16px;
}

/* ========== 名前選択画面 ========== */
.user-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.user-card {
  background: var(--color-card);
  border: 2px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 6px;
  font-size: 15px;
  font-weight: 600;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: var(--shadow);
  transition: transform .1s, background .15s;
  word-break: break-all;
  line-height: 1.2;
}
.user-card:active {
  transform: scale(.97);
  background: #e8f3ec;
}
.user-card.admin {
  border-color: var(--color-accent);
}
.user-card.admin::after {
  content: "管理者";
  font-size: 9px;
  background: var(--color-accent);
  color: white;
  padding: 1px 6px;
  border-radius: 8px;
  margin-top: 2px;
}
.recovery-area {
  margin-top: 12px;
  text-align: center;
}
.recovery-warn {
  background: #fff5e5;
  color: #8a4a00;
  border: 1px solid #f4c47a;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 10px;
  line-height: 1.4;
}
.text-btn {
  display: block;
  margin: 0 auto;
  padding: 10px 16px;
  color: var(--color-primary-dark);
  font-size: 14px;
  text-decoration: underline;
}
.text-btn.danger { color: var(--color-danger); }

/* ========== 材料一覧 ========== */
.material-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.material-summary:empty { display: none; }
.summary-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 14px;
  border: 1px solid transparent;
  line-height: 1.2;
  cursor: pointer;
}
.summary-badge.badge-low {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}
.summary-badge.badge-ordered {
  background: #fff7ed;
  color: #c2410c;
  border-color: #fdba74;
}
.summary-badge.badge-info {
  background: #f3f4f6;
  color: #4b5563;
  cursor: default;
}
.summary-badge.badge-clear {
  background: var(--color-primary);
  color: white;
}
.summary-badge.active {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}
.list-actions {
  margin-bottom: 12px;
}
#search-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: white;
}
.material-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.material-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: var(--tap);
}
.material-row .info {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.material-row .name {
  font-weight: 600;
  font-size: 16px;
}
.material-row .meta {
  font-size: 13px;
  color: var(--color-text-muted);
}
.material-row .stock {
  font-size: 22px;
  font-weight: 700;
  min-width: 60px;
  text-align: right;
}
.material-row .stock .unit {
  font-size: 13px;
  font-weight: 400;
  color: var(--color-text-muted);
  margin-left: 2px;
}
.material-row.low .stock { color: var(--color-danger); }
.material-row.low .name::after {
  content: " ⚠";
  color: var(--color-danger);
}
.material-row .ordered-mark {
  display: inline-block;
  background: #fff7ed;
  color: #c2410c;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 8px;
  margin-left: 4px;
  font-weight: 600;
}

/* ========== 材料詳細 ========== */
.detail-card {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
  text-align: center;
}
.detail-name {
  font-size: 22px;
  margin: 8px 0 16px;
  font-weight: 700;
}
.detail-stock {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin: 24px 0;
}
.stock-label {
  font-size: 14px;
  color: var(--color-text-muted);
  margin-right: 12px;
}
.stock-number {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  color: var(--color-primary-dark);
}
.stock-unit {
  font-size: 20px;
  color: var(--color-text-muted);
}
.detail-stock.low .stock-number { color: var(--color-danger); }

.alert-bar {
  background: #fef2f2;
  color: var(--color-danger);
  padding: 10px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}
.alert-bar.ordered {
  background: #fff7ed;
  color: #c2410c;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}
.big-btn {
  min-height: 80px;
  font-size: 22px;
  font-weight: 700;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform .1s;
}
.big-btn:active { transform: scale(.97); }
.big-btn small {
  font-size: 12px;
  font-weight: 500;
  opacity: .9;
}
.big-btn.minus {
  background: var(--color-accent);
  color: white;
}
.big-btn.plus {
  background: var(--color-primary);
  color: white;
}
.big-btn.danger {
  background: var(--color-danger);
  color: white;
}
.big-btn.delivery {
  background: #1d4ed8;
  color: white;
  margin-top: 12px;
  width: 100%;
  min-height: 64px;
  font-size: 18px;
}
.big-btn.order {
  background: #06c755; /* LINE色 */
  color: white;
  margin-top: 12px;
  width: 100%;
  min-height: 72px;
  font-size: 18px;
}
#btn-save-stocktake {
  width: 100%;
  margin-top: 8px;
}

.detail-meta {
  display: flex;
  justify-content: space-around;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
  font-size: 14px;
  color: var(--color-text-muted);
}

/* ========== 履歴 ========== */
.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-row {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  background: var(--color-card);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 14px;
  align-items: center;
}
.history-row .action {
  font-weight: 700;
  min-width: 44px;
  text-align: center;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 13px;
}
.history-row .action.minus { background: #fff3e0; color: var(--color-accent); }
.history-row .action.plus { background: #e8f3ec; color: var(--color-primary-dark); }
.history-row .action.stocktake { background: #e0e7ff; color: #4338ca; }
.history-row .action.delivery { background: #dbeafe; color: #1d4ed8; }
.history-row .action.order { background: #fff7ed; color: #c2410c; }
.history-row .info {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.history-row .info .top { font-weight: 600; }
.history-row .info .bottom { font-size: 12px; color: var(--color-text-muted); }

/* ========== 管理者メニュー ========== */
.admin-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-btn {
  padding: 18px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  box-shadow: var(--shadow);
}
.admin-btn:active { background: #f1f5f9; }
.admin-btn.danger { color: var(--color-danger); }

/* ========== フォーム ========== */
.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--color-card);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}
.form input, .form select {
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: white;
  font-size: 16px;
  font-weight: 400;
}
.form input:focus, .form select:focus {
  outline: 2px solid var(--color-primary);
  border-color: transparent;
}
.form-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}
.form.inline {
  flex-direction: row;
  padding: 12px;
  gap: 8px;
  align-items: center;
}
.form.inline input { flex: 1; }
.small-btn {
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
}
.small-btn.plus { background: var(--color-primary); color: white; }

/* ========== 棚卸し ========== */
.stocktake-list {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stocktake-row {
  display: grid;
  grid-template-columns: 1fr 100px;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: var(--color-card);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.stocktake-row .label {
  font-weight: 600;
}
.stocktake-row .label small {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--color-text-muted);
}
.stocktake-row input {
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  text-align: right;
  font-size: 18px;
  font-weight: 700;
  width: 100%;
}

/* ========== 名前リスト ========== */
.users-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.users-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--color-card);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.users-list .role-toggle {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  background: #f3f4f6;
  color: var(--color-text-muted);
  margin-right: 8px;
}
.users-list .role-toggle.admin {
  background: var(--color-accent);
  color: white;
}
.users-list .del {
  color: var(--color-danger);
  font-size: 13px;
  text-decoration: underline;
}

/* ========== フッターナビ ========== */
#footer-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: white;
  border-top: 1px solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.nav-btn {
  flex: 1;
  padding: 8px 4px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--color-text-muted);
  min-height: 56px;
}
.nav-btn.active {
  color: var(--color-primary-dark);
  font-weight: 700;
}

/* ========== トースト ========== */
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.85);
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 100;
  animation: toastIn .2s ease;
  max-width: 90%;
  text-align: center;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ========== モーダル ========== */
#modal,
#num-modal,
#pin-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  overflow-y: auto;
}
#modal.hidden,
#num-modal.hidden,
#pin-modal.hidden {
  display: none;
}
.modal-card {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.modal-card p {
  margin: 0 0 20px;
  font-size: 16px;
}
.modal-card input[type="number"],
.modal-card input[type="password"] {
  width: 100%;
  padding: 14px;
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 16px;
  letter-spacing: 8px;
}
.modal-card input[type="number"]:focus,
.modal-card input[type="password"]:focus {
  outline: 2px solid var(--color-primary);
  border-color: transparent;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.modal-actions button {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  background: #f3f4f6;
}
.modal-actions button.primary {
  background: var(--color-primary);
  color: white;
}
.modal-actions button.primary.danger {
  background: var(--color-danger);
}

/* ========== ユーティリティ ========== */
.admin-only { /* JSで is-admin クラス制御 */ }
body:not(.is-admin) .admin-only { display: none !important; }

.empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: 40px 20px;
  font-size: 14px;
}

/* ========== ロック画面（合言葉ゲート） ========== */
#lock-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #1e5a37, #2f7d4f);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#lock-screen.hidden { display: none; }
.lock-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px 22px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  text-align: center;
}
.lock-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
  color: var(--color-primary-dark);
}
.lock-card p { margin: 6px 0 16px; color: var(--color-text-muted); font-size: 14px; }
.lock-card input[type="password"] {
  width: 100%;
  font-size: 20px;
  padding: 14px;
  border: 2px solid var(--color-border);
  border-radius: 10px;
  text-align: center;
  letter-spacing: 4px;
  margin-bottom: 14px;
}
.lock-card input[type="password"]:focus {
  outline: none;
  border-color: var(--color-primary);
}
.lock-card .big-btn { width: 100%; }
.lock-error {
  color: var(--color-danger);
  font-weight: bold;
  margin-top: 12px;
}
.lock-hint {
  margin-top: 14px;
  font-size: 12px;
  color: var(--color-text-muted);
}
