* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', sans-serif;
  background: #f0f4f8;
  color: #2d3748;
  min-height: 100vh;
}

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
}

/* ========== ヘッダー ========== */

header {
  text-align: center;
  padding: 28px 0 20px;
}

header h1 {
  font-size: 26px;
  font-weight: 700;
  color: #1a202c;
}

.subtitle {
  margin-top: 5px;
  font-size: 13px;
  color: #718096;
}

.family-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 99px;
  padding: 5px 10px 5px 14px;
  font-size: 13px;
}

.family-label {
  color: #718096;
}

.family-code {
  font-weight: 700;
  color: #2b6cb0;
  letter-spacing: 0.1em;
  font-size: 14px;
}

/* ========== カード ========== */

.card {
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.card h2 {
  font-size: 16px;
  font-weight: 600;
  color: #1a202c;
  margin-bottom: 16px;
  padding-bottom: 11px;
  border-bottom: 1px solid #e2e8f0;
}

/* ========== フォーム ========== */

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #4a5568;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row select {
  flex: 1;
}

input[type="text"],
input[type="date"],
input[type="number"],
select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 15px;
  color: #2d3748;
  background: #f7fafc;
  transition: border-color 0.15s, background 0.15s;
  appearance: auto;
}

input:focus,
select:focus {
  outline: none;
  border-color: #4299e1;
  background: #fff;
}

/* ========== ボタン ========== */

.btn-primary {
  width: 100%;
  padding: 11px;
  background: #4299e1;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover  { background: #3182ce; }
.btn-primary:disabled { background: #a0aec0; cursor: not-allowed; }

.btn-secondary {
  padding: 9px 13px;
  background: #edf2f7;
  color: #4a5568;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-secondary:hover { background: #e2e8f0; }

.btn-danger {
  padding: 4px 9px;
  background: #fff5f5;
  color: #e53e3e;
  border: 1px solid #feb2b2;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-danger:hover { background: #fed7d7; }

.btn-tiny {
  padding: 3px 9px;
  background: #edf2f7;
  color: #4a5568;
  border: none;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-tiny:hover { background: #e2e8f0; }

.hidden { display: none !important; }

.empty-msg {
  color: #a0aec0;
  font-size: 14px;
  text-align: center;
  padding: 14px 0;
}

/* ========== 次回購入予定 ========== */

.prediction-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 0;
  border-bottom: 1px solid #f0f4f8;
}

.prediction-item:last-child { border-bottom: none; }

.prediction-name {
  font-size: 15px;
  font-weight: 600;
  color: #2d3748;
}

.prediction-meta {
  font-size: 12px;
  color: #718096;
  margin-top: 3px;
}

.prediction-date { text-align: right; }

.prediction-date .date-label {
  font-size: 11px;
  color: #a0aec0;
  letter-spacing: 0.04em;
}

.prediction-date .date-value {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}

.prediction-date .date-value.overdue { color: #e53e3e; }
.prediction-date .date-value.soon    { color: #dd6b20; }
.prediction-date .date-value.ok      { color: #38a169; }

.days-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 99px;
  margin-top: 4px;
  font-weight: 600;
}

.days-badge.overdue { background: #fff5f5; color: #e53e3e; }
.days-badge.soon    { background: #fffaf0; color: #dd6b20; }
.days-badge.ok      { background: #f0fff4; color: #38a169; }

/* ========== 購入履歴 ========== */

.item-block { margin-bottom: 18px; }
.item-block:last-child { margin-bottom: 0; }

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

.item-header-name {
  font-size: 15px;
  font-weight: 600;
  color: #2d3748;
  display: flex;
  align-items: center;
  gap: 6px;
}

.unit-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  color: #718096;
  background: #edf2f7;
  padding: 1px 7px;
  border-radius: 99px;
}

.purchase-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 11px;
  background: #f7fafc;
  border-radius: 7px;
  margin-bottom: 4px;
  font-size: 13px;
  color: #4a5568;
}

.purchase-info {
  display: flex;
  gap: 14px;
}

.no-purchases {
  font-size: 13px;
  color: #a0aec0;
  padding: 6px 11px;
}

.item-divider {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 14px 0;
}

/* ========== モーダル ========== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-box {
  background: #fff;
  border-radius: 14px;
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 380px;
  position: relative;
}

.modal-box h2 {
  font-size: 18px;
  font-weight: 700;
  color: #1a202c;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 13px;
  color: #718096;
  margin-bottom: 20px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.modal-actions .btn-primary { flex: 1; }

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  font-size: 16px;
  color: #a0aec0;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s;
}

.modal-close:hover { background: #f0f4f8; }

/* ========== ローディング ========== */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e2e8f0;
  border-top-color: #4299e1;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========== トースト ========== */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2d3748;
  color: #fff;
  padding: 11px 22px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  transition: opacity 0.3s;
  max-width: calc(100vw - 32px);
  text-align: center;
  white-space: normal;
}

.toast.hidden { opacity: 0; pointer-events: none; }

@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
  .modal-actions { flex-direction: column; }
}
