/* ================= リセットとベース ================= */
* {
  box-sizing: border-box;
}

body {
  font-family: "Yu Gothic", "游ゴシック体", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background-color: #fafafa;
  color: #333;
  margin: 0;
  padding: 10px 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ================= ヘッダー ================= */
header {
  text-align: center;
  margin-bottom: 10px;
}

header h1 {
  font-size: 1.6rem;
  margin: 0;
}

/* ================= ナビボタン ================= */
.nav-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-group.main-nav button,
.nav-group.extra-nav button {
  cursor: pointer;
  padding: 6px 12px;
  font-size: 16px;
  border: 1px solid #888;
  background-color: #fff;
  border-radius: 4px;
  transition: background-color 0.3s ease;
  user-select: none;
}

.nav-group.main-nav button:hover,
.nav-group.extra-nav button:hover {
  background-color: #4a7c59;
  color: white;
}

/* ================= 今日 設定 保存 読込み ボタン配置 ================= */
@media (min-width: 601px) {
  .main-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 20px;
  }

  .main-buttons button {
    min-width: 120px;
    padding: 8px 12px;
    font-size: 16px;
    flex-grow: 1;
  }

  .today-button-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
  }

  #today-button {
    min-width: 120px;
    padding: 8px 12px;
    font-size: 16px;
    border: 1px solid #888;
    background-color: #fff;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.3s ease;
    text-align: center;
  }

  #today-button:hover {
    background-color: #4a7c59;
    color: white;
  }
}

@media (max-width: 600px) {
  .main-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 12px;
    width: 100%;
    margin-bottom: 12px;
  }

  .main-buttons button {
    font-size: 14px;
    padding: 6px 8px;
  }

  .today-button-wrapper {
    margin-top: 15px;
    width: 100%;
  }

  #today-button {
    width: 100%;
    font-size: 14px;
    padding: 8px 12px;
  }

  .nav-buttons {
    flex-direction: column;
    gap: 6px;
  }

  .nav-group.extra-nav {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 12px;
    width: 100%;
  }

  .nav-group.extra-nav button {
    font-size: 14px;
    padding: 6px 8px;
  }
}

/* ================= カレンダー ================= */
#calendar-container {
  width: 100%;
  max-width: 720px;
  overflow-x: auto;
  border-radius: 8px;
  box-shadow: 0 0 8px rgba(0,0,0,0.1);
  background: white;
}

#calendar {
  border-collapse: collapse;
  width: 700px;
  min-width: 700px;
}

#calendar th,
#calendar td {
  border: 1px solid #ccc;
  width: 14.28%;
  padding: 6px;
  height: 80px;
  font-size: 14px;
  vertical-align: top;
  user-select: none;
  overflow: hidden;
  word-break: break-word;
}

#calendar th {
  background-color: #4a7c59;
  color: white;
  font-weight: 600;
  text-align: center;
}

.sunday {
  color: #cc4a4a;
}

.saturday {
  color: #4a6bcc;
}

.adjacent-month {
  color: #bbb;
  background-color: #f9f9f9;
}

.today {
  border: 2px solid #4a7c59;
}

td > div:first-child {
  font-weight: bold;
  margin-bottom: 4px;
}

/* ================= イベント表示 ================= */
.event {
  background-color: #d3f1d8;
  border-radius: 6px;
  margin-bottom: 3px;
  padding: 3px 6px;
  font-size: 13px;
  line-height: 1.2em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  cursor: default;
}

.event-tag {
  padding: 1px 5px;
  border-radius: 3px;
  color: white;
  font-size: 0.75em;
  font-weight: 600;
  user-select: none;
}

.event-location {
  font-size: 0.75em;
  color: #444;
  margin-left: 4px;
}

.event-notify {
  font-size: 0.9em;
  margin-left: 4px;
}

.event > button {
  margin-left: auto;
  padding: 3px 8px;
  font-size: 0.75em;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background-color: #7c7c7c;
  color: white;
}

.event > button:hover {
  background-color: #4a7c59;
}

/* ================= モーダル（予定追加/編集） ================= */
.modal-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.modal {
  background-color: white;
  border-radius: 12px;
  padding: 20px 25px;
  max-width: 480px;
  width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 0 15px rgba(0,0,0,0.2);
}

.modal h2 {
  margin-top: 0;
  text-align: center;
}

.event-inputs label {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  font-size: 0.95em;
}

.event-inputs label.notify-label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.event-inputs input[type="text"],
.event-inputs input[type="time"],
.event-inputs input[type="color"],
.event-inputs textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 6px;
  font-size: 14px;
  border: 1px solid #aaa;
  border-radius: 5px;
  resize: vertical;
  min-height: 2em;
  font-family: inherit;
}

.event-inputs textarea {
  min-height: 3em;
  max-height: 10em;
  overflow-y: auto;
  font-family: inherit;
}

/* モーダルボタン */
.modal-buttons {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.modal-buttons button {
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  background-color: #4a7c59;
  color: white;
  font-size: 14px;
  transition: background-color 0.3s ease;
}

.modal-buttons button:hover {
  background-color: #3d6646;
}

/* ================= タグカラー設定 ================= */
.tag-color-list {
  max-height: 250px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.tag-color-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.tag-color-item label {
  flex-grow: 1;
  user-select: none;
}

.tag-color-item input[type="color"] {
  cursor: pointer;
  background: none;
  width: 40px;
  height: 30px;
  padding: 0;
  border-radius: 4px;
  appearance: none;
}

.tag-color-item button {
  background-color: #cc4a4a;
  color: white;
  padding: 4px 8px;
  border: none;
  border-radius: 4px;
  font-size: 0.85em;
  cursor: pointer;
}

.tag-color-item button:hover {
  background-color: #a83232;
}

.tag-add {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}

.tag-add input[type="text"] {
  flex-grow: 1;
  padding: 6px 8px;
  font-size: 1em;
  border: 1px solid #aaa;
  border-radius: 6px;
}

.tag-add input[type="color"] {
  width: 40px;
  height: 32px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  appearance: none;
}

.tag-add button {
  background-color: #4a7c59;
  color: white;
  padding: 6px 14px;
  font-weight: 600;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.tag-add button:hover {
  background-color: #3d6646;
}

/* ================= レスポンシブ（スマホ対応） ================= */
@media (max-width: 600px) {
  /* カレンダー全体パディングをやや狭く */
  #calendar {
    padding: 8px;
    width: 100% !important;
    min-width: 100% !important;
  }

  /* カレンダーテーブルのフォントサイズとセルサイズ縮小 */
  #calendar th,
  #calendar td {
    font-size: 12px;
    height: 60px;
    padding: 4px;
  }

  /* 月年表示のフォントサイズを縮小 */
  #month-year {
    font-size: 1rem;
  }

  /* ボタンのパディングとフォントサイズ調整 */
  button {
    padding: 5px 8px;
    font-size: 14px;
  }

  /* テキストエリアと時間入力のフォントサイズ縮小 */
  textarea,
  input[type="time"] {
    font-size: 13px;
  }

  /* モーダルの幅とパディング調整 */
  .modal {
    max-width: 100%;
    height: 90vh;
    padding: 16px 20px;
  }
}
