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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Helvetica Neue', Arial, sans-serif;
  color: #333;
  background: #fafafa;
  line-height: 1.6;
}

body {
  padding: 20px;
}

h1 {
  font-size: 28px;
  margin-bottom: 20px;
  color: #222;
}

h2 {
  font-size: 20px;
  margin-bottom: 15px;
  color: #222;
}

p {
  margin-bottom: 10px;
}

a {
  color: #0070f3;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  font-size: 14px;
}

button:hover {
  opacity: 0.8;
}

/* Form styles */
input, textarea, select {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-family: inherit;
  font-size: 14px;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: #0070f3;
  box-shadow: 0 0 0 3px rgba(0, 112, 243, 0.1);
}

label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: #222;
}

/* Table styles */
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 4px;
  overflow: hidden;
}

th {
  background: #f5f5f5;
  padding: 12px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid #eee;
}

td {
  padding: 12px;
  border-bottom: 1px solid #eee;
}

tr:hover {
  background: #f9f9f9;
}

/* Message styles */
.success {
  background: #d4edda;
  color: #155724;
  padding: 12px;
  border-radius: 4px;
  margin-bottom: 20px;
}

.error {
  background: #f8d7da;
  color: #721c24;
  padding: 12px;
  border-radius: 4px;
  margin-bottom: 20px;
}

.info {
  background: #d1ecf1;
  color: #0c5460;
  padding: 12px;
  border-radius: 4px;
  margin-bottom: 20px;
}

/* Summary grid styles */
.summary-grid {
  display: grid;
  gap: 10px;
}

/* PC: 常に7列で固定 */
@media (min-width: 769px) {
  .summary-grid {
    grid-template-columns: repeat(7, 1fr);
  }
}

/* モバイル: 自動折り返し */
@media (max-width: 768px) {
  .summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  }
}

.summary-item {
  background: white;
  padding: 12px;
  border-radius: 4px;
}

.summary-label {
  font-size: 11px;
  color: #666;
  margin-bottom: 8px;
}

.summary-value {
  font-size: 20px;
  font-weight: bold;
}

/* モバイル版：年月表示のレイアウト */
@media (max-width: 768px) {
  body > div > div:nth-child(2) {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
    margin-bottom: 30px !important;
  }

  #current-month {
    grid-column: 1 / -1 !important;
    text-align: center !important;
    font-size: 20px !important;
    min-width: unset !important;
    margin-bottom: 10px !important;
  }

  body > div > div:nth-child(2) button:nth-child(1) {
    grid-column: 1;
    grid-row: 2;
  }

  body > div > div:nth-child(2) button:nth-child(3) {
    grid-column: 2;
    grid-row: 2;
  }

  body > div > div:nth-child(2) button:nth-child(4) {
    grid-column: 1 / -1;
    grid-row: 3;
    margin-left: 0 !important;
  }
}

/* モバイル版：ヘッダーレイアウト */
@media (max-width: 768px) {
  body > div > div:first-child {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 15px !important;
    align-items: start !important;
    border-bottom: 2px solid #eee !important;
    padding-bottom: 20px !important;
  }

  body > div > div:first-child > div {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    width: 100%;
    grid-row: 1;
    gap: 10px;
  }

  #user-name {
    font-size: 12px !important;
    margin-right: 0 !important;
    font-weight: bold;
    text-align: right;
  }

  body > div > div:first-child button {
    font-size: 10px !important;
    margin-left: 0 !important;
    padding: 8px 16px !important;
  }

  body > div > div:first-child h1 {
    text-align: center;
    font-size: 22px !important;
    margin-bottom: 0 !important;
    width: 100%;
    grid-row: 2;
  }
}

