:root {
  --main-color: #4a90e2;
  --main-dark: #357ab8;
  --accent-color: #e74c3c;
  --bg-color: #f0f2f5;
  --card-bg: #ffffff;
  --text-color: #333;
  --text-sub: #777;
  --border-radius: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  padding: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1 {
  text-align: center;
  color: var(--main-color);
  font-size: 1.4rem;
  margin: 10px 0 20px;
}

h3 {
  color: var(--text-color);
  margin: 0 0 15px;
  font-size: 1.1rem;
  border-left: 4px solid var(--main-color);
  padding-left: 10px;
  display: flex;
  align-items: center;
}

/* メインコンテンツエリア（履歴リストなど） */
#history {
  background: var(--card-bg);
  padding: 5px;
  margin: 0 auto 20px;
  max-width: 600px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
}

/* --- 新規追加ボタン（ページ上部） --- */
.open-modal-btn {
  display: block;
  width: 100%;
  max-width: 600px;
  margin: 0 auto 20px;
  padding: 16px;
  font-size: 1.1rem;
  font-weight: bold;
  color: white;
  background-color: var(--main-color);
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(74, 144, 226, 0.3);
  transition: transform 0.2s, background-color 0.2s;
  text-align: center;
}
.open-modal-btn:active {
  transform: scale(0.98);
  background-color: var(--main-dark);
}
.open-modal-btn i {
  margin-right: 8px;
}

/* --- モーダル（ポップアップ）関連 --- */
.modal-overlay {
  display: none; /* 初期状態は非表示 */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5); /* 背景を暗く */
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 15px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* モーダル表示時のクラス */
.modal-overlay.active {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: var(--card-bg);
  width: 100%;
  max-width: 500px;
  border-radius: 16px;
  padding: 25px 20px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  position: relative;
  transform: translateY(20px);
  transition: transform 0.3s ease;
  max-height: 90vh;
  overflow-y: auto; /* 画面が小さい時にスクロール */
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

/* 閉じるボタン（×） */
.close-modal-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  background: #f1f1f1;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.2rem;
  color: #555;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.close-modal-btn:hover {
  background: #ddd;
}

/* --- フォームパーツ --- */
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 12px;
  margin-bottom: 15px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  background: #f9f9f9;
  appearance: none;
}
input:focus {
  outline: none;
  border-color: var(--main-color);
  background: #fff;
}

.search-btn {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: bold;
  background-color: var(--main-color);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.search-btn:active { background-color: var(--main-dark); }

/* 運送会社選択カード */
.carrier-wrapper {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); /* 少し小さく調整 */
  gap: 8px;
  margin-bottom: 20px;
}
.carrier-radio { display: none; }
.carrier-label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 4px;
  background: #fff;
  border: 2px solid #eee;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  color: #555;
  font-size: 0.85rem;
  transition: all 0.2s;
  text-align: center;
}
.carrier-radio:checked + .carrier-label {
  border-color: var(--main-color);
  background-color: #eef6fc;
  color: var(--main-color);
}


/* --- 履歴リスト --- */
#historyList {
  list-style: none;
  padding: 0;
  margin: 0;
}

.history-entry {
  background: #fff;
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: all 0.2s;
  cursor: pointer; 
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.history-entry.selected {
  background-color: #f0f8ff;
  border-color: #4a90e2;
  box-shadow: 0 0 0 1px #4a90e2;
}

.history-entry:active {
  transform: scale(0.98);
}

.history-entry a, 
.history-entry button {
  cursor: pointer;
  z-index: 2;
  position: relative;
}

.history-col-checkbox {
  display: flex;
  align-items: center;
  padding-top: 4px;
}
.history-entry input[type="checkbox"] {
  transform: scale(1.2);
  cursor: pointer;
}

.history-col-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.history-meta {
  font-size: 0.8rem;
  color: var(--text-sub);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.carrier-badge {
  background: #eee;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  color: #666;
}

.tracking-number-link {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--main-color);
  text-decoration: none;
  letter-spacing: 0.5px;
  display: inline-block;
  word-break: break-all;
}
.tracking-number-link:hover { text-decoration: underline; }

.history-note {
  font-size: 0.85rem;
  color: #555;
  background: #fcf8e3;
  padding: 6px 10px;
  border-radius: 6px;
  margin-top: 4px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  line-height: 1.4;
}
.history-note i {
    color: #f0ad4e;
    margin-top: 3px;
}

.history-col-action {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  min-width: 80px;
}

.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: bold;
  color: white;
  background-color: #ccc;
  white-space: nowrap;
  text-align: center;
}
.status-badge[data-status*="完了"], .status-badge[data-status*="済"] { background-color: #28a745; }
.status-badge[data-status*="輸送中"], .status-badge[data-status*="通過"], .status-badge[data-status*="保管"] { background-color: #007bff; }
.status-badge[data-status*="持戻"], .status-badge[data-status*="調査"] { background-color: #fd7e14; }
.status-badge[data-status*="確認"], .status-badge[data-status*="不明"] { background-color: #ffc107; color: #333; }
.status-badge[data-status*="失敗"], .status-badge[data-status*="なし"], .status-badge[data-status*="エラー"] { background-color: #dc3545; }

.reload-btn {
  padding: 6px 10px;
  font-size: 0.8rem;
  background-color: #fff;
  color: var(--main-dark);
  border: 1px solid var(--main-dark);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.reload-btn:hover { background-color: #eef6fc; }
.reload-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.delete-section {
  text-align: right;
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #eee;
}
.delete-btn {
  background: transparent;
  color: #d9534f;
  border: 1px solid #d9534f;
  padding: 8px 12px;
  font-size: 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.delete-btn:hover { background-color: #fdf2f2; }

#history-privacy {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-top: 20px;
}

@media screen and (max-width: 360px) {
    .history-entry {
        gap: 8px;
        padding: 10px;
    }
    .history-col-action {
        min-width: auto;
    }
    .reload-btn span {
        display: none;
    }
}