/* ===== 共通モーダルスタイル (pia-practice-modal.js / pia-settings-modal) ===== */

@keyframes piaModalSlideIn {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pia-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99999;
  justify-content: center;
  align-items: center;
  padding: 20px 16px;
  overflow: hidden;
  overscroll-behavior: contain;
}
.pia-modal-overlay.is-open {
  display: flex;
}
.pia-modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 40px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  position: relative;
  animation: piaModalSlideIn 0.25s ease;
  display: flex;
  flex-direction: column;
}
.pia-modal-header {
  padding: 24px 28px 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pia-modal-header h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  color: #333;
}
.pia-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #999;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 6px;
  transition: background 0.15s;
}
.pia-modal-close:hover {
  background: #f0f0f0;
  color: #333;
}
.pia-modal-header {
  flex-shrink: 0;
}
.pia-modal-footer {
  flex-shrink: 0;
}
.pia-modal-body {
  padding: 24px 28px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
  min-height: 0;
  overscroll-behavior: contain;
}
.pia-modal-footer {
  padding: 16px 28px 24px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* フォームグループ */
.pia-modal-body .pm-group {
  margin-bottom: 20px;
}
.pia-modal-body .pm-label {
  display: block;
  font-weight: 600;
  color: #333;
  margin-bottom: 6px;
  font-size: 14px;
}
.pia-modal-body .pm-label .pm-req {
  color: #e74c3c;
  font-size: 0.8rem;
  font-weight: 700;
  background: #ffebee;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 4px;
}
.pia-modal-body .pm-label .pm-opt {
  color: #999;
  font-size: 0.8rem;
  font-weight: 600;
  background: #f5f5f5;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 4px;
}

/* 入力フィールド */
.pia-modal-body .pm-input,
.pia-modal-body .pm-textarea,
.pia-modal-body .pm-select {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s;
  font-family: inherit;
  box-sizing: border-box;
}
.pia-modal-body .pm-input:focus,
.pia-modal-body .pm-textarea:focus,
.pia-modal-body .pm-select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102,126,234,0.1);
}
.pia-modal-body .pm-input.pm-invalid,
.pia-modal-body .pm-textarea.pm-invalid,
.pia-modal-body .pm-select.pm-invalid,
.pia-modal-body .pm-search-selected.pm-invalid,
.pia-modal-body .pm-group.pm-invalid .pm-piece-info,
.pia-modal-body .pm-group.pm-invalid .pm-input,
.pia-modal-body .pm-group.pm-invalid .pm-select {
  border-color: #e53935 !important;
  box-shadow: 0 0 0 3px rgba(229,57,53,0.12);
}
.pia-modal-body .pm-textarea {
  resize: vertical;
  min-height: 80px;
}
.pia-modal-body .pm-help {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
  line-height: 1.5;
}

/* 練習時間（時間・分横並び） */
.pia-modal-body .pm-duration {
  display: flex;
  gap: 10px;
  align-items: center;
  border-radius: 10px;
}
.pia-modal-body .pm-dur-group {
  display: flex;
  gap: 6px;
  align-items: center;
}
.pia-modal-body .pm-dur-group .pm-select {
  width: auto;
  min-width: 70px;
}
.pia-modal-body .pm-dur-label {
  font-size: 14px;
  color: #666;
}

/* チェックボックス */
.pia-modal-body .pm-checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pia-modal-body .pm-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}
.pia-modal-body .pm-checkbox-label {
  font-size: 14px;
  color: #333;
  cursor: pointer;
}

/* 今週の目標スライダー */
.pm-week-goal-box {
  background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
  border: 2px solid #1976d2;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 24px;
}
.pm-slider-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: #667eea;
  text-align: center;
  margin-bottom: 10px;
}
.pm-slider {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  outline: none;
  cursor: pointer;
  appearance: none;
}
.pm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #667eea;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(102,126,234,0.4);
}
.pm-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #667eea;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(102,126,234,0.4);
}
.pm-slider-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: #666;
}