/* モバイル：月次集計を折りたたみ式 */
@media (max-width: 768px) {
  #summary-section {
    padding: 0;
    background: none;
    margin: 0 -20px 30px -20px;
  }

  #summary-section summary {
    display: block !important;
    background: #f5f5f5;
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 0;
    list-style: none;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
  }

  #summary-section:not([open]) {
    background: none;
    padding: 0;
  }

  #summary-section[open] {
    background: #f5f5f5;
    padding: 20px;
    border-radius: 8px;
  }

  #summary-section[open] summary {
    padding: 0 0 15px 0;
    background: none;
    border-radius: 0;
    margin-bottom: 15px;
  }

  #summary-section:not([open]) .summary-grid {
    display: none;
  }

  #summary-section[open] .summary-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    padding: 0 10px 10px 10px;
  }

  /* スマホ版：月次集計のレイアウト調整 */
  /* 1行目：営業日数、稼働日数（各3列で均等表示）*/
  #summary-section[open] .summary-item:nth-child(1) {
    grid-column: 1 / 4;
  }

  #summary-section[open] .summary-item:nth-child(2) {
    grid-column: 4 / 7;
  }

  /* 2行目：実働時間（全幅） */
  #summary-section[open] .summary-item:nth-child(3) {
    grid-column: 1 / -1;
  }

  /* 平均勤務時間：非表示 */
  #summary-section[open] .summary-item:nth-child(4) {
    display: none;
  }

  /* 3行目：遅刻、早退、休暇日数（各2列で均等） */
  #summary-section[open] .summary-item:nth-child(5) {
    grid-column: 1 / 3;
  }

  #summary-section[open] .summary-item:nth-child(6) {
    grid-column: 3 / 5;
  }

  #summary-section[open] .summary-item:nth-child(7) {
    grid-column: 5 / 7;
  }

  /* モバイル版：月次集計セクションを調整 */
  #summary-section {
    margin: 0 -20px 30px -20px !important;
    padding: 0 !important;
  }

  #summary-section summary {
    padding: 15px 20px !important;
  }

  /* モバイル版：休日設定セクションの幅を月次集計と同じにする */
  #summary-section + div {
    margin: 0 -20px 30px -20px !important;
    padding: 15px 20px !important;
    background: #f5f5f5 !important;
    border-radius: 8px !important;
    border: 1px solid #eee !important;
  }

  /* モバイル版：休日設定の入力欄をグリッドレイアウト */
  #holiday-inputs-wrapper {
    display: none;
  }

  #holiday-inputs-wrapper.holiday-inputs-visible {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    align-items: stretch !important;
  }

  #holiday-inputs-wrapper .holiday-input {
    width: 100% !important;
  }

  #holiday-inputs-wrapper #holiday-toggle-btn {
    grid-column: 1 / 3;
    grid-row: 4;
  }

  /* モバイル版：稼働記録入力フォーム */
  body > div > div:nth-child(5) {
    margin: 0 -20px 30px -20px !important;
    background: #fff5e6 !important;
    padding: 20px !important;
    border-radius: 8px !important;
  }

  /* モバイル版：稼働記録フォームのグリッドレイアウト */
  body > div > div:nth-child(5) form > div:first-child {
    display: grid !important;
    grid-template-columns: repeat(20, 1fr) !important;
    gap: 8px !important;
  }

  /* 日付：1行目左（1-13列、60%） */
  body > div > div:nth-child(5) form > div:first-child > div:nth-child(1) {
    grid-column: 1 / 13;
    grid-row: 1;
  }

  body > div > div:nth-child(5) form > div:first-child > div:nth-child(1) label {
    font-size: 12px;
  }

  /* 開始時刻：2行目左（1-8列）。iOSのネイティブ時刻ピッカーが
     フォントサイズ16pxで窮屈にならないよう、休憩(分)より広めに確保。
     「休憩（分）」ラベルが2行に折り返さないよう、休憩側に幅を残す */
  body > div > div:nth-child(5) form > div:first-child > div:nth-child(2) {
    grid-column: 1 / 8;
    grid-row: 2;
  }

  body > div > div:nth-child(5) form > div:first-child > div:nth-child(2) label {
    font-size: 12px;
  }

  body > div > div:nth-child(5) form > div:first-child > div:nth-child(2) input {
    width: 100% !important;
  }

  /* 終了時刻：2行目中央（8-15列）。開始時刻と同じ理由で幅を広めに確保 */
  body > div > div:nth-child(5) form > div:first-child > div:nth-child(3) {
    grid-column: 8 / 15;
    grid-row: 2;
  }

  body > div > div:nth-child(5) form > div:first-child > div:nth-child(3) label {
    font-size: 12px;
  }

  body > div > div:nth-child(5) form > div:first-child > div:nth-child(3) input {
    width: 100% !important;
  }

  /* 休憩時間：2行目右（15-21列）。「休憩（分）」ラベルが1行に収まる幅を確保 */
  body > div > div:nth-child(5) form > div:first-child > div:nth-child(4) {
    grid-column: 15 / 21;
    grid-row: 2;
  }

  body > div > div:nth-child(5) form > div:first-child > div:nth-child(4) label {
    font-size: 12px;
  }

  /* ステータス：1行目右（13-21列、40%） */
  body > div > div:nth-child(5) form > div:first-child > div:nth-child(5) {
    grid-column: 13 / 21;
    grid-row: 1;
  }

  body > div > div:nth-child(5) form > div:first-child > div:nth-child(5) label {
    font-size: 12px;
  }

  /* モバイル版：業務内容セクション */
  body > div > div:nth-child(5) form > div:nth-child(2) label {
    font-size: 12px !important;
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    margin-bottom: 8px !important;
  }

  body > div > div:nth-child(5) form > div:nth-child(2) label span {
    display: none !important;
  }

  body > div > div:nth-child(5) form > div:nth-child(2) label::after {
    content: "（業務内容または遅刻・早退の理由を入力）※改行は使えません";
    font-size: 6px;
    color: #999;
    white-space: nowrap;
  }

  body > div > div:nth-child(5) form > div:nth-child(2) textarea {
    margin-bottom: 5px !important;
  }

  /* モバイル版：記録を登録ボタン */
  body > div > div:nth-child(5) form #submit-record-btn {
    width: 100% !important;
    font-size: 14px !important;
  }

  /* モバイル版：入力フィールドのフォントサイズ。
     iOS Safari は input/textarea/select の font-size が 16px 未満だと
     フォーカス時にページを自動拡大してしまう（登録後もズームが戻らない）ため、
     ズームが発生しない 16px にする。 */
  body > div > div:nth-child(5) form input,
  body > div > div:nth-child(5) form textarea,
  body > div > div:nth-child(5) form select {
    font-size: 16px !important;
  }

  /* iOS Safari で日付・時刻の入力欄が灰色の空箱に見える問題への対処。
     ネイティブの見た目をリセットし、白背景・高さ・値の色を明示する。 */
  input[type="date"],
  input[type="time"] {
    -webkit-appearance: none;
    appearance: none;
    background-color: #fff;
    min-height: 40px;
    color: #333;
    line-height: 1.2;
  }
  input[type="date"]::-webkit-date-and-time-value,
  input[type="time"]::-webkit-date-and-time-value {
    text-align: left;
  }

  /* モバイル版：稼働記録一覧セクション */
  body > div > div:nth-child(6) {
    background: none !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    margin: 0 -20px !important;
  }

  body > div > div:nth-child(6) table {
    border-radius: 0 !important;
  }

  /* モバイル版：テーブルヘッダーを非表示 */
  body > div > div:nth-child(6) table thead {
    display: none !important;
  }

  /* モバイル版：details要素のデフォルト矢印を非表示 */
  body > div > div:nth-child(6) details > summary {
    list-style: none;
  }

  body > div > div:nth-child(6) details > summary::-webkit-details-marker {
    display: none;
  }

  /* モバイル版：稼働記録アコーディオンボタンのフォントサイズ */
  body > div > div:nth-child(6) details button {
    font-size: 11px !important;
  }
}
