/* ===== リセット & ベース ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:     #4f46e5;
  --primary-d:   #3730a3;
  --primary-l:   #6366f1;
  --accent:      #eef2ff;
  --accent-2:    #e0e7ff;
  --bg:          #f1f5f9;
  --card:        #ffffff;
  --border:      #e2e8f0;
  --text:        #0f172a;
  --text-sub:    #64748b;
  --danger:      #ef4444;
  --success:     #10b981;
  --radius:      14px;
  --radius-sm:   8px;
  --shadow:      0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --shadow-md:   0 4px 24px rgba(79,70,229,.12);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 48px;
}

/* ===== ヘッダー ===== */
.app-header {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #fff;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 16px rgba(79,70,229,.35);
}

.header-icon {
  font-size: 24px;
  background: rgba(255,255,255,.18);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .5px;
}

/* ===== レイアウト ===== */
.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===== カード ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: box-shadow .2s;
}

.card:focus-within {
  box-shadow: var(--shadow-md);
  border-color: #c7d2fe;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent-2);
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-title::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 14px;
  background: var(--primary);
  border-radius: 2px;
}

/* ===== フォーム部品 ===== */
label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.input-full,
select,
textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  background: #fff;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .18s, box-shadow .18s;
}

.input-full:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-l);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.textarea-md { height: 90px; resize: vertical; line-height: 1.65; }
.textarea-sm { height: 66px; resize: vertical; line-height: 1.65; }

/* ===== 日付行 ===== */
.row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field { display: flex; flex-direction: column; }

.date-day-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-flex { flex: 1; min-width: 0; }

.day-badge {
  background: var(--accent-2);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  min-width: 38px;
  text-align: center;
  border: 1.5px solid #c7d2fe;
}

/* ===== 商品行 ===== */
.item-row {
  background: var(--accent);
  border-radius: 10px;
  padding: 13px;
  margin-bottom: 10px;
  border: 1px solid #c7d2fe;
  position: relative;
}

.item-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.item-row-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .5px;
  background: var(--accent-2);
  padding: 3px 9px;
  border-radius: 20px;
}

.btn-remove {
  background: none;
  border: 1.5px solid #fca5a5;
  color: var(--danger);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: background .15s;
}

.btn-remove:active { background: #fee2e2; }

.item-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.item-grid .field-product { grid-column: 1 / -1; }

/* ===== ボタン ===== */
.btn-secondary {
  width: 100%;
  padding: 12px;
  border: 2px dashed #a5b4fc;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: background .15s, border-color .15s;
}
.btn-secondary:active { background: var(--accent); }
.btn-secondary:hover  { border-color: var(--primary); background: var(--accent); }

.action-area {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  padding: 4px 0;
}

.btn-primary {
  padding: 15px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-l) 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  box-shadow: 0 4px 14px rgba(79,70,229,.35);
  letter-spacing: .3px;
}

.btn-primary:hover  { opacity: .92; }
.btn-primary:active {
  opacity: .85;
  transform: scale(.98);
}

.btn-outline {
  padding: 15px;
  background: #fff;
  color: var(--primary);
  border: 2px solid var(--primary-l);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.btn-outline:hover  { background: var(--accent); border-color: var(--primary); }
.btn-outline:active { background: var(--accent-2); }

/* ===== モーダル ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 24px;
  backdrop-filter: blur(4px);
}

.modal.hidden { display: none; }

.modal-box {
  background: #fff;
  border-radius: 18px;
  padding: 36px 28px;
  text-align: center;
  width: 100%;
  max-width: 300px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.modal-icon { font-size: 52px; margin-bottom: 16px; }

#modalMessage {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 22px;
  white-space: pre-line;
}

/* ===== 履歴ボタン（ヘッダー内） ===== */
.btn-header-history {
  margin-left: auto;
  padding: 7px 16px;
  background: rgba(255,255,255,.18);
  color: #fff;
  border: 1.5px solid rgba(255,255,255,.4);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-header-history:active { background: rgba(255,255,255,.3); }

/* ===== 履歴パネル ===== */
.history-panel {
  position: fixed;
  inset: 0;
  z-index: 998;
}

.history-panel.hidden { display: none; }

.history-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(3px);
}

.history-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100vw);
  background: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 32px rgba(0,0,0,.18);
  animation: slideIn .22s ease-out;
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.history-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1.5px solid var(--border);
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #fff;
}

.history-drawer-title {
  font-size: 16px;
  font-weight: 700;
}

.btn-close {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.btn-close:active { background: rgba(255,255,255,.35); }

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.history-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.history-item-dest {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.history-item-date {
  font-size: 11px;
  color: var(--text-sub);
}

.history-item-status {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  margin-bottom: 8px;
}

.history-item-status.ok  { background: #d1fae5; color: #065f46; }
.history-item-status.dev { background: #fef3c7; color: #92400e; }

.history-item-meta {
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.7;
}

.history-item-meta span {
  margin-right: 12px;
}

.history-item-products {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text);
  line-height: 1.7;
}

/* ===== 数量入力 ===== */
input[type="number"] {
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

/* ===== 指示書セクション ===== */
.card-instruction {
  border-left: 4px solid #0891b2;
}

.card-instruction .section-title::before {
  background: #0891b2;
}

.card-instruction .section-title {
  color: #0891b2;
  border-bottom-color: #cffafe;
}

.instr-note {
  font-size: 12px;
  color: #0e7490;
  background: #f0fdfe;
  border: 1px solid #a5f3fc;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 14px;
  line-height: 1.6;
}

.instr-badge {
  font-size: 10px;
  font-weight: 700;
  background: #cffafe;
  color: #0e7490;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 6px;
}

.instr-field {
  margin-bottom: 12px;
}

.select-add-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.select-add-row .input-flex {
  flex: 1;
  min-width: 0;
}

.btn-add-option {
  background: #cffafe;
  color: #0e7490;
  border: 1.5px solid #a5f3fc;
  border-radius: var(--radius-sm);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 14px;
  white-space: nowrap;
  transition: background .15s, color .15s;
  line-height: 1;
}

.btn-add-option:hover  { background: #a5f3fc; color: #0c4a6e; }
.btn-add-option:active { background: #67e8f9; }

/* ===== 転送先詳細 ===== */
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.section-title-row .section-title {
  margin-bottom: 0;
}

.btn-edit {
  background: var(--accent);
  color: var(--primary);
  border: 1.5px solid var(--accent-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  padding: 4px 12px;
  cursor: pointer;
  font-weight: 500;
}

.btn-edit:hover  { background: var(--accent-2); }

.details-display {
  min-height: 40px;
}

.details-text {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.6;
  padding: 8px 0;
}

.details-placeholder {
  font-size: 13px;
  color: var(--text-sub);
  padding: 8px 0;
}

#detailsEdit .btn-secondary {
  margin-top: 8px;
}

/* ===== レスポンシブ（小画面） ===== */
@media (max-width: 360px) {
  .row-2col   { grid-template-columns: 1fr; }
  .action-area { grid-template-columns: 1fr; }
}