/* ボタン */
.pm-btn-cancel {
  padding: 10px 24px;
  background: #f0f0f0;
  color: #666;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.pm-btn-cancel:hover {
  background: #e0e0e0;
}
.pm-btn-submit {
  padding: 10px 24px;
  background: #6E4CD6;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.pm-btn-submit:hover {
  background: #4f28b2;
  box-shadow: none;
}
.pm-btn-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* メッセージ */
.pm-error-msg {
  padding: 10px 14px;
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.pm-error-msg.is-visible {
  display: block;
}
.pm-success-msg {
  padding: 10px 14px;
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.pm-success-msg.is-visible {
  display: block;
}

/* 練習曲表示（pieceIdあり時） */
.pm-piece-info {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 14px;
  border: 2px solid #e0e0e0;
  margin-bottom: 20px;
}
.pm-piece-info-label {
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}
.pm-piece-info-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #667eea;
  margin: 0;
}

/* ===== 曲検索UI ===== */

/* 検索結果ドロップダウン */
.pm-search-results {
  border: 1.5px solid #ddd;
  border-radius: 8px;
  background: #fff;
  max-height: 220px;
  overflow-y: auto;
  margin-top: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.pm-search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.1s;
}
.pm-search-result-item:last-child { border-bottom: none; }
.pm-search-result-item:hover { background: #f0f5ff; }
.pm-search-loading,
.pm-search-no-result {
  padding: 10px 14px;
  font-size: 13px;
  color: #aaa;
}

/* 選択済み表示 */
.pm-search-selected {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #f0f7ff;
  border: 1.5px solid #93c5fd;
  border-radius: 8px;
}
.pm-search-selected-label {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: #1e40af;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pm-search-clear-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  border: 1.5px solid #93c5fd;
  border-radius: 6px;
  background: #fff;
  color: #3b82f6;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.pm-search-clear-btn:hover { background: #eff6ff; }

/* テキストリンクボタン */
.pm-link-btn {
  background: none;
  border: none;
  padding: 0;
  color: #6b7280;
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
}
.pm-link-btn:hover { color: #3b82f6; }

/* ===== 録音UI ===== */

.pm-audio-file-input {
  display: block !important;
  width: 100%;
  padding: 10px 12px;
  border: 2px dashed #ddd;
  border-radius: 8px;
  background: #fafafa;
  font-size: 13px;
  box-sizing: border-box;
  cursor: pointer;
  margin-bottom: 0;
}

.pm-rec-start-btn {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  background: #fff;
  border: 1.5px solid #4f81bd;
  border-radius: 8px;
  color: #4f81bd;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
.pm-rec-start-btn:hover { background: #e3f0fb; }
.pm-rec-start-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.pm-rec-note {
  margin: 6px 0 0;
  font-size: 11px;
  color: #999;
  line-height: 1.5;
}

.pm-recording-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #fff3f3;
  border: 1.5px solid #ef9a9a;
  border-radius: 8px;
}

.pm-rec-dot {
  width: 10px;
  height: 10px;
  background: #e53935;
  border-radius: 50%;
  flex-shrink: 0;
  animation: recDotBlink 1s ease-in-out infinite;
}
@keyframes recDotBlink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.25; }
}

.pm-rec-label {
  font-size: 13px;
  font-weight: 600;
  color: #e53935;
}

.pm-rec-timer {
  flex: 1;
  font-size: 14px;
  font-weight: 700;
  color: #e53935;
  font-variant-numeric: tabular-nums;
}

.pm-rec-stop-btn {
  padding: 6px 14px;
  background: #e53935;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
.pm-rec-stop-btn:hover { background: #c62828; }

.pm-rec-btns {
  display: flex;
  gap: 8px;
}

.pm-rec-retry-btn {
  flex: 1;
  padding: 8px 12px;
  background: #f5f5f5;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  color: #666;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.pm-rec-retry-btn:hover { background: #eee; }

.pm-rec-use-btn {
  flex: 2;
  padding: 8px 12px;
  background: #4f81bd;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.pm-rec-use-btn:hover { background: #3a6899; }

.pm-rec-confirmed-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #e8f4fd;
  border: 1.5px solid #90caf9;
  border-radius: 8px;
  font-size: 14px;
  color: #1565c0;
  font-weight: 600;
}
.pm-rec-confirmed-row .pm-link-btn {
  margin-left: auto;
  color: #666;
}

/* iOS Safari: date input のはみ出し対策 */
.pia-modal-body input[type="date"].pm-input {
  -webkit-appearance: none;
  appearance: none;
  max-width: 100%;
}

/* スマホ */
@media (max-width: 768px) {
  .pia-modal-overlay {
    padding: 10px;
    align-items: flex-end;
  }
  .pia-modal {
    max-height: calc(100dvh - 20px);
    border-radius: 16px 16px 12px 12px;
  }
  .pia-modal-header {
    padding: 16px 20px 12px;
  }
  .pia-modal-body {
    padding: 16px 20px;
  }
  .pia-modal-footer {
    padding: 12px 20px 20px;
    flex-direction: column-reverse;
  }
  .pm-btn-cancel, .pm-btn-submit {
    width: 100%;
    text-align: center;
  }
  .pia-modal-body .pm-duration {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }
}
